summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandroColomar <colomar.6.4.3@gmail.com>2018-11-03 17:07:57 +0100
committerAlejandroColomar <colomar.6.4.3@gmail.com>2018-11-03 17:07:57 +0100
commitdd636486d11673ffdf8d45fa1d16e8d8962f9845 (patch)
treefc1225a928250cc843c48de5909f40f98ea7312a
parent03a5ea62cf3c5bd6881796a72e5ce76dc90b57db (diff)
Add bitwise operations to image; Add steps to proc_resistor; Funtion to get pixel value (1 chan);
-rw-r--r--modules/image/inc/img_cv.hpp7
-rw-r--r--modules/image/inc/img_iface.h5
-rw-r--r--modules/image/inc/img_iface.hpp16
-rw-r--r--modules/image/src/img_cv.cpp113
-rw-r--r--modules/image/src/img_iface.cpp117
-rw-r--r--modules/proc/inc/proc.h5
-rw-r--r--modules/proc/inc/proc.hpp5
-rw-r--r--modules/proc/src/proc.cpp461
-rw-r--r--modules/user/inc/user_clui.h1
-rw-r--r--modules/user/inc/user_iface.h4
-rw-r--r--modules/user/inc/user_iface.hpp4
-rw-r--r--modules/user/src/user_clui.c94
-rw-r--r--modules/user/src/user_iface.c1
-rw-r--r--modules/user/src/user_tui.c84
14 files changed, 690 insertions, 227 deletions
diff --git a/modules/image/inc/img_cv.hpp b/modules/image/inc/img_cv.hpp
index e352b9a..9290ac5 100644
--- a/modules/image/inc/img_cv.hpp
+++ b/modules/image/inc/img_cv.hpp
@@ -24,7 +24,9 @@
IMG_CV_ACT_FOO = 0,
IMG_CV_ACT_CV = 0x0100,
- IMG_CV_ACT_INVERT,
+ IMG_CV_ACT_NOT,
+ IMG_CV_ACT_OR_2REF,
+ IMG_CV_ACT_AND_2REF,
IMG_CV_ACT_CVT_COLOR,
IMG_CV_ACT_COMPONENT,
IMG_CV_ACT_HISTOGRAM,
@@ -41,7 +43,8 @@
IMG_CV_ACT_FIT_ELLIPSE,
IMG_CV_ACT_ROTATE_ORTO,
IMG_CV_ACT_ROTATE,
- IMG_CV_ACT_SET_ROI
+ IMG_CV_ACT_SET_ROI,
+ IMG_CV_ACT_PIXEL_VALUE
};
diff --git a/modules/image/inc/img_iface.h b/modules/image/inc/img_iface.h
index 0105f58..b7e14ca 100644
--- a/modules/image/inc/img_iface.h
+++ b/modules/image/inc/img_iface.h
@@ -32,7 +32,9 @@
IMG_IFACE_ACT_FOO = 0,
IMG_IFACE_ACT_CV = 0x0100,
- IMG_IFACE_ACT_INVERT,
+ IMG_IFACE_ACT_NOT,
+ IMG_IFACE_ACT_OR_2REF,
+ IMG_IFACE_ACT_AND_2REF,
IMG_IFACE_ACT_CVT_COLOR,
IMG_IFACE_ACT_COMPONENT,
IMG_IFACE_ACT_HISTOGRAM,
@@ -50,6 +52,7 @@
IMG_IFACE_ACT_ROTATE_ORTO,
IMG_IFACE_ACT_ROTATE,
IMG_IFACE_ACT_SET_ROI,
+ IMG_IFACE_ACT_PIXEL_VALUE,
IMG_IFACE_ACT_DILATE_ERODE,
IMG_IFACE_ACT_ERODE_DILATE,
diff --git a/modules/image/inc/img_iface.hpp b/modules/image/inc/img_iface.hpp
index 5c2590c..710709a 100644
--- a/modules/image/inc/img_iface.hpp
+++ b/modules/image/inc/img_iface.hpp
@@ -38,7 +38,9 @@
IMG_IFACE_ACT_FOO = 0,
IMG_IFACE_ACT_CV = 0x0100,
- IMG_IFACE_ACT_INVERT,
+ IMG_IFACE_ACT_NOT,
+ IMG_IFACE_ACT_OR_2REF,
+ IMG_IFACE_ACT_AND_2REF,
IMG_IFACE_ACT_CVT_COLOR,
IMG_IFACE_ACT_COMPONENT,
IMG_IFACE_ACT_HISTOGRAM,
@@ -56,6 +58,7 @@
IMG_IFACE_ACT_ROTATE_ORTO,
IMG_IFACE_ACT_ROTATE,
IMG_IFACE_ACT_SET_ROI,
+ IMG_IFACE_ACT_PIXEL_VALUE,
IMG_IFACE_ACT_DILATE_ERODE,
IMG_IFACE_ACT_ERODE_DILATE,
@@ -165,13 +168,14 @@
struct Img_Iface_Data_Contours_Size {
std::vector <std::vector <class cv::Point_ <int>>> *contours;
- double area [CONTOURS_MAX];
- double perimeter [CONTOURS_MAX];
+ double *area;
+ double *perimeter;
};
struct Img_Iface_Data_MinARect {
std::vector <class cv::Point_ <int>> *contour;
class cv::RotatedRect *rect;
+ bool show;
};
struct Img_Iface_Data_Rotate_Orto {
@@ -187,6 +191,12 @@
class cv::Rect_ <int> rect;
};
+ struct Img_Iface_Data_Pixel_Value {
+ unsigned char *val;
+ int x;
+ int y;
+ };
+
/* img_zbar -------------------------------------------------------------------*/
struct Img_Iface_Data_Decode {
enum zbar::zbar_symbol_type_e code_type;
diff --git a/modules/image/src/img_cv.cpp b/modules/image/src/img_cv.cpp
index bc98b93..6954a69 100644
--- a/modules/image/src/img_cv.cpp
+++ b/modules/image/src/img_cv.cpp
@@ -7,6 +7,8 @@
******* headers **************************************************************
******************************************************************************/
/* Standard C ----------------------------------------------------------------*/
+ /* fabs */
+ #include <cmath>
/* true & false */
#include <cstdbool>
/* snprintf() */
@@ -31,7 +33,9 @@
******* static functions *****************************************************
******************************************************************************/
/* Filters */
-static void img_cv_invert (class cv::Mat *imgptr);
+static void img_cv_not (class cv::Mat *imgptr);
+static void img_cv_or_2ref (class cv::Mat *imgptr, void *data);
+static void img_cv_and_2ref (class cv::Mat *imgptr, void *data);
static void img_cv_cvt_color (class cv::Mat *imgptr, void *data);
static void img_cv_component (class cv::Mat *imgptr, void *data);
static void img_cv_histogram (class cv::Mat *imgptr, void *data);
@@ -49,6 +53,7 @@ static void img_cv_fit_ellipse (class cv::Mat *imgptr, void *data);
static void img_cv_rotate_orto (class cv::Mat *imgptr, void *data);
static void img_cv_rotate (class cv::Mat *imgptr, void *data);
static void img_cv_set_ROI (class cv::Mat *imgptr, void *data);
+static void img_cv_pixel_value (class cv::Mat *imgptr, void *data);
/******************************************************************************
@@ -57,8 +62,14 @@ static void img_cv_set_ROI (class cv::Mat *imgptr, void *data);
void img_cv_act (class cv::Mat *imgptr, int action, void *data)
{
switch (action) {
- case IMG_CV_ACT_INVERT:
- img_cv_invert(imgptr);
+ case IMG_CV_ACT_NOT:
+ img_cv_not(imgptr);
+ break;
+ case IMG_CV_ACT_OR_2REF:
+ img_cv_or_2ref(imgptr, data);
+ break;
+ case IMG_CV_ACT_AND_2REF:
+ img_cv_and_2ref(imgptr, data);
break;
case IMG_CV_ACT_CVT_COLOR:
@@ -118,6 +129,10 @@ void img_cv_act (class cv::Mat *imgptr, int action, void *data)
case IMG_CV_ACT_SET_ROI:
img_cv_set_ROI(imgptr, data);
break;
+
+ case IMG_CV_ACT_PIXEL_VALUE:
+ img_cv_pixel_value(imgptr, data);
+ break;
}
}
@@ -125,14 +140,27 @@ void img_cv_act (class cv::Mat *imgptr, int action, void *data)
/******************************************************************************
******* static functions *****************************************************
******************************************************************************/
-/* * * * * * * * * *
- * * * Filters * * * * * *
- * * * * * * * * * */
-static void img_cv_invert (class cv::Mat *imgptr)
+static void img_cv_not (class cv::Mat *imgptr)
{
cv::bitwise_not(*imgptr, *imgptr);
}
+static void img_cv_or_2ref (class cv::Mat *imgptr, void *data)
+{
+ class cv::Mat *img_ref;
+ img_ref = (class cv::Mat *)data;
+
+ cv::bitwise_or(*imgptr, *img_ref, *imgptr);
+}
+
+static void img_cv_and_2ref (class cv::Mat *imgptr, void *data)
+{
+ class cv::Mat *img_ref;
+ img_ref = (class cv::Mat *)data;
+
+ cv::bitwise_and(*imgptr, *img_ref, *imgptr);
+}
+
static void img_cv_cvt_color (class cv::Mat *imgptr, void *data)
{
/* Data */
@@ -445,8 +473,10 @@ static void img_cv_contours_size (void *data)
/* Get area and perimeter */
int i;
for (i = 0; i < contours->size(); i++) {
- data_cast->area[i] = cv::contourArea((*contours)[i], false);
- data_cast->perimeter[i] = cv::arcLength((*contours)[i], true);
+ data_cast->area[i] = cv::contourArea(
+ (*contours)[i], false);
+ data_cast->perimeter[i] = cv::arcLength(
+ (*contours)[i], true);
}
}
@@ -462,25 +492,30 @@ static void img_cv_min_area_rect (class cv::Mat *imgptr, void *data)
/* Rotated rectangle */
class cv::RotatedRect *rect;
rect = data_cast->rect;
+ /* Show rectangle ? */
+ bool show;
+ show = data_cast->show;
/* Get rectangle */
*rect = cv::minAreaRect(*contour);
/* Draw rectangle */
class cv::Point_<float> vertices[4];
- rect->points(vertices);
- cv::line(*imgptr, cv::Point(vertices[0].x, vertices[0].y),
- cv::Point(vertices[1].x, vertices[1].y),
- CV_RGB(0, 0, 255), 1, 8, 0);
- cv::line(*imgptr, cv::Point(vertices[1].x, vertices[1].y),
- cv::Point(vertices[2].x, vertices[2].y),
- CV_RGB(0, 0, 255), 1, 8, 0);
- cv::line(*imgptr, cv::Point(vertices[2].x, vertices[2].y),
- cv::Point(vertices[3].x, vertices[3].y),
- CV_RGB(0, 0, 255), 1, 8, 0);
- cv::line(*imgptr, cv::Point(vertices[3].x, vertices[3].y),
- cv::Point(vertices[0].x, vertices[0].y),
- CV_RGB(0, 0, 255), 1, 8, 0);
+ if (show) {
+ rect->points(vertices);
+ cv::line(*imgptr, cv::Point(vertices[0].x, vertices[0].y),
+ cv::Point(vertices[1].x, vertices[1].y),
+ CV_RGB(0, 0, 255), 1, 8, 0);
+ cv::line(*imgptr, cv::Point(vertices[1].x, vertices[1].y),
+ cv::Point(vertices[2].x, vertices[2].y),
+ CV_RGB(0, 0, 255), 1, 8, 0);
+ cv::line(*imgptr, cv::Point(vertices[2].x, vertices[2].y),
+ cv::Point(vertices[3].x, vertices[3].y),
+ CV_RGB(0, 0, 255), 1, 8, 0);
+ cv::line(*imgptr, cv::Point(vertices[3].x, vertices[3].y),
+ cv::Point(vertices[0].x, vertices[0].y),
+ CV_RGB(0, 0, 255), 1, 8, 0);
+ }
}
static void img_cv_fit_ellipse (class cv::Mat *imgptr, void *data)
@@ -560,13 +595,16 @@ static void img_cv_rotate (class cv::Mat *imgptr, void *data)
double angle;
angle = data_cast->angle;
- /* Get map_matrix */
- map_matrix = cv::getRotationMatrix2D(*center, angle, 1);
+ /* Don't rotate if angle is negligible */
+ if (fabs(angle) < 1.0) {
+ /* Get map_matrix */
+ map_matrix = cv::getRotationMatrix2D(*center, angle, 1);
- /* Rotate */
- cv::warpAffine(*imgptr, *imgptr, map_matrix, imgptr->size(),
- cv::INTER_LINEAR, cv::BORDER_CONSTANT,
- cv::Scalar(0, 0, 0));
+ /* Rotate */
+ cv::warpAffine(*imgptr, *imgptr, map_matrix, imgptr->size(),
+ cv::INTER_LINEAR, cv::BORDER_CONSTANT,
+ cv::Scalar(0, 0, 0));
+ }
/* clean up */
map_matrix.release();
@@ -586,6 +624,25 @@ static void img_cv_set_ROI (class cv::Mat *imgptr, void *data)
*imgptr = (*imgptr)(*rect);
}
+static void img_cv_pixel_value (class cv::Mat *imgptr, void *data)
+{
+ /* Data */
+ struct Img_Iface_Data_Pixel_Value *data_cast;
+ data_cast = (struct Img_Iface_Data_Pixel_Value *)data;
+
+ /* Value */
+ unsigned char *val;
+ val = data_cast->val;
+ /* Position */
+ int x;
+ x = data_cast->x;
+ int y;
+ y = data_cast->y;
+
+ /* Get value */
+ *val = imgptr->at<unsigned char>(y, x);
+}
+
/******************************************************************************
******* end of file **********************************************************
diff --git a/modules/image/src/img_iface.cpp b/modules/image/src/img_iface.cpp
index 1abdeb5..5142944 100644
--- a/modules/image/src/img_iface.cpp
+++ b/modules/image/src/img_iface.cpp
@@ -65,6 +65,8 @@ static class cv::Mat histogram_c2;
static class cv::Mat hist_img_c1;
static class cv::Mat hist_img_c3;
static std::vector <std::vector <cv::Point_ <int>>> contours;
+static double area [CONTOURS_MAX];
+static double perimeter [CONTOURS_MAX];
static class cv::Mat hierarchy;
static class cv::RotatedRect rectangle;
@@ -73,7 +75,9 @@ static class cv::RotatedRect rectangle;
******* static functions *****************************************************
******************************************************************************/
/* img_cv */
-static void img_iface_invert (void);
+static void img_iface_not (void);
+static void img_iface_or_2ref (void);
+static void img_iface_and_2ref (void);
static void img_iface_cvt_color (void *data);
static void img_iface_component (void *data);
static void img_iface_histogram (void *data);
@@ -91,6 +95,7 @@ static void img_iface_fit_ellipse (void *data);
static void img_iface_rotate_orto (void *data);
static void img_iface_rotate (void *data);
static void img_iface_set_ROI (void *data);
+static void img_iface_pixel_value (void *data);
static void img_iface_dilate_erode (void *data);
static void img_iface_erode_dilate (void *data);
@@ -116,8 +121,8 @@ static void img_iface_save_file (void);
******************************************************************************/
void img_iface_init (void)
{
- cv::namedWindow(WIN_NAME_IMG, cv::WINDOW_NORMAL);
cv::namedWindow(WIN_NAME_HIST, cv::WINDOW_NORMAL);
+ cv::namedWindow(WIN_NAME_IMG, cv::WINDOW_NORMAL);
hist_img_c1.release();
hist_img_c1 = cv::Mat::zeros(cv::Size(256, 100), CV_8UC3);
@@ -186,8 +191,14 @@ void img_iface_act (int action, void *data)
{
switch (action) {
/* img_cv */
- case IMG_IFACE_ACT_INVERT:
- img_iface_invert();
+ case IMG_IFACE_ACT_NOT:
+ img_iface_not();
+ break;
+ case IMG_IFACE_ACT_OR_2REF:
+ img_iface_or_2ref();
+ break;
+ case IMG_IFACE_ACT_AND_2REF:
+ img_iface_and_2ref();
break;
case IMG_IFACE_ACT_CVT_COLOR:
img_iface_cvt_color(data);
@@ -240,6 +251,9 @@ void img_iface_act (int action, void *data)
case IMG_IFACE_ACT_SET_ROI:
img_iface_set_ROI(data);
break;
+ case IMG_IFACE_ACT_PIXEL_VALUE:
+ img_iface_pixel_value(data);
+ break;
case IMG_IFACE_ACT_DILATE_ERODE:
img_iface_dilate_erode(data);
@@ -317,7 +331,7 @@ void img_iface_show_hist_c3 (void)
******* static functions *****************************************************
******************************************************************************/
/* img_cv --------------------------------------------------------------------*/
-static void img_iface_invert (void)
+static void img_iface_not (void)
{
/* Write into log */
snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
@@ -325,8 +339,54 @@ static void img_iface_invert (void)
user_iface_log.lvl[user_iface_log.len] = 1;
(user_iface_log.len)++;
- /* Filter: invert color */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_INVERT, NULL);
+ /* Bitwise NOT */
+ img_cv_act(&image_copy_tmp, IMG_CV_ACT_NOT, NULL);
+}
+
+static void img_iface_or_2ref (void)
+{
+ /* Must have same channels */
+ if (image_copy_tmp.channels() != image_ref.channels()) {
+ /* Write into log */
+ snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
+ "! Invalid input");
+ user_iface_log.lvl[user_iface_log.len] = 1;
+ (user_iface_log.len)++;
+
+ return;
+ }
+
+ /* Write into log */
+ snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
+ "Bitwise OR");
+ user_iface_log.lvl[user_iface_log.len] = 1;
+ (user_iface_log.len)++;
+
+ /* Bitwise OR to reference */
+ img_cv_act(&image_copy_tmp, IMG_CV_ACT_OR_2REF, (void *)&image_ref);
+}
+
+static void img_iface_and_2ref (void)
+{
+ /* Must have same channels */
+ if (image_copy_tmp.channels() != image_ref.channels()) {
+ /* Write into log */
+ snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
+ "! Invalid input");
+ user_iface_log.lvl[user_iface_log.len] = 1;
+ (user_iface_log.len)++;
+
+ return;
+ }
+
+ /* Write into log */
+ snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
+ "Bitwise AND");
+ user_iface_log.lvl[user_iface_log.len] = 1;
+ (user_iface_log.len)++;
+
+ /* Bitwise AND to reference */
+ img_cv_act(&image_copy_tmp, IMG_CV_ACT_AND_2REF, (void *)&image_ref);
}
static void img_iface_cvt_color (void *data)
@@ -728,6 +788,8 @@ static void img_iface_contours_size (void *data)
struct Img_Iface_Data_Contours_Size data_tmp;
if (!data) {
data_tmp.contours = &contours;
+ data_tmp.area = area;
+ data_tmp.perimeter = perimeter;
data = (void *)&data_tmp;
}
@@ -770,8 +832,8 @@ static void img_iface_min_area_rect (void *data)
return;
}
data_tmp.contour = &(contours[0]);
-
data_tmp.rect = &rectangle;
+ data_tmp.show = true;
data = (void *)&data_tmp;
}
@@ -924,6 +986,45 @@ static void img_iface_set_ROI (void *data)
img_cv_act(&image_copy_tmp, IMG_CV_ACT_SET_ROI, data);
}
+static void img_iface_pixel_value (void *data)
+{
+ /* Data */
+ struct Img_Iface_Data_Pixel_Value data_tmp;
+ unsigned char val;
+ if (!data) {
+ data_tmp.val = &val;
+
+ /* Ask user */
+ char title [80];
+ snprintf(title, 80, "x:");
+ data_tmp.x = user_iface_getint(0, 0,
+ image_copy_tmp.cols,
+ title, NULL);
+
+ snprintf(title, 80, "y:");
+ data_tmp.y = user_iface_getint(0, 0,
+ image_copy_tmp.rows,
+ title, NULL);
+
+ data = (void *)&data_tmp;
+ }
+
+ /* Contours size */
+ img_cv_act(&image_copy_tmp, IMG_CV_ACT_PIXEL_VALUE, data);
+
+ /* Write into log */
+ struct Img_Iface_Data_Pixel_Value *data_cast;
+ data_cast = (struct Img_Iface_Data_Pixel_Value *)data;
+ snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
+ "Pixel value: (%i, %i): %i",
+ data_cast->x,
+ data_cast->y,
+ *(data_cast->val));
+ user_iface_log.lvl[user_iface_log.len] = 1;
+ (user_iface_log.len)++;
+}
+
+/* img_cv: composite --------------------------------------------------------*/
static void img_iface_dilate_erode (void *data)
{
/* Data */
diff --git a/modules/proc/inc/proc.h b/modules/proc/inc/proc.h
index d932b08..498f9e5 100644
--- a/modules/proc/inc/proc.h
+++ b/modules/proc/inc/proc.h
@@ -44,7 +44,10 @@
enum Proc_Resistor {
RESISTOR_OK,
- RESISTOR_NOK_RESISTOR
+ RESISTOR_NOK_RESISTOR,
+ RESISTOR_NOK_BANDS,
+ RESISTOR_NOK_STD_VALUE,
+ RESISTOR_NOK_TOLERANCE
};
diff --git a/modules/proc/inc/proc.hpp b/modules/proc/inc/proc.hpp
index 1fd6dec..f933c39 100644
--- a/modules/proc/inc/proc.hpp
+++ b/modules/proc/inc/proc.hpp
@@ -44,7 +44,10 @@
enum Proc_Resistor {
RESISTOR_OK,
- RESISTOR_NOK_RESISTOR
+ RESISTOR_NOK_RESISTOR,
+ RESISTOR_NOK_BANDS,
+ RESISTOR_NOK_STD_VALUE,
+ RESISTOR_NOK_TOLERANCE
};
diff --git a/modules/proc/src/proc.cpp b/modules/proc/src/proc.cpp
index df2a7cc..9f92341 100644
--- a/modules/proc/src/proc.cpp
+++ b/modules/proc/src/proc.cpp
@@ -7,6 +7,8 @@
******* headers **************************************************************
******************************************************************************/
/* Standard C ----------------------------------------------------------------*/
+ /* pow() */
+ #include <cmath>
/* snprintf() & fflush() */
#include <cstdio>
/* strcmp() */
@@ -55,12 +57,16 @@ static void result_resistor (int status);
static void proc_save_mem (int n);
static void proc_load_mem (int n);
+static void proc_save_ref (void);
+
static void proc_cvt_color (int method);
static void proc_cmp (int cmp);
static void proc_smooth (int method, int ksize);
static void proc_adaptive_threshold (int method, int type, int ksize);
static void proc_threshold (int type, int ksize);
-static void proc_invert (void);
+static void proc_not (void);
+static void proc_or_2ref (void);
+static void proc_and_2ref (void);
static void proc_dilate (int size);
static void proc_erode (int size);
static void proc_dilate_erode (int size);
@@ -68,14 +74,22 @@ static void proc_erode_dilate (int size);
static void proc_contours (
std::vector <std::vector <class cv::Point_ <int>>> *contours,
class cv::Mat *hierarchy);
+static void proc_contours_size (
+ std::vector <std::vector <class cv::Point_ <int>>> *contours,
+ double *area,
+ double *perimeter);
static void proc_min_area_rect (
std::vector <class cv::Point_ <int>> *contour,
- class cv::RotatedRect *rect);
+ class cv::RotatedRect *rect,
+ bool show);
static void proc_fit_ellipse (
std::vector <class cv::Point_ <int>> *contour,
- class cv::RotatedRect *rect);
+ class cv::RotatedRect *rect,
+ bool show);
static void proc_rotate (class cv::RotatedRect *rect);
static void proc_ROI (int x, int y, int w, int h);
+static void proc_pixel_value (int x, int y, unsigned char *val);
+
static void proc_OCR (int lang, int conf);
static void proc_zbar (int type);
@@ -215,12 +229,12 @@ static int proc_label (void)
proc_cmp(IMG_IFACE_CMP_BLUE);
proc_smooth(IMGI_SMOOTH_MEDIAN, 7);
- #if 0
- proc_adaptive_threshold(CV_ADAPTIVE_THRESH_MEAN_C,
- CV_THRESH_BINARY, 5);
- #else
- proc_invert();
- #endif
+#if 0
+ proc_adaptive_threshold(CV_ADAPTIVE_THRESH_MEAN_C,
+ CV_THRESH_BINARY, 5);
+#else
+ proc_not();
+#endif
proc_smooth(IMGI_SMOOTH_MEAN, 21);
proc_threshold(cv::THRESH_BINARY_INV, 2);
proc_dilate_erode(100);
@@ -233,7 +247,7 @@ static int proc_label (void)
return status;
}
- proc_min_area_rect(&(contours[0]), &rect);
+ proc_min_area_rect(&(contours[0]), &rect, true);
/* If angle is < -45º, it is taking into acount the incorrect side */
if (rect.angle < -45.0) {
@@ -450,31 +464,31 @@ static void result_label (int status)
switch (status) {
case LABEL_OK:
snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Label: OK");
+ "Label: OK");
break;
case LABEL_NOK_LABEL:
snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Label: NOK_LABEL");
+ "Label: NOK_LABEL");
break;
case LABEL_NOK_CERDO:
snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Label: NOK_CERDO");
+ "Label: NOK_CERDO");
break;
case LABEL_NOK_BCODE:
snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Label: NOK_BCODE");
+ "Label: NOK_BCODE");
break;
case LABEL_NOK_PRODUCT:
snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Label: NOK_PRODUCT");
+ "Label: NOK_PRODUCT");
break;
case LABEL_NOK_PRICE:
snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Label: NOK_PRICE");
+ "Label: NOK_PRICE");
break;
default:
snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Label: NOK");
+ "Label: NOK");
break;
}
user_iface_log.lvl[user_iface_log.len] = 0;
@@ -497,7 +511,38 @@ static int proc_resistor (void)
int w;
int h;
- char price [80];
+ struct {
+ /* found? */
+ bool found;
+
+ /* position */
+ int x;
+ int y;
+ } blobs [5];
+
+ struct {
+ /* found? */
+ bool found;
+
+ /* blob num */
+ int blob;
+
+ /* position */
+ int x;
+ int y;
+
+ /* value */
+ unsigned char h;
+ unsigned char s;
+ unsigned char v;
+ } bands [5];
+
+ char code [6] = {'\0', '\0', '\0', '\0', '\0', '\0'};
+ float resistance;
+ float tolerance;
+
+ int i;
+ int j;
proc_save_mem(0);
/* Find resistor (position and angle) */
@@ -520,29 +565,29 @@ static int proc_resistor (void)
return status;
}
- #if 0
- proc_min_area_rect(&(contours[0]), &rect);
+#if 1
+ proc_min_area_rect(&(contours[0]), &rect, true);
- /* If angle is < -45º, it is taking into acount the incorrect side */
- if (rect.angle < -45.0) {
- int tmp;
- rect.angle = rect.angle + 90.0;
- tmp = rect.size.width;
- rect.size.width = rect.size.height;
- rect.size.height = tmp;
- }
- #else
- proc_fit_ellipse(&(contours[0]), &rect);
-
- /* If height > width, it is taking into acount the incorrect side */
- if (rect.size.height > rect.size.width) {
- int tmp;
- rect.angle = rect.angle - 90.0;
- tmp = rect.size.width;
- rect.size.width = rect.size.height;
- rect.size.height = tmp;
- }
- #endif
+ /* If angle is < -45º, it is taking into acount the incorrect side */
+ if (rect.angle < -45.0) {
+ int tmp;
+ rect.angle = rect.angle + 90.0;
+ tmp = rect.size.width;
+ rect.size.width = rect.size.height;
+ rect.size.height = tmp;
+ }
+#else
+ proc_fit_ellipse(&(contours[0]), &rect, true);
+
+ /* If height > width, it is taking into acount the incorrect side */
+ if (rect.size.height > rect.size.width) {
+ int tmp;
+ rect.angle = rect.angle - 90.0;
+ tmp = rect.size.width;
+ rect.size.width = rect.size.height;
+ rect.size.height = tmp;
+ }
+#endif
/* Measure time */
time_1 = clock();
@@ -560,15 +605,15 @@ static int proc_resistor (void)
proc_load_mem(0);
proc_rotate(&rect);
- x = rect.center.x - (0.9 * rect.size.width / 2.0);
+ x = rect.center.x - (0.8 * rect.size.width / 2.0);
if (x < 0) {
x = 0;
}
- y = rect.center.y - (0.0 * rect.size.height / 2.0);
+ y = rect.center.y - (0 * rect.size.height / 2.0);
if (y < 0) {
y = 0;
}
- w = rect.size.width * 0.9;
+ w = rect.size.width * 0.8;
h = rect.size.height * 0.3;
proc_ROI(x, y, w, h);
proc_save_mem(1);
@@ -582,7 +627,7 @@ static int proc_resistor (void)
user_iface_log.lvl[user_iface_log.len] = 0;
(user_iface_log.len)++;
}
- /* Separate background and lines */
+ /* Separate background (BK) and lines (WH) */
{
/* Measure time */
time_0 = clock();
@@ -592,29 +637,42 @@ static int proc_resistor (void)
proc_smooth(IMGI_SMOOTH_MEDIAN, 5);
proc_save_mem(2);
- /* hue: bkgd->black; */
+ /* hue */
proc_cmp(IMG_IFACE_CMP_HUE);
- proc_invert();
+ proc_save_mem(3);
+ proc_not();
proc_threshold(cv::THRESH_TOZERO_INV, 255 - 15);
proc_threshold(cv::THRESH_TOZERO, 255 - 23);
proc_threshold(cv::THRESH_BINARY_INV, 1);
- proc_save_mem(3);
+ proc_save_mem(4);
- /* saturation: bkgd->black; */
+ /* saturation */
proc_load_mem(2);
proc_cmp(IMG_IFACE_CMP_SATURATION);
+ proc_save_mem(5);
proc_threshold(cv::THRESH_TOZERO_INV, 163);
proc_threshold(cv::THRESH_TOZERO, 50);
proc_threshold(cv::THRESH_BINARY_INV, 1);
- proc_save_mem(4);
+ proc_save_mem(6);
- /* value: bkgd->black; */
+ /* value */
proc_load_mem(2);
proc_cmp(IMG_IFACE_CMP_VALUE);
+ proc_save_mem(7);
proc_threshold(cv::THRESH_TOZERO_INV, 240);
proc_threshold(cv::THRESH_TOZERO, 100);
proc_threshold(cv::THRESH_BINARY_INV, 1);
- proc_save_mem(5);
+ proc_save_mem(8);
+
+ /* Merge the components: H | S | V */
+ proc_save_ref();
+ proc_load_mem(6);
+ proc_or_2ref();
+ proc_save_ref();
+ proc_load_mem(4);
+ proc_or_2ref();
+ proc_dilate_erode(1);
+ proc_save_mem(9);
/* Measure time */
time_1 = clock();
@@ -625,70 +683,208 @@ static int proc_resistor (void)
user_iface_log.lvl[user_iface_log.len] = 0;
(user_iface_log.len)++;
}
-#if 0
- /* Convert color from BGR to HSV */
+ /* Find bands: contours -> rectangles -> positions */
{
/* Measure time */
time_0 = clock();
- proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU);
- proc_erode(1);
- proc_OCR(IMG_IFACE_OCR_LANG_ENG, IMG_IFACE_OCR_CONF_NONE);
+ /* Contours */
+ proc_contours(&contours, &hierarchy);
- /* Compare Label text to "Cerdo". */
- bool cerdo_nok;
- cerdo_nok = strncmp(img_ocr_text, "Cerdo",
- strlen("Cerdo"));
- if (cerdo_nok) {
- status = LABEL_NOK_CERDO;
+ bool bands_nok;
+ bands_nok = contours.size() != 4;
+ if (bands_nok) {
+ status = RESISTOR_NOK_BANDS;
result_label(status);
return status;
}
+ for (i = 0; i < contours.size(); i++) {
+ blobs[i].found = true;
+ proc_min_area_rect(&(contours[i]), &rect, true);
+ blobs[i].x = rect.center.x;
+ blobs[i].y = rect.center.y;
+ }
+
/* Measure time */
time_1 = clock();
times = ((double) time_1 - time_0) / CLOCKS_PER_SEC;
/* Write time into log */
snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Time2: %.3lf", times);
+ "Time3: %.3lf", times);
user_iface_log.lvl[user_iface_log.len] = 0;
(user_iface_log.len)++;
+
}
- /* Read barcode in original image */
+ /* Read values of HSV on the center of each band */
{
/* Measure time */
time_0 = clock();
- proc_load_mem(0);
- proc_cmp(IMG_IFACE_CMP_GREEN);
- proc_zbar(zbar::ZBAR_EAN13);
+ /* Sort blobs into bands (sort x) */
+ float tmp_x;
+ int tmp_i;
+ for (i = 0; i < contours.size(); i++) {
+ tmp_x = INFINITY;
+ for (j = 0; j < contours.size(); j++) {
+ if ((blobs[j].x < tmp_x) && (blobs[j].found)) {
+ tmp_x = blobs[j].x;
+ tmp_i = j;
+ }
+ }
+ blobs[tmp_i].found = false;
+ bands[i].blob = tmp_i;
+ bands[i].x = blobs[tmp_i].x;
+ bands[i].y = blobs[tmp_i].y;
+ }
- /* Check that 1 and only 1 bcode is read. */
- if (zb_codes.n != 1) {
- status = LABEL_NOK_BCODE;
+ /* Hue */
+ proc_load_mem(3);
+ for (i = 0; i < contours.size(); i++) {
+ proc_pixel_value(bands[i].x, bands[i].y, &(bands[i].h));
+ }
+ /* Saturation */
+ proc_load_mem(5);
+ for (i = 0; i < contours.size(); i++) {
+ proc_pixel_value(bands[i].x, bands[i].y, &(bands[i].s));
+ }
+ /* Value */
+ proc_load_mem(7);
+ for (i = 0; i < contours.size(); i++) {
+ proc_pixel_value(bands[i].x, bands[i].y, &(bands[i].v));
+ }
+
+ /* Measure time */
+ time_1 = clock();
+ times = ((double) time_1 - time_0) / CLOCKS_PER_SEC;
+ /* Write time into log */
+ snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
+ "Time4: %.3lf", times);
+ user_iface_log.lvl[user_iface_log.len] = 0;
+ (user_iface_log.len)++;
+
+ }
+ /* Interpret colors */
+ {
+ /* Measure time */
+ time_0 = clock();
+
+ for (i = 0; (i < contours.size()) && (i < 5); i++) {
+ if (bands[i].s < 100) {
+ if (bands[i].v < 50) {
+ code[i] = '0';
+ } else if (bands[i].v > 200) {
+ code[i] = '9';
+ } else {
+ code[i] = '8';
+ }
+ } else {
+ if (bands[i].h < 20) {
+ if (bands[i].v > 220) {
+ code[i] = '3';
+ } else if (bands[i].v < 100) {
+ code[i] = '1';
+ } else {
+ code[i] = '2';
+ }
+ } else if (bands[i].h < 50) {
+ code[i] = '4';
+ } else if (bands[i].h < 93) {
+ code[i] = '5';
+ } else if (bands[i].h < 127) {
+ code[i] = '6';
+ } else if (bands[i].h < 161) {
+ code[i] = '7';
+ } else {
+ if (bands[i].v < 100) {
+ code[i] = '1';
+ } else {
+ code[i] = '2';
+ }
+ }
+ }
+ }
+
+#if 0
+ if (contours.size() == 3) {
+ /* Precission band not detected: gold */
+ code[3] = '4';
+ }
+#endif
+
+ /* Write bands' code into log */
+ snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
+ "Code: \"%s\"", code);
+ user_iface_log.lvl[user_iface_log.len] = 0;
+ (user_iface_log.len)++;
+
+ /* Measure time */
+ time_1 = clock();
+ times = ((double) time_1 - time_0) / CLOCKS_PER_SEC;
+ /* Write time into log */
+ snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
+ "Time5: %.3lf", times);
+ user_iface_log.lvl[user_iface_log.len] = 0;
+ (user_iface_log.len)++;
+ }
+ /* Calculate resistor value */
+ {
+ /* Measure time */
+ time_0 = clock();
+
+ /* Base value */
+ int base;
+ base = 10 * (code[0] - '0') + (code[1] - '0');
+
+ /* Check that base value is a standard value */
+ int std_values [12] = {10,12,15,18,22,27,33,39,47,56,68,82};
+ bool std_value_nok;
+ std_value_nok = true;
+ for (i = 0; i < 12; i++) {
+ if (base == std_values[i]) {
+ std_value_nok = false;
+ }
+ }
+ if (std_value_nok) {
+ status = RESISTOR_NOK_STD_VALUE;
result_label(status);
return status;
}
+ /* Calculate resistance */
+ int power;
+ power = code[2] - '0';
+ resistance = base * pow(10, power);
+
/* Measure time */
time_1 = clock();
times = ((double) time_1 - time_0) / CLOCKS_PER_SEC;
/* Write time into log */
snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Time3: %.3lf", times);
+ "Time6: %.3lf", times);
user_iface_log.lvl[user_iface_log.len] = 0;
(user_iface_log.len)++;
}
- /* Check product code in barcode */
+ /* Calculate resistor tolerance */
{
/* Measure time */
time_0 = clock();
- bool prod_nok;
- prod_nok = strncmp(zb_codes.arr[0].data, "2301703",
- strlen("2301703"));
- if (prod_nok) {
- status = LABEL_NOK_PRODUCT;
+ switch (code[3]) {
+ case '1':
+ tolerance = 1;
+ break;
+ case '2':
+ tolerance = 2;
+ break;
+ case '4':
+ tolerance = 5;
+ break;
+ case '8':
+ tolerance = 10;
+ break;
+ default:
+ status = RESISTOR_NOK_TOLERANCE;
result_label(status);
return status;
}
@@ -698,10 +894,11 @@ static int proc_resistor (void)
times = ((double) time_1 - time_0) / CLOCKS_PER_SEC;
/* Write time into log */
snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Time4: %.3lf", times);
+ "Time7: %.3lf", times);
user_iface_log.lvl[user_iface_log.len] = 0;
(user_iface_log.len)++;
}
+#if 0
/* Read price in aligned image (green component) */
{
/* Measure time */
@@ -778,12 +975,10 @@ static int proc_resistor (void)
user_iface_log.lvl[user_iface_log.len] = 0;
(user_iface_log.len)++;
}
-#else
- getchar();
#endif
status = RESISTOR_OK;
- result_label(status);
+ result_resistor(status);
return status;
}
@@ -796,33 +991,27 @@ static void result_resistor (int status)
switch (status) {
case RESISTOR_OK:
snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Label: OK");
+ "Resistor: OK");
break;
case RESISTOR_NOK_RESISTOR:
snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Label: NOK_RESISTOR");
- break;
-/*
- case RESISTOR_NOK_CERDO:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Label: NOK_CERDO");
+ "Resistor: NOK_RESISTOR");
break;
- case RESISTOR_NOK_BCODE:
+ case RESISTOR_NOK_BANDS:
snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Label: NOK_BCODE");
+ "Resistor: NOK_BANDS");
break;
- case RESISTOR_NOK_PRODUCT:
+ case RESISTOR_NOK_STD_VALUE:
snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Label: NOK_PRODUCT");
+ "Resistor: NOK_STD_VALUE");
break;
- case RESISTOR_NOK_PRICE:
+ case RESISTOR_NOK_TOLERANCE:
snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Label: NOK_PRICE");
+ "Resistor: NOK_TOLERANCE");
break;
-*/
default:
snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Label: NOK");
+ "Resistor: NOK");
break;
}
user_iface_log.lvl[user_iface_log.len] = 0;
@@ -841,6 +1030,11 @@ static void proc_load_mem (int n)
proc_show_img();
}
+static void proc_save_ref (void)
+{
+ img_iface_act(IMG_IFACE_ACT_SAVE_REF, NULL);
+}
+
static void proc_cvt_color (int method)
{
struct Img_Iface_Data_Cvt_Color data;
@@ -890,9 +1084,23 @@ static void proc_threshold (int type, int size)
proc_show_img();
}
-static void proc_invert (void)
+static void proc_not (void)
+{
+ img_iface_act(USER_IFACE_ACT_NOT, NULL);
+
+ proc_show_img();
+}
+
+static void proc_or_2ref (void)
+{
+ img_iface_act(USER_IFACE_ACT_OR_2REF, NULL);
+
+ proc_show_img();
+}
+
+static void proc_and_2ref (void)
{
- img_iface_act(USER_IFACE_ACT_INVERT, NULL);
+ img_iface_act(USER_IFACE_ACT_AND_2REF, NULL);
proc_show_img();
}
@@ -933,12 +1141,9 @@ static void proc_erode_dilate (int size)
proc_show_img();
}
-static void proc_contours (std::vector <
- std::vector <
- class cv::Point_ <int>
- >
- > *contours,
- class cv::Mat *hierarchy)
+static 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;
@@ -948,30 +1153,49 @@ static void proc_contours (std::vector <
proc_show_img();
}
-static void proc_min_area_rect (std::vector <
- class cv::Point_ <int>
- > *contour,
- class cv::RotatedRect *rect)
+static 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);
+}
+
+static 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);
- proc_show_img();
+ if (show) {
+ proc_show_img();
+ }
}
-static void proc_fit_ellipse (std::vector <
- class cv::Point_ <int>
- > *contour,
- class cv::RotatedRect *rect)
+static 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);
- proc_show_img();
+
+ if (show) {
+ proc_show_img();
+ }
}
static void proc_rotate (class cv::RotatedRect *rect)
@@ -997,6 +1221,15 @@ static void proc_ROI (int x, int y, int w, int h)
proc_show_img();
}
+static 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);
+}
+
static void proc_OCR (int lang, int conf)
{
struct Img_Iface_Data_Read data;
diff --git a/modules/user/inc/user_clui.h b/modules/user/inc/user_clui.h
index 07ff866..dffc625 100644
--- a/modules/user/inc/user_clui.h
+++ b/modules/user/inc/user_clui.h
@@ -13,6 +13,7 @@
/******************************************************************************
******* functions ************************************************************
******************************************************************************/
+void user_clui_init (void);
int user_clui (const char *title, const char *subtitle);
void user_clui_fname (const char *filepath, char *filename);
void user_clui_show_log (const char *title, const char *subtitle);
diff --git a/modules/user/inc/user_iface.h b/modules/user/inc/user_iface.h
index 09a1e96..ee9ad7c 100644
--- a/modules/user/inc/user_iface.h
+++ b/modules/user/inc/user_iface.h
@@ -38,7 +38,9 @@
USER_IFACE_ACT_FOO = 0,
USER_IFACE_ACT_CV = 0x0100,
- USER_IFACE_ACT_INVERT,
+ USER_IFACE_ACT_NOT,
+ USER_IFACE_ACT_OR_2REF,
+ USER_IFACE_ACT_AND_2REF,
USER_IFACE_ACT_CVT_COLOR,
USER_IFACE_ACT_COMPONENT,
USER_IFACE_ACT_HISTOGRAM,
diff --git a/modules/user/inc/user_iface.hpp b/modules/user/inc/user_iface.hpp
index 867a354..480cd51 100644
--- a/modules/user/inc/user_iface.hpp
+++ b/modules/user/inc/user_iface.hpp
@@ -38,7 +38,9 @@
USER_IFACE_ACT_FOO = 0,
USER_IFACE_ACT_CV = 0x0100,
- USER_IFACE_ACT_INVERT,
+ USER_IFACE_ACT_NOT,
+ USER_IFACE_ACT_OR_2REF,
+ USER_IFACE_ACT_AND_2REF,
USER_IFACE_ACT_CVT_COLOR,
USER_IFACE_ACT_COMPONENT,
USER_IFACE_ACT_HISTOGRAM,
diff --git a/modules/user/src/user_clui.c b/modules/user/src/user_clui.c
index b28fde1..28c88b2 100644
--- a/modules/user/src/user_clui.c
+++ b/modules/user/src/user_clui.c
@@ -28,6 +28,12 @@
/******************************************************************************
+ ******* static variables *****************************************************
+ ******************************************************************************/
+static int log_pos;
+
+
+/******************************************************************************
******* static functions *****************************************************
******************************************************************************/
/* Log */
@@ -41,6 +47,11 @@ static void show_help (void);
/******************************************************************************
******* main *****************************************************************
******************************************************************************/
+void user_clui_init (void)
+{
+ log_pos = 0;
+}
+
int user_clui (const char *title, const char *subtitle)
{
int action;
@@ -80,16 +91,15 @@ void user_clui_show_log (const char *title, const char *subtitle)
/* Log -----------------------------------------------------------------------*/
static void log_loop (void)
{
- static int i = 0;
int lvl;
putchar('\n');
- for (; i < user_iface_log.len; i++) {
- if (user_iface_log.lvl[i] <= user_iface_log.visible) {
- for (lvl = 0; lvl < user_iface_log.lvl[i]; lvl++) {
+ for (; log_pos < user_iface_log.len; log_pos++) {
+ if (user_iface_log.lvl[log_pos] <= user_iface_log.visible) {
+ for (lvl = 0; lvl < user_iface_log.lvl[log_pos]; lvl++) {
printf("\t");
}
- printf("%s\n", user_iface_log.line[i]);
+ printf("%s\n", user_iface_log.line[log_pos]);
}
}
putchar('\n');
@@ -151,16 +161,16 @@ static int usr_input (void)
/* img_cv */
switch (ch[2]) {
case '0':
- /* color manipulation */
+ /* bitwise manipulation */
switch (ch[3]) {
case '0':
- action = USER_IFACE_ACT_INVERT;
+ action = USER_IFACE_ACT_NOT;
break;
case '1':
- action = USER_IFACE_ACT_CVT_COLOR;
+ action = USER_IFACE_ACT_OR_2REF;
break;
case '2':
- action = USER_IFACE_ACT_COMPONENT;
+ action = USER_IFACE_ACT_AND_2REF;
break;
default:
action = USER_IFACE_ACT_FOO;
@@ -168,6 +178,20 @@ static int usr_input (void)
}
break;
case '1':
+ /* color manipulation */
+ switch (ch[3]) {
+ case '0':
+ action = USER_IFACE_ACT_CVT_COLOR;
+ break;
+ case '1':
+ action = USER_IFACE_ACT_COMPONENT;
+ break;
+ default:
+ action = USER_IFACE_ACT_FOO;
+ break;
+ }
+ break;
+ case '2':
/* grayscale filters */
switch (ch[3]) {
case '0':
@@ -193,7 +217,7 @@ static int usr_input (void)
break;
}
break;
- case '2':
+ case '3':
/* black & white filters */
switch (ch[3]) {
case '0':
@@ -213,7 +237,7 @@ static int usr_input (void)
break;
}
break;
- case '3':
+ case '4':
/* contour */
switch (ch[3]) {
case '0':
@@ -233,7 +257,7 @@ static int usr_input (void)
break;
}
break;
- case '4':
+ case '5':
/* contour */
switch (ch[3]) {
case '0':
@@ -250,7 +274,7 @@ static int usr_input (void)
break;
}
break;
- case '5':
+ case '6':
/* ROI */
switch (ch[3]) {
case '0':
@@ -371,27 +395,29 @@ static void show_help (void)
printf("Save to ref: %c\n", 'r');
printf("Save to file: %c\n", 's');
printf("Functions:\n");
- printf(" - Invert: %s\n", "f100");
- printf(" - Cvt color: %s\n", "f101");
- printf(" - Component: %s\n", "f102");
- printf(" - Histogram: %s\n", "f110");
- printf(" - Histogram c3:%s\n", "f111");
- printf(" - Smooth: %s\n", "f112");
- printf(" - Sobel: %s\n", "f113");
- printf(" - Threshold: %s\n", "f114");
- printf(" - Adaptive Thr:%s\n", "f115");
- printf(" - Dilate: %s\n", "f120");
- printf(" - Erode: %s\n", "f121");
- printf(" - D-E: %s\n", "f122");
- printf(" - E-D: %s\n", "f123");
- printf(" - Contours: %s\n", "f130");
- printf(" - Contours siz:%s\n", "f131");
- printf(" - Min. A rect.:%s\n", "f132");
- printf(" - Fit ellipse: %s\n", "f133");
- printf(" - Rotate orto.:%s\n", "f140");
- printf(" - Rotate: %s\n", "f141");
- printf(" - Rotate 2rect:%s\n", "f142");
- printf(" - Set ROI: %s\n", "f150");
+ printf(" - Bitwise NOT: %s\n", "f100");
+ printf(" - BW. OR 2ref: %s\n", "f101");
+ printf(" - BW. AND 2ref:%s\n", "f102");
+ printf(" - Cvt color: %s\n", "f110");
+ printf(" - Component: %s\n", "f111");
+ printf(" - Histogram: %s\n", "f120");
+ printf(" - Histogram c3:%s\n", "f121");
+ printf(" - Smooth: %s\n", "f122");
+ printf(" - Sobel: %s\n", "f123");
+ printf(" - Threshold: %s\n", "f124");
+ printf(" - Adaptive Thr:%s\n", "f125");
+ printf(" - Dilate: %s\n", "f130");
+ printf(" - Erode: %s\n", "f131");
+ printf(" - D-E: %s\n", "f132");
+ printf(" - E-D: %s\n", "f133");
+ printf(" - Contours: %s\n", "f140");
+ printf(" - Contours siz:%s\n", "f141");
+ printf(" - Min. A rect.:%s\n", "f142");
+ printf(" - Fit ellipse: %s\n", "f143");
+ printf(" - Rotate orto.:%s\n", "f150");
+ printf(" - Rotate: %s\n", "f151");
+ printf(" - Rotate 2rect:%s\n", "f152");
+ printf(" - Set ROI: %s\n", "f160");
printf(" - Scan codes: %s\n", "f20");
printf(" - Scan text: %s\n", "f30");
printf(" - Align: %s\n", "f40");
diff --git a/modules/user/src/user_iface.c b/modules/user/src/user_iface.c
index 8608ee3..c35d2c2 100644
--- a/modules/user/src/user_iface.c
+++ b/modules/user/src/user_iface.c
@@ -56,6 +56,7 @@ void user_iface_init (void)
switch (user_iface_mode) {
case USER_IFACE_CLUI:
+ user_clui_init();
break;
case USER_IFACE_TUI:
diff --git a/modules/user/src/user_tui.c b/modules/user/src/user_tui.c
index 041300f..b2cefd0 100644
--- a/modules/user/src/user_tui.c
+++ b/modules/user/src/user_tui.c
@@ -53,14 +53,14 @@ void user_tui_init (void)
alx_resume_curses();
/* Dimensions: log */
- const int h1 = 48;
+ const int h1 = 54;
const int w1 = 50;
const int r1 = 0;
const int c1 = 30;
win_log = newwin(h1, w1, r1, c1);
/* Dimensions: help */
- const int h2 = 48;
+ const int h2 = 54;
const int w2 = 30;
const int r2 = 0;
const int c2 = 0;
@@ -173,8 +173,8 @@ static void log_loop (void)
int l;
int l_0;
- if ((user_iface_log.len - 40) > 0) {
- i_0 = user_iface_log.len - 21;
+ if (user_iface_log.len > 51) {
+ i_0 = user_iface_log.len - 51;
l_0 = 1;
mvwprintw(win_log, 1, 10, "...");
} else {
@@ -250,18 +250,18 @@ static int usr_input (void)
switch (ch) {
case '0':
- /* color manipulation */
+ /* bitwise manipulation */
ch = wgetch(win_log);
switch (ch) {
case '0':
- action = USER_IFACE_ACT_INVERT;
+ action = USER_IFACE_ACT_NOT;
break;
case '1':
- action = USER_IFACE_ACT_CVT_COLOR;
+ action = USER_IFACE_ACT_OR_2REF;
break;
case '2':
- action = USER_IFACE_ACT_COMPONENT;
+ action = USER_IFACE_ACT_AND_2REF;
break;
default:
action = USER_IFACE_ACT_FOO;
@@ -269,6 +269,22 @@ static int usr_input (void)
}
break;
case '1':
+ /* color manipulation */
+ ch = wgetch(win_log);
+
+ switch (ch) {
+ case '0':
+ action = USER_IFACE_ACT_CVT_COLOR;
+ break;
+ case '1':
+ action = USER_IFACE_ACT_COMPONENT;
+ break;
+ default:
+ action = USER_IFACE_ACT_FOO;
+ break;
+ }
+ break;
+ case '2':
/* grayscale filters */
ch = wgetch(win_log);
@@ -296,7 +312,7 @@ static int usr_input (void)
break;
}
break;
- case '2':
+ case '3':
/* black & white filters */
ch = wgetch(win_log);
@@ -318,7 +334,7 @@ static int usr_input (void)
break;
}
break;
- case '3':
+ case '4':
/* contour */
ch = wgetch(win_log);
@@ -340,7 +356,7 @@ static int usr_input (void)
break;
}
break;
- case '4':
+ case '5':
/* rotation */
ch = wgetch(win_log);
@@ -359,7 +375,7 @@ static int usr_input (void)
break;
}
break;
- case '5':
+ case '6':
/* ROI */
ch = wgetch(win_log);
@@ -503,27 +519,29 @@ static void show_help (void)
mvwprintw(win_help, r++, c, "Save to ref: %c", 'r');
mvwprintw(win_help, r++, c, "Save to file: %c", 's');
mvwprintw(win_help, r++, c, "Functions:");
- mvwprintw(win_help, r++, c, " - Invert: %s", "f100");
- mvwprintw(win_help, r++, c, " - Cvt color: %s", "f101");
- mvwprintw(win_help, r++, c, " - Component: %s", "f102");
- mvwprintw(win_help, r++, c, " - Histogram: %s", "f110");
- mvwprintw(win_help, r++, c, " - Histogram_c3:%s", "f111");
- mvwprintw(win_help, r++, c, " - Smooth: %s", "f112");
- mvwprintw(win_help, r++, c, " - Sobel: %s", "f113");
- mvwprintw(win_help, r++, c, " - Threshold: %s", "f114");
- mvwprintw(win_help, r++, c, " - Adaptive Thr:%s", "f115");
- mvwprintw(win_help, r++, c, " - Dilate: %s", "f120");
- mvwprintw(win_help, r++, c, " - Erode: %s", "f121");
- mvwprintw(win_help, r++, c, " - D-E: %s", "f122");
- mvwprintw(win_help, r++, c, " - E-D: %s", "f123");
- mvwprintw(win_help, r++, c, " - Contours: %s", "f130");
- mvwprintw(win_help, r++, c, " - Contours siz:%s", "f131");
- mvwprintw(win_help, r++, c, " - Min. A rect.:%s", "f132");
- mvwprintw(win_help, r++, c, " - Fit ellipse: %s", "f133");
- mvwprintw(win_help, r++, c, " - Rotate orto.:%s", "f140");
- mvwprintw(win_help, r++, c, " - Rotate: %s", "f141");
- mvwprintw(win_help, r++, c, " - Rotate 2rect:%s", "f142");
- mvwprintw(win_help, r++, c, " - Set ROI: %s", "f150");
+ mvwprintw(win_help, r++, c, " - Bitwise NOT: %s", "f100");
+ mvwprintw(win_help, r++, c, " - BW. OR 2ref: %s", "f101");
+ mvwprintw(win_help, r++, c, " - BW. AND 2ref:%s", "f102");
+ mvwprintw(win_help, r++, c, " - Cvt color: %s", "f110");
+ mvwprintw(win_help, r++, c, " - Component: %s", "f111");
+ mvwprintw(win_help, r++, c, " - Histogram: %s", "f120");
+ mvwprintw(win_help, r++, c, " - Histogram_c3:%s", "f121");
+ mvwprintw(win_help, r++, c, " - Smooth: %s", "f122");
+ mvwprintw(win_help, r++, c, " - Sobel: %s", "f123");
+ mvwprintw(win_help, r++, c, " - Threshold: %s", "f124");
+ mvwprintw(win_help, r++, c, " - Adaptive Thr:%s", "f125");
+ mvwprintw(win_help, r++, c, " - Dilate: %s", "f130");
+ mvwprintw(win_help, r++, c, " - Erode: %s", "f131");
+ mvwprintw(win_help, r++, c, " - D-E: %s", "f132");
+ mvwprintw(win_help, r++, c, " - E-D: %s", "f133");
+ mvwprintw(win_help, r++, c, " - Contours: %s", "f140");
+ mvwprintw(win_help, r++, c, " - Contours siz:%s", "f141");
+ mvwprintw(win_help, r++, c, " - Min. A rect.:%s", "f142");
+ mvwprintw(win_help, r++, c, " - Fit ellipse: %s", "f143");
+ mvwprintw(win_help, r++, c, " - Rotate orto.:%s", "f150");
+ mvwprintw(win_help, r++, c, " - Rotate: %s", "f151");
+ mvwprintw(win_help, r++, c, " - Rotate 2rect:%s", "f152");
+ mvwprintw(win_help, r++, c, " - Set ROI: %s", "f160");
mvwprintw(win_help, r++, c, " - Scan codes: %s", "f20");
mvwprintw(win_help, r++, c, " - Scan text: %s", "f30");
mvwprintw(win_help, r++, c, " - Align: %s", "f40");