summaryrefslogtreecommitdiffstats
path: root/modules/proc/src/proc_common.cpp
blob: 048c2d7b78e96606c82cc73be553b74422f38cf1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
/******************************************************************************
 *	Copyright (C) 2018	Alejandro Colomar Andrés		      *
 ******************************************************************************/


/******************************************************************************
 ******* headers **************************************************************
 ******************************************************************************/
/* Standard C ----------------------------------------------------------------*/
		/* snprintf() & fflush() */
	#include <cstdio>
		/* clock_t & clock() & CLOCKS_PER_SEC */
	#include <ctime>

/* Packages ------------------------------------------------------------------*/
		/* openCV */
	#include <opencv2/opencv.hpp>
		/* enum zbar::zbar_symbol_type_e */
	#include <zbar.h>

/* Project -------------------------------------------------------------------*/
		/* img_iface_act() */
	#include "img_iface.hpp"
		/* user_iface_log */
	#include "user_iface.hpp"

/* Module --------------------------------------------------------------------*/
		/* enum Proc_DBG */
	#include "proc_iface.hpp"

	#include "proc_common.hpp"


/******************************************************************************
 ******* variables ************************************************************
 ******************************************************************************/
/* Global --------------------------------------------------------------------*/

/* Static --------------------------------------------------------------------*/
static	clock_t	clock_0;
static	clock_t	clock_1;


/******************************************************************************
 ******* static functions *****************************************************
 ******************************************************************************/


/******************************************************************************
 ******* global functions *****************************************************
 ******************************************************************************/
void	proc_apply		(void)
{
	img_iface_act(IMG_IFACE_ACT_APPLY, NULL);
}

void	proc_save_mem		(int n)
{
	img_iface_act(IMG_IFACE_ACT_SAVE_MEM, (void *)&n);
}

void	proc_load_mem		(int n)
{
	img_iface_act(IMG_IFACE_ACT_LOAD_MEM, (void *)&n);

	proc_show_img();
}

void	proc_save_ref		(void)
{
	img_iface_act(IMG_IFACE_ACT_SAVE_REF, NULL);
}

void	proc_save_file		(void)
{
	img_iface_act(IMG_IFACE_ACT_SAVE_FILE, NULL);
}

void	proc_save_update	(void)
{
	img_iface_act(IMG_IFACE_ACT_SAVE_UPDT, NULL);
}

void	proc_local_max		(void)
{
	img_iface_act(IMG_IFACE_ACT_LOCAL_MAX, NULL);

	proc_show_img();
}

void	proc_lines_vertical	(void)
{
	img_iface_act(IMG_IFACE_ACT_LINES_VERTICAL, NULL);

	proc_show_img();
}

void	proc_median_horizontal	(void)
{
	img_iface_act(IMG_IFACE_ACT_MEDIAN_HORIZONTAL, NULL);

	proc_show_img();
}

void	proc_median_vertical	(void)
{
	img_iface_act(IMG_IFACE_ACT_MEDIAN_VERTICAL, NULL);

	proc_show_img();
}

void	proc_pixel_value	(int x, int y, unsigned char *val)
{
	struct Img_Iface_Data_Pixel_Value	data;
	data.x		= x;
	data.y		= y;
	data.val	= val;
	img_iface_act(IMG_IFACE_ACT_PIXEL_VALUE, (void *)&data);
}

void	proc_ROI		(int x, int y, int w, int h)
{
	struct Img_Iface_Data_SetROI		data;
	data.rect.x		= x;
	data.rect.y		= y;
	data.rect.width		= w;
	data.rect.height	= h;
	img_iface_act(IMG_IFACE_ACT_SET_ROI, (void *)&data);

	proc_show_img();
}

void	proc_and_2ref		(void)
{
	img_iface_act(USER_IFACE_ACT_AND_2REF, NULL);

	proc_show_img();
}

void	proc_not		(void)
{
	img_iface_act(USER_IFACE_ACT_NOT, NULL);

	proc_show_img();
}

void	proc_or_2ref		(void)
{
	img_iface_act(USER_IFACE_ACT_OR_2REF, NULL);

	proc_show_img();
}

void	proc_cmp		(int cmp)
{
	struct Img_Iface_Data_Component		data;
	data.cmp	= cmp;
	img_iface_act(IMG_IFACE_ACT_COMPONENT, (void *)&data);

	proc_show_img();
}

void	proc_dilate		(int size)
{
	struct Img_Iface_Data_Dilate_Erode	data;
	data.i	= size;
	img_iface_act(IMG_IFACE_ACT_DILATE, (void *)&data);

	proc_show_img();
}

void	proc_erode		(int size)
{
	struct Img_Iface_Data_Dilate_Erode	data;
	data.i	= size;
	img_iface_act(IMG_IFACE_ACT_ERODE, (void *)&data);

	proc_show_img();
}

void	proc_dilate_erode	(int size)
{
	struct Img_Iface_Data_Dilate_Erode	data;
	data.i	= size;
	img_iface_act(IMG_IFACE_ACT_DILATE_ERODE, (void *)&data);

	proc_show_img();
}

void	proc_erode_dilate	(int size)
{
	struct Img_Iface_Data_Dilate_Erode	data;
	data.i	= size;
	img_iface_act(IMG_IFACE_ACT_ERODE_DILATE, (void *)&data);

	proc_show_img();
}

void	proc_smooth		(int method, int ksize)
{
	struct Img_Iface_Data_Smooth		data;
	data.method	= method;
	data.ksize	= ksize;
	img_iface_act(IMG_IFACE_ACT_SMOOTH, (void *)&data);

	proc_show_img();
}

void	proc_rotate		(class cv::RotatedRect  *rect)
{
	struct Img_Iface_Data_Rotate		data;
	data.center.x	= rect->center.x;
	data.center.y	= rect->center.y;
	data.angle	= rect->angle;
	img_iface_act(IMG_IFACE_ACT_ROTATE, (void *)&data);

	proc_show_img();
}

void	proc_adaptive_threshold	(int method, int type, int ksize)
{
	struct Img_Iface_Data_Adaptive_Thr	data;
	data.method	= method;
	data.thr_typ	= type;
	data.ksize	= ksize;
	img_iface_act(USER_IFACE_ACT_ADAPTIVE_THRESHOLD, (void *)&data);

	proc_show_img();
}

void	proc_cvt_color		(int method)
{
	struct Img_Iface_Data_Cvt_Color		data;
	data.method	= method;
	img_iface_act(IMG_IFACE_ACT_CVT_COLOR, (void *)&data);

	proc_show_img();
}

void	proc_threshold		(int type, int size)
{
	struct Img_Iface_Data_Threshold		data;
	data.thr_typ	= type;
	data.thr_val	= size;
	img_iface_act(IMG_IFACE_ACT_THRESHOLD, (void *)&data);

	proc_show_img();
}

void	proc_distance_transform	(void)
{
	img_iface_act(IMG_IFACE_ACT_DISTANCE_TRANSFORM, NULL);

	proc_show_img();
}

void	proc_contours		(
			std::vector <std::vector <class cv::Point_ <int>>>  *contours,
			class cv::Mat  *hierarchy)
{
	struct Img_Iface_Data_Contours		data;
	data.contours	= contours;
	data.hierarchy	= hierarchy;
	img_iface_act(IMG_IFACE_ACT_CONTOURS, (void *)&data);

	proc_show_img();
}

void	proc_contours_size		(
			std::vector <std::vector <class cv::Point_ <int>>>  *contours,
			double  *area,
			double  *perimeter)
{
	struct Img_Iface_Data_Contours_Size	data;
	data.contours	= contours;
	data.area	= area;
	data.perimeter	= perimeter;
	img_iface_act(IMG_IFACE_ACT_CONTOURS_SIZE, (void *)&data);
}

void	proc_bounding_rect	(
			std::vector <class cv::Point_ <int>>  *contour,
			class cv::Rect_ <int>  *rect,
			bool  show)
{
	struct Img_Iface_Data_Bounding_Rect	data;
	data.contour	= contour;
	data.rect	= rect;
	data.show	= show;
	img_iface_act(IMG_IFACE_ACT_BOUNDING_RECT, (void *)&data);

	if (show) {
		proc_show_img();
	}
}

void	proc_fit_ellipse	(
			std::vector <class cv::Point_ <int>>  *contour,
			class cv::RotatedRect  *rect,
			bool show)
{
	struct Img_Iface_Data_MinARect		data;
	data.contour	= contour;
	data.rect	= rect;
	data.show	= show;
	img_iface_act(IMG_IFACE_ACT_FIT_ELLIPSE, (void *)&data);


	if (show) {
		proc_show_img();
	}
}

void	proc_min_area_rect	(
			std::vector <class cv::Point_ <int>>  *contour,
			class cv::RotatedRect  *rect,
			bool  show)
{
	struct Img_Iface_Data_MinARect		data;
	data.contour	= contour;
	data.rect	= rect;
	data.show	= show;
	img_iface_act(IMG_IFACE_ACT_MIN_AREA_RECT, (void *)&data);

	if (show) {
		proc_show_img();
	}
}

void	proc_OCR		(int lang, int conf)
{
	struct Img_Iface_Data_Read		data;
	data.lang	= lang;	/* eng=0, spa=1, cat=2 */
	data.conf	= conf;	/* none=0, price=1 */
	img_iface_act(IMG_IFACE_ACT_READ, (void *)&data);
}

void	proc_zbar		(int type)
{
	struct Img_Iface_Data_Decode		data;
	data.code_type	= (enum zbar::zbar_symbol_type_e)type;
	img_iface_act(IMG_IFACE_ACT_DECODE, (void *)&data);
}

void	proc_show_img		(void)
{
	if (proc_debug >= PROC_DBG_DELAY_STEP) {
		img_iface_show_img();

		if (proc_debug >= PROC_DBG_STOP_STEP) {
			getchar();
		}
	}
}

void	clock_start		(void)
{
	clock_0	= clock();
}

void	clock_stop		(const char  *txt)
{
	clock_t	clock_diff;
	double	time_diff;

	clock_1		= clock();
	clock_diff	= clock_1 - clock_0;
	time_diff	= (double)clock_diff / (double)CLOCKS_PER_SEC;

	/* Write time_diff into log */
	snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
							"Time:  %.3lf  (%s)",
							txt, time_diff);
	user_iface_log.lvl[user_iface_log.len]	= 0;
	(user_iface_log.len)++;
}


/******************************************************************************
 ******* end of file **********************************************************
 ******************************************************************************/