From 594e716b6277eff87c909f44acf62f666bb3c70b Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Thu, 22 Nov 2018 14:45:07 +0100 Subject: -Wall -Werror --- .gitmodules | 2 +- Makefile | 32 +++++++++++++++++++------------- bin/Makefile | 9 ++++----- libalx | 2 +- modules/image/src/img_ocr.c | 2 +- modules/menu/src/menu_clui.c | 4 ++-- modules/menu/src/menu_tui.c | 6 ------ modules/proc/src/proc_iface.c | 7 +++++-- modules/user/src/user_iface.c | 12 ++++++++++++ modules/user/src/user_tui.c | 1 + 10 files changed, 46 insertions(+), 31 deletions(-) diff --git a/.gitmodules b/.gitmodules index ed38291..3f28722 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "libalx"] path = libalx - url = https://github.com/AlejandroColomar/libalx + url = https://github.com/alejandro-colomar/libalx diff --git a/Makefile b/Makefile index e6b1aaa..fb18b0d 100644 --- a/Makefile +++ b/Makefile @@ -123,7 +123,9 @@ CFLAGS_STD = -std=c11 CFLAGS_OPT = -O3 CFLAGS_OPT += -march=native -CFLAGS_W = -Wno-format-truncation +CFLAGS_W = -Wall +CFLAGS_W += -Werror +CFLAGS_W += -Wno-format-truncation CFLAGS_W += -Wno-format-zero-length CFLAGS_PKG = `pkg-config --cflags ncurses` @@ -132,11 +134,11 @@ CFLAGS_PKG += `pkg-config --cflags zbar` CFLAGS_PKG += `pkg-config --cflags tesseract` CFLAGS_PKG += `pkg-config --cflags lept` -CFLAGS_D = -D 'PROG_VERSION="$(PROGRAMVERSION)"' -CFLAGS_D += -D 'INSTALL_SHARE_DIR="$(INSTALL_SHARE_DIR)"' -CFLAGS_D += -D 'SHARE_DIR="$(SHARE_DIR)"' -CFLAGS_D += -D 'INSTALL_VAR_DIR="$(INSTALL_VAR_DIR)"' -CFLAGS_D += -D 'VAR_DIR="$(VAR_DIR)"' +CFLAGS_D = -D PROG_VERSION=\"$(PROGRAMVERSION)\" +CFLAGS_D += -D INSTALL_SHARE_DIR=\"$(INSTALL_SHARE_DIR)\" +CFLAGS_D += -D SHARE_DIR=\"$(SHARE_DIR)\" +CFLAGS_D += -D INSTALL_VAR_DIR=\"$(INSTALL_VAR_DIR)\" +CFLAGS_D += -D VAR_DIR=\"$(VAR_DIR)\" CFLAGS = $(CFLAGS_STD) CFLAGS += $(CFLAGS_OPT) @@ -153,8 +155,12 @@ CXXFLAGS_STD = -std=c++17 CXXFLAGS_OPT = -O3 CXXFLAGS_OPT += -march=native -CXXFLAGS_W = -Wno-format-truncation -CXXFLAGS_W += -Wno-format-zero-length +CFLAGS_W = -Wall +CFLAGS_W += -Werror +CFLAGS_W += -Wno-format-truncation +CFLAGS_W += -Wno-format-zero-length +#CFLAGS_W += -Wno-unused-function +CFLAGS_W += -Wno-uninitialized CXXFLAGS_PKG = `pkg-config --cflags ncurses` CXXFLAGS_PKG += `pkg-config --cflags opencv` @@ -162,11 +168,11 @@ CXXFLAGS_PKG += `pkg-config --cflags zbar` CXXFLAGS_PKG += `pkg-config --cflags tesseract` CXXFLAGS_PKG += `pkg-config --cflags lept` -CXXFLAGS_D = -D 'PROG_VERSION="$(PROGRAMVERSION)"' -CXXFLAGS_D += -D 'INSTALL_SHARE_DIR="$(INSTALL_SHARE_DIR)"' -CXXFLAGS_D += -D 'SHARE_DIR="$(SHARE_DIR)"' -CXXFLAGS_D += -D 'INSTALL_VAR_DIR="$(INSTALL_VAR_DIR)"' -CXXFLAGS_D += -D 'VAR_DIR="$(VAR_DIR)"' +CXXFLAGS_D = -D PROG_VERSION=\"$(PROGRAMVERSION)\" +CXXFLAGS_D += -D INSTALL_SHARE_DIR=\"$(INSTALL_SHARE_DIR)\" +CXXFLAGS_D += -D SHARE_DIR=\"$(SHARE_DIR)\" +CXXFLAGS_D += -D INSTALL_VAR_DIR=\"$(INSTALL_VAR_DIR)\" +CXXFLAGS_D += -D VAR_DIR=\"$(VAR_DIR)\" CXXFLAGS = $(CXXFLAGS_STD) CXXFLAGS += $(CXXFLAGS_OPT) diff --git a/bin/Makefile b/bin/Makefile index 25156a9..bec1ca0 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -6,18 +6,17 @@ LIBALX_LIB_DIR = $(LIBALX_DIR)/lib/ MODULES_TMP_DIR = $(MODULES_DIR)/tmp/ -TMP_DIR = $(MAIN_DIR)/tmp/ +TMP_DIR = $(MAIN_DIR)/tmp/ # dependencies ALL = $(BIN_NAME) MAIN_OBJ_MODULES = modules.o - -MAIN_OBJS = $(TMP_DIR)/main.o \ - $(patsubst %,$(MODULES_TMP_DIR)/%,$(MAIN_OBJ_MODULES)) +MAIN_OBJS = $(TMP_DIR)/main.o \ + $(patsubst %,$(MODULES_TMP_DIR)/%,$(MAIN_OBJ_MODULES)) # static libs -MAIN_LIB_LIBALX = -L $(LIBALX_LIB_DIR) -l alx +MAIN_LIB_LIBALX = -L $(LIBALX_LIB_DIR) -l alx STATIC_LIBS = $(MAIN_LIB_LIBALX) diff --git a/libalx b/libalx index 09e8b87..8bd5d7e 160000 --- a/libalx +++ b/libalx @@ -1 +1 @@ -Subproject commit 09e8b872f29a29ac26f8233370e398b041bdf4a5 +Subproject commit 8bd5d7e5c88d5098da90b3a487a059b1ab19a0cd diff --git a/modules/image/src/img_ocr.c b/modules/image/src/img_ocr.c index 2eea9c9..a4d2e91 100644 --- a/modules/image/src/img_ocr.c +++ b/modules/image/src/img_ocr.c @@ -85,7 +85,7 @@ static void img_ocr_read (void *data) conf = data_cast->conf; switch (conf) { case IMG_IFACE_OCR_CONF_PRICE: - sprintf(conf_str, "%s/%s", share_path, "price"); + snprintf(conf_str, 6, "%s/%s", share_path, "price"); break; } diff --git a/modules/menu/src/menu_clui.c b/modules/menu/src/menu_clui.c index 0e8ea31..49c58e2 100644 --- a/modules/menu/src/menu_clui.c +++ b/modules/menu/src/menu_clui.c @@ -25,8 +25,8 @@ /****************************************************************************** ******* static functions ***************************************************** ******************************************************************************/ -static void menu_clui_rand (void); -static void menu_clui_custom (void); +//static void menu_clui_rand (void); +//static void menu_clui_custom (void); static void menu_clui_load (void); static void menu_clui_start (void); diff --git a/modules/menu/src/menu_tui.c b/modules/menu/src/menu_tui.c index 64e460a..c24ef79 100644 --- a/modules/menu/src/menu_tui.c +++ b/modules/menu/src/menu_tui.c @@ -186,15 +186,10 @@ static void menu_tui_continue (void) static void menu_tui_select (void) { /* Menu dimensions & options */ - WINDOW *win; int h; int w; - int r; - int c; h = 23; w = 80; - r = 1; - c = (80 - w) / 2; int N; N = 3; struct Alx_Menu mnu[3] = { @@ -223,7 +218,6 @@ static void menu_tui_select (void) static void menu_tui_series (void) { /* Menu dimensions & options */ - WINDOW *win; int h; int w; h = 23; diff --git a/modules/proc/src/proc_iface.c b/modules/proc/src/proc_iface.c index d6108a5..7fb988e 100644 --- a/modules/proc/src/proc_iface.c +++ b/modules/proc/src/proc_iface.c @@ -76,6 +76,8 @@ int proc_iface_single (int action) case PROC_MODE_RESISTOR: error = proc_resistor(); break; + default: + error = -1; } /* End timer */ @@ -152,8 +154,9 @@ void proc_iface_series (void) /* Save failed image into file */ proc_show_img(); snprintf(save_error_as, FILENAME_MAX, - "%s%04i_err%s", - file_basename, i, + "%s%0*i_err%s", + file_basename, + num_len, i, file_ext); save_image_file(proc_fail_path, save_error_as); diff --git a/modules/user/src/user_iface.c b/modules/user/src/user_iface.c index d196097..0dd0d85 100644 --- a/modules/user/src/user_iface.c +++ b/modules/user/src/user_iface.c @@ -101,6 +101,10 @@ void user_iface (void) case USER_IFACE_TUI: user_action = user_tui(title, subtitle); break; + + default: + user_action = USER_IFACE_ACT_FOO; + break; } /* Do action */ @@ -155,6 +159,10 @@ int64_t user_iface_getint (double m, int64_t def, double M, case USER_IFACE_TUI: i = user_tui_getint(m, def, M, title, help); break; + + default: + i = 1; + break; } return i; @@ -174,6 +182,10 @@ double user_iface_getdbl (double m, double def, double M, case USER_IFACE_TUI: i = user_tui_getdbl(m, def, M, title, help); break; + + default: + i = 1; + break; } return i; diff --git a/modules/user/src/user_tui.c b/modules/user/src/user_tui.c index e664da2..65cda48 100644 --- a/modules/user/src/user_tui.c +++ b/modules/user/src/user_tui.c @@ -82,6 +82,7 @@ void user_tui_cleanup (void) int user_tui (const char *title, const char *subtitle) { int action; + action = USER_IFACE_ACT_FOO; show_help(); user_tui_show_log(title, subtitle); -- cgit v1.2.3 From 1d22aad26085ca7294b6d25b40427f965d2fceb8 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Thu, 22 Nov 2018 14:46:44 +0100 Subject: -Wall -Werror --- modules/user/src/user_tui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/user/src/user_tui.c b/modules/user/src/user_tui.c index 65cda48..0b2ae45 100644 --- a/modules/user/src/user_tui.c +++ b/modules/user/src/user_tui.c @@ -82,7 +82,7 @@ void user_tui_cleanup (void) int user_tui (const char *title, const char *subtitle) { int action; - action = USER_IFACE_ACT_FOO; +// action = USER_IFACE_ACT_FOO; show_help(); user_tui_show_log(title, subtitle); -- cgit v1.2.3 From b2b24db96a0589d664203729ba26d3243f5d10d4 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Thu, 22 Nov 2018 15:13:19 +0100 Subject: -Wall -Werror --- Makefile | 12 ++++++------ modules/image/src/img_cv.cpp | 5 ++--- modules/image/src/img_iface.cpp | 4 +--- modules/image/src/img_orb.cpp | 2 +- modules/proc/src/proc_coins.cpp | 1 - modules/proc/src/proc_common.cpp | 2 +- modules/proc/src/proc_label.cpp | 1 - modules/proc/src/proc_resistor.cpp | 6 ++++-- modules/user/src/user_tui.c | 2 ++ 9 files changed, 17 insertions(+), 18 deletions(-) diff --git a/Makefile b/Makefile index fb18b0d..6999dbc 100644 --- a/Makefile +++ b/Makefile @@ -127,6 +127,7 @@ CFLAGS_W = -Wall CFLAGS_W += -Werror CFLAGS_W += -Wno-format-truncation CFLAGS_W += -Wno-format-zero-length +#CFLAGS_W += -Wno-unused-function CFLAGS_PKG = `pkg-config --cflags ncurses` CFLAGS_PKG += `pkg-config --cflags opencv` @@ -155,12 +156,11 @@ CXXFLAGS_STD = -std=c++17 CXXFLAGS_OPT = -O3 CXXFLAGS_OPT += -march=native -CFLAGS_W = -Wall -CFLAGS_W += -Werror -CFLAGS_W += -Wno-format-truncation -CFLAGS_W += -Wno-format-zero-length -#CFLAGS_W += -Wno-unused-function -CFLAGS_W += -Wno-uninitialized +CXXFLAGS_W = -Wall +CXXFLAGS_W += -Werror +CXXFLAGS_W += -Wno-format-truncation +CXXFLAGS_W += -Wno-format-zero-length +#CXXFLAGS_W += -Wno-unused-function CXXFLAGS_PKG = `pkg-config --cflags ncurses` CXXFLAGS_PKG += `pkg-config --cflags opencv` diff --git a/modules/image/src/img_cv.cpp b/modules/image/src/img_cv.cpp index 2359218..8e10f7d 100644 --- a/modules/image/src/img_cv.cpp +++ b/modules/image/src/img_cv.cpp @@ -543,7 +543,6 @@ static void img_cv_histogram_c3 (class cv::Mat *imgptr, void *data) /* Draw hist into hist_img */ int i; - int j; for(i = 0; i < 256; i++ ) { cv::line(*hist_img, cv::Point(3*i, hist_img->rows - 0), cv::Point(3*i, @@ -609,7 +608,7 @@ static void img_cv_contours_size (void *data) /* Get area and perimeter */ int i; - for (i = 0; i < contours->size(); i++) { + for (i = 0; i < (int)contours->size(); i++) { data_cast->area[i] = cv::contourArea( (*contours)[i], false); data_cast->perimeter[i] = cv::arcLength( @@ -771,7 +770,7 @@ static void img_cv_hough_circles (class cv::Mat *imgptr, void *data) class cv::Point_ center; int radius; int i; - for (i = 0; i < circles->size(); i++) { + for (i = 0; i < (int)circles->size(); i++) { center.x = cvRound((*circles)[i][0]); center.y = cvRound((*circles)[i][1]); radius = cvRound((*circles)[i][2]); diff --git a/modules/image/src/img_iface.cpp b/modules/image/src/img_iface.cpp index e13449a..6f901a8 100644 --- a/modules/image/src/img_iface.cpp +++ b/modules/image/src/img_iface.cpp @@ -1060,8 +1060,6 @@ static void img_iface_rotate_2rect (void *data) } /* Write into log */ - struct Img_Iface_Data_Rotate *data_cast; - data_cast = (struct Img_Iface_Data_Rotate *)data; snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Rotate to rectangle"); user_iface_log.lvl[user_iface_log.len] = 1; @@ -1346,7 +1344,7 @@ static void img_iface_contours_size (void *data) user_iface_log.lvl[user_iface_log.len] = 1; (user_iface_log.len)++; int i; - for (i = 0; i < data_cast->contours->size(); i++) { + for (i = 0; i < (int)data_cast->contours->size(); i++) { snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "cnt[%i]: A=%lf; P=%lf;", i, diff --git a/modules/image/src/img_orb.cpp b/modules/image/src/img_orb.cpp index 58d7a4e..dda46ed 100644 --- a/modules/image/src/img_orb.cpp +++ b/modules/image/src/img_orb.cpp @@ -102,7 +102,7 @@ static void img_orb_align (class cv::Mat *img_0, std::vector > points_0; std::vector > points_1; int i; - for (i = 0; i < matches.size(); i++) { + for (i = 0; i < (int)matches.size(); i++) { points_1.push_back(keypoints_1[matches[i].queryIdx].pt); points_0.push_back(keypoints_0[matches[i].trainIdx].pt); } diff --git a/modules/proc/src/proc_coins.cpp b/modules/proc/src/proc_coins.cpp index 676e214..36226ad 100644 --- a/modules/proc/src/proc_coins.cpp +++ b/modules/proc/src/proc_coins.cpp @@ -81,7 +81,6 @@ static void result_coins (int status) /* Cleanup */ /* Write result into log */ - char result [LOG_LINE_LEN]; switch (status) { case COINS_OK: snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, diff --git a/modules/proc/src/proc_common.cpp b/modules/proc/src/proc_common.cpp index 048c2d7..a4ebfeb 100644 --- a/modules/proc/src/proc_common.cpp +++ b/modules/proc/src/proc_common.cpp @@ -370,7 +370,7 @@ void clock_stop (const char *txt) /* Write time_diff into log */ snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Time: %.3lf (%s)", - txt, time_diff); + time_diff, txt); user_iface_log.lvl[user_iface_log.len] = 0; (user_iface_log.len)++; } diff --git a/modules/proc/src/proc_label.cpp b/modules/proc/src/proc_label.cpp index 765856d..a2e0783 100644 --- a/modules/proc/src/proc_label.cpp +++ b/modules/proc/src/proc_label.cpp @@ -168,7 +168,6 @@ static void result_label (int status) /* Cleanup */ /* Write result into log */ - char result [LOG_LINE_LEN]; switch (status) { case LABEL_OK: snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, diff --git a/modules/proc/src/proc_resistor.cpp b/modules/proc/src/proc_resistor.cpp index 5ee8e14..7a29a31 100644 --- a/modules/proc/src/proc_resistor.cpp +++ b/modules/proc/src/proc_resistor.cpp @@ -224,7 +224,7 @@ int proc_resistor (void) /* Write resistor value into log */ if (bands_n != 1) { snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistance: %.2E ± %i% Ohm", + "Resistance: %.2E ± %i%% Ohm", resistance, tolerance); } else { snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, @@ -265,7 +265,6 @@ static void result_resistor (int status) /* Cleanup */ /* Write result into log */ - char result [LOG_LINE_LEN]; switch (status) { case RESISTOR_OK: snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, @@ -1331,6 +1330,9 @@ static void resistor_value (void) power = -1; } else if (code[3] == 's') { power = -2; + } else { + // error + return; } resistance = base * pow(10, power); } diff --git a/modules/user/src/user_tui.c b/modules/user/src/user_tui.c index 0b2ae45..4231753 100644 --- a/modules/user/src/user_tui.c +++ b/modules/user/src/user_tui.c @@ -605,6 +605,8 @@ static int usr_input (void) break; case 'x': + action = USER_IFACE_ACT_FOO; + /* Special sequence "xyzzy" */ ch = wgetch(win_log); if (ch == 'y') { -- cgit v1.2.3 From 8446315ed369a6c5fd6d1be206dbaef6107833b0 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 22 Nov 2018 17:46:49 +0100 Subject: Resistor: bands not detected -> '?' --- modules/image/src/img_calib3d.cpp | 96 ++++++++++++++++++++++++++++++++++++++ modules/image/src/img_cv.cpp | 4 ++ modules/image/src/img_iface.cpp | 4 ++ modules/proc/src/proc_resistor.cpp | 40 ++++++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 modules/image/src/img_calib3d.cpp diff --git a/modules/image/src/img_calib3d.cpp b/modules/image/src/img_calib3d.cpp new file mode 100644 index 0000000..26cfc39 --- /dev/null +++ b/modules/image/src/img_calib3d.cpp @@ -0,0 +1,96 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C++ --------------------------------------------------------------*/ + /* std::vector */ + #include + +/* Standard C ----------------------------------------------------------------*/ + /* snprintf() */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* opencv */ + #include + #include + +/* Module -------------------------------------------------------------------*/ + #include "img_calib3d.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void img_calib3d_calibrate (class cv::Mat *imgptr, void *data); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void img_calib3d_act (class cv::Mat *imgptr, int action, void *data) +{ + switch (action) { + case IMG_CALIB3D_ACT_CALIBRATE: + img_calib3d_calibrate(imgptr, data); + break; + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void img_calib3d_calibrate (class cv::Mat *imgptr, void *data) +{ + const class cv::Size pattern_size(8, 6); + + class cv::Mat corners; + bool found; + + found = cv::findChessboardCorners(*imgptr, pattern_size, corners); + + int i; + int j; + + // Object points + std::vector > object_points; + for (i = 0; i < pattern_size.height; i++) { + for (j = 0; j < pattern_size.width; j++) { + object_points.at(0).push_back(Vec3f(i, j, 0)); + } + } + + // Image points + std::vector > image_points; + int num; + for (i = 0; i < pattern_size.height; i++) { + for (j = 0; j < pattern_size.width; j++) { + image_points.at(0).push_back(corners.at(num, 0)); + } + } + + class cv::Mat camera_matrix; + class cv::Mat dist_matrix; + class cv::Mat rvecs; + class cv::Mat tvecs; + + cv::calibrateCamera(object_points, image_points, + cv::Size(imgptr->size().width, + imgptr->size().height) + camera_matrix, dist_matrix, rvecs, tvecs); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/src/img_cv.cpp b/modules/image/src/img_cv.cpp index 8e10f7d..4f095e8 100644 --- a/modules/image/src/img_cv.cpp +++ b/modules/image/src/img_cv.cpp @@ -6,6 +6,10 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ +/* Standard C++ --------------------------------------------------------------*/ + /* std::vector */ + #include + /* Standard C ----------------------------------------------------------------*/ /* fabs */ #include diff --git a/modules/image/src/img_iface.cpp b/modules/image/src/img_iface.cpp index 6f901a8..60d7aa2 100644 --- a/modules/image/src/img_iface.cpp +++ b/modules/image/src/img_iface.cpp @@ -6,6 +6,10 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ +/* Standard C++ --------------------------------------------------------------*/ + /* std::vector */ + #include + /* Standard C ----------------------------------------------------------------*/ /* errno */ #include diff --git a/modules/proc/src/proc_resistor.cpp b/modules/proc/src/proc_resistor.cpp index 7a29a31..cd02eb7 100644 --- a/modules/proc/src/proc_resistor.cpp +++ b/modules/proc/src/proc_resistor.cpp @@ -84,6 +84,7 @@ static void bands_code (void); static char band_hsv2code (struct Resistor_Bands *band); static void bands_code_deduce_0 (void); static void bands_code_deduce_1 (void); +static void bands_code_deduce_no (void); static void resistor_value (void); static int resistor_tolerance (void); static int chk_std_value (void); @@ -190,6 +191,7 @@ int proc_resistor (void) bands_code(); bands_code_deduce_0(); bands_code_deduce_1(); + bands_code_deduce_no(); int i; for (i = 0; i < 5; i++) { switch (code[i]) { @@ -1117,12 +1119,14 @@ static void bands_code_deduce_1 (void) { /* * Not able to segmentate: + * q = 1 2 * w = 2 3 * e = 3 g * r = 3 4 * t = 1 8 * y = 0 1 + * u = 0 1 8 */ @@ -1311,6 +1315,42 @@ static void bands_code_deduce_1 (void) (user_iface_log.len)++; } +static void bands_code_deduce_no (void) +{ + /* + * Not able to segmentate: + * q = 1 2 + * w = 2 3 + * e = 3 g + * r = 3 4 + * t = 1 8 + * y = 0 1 + * u = 0 1 8 + */ + + /* Band 0 (hundreds) */ + for (i = 0; i < 5; i++9 { + switch (code[i]) { + case 'q': + case 'w': + case 'e': + case 'r': + case 't': + case 'y': + case 'u': + code[i] = '?'; + break; + } + } + + /* 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)++; +} + static void resistor_value (void) { /* Base value */ -- cgit v1.2.3 From 8a5604773ac4be92f459e394170b7b38bbd91ed0 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Wed, 28 Nov 2018 18:13:38 +0100 Subject: proc: coins --- modules/proc/src/proc_coins.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/modules/proc/src/proc_coins.cpp b/modules/proc/src/proc_coins.cpp index 36226ad..93ece3a 100644 --- a/modules/proc/src/proc_coins.cpp +++ b/modules/proc/src/proc_coins.cpp @@ -66,6 +66,20 @@ int proc_coins (void) /* Measure time */ clock_stop("Find coins"); } + /* Calibrate with the biggest coin; every img should have a 2 € coin */ + { + /* Measure time */ + clock_start(); + + status = coins_find(); + if (status) { + result_coins(status); + return status; + } + + /* Measure time */ + clock_stop("Find coins"); + } status = COINS_OK; result_coins(status); -- cgit v1.2.3 From cb4a36765096a7a9c1f7f4e5ee8d0a0ff8691d6a Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Wed, 28 Nov 2018 23:09:07 +0100 Subject: finish proc_coins; fix bugs in proc_resistors; --- bin/Makefile | 12 +- modules/image/src/img_alx.cpp | 6 +- modules/proc/inc/proc_coins.h | 3 +- modules/proc/inc/proc_coins.hpp | 3 +- modules/proc/src/proc_coins.cpp | 252 +++++++++++++++++++++++++++++++++++-- modules/proc/src/proc_resistor.cpp | 12 +- modules/proc/tmp/Makefile | 9 +- 7 files changed, 265 insertions(+), 32 deletions(-) diff --git a/bin/Makefile b/bin/Makefile index bec1ca0..300f428 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -15,10 +15,14 @@ MAIN_OBJ_MODULES = modules.o MAIN_OBJS = $(TMP_DIR)/main.o \ $(patsubst %,$(MODULES_TMP_DIR)/%,$(MAIN_OBJ_MODULES)) +MAIN_LIB_LIBALX = libalx.a +MAIN_LIBS = \ + $(patsubst %,$(LIBALX_LIB_DIR)/%,$(MAIN_LIB_LIBALX)) + # static libs -MAIN_LIB_LIBALX = -L $(LIBALX_LIB_DIR) -l alx +STATIC_LIB_LIBALX = -L $(LIBALX_LIB_DIR) -l alx -STATIC_LIBS = $(MAIN_LIB_LIBALX) +STATIC_LIBS = $(STATIC_LIB_LIBALX) # target: dependencies @@ -27,8 +31,8 @@ STATIC_LIBS = $(MAIN_LIB_LIBALX) all: $(ALL) -$(BIN_NAME): $(MAIN_OBJS) - $(Q)$(CXX) $^ -o $@ $(STATIC_LIBS) $(LIBS) +$(BIN_NAME): $(MAIN_OBJS) $(MAIN_LIBS) + $(Q)$(CXX) $(MAIN_OBJS) -o $@ $(STATIC_LIBS) $(LIBS) @echo " CXX $@" @echo "" diff --git a/modules/image/src/img_alx.cpp b/modules/image/src/img_alx.cpp index f1f0b93..881c178 100644 --- a/modules/image/src/img_alx.cpp +++ b/modules/image/src/img_alx.cpp @@ -17,7 +17,7 @@ #include /* libalx --------------------------------------------------------------------*/ - /* alx_median_uint8() */ + /* alx_median_u8() */ #include "alx_math.hpp" /* Module --------------------------------------------------------------------*/ @@ -259,7 +259,7 @@ static void img_alx_median_horizontal (class cv::Mat *imgptr) img_pix = imgptr->data + i * imgptr->step + j; row[j] = *img_pix; } - median = alx_median_uint8(imgptr->cols, row); + median = alx_median_u8(imgptr->cols, row); for (j = 0; j < imgptr->cols; j++) { img_pix = imgptr->data + i * imgptr->step + j; @@ -283,7 +283,7 @@ static void img_alx_median_vertical (class cv::Mat *imgptr) img_pix = imgptr->data + j * imgptr->step + i; col[j] = *img_pix; } - median = alx_median_uint8(imgptr->rows, col); + median = alx_median_u8(imgptr->rows, col); for (j = 0; j < imgptr->rows; j++) { img_pix = imgptr->data + j * imgptr->step + i; diff --git a/modules/proc/inc/proc_coins.h b/modules/proc/inc/proc_coins.h index 68d15a2..211971c 100644 --- a/modules/proc/inc/proc_coins.h +++ b/modules/proc/inc/proc_coins.h @@ -21,7 +21,8 @@ enum Proc_Coins { COINS_OK, COINS_NOK_COINS, - COINS_NOK_OVERLAP + COINS_NOK_OVERLAP, + COINS_NOK_SIZE }; diff --git a/modules/proc/inc/proc_coins.hpp b/modules/proc/inc/proc_coins.hpp index 6dbf7b7..5b64870 100644 --- a/modules/proc/inc/proc_coins.hpp +++ b/modules/proc/inc/proc_coins.hpp @@ -21,7 +21,8 @@ enum Proc_Coins { COINS_OK, COINS_NOK_COINS, - COINS_NOK_OVERLAP + COINS_NOK_OVERLAP, + COINS_NOK_SIZE }; diff --git a/modules/proc/src/proc_coins.cpp b/modules/proc/src/proc_coins.cpp index 93ece3a..ef13ef0 100644 --- a/modules/proc/src/proc_coins.cpp +++ b/modules/proc/src/proc_coins.cpp @@ -14,6 +14,10 @@ /* openCV */ #include +/* libalx ------------------------------------------------------------------*/ + /* alx_maximum_u8() */ + #include "alx_math.hpp" + /* Project -------------------------------------------------------------------*/ /* constants */ #include "img_iface.hpp" @@ -26,6 +30,27 @@ #include "proc_coins.hpp" +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define COINS_MAX 1024 + + +/****************************************************************************** + ******* structs ************************************************************** + ******************************************************************************/ +struct Coins_Properties { + /* position */ + int x; + int y; + + /* value */ + uint8_t diameter_pix; + double diameter_mm; + double value; +}; + + /****************************************************************************** ******* variables ************************************************************ ******************************************************************************/ @@ -34,6 +59,11 @@ /* Static --------------------------------------------------------------------*/ static std::vector >> contours; static class cv::Mat hierarchy; +static class cv::Rect_ rectangle [COINS_MAX]; +static int coins_n; +static struct Coins_Properties coins [COINS_MAX]; +static double ratio_mm_per_pix; +static double value_total; /****************************************************************************** @@ -41,7 +71,14 @@ static class cv::Mat hierarchy; ******************************************************************************/ static void result_coins (int status); -static int coins_find (void); +static void coins_segmentate (void); +static int coins_positions (void); +static void coins_diameters_pix (void); +static void calibrate_mm_per_pix (void); +static void coins_diameters_mm (void); +static int coins_values (void); +static double coin_value (double diameter_mm); +static void coins_total_value (void); /****************************************************************************** @@ -52,33 +89,83 @@ int proc_coins (void) int status; proc_save_mem(0); - /* Find coins */ + /* Segmentate coins */ + { + /* Measure time */ + clock_start(); + + coins_segmentate(); + + /* Measure time */ + clock_stop("Segmentate coins"); + } + /* Find coins positions */ { /* Measure time */ clock_start(); - status = coins_find(); + status = coins_positions(); if (status) { result_coins(status); return status; } /* Measure time */ - clock_stop("Find coins"); + clock_stop("Find coins positions"); + } + /* Get coin diameters in pixels */ + { + /* Measure time */ + clock_start(); + + coins_diameters_pix(); + + /* Measure time */ + clock_stop("Coins diameters in pixels"); } /* Calibrate with the biggest coin; every img should have a 2 € coin */ { /* Measure time */ clock_start(); - status = coins_find(); + calibrate_mm_per_pix(); + + /* Measure time */ + clock_stop("Calibrate (mm per pix)"); + } + /* Get coins diameters in mm */ + { + /* Measure time */ + clock_start(); + + coins_diameters_mm(); + + /* Measure time */ + clock_stop("Coins diameters in mm"); + } + /* Get coins values (by their sizes) */ + { + /* Measure time */ + clock_start(); + + status = coins_values(); if (status) { result_coins(status); return status; } /* Measure time */ - clock_stop("Find coins"); + clock_stop("Coins values"); + } + /* Add total value */ + { + /* Measure time */ + clock_start(); + + coins_total_value(); + + /* Measure time */ + clock_stop("Total value"); } status = COINS_OK; @@ -104,10 +191,16 @@ static void result_coins (int status) snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Coin: NOK_COINS"); break; +#if 0 case COINS_NOK_OVERLAP: snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Coin: NOK_OVERLAP"); break; +#endif + case COINS_NOK_SIZE: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK_SIZE"); + break; default: snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Coin: NOK"); @@ -117,10 +210,8 @@ static void result_coins (int status) (user_iface_log.len)++; } -static int coins_find (void) +static void coins_segmentate (void) { - int status; - proc_load_mem(0); proc_cmp(IMG_IFACE_CMP_BLUE); @@ -129,21 +220,160 @@ static int coins_find (void) // proc_threshold(cv::THRESH_BINARY_INV, 100); proc_distance_transform(); proc_local_max(); - proc_dilate(8); + proc_dilate(6); proc_save_mem(1); +} + +static int coins_positions (void) +{ + int status; + + proc_load_mem(1); proc_contours(&contours, &hierarchy); + coins_n = contours.size(); /* If no contour is found, error: NOK_COINS */ - if (!contours.size()) { + if (!coins_n) { status = COINS_NOK_COINS; return status; } + /* Get position of each contour */ + int i; + for (i = 0; i < coins_n; i++) { + proc_bounding_rect(&(contours[i]), &(rectangle[i]), true); + coins[i].x = rectangle[i].x + rectangle[i].width / 2.0; + coins[i].y = rectangle[i].y + rectangle[i].height / 2.0; + } + + status = COINS_OK; + return status; +} + +static void coins_diameters_pix (void) +{ + proc_load_mem(1); + + /* Get coins diameters in pixels */ + int i; + for (i = 0; i < coins_n; i++) { + proc_pixel_value(coins[i].x, coins[i].y, + &(coins[i].diameter_pix)); + coins[i].diameter_pix *= 2; + } +} + +static void calibrate_mm_per_pix (void) +{ + uint8_t coins_size_pix [coins_n]; + + int i; + for (i = 0; i < coins_n; i++) { + coins_size_pix[i] = coins[i].diameter_pix; + } + + int max_pos; + int max_size; + max_pos = alx_maximum_u8(coins_n, coins_size_pix); + max_size = coins_size_pix[max_pos]; + ratio_mm_per_pix = 25.75 / max_size; +} + +static void coins_diameters_mm (void) +{ + /* Get coins diameters in mm */ + int i; + for (i = 0; i < coins_n; i++) { + coins[i].diameter_mm = ratio_mm_per_pix * + coins[i].diameter_pix; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin[%i]: %.2lf mm", + i, + coins[i].diameter_mm); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + } +} + +static int coins_values (void) +{ + int status; + + /* Get coins values in € (EUR) */ + int i; + for (i = 0; i < coins_n; i++) { + coins[i].value = coin_value(coins[i].diameter_mm); + + /* If a coin is of invalid size, error: NOK_SIZE */ + if (coins[i].value < 0) { + status = COINS_NOK_SIZE; + return status; + } + + /* Write values into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin[%i]: %.2lf EUR", + i, + coins[i].value); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + } + status = COINS_OK; return status; } +static double coin_value (double diameter_mm) +{ + double value; + + /* Get coin value by its diameter in mm */ + if (diameter_mm > 30.00) { + value = -1; + } else if (diameter_mm > 25.00) { + value = 2.00; + } else if (diameter_mm > 23.75) { + value = 0.50; + } else if (diameter_mm > 22.75) { + value = 1.00; + } else if (diameter_mm > 21.75) { + value = 0.20; + } else if (diameter_mm > 20.50) { + value = 0.05; + } else if (diameter_mm > 19.25) { + value = 0.10; + } else if (diameter_mm > 17.50) { + value = 0.02; + } else if (diameter_mm > 10.00) { + value = 0.01; + } else { + value = -1; + } + + return value; +} + +static void coins_total_value (void) +{ + value_total = 0.00; + + /* Get total value in € (EUR) */ + int i; + for (i = 0; i < coins_n; i++) { + value_total += coins[i].value; + } + + /* Write total value into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Total value: %.2lf €", + value_total); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + /****************************************************************************** ******* end of file ********************************************************** diff --git a/modules/proc/src/proc_resistor.cpp b/modules/proc/src/proc_resistor.cpp index cd02eb7..560b3a4 100644 --- a/modules/proc/src/proc_resistor.cpp +++ b/modules/proc/src/proc_resistor.cpp @@ -194,14 +194,7 @@ int proc_resistor (void) bands_code_deduce_no(); int i; for (i = 0; i < 5; i++) { - switch (code[i]) { - case 'q': - case 'w': - case 'e': - case 'r': - case 't': - case 'y': - case 'u': + if (code[i] == '?') { status = RESISTOR_NOK_COLOR; result_resistor(status); return status; @@ -1329,7 +1322,8 @@ static void bands_code_deduce_no (void) */ /* Band 0 (hundreds) */ - for (i = 0; i < 5; i++9 { + int i; + for (i = 0; i < 5; i++) { switch (code[i]) { case 'q': case 'w': diff --git a/modules/proc/tmp/Makefile b/modules/proc/tmp/Makefile index fa5c159..420b8dd 100644 --- a/modules/proc/tmp/Makefile +++ b/modules/proc/tmp/Makefile @@ -29,16 +29,19 @@ PROC_LAB_INC_DIRS = -I $(INC_DIR) \ -I $(IMG_INC_DIR) \ -I $(USR_INC_DIR) +PROC_COIN_INC_LIBALX = alx_math.hpp PROC_COIN_INC_IMG = img_iface.hpp PROC_COIN_INC_USR = user_iface.hpp PROC_COIN_INC = proc_coins.hpp proc_common.hpp PROC_COIN_DEPS = $(SRC_DIR)/proc_coins.cpp \ $(patsubst %,$(INC_DIR)/%,$(PROC_COIN_INC)) \ $(patsubst %,$(IMG_INC_DIR)/%,$(PROC_COIN_INC_IMG)) \ - $(patsubst %,$(USR_INC_DIR)/%,$(PROC_COIN_INC_USR)) + $(patsubst %,$(USR_INC_DIR)/%,$(PROC_COIN_INC_USR)) \ + $(patsubst %,$(LIBALX_INC_DIR)/%,$(PROC_COIN_INC_LIBALX)) PROC_COIN_INC_DIRS = -I $(INC_DIR) \ -I $(IMG_INC_DIR) \ - -I $(USR_INC_DIR) + -I $(USR_INC_DIR) \ + -I $(LIBALX_INC_DIR) PROC_RES_INC_IMG = img_iface.hpp PROC_RES_INC_USR = user_iface.hpp @@ -62,8 +65,8 @@ PROC_CMN_INC_DIRS = -I $(INC_DIR) \ -I $(IMG_INC_DIR) \ -I $(USR_INC_DIR) -PROC_IFACE_INC_IMG = img_iface.h PROC_IFACE_INC_LIBALX = alx_input.h +PROC_IFACE_INC_IMG = img_iface.h PROC_IFACE_INC_SAVE = save.h PROC_IFACE_INC_USR = user_iface.h PROC_IFACE_INC = proc_iface.h proc_label.h proc_coins.h proc_resistor.h -- cgit v1.2.3 From 7abb15e01179733ccbf4cd88706c23542878933a Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 29 Nov 2018 15:04:43 +0100 Subject: Fix minor bugs --- modules/proc/src/proc_resistor.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/proc/src/proc_resistor.cpp b/modules/proc/src/proc_resistor.cpp index cd02eb7..b62d180 100644 --- a/modules/proc/src/proc_resistor.cpp +++ b/modules/proc/src/proc_resistor.cpp @@ -1329,7 +1329,8 @@ static void bands_code_deduce_no (void) */ /* Band 0 (hundreds) */ - for (i = 0; i < 5; i++9 { + int i; + for (i = 0; i < 5; i++) { switch (code[i]) { case 'q': case 'w': -- cgit v1.2.3 From 1533005693767874974a91fdb1afc361d94505f1 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 29 Nov 2018 15:05:35 +0100 Subject: Fix minor bugs --- modules/proc/src/proc_resistor.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/proc/src/proc_resistor.cpp b/modules/proc/src/proc_resistor.cpp index 560b3a4..1cead11 100644 --- a/modules/proc/src/proc_resistor.cpp +++ b/modules/proc/src/proc_resistor.cpp @@ -1321,7 +1321,6 @@ static void bands_code_deduce_no (void) * u = 0 1 8 */ - /* Band 0 (hundreds) */ int i; for (i = 0; i < 5; i++) { switch (code[i]) { -- cgit v1.2.3 From 5b48167344fec54a276751ee7687d9a5f68ae6c5 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 29 Nov 2018 17:33:35 +0100 Subject: Minor changes to proc_coins --- libalx | 2 +- modules/proc/src/proc_coins.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libalx b/libalx index 8bd5d7e..464bca2 160000 --- a/libalx +++ b/libalx @@ -1 +1 @@ -Subproject commit 8bd5d7e5c88d5098da90b3a487a059b1ab19a0cd +Subproject commit 464bca2b23db1d4aed73549b9a1a04054341709e diff --git a/modules/proc/src/proc_coins.cpp b/modules/proc/src/proc_coins.cpp index ef13ef0..61b7612 100644 --- a/modules/proc/src/proc_coins.cpp +++ b/modules/proc/src/proc_coins.cpp @@ -331,7 +331,7 @@ static double coin_value (double diameter_mm) double value; /* Get coin value by its diameter in mm */ - if (diameter_mm > 30.00) { + if (diameter_mm > 27.00) { value = -1; } else if (diameter_mm > 25.00) { value = 2.00; @@ -347,7 +347,7 @@ static double coin_value (double diameter_mm) value = 0.10; } else if (diameter_mm > 17.50) { value = 0.02; - } else if (diameter_mm > 10.00) { + } else if (diameter_mm > 15.00) { value = 0.01; } else { value = -1; @@ -368,7 +368,7 @@ static void coins_total_value (void) /* Write total value into log */ snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Total value: %.2lf €", + "Total value: %.2lf EUR", value_total); user_iface_log.lvl[user_iface_log.len] = 0; (user_iface_log.len)++; -- cgit v1.2.3 From e2f22be0b8403ab9667016e8952bbfee0341cc68 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Fri, 30 Nov 2018 22:44:33 +0100 Subject: Minor changes to makefile --- Makefile | 77 +++++++++++++++++++++++++++++++++++----------------------------- libalx | 2 +- 2 files changed, 43 insertions(+), 36 deletions(-) diff --git a/Makefile b/Makefile index 6999dbc..6ee04ea 100644 --- a/Makefile +++ b/Makefile @@ -69,51 +69,18 @@ MAKEFLAGS += --no-print-directory PROGRAMVERSION = $(VERSION)$(if $(PATCHLEVEL),$(PATCHLEVEL)$(if $(SUBLEVEL),$(SUBLEVEL)))$(EXTRAVERSION) export PROGRAMVERSION -################################################################################ -# directories - -MAIN_DIR = $(CURDIR) - -LIBALX_DIR = $(CURDIR)/libalx/ -MODULES_DIR = $(CURDIR)/modules/ -TMP_DIR = $(CURDIR)/tmp/ -BIN_DIR = $(CURDIR)/bin/ - -export MAIN_DIR -export LIBALX_DIR -export MODULES_DIR - -# FIXME: Set local or not local when building a package -INSTALL_BIN_DIR = /usr/local/bin/ -#INSTALL_BIN_DIR = /usr/bin/ -INSTALL_SHARE_DIR = /usr/local/share/ -#INSTALL_SHARE_DIR = /usr/share/ -SHARE_DIR = vision-artificial/ -INSTALL_VAR_DIR = /var/local/ -#INSTALL_VAR_DIR = /var/lib/ -VAR_DIR = vision-artificial/ - -export INSTALL_DIR -export INSTALL_SHARE_DIR -export SHARE_DIR - -################################################################################ -# executables - -BIN_NAME = vision-artificial2 - -export BIN_NAME - ################################################################################ # Make variables (CC, etc...) CC = gcc CXX = g++ AS = as + AR = ar LD = ld export CC export CXX export AS +export AR export LD ################################################################################ @@ -124,10 +91,13 @@ CFLAGS_OPT = -O3 CFLAGS_OPT += -march=native CFLAGS_W = -Wall +CFLAGS_W += -Wextra +CFLAGS_W += -Wstrict-prototypes CFLAGS_W += -Werror CFLAGS_W += -Wno-format-truncation CFLAGS_W += -Wno-format-zero-length #CFLAGS_W += -Wno-unused-function +CFLAGS_W += -Wno-unused-parameter CFLAGS_PKG = `pkg-config --cflags ncurses` CFLAGS_PKG += `pkg-config --cflags opencv` @@ -157,10 +127,12 @@ CXXFLAGS_OPT = -O3 CXXFLAGS_OPT += -march=native CXXFLAGS_W = -Wall +CXXFLAGS_W += -Wextra CXXFLAGS_W += -Werror CXXFLAGS_W += -Wno-format-truncation CXXFLAGS_W += -Wno-format-zero-length #CXXFLAGS_W += -Wno-unused-function +CXXFLAGS_W += -Wno-unused-parameter CXXFLAGS_PKG = `pkg-config --cflags ncurses` CXXFLAGS_PKG += `pkg-config --cflags opencv` @@ -194,6 +166,41 @@ LIBS = $(LIBS_PKG) export LIBS +################################################################################ +# directories + +MAIN_DIR = $(CURDIR) + +LIBALX_DIR = $(CURDIR)/libalx/ +MODULES_DIR = $(CURDIR)/modules/ +TMP_DIR = $(CURDIR)/tmp/ +BIN_DIR = $(CURDIR)/bin/ + +export MAIN_DIR +export LIBALX_DIR +export MODULES_DIR + +# FIXME: Set local or not local when building a package +INSTALL_BIN_DIR = /usr/local/bin/ +#INSTALL_BIN_DIR = /usr/bin/ +INSTALL_SHARE_DIR = /usr/local/share/ +#INSTALL_SHARE_DIR = /usr/share/ +SHARE_DIR = vision-artificial/ +INSTALL_VAR_DIR = /var/local/ +#INSTALL_VAR_DIR = /var/lib/ +VAR_DIR = vision-artificial/ + +export INSTALL_DIR +export INSTALL_SHARE_DIR +export SHARE_DIR + +################################################################################ +# executables + +BIN_NAME = vision-artificial2 + +export BIN_NAME + ################################################################################ # target: dependencies # action diff --git a/libalx b/libalx index 8bd5d7e..8b81fe9 160000 --- a/libalx +++ b/libalx @@ -1 +1 @@ -Subproject commit 8bd5d7e5c88d5098da90b3a487a059b1ab19a0cd +Subproject commit 8b81fe9c7060be7b6a99817200254bc0b7d1518c -- cgit v1.2.3 From 92b86ae2770341bc58232f11ad7ae60cb7cce078 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Fri, 30 Nov 2018 22:53:06 +0100 Subject: Minor changes to proc_resistor --- modules/proc/src/proc_resistor.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/modules/proc/src/proc_resistor.cpp b/modules/proc/src/proc_resistor.cpp index 1cead11..5a3a7ba 100644 --- a/modules/proc/src/proc_resistor.cpp +++ b/modules/proc/src/proc_resistor.cpp @@ -84,7 +84,7 @@ static void bands_code (void); static char band_hsv2code (struct Resistor_Bands *band); static void bands_code_deduce_0 (void); static void bands_code_deduce_1 (void); -static void bands_code_deduce_no (void); +static int bands_code_deduce_no (void); static void resistor_value (void); static int resistor_tolerance (void); static int chk_std_value (void); @@ -191,14 +191,10 @@ int proc_resistor (void) bands_code(); bands_code_deduce_0(); bands_code_deduce_1(); - bands_code_deduce_no(); - int i; - for (i = 0; i < 5; i++) { - if (code[i] == '?') { - status = RESISTOR_NOK_COLOR; - result_resistor(status); - return status; - } + status = bands_code_deduce_no(); + if (status) { + result_resistor(status); + return status; } /* Measure time */ @@ -1308,8 +1304,9 @@ static void bands_code_deduce_1 (void) (user_iface_log.len)++; } -static void bands_code_deduce_no (void) +static int bands_code_deduce_no (void) { + int status; /* * Not able to segmentate: * q = 1 2 @@ -1336,12 +1333,22 @@ static void bands_code_deduce_no (void) } } + for (i = 0; i < 5; i++) { + if (code[i] == '?') { + status = RESISTOR_NOK_COLOR; + return status; + } + } + /* 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)++; + + status = RESISTOR_OK; + return status; } static void resistor_value (void) -- cgit v1.2.3 From 307d3c59fa2a24835ee7caeeceaae1659d551d28 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Mon, 3 Dec 2018 22:30:14 +0100 Subject: Minor changes --- Makefile | 34 ++++++++++++++++++++++------------ bin/Makefile | 4 ++-- libalx | 2 +- modules/Makefile | 27 ++++++++++++++++++--------- modules/about/tmp/Makefile | 1 - modules/ctrl/tmp/Makefile | 1 - modules/image/tmp/Makefile | 1 - modules/menu/tmp/Makefile | 1 - modules/proc/tmp/Makefile | 1 - modules/save/tmp/Makefile | 1 - modules/tmp/Makefile | 1 - modules/user/tmp/Makefile | 1 - 12 files changed, 43 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index 6ee04ea..368e50f 100644 --- a/Makefile +++ b/Makefile @@ -212,31 +212,37 @@ all: binary PHONY += libalx libalx: - $(Q)cd $(LIBALX_DIR) && $(MAKE) && cd .. + @echo ' MAKE libalx-base' + $(Q)make base -C $(LIBALX_DIR) + @echo ' MAKE libalx-curses' + $(Q)make curses -C $(LIBALX_DIR) PHONY += modules modules: libalx - $(Q)cd $(MODULES_DIR) && $(MAKE) && cd .. + @echo ' MAKE modules' + $(Q)make -C $(MODULES_DIR) PHONY += object object: modules libalx - $(Q)cd $(TMP_DIR) && $(MAKE) && cd .. + @echo ' MAKE objects' + $(Q)make -C $(TMP_DIR) PHONY += binary binary: object - $(Q)cd $(BIN_DIR) && $(MAKE) && cd .. + @echo ' MAKE binary' + $(Q)make -C $(BIN_DIR) PHONY += install install: uninstall - @echo "Create $(INSTALL_BIN_DIR)/" + @echo " MKDIR -p $(INSTALL_BIN_DIR)/" $(Q)mkdir -p $(DESTDIR)/$(INSTALL_BIN_DIR)/ @echo "Copy $(BIN_NAME)" $(Q)cp $(BIN_DIR)/$(BIN_NAME) $(DESTDIR)/$(INSTALL_BIN_DIR)/ @echo "" - @echo "Create $(INSTALL_SHARE_DIR)/$(SHARE_DIR)/" + @echo " MKDIR -p $(INSTALL_SHARE_DIR)/$(SHARE_DIR)/" $(Q)mkdir -p $(DESTDIR)/$(INSTALL_SHARE_DIR)/$(SHARE_DIR)/ - @echo "Copy share/*" + @echo " CP -r share/*" $(Q)cp -r ./share/* $(DESTDIR)/$(INSTALL_SHARE_DIR)/$(SHARE_DIR)/ @echo "" @@ -245,17 +251,21 @@ install: uninstall PHONY += uninstall uninstall: + @echo "Clean old installations" $(Q)rm -f $(DESTDIR)/$(INSTALL_BIN_DIR)/$(BIN_NAME) $(Q)rm -f -r $(DESTDIR)/$(INSTALL_SHARE_DIR)/$(SHARE_DIR)/ - @echo "Clean old installations" @echo "" PHONY += clean clean: - $(Q)cd $(LIBALX_DIR) && $(MAKE) clean && cd .. - $(Q)cd $(MODULES_DIR) && $(MAKE) clean && cd .. - $(Q)cd $(TMP_DIR) && $(MAKE) clean && cd .. - $(Q)cd $(BIN_DIR) && $(MAKE) clean && cd .. + @echo ' CLEAN libalx' + $(Q)make clean -C $(LIBALX_DIR) + @echo ' CLEAN modules' + $(Q)make clean -C $(MODULES_DIR) + @echo ' CLEAN tmp' + $(Q)make clean -C $(TMP_DIR) + @echo ' CLEAN bin' + $(Q)make clean -C $(BIN_DIR) PHONY += help help: diff --git a/bin/Makefile b/bin/Makefile index 300f428..7d1ccf4 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -15,12 +15,12 @@ MAIN_OBJ_MODULES = modules.o MAIN_OBJS = $(TMP_DIR)/main.o \ $(patsubst %,$(MODULES_TMP_DIR)/%,$(MAIN_OBJ_MODULES)) -MAIN_LIB_LIBALX = libalx.a +MAIN_LIB_LIBALX = libalx-base.a libalx-curses.a MAIN_LIBS = \ $(patsubst %,$(LIBALX_LIB_DIR)/%,$(MAIN_LIB_LIBALX)) # static libs -STATIC_LIB_LIBALX = -L $(LIBALX_LIB_DIR) -l alx +STATIC_LIB_LIBALX = -L $(LIBALX_LIB_DIR) -l alx-curses -l alx-base STATIC_LIBS = $(STATIC_LIB_LIBALX) diff --git a/libalx b/libalx index 8b81fe9..cdb8455 160000 --- a/libalx +++ b/libalx @@ -1 +1 @@ -Subproject commit 8b81fe9c7060be7b6a99817200254bc0b7d1518c +Subproject commit cdb845529db48059564a0e44fb174f1d2e4f3023 diff --git a/modules/Makefile b/modules/Makefile index fbf9bc1..38a8745 100644 --- a/modules/Makefile +++ b/modules/Makefile @@ -29,20 +29,29 @@ export USR_DIR # action all: - $(Q)cd $(ABOUT_DIR) && $(MAKE) && cd .. - $(Q)cd $(CTRL_DIR) && $(MAKE) && cd .. - $(Q)cd $(IMG_DIR) && $(MAKE) && cd .. - $(Q)cd $(MENU_DIR) && $(MAKE) && cd .. - $(Q)cd $(PROC_DIR) && $(MAKE) && cd .. - $(Q)cd $(SAVE_DIR) && $(MAKE) && cd .. - $(Q)cd $(USR_DIR) && $(MAKE) && cd .. - $(Q)cd $(TMP_DIR) && $(MAKE) && cd .. + @echo ' MAKE modules: about' + $(Q)make -C $(ABOUT_DIR) + @echo ' MAKE modules: ctrl' + $(Q)make -C $(CTRL_DIR) + @echo ' MAKE modules: image' + $(Q)make -C $(IMG_DIR) + @echo ' MAKE modules: menu' + $(Q)make -C $(MENU_DIR) + @echo ' MAKE modules: proc' + $(Q)make -C $(PROC_DIR) + @echo ' MAKE modules: save' + $(Q)make -C $(SAVE_DIR) + @echo ' MAKE modules: usr' + $(Q)make -C $(USR_DIR) + @echo ' MAKE modules.o' + $(Q)make -C $(TMP_DIR) + @echo "" clean: + @echo " RM *.o *.s" $(Q)find . -type f -name '*.o' -exec rm '{}' '+' $(Q)find . -type f -name '*.s' -exec rm '{}' '+' - @echo "Clean modules" ################################################################################ ######## End of file ########################################################### diff --git a/modules/about/tmp/Makefile b/modules/about/tmp/Makefile index c415744..5516dd7 100644 --- a/modules/about/tmp/Makefile +++ b/modules/about/tmp/Makefile @@ -31,7 +31,6 @@ all: $(ALL) about_mod.o: $(_ALL) $(Q)$(LD) -r $^ -o $@ @echo " LD $@" - @echo "" about.s: $(ABOU_DEPS) diff --git a/modules/ctrl/tmp/Makefile b/modules/ctrl/tmp/Makefile index c11f389..c02411f 100644 --- a/modules/ctrl/tmp/Makefile +++ b/modules/ctrl/tmp/Makefile @@ -43,7 +43,6 @@ all: $(ALL) ctrl_mod.o: $(_ALL) $(Q)$(LD) -r $^ -o $@ @echo " LD $@" - @echo "" start.s: $(STRT_DEPS) diff --git a/modules/image/tmp/Makefile b/modules/image/tmp/Makefile index 56cafec..dd807f1 100644 --- a/modules/image/tmp/Makefile +++ b/modules/image/tmp/Makefile @@ -70,7 +70,6 @@ all: $(ALL) img_mod.o: $(_ALL) $(Q)$(LD) -r $^ -o $@ @echo " LD $@" - @echo "" img_alx.s: $(IMGALX_DEPS) diff --git a/modules/menu/tmp/Makefile b/modules/menu/tmp/Makefile index 3acc26e..7da117c 100644 --- a/modules/menu/tmp/Makefile +++ b/modules/menu/tmp/Makefile @@ -88,7 +88,6 @@ all: $(ALL) menu_mod.o: $(_ALL) $(Q)$(LD) -r $^ -o $@ @echo " LD $@" - @echo "" parser.s: $(PARS_DEPS) diff --git a/modules/proc/tmp/Makefile b/modules/proc/tmp/Makefile index 420b8dd..83a4a01 100644 --- a/modules/proc/tmp/Makefile +++ b/modules/proc/tmp/Makefile @@ -91,7 +91,6 @@ all: $(ALL) proc_mod.o: $(_ALL) $(Q)$(LD) -r $^ -o $@ @echo " LD $@" - @echo "" proc_label.s: $(PROC_LAB_DEPS) diff --git a/modules/save/tmp/Makefile b/modules/save/tmp/Makefile index e33755e..2003a10 100644 --- a/modules/save/tmp/Makefile +++ b/modules/save/tmp/Makefile @@ -31,7 +31,6 @@ all: $(ALL) save_mod.o: $(_ALL) $(Q)$(LD) -r $^ -o $@ @echo " LD $@" - @echo "" save.s: $(SAVE_DEPS) diff --git a/modules/tmp/Makefile b/modules/tmp/Makefile index 1738e4c..93693cc 100644 --- a/modules/tmp/Makefile +++ b/modules/tmp/Makefile @@ -40,7 +40,6 @@ all: $(ALL) modules.o: $(MODS_OBJS) $(Q)$(LD) -r $^ -o $@ @echo " LD $@" - @echo "" clean: diff --git a/modules/user/tmp/Makefile b/modules/user/tmp/Makefile index 2dc948f..572a912 100644 --- a/modules/user/tmp/Makefile +++ b/modules/user/tmp/Makefile @@ -61,7 +61,6 @@ all: $(ALL) user_mod.o: $(_ALL) $(Q)$(LD) -r $^ -o $@ @echo " LD $@" - @echo "" user_iface.s: $(UI_DEPS) -- cgit v1.2.3 From 26c955f51d7e94d64e07593dfe293634198e3684 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Mon, 3 Dec 2018 22:32:29 +0100 Subject: Minor changes --- bin/Makefile | 2 +- tmp/Makefile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/Makefile b/bin/Makefile index 7d1ccf4..e480144 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -38,8 +38,8 @@ $(BIN_NAME): $(MAIN_OBJS) $(MAIN_LIBS) clean: + @echo " RM $(ALL)" $(Q)rm -f $(ALL) - @echo "Clean binaries" ################################################################################ ######## End of file ########################################################### diff --git a/tmp/Makefile b/tmp/Makefile index 12162dc..25df3b9 100644 --- a/tmp/Makefile +++ b/tmp/Makefile @@ -66,8 +66,8 @@ main.o: main.s clean: + @echo " RM *.o *.s" $(Q)rm -f *.o *.s - @echo "Clean tmp" ################################################################################ ######## End of file ########################################################### -- cgit v1.2.3 From 190efe9444d30b08036acf310c52fc9c89ea5248 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Mon, 3 Dec 2018 22:37:49 +0100 Subject: Minor changes --- Makefile | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 368e50f..543b425 100644 --- a/Makefile +++ b/Makefile @@ -234,26 +234,26 @@ binary: object PHONY += install install: uninstall - @echo " MKDIR -p $(INSTALL_BIN_DIR)/" + @echo " Install:" + @echo " MKDIR $(INSTALL_BIN_DIR)/" $(Q)mkdir -p $(DESTDIR)/$(INSTALL_BIN_DIR)/ - @echo "Copy $(BIN_NAME)" + @echo " CP $(BIN_NAME)" $(Q)cp $(BIN_DIR)/$(BIN_NAME) $(DESTDIR)/$(INSTALL_BIN_DIR)/ - @echo "" - - @echo " MKDIR -p $(INSTALL_SHARE_DIR)/$(SHARE_DIR)/" + @echo " MKDIR $(INSTALL_SHARE_DIR)/$(SHARE_DIR)/" $(Q)mkdir -p $(DESTDIR)/$(INSTALL_SHARE_DIR)/$(SHARE_DIR)/ - @echo " CP -r share/*" + @echo " CP -r share/*" $(Q)cp -r ./share/* $(DESTDIR)/$(INSTALL_SHARE_DIR)/$(SHARE_DIR)/ - @echo "" - - @echo "Done" + @echo " Done" @echo "" PHONY += uninstall uninstall: - @echo "Clean old installations" - $(Q)rm -f $(DESTDIR)/$(INSTALL_BIN_DIR)/$(BIN_NAME) - $(Q)rm -f -r $(DESTDIR)/$(INSTALL_SHARE_DIR)/$(SHARE_DIR)/ + @echo " Clean old installations:" + @echo ' RM binary' + $(Q)rm -f $(DESTDIR)/$(INSTALL_BIN_DIR)/$(BIN_NAME) + @echo ' RM share/*' + $(Q)rm -f -r $(DESTDIR)/$(INSTALL_SHARE_DIR)/$(SHARE_DIR)/ + @echo " Done" @echo "" PHONY += clean -- cgit v1.2.3 From 93e7f0df83e808865e601b2763d4acd0cccc9143 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Sun, 9 Dec 2018 02:47:42 +0100 Subject: Add proc: objects --- libalx | 2 +- modules/Makefile | 14 +- modules/image/inc/img_alx.hpp | 4 +- modules/image/inc/img_calib3d.hpp | 46 ++++ modules/image/inc/img_cv.hpp | 4 +- modules/image/inc/img_iface.h | 24 ++- modules/image/inc/img_iface.hpp | 75 ++++--- modules/image/inc/img_ocr.h | 4 +- modules/image/inc/img_ocr.hpp | 4 +- modules/image/inc/img_orb.hpp | 16 +- modules/image/inc/img_zbar.hpp | 4 +- modules/image/src/img_calib3d.cpp | 98 ++++++--- modules/image/src/img_cv.cpp | 14 +- modules/image/src/img_iface.cpp | 139 +++++++++--- modules/image/src/img_orb.cpp | 12 +- modules/image/tmp/Makefile | 41 ++-- modules/menu/src/menu_tui.c | 18 +- modules/proc/inc/proc_iface.h | 18 +- modules/proc/inc/proc_iface.hpp | 18 +- modules/proc/inc/proc_objects.h | 48 +++++ modules/proc/inc/proc_objects.hpp | 60 ++++++ modules/proc/src/proc_iface.c | 45 +++- modules/proc/src/proc_objects.cpp | 442 ++++++++++++++++++++++++++++++++++++++ modules/proc/tmp/Makefile | 26 ++- modules/save/inc/save.h | 4 + modules/save/inc/save.hpp | 4 + modules/save/src/save.cpp | 4 + modules/user/inc/user_iface.h | 41 ++-- modules/user/inc/user_iface.hpp | 41 ++-- modules/user/src/user_clui.c | 57 ++++- modules/user/src/user_iface.c | 13 +- modules/user/src/user_tui.c | 64 ++++-- 32 files changed, 1159 insertions(+), 245 deletions(-) create mode 100644 modules/image/inc/img_calib3d.hpp create mode 100644 modules/proc/inc/proc_objects.h create mode 100644 modules/proc/inc/proc_objects.hpp create mode 100644 modules/proc/src/proc_objects.cpp diff --git a/libalx b/libalx index cdb8455..66307d2 160000 --- a/libalx +++ b/libalx @@ -1 +1 @@ -Subproject commit cdb845529db48059564a0e44fb174f1d2e4f3023 +Subproject commit 66307d2cfd0a3e82d7539772151f787378bb994c diff --git a/modules/Makefile b/modules/Makefile index 38a8745..e3169fc 100644 --- a/modules/Makefile +++ b/modules/Makefile @@ -29,19 +29,19 @@ export USR_DIR # action all: - @echo ' MAKE modules: about' + @echo ' MAKE modules: about' $(Q)make -C $(ABOUT_DIR) - @echo ' MAKE modules: ctrl' + @echo ' MAKE modules: ctrl' $(Q)make -C $(CTRL_DIR) - @echo ' MAKE modules: image' + @echo ' MAKE modules: image' $(Q)make -C $(IMG_DIR) - @echo ' MAKE modules: menu' + @echo ' MAKE modules: menu' $(Q)make -C $(MENU_DIR) - @echo ' MAKE modules: proc' + @echo ' MAKE modules: proc' $(Q)make -C $(PROC_DIR) - @echo ' MAKE modules: save' + @echo ' MAKE modules: save' $(Q)make -C $(SAVE_DIR) - @echo ' MAKE modules: usr' + @echo ' MAKE modules: usr' $(Q)make -C $(USR_DIR) @echo ' MAKE modules.o' $(Q)make -C $(TMP_DIR) diff --git a/modules/image/inc/img_alx.hpp b/modules/image/inc/img_alx.hpp index fd20a09..ec84ab3 100644 --- a/modules/image/inc/img_alx.hpp +++ b/modules/image/inc/img_alx.hpp @@ -21,9 +21,9 @@ ******* enums **************************************************************** ******************************************************************************/ enum Img_Alx_Action { - IMG_ALX_ACT_FOO = 0, + IMG_ALX_ACT_FOO = 0x000000u, - IMG_ALX_ACT_ALX = 0x0010, + IMG_ALX_ACT_ALX = 0x000010u, IMG_ALX_ACT_LOCAL_MAX, IMG_ALX_ACT_LINES_HORIZONTAL, IMG_ALX_ACT_LINES_VERTICAL, diff --git a/modules/image/inc/img_calib3d.hpp b/modules/image/inc/img_calib3d.hpp new file mode 100644 index 0000000..777f33c --- /dev/null +++ b/modules/image/inc/img_calib3d.hpp @@ -0,0 +1,46 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_IMG_CALIB3D_HPP + # define VA_IMG_CALIB3D_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + /* openCV */ + #include + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Img_Calib3d_Action { + IMG_CALIB3D_ACT_FOO = 0x000000u, + + IMG_CALIB3D_ACT_CALIB3D = 0x000400u, + IMG_CALIB3D_ACT_CALIBRATE, + IMG_CALIB3D_ACT_UNDISTORT + }; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void img_calib3d_act (class cv::Mat *imgptr, int action, void *data); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* img_calib3d.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/inc/img_cv.hpp b/modules/image/inc/img_cv.hpp index 38e2fb1..8327d67 100644 --- a/modules/image/inc/img_cv.hpp +++ b/modules/image/inc/img_cv.hpp @@ -21,9 +21,9 @@ ******* enums **************************************************************** ******************************************************************************/ enum Img_Cv_Action { - IMG_CV_ACT_FOO = 0, + IMG_CV_ACT_FOO = 0x000000u, - IMG_CV_ACT_CV = 0x0100, + IMG_CV_ACT_CV = 0x000100u, IMG_CV_ACT_PIXEL_VALUE, IMG_CV_ACT_SET_ROI, IMG_CV_ACT_AND_2REF, diff --git a/modules/image/inc/img_iface.h b/modules/image/inc/img_iface.h index 8bb023f..cc08ef3 100644 --- a/modules/image/inc/img_iface.h +++ b/modules/image/inc/img_iface.h @@ -29,9 +29,9 @@ ******* enums **************************************************************** ******************************************************************************/ enum Img_Iface_Action { - IMG_IFACE_ACT_FOO = 0, + IMG_IFACE_ACT_FOO = 0x000000u, - IMG_IFACE_ACT_ALX = 0x0010, + IMG_IFACE_ACT_ALX = 0x000010u, IMG_IFACE_ACT_LOCAL_MAX, IMG_IFACE_ACT_LINES_HORIZONTAL, IMG_IFACE_ACT_LINES_VERTICAL, @@ -40,7 +40,7 @@ IMG_IFACE_ACT_MEDIAN_HORIZONTAL, IMG_IFACE_ACT_MEDIAN_VERTICAL, - IMG_IFACE_ACT_CV = 0x0100, + IMG_IFACE_ACT_CV = 0x000100u, IMG_IFACE_ACT_PIXEL_VALUE, IMG_IFACE_ACT_SET_ROI, IMG_IFACE_ACT_SET_ROI_2RECT, @@ -70,23 +70,27 @@ IMG_IFACE_ACT_MIN_AREA_RECT, IMG_IFACE_ACT_HOUGH_CIRCLES, - IMG_IFACE_ACT_ZB = 0x0200, + IMG_IFACE_ACT_ORB = 0x000200u, + IMG_IFACE_ACT_ALIGN, + + IMG_IFACE_ACT_CALIB3D = 0x000400u, + IMG_IFACE_ACT_CALIBRATE, + IMG_IFACE_ACT_UNDISTORT, + + IMG_IFACE_ACT_ZB = 0x000800u, IMG_IFACE_ACT_DECODE, - IMG_IFACE_ACT_OCR = 0x0400, + IMG_IFACE_ACT_OCR = 0x001000u, IMG_IFACE_ACT_READ, - IMG_IFACE_ACT_ORB = 0x0800, - IMG_IFACE_ACT_ALIGN, - - IMG_IFACE_ACT_IMGI = 0x1000, + IMG_IFACE_ACT_IMGI = 0x002000u, IMG_IFACE_ACT_APPLY, IMG_IFACE_ACT_DISCARD, IMG_IFACE_ACT_SAVE_MEM, IMG_IFACE_ACT_LOAD_MEM, IMG_IFACE_ACT_SAVE_REF, - IMG_IFACE_ACT_SAVE = 0x2000, + IMG_IFACE_ACT_SAVE = 0x004000u, IMG_IFACE_ACT_SAVE_FILE, IMG_IFACE_ACT_SAVE_UPDT }; diff --git a/modules/image/inc/img_iface.hpp b/modules/image/inc/img_iface.hpp index 0cb858b..1baaed7 100644 --- a/modules/image/inc/img_iface.hpp +++ b/modules/image/inc/img_iface.hpp @@ -13,6 +13,10 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ +/* Standard C++ --------------------------------------------------------------*/ + /* class std::vector */ + #include + /* Packages ------------------------------------------------------------------*/ /* opencv */ #include @@ -35,9 +39,9 @@ ******* enums **************************************************************** ******************************************************************************/ enum Img_Iface_Action { - IMG_IFACE_ACT_FOO = 0, + IMG_IFACE_ACT_FOO = 0x000000u, - IMG_IFACE_ACT_ALX = 0x0010, + IMG_IFACE_ACT_ALX = 0x000010u, IMG_IFACE_ACT_LOCAL_MAX, IMG_IFACE_ACT_LINES_HORIZONTAL, IMG_IFACE_ACT_LINES_VERTICAL, @@ -46,7 +50,7 @@ IMG_IFACE_ACT_MEDIAN_HORIZONTAL, IMG_IFACE_ACT_MEDIAN_VERTICAL, - IMG_IFACE_ACT_CV = 0x0100, + IMG_IFACE_ACT_CV = 0x000100u, IMG_IFACE_ACT_PIXEL_VALUE, IMG_IFACE_ACT_SET_ROI, IMG_IFACE_ACT_SET_ROI_2RECT, @@ -76,23 +80,27 @@ IMG_IFACE_ACT_MIN_AREA_RECT, IMG_IFACE_ACT_HOUGH_CIRCLES, - IMG_IFACE_ACT_ZB = 0x0200, + IMG_IFACE_ACT_ORB = 0x000200u, + IMG_IFACE_ACT_ALIGN, + + IMG_IFACE_ACT_CALIB3D = 0x000400u, + IMG_IFACE_ACT_CALIBRATE, + IMG_IFACE_ACT_UNDISTORT, + + IMG_IFACE_ACT_ZB = 0x000800u, IMG_IFACE_ACT_DECODE, - IMG_IFACE_ACT_OCR = 0x0400, + IMG_IFACE_ACT_OCR = 0x001000u, IMG_IFACE_ACT_READ, - IMG_IFACE_ACT_ORB = 0x0800, - IMG_IFACE_ACT_ALIGN, - - IMG_IFACE_ACT_IMGI = 0x1000, + IMG_IFACE_ACT_IMGI = 0x002000u, IMG_IFACE_ACT_APPLY, IMG_IFACE_ACT_DISCARD, IMG_IFACE_ACT_SAVE_MEM, IMG_IFACE_ACT_LOAD_MEM, IMG_IFACE_ACT_SAVE_REF, - IMG_IFACE_ACT_SAVE = 0x2000, + IMG_IFACE_ACT_SAVE = 0x004000u, IMG_IFACE_ACT_SAVE_FILE, IMG_IFACE_ACT_SAVE_UPDT }; @@ -194,35 +202,48 @@ }; struct Img_Iface_Data_Contours { - std::vector >> *contours; - class cv::Mat *hierarchy; + class std::vector >> *contours; + class cv::Mat *hierarchy; }; struct Img_Iface_Data_Contours_Size { - std::vector >> *contours; - double *area; - double *perimeter; + class std::vector >> *contours; + double *area; + double *perimeter; }; struct Img_Iface_Data_Bounding_Rect { - std::vector > *contour; - class cv::Rect_ *rect; - bool show; + class std::vector > *contour; + class cv::Rect_ *rect; + bool show; }; struct Img_Iface_Data_MinARect { - std::vector > *contour; - class cv::RotatedRect *rect; - bool show; + class std::vector > *contour; + class cv::RotatedRect *rect; + bool show; }; struct Img_Iface_Data_Hough_Circles { - std::vector > *circles; - double dist_min; - double param_1; - double param_2; - int radius_min; - int radius_max; + class std::vector > *circles; + double dist_min; + double param_1; + double param_2; + int radius_min; + int radius_max; + }; + +/* img_calib3d ---------------------------------------------------------------*/ + struct Img_Iface_Data_Calibrate { + class cv::Mat *intrinsic_mat; + class cv::Mat *dist_coefs; + class std::vector *rvecs; + class std::vector *tvecs; + }; + + struct Img_Iface_Data_Undistort { + class cv::Mat *intrinsic_mat; + class cv::Mat *dist_coefs; }; /* img_zbar -------------------------------------------------------------------*/ diff --git a/modules/image/inc/img_ocr.h b/modules/image/inc/img_ocr.h index 2c216ad..f2e8742 100644 --- a/modules/image/inc/img_ocr.h +++ b/modules/image/inc/img_ocr.h @@ -14,9 +14,9 @@ ******* enums **************************************************************** ******************************************************************************/ enum Img_OCR_Action { - IMG_OCR_ACT_FOO = 0, + IMG_OCR_ACT_FOO = 0x000000u, - IMG_OCR_ACT_OCR = 0x0400, + IMG_OCR_ACT_OCR = 0x001000u, IMG_OCR_ACT_READ }; diff --git a/modules/image/inc/img_ocr.hpp b/modules/image/inc/img_ocr.hpp index 723588e..446f986 100644 --- a/modules/image/inc/img_ocr.hpp +++ b/modules/image/inc/img_ocr.hpp @@ -14,9 +14,9 @@ ******* enums **************************************************************** ******************************************************************************/ enum Img_OCR_Action { - IMG_OCR_ACT_FOO = 0, + IMG_OCR_ACT_FOO = 0x000000u, - IMG_OCR_ACT_OCR = 0x0400, + IMG_OCR_ACT_OCR = 0x001000u, IMG_OCR_ACT_READ }; diff --git a/modules/image/inc/img_orb.hpp b/modules/image/inc/img_orb.hpp index 6138a04..b29fefa 100644 --- a/modules/image/inc/img_orb.hpp +++ b/modules/image/inc/img_orb.hpp @@ -17,19 +17,13 @@ #include -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - /****************************************************************************** ******* enums **************************************************************** ******************************************************************************/ enum Img_ORB_Action { - IMG_ORB_ACT_FOO = 0, + IMG_ORB_ACT_FOO = 0x000000u, - IMG_ORB_ACT_ORB = 0x0800, + IMG_ORB_ACT_ORB = 0x000200u, IMG_ORB_ACT_ALIGN }; @@ -41,12 +35,6 @@ extern "C" { class cv::Mat *imgptr, int action); -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - /****************************************************************************** ******* include guard ******************************************************** ******************************************************************************/ diff --git a/modules/image/inc/img_zbar.hpp b/modules/image/inc/img_zbar.hpp index 3132175..2019ae3 100644 --- a/modules/image/inc/img_zbar.hpp +++ b/modules/image/inc/img_zbar.hpp @@ -22,9 +22,9 @@ ******* enums **************************************************************** ******************************************************************************/ enum Img_ZB_Action { - IMG_ZB_ACT_FOO = 0, + IMG_ZB_ACT_FOO = 0x000000u, - IMG_ZB_ACT_ZB = 0x0200, + IMG_ZB_ACT_ZB = 0x000800u, IMG_ZB_ACT_DECODE }; diff --git a/modules/image/src/img_calib3d.cpp b/modules/image/src/img_calib3d.cpp index 26cfc39..da6bb95 100644 --- a/modules/image/src/img_calib3d.cpp +++ b/modules/image/src/img_calib3d.cpp @@ -7,7 +7,7 @@ ******* headers ************************************************************** ******************************************************************************/ /* Standard C++ --------------------------------------------------------------*/ - /* std::vector */ + /* class std::vector */ #include /* Standard C ----------------------------------------------------------------*/ @@ -20,18 +20,24 @@ #include /* Module -------------------------------------------------------------------*/ + /* data */ + #include "img_iface.hpp" + #include "img_calib3d.hpp" /****************************************************************************** ******* macros *************************************************************** ******************************************************************************/ + # define CORNERS_HOR (16) + # define CORNERS_VER (13) /****************************************************************************** ******* static functions ***************************************************** ******************************************************************************/ static void img_calib3d_calibrate (class cv::Mat *imgptr, void *data); +static void img_calib3d_undistort (class cv::Mat *imgptr, void *data); /****************************************************************************** @@ -43,6 +49,10 @@ void img_calib3d_act (class cv::Mat *imgptr, int action, void *data) case IMG_CALIB3D_ACT_CALIBRATE: img_calib3d_calibrate(imgptr, data); break; + + case IMG_CALIB3D_ACT_UNDISTORT: + img_calib3d_undistort(imgptr, data); + break; } } @@ -52,42 +62,78 @@ void img_calib3d_act (class cv::Mat *imgptr, int action, void *data) ******************************************************************************/ static void img_calib3d_calibrate (class cv::Mat *imgptr, void *data) { - const class cv::Size pattern_size(8, 6); + /* Data */ + struct Img_Iface_Data_Calibrate *data_cast; - class cv::Mat corners; - bool found; + class cv::Mat *intrinsic_mat; + class cv::Mat *dist_coefs; + class std::vector *rvecs; + class std::vector *tvecs; - found = cv::findChessboardCorners(*imgptr, pattern_size, corners); + class cv::Size_ pattern_size; + class std::vector >> object_points; + class std::vector >> image_points; + class std::vector > corners; + class std::vector > obj; + bool found; int i; int j; - // Object points - std::vector > object_points; - for (i = 0; i < pattern_size.height; i++) { - for (j = 0; j < pattern_size.width; j++) { - object_points.at(0).push_back(Vec3f(i, j, 0)); - } - } + data_cast = (struct Img_Iface_Data_Calibrate *)data; + intrinsic_mat = data_cast->intrinsic_mat; + dist_coefs = data_cast->dist_coefs; + rvecs = data_cast->rvecs; + tvecs = data_cast->tvecs; + + pattern_size = cv::Size(CORNERS_HOR, CORNERS_VER); + *intrinsic_mat = cv::Mat(3, 3, CV_32FC1); + (*intrinsic_mat).ptr(0)[0] = 1; + (*intrinsic_mat).ptr(1)[1] = 1; - // Image points - std::vector > image_points; - int num; - for (i = 0; i < pattern_size.height; i++) { - for (j = 0; j < pattern_size.width; j++) { - image_points.at(0).push_back(corners.at(num, 0)); + for (i = 0; i < CORNERS_HOR; i++) { + for (j = 0; j < CORNERS_VER; j++) { + obj.push_back(cv::Point3f(i, j * 10.0, 0.0)); } } - class cv::Mat camera_matrix; - class cv::Mat dist_matrix; - class cv::Mat rvecs; - class cv::Mat tvecs; + found = cv::findChessboardCorners(*imgptr, pattern_size, corners, + CV_CALIB_CB_ADAPTIVE_THRESH | + CV_CALIB_CB_FILTER_QUADS); + + cv::cornerSubPix(*imgptr, corners, cv::Size(11, 11), + cv::Size(-1, -1), + cv::TermCriteria(CV_TERMCRIT_EPS | + CV_TERMCRIT_ITER, 30, 0.1)); + cv::drawChessboardCorners(*imgptr, pattern_size, corners, found); + + image_points.push_back(corners); + object_points.push_back(obj); + + /* Calibrate */ + cv::calibrateCamera(object_points, image_points, imgptr->size(), + *intrinsic_mat, *dist_coefs, *rvecs, *tvecs); +} + +static void img_calib3d_undistort (class cv::Mat *imgptr, void *data) +{ + class cv::Mat imgtmp; + + /* Data */ + struct Img_Iface_Data_Undistort *data_cast; + + class cv::Mat *intrinsic_mat; + class cv::Mat *dist_coefs; + + data_cast = (struct Img_Iface_Data_Undistort *)data; + intrinsic_mat = data_cast->intrinsic_mat; + dist_coefs = data_cast->dist_coefs; + + cv::undistort(*imgptr, imgtmp, *intrinsic_mat, *dist_coefs); - cv::calibrateCamera(object_points, image_points, - cv::Size(imgptr->size().width, - imgptr->size().height) - camera_matrix, dist_matrix, rvecs, tvecs); + /* Write tmp into imgptr */ + imgptr->release(); + imgtmp.copyTo(*imgptr); } diff --git a/modules/image/src/img_cv.cpp b/modules/image/src/img_cv.cpp index 4f095e8..f043156 100644 --- a/modules/image/src/img_cv.cpp +++ b/modules/image/src/img_cv.cpp @@ -7,7 +7,7 @@ ******* headers ************************************************************** ******************************************************************************/ /* Standard C++ --------------------------------------------------------------*/ - /* std::vector */ + /* class std::vector */ #include /* Standard C ----------------------------------------------------------------*/ @@ -583,7 +583,7 @@ static void img_cv_contours (class cv::Mat *imgptr, void *data) data_cast = (struct Img_Iface_Data_Contours *)data; /* Contours */ - std::vector >> *contours; + class std::vector >> *contours; contours = data_cast->contours; class cv::Mat *hierarchy; hierarchy = data_cast->hierarchy; @@ -607,7 +607,7 @@ static void img_cv_contours_size (void *data) data_cast = (struct Img_Iface_Data_Contours_Size *)data; /* Contours */ - std::vector >> *contours; + class std::vector >> *contours; contours = data_cast->contours; /* Get area and perimeter */ @@ -627,7 +627,7 @@ static void img_cv_bounding_rect (class cv::Mat *imgptr, void *data) data_cast = (struct Img_Iface_Data_Bounding_Rect *)data; /* Contours */ - std::vector > *contour; + class std::vector > *contour; contour = data_cast->contour; /* Rotated rectangle */ class cv::Rect_ *rect; @@ -672,7 +672,7 @@ static void img_cv_fit_ellipse (class cv::Mat *imgptr, void *data) data_cast = (struct Img_Iface_Data_MinARect *)data; /* Contours */ - std::vector > *contour; + class std::vector > *contour; contour = data_cast->contour; /* Rotated rectangle */ class cv::RotatedRect *rect; @@ -710,7 +710,7 @@ static void img_cv_min_area_rect (class cv::Mat *imgptr, void *data) data_cast = (struct Img_Iface_Data_MinARect *)data; /* Contours */ - std::vector > *contour; + class std::vector > *contour; contour = data_cast->contour; /* Rotated rectangle */ class cv::RotatedRect *rect; @@ -749,7 +749,7 @@ static void img_cv_hough_circles (class cv::Mat *imgptr, void *data) data_cast = (struct Img_Iface_Data_Hough_Circles *)data; /* Contours */ - std::vector > *circles; + class std::vector > *circles; circles = data_cast->circles; /* Parameters */ double dist_min; diff --git a/modules/image/src/img_iface.cpp b/modules/image/src/img_iface.cpp index 60d7aa2..c7b516c 100644 --- a/modules/image/src/img_iface.cpp +++ b/modules/image/src/img_iface.cpp @@ -7,7 +7,7 @@ ******* headers ************************************************************** ******************************************************************************/ /* Standard C++ --------------------------------------------------------------*/ - /* std::vector */ + /* class std::vector */ #include /* Standard C ----------------------------------------------------------------*/ @@ -33,12 +33,14 @@ #include "img_alx.hpp" /* img_cv_act() */ #include "img_cv.hpp" + /* img_orb_act() */ + #include "img_orb.hpp" + /* img_calib3d_act() */ + #include "img_calib3d.hpp" /* img_zb_act() */ #include "img_zbar.hpp" - /* OCR */ + /* img_ocr_act() */ #include "img_ocr.hpp" - /* ORB */ - #include "img_orb.hpp" #include "img_iface.hpp" @@ -70,13 +72,17 @@ static class cv::Mat histogram_c1; static class cv::Mat histogram_c2; static class cv::Mat hist_img_c1; static class cv::Mat hist_img_c3; -static std::vector >> contours; +static class std::vector >> contours; static double area [CONTOURS_MAX]; static double perimeter [CONTOURS_MAX]; static class cv::Mat hierarchy; static class cv::Rect_ rectangle; static class cv::RotatedRect rectangle_rot; -static std::vector > circles; +static class std::vector > circles; +static class cv::Mat intrinsic_mat; +static class cv::Mat dist_coefs; +static class std::vector rvecs; +static class std::vector tvecs; /****************************************************************************** @@ -132,12 +138,17 @@ static void img_iface_min_area_rect (void *data); /* Feature detection */ static void img_iface_hough_circles (void *data); + /* img_orb */ +static void img_iface_align (void); + /* img_calib3d */ +static void img_iface_calibrate (void *data); +static void img_iface_undistort (void *data); + /* img_zbar */ static void img_iface_decode (void *data); /* img_ocr */ static void img_iface_read (void *data); - /* img_orb */ -static void img_iface_align (void); + /* img_iface */ static void img_iface_apply (void); static void img_iface_discard (void); @@ -348,6 +359,14 @@ void img_iface_act (int action, void *data) img_iface_align(); break; + /* img_calib3d */ + case IMG_IFACE_ACT_CALIBRATE: + img_iface_calibrate(data); + break; + case IMG_IFACE_ACT_UNDISTORT: + img_iface_undistort(data); + break; + /* img_zbar */ case IMG_IFACE_ACT_DECODE: img_iface_decode(data); @@ -1507,6 +1526,86 @@ static void img_iface_hough_circles (void *data) (user_iface_log.len)++; } +/* img_orb -------------------------------------------------------------------*/ +static void img_iface_align (void) +{ + /* Must have defined a reference */ + if (image_ref.empty()) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! Reference is NULL"); + 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, + "Align to reference"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Align to reference image_ref */ + img_orb_act(&image_ref, &image_copy_tmp, IMG_ORB_ACT_ALIGN); +} + +/* img_calib3d ---------------------------------------------------------------*/ +static void img_iface_calibrate (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Data */ + struct Img_Iface_Data_Calibrate data_tmp; + if (!data) { + data_tmp.intrinsic_mat = &intrinsic_mat; + data_tmp.dist_coefs = &dist_coefs; + data_tmp.rvecs = &rvecs; + data_tmp.tvecs = &tvecs; + + data = (void *)&data_tmp; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Calibrate"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Contours */ + img_calib3d_act(&image_copy_tmp, IMG_CALIB3D_ACT_CALIBRATE, data); +} + +static void img_iface_undistort (void *data) +{ + /* Data */ + struct Img_Iface_Data_Undistort data_tmp; + if (!data) { + data_tmp.intrinsic_mat = &intrinsic_mat; + data_tmp.dist_coefs = &dist_coefs; + + data = (void *)&data_tmp; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Undistort"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Contours */ + img_calib3d_act(&image_copy_tmp, IMG_CALIB3D_ACT_UNDISTORT, data); +} + /* img_zbar ------------------------------------------------------------------*/ static void img_iface_decode (void *data) { @@ -1625,30 +1724,6 @@ static void img_iface_read (void *data) } } -/* img_orb -------------------------------------------------------------------*/ -static void img_iface_align (void) -{ - /* Must have defined a reference */ - if (image_ref.empty()) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Reference is NULL"); - 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, - "Align to reference"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Align to reference image_ref */ - img_orb_act(&image_ref, &image_copy_tmp, IMG_ORB_ACT_ALIGN); -} - /* img_iface -----------------------------------------------------------------*/ static void img_iface_apply (void) { diff --git a/modules/image/src/img_orb.cpp b/modules/image/src/img_orb.cpp index dda46ed..f62203c 100644 --- a/modules/image/src/img_orb.cpp +++ b/modules/image/src/img_orb.cpp @@ -7,7 +7,7 @@ ******* headers ************************************************************** ******************************************************************************/ /* Standard C++ --------------------------------------------------------------*/ - /* std::vector */ + /* class std::vector */ #include /* Standard C ----------------------------------------------------------------*/ @@ -58,8 +58,8 @@ static void img_orb_align (class cv::Mat *img_0, class cv::Mat *img_1) { /* Variables to store keypoints & descriptors */ - std::vector keypoints_0; - std::vector keypoints_1; + class std::vector keypoints_0; + class std::vector keypoints_1; class cv::Mat descriptors_0; class cv::Mat descriptors_1; @@ -79,7 +79,7 @@ static void img_orb_align (class cv::Mat *img_0, /* Match structures */ - std::vector matches; + class std::vector matches; cv::Ptr matcher; matcher = cv::DescriptorMatcher::create("BruteForce-Hamming"); matcher->match(descriptors_1, descriptors_0, matches, cv::Mat()); @@ -99,8 +99,8 @@ static void img_orb_align (class cv::Mat *img_0, cv::imwrite("matches.jpg", img_matches); /* Extract location of good matches */ - std::vector > points_0; - std::vector > points_1; + class std::vector > points_0; + class std::vector > points_1; int i; for (i = 0; i < (int)matches.size(); i++) { points_1.push_back(keypoints_1[matches[i].queryIdx].pt); diff --git a/modules/image/tmp/Makefile b/modules/image/tmp/Makefile index dd807f1..e41df65 100644 --- a/modules/image/tmp/Makefile +++ b/modules/image/tmp/Makefile @@ -15,8 +15,9 @@ SRC_DIR = $(IMG_DIR)/src/ # dependencies -_ALL = img_alx.o img_cv.o img_zbar.o img_ocr.o img_orb.o img_iface.o -ALL = $(_ALL) img_mod.o +_ALL = img_alx.o img_cv.o img_orb.o img_calib3d.o \ + img_zbar.o img_ocr.o img_iface.o +ALL = $(_ALL) img_mod.o IMGALX_INC_LIBALX = alx_math.hpp IMGALX_INC = img_alx.hpp img_iface.hpp @@ -31,6 +32,16 @@ IMGCV_DEPS = $(SRC_DIR)/img_cv.cpp \ $(patsubst %,$(INC_DIR)/%,$(IMGCV_INC)) IMGCV_INC_DIRS = -I $(INC_DIR) +IMGORB_INC = img_orb.hpp img_iface.hpp +IMGORB_DEPS = $(SRC_DIR)/img_orb.cpp \ + $(patsubst %,$(INC_DIR)/%,$(IMGORB_INC)) +IMGORB_INC_DIRS = -I $(INC_DIR) + +IMGC3D_INC = img_calib3d.hpp img_iface.hpp +IMGC3D_DEPS = $(SRC_DIR)/img_calib3d.cpp \ + $(patsubst %,$(INC_DIR)/%,$(IMGC3D_INC)) +IMGC3D_INC_DIRS = -I $(INC_DIR) + IMGZB_INC = img_zbar.hpp img_iface.hpp IMGZB_DEPS = $(SRC_DIR)/img_zbar.cpp \ $(patsubst %,$(INC_DIR)/%,$(IMGZB_INC)) @@ -44,11 +55,6 @@ IMGOCR_DEPS = $(SRC_DIR)/img_ocr.c \ IMGOCR_INC_DIRS = -I $(INC_DIR) \ -I $(ABOUT_INC_DIR) -IMGORB_INC = img_orb.hpp img_iface.hpp -IMGORB_DEPS = $(SRC_DIR)/img_orb.cpp \ - $(patsubst %,$(INC_DIR)/%,$(IMGORB_INC)) -IMGORB_INC_DIRS = -I $(INC_DIR) - IMGI_INC_SAVE = save.hpp IMGI_INC_USR = user_iface.hpp IMGI_INC = img_iface.hpp img_alx.hpp img_cv.hpp img_zbar.hpp \ @@ -86,6 +92,20 @@ img_cv.o: img_cv.s $(Q)$(AS) $< -o $@ @echo " AS $@" +img_orb.s: $(IMGORB_DEPS) + $(Q)$(CXX) $(CXXFLAGS) $(IMGORB_INC_DIRS) -S $< -o $@ + @echo " CXX $@" +img_orb.o: img_orb.s + $(Q)$(AS) $< -o $@ + @echo " AS $@" + +img_calib3d.s: $(IMGC3D_DEPS) + $(Q)$(CXX) $(CXXFLAGS) $(IMGC3D_INC_DIRS) -S $< -o $@ + @echo " CXX $@" +img_calib3d.o: img_calib3d.s + $(Q)$(AS) $< -o $@ + @echo " AS $@" + img_zbar.s: $(IMGZB_DEPS) $(Q)$(CXX) $(CXXFLAGS) $(IMGZB_INC_DIRS) -S $< -o $@ @echo " CXX $@" @@ -100,13 +120,6 @@ img_ocr.o: img_ocr.s $(Q)$(AS) $< -o $@ @echo " AS $@" -img_orb.s: $(IMGORB_DEPS) - $(Q)$(CXX) $(CXXFLAGS) $(IMGORB_INC_DIRS) -S $< -o $@ - @echo " CXX $@" -img_orb.o: img_orb.s - $(Q)$(AS) $< -o $@ - @echo " AS $@" - img_iface.s: $(IMGI_DEPS) $(Q)$(CXX) $(CXXFLAGS) $(IMGI_INC_DIRS) -S $< -o $@ @echo " CXX $@" diff --git a/modules/menu/src/menu_tui.c b/modules/menu/src/menu_tui.c index c24ef79..ec50267 100644 --- a/modules/menu/src/menu_tui.c +++ b/modules/menu/src/menu_tui.c @@ -223,12 +223,13 @@ static void menu_tui_series (void) h = 23; w = 80; int N; - N = 4; - struct Alx_Menu mnu[4] = { + N = 5; + struct Alx_Menu mnu[5] = { {6, 4, "[0] Back"}, {2, 4, "[1] Label"}, - {3, 4, "[-] -"}, - {4, 4, "[2] Resistor"} + {3, 4, "[2] Objects"}, + {4, 4, "[3] Coins"}, + {5, 4, "[4] Resistor"} }; /* Menu loop */ @@ -238,13 +239,16 @@ static void menu_tui_series (void) /* Selection */ switch (sw) { case 1: - proc_mode = PROC_MODE_LABEL; + proc_mode = PROC_MODE_LABEL_SERIES; break; case 2: - proc_mode = PROC_MODE_FOO; + proc_mode = PROC_MODE_OBJECTS_SERIES; break; case 3: - proc_mode = PROC_MODE_RESISTOR; + proc_mode = PROC_MODE_COINS_SERIES; + break; + case 4: + proc_mode = PROC_MODE_RESISTOR_SERIES; break; } diff --git a/modules/proc/inc/proc_iface.h b/modules/proc/inc/proc_iface.h index 847eca3..7225f25 100644 --- a/modules/proc/inc/proc_iface.h +++ b/modules/proc/inc/proc_iface.h @@ -10,6 +10,11 @@ # define VA_PROC_IFACE_H +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + /****************************************************************************** ******* macros *************************************************************** ******************************************************************************/ @@ -21,10 +26,15 @@ enum Proc_Mode { PROC_MODE_FOO, - PROC_MODE = 0x4000, - PROC_MODE_LABEL, - PROC_MODE_COINS, - PROC_MODE_RESISTOR + PROC_MODE = 0x008000u, + PROC_MODE_LABEL_SERIES, + PROC_MODE_LABEL_CALIB, + PROC_MODE_OBJECTS_SERIES, + PROC_MODE_OBJECTS_CALIB, + PROC_MODE_COINS_SERIES, + PROC_MODE_COINS_CALIB, + PROC_MODE_RESISTOR_SERIES, + PROC_MODE_RESISTOR_CALIB }; enum Proc_DBG { diff --git a/modules/proc/inc/proc_iface.hpp b/modules/proc/inc/proc_iface.hpp index f4345a8..941467b 100644 --- a/modules/proc/inc/proc_iface.hpp +++ b/modules/proc/inc/proc_iface.hpp @@ -10,6 +10,11 @@ # define VA_PROC_IFACE_H +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + /****************************************************************************** ******* macros *************************************************************** ******************************************************************************/ @@ -21,10 +26,15 @@ enum Proc_Mode { PROC_MODE_FOO, - PROC_MODE = 0x4000, - PROC_MODE_LABEL, - PROC_MODE_COINS, - PROC_MODE_RESISTOR + PROC_MODE = 0x008000u, + PROC_MODE_LABEL_SERIES, + PROC_MODE_LABEL_CALIB, + PROC_MODE_OBJECTS_SERIES, + PROC_MODE_OBJECTS_CALIB, + PROC_MODE_COINS_SERIES, + PROC_MODE_COINS_CALIB, + PROC_MODE_RESISTOR_SERIES, + PROC_MODE_RESISTOR_CALIB }; enum Proc_DBG { diff --git a/modules/proc/inc/proc_objects.h b/modules/proc/inc/proc_objects.h new file mode 100644 index 0000000..e066bd7 --- /dev/null +++ b/modules/proc/inc/proc_objects.h @@ -0,0 +1,48 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_OBJECTS_H + # define VA_PROC_OBJECTS_H + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Objects { + OBJECTS_OK, + OBJECTS_NOK_OBJECTS, + OBJECTS_NOK_SIZE + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_objects_calibrate (void); + int proc_objects (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_objects.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_objects.hpp b/modules/proc/inc/proc_objects.hpp new file mode 100644 index 0000000..20806df --- /dev/null +++ b/modules/proc/inc/proc_objects.hpp @@ -0,0 +1,60 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_OBJECTS_HPP + # define VA_PROC_OBJECTS_HPP + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Objects { + OBJECTS_OK, + OBJECTS_NOK_OBJECTS, + OBJECTS_NOK_SIZE + }; + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_objects_calibrate (void); + int proc_objects (void); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_objects.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/src/proc_iface.c b/modules/proc/src/proc_iface.c index 7fb988e..a90466e 100644 --- a/modules/proc/src/proc_iface.c +++ b/modules/proc/src/proc_iface.c @@ -9,6 +9,7 @@ /* Standard C ----------------------------------------------------------------*/ /* errno */ #include + #include /* snprintf() & fflush() */ #include /* clock_t & clock() & CLOCKS_PER_SEC */ @@ -28,6 +29,7 @@ /* Module --------------------------------------------------------------------*/ #include "proc_label.h" + #include "proc_objects.h" #include "proc_coins.h" #include "proc_resistor.h" #include "proc_common.h" @@ -67,13 +69,19 @@ int proc_iface_single (int action) /* Process */ switch (action) { - case PROC_MODE_LABEL: + case PROC_MODE_LABEL_SERIES: error = proc_label(); break; - case PROC_MODE_COINS: + case PROC_MODE_OBJECTS_CALIB: + error = proc_objects_calibrate(); + break; + case PROC_MODE_OBJECTS_SERIES: + error = proc_objects(); + break; + case PROC_MODE_COINS_SERIES: error = proc_coins(); break; - case PROC_MODE_RESISTOR: + case PROC_MODE_RESISTOR_SERIES: error = proc_resistor(); break; default: @@ -105,35 +113,50 @@ void proc_iface_series (void) char file_name [FILENAME_MAX]; bool proc_error; char save_error_as [FILENAME_MAX]; + bool wh; + /* if i starts being 0, the camera needs calibration */ + int i; switch (proc_mode) { - case PROC_MODE_LABEL: + case PROC_MODE_LABEL_SERIES: snprintf(proc_path, FILENAME_MAX, "%s", labels_path); snprintf(proc_fail_path, FILENAME_MAX, "%s", labels_fail_path); snprintf(file_basename, 80, "b"); num_len = 4; snprintf(file_ext, 80, ".BMP"); + i = 1; + break; + case PROC_MODE_OBJECTS_SERIES: + snprintf(proc_path, FILENAME_MAX, "%s", objects_path); + snprintf(proc_fail_path, FILENAME_MAX, "%s", objects_fail_path); + snprintf(file_basename, 80, "o"); + num_len = 4; + snprintf(file_ext, 80, ".jpeg"); + i = 0; + proc_mode++; break; - case PROC_MODE_COINS: + case PROC_MODE_COINS_SERIES: snprintf(proc_path, FILENAME_MAX, "%s", coins_path); snprintf(proc_fail_path, FILENAME_MAX, "%s", coins_fail_path); snprintf(file_basename, 80, "c"); num_len = 4; snprintf(file_ext, 80, ".png"); + i = 1; break; - case PROC_MODE_RESISTOR: + case PROC_MODE_RESISTOR_SERIES: snprintf(proc_path, FILENAME_MAX, "%s", resistors_path); snprintf(proc_fail_path, FILENAME_MAX, "%s", resistors_fail_path); snprintf(file_basename, 80, "r"); num_len = 4; snprintf(file_ext, 80, ".png"); + i = 1; break; + default: + return; } - bool wh; - int i; wh = true; - for (i = 0; wh; i++) { + for (; wh; i++) { snprintf(file_name, FILENAME_MAX, "%s%04i%s", file_basename, i, file_ext); @@ -174,6 +197,10 @@ void proc_iface_series (void) printf("errno:%i\n", errno); } } + + if (!i) { + proc_mode--; + } } } diff --git a/modules/proc/src/proc_objects.cpp b/modules/proc/src/proc_objects.cpp new file mode 100644 index 0000000..692ae34 --- /dev/null +++ b/modules/proc/src/proc_objects.cpp @@ -0,0 +1,442 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* snprintf() */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* openCV */ + #include + +/* libalx ------------------------------------------------------------------*/ + /* alx_maximum_u8() */ + #include "alx_math.hpp" + +/* Project -------------------------------------------------------------------*/ + /* constants */ + #include "img_iface.hpp" + /* user_iface_log */ + #include "user_iface.hpp" + +/* Module --------------------------------------------------------------------*/ + #include "proc_common.hpp" + + #include "proc_objects.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define COINS_MAX 1024 + + +/****************************************************************************** + ******* structs ************************************************************** + ******************************************************************************/ +struct Objects_Properties { + /* position */ + double x_pix; + double y_pix; + double x_mm; + double y_mm; + + /* Angle */ + double angle; + + /* Area */ + double area_pix2; + double area_mm2; + + /* Perimeter */ + double perimeter_pix; + double perimeter_mm; + + /* type */ + double ratio_p2_a; + int8_t value; + + /* diammeter */ + uint8_t diameter_pix; +}; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ + +/* Static --------------------------------------------------------------------*/ +static std::vector >> contours; +static class cv::Mat hierarchy; +static class cv::RotatedRect rectangle [CONTOURS_MAX]; +static int objects_n; +static struct Objects_Properties objects [CONTOURS_MAX]; +static double ratio_mm_per_pix; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_objects (int status); + +static void pattern_segmentate (void); +static void pattern_len_pix (void); +static void calibrate_mm_per_pix (void); + +static void objects_segmentate (void); +static int objects_contours (void); +static void objects_position_pix (void); +static void objects_size_pix (void); +static void objects_position_mm (void); +static void objects_size_mm (void); +static void objects_log (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +int proc_objects_calibrate (void) +{ + int status; + + proc_save_mem(0); + /* Segmentate coins */ + { + /* Measure time */ + clock_start(); + + pattern_segmentate(); + + /* Measure time */ + clock_stop("Segmentate coins"); + } + /* Find coins positions */ + { + /* Measure time */ + clock_start(); + + status = objects_contours(); + if (status) { + result_objects(status); + return status; + } + objects_position_pix(); + + /* Measure time */ + clock_stop("Find squares"); + } + /* Calibrate with the mean of the squares */ + { + /* Measure time */ + clock_start(); + + pattern_len_pix(); + calibrate_mm_per_pix(); + + /* Measure time */ + clock_stop("Calibrate (mm per pix)"); + } + + status = OBJECTS_OK; + result_objects(status); + return status; +} + +int proc_objects (void) +{ + int status; + + proc_save_mem(0); + /* Segmentate coins */ + { + /* Measure time */ + clock_start(); + + objects_segmentate(); + + /* Measure time */ + clock_stop("Segmentate objects"); + } + /* Find coins positions */ + { + /* Measure time */ + clock_start(); + + status = objects_contours(); + if (status) { + result_objects(status); + return status; + } + + /* Measure time */ + clock_stop("Find objects positions"); + } + /* Get objects properties in pixels */ + { + /* Measure time */ + clock_start(); + + objects_position_pix(); + objects_size_pix(); + + /* Measure time */ + clock_stop("Objects properties in pixels"); + } + /* Get objects properties in mm */ + { + /* Measure time */ + clock_start(); + + objects_position_mm(); + objects_size_mm(); + + /* Measure time */ + clock_stop("Objects properties in mm"); + } + /* Print properties of objects into log */ + { + /* Measure time */ + clock_start(); + + objects_log(); + + /* Measure time */ + clock_stop("Objects properties (log)"); + } + + status = OBJECTS_OK; + result_objects(status); + return status; +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_objects (int status) +{ + /* Cleanup */ + + /* Write result into log */ + switch (status) { + case OBJECTS_OK: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: OK"); + break; + case OBJECTS_NOK_OBJECTS: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK_OBJECTS"); + break; + + case OBJECTS_NOK_SIZE: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK_SIZE"); + break; + default: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK"); + break; + } + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + +/* calibration ---------------------------------------------------------------*/ +static void pattern_segmentate (void) +{ + proc_load_mem(0); + + proc_cvt_color(cv::COLOR_BGR2GRAY); + proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU); + proc_distance_transform(); + proc_local_max(); + proc_dilate(6); + proc_save_mem(1); +} + +static void pattern_len_pix (void) +{ + int i; + + proc_load_mem(1); + + /* Get pattern square side lenght in pixels */ + for (i = 0; i < objects_n; i++) { + proc_pixel_value(objects[i].x_pix, objects[i].y_pix, + &(objects[i].diameter_pix)); + objects[i].diameter_pix *= 2; + } +} + +static void calibrate_mm_per_pix (void) +{ + uint8_t pattern_size_pix [CONTOURS_MAX]; + int i; + int median_size; + + for (i = 0; i < objects_n; i++) { + pattern_size_pix[i] = objects[i].diameter_pix; + } + + median_size = alx_median_u8(objects_n, pattern_size_pix); + ratio_mm_per_pix = 10.0 / median_size; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "mm/pix = %lf", + ratio_mm_per_pix); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + +/* process -------------------------------------------------------------------*/ +static void objects_segmentate (void) +{ + proc_load_mem(0); + + proc_cvt_color(cv::COLOR_BGR2GRAY); + proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU); + proc_distance_transform(); + proc_threshold(cv::THRESH_BINARY, 20); + proc_save_mem(1); +} + +static int objects_contours (void) +{ + int status; + + proc_load_mem(1); + + proc_contours(&contours, &hierarchy); + objects_n = contours.size(); + + /* If no contour is found, error: NOK_OBJECTS */ + if (!objects_n) { + status = OBJECTS_NOK_OBJECTS; + return status; + } + + status = OBJECTS_OK; + return status; +} + +static void objects_position_pix (void) +{ + int i; + + /* Get position of each contour */ + for (i = 0; i < objects_n; i++) { + proc_min_area_rect(&(contours[i]), &(rectangle[i]), true); + + objects[i].x_pix = rectangle[i].center.x; + objects[i].y_pix = rectangle[i].center.y; + + if (rectangle[i].size.width > rectangle[i].size.height) { + objects[i].angle = rectangle[i].angle; + } else { + objects[i].angle = rectangle[i].angle + 90.0; + } + } +} + +static void objects_size_pix (void) +{ + double area [CONTOURS_MAX]; + double perimeter [CONTOURS_MAX]; + int i; + + /* Get size of each contour */ + proc_contours_size(&contours, area, perimeter); + for (i = 0; i < objects_n; i++) { + + objects[i].area_pix2 = area[i]; + objects[i].perimeter_pix = perimeter[i]; + + objects[i].ratio_p2_a = pow(perimeter[i], 2) / area[i]; + } +} + +static void objects_position_mm (void) +{ + int i; + + /* Get position of each contour */ + for (i = 0; i < objects_n; i++) { + objects[i].x_mm = ratio_mm_per_pix * objects[i].x_pix; + objects[i].y_mm = ratio_mm_per_pix * objects[i].y_pix; + } +} + +static void objects_size_mm (void) +{ + int i; + + /* Get position of each contour */ + for (i = 0; i < objects_n; i++) { + objects[i].area_mm2 = pow(ratio_mm_per_pix, 2) * + objects[i].area_pix2; + objects[i].perimeter_mm = ratio_mm_per_pix * + objects[i].perimeter_pix; + } +} + +static void objects_log (void) +{ + int i; + + /* Get coins diameters in mm */ + for (i = 0; i < objects_n; i++) { + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Object[%i]:", + i); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " pos: (%.1lf, %.1lf) mm", + objects[i].x_mm, objects[i].y_mm); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " ang = %.1lf DEG", + objects[i].angle); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " A = %.1lf mm2", + objects[i].area_mm2); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " P = %.1lf mm", + objects[i].perimeter_mm); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " p2/A = %.2lf", + objects[i].ratio_p2_a); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/tmp/Makefile b/modules/proc/tmp/Makefile index 83a4a01..f84422f 100644 --- a/modules/proc/tmp/Makefile +++ b/modules/proc/tmp/Makefile @@ -15,8 +15,9 @@ SRC_DIR = $(PROC_DIR)/src/ # dependencies -_ALL = proc_label.o proc_coins.o proc_resistor.o proc_common.o proc_iface.o -ALL = $(_ALL) proc_mod.o +_ALL = proc_label.o proc_objects.o proc_coins.o \ + proc_resistor.o proc_common.o proc_iface.o +ALL = $(_ALL) proc_mod.o PROC_LAB_INC_IMG = img_iface.hpp PROC_LAB_INC_USR = user_iface.hpp @@ -29,6 +30,20 @@ PROC_LAB_INC_DIRS = -I $(INC_DIR) \ -I $(IMG_INC_DIR) \ -I $(USR_INC_DIR) +PROC_OBJS_INC_LIBALX = alx_math.hpp +PROC_OBJS_INC_IMG = img_iface.hpp +PROC_OBJS_INC_USR = user_iface.hpp +PROC_OBJS_INC = proc_objects.hpp proc_common.hpp +PROC_OBJS_DEPS = $(SRC_DIR)/proc_objects.cpp \ + $(patsubst %,$(INC_DIR)/%,$(PROC_OBJS_INC)) \ + $(patsubst %,$(IMG_INC_DIR)/%,$(PROC_OBJS_INC_IMG)) \ + $(patsubst %,$(USR_INC_DIR)/%,$(PROC_OBJS_INC_USR)) \ + $(patsubst %,$(LIBALX_INC_DIR)/%,$(PROC_OBJS_INC_LIBALX)) +PROC_OBJS_INC_DIRS = -I $(INC_DIR) \ + -I $(IMG_INC_DIR) \ + -I $(USR_INC_DIR) \ + -I $(LIBALX_INC_DIR) + PROC_COIN_INC_LIBALX = alx_math.hpp PROC_COIN_INC_IMG = img_iface.hpp PROC_COIN_INC_USR = user_iface.hpp @@ -100,6 +115,13 @@ proc_label.o: proc_label.s $(PROC_LAB_DEPS) $(Q)$(AS) $< -o $@ @echo " AS $@" +proc_objects.s: $(PROC_OBJS_DEPS) + $(Q)$(CXX) $(CXXFLAGS) $(PROC_OBJS_INC_DIRS) -S $< -o $@ + @echo " CXX $@" +proc_objects.o: proc_objects.s $(PROC_OBJS_DEPS) + $(Q)$(AS) $< -o $@ + @echo " AS $@" + proc_coins.s: $(PROC_COIN_DEPS) $(Q)$(CXX) $(CXXFLAGS) $(PROC_COIN_INC_DIRS) -S $< -o $@ @echo " CXX $@" diff --git a/modules/save/inc/save.h b/modules/save/inc/save.h index 1badd38..dc0d850 100644 --- a/modules/save/inc/save.h +++ b/modules/save/inc/save.h @@ -27,6 +27,8 @@ # define USER_SAVED_DIR "vision-artificial/saved/" # define USER_LABELS_DIR "vision-artificial/labels/" # define USER_LABELS_FAIL_DIR "vision-artificial/labels/fail" + # define USER_OBJECTS_DIR "vision-artificial/objects/" + # define USER_OBJECTS_FAIL_DIR "vision-artificial/objects/fail" # define USER_COINS_DIR "vision-artificial/coins/" # define USER_COINS_FAIL_DIR "vision-artificial/coins/fail" # define USER_RESISTORS_DIR "vision-artificial/resistors/" @@ -42,6 +44,8 @@ extern char saved_path [FILENAME_MAX]; extern char labels_path [FILENAME_MAX]; extern char labels_fail_path [FILENAME_MAX]; + extern char objects_path [FILENAME_MAX]; + extern char objects_fail_path [FILENAME_MAX]; extern char coins_path [FILENAME_MAX]; extern char coins_fail_path [FILENAME_MAX]; extern char resistors_path [FILENAME_MAX]; diff --git a/modules/save/inc/save.hpp b/modules/save/inc/save.hpp index 41a79fb..edabbf3 100644 --- a/modules/save/inc/save.hpp +++ b/modules/save/inc/save.hpp @@ -37,6 +37,8 @@ extern "C" { # define USER_SAVED_DIR "vision-artificial/saved/" # define USER_LABELS_DIR "vision-artificial/labels/" # define USER_LABELS_FAIL_DIR "vision-artificial/labels/fail" + # define USER_OBJECTS_DIR "vision-artificial/objects/" + # define USER_OBJECTS_FAIL_DIR "vision-artificial/objects/fail" # define USER_COINS_DIR "vision-artificial/coins/" # define USER_COINS_FAIL_DIR "vision-artificial/coins/fail" # define USER_RESISTORS_DIR "vision-artificial/resistors/" @@ -53,6 +55,8 @@ extern "C" { extern char saved_path [FILENAME_MAX]; extern char labels_path [FILENAME_MAX]; extern char labels_fail_path [FILENAME_MAX]; + extern char objects_path [FILENAME_MAX]; + extern char objects_fail_path [FILENAME_MAX]; extern char coins_path [FILENAME_MAX]; extern char coins_fail_path [FILENAME_MAX]; extern char resistors_path [FILENAME_MAX]; diff --git a/modules/save/src/save.cpp b/modules/save/src/save.cpp index ca79250..861a06e 100644 --- a/modules/save/src/save.cpp +++ b/modules/save/src/save.cpp @@ -39,6 +39,8 @@ char user_prog_path [FILENAME_MAX]; char saved_path [FILENAME_MAX]; char labels_path [FILENAME_MAX]; char labels_fail_path [FILENAME_MAX]; +char objects_path [FILENAME_MAX]; +char objects_fail_path [FILENAME_MAX]; char coins_path [FILENAME_MAX]; char coins_fail_path [FILENAME_MAX]; char resistors_path [FILENAME_MAX]; @@ -56,6 +58,8 @@ void save_init (void) snprintf(saved_path, FILENAME_MAX, "%s/%s/", home_path, USER_SAVED_DIR); snprintf(labels_path, FILENAME_MAX, "%s/%s/", home_path, USER_LABELS_DIR); snprintf(labels_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_LABELS_FAIL_DIR); + snprintf(objects_path, FILENAME_MAX, "%s/%s/", home_path, USER_OBJECTS_DIR); + snprintf(objects_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_OBJECTS_FAIL_DIR); snprintf(coins_path, FILENAME_MAX, "%s/%s/", home_path, USER_COINS_DIR); snprintf(coins_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_COINS_FAIL_DIR); snprintf(resistors_path, FILENAME_MAX, "%s/%s/", home_path, USER_RESISTORS_DIR); diff --git a/modules/user/inc/user_iface.h b/modules/user/inc/user_iface.h index 2034e22..24cfccb 100644 --- a/modules/user/inc/user_iface.h +++ b/modules/user/inc/user_iface.h @@ -35,9 +35,9 @@ }; enum Player_Iface_Action { - USER_IFACE_ACT_FOO = 0, + USER_IFACE_ACT_FOO = 0x000000u, - USER_IFACE_ACT_ALX = 0x0010, + USER_IFACE_ACT_ALX = 0x000010u, USER_IFACE_ACT_LOCAL_MAX, USER_IFACE_ACT_LINES_HORIZONTAL, USER_IFACE_ACT_LINES_VERTICAL, @@ -46,7 +46,7 @@ USER_IFACE_ACT_MEDIAN_HORIZONTAL, USER_IFACE_ACT_MEDIAN_VERTICAL, - USER_IFACE_ACT_CV = 0x0100, + USER_IFACE_ACT_CV = 0x000100u, USER_IFACE_ACT_PIXEL_VALUE, USER_IFACE_ACT_SET_ROI, USER_IFACE_ACT_SET_ROI_2RECT, @@ -76,32 +76,41 @@ USER_IFACE_ACT_MIN_AREA_RECT, USER_IFACE_ACT_HOUGH_CIRCLES, - USER_IFACE_ACT_ZB = 0x0200, + USER_IFACE_ACT_ORB = 0x000200u, + USER_IFACE_ACT_ALIGN, + + USER_IFACE_ACT_CALIB3D = 0x000400u, + USER_IFACE_ACT_CALIBRATE, + USER_IFACE_ACT_UNDISTORT, + + USER_IFACE_ACT_ZB = 0x000800u, USER_IFACE_ACT_DECODE, - USER_IFACE_ACT_OCR = 0x0400, + USER_IFACE_ACT_OCR = 0x001000u, USER_IFACE_ACT_READ, - USER_IFACE_ACT_ORB = 0x0800, - USER_IFACE_ACT_ALIGN, - - USER_IFACE_ACT_IMGI = 0x1000, + USER_IFACE_ACT_IMGI = 0x002000u, USER_IFACE_ACT_APPLY, USER_IFACE_ACT_DISCARD, USER_IFACE_ACT_SAVE_MEM, USER_IFACE_ACT_LOAD_MEM, USER_IFACE_ACT_SAVE_REF, - USER_IFACE_ACT_SAVE = 0x2000, + USER_IFACE_ACT_SAVE = 0x004000u, USER_IFACE_ACT_SAVE_FILE, USER_IFACE_ACT_SAVE_UPDT, - USER_IFACE_ACT_PROC = 0x4000, - USER_IFACE_ACT_PROC_LABEL, - USER_IFACE_ACT_PROC_COINS, - USER_IFACE_ACT_PROC_RESISTOR, - - USER_IFACE_ACT_USRI = 0x8000, + USER_IFACE_ACT_PROC = 0x008000u, + USER_IFACE_ACT_PROC_LABEL_SERIES, + USER_IFACE_ACT_PROC_LABEL_CALIB, + USER_IFACE_ACT_PROC_OBJECTS_SERIES, + USER_IFACE_ACT_PROC_OBJECTS_CALIB, + USER_IFACE_ACT_PROC_COINS_SERIES, + USER_IFACE_ACT_PROC_COINS_CALIB, + USER_IFACE_ACT_PROC_RESISTOR_SERIES, + USER_IFACE_ACT_PROC_RESISTOR_CALIB, + + USER_IFACE_ACT_USRI = 0x010000u, USER_IFACE_ACT_SHOW_OCR, USER_IFACE_ACT_QUIT }; diff --git a/modules/user/inc/user_iface.hpp b/modules/user/inc/user_iface.hpp index 76e16dc..ce241b2 100644 --- a/modules/user/inc/user_iface.hpp +++ b/modules/user/inc/user_iface.hpp @@ -35,9 +35,9 @@ }; enum Player_Iface_Action { - USER_IFACE_ACT_FOO = 0, + USER_IFACE_ACT_FOO = 0x000000u, - USER_IFACE_ACT_ALX = 0x0010, + USER_IFACE_ACT_ALX = 0x000010u, USER_IFACE_ACT_LOCAL_MAX, USER_IFACE_ACT_LINES_HORIZONTAL, USER_IFACE_ACT_LINES_VERTICAL, @@ -46,7 +46,7 @@ USER_IFACE_ACT_MEDIAN_HORIZONTAL, USER_IFACE_ACT_MEDIAN_VERTICAL, - USER_IFACE_ACT_CV = 0x0100, + USER_IFACE_ACT_CV = 0x000100u, USER_IFACE_ACT_PIXEL_VALUE, USER_IFACE_ACT_SET_ROI, USER_IFACE_ACT_SET_ROI_2RECT, @@ -76,32 +76,41 @@ USER_IFACE_ACT_MIN_AREA_RECT, USER_IFACE_ACT_HOUGH_CIRCLES, - USER_IFACE_ACT_ZB = 0x0200, + USER_IFACE_ACT_ORB = 0x000200u, + USER_IFACE_ACT_ALIGN, + + USER_IFACE_ACT_CALIB3D = 0x000400u, + USER_IFACE_ACT_CALIBRATE, + USER_IFACE_ACT_UNDISTORT, + + USER_IFACE_ACT_ZB = 0x000800u, USER_IFACE_ACT_DECODE, - USER_IFACE_ACT_OCR = 0x0400, + USER_IFACE_ACT_OCR = 0x001000u, USER_IFACE_ACT_READ, - USER_IFACE_ACT_ORB = 0x0800, - USER_IFACE_ACT_ALIGN, - - USER_IFACE_ACT_IMGI = 0x1000, + USER_IFACE_ACT_IMGI = 0x002000u, USER_IFACE_ACT_APPLY, USER_IFACE_ACT_DISCARD, USER_IFACE_ACT_SAVE_MEM, USER_IFACE_ACT_LOAD_MEM, USER_IFACE_ACT_SAVE_REF, - USER_IFACE_ACT_SAVE = 0x2000, + USER_IFACE_ACT_SAVE = 0x004000u, USER_IFACE_ACT_SAVE_FILE, USER_IFACE_ACT_SAVE_UPDT, - USER_IFACE_ACT_PROC = 0x4000, - USER_IFACE_ACT_PROC_LABEL, - USER_IFACE_ACT_PROC_COINS, - USER_IFACE_ACT_PROC_RESISTOR, - - USER_IFACE_ACT_USRI = 0x8000, + USER_IFACE_ACT_PROC = 0x008000u, + USER_IFACE_ACT_PROC_LABEL_SERIES, + USER_IFACE_ACT_PROC_LABEL_CALIB, + USER_IFACE_ACT_PROC_OBJECTS_SERIES, + USER_IFACE_ACT_PROC_OBJECTS_CALIB, + USER_IFACE_ACT_PROC_COINS_SERIES, + USER_IFACE_ACT_PROC_COINS_CALIB, + USER_IFACE_ACT_PROC_RESISTOR_SERIES, + USER_IFACE_ACT_PROC_RESISTOR_CALIB, + + USER_IFACE_ACT_USRI = 0x010000u, USER_IFACE_ACT_SHOW_OCR, USER_IFACE_ACT_QUIT }; diff --git a/modules/user/src/user_clui.c b/modules/user/src/user_clui.c index fffc79f..28ef1e5 100644 --- a/modules/user/src/user_clui.c +++ b/modules/user/src/user_clui.c @@ -142,9 +142,24 @@ static int usr_input (void) /* Exercises from class */ switch (ch[1]) { case '1': + /* Label */ + switch (ch[2]) { + case '1': + action = USER_IFACE_ACT_PROC_LABEL_SERIES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* Objects */ switch (ch[2]) { case '0': - action = USER_IFACE_ACT_PROC_LABEL; + action = USER_IFACE_ACT_PROC_OBJECTS_CALIB; + break; + case '1': + action = USER_IFACE_ACT_PROC_OBJECTS_SERIES; break; default: action = USER_IFACE_ACT_FOO; @@ -152,9 +167,10 @@ static int usr_input (void) } break; case '3': + /* Coins */ switch (ch[2]) { - case '0': - action = USER_IFACE_ACT_PROC_COINS; + case '1': + action = USER_IFACE_ACT_PROC_COINS_SERIES; break; default: action = USER_IFACE_ACT_FOO; @@ -162,9 +178,10 @@ static int usr_input (void) } break; case '4': + /* Resistor */ switch (ch[2]) { - case '0': - action = USER_IFACE_ACT_PROC_RESISTOR; + case '1': + action = USER_IFACE_ACT_PROC_RESISTOR_SERIES; break; default: action = USER_IFACE_ACT_FOO; @@ -417,6 +434,20 @@ static int usr_input (void) } break; case '3': + /* img_calib3d */ + switch (ch[2]) { + case '0': + action = USER_IFACE_ACT_CALIBRATE; + break; + case '1': + action = USER_IFACE_ACT_UNDISTORT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '4': /* img_zbar */ switch (ch[2]) { case '0': @@ -427,7 +458,7 @@ static int usr_input (void) break; } break; - case '4': + case '5': /* img_ocr */ switch (ch[2]) { case '0': @@ -546,12 +577,16 @@ static void show_help (void) printf(" - Min. area rectangle: %s\n", "f1144"); printf(" - Hough circles: %s\n", "f1150"); printf(" - Align 2ref (ORB): %s\n", "f20"); - printf(" - Scan codes (ZBAR): %s\n", "f30"); - printf(" - Scan text (OCR): %s\n", "f40"); + printf(" - Calibrate (Calib3d): %s\n", "f30"); + printf(" - Undistort (Calib3d): %s\n", "f31"); + printf(" - Scan codes (ZBAR): %s\n", "f40"); + printf(" - Scan text (OCR): %s\n", "f50"); printf("Exercises:\n"); - printf(" - Label: %s\n", "e10"); - printf(" - Coins: %s\n", "e30"); - printf(" - Resistor: %s\n", "e40"); + printf(" - Label: %s\n", "e11"); + printf(" - Objects (calib): %s\n", "e20"); + printf(" - Objects: %s\n", "e21"); + printf(" - Coins: %s\n", "e31"); + printf(" - Resistor: %s\n", "e41"); printf("Other:\n"); printf(" - Show OCR text: %s\n", "u1"); printf("Quit: %c\n", 'q'); diff --git a/modules/user/src/user_iface.c b/modules/user/src/user_iface.c index 0dd0d85..629dfd8 100644 --- a/modules/user/src/user_iface.c +++ b/modules/user/src/user_iface.c @@ -108,14 +108,7 @@ void user_iface (void) } /* Do action */ - switch (user_action & 0xF000) { - case USER_IFACE_ACT_PROC: - proc_iface_single(user_action); - break; - default: - user_iface_act(user_action); - break; - } + user_iface_act(user_action); } while (user_action != USER_IFACE_ACT_QUIT); } @@ -206,6 +199,10 @@ void user_iface_act (int action) /* do nothing */ break; } + + } else if (action & USER_IFACE_ACT_PROC) { + proc_iface_single(action); + } else { img_iface_act_nodata(action); } diff --git a/modules/user/src/user_tui.c b/modules/user/src/user_tui.c index 4231753..d12137c 100644 --- a/modules/user/src/user_tui.c +++ b/modules/user/src/user_tui.c @@ -224,9 +224,25 @@ static int usr_input (void) /* Label */ ch = wgetch(win_log); + switch (ch) { + case '1': + action = USER_IFACE_ACT_PROC_LABEL_SERIES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* Objects */ + ch = wgetch(win_log); + switch (ch) { case '0': - action = USER_IFACE_ACT_PROC_LABEL; + action = USER_IFACE_ACT_PROC_OBJECTS_CALIB; + break; + case '1': + action = USER_IFACE_ACT_PROC_OBJECTS_SERIES; break; default: action = USER_IFACE_ACT_FOO; @@ -234,12 +250,12 @@ static int usr_input (void) } break; case '3': - /* Resistor */ + /* Coins */ ch = wgetch(win_log); switch (ch) { - case '0': - action = USER_IFACE_ACT_PROC_COINS; + case '1': + action = USER_IFACE_ACT_PROC_COINS_SERIES; break; default: action = USER_IFACE_ACT_FOO; @@ -251,8 +267,8 @@ static int usr_input (void) ch = wgetch(win_log); switch (ch) { - case '0': - action = USER_IFACE_ACT_PROC_RESISTOR; + case '1': + action = USER_IFACE_ACT_PROC_RESISTOR_SERIES; break; default: action = USER_IFACE_ACT_FOO; @@ -539,6 +555,22 @@ static int usr_input (void) } break; case '3': + /* img_calib3d */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_CALIBRATE; + break; + case '1': + action = USER_IFACE_ACT_UNDISTORT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '4': /* img_zbar */ ch = wgetch(win_log); @@ -551,7 +583,7 @@ static int usr_input (void) break; } break; - case '4': + case '5': /* img_ocr */ ch = wgetch(win_log); @@ -655,9 +687,9 @@ static void show_help (void) mvwprintw(win_help, r++, c, "Functions:"); mvwprintw(win_help, r++, c, " - Local maxima: %s", "f00"); mvwprintw(win_help, r++, c, " - Horizontal lines: %s", "f010"); - mvwprintw(win_help, r++, c, " - Vertical lines: %s", "f011"); + mvwprintw(win_help, r++, c, " - Vertical lines: %s", "f011"); mvwprintw(win_help, r++, c, " - Horizontal mean: %s", "f020"); - mvwprintw(win_help, r++, c, " - Vertical mean: %s", "f021"); + mvwprintw(win_help, r++, c, " - Vertical mean: %s", "f021"); mvwprintw(win_help, r++, c, " - Horizontal median: %s", "f022"); mvwprintw(win_help, r++, c, " - Vertical median: %s", "f023"); mvwprintw(win_help, r++, c, " - Pixel value: %s", "f1000"); @@ -689,12 +721,16 @@ static void show_help (void) mvwprintw(win_help, r++, c, " - Min. area rectangle: %s", "f1144"); mvwprintw(win_help, r++, c, " - Hough circles: %s", "f1150"); mvwprintw(win_help, r++, c, " - Align 2ref (ORB): %s", "f20"); - mvwprintw(win_help, r++, c, " - Scan codes (ZBAR): %s", "f30"); - mvwprintw(win_help, r++, c, " - Scan text (OCR): %s", "f40"); + mvwprintw(win_help, r++, c, " - Calibrate (Calib3d): %s", "f30"); + mvwprintw(win_help, r++, c, " - Undistort (Calib3d): %s", "f31"); + mvwprintw(win_help, r++, c, " - Scan codes (ZBAR): %s", "f40"); + mvwprintw(win_help, r++, c, " - Scan text (OCR): %s", "f50"); mvwprintw(win_help, r++, c, "Exercises:"); - mvwprintw(win_help, r++, c, " - Label: %s", "e10"); - mvwprintw(win_help, r++, c, " - Coins: %s", "e30"); - mvwprintw(win_help, r++, c, " - Resistor: %s", "e40"); + mvwprintw(win_help, r++, c, " - Label: %s", "e11"); + mvwprintw(win_help, r++, c, " - Objects (calib): %s", "e20"); + mvwprintw(win_help, r++, c, " - Objects: %s", "e21"); + mvwprintw(win_help, r++, c, " - Coins: %s", "e31"); + mvwprintw(win_help, r++, c, " - Resistor: %s", "e41"); mvwprintw(win_help, r++, c, "Other:"); mvwprintw(win_help, r++, c, " - Show OCR: %s", "u1"); mvwprintw(win_help, r++, c, "Quit: %c", 'q'); -- cgit v1.2.3 From d10eea51fe4cc9b372d52c8e1aac581309a5569c Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Tue, 11 Dec 2018 01:35:04 +0100 Subject: Add function to get skeleton from distance transform --- modules/image/inc/img_alx.hpp | 1 + modules/image/inc/img_iface.h | 1 + modules/image/inc/img_iface.hpp | 1 + modules/image/src/img_alx.cpp | 99 +++++++++++++++++++++++++++++++++++++---- modules/image/src/img_iface.cpp | 27 +++++++++++ modules/user/inc/user_iface.h | 1 + modules/user/inc/user_iface.hpp | 1 + modules/user/src/user_clui.c | 16 ++++++- modules/user/src/user_tui.c | 18 +++++++- 9 files changed, 153 insertions(+), 12 deletions(-) diff --git a/modules/image/inc/img_alx.hpp b/modules/image/inc/img_alx.hpp index ec84ab3..9476ef8 100644 --- a/modules/image/inc/img_alx.hpp +++ b/modules/image/inc/img_alx.hpp @@ -25,6 +25,7 @@ IMG_ALX_ACT_ALX = 0x000010u, IMG_ALX_ACT_LOCAL_MAX, + IMG_ALX_ACT_SKELETON, IMG_ALX_ACT_LINES_HORIZONTAL, IMG_ALX_ACT_LINES_VERTICAL, IMG_ALX_ACT_MEAN_HORIZONTAL, diff --git a/modules/image/inc/img_iface.h b/modules/image/inc/img_iface.h index cc08ef3..f23991b 100644 --- a/modules/image/inc/img_iface.h +++ b/modules/image/inc/img_iface.h @@ -33,6 +33,7 @@ IMG_IFACE_ACT_ALX = 0x000010u, IMG_IFACE_ACT_LOCAL_MAX, + IMG_IFACE_ACT_SKELETON, IMG_IFACE_ACT_LINES_HORIZONTAL, IMG_IFACE_ACT_LINES_VERTICAL, IMG_IFACE_ACT_MEAN_HORIZONTAL, diff --git a/modules/image/inc/img_iface.hpp b/modules/image/inc/img_iface.hpp index 1baaed7..f17c609 100644 --- a/modules/image/inc/img_iface.hpp +++ b/modules/image/inc/img_iface.hpp @@ -43,6 +43,7 @@ IMG_IFACE_ACT_ALX = 0x000010u, IMG_IFACE_ACT_LOCAL_MAX, + IMG_IFACE_ACT_SKELETON, IMG_IFACE_ACT_LINES_HORIZONTAL, IMG_IFACE_ACT_LINES_VERTICAL, IMG_IFACE_ACT_MEAN_HORIZONTAL, diff --git a/modules/image/src/img_alx.cpp b/modules/image/src/img_alx.cpp index 881c178..b068801 100644 --- a/modules/image/src/img_alx.cpp +++ b/modules/image/src/img_alx.cpp @@ -9,6 +9,8 @@ /* Standard C ----------------------------------------------------------------*/ /* true & false */ #include + /* abs() */ + #include /* snprintf() */ #include @@ -31,6 +33,7 @@ ******* static functions ***************************************************** ******************************************************************************/ static void img_alx_local_max (class cv::Mat *imgptr); +static void img_alx_skeleton (class cv::Mat *imgptr); static void img_alx_lines_horizontal (class cv::Mat *imgptr); static void img_alx_lines_vertical (class cv::Mat *imgptr); static void img_alx_mean_horizontal (class cv::Mat *imgptr); @@ -48,6 +51,9 @@ void img_alx_act (class cv::Mat *imgptr, int action, void *data) case IMG_ALX_ACT_LOCAL_MAX: img_alx_local_max(imgptr); break; + case IMG_ALX_ACT_SKELETON: + img_alx_skeleton(imgptr); + break; case IMG_ALX_ACT_LINES_HORIZONTAL: img_alx_lines_horizontal(imgptr); @@ -82,8 +88,10 @@ static void img_alx_local_max (class cv::Mat *imgptr) int k; int l; bool local_max; - int dist_min; - int val_min; + /* Minimum distance between local maxima */ + const int dist_min = 16; + /* Minimum value of local maxima */ + const int val_min = 16; class cv::Mat imgtmp; /* pointer to a pixel (in imgptr) */ @@ -95,10 +103,6 @@ static void img_alx_local_max (class cv::Mat *imgptr) /* Tmp image copy */ imgptr->copyTo(imgtmp); - /* Minimum distance between local maxima */ - dist_min = 16; - /* Minimum value of local maxima */ - val_min = 16; for (i = 0; i < imgptr->rows; i++) { for (j = 0; j < imgptr->cols; j++) { @@ -113,8 +117,8 @@ static void img_alx_local_max (class cv::Mat *imgptr) for (k = i - dist_min; (k < i + dist_min+1) && local_max; k++) { for (l = j - dist_min; (l < j + dist_min+1) && local_max; l++) { near_pix = imgptr->data + k * imgptr->step + l; - if (k >= 0 && k < imgptr->rows) { - if (l >= 0 && l < imgptr->cols) { + if ((k >= 0) && (k < imgptr->rows)) { + if ((l >= 0) && (l < imgptr->cols)) { if (*img_pix < *near_pix) { local_max = false; } @@ -136,6 +140,85 @@ static void img_alx_local_max (class cv::Mat *imgptr) imgtmp.release(); } +static void img_alx_skeleton (class cv::Mat *imgptr) +{ + int i; + int j; + int k; + int l; + int r; + int dist_x; + int dist_y; + /* Width of the skeleton */ + const int width = 5; + /* Minimum value of the skeleton */ + bool skeleton; + int cnt_lo [width]; + int cnt_hi_or_eq [width]; + class cv::Mat imgtmp; + + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + /* pointer to a pixel near img_pix (in imgptr) */ + uint8_t *near_pix; + /* pointer to a pixel (same position as img_pix, but in imgtmp) */ + uint8_t *tmp_pix; + + /* Tmp image copy */ + imgptr->copyTo(imgtmp); + + for (i = 0; i < imgptr->rows; i++) { + for (j = 0; j < imgptr->cols; j++) { + img_pix = imgptr->data + i * imgptr->step + j; + tmp_pix = imgtmp.data + i * imgptr->step + j; + + for (r = 0; r < width; r++) { + cnt_lo[r] = 0; + cnt_hi_or_eq[r] = 0; + } + skeleton = false; + + for (k = i - width; k <= i + width; k++) { + for (l = j - width; l <= j + width; l++) { + near_pix = imgptr->data + k * imgptr->step + l; + + dist_x = abs(k - i); + dist_y = abs(l - j); + + if ((k >= 0) && (k < imgptr->rows)) { + if ((l >= 0) && (l < imgptr->cols)) { + if (dist_x || dist_y) { + if (*near_pix < *img_pix) { + cnt_lo[std::max(dist_x, dist_y)]++; + } else { + cnt_hi_or_eq[std::max(dist_x, dist_y)]++; + } + } + } + } + + } + } + + for (r = 0; r < width; r++) { + if (cnt_lo[r] > (cnt_hi_or_eq[r] + (1.6) * (r + 1))) { + skeleton = true; + } + } + + if (skeleton) { + *tmp_pix = *img_pix; + } else { + *tmp_pix = 0; + } + } + } + + /* Cleanup */ + imgtmp.copyTo(*imgptr); + imgtmp.release(); +} + static void img_alx_lines_horizontal (class cv::Mat *imgptr) { int i; diff --git a/modules/image/src/img_iface.cpp b/modules/image/src/img_iface.cpp index c7b516c..6f80249 100644 --- a/modules/image/src/img_iface.cpp +++ b/modules/image/src/img_iface.cpp @@ -90,6 +90,7 @@ static class std::vector tvecs; ******************************************************************************/ /* img_alx */ static void img_iface_local_max (void); +static void img_iface_skeleton (void); static void img_iface_lines_horizontal (void); static void img_iface_lines_vertical (void); static void img_iface_mean_horizontal (void); @@ -238,6 +239,9 @@ void img_iface_act (int action, void *data) case IMG_IFACE_ACT_LOCAL_MAX: img_iface_local_max(); break; + case IMG_IFACE_ACT_SKELETON: + img_iface_skeleton(); + break; case IMG_IFACE_ACT_LINES_HORIZONTAL: img_iface_lines_horizontal(); break; @@ -454,6 +458,29 @@ static void img_iface_local_max (void) (user_iface_log.len)++; } +static void img_iface_skeleton (void) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Skeleton */ + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_SKELETON, NULL); + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Skeleton"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + static void img_iface_lines_horizontal (void) { /* Must have 1 channel */ diff --git a/modules/user/inc/user_iface.h b/modules/user/inc/user_iface.h index 24cfccb..6e3de47 100644 --- a/modules/user/inc/user_iface.h +++ b/modules/user/inc/user_iface.h @@ -39,6 +39,7 @@ USER_IFACE_ACT_ALX = 0x000010u, USER_IFACE_ACT_LOCAL_MAX, + USER_IFACE_ACT_SKELETON, USER_IFACE_ACT_LINES_HORIZONTAL, USER_IFACE_ACT_LINES_VERTICAL, USER_IFACE_ACT_MEAN_HORIZONTAL, diff --git a/modules/user/inc/user_iface.hpp b/modules/user/inc/user_iface.hpp index ce241b2..90c63b6 100644 --- a/modules/user/inc/user_iface.hpp +++ b/modules/user/inc/user_iface.hpp @@ -39,6 +39,7 @@ USER_IFACE_ACT_ALX = 0x000010u, USER_IFACE_ACT_LOCAL_MAX, + USER_IFACE_ACT_SKELETON, USER_IFACE_ACT_LINES_HORIZONTAL, USER_IFACE_ACT_LINES_VERTICAL, USER_IFACE_ACT_MEAN_HORIZONTAL, diff --git a/modules/user/src/user_clui.c b/modules/user/src/user_clui.c index 28ef1e5..55fb3aa 100644 --- a/modules/user/src/user_clui.c +++ b/modules/user/src/user_clui.c @@ -201,7 +201,18 @@ static int usr_input (void) /* img_alx */ switch (ch[2]) { case '0': - action = USER_IFACE_ACT_LOCAL_MAX; + /* Distance transform postprocessing */ + switch (ch[3]) { + case '0': + action = USER_IFACE_ACT_LOCAL_MAX; + break; + case '1': + action = USER_IFACE_ACT_SKELETON; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } break; case '1': /* Lines */ @@ -541,7 +552,8 @@ static void show_help (void) printf("Save to ref: %c\n", 'r'); printf("Save to file: %c\n", 's'); printf("Functions:\n"); - printf(" - Local maxima: %s\n", "f00"); + printf(" - Local maxima: %s\n", "f000"); + printf(" - Skeleton: %s\n", "f001"); printf(" - Horizontal lines: %s\n", "f010"); printf(" - Vertical lines: %s\n", "f011"); printf(" - Horizontal mean: %s\n", "f020"); diff --git a/modules/user/src/user_tui.c b/modules/user/src/user_tui.c index d12137c..d3b9ca7 100644 --- a/modules/user/src/user_tui.c +++ b/modules/user/src/user_tui.c @@ -292,7 +292,20 @@ static int usr_input (void) switch (ch) { case '0': - action = USER_IFACE_ACT_LOCAL_MAX; + /* Distance transform postprocessing */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_LOCAL_MAX; + break; + case '1': + action = USER_IFACE_ACT_SKELETON; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } break; case '1': /* Lines */ @@ -685,7 +698,8 @@ 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, " - Local maxima: %s", "f00"); + mvwprintw(win_help, r++, c, " - Local maxima: %s", "f000"); + mvwprintw(win_help, r++, c, " - Skeleton: %s", "f001"); mvwprintw(win_help, r++, c, " - Horizontal lines: %s", "f010"); mvwprintw(win_help, r++, c, " - Vertical lines: %s", "f011"); mvwprintw(win_help, r++, c, " - Horizontal mean: %s", "f020"); -- cgit v1.2.3 From 823a190a7b214d2d3e0f7119676cbe4eb4f731a0 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Tue, 11 Dec 2018 01:35:28 +0100 Subject: Use skeleton to improve proc_objects --- modules/proc/inc/proc_common.hpp | 1 + modules/proc/src/proc_coins.cpp | 2 - modules/proc/src/proc_common.cpp | 7 +++ modules/proc/src/proc_objects.cpp | 122 ++++++++++++++++++++++++++------------ 4 files changed, 93 insertions(+), 39 deletions(-) diff --git a/modules/proc/inc/proc_common.hpp b/modules/proc/inc/proc_common.hpp index f21e530..ff3a69e 100644 --- a/modules/proc/inc/proc_common.hpp +++ b/modules/proc/inc/proc_common.hpp @@ -42,6 +42,7 @@ extern "C" { void proc_save_update (void); void proc_local_max (void); + void proc_skeleton (void); void proc_lines_vertical (void); void proc_median_horizontal (void); void proc_median_vertical (void); diff --git a/modules/proc/src/proc_coins.cpp b/modules/proc/src/proc_coins.cpp index 61b7612..35922e3 100644 --- a/modules/proc/src/proc_coins.cpp +++ b/modules/proc/src/proc_coins.cpp @@ -215,9 +215,7 @@ static void coins_segmentate (void) proc_load_mem(0); proc_cmp(IMG_IFACE_CMP_BLUE); -// proc_smooth(IMGI_SMOOTH_MEDIAN, 11); proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU); -// proc_threshold(cv::THRESH_BINARY_INV, 100); proc_distance_transform(); proc_local_max(); proc_dilate(6); diff --git a/modules/proc/src/proc_common.cpp b/modules/proc/src/proc_common.cpp index a4ebfeb..faa9cdf 100644 --- a/modules/proc/src/proc_common.cpp +++ b/modules/proc/src/proc_common.cpp @@ -88,6 +88,13 @@ void proc_local_max (void) proc_show_img(); } +void proc_skeleton (void) +{ + img_iface_act(IMG_IFACE_ACT_SKELETON, NULL); + + proc_show_img(); +} + void proc_lines_vertical (void) { img_iface_act(IMG_IFACE_ACT_LINES_VERTICAL, NULL); diff --git a/modules/proc/src/proc_objects.cpp b/modules/proc/src/proc_objects.cpp index 692ae34..5803f11 100644 --- a/modules/proc/src/proc_objects.cpp +++ b/modules/proc/src/proc_objects.cpp @@ -46,6 +46,9 @@ struct Objects_Properties { double x_mm; double y_mm; + /* Calibration */ + int8_t value; + /* Angle */ double angle; @@ -59,7 +62,10 @@ struct Objects_Properties { /* type */ double ratio_p2_a; - int8_t value; + double area_rect; + double ratio_a_arect; + double perimeter_rect; + double ratio_p_prect; /* diammeter */ uint8_t diameter_pix; @@ -114,7 +120,7 @@ int proc_objects_calibrate (void) pattern_segmentate(); /* Measure time */ - clock_stop("Segmentate coins"); + clock_stop("Segmentate pattern squares"); } /* Find coins positions */ { @@ -257,14 +263,14 @@ static void pattern_segmentate (void) proc_distance_transform(); proc_local_max(); proc_dilate(6); - proc_save_mem(1); + proc_save_mem(3); } static void pattern_len_pix (void) { int i; - proc_load_mem(1); + proc_load_mem(3); /* Get pattern square side lenght in pixels */ for (i = 0; i < objects_n; i++) { @@ -302,16 +308,30 @@ static void objects_segmentate (void) proc_cvt_color(cv::COLOR_BGR2GRAY); proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU); - proc_distance_transform(); - proc_threshold(cv::THRESH_BINARY, 20); + proc_dilate_erode(3); + proc_erode_dilate(3); proc_save_mem(1); + + proc_distance_transform(); + proc_threshold(cv::THRESH_BINARY_INV, 30); + proc_distance_transform(); + proc_skeleton(); + proc_threshold(cv::THRESH_BINARY_INV, 10); + proc_save_ref(); + proc_save_mem(2); + + proc_load_mem(1); + proc_and_2ref(); + proc_distance_transform(); + proc_threshold(cv::THRESH_BINARY, 5); + proc_save_mem(3); } static int objects_contours (void) { int status; - proc_load_mem(1); + proc_load_mem(3); proc_contours(&contours, &hierarchy); objects_n = contours.size(); @@ -336,12 +356,6 @@ static void objects_position_pix (void) objects[i].x_pix = rectangle[i].center.x; objects[i].y_pix = rectangle[i].center.y; - - if (rectangle[i].size.width > rectangle[i].size.height) { - objects[i].angle = rectangle[i].angle; - } else { - objects[i].angle = rectangle[i].angle + 90.0; - } } } @@ -359,6 +373,24 @@ static void objects_size_pix (void) objects[i].perimeter_pix = perimeter[i]; objects[i].ratio_p2_a = pow(perimeter[i], 2) / area[i]; + + + if (rectangle[i].size.width > rectangle[i].size.height) { + objects[i].angle = rectangle[i].angle; + } else { + objects[i].angle = rectangle[i].angle + 90.0; + + } + objects[i].area_rect = rectangle[i].size.width * + rectangle[i].size.height; + objects[i].perimeter_rect = 2.0 * + (rectangle[i].size.width + + rectangle[i].size.height); + + objects[i].ratio_p_prect = objects[i].perimeter_pix / + objects[i].perimeter_rect; + objects[i].ratio_a_arect = objects[i].area_pix2 / + objects[i].area_rect; } } @@ -392,47 +424,63 @@ static void objects_log (void) /* Get coins diameters in mm */ for (i = 0; i < objects_n; i++) { - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + if (objects[i].area_mm2 > 100) { + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Object[%i]:", i); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, " pos: (%.1lf, %.1lf) mm", objects[i].x_mm, objects[i].y_mm); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, " ang = %.1lf DEG", objects[i].angle); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, " A = %.1lf mm2", objects[i].area_mm2); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, " P = %.1lf mm", objects[i].perimeter_mm); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, " p2/A = %.2lf", objects[i].ratio_p2_a); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " p/p_r = %.2lf", + objects[i].ratio_p_prect); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " A/A_r = %.2lf", + objects[i].ratio_a_arect); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + } } } -- cgit v1.2.3 From b301e76cb340555ffc0974d4895f1c67e2287d90 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Tue, 11 Dec 2018 12:19:14 +0100 Subject: Improve proc_objects: calibrate angle --- libalx | 2 +- modules/proc/inc/proc_objects.hpp | 1 + modules/proc/src/proc_objects.cpp | 163 +++++++++++++++++++++++++++++--------- 3 files changed, 126 insertions(+), 40 deletions(-) diff --git a/libalx b/libalx index 66307d2..d485239 160000 --- a/libalx +++ b/libalx @@ -1 +1 @@ -Subproject commit 66307d2cfd0a3e82d7539772151f787378bb994c +Subproject commit d485239428684467311ac201258897ec6d29fe9f diff --git a/modules/proc/inc/proc_objects.hpp b/modules/proc/inc/proc_objects.hpp index 20806df..b8d04d5 100644 --- a/modules/proc/inc/proc_objects.hpp +++ b/modules/proc/inc/proc_objects.hpp @@ -20,6 +20,7 @@ ******************************************************************************/ enum Proc_Objects { OBJECTS_OK, + OBJECTS_NOK_PATTERN_ANGLE, OBJECTS_NOK_OBJECTS, OBJECTS_NOK_SIZE }; diff --git a/modules/proc/src/proc_objects.cpp b/modules/proc/src/proc_objects.cpp index 5803f11..fdac393 100644 --- a/modules/proc/src/proc_objects.cpp +++ b/modules/proc/src/proc_objects.cpp @@ -80,10 +80,11 @@ struct Objects_Properties { /* Static --------------------------------------------------------------------*/ static std::vector >> contours; static class cv::Mat hierarchy; -static class cv::RotatedRect rectangle [CONTOURS_MAX]; +static class cv::RotatedRect rect_rot [CONTOURS_MAX]; static int objects_n; static struct Objects_Properties objects [CONTOURS_MAX]; static double ratio_mm_per_pix; +static double pattern_angle; /****************************************************************************** @@ -92,13 +93,16 @@ static double ratio_mm_per_pix; static void result_objects (int status); static void pattern_segmentate (void); +static void pattern_position_pix (void); static void pattern_len_pix (void); static void calibrate_mm_per_pix (void); +static int pattern_angle_get (void); static void objects_segmentate (void); static int objects_contours (void); static void objects_position_pix (void); static void objects_size_pix (void); +static void objects_shape (void); static void objects_position_mm (void); static void objects_size_mm (void); static void objects_log (void); @@ -132,12 +136,12 @@ int proc_objects_calibrate (void) result_objects(status); return status; } - objects_position_pix(); + pattern_position_pix(); /* Measure time */ clock_stop("Find squares"); } - /* Calibrate with the mean of the squares */ + /* Calibrate size with the mean of the squares */ { /* Measure time */ clock_start(); @@ -148,6 +152,20 @@ int proc_objects_calibrate (void) /* Measure time */ clock_stop("Calibrate (mm per pix)"); } + /* Calibrate angle with the whole pattern */ + { + /* Measure time */ + clock_start(); + + status = pattern_angle_get(); + if (status) { + result_objects(status); + return status; + } + + /* Measure time */ + clock_stop("Calibrate (angle)"); + } status = OBJECTS_OK; result_objects(status); @@ -189,21 +207,31 @@ int proc_objects (void) clock_start(); objects_position_pix(); - objects_size_pix(); + objects_position_mm(); /* Measure time */ - clock_stop("Objects properties in pixels"); + clock_stop("Objects positions"); } /* Get objects properties in mm */ { /* Measure time */ clock_start(); - objects_position_mm(); + objects_size_pix(); objects_size_mm(); /* Measure time */ - clock_stop("Objects properties in mm"); + clock_stop("Objects sizes"); + } + /* Get objects properties in mm */ + { + /* Measure time */ + clock_start(); + + objects_shape(); + + /* Measure time */ + clock_stop("Objects shapes"); } /* Print properties of objects into log */ { @@ -260,12 +288,29 @@ static void pattern_segmentate (void) proc_cvt_color(cv::COLOR_BGR2GRAY); proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU); + proc_save_mem(1); + proc_distance_transform(); proc_local_max(); proc_dilate(6); + /* Needs to be 3 because objects_contours() loads mem3 */ proc_save_mem(3); } +static void pattern_position_pix (void) +{ + int i; + class cv::Rect_ rect [CONTOURS_MAX]; + + /* Get position of each contour */ + for (i = 0; i < objects_n; i++) { + proc_bounding_rect(&(contours[i]), &(rect[i]), true); + + objects[i].x_pix = rect[i].x + rect[i].width / 2.0; + objects[i].y_pix = rect[i].y + rect[i].height / 2.0; + } +} + static void pattern_len_pix (void) { int i; @@ -301,6 +346,37 @@ static void calibrate_mm_per_pix (void) (user_iface_log.len)++; } +static int pattern_angle_get (void) +{ + int status; + + proc_load_mem(1); + + proc_erode_dilate(2); + proc_dilate(2); + proc_contours(&contours, &hierarchy); + proc_save_mem(2); + + /* If no contour is found, error: NOK_PATTERN_ANGLE */ + if (contours.size() != 1) { + status = OBJECTS_NOK_PATTERN_ANGLE; + return status; + } + + proc_min_area_rect(&(contours[0]), &(rect_rot[0]), true); + pattern_angle = -rect_rot[0].angle; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "pattern angle = %lf DEG", + pattern_angle); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + status = OBJECTS_OK; + return status; +} + /* process -------------------------------------------------------------------*/ static void objects_segmentate (void) { @@ -352,10 +428,27 @@ static void objects_position_pix (void) /* Get position of each contour */ for (i = 0; i < objects_n; i++) { - proc_min_area_rect(&(contours[i]), &(rectangle[i]), true); + proc_fit_ellipse(&(contours[i]), &(rect_rot[i]), true); + + objects[i].x_pix = rect_rot[i].center.x; + objects[i].y_pix = rect_rot[i].center.y; + + objects[i].angle = (-rect_rot[i].angle + 90.0) - + pattern_angle; + if (objects[i].angle < 0) { + objects[i].angle += 180.0; + } + } +} + +static void objects_position_mm (void) +{ + int i; - objects[i].x_pix = rectangle[i].center.x; - objects[i].y_pix = rectangle[i].center.y; + /* Get position of each contour */ + for (i = 0; i < objects_n; i++) { + objects[i].x_mm = ratio_mm_per_pix * objects[i].x_pix; + objects[i].y_mm = ratio_mm_per_pix * objects[i].y_pix; } } @@ -368,53 +461,45 @@ static void objects_size_pix (void) /* Get size of each contour */ proc_contours_size(&contours, area, perimeter); for (i = 0; i < objects_n; i++) { - objects[i].area_pix2 = area[i]; objects[i].perimeter_pix = perimeter[i]; - - objects[i].ratio_p2_a = pow(perimeter[i], 2) / area[i]; - - - if (rectangle[i].size.width > rectangle[i].size.height) { - objects[i].angle = rectangle[i].angle; - } else { - objects[i].angle = rectangle[i].angle + 90.0; - - } - objects[i].area_rect = rectangle[i].size.width * - rectangle[i].size.height; - objects[i].perimeter_rect = 2.0 * - (rectangle[i].size.width + - rectangle[i].size.height); - - objects[i].ratio_p_prect = objects[i].perimeter_pix / - objects[i].perimeter_rect; - objects[i].ratio_a_arect = objects[i].area_pix2 / - objects[i].area_rect; } } -static void objects_position_mm (void) +static void objects_size_mm (void) { int i; /* Get position of each contour */ for (i = 0; i < objects_n; i++) { - objects[i].x_mm = ratio_mm_per_pix * objects[i].x_pix; - objects[i].y_mm = ratio_mm_per_pix * objects[i].y_pix; + objects[i].area_mm2 = pow(ratio_mm_per_pix, 2) * + objects[i].area_pix2; + objects[i].perimeter_mm = ratio_mm_per_pix * + objects[i].perimeter_pix; } } -static void objects_size_mm (void) +static void objects_shape (void) { int i; - /* Get position of each contour */ + /* Get shape of each contour */ for (i = 0; i < objects_n; i++) { - objects[i].area_mm2 = pow(ratio_mm_per_pix, 2) * + proc_min_area_rect(&(contours[i]), &(rect_rot[i]), true); + + objects[i].ratio_p2_a = pow(objects[i].perimeter_pix, 2) / objects[i].area_pix2; - objects[i].perimeter_mm = ratio_mm_per_pix * - objects[i].perimeter_pix; + + objects[i].area_rect = rect_rot[i].size.width * + rect_rot[i].size.height; + objects[i].perimeter_rect = 2.0 * + (rect_rot[i].size.width + + rect_rot[i].size.height); + + objects[i].ratio_p_prect = objects[i].perimeter_pix / + objects[i].perimeter_rect; + objects[i].ratio_a_arect = objects[i].area_pix2 / + objects[i].area_rect; } } -- cgit v1.2.3 From 4106384e2f7cf2a63de7fe047e21f14cbb40083a Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Wed, 12 Dec 2018 23:37:17 +0100 Subject: Improve calibration in proc_objects: Fix rotation & crop to pattern --- modules/image/src/img_cv.cpp | 17 +- modules/proc/inc/proc_common.hpp | 5 +- modules/proc/inc/proc_objects.h | 1 + modules/proc/inc/proc_objects.hpp | 2 +- modules/proc/src/proc_common.cpp | 8 +- modules/proc/src/proc_label.cpp | 2 +- modules/proc/src/proc_objects.cpp | 489 +++++++++++++++++++++++-------------- modules/proc/src/proc_resistor.cpp | 4 +- 8 files changed, 327 insertions(+), 201 deletions(-) diff --git a/modules/image/src/img_cv.cpp b/modules/image/src/img_cv.cpp index f043156..de9e870 100644 --- a/modules/image/src/img_cv.cpp +++ b/modules/image/src/img_cv.cpp @@ -376,16 +376,13 @@ static void img_cv_rotate (class cv::Mat *imgptr, void *data) double angle; angle = data_cast->angle; - /* 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)); - } + /* 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)); /* clean up */ map_matrix.release(); diff --git a/modules/proc/inc/proc_common.hpp b/modules/proc/inc/proc_common.hpp index ff3a69e..dbc4d95 100644 --- a/modules/proc/inc/proc_common.hpp +++ b/modules/proc/inc/proc_common.hpp @@ -58,7 +58,10 @@ extern "C" { void proc_dilate_erode (int size); void proc_erode_dilate (int size); void proc_smooth (int method, int ksize); - void proc_rotate (class cv::RotatedRect *rect); + void proc_rotate ( + double center_x, + double center_y, + double angle); void proc_adaptive_threshold (int method, int type, int ksize); void proc_cvt_color (int method); void proc_distance_transform (void); diff --git a/modules/proc/inc/proc_objects.h b/modules/proc/inc/proc_objects.h index e066bd7..fb53ac4 100644 --- a/modules/proc/inc/proc_objects.h +++ b/modules/proc/inc/proc_objects.h @@ -20,6 +20,7 @@ ******************************************************************************/ enum Proc_Objects { OBJECTS_OK, + OBJECTS_NOK_PATTERN, OBJECTS_NOK_OBJECTS, OBJECTS_NOK_SIZE }; diff --git a/modules/proc/inc/proc_objects.hpp b/modules/proc/inc/proc_objects.hpp index b8d04d5..300e625 100644 --- a/modules/proc/inc/proc_objects.hpp +++ b/modules/proc/inc/proc_objects.hpp @@ -20,7 +20,7 @@ ******************************************************************************/ enum Proc_Objects { OBJECTS_OK, - OBJECTS_NOK_PATTERN_ANGLE, + OBJECTS_NOK_PATTERN, OBJECTS_NOK_OBJECTS, OBJECTS_NOK_SIZE }; diff --git a/modules/proc/src/proc_common.cpp b/modules/proc/src/proc_common.cpp index faa9cdf..7f92e9b 100644 --- a/modules/proc/src/proc_common.cpp +++ b/modules/proc/src/proc_common.cpp @@ -213,12 +213,12 @@ void proc_smooth (int method, int ksize) proc_show_img(); } -void proc_rotate (class cv::RotatedRect *rect) +void proc_rotate (double center_x, double center_y, double angle) { struct Img_Iface_Data_Rotate data; - data.center.x = rect->center.x; - data.center.y = rect->center.y; - data.angle = rect->angle; + data.center.x = center_x; + data.center.y = center_y; + data.angle = angle; img_iface_act(IMG_IFACE_ACT_ROTATE, (void *)&data); proc_show_img(); diff --git a/modules/proc/src/proc_label.cpp b/modules/proc/src/proc_label.cpp index a2e0783..9d4caf6 100644 --- a/modules/proc/src/proc_label.cpp +++ b/modules/proc/src/proc_label.cpp @@ -246,7 +246,7 @@ static void label_align (void) { proc_load_mem(0); - proc_rotate(&rect); + proc_rotate(rect.center.x, rect.center.y, rect.angle); proc_cmp(IMG_IFACE_CMP_GREEN); proc_save_mem(1); } diff --git a/modules/proc/src/proc_objects.cpp b/modules/proc/src/proc_objects.cpp index fdac393..c83f96c 100644 --- a/modules/proc/src/proc_objects.cpp +++ b/modules/proc/src/proc_objects.cpp @@ -33,42 +33,67 @@ /****************************************************************************** ******* macros *************************************************************** ******************************************************************************/ - # define COINS_MAX 1024 + # define OBJECTS_MAX (1024) + # define PATTERN_SQUARE_LEN_MM (10.0) + + # define PATTERN_DILATE (2) /****************************************************************************** ******* structs ************************************************************** ******************************************************************************/ +struct Point { + uint16_t x_pix; + uint16_t y_pix; + + double x_mm; + double y_mm; +}; + +struct Pattern_Square { + struct Point pos; + + double len_mm; + uint8_t len_pix; +}; + +struct Pattern_Properties { + /* center */ + struct Point center; + struct Point origin; + + /* Angle */ + double angle; + + /* Size */ + uint16_t height; + uint16_t width; + + /* Squares (distance calibration) */ + struct Pattern_Square square [OBJECTS_MAX]; +}; + struct Objects_Properties { /* position */ - double x_pix; - double y_pix; - double x_mm; - double y_mm; - - /* Calibration */ - int8_t value; + struct Point pos; /* Angle */ - double angle; + double angle; /* Area */ - double area_pix2; - double area_mm2; + double area_pix2; + double area_mm2; /* Perimeter */ - double perimeter_pix; - double perimeter_mm; + double perimeter_pix; + double perimeter_mm; /* type */ - double ratio_p2_a; - double area_rect; - double ratio_a_arect; - double perimeter_rect; - double ratio_p_prect; - - /* diammeter */ - uint8_t diameter_pix; + double ratio_p2_a; + double area_rect; + double ratio_a_arect; + double perimeter_rect; + double ratio_p_prect; }; @@ -80,11 +105,13 @@ struct Objects_Properties { /* Static --------------------------------------------------------------------*/ static std::vector >> contours; static class cv::Mat hierarchy; -static class cv::RotatedRect rect_rot [CONTOURS_MAX]; +static class cv::RotatedRect rect_rot [OBJECTS_MAX]; +static class cv::Rect_ rect [OBJECTS_MAX]; +static struct Pattern_Properties pattern; +static int squares_n; +static double ratio_mm_pix; static int objects_n; -static struct Objects_Properties objects [CONTOURS_MAX]; -static double ratio_mm_per_pix; -static double pattern_angle; +static struct Objects_Properties objects [OBJECTS_MAX]; /****************************************************************************** @@ -92,13 +119,21 @@ static double pattern_angle; ******************************************************************************/ static void result_objects (int status); -static void pattern_segmentate (void); -static void pattern_position_pix (void); -static void pattern_len_pix (void); -static void calibrate_mm_per_pix (void); -static int pattern_angle_get (void); - -static void objects_segmentate (void); +static void pattern_bgr2gray (void); +static int pattern_find (void); +static void pattern_rotation_get (void); +static void pattern_rotation_fix (void); +static void pattern_dimensions_get (void); +static void pattern_dimensions_fix (void); +static void pattern_squares_find (void); +static void pattern_squares_pos_get (void); +static void pattern_squares_len_get (void); +static void pattern_calib_mm_pix (void); + +static void objects_bgr2gray (void); +static void objects_rotation_fix (void); +static void objects_dimensions_fix (void); +static void objects_segment (void); static int objects_contours (void); static void objects_position_pix (void); static void objects_size_pix (void); @@ -116,55 +151,46 @@ int proc_objects_calibrate (void) int status; proc_save_mem(0); - /* Segmentate coins */ - { - /* Measure time */ - clock_start(); - - pattern_segmentate(); - - /* Measure time */ - clock_stop("Segmentate pattern squares"); - } - /* Find coins positions */ + /* Calibrate angle with the whole pattern */ { /* Measure time */ clock_start(); - status = objects_contours(); + pattern_bgr2gray(); + status = pattern_find(); if (status) { result_objects(status); return status; } - pattern_position_pix(); + pattern_rotation_get(); + pattern_rotation_fix(); /* Measure time */ - clock_stop("Find squares"); + clock_stop("Calibrate: rotation"); } - /* Calibrate size with the mean of the squares */ + /* Segmentate pattern squares */ { /* Measure time */ clock_start(); - pattern_len_pix(); - calibrate_mm_per_pix(); + pattern_dimensions_get(); + pattern_dimensions_fix(); /* Measure time */ - clock_stop("Calibrate (mm per pix)"); + clock_stop("Calibrate: dimensions"); } - /* Calibrate angle with the whole pattern */ + /* Find squares */ { /* Measure time */ clock_start(); - status = pattern_angle_get(); - if (status) { - result_objects(status); - return status; - } + pattern_squares_find(); + pattern_squares_pos_get(); + pattern_squares_len_get(); + pattern_calib_mm_pix(); /* Measure time */ - clock_stop("Calibrate (angle)"); + clock_stop("Calibrate (mm per pix)"); } status = OBJECTS_OK; @@ -177,15 +203,27 @@ int proc_objects (void) int status; proc_save_mem(0); + /* Align image */ + { + /* Measure time */ + clock_start(); + + objects_bgr2gray(); + objects_rotation_fix(); + objects_dimensions_fix(); + + /* Measure time */ + clock_stop("Align image to pattern"); + } /* Segmentate coins */ { /* Measure time */ clock_start(); - objects_segmentate(); + objects_segment(); /* Measure time */ - clock_stop("Segmentate objects"); + clock_stop("Segment objects"); } /* Find coins positions */ { @@ -199,7 +237,7 @@ int proc_objects (void) } /* Measure time */ - clock_stop("Find objects positions"); + clock_stop("Find objects"); } /* Get objects properties in pixels */ { @@ -282,111 +320,200 @@ static void result_objects (int status) } /* calibration ---------------------------------------------------------------*/ -static void pattern_segmentate (void) +static void pattern_bgr2gray (void) { proc_load_mem(0); proc_cvt_color(cv::COLOR_BGR2GRAY); - proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU); proc_save_mem(1); +} + +static int pattern_find (void) +{ + int status; + + proc_load_mem(1); + + proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU); + proc_erode_dilate(2); + proc_dilate(2); + proc_contours(&contours, &hierarchy); + + /* If no contour is found, error: NOK_PATTERN */ + if (contours.size() != 1) { + status = OBJECTS_NOK_PATTERN; + return status; + } + + status = OBJECTS_OK; + return status; +} + +static void pattern_rotation_get (void) +{ + proc_min_area_rect(&(contours[0]), &(rect_rot[0]), true); + + /* If angle is < -45º, it is taking into account the incorrect side */ + if (rect_rot[0].angle < -45.0) { + rect_rot[0].angle += 90.0; + } + pattern.angle = rect_rot[0].angle; + pattern.center.x_pix = rect_rot[0].center.x; + pattern.center.y_pix = rect_rot[0].center.y; + + /* Write pattern properties into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "pattern angle = %lf DEG", + -pattern.angle); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "pattern center (x) = %i pix", + pattern.center.x_pix); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "pattern center (y) = %i pix", + pattern.center.y_pix); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + +static void pattern_rotation_fix (void) +{ + proc_load_mem(1); + + /* invert image before rotation to avoid black bands */ + proc_not(); + proc_rotate(pattern.center.x_pix, pattern.center.y_pix, pattern.angle); + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_save_mem(2); +} + +static void pattern_dimensions_get (void) +{ + proc_load_mem(2); + + proc_erode_dilate(2); + proc_dilate(PATTERN_DILATE); + proc_contours(&contours, &hierarchy); + proc_bounding_rect(&(contours[0]), &(rect[0]), true); +} + +static void pattern_dimensions_fix (void) +{ + /* Need to correct also pattern dilatation (pattern_dimensions_get()) */ + pattern.origin.x_pix = rect[0].x; + pattern.origin.y_pix = rect[0].y; + pattern.width = rect[0].width; + pattern.height = rect[0].height; + + proc_load_mem(2); + + proc_ROI(pattern.origin.x_pix, pattern.origin.y_pix, + pattern.width, pattern.height); + proc_save_mem(3); +} + +static void pattern_squares_find (void) +{ + proc_load_mem(3); proc_distance_transform(); proc_local_max(); proc_dilate(6); - /* Needs to be 3 because objects_contours() loads mem3 */ - proc_save_mem(3); + proc_save_mem(4); + + proc_contours(&contours, &hierarchy); + squares_n = contours.size(); } -static void pattern_position_pix (void) +static void pattern_squares_pos_get (void) { int i; - class cv::Rect_ rect [CONTOURS_MAX]; /* Get position of each contour */ - for (i = 0; i < objects_n; i++) { + for (i = 0; i < squares_n; i++) { proc_bounding_rect(&(contours[i]), &(rect[i]), true); - objects[i].x_pix = rect[i].x + rect[i].width / 2.0; - objects[i].y_pix = rect[i].y + rect[i].height / 2.0; + pattern.square[i].pos.x_pix = rect[i].x + rect[i].width/2.0; + pattern.square[i].pos.y_pix = rect[i].y + rect[i].height/2.0; } } -static void pattern_len_pix (void) +static void pattern_squares_len_get (void) { int i; - proc_load_mem(3); + proc_load_mem(4); /* Get pattern square side lenght in pixels */ - for (i = 0; i < objects_n; i++) { - proc_pixel_value(objects[i].x_pix, objects[i].y_pix, - &(objects[i].diameter_pix)); - objects[i].diameter_pix *= 2; + for (i = 0; i < squares_n; i++) { + proc_pixel_value(pattern.square[i].pos.x_pix, + pattern.square[i].pos.y_pix, + &(pattern.square[i].len_pix)); + pattern.square[i].len_pix *= 2; } } -static void calibrate_mm_per_pix (void) +static void pattern_calib_mm_pix (void) { - uint8_t pattern_size_pix [CONTOURS_MAX]; int i; - int median_size; + uint8_t pattern_len_pix [OBJECTS_MAX]; + uint8_t median_size; - for (i = 0; i < objects_n; i++) { - pattern_size_pix[i] = objects[i].diameter_pix; + for (i = 0; i < squares_n; i++) { + pattern_len_pix[i] = pattern.square[i].len_pix; } - median_size = alx_median_u8(objects_n, pattern_size_pix); - ratio_mm_per_pix = 10.0 / median_size; + median_size = alx_median_u8(squares_n, pattern_len_pix); + ratio_mm_pix = PATTERN_SQUARE_LEN_MM / median_size; /* Write diameters into log */ snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "mm/pix = %lf", - ratio_mm_per_pix); + ratio_mm_pix); user_iface_log.lvl[user_iface_log.len] = 0; (user_iface_log.len)++; } -static int pattern_angle_get (void) +/* process -------------------------------------------------------------------*/ +static void objects_bgr2gray (void) { - int status; + proc_load_mem(0); + proc_cvt_color(cv::COLOR_BGR2GRAY); + proc_save_mem(1); +} + +static void objects_rotation_fix (void) +{ proc_load_mem(1); - proc_erode_dilate(2); - proc_dilate(2); - proc_contours(&contours, &hierarchy); + /* invert image before rotation to avoid black bands */ + proc_not(); + proc_rotate(pattern.center.x_pix, pattern.center.y_pix, pattern.angle); proc_save_mem(2); +} - /* If no contour is found, error: NOK_PATTERN_ANGLE */ - if (contours.size() != 1) { - status = OBJECTS_NOK_PATTERN_ANGLE; - return status; - } - - proc_min_area_rect(&(contours[0]), &(rect_rot[0]), true); - pattern_angle = -rect_rot[0].angle; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "pattern angle = %lf DEG", - pattern_angle); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; +static void objects_dimensions_fix (void) +{ + /* Need to correct also pattern dilatation (pattern_dimensions_get()) */ + proc_load_mem(2); - status = OBJECTS_OK; - return status; + proc_ROI(pattern.origin.x_pix, pattern.origin.y_pix, + pattern.width, pattern.height); + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_save_mem(3); } -/* process -------------------------------------------------------------------*/ -static void objects_segmentate (void) +static void objects_segment (void) { - proc_load_mem(0); + proc_load_mem(3); - proc_cvt_color(cv::COLOR_BGR2GRAY); - proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU); proc_dilate_erode(3); proc_erode_dilate(3); - proc_save_mem(1); + proc_save_mem(4); proc_distance_transform(); proc_threshold(cv::THRESH_BINARY_INV, 30); @@ -394,20 +521,20 @@ static void objects_segmentate (void) proc_skeleton(); proc_threshold(cv::THRESH_BINARY_INV, 10); proc_save_ref(); - proc_save_mem(2); + proc_save_mem(5); - proc_load_mem(1); + proc_load_mem(3); proc_and_2ref(); proc_distance_transform(); proc_threshold(cv::THRESH_BINARY, 5); - proc_save_mem(3); + proc_save_mem(6); } static int objects_contours (void) { int status; - proc_load_mem(3); + proc_load_mem(6); proc_contours(&contours, &hierarchy); objects_n = contours.size(); @@ -430,11 +557,10 @@ static void objects_position_pix (void) for (i = 0; i < objects_n; i++) { proc_fit_ellipse(&(contours[i]), &(rect_rot[i]), true); - objects[i].x_pix = rect_rot[i].center.x; - objects[i].y_pix = rect_rot[i].center.y; + objects[i].pos.x_pix = rect_rot[i].center.x; + objects[i].pos.y_pix = rect_rot[i].center.y; - objects[i].angle = (-rect_rot[i].angle + 90.0) - - pattern_angle; + objects[i].angle = -rect_rot[i].angle + 90.0; if (objects[i].angle < 0) { objects[i].angle += 180.0; } @@ -447,15 +573,15 @@ static void objects_position_mm (void) /* Get position of each contour */ for (i = 0; i < objects_n; i++) { - objects[i].x_mm = ratio_mm_per_pix * objects[i].x_pix; - objects[i].y_mm = ratio_mm_per_pix * objects[i].y_pix; + objects[i].pos.x_mm = ratio_mm_pix * objects[i].pos.x_pix; + objects[i].pos.y_mm = ratio_mm_pix * objects[i].pos.y_pix; } } static void objects_size_pix (void) { - double area [CONTOURS_MAX]; - double perimeter [CONTOURS_MAX]; + double area [OBJECTS_MAX]; + double perimeter [OBJECTS_MAX]; int i; /* Get size of each contour */ @@ -472,9 +598,9 @@ static void objects_size_mm (void) /* Get position of each contour */ for (i = 0; i < objects_n; i++) { - objects[i].area_mm2 = pow(ratio_mm_per_pix, 2) * + objects[i].area_mm2 = pow(ratio_mm_pix, 2) * objects[i].area_pix2; - objects[i].perimeter_mm = ratio_mm_per_pix * + objects[i].perimeter_mm = ratio_mm_pix * objects[i].perimeter_pix; } } @@ -509,63 +635,62 @@ static void objects_log (void) /* Get coins diameters in mm */ for (i = 0; i < objects_n; i++) { - if (objects[i].area_mm2 > 100) { - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Object[%i]:", - i); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " pos: (%.1lf, %.1lf) mm", - objects[i].x_mm, objects[i].y_mm); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " ang = %.1lf DEG", - objects[i].angle); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " A = %.1lf mm2", - objects[i].area_mm2); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " P = %.1lf mm", - objects[i].perimeter_mm); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " p2/A = %.2lf", - objects[i].ratio_p2_a); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " p/p_r = %.2lf", - objects[i].ratio_p_prect); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " A/A_r = %.2lf", - objects[i].ratio_a_arect); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - } + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Object[%i]:", + i); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " pos: (%.1lf, %.1lf) mm", + objects[i].pos.x_mm, + objects[i].pos.y_mm); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " ang = %.1lf DEG", + objects[i].angle); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " A = %.1lf mm2", + objects[i].area_mm2); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " P = %.1lf mm", + objects[i].perimeter_mm); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " p2/A = %.2lf", + objects[i].ratio_p2_a); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " p/p_r = %.2lf", + objects[i].ratio_p_prect); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " A/A_r = %.2lf", + objects[i].ratio_a_arect); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; } } diff --git a/modules/proc/src/proc_resistor.cpp b/modules/proc/src/proc_resistor.cpp index 5a3a7ba..a3bf80d 100644 --- a/modules/proc/src/proc_resistor.cpp +++ b/modules/proc/src/proc_resistor.cpp @@ -327,10 +327,10 @@ static int resistor_find (void) static void resistor_align (void) { proc_load_mem(19); - proc_rotate(&rect_rot); + proc_rotate(rect_rot.center.x, rect_rot.center.y, rect_rot.angle); proc_save_mem(2); proc_load_mem(1); - proc_rotate(&rect_rot); + proc_rotate(rect_rot.center.x, rect_rot.center.y, rect_rot.angle); proc_save_mem(3); } -- cgit v1.2.3 From dd32a023f768c0c34831ea8e91cd8db05954f6b3 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Wed, 12 Dec 2018 23:38:47 +0100 Subject: Update libalx --- libalx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libalx b/libalx index d485239..0be5766 160000 --- a/libalx +++ b/libalx @@ -1 +1 @@ -Subproject commit d485239428684467311ac201258897ec6d29fe9f +Subproject commit 0be5766a2bcea31148de476d3ab13faed680cbef -- cgit v1.2.3 From 85653638235462daf54626f34acd9391cb74b2b6 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Thu, 13 Dec 2018 15:28:03 +0100 Subject: urgenciatd --- modules/image/src/img_alx.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/modules/image/src/img_alx.cpp b/modules/image/src/img_alx.cpp index b068801..6f172fe 100644 --- a/modules/image/src/img_alx.cpp +++ b/modules/image/src/img_alx.cpp @@ -172,6 +172,11 @@ static void img_alx_skeleton (class cv::Mat *imgptr) img_pix = imgptr->data + i * imgptr->step + j; tmp_pix = imgtmp.data + i * imgptr->step + j; + if (!(*img_pix)) { + *tmp_pix = 0; + continue; + } + for (r = 0; r < width; r++) { cnt_lo[r] = 0; cnt_hi_or_eq[r] = 0; -- cgit v1.2.3 From ced912e347a0540a46ed42e14151685326aa655e Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 19 Dec 2018 11:59:16 +0100 Subject: Update libalx --- libalx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libalx b/libalx index 0be5766..99b8f33 160000 --- a/libalx +++ b/libalx @@ -1 +1 @@ -Subproject commit 0be5766a2bcea31148de476d3ab13faed680cbef +Subproject commit 99b8f338b7dac5db72adb6c042d5e54172ea8c05 -- cgit v1.2.3 From 87d5fb2f56499ed8b212ef4266e79c0ac0bbf78d Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 19 Dec 2018 11:59:56 +0100 Subject: Modify proc_objects contants --- modules/proc/src/proc_objects.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/proc/src/proc_objects.cpp b/modules/proc/src/proc_objects.cpp index c83f96c..13437a3 100644 --- a/modules/proc/src/proc_objects.cpp +++ b/modules/proc/src/proc_objects.cpp @@ -335,7 +335,7 @@ static int pattern_find (void) proc_load_mem(1); proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU); - proc_erode_dilate(2); + proc_erode_dilate(16); proc_dilate(2); proc_contours(&contours, &hierarchy); @@ -394,7 +394,7 @@ static void pattern_dimensions_get (void) { proc_load_mem(2); - proc_erode_dilate(2); + proc_erode_dilate(16); proc_dilate(PATTERN_DILATE); proc_contours(&contours, &hierarchy); proc_bounding_rect(&(contours[0]), &(rect[0]), true); @@ -526,7 +526,7 @@ static void objects_segment (void) proc_load_mem(3); proc_and_2ref(); proc_distance_transform(); - proc_threshold(cv::THRESH_BINARY, 5); + proc_threshold(cv::THRESH_BINARY, 10); proc_save_mem(6); } -- cgit v1.2.3 From 3a15fc0de0541ed3e6a8f6ac43a2d55188784f0c Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 19 Dec 2018 13:53:16 +0100 Subject: Add mirror function --- modules/image/inc/img_cv.hpp | 1 + modules/image/inc/img_iface.h | 1 + modules/image/inc/img_iface.hpp | 5 +++++ modules/image/src/img_cv.cpp | 19 +++++++++++++++++++ modules/image/src/img_iface.cpp | 30 ++++++++++++++++++++++++++++++ modules/user/inc/user_iface.h | 1 + modules/user/inc/user_iface.hpp | 1 + modules/user/src/user_clui.c | 14 +++++++++----- modules/user/src/user_tui.c | 14 +++++++++----- 9 files changed, 76 insertions(+), 10 deletions(-) diff --git a/modules/image/inc/img_cv.hpp b/modules/image/inc/img_cv.hpp index 8327d67..31c121f 100644 --- a/modules/image/inc/img_cv.hpp +++ b/modules/image/inc/img_cv.hpp @@ -34,6 +34,7 @@ IMG_CV_ACT_ERODE, IMG_CV_ACT_SMOOTH, IMG_CV_ACT_SOBEL, + IMG_CV_ACT_MIRROR, IMG_CV_ACT_ROTATE_ORTO, IMG_CV_ACT_ROTATE, IMG_CV_ACT_ADAPTIVE_THRESHOLD, diff --git a/modules/image/inc/img_iface.h b/modules/image/inc/img_iface.h index f23991b..3e5704c 100644 --- a/modules/image/inc/img_iface.h +++ b/modules/image/inc/img_iface.h @@ -55,6 +55,7 @@ IMG_IFACE_ACT_ERODE_DILATE, IMG_IFACE_ACT_SMOOTH, IMG_IFACE_ACT_SOBEL, + IMG_IFACE_ACT_MIRROR, IMG_IFACE_ACT_ROTATE_ORTO, IMG_IFACE_ACT_ROTATE, IMG_IFACE_ACT_ROTATE_2RECT, diff --git a/modules/image/inc/img_iface.hpp b/modules/image/inc/img_iface.hpp index f17c609..7e7002b 100644 --- a/modules/image/inc/img_iface.hpp +++ b/modules/image/inc/img_iface.hpp @@ -65,6 +65,7 @@ IMG_IFACE_ACT_ERODE_DILATE, IMG_IFACE_ACT_SMOOTH, IMG_IFACE_ACT_SOBEL, + IMG_IFACE_ACT_MIRROR, IMG_IFACE_ACT_ROTATE_ORTO, IMG_IFACE_ACT_ROTATE, IMG_IFACE_ACT_ROTATE_2RECT, @@ -171,6 +172,10 @@ int ksize; }; + struct Img_Iface_Data_Mirror { + int axis; + }; + struct Img_Iface_Data_Rotate_Orto { int n; }; diff --git a/modules/image/src/img_cv.cpp b/modules/image/src/img_cv.cpp index de9e870..1cd11a4 100644 --- a/modules/image/src/img_cv.cpp +++ b/modules/image/src/img_cv.cpp @@ -49,6 +49,7 @@ static void img_cv_erode (class cv::Mat *imgptr, void *data); static void img_cv_smooth (class cv::Mat *imgptr, void *data); static void img_cv_sobel (class cv::Mat *imgptr, void *data); /* Geometric image transformations */ +static void img_cv_mirror (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); /* Miscellaneous image transformations */ @@ -109,6 +110,9 @@ void img_cv_act (class cv::Mat *imgptr, int action, void *data) img_cv_sobel(imgptr, data); break; + case IMG_CV_ACT_MIRROR: + img_cv_mirror(imgptr, data); + break; case IMG_CV_ACT_ROTATE_ORTO: img_cv_rotate_orto(imgptr, data); break; @@ -332,6 +336,21 @@ static void img_cv_sobel (class cv::Mat *imgptr, void *data) } /* ----- Geometric image transformations */ +static void img_cv_mirror (class cv::Mat *imgptr, void *data) +{ + struct Img_Iface_Data_Mirror *data_cast; + int axis; + + /* Data */ + data_cast = (struct Img_Iface_Data_Mirror *)data; + + /* Rotate n * pi/2 rad */ + axis = data_cast->axis; + + /* flip around axis */ + cv::flip(*imgptr, *imgptr, axis); +} + static void img_cv_rotate_orto (class cv::Mat *imgptr, void *data) { /* Data */ diff --git a/modules/image/src/img_iface.cpp b/modules/image/src/img_iface.cpp index 6f80249..9cc3760 100644 --- a/modules/image/src/img_iface.cpp +++ b/modules/image/src/img_iface.cpp @@ -119,6 +119,7 @@ static void img_iface_erode_dilate (void *data); static void img_iface_smooth (void *data); static void img_iface_sobel (void *data); /* Geometric image transformations */ +static void img_iface_mirror (void *data); static void img_iface_rotate_orto (void *data); static void img_iface_rotate (void *data); static void img_iface_rotate_2rect (void *data); @@ -308,6 +309,9 @@ void img_iface_act (int action, void *data) img_iface_sobel(data); break; /* Geometric image transformations */ + case IMG_IFACE_ACT_MIRROR: + img_iface_mirror(data); + break; case IMG_IFACE_ACT_ROTATE_ORTO: img_iface_rotate_orto(data); break; @@ -1032,6 +1036,32 @@ static void img_iface_sobel (void *data) } /* ----- ------- Geometric image transformations */ +static void img_iface_mirror (void *data) +{ + /* Data */ + struct Img_Iface_Data_Mirror data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Axis: 0=x; 1=y"); + data_tmp.axis = user_iface_getint(0, 1, 1, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Mirror *data_cast; + data_cast = (struct Img_Iface_Data_Mirror *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Mirror axis: %i", + data_cast->axis); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Mirror */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_MIRROR, data); +} + static void img_iface_rotate_orto (void *data) { /* Data */ diff --git a/modules/user/inc/user_iface.h b/modules/user/inc/user_iface.h index 6e3de47..284f4d9 100644 --- a/modules/user/inc/user_iface.h +++ b/modules/user/inc/user_iface.h @@ -61,6 +61,7 @@ USER_IFACE_ACT_ERODE_DILATE, USER_IFACE_ACT_SMOOTH, USER_IFACE_ACT_SOBEL, + USER_IFACE_ACT_MIRROR, USER_IFACE_ACT_ROTATE_ORTO, USER_IFACE_ACT_ROTATE, USER_IFACE_ACT_ROTATE_2RECT, diff --git a/modules/user/inc/user_iface.hpp b/modules/user/inc/user_iface.hpp index 90c63b6..c291567 100644 --- a/modules/user/inc/user_iface.hpp +++ b/modules/user/inc/user_iface.hpp @@ -61,6 +61,7 @@ USER_IFACE_ACT_ERODE_DILATE, USER_IFACE_ACT_SMOOTH, USER_IFACE_ACT_SOBEL, + USER_IFACE_ACT_MIRROR, USER_IFACE_ACT_ROTATE_ORTO, USER_IFACE_ACT_ROTATE, USER_IFACE_ACT_ROTATE_2RECT, diff --git a/modules/user/src/user_clui.c b/modules/user/src/user_clui.c index 55fb3aa..070bf24 100644 --- a/modules/user/src/user_clui.c +++ b/modules/user/src/user_clui.c @@ -342,12 +342,15 @@ static int usr_input (void) /* Geometric image transformations */ switch (ch[4]) { case '0': - action = USER_IFACE_ACT_ROTATE_ORTO; + action = USER_IFACE_ACT_MIRROR; break; case '1': - action = USER_IFACE_ACT_ROTATE; + action = USER_IFACE_ACT_ROTATE_ORTO; break; case '2': + action = USER_IFACE_ACT_ROTATE; + break; + case '3': action = USER_IFACE_ACT_ROTATE_2RECT; break; default: @@ -573,9 +576,10 @@ static void show_help (void) printf(" - E-D: %s\n", "f1103"); printf(" - Smooth: %s\n", "f1104"); printf(" - Sobel: %s\n", "f1105"); - printf(" - Rotate ortogonally: %s\n", "f1110"); - printf(" - Rotate: %s\n", "f1111"); - printf(" - Rotate 2rect_rot: %s\n", "f1112"); + printf(" - Mirror: %s\n", "f1110"); + printf(" - Rotate ortogonally: %s\n", "f1111"); + printf(" - Rotate: %s\n", "f1112"); + printf(" - Rotate 2rect_rot: %s\n", "f1113"); printf(" - Adaptive threshold: %s\n", "f1120"); printf(" - Cvt color: %s\n", "f1121"); printf(" - Distance transform: %s\n", "f1122"); diff --git a/modules/user/src/user_tui.c b/modules/user/src/user_tui.c index d3b9ca7..eb93ba5 100644 --- a/modules/user/src/user_tui.c +++ b/modules/user/src/user_tui.c @@ -455,12 +455,15 @@ static int usr_input (void) switch (ch) { case '0': - action = USER_IFACE_ACT_ROTATE_ORTO; + action = USER_IFACE_ACT_MIRROR; break; case '1': - action = USER_IFACE_ACT_ROTATE; + action = USER_IFACE_ACT_ROTATE_ORTO; break; case '2': + action = USER_IFACE_ACT_ROTATE; + break; + case '3': action = USER_IFACE_ACT_ROTATE_2RECT; break; default: @@ -719,9 +722,10 @@ static void show_help (void) mvwprintw(win_help, r++, c, " - E-D: %s", "f1103"); mvwprintw(win_help, r++, c, " - Smooth: %s", "f1104"); mvwprintw(win_help, r++, c, " - Sobel: %s", "f1105"); - mvwprintw(win_help, r++, c, " - Rotate ortogonally: %s", "f1110"); - mvwprintw(win_help, r++, c, " - Rotate: %s", "f1111"); - mvwprintw(win_help, r++, c, " - Rotate 2rect_rot: %s", "f1112"); + mvwprintw(win_help, r++, c, " - Mirror: %s", "f1110"); + mvwprintw(win_help, r++, c, " - Rotate ortogonally: %s", "f1111"); + mvwprintw(win_help, r++, c, " - Rotate: %s", "f1112"); + mvwprintw(win_help, r++, c, " - Rotate 2rect_rot: %s", "f1113"); mvwprintw(win_help, r++, c, " - Adaptive threshold: %s", "f1120"); mvwprintw(win_help, r++, c, " - Cvt color: %s", "f1121"); mvwprintw(win_help, r++, c, " - Distance transform: %s", "f1122"); -- cgit v1.2.3 From 393a4da96df46b031e3ba5c796e44feaad6e67e4 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 19 Dec 2018 13:54:41 +0100 Subject: Fix minor bugs --- modules/proc/src/proc_objects.cpp | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/modules/proc/src/proc_objects.cpp b/modules/proc/src/proc_objects.cpp index 13437a3..06d92e9 100644 --- a/modules/proc/src/proc_objects.cpp +++ b/modules/proc/src/proc_objects.cpp @@ -53,8 +53,7 @@ struct Point { struct Pattern_Square { struct Point pos; - double len_mm; - uint8_t len_pix; + uint8_t len; }; struct Pattern_Properties { @@ -215,7 +214,7 @@ int proc_objects (void) /* Measure time */ clock_stop("Align image to pattern"); } - /* Segmentate coins */ + /* Segment objects */ { /* Measure time */ clock_start(); @@ -225,7 +224,7 @@ int proc_objects (void) /* Measure time */ clock_stop("Segment objects"); } - /* Find coins positions */ + /* Find objects positions */ { /* Measure time */ clock_start(); @@ -451,22 +450,22 @@ static void pattern_squares_len_get (void) for (i = 0; i < squares_n; i++) { proc_pixel_value(pattern.square[i].pos.x_pix, pattern.square[i].pos.y_pix, - &(pattern.square[i].len_pix)); - pattern.square[i].len_pix *= 2; + &(pattern.square[i].len)); + pattern.square[i].len *= 2; } } static void pattern_calib_mm_pix (void) { int i; - uint8_t pattern_len_pix [OBJECTS_MAX]; + uint8_t pattern_len [OBJECTS_MAX]; uint8_t median_size; for (i = 0; i < squares_n; i++) { - pattern_len_pix[i] = pattern.square[i].len_pix; + pattern_len[i] = pattern.square[i].len; } - median_size = alx_median_u8(squares_n, pattern_len_pix); + median_size = alx_median_u8(squares_n, pattern_len); ratio_mm_pix = PATTERN_SQUARE_LEN_MM / median_size; /* Write diameters into log */ -- cgit v1.2.3 From e5c5356df074ea679c8b9363e782dfbaee3a2b08 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 19 Dec 2018 13:56:34 +0100 Subject: Add lighter proc --- modules/proc/src/proc_lighter.cpp | 675 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 675 insertions(+) create mode 100644 modules/proc/src/proc_lighter.cpp diff --git a/modules/proc/src/proc_lighter.cpp b/modules/proc/src/proc_lighter.cpp new file mode 100644 index 0000000..3aa2b2a --- /dev/null +++ b/modules/proc/src/proc_lighter.cpp @@ -0,0 +1,675 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* snprintf() */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* openCV */ + #include + +/* libalx ------------------------------------------------------------------*/ + /* alx_maximum_u8() */ + #include "alx_math.hpp" + +/* Project -------------------------------------------------------------------*/ + /* constants */ + #include "img_iface.hpp" + /* user_iface_log */ + #include "user_iface.hpp" + +/* Module --------------------------------------------------------------------*/ + #include "proc_common.hpp" + + #include "proc_lighter.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define PATTERN_SQUARE_LEN_MM (10.0) + + # define PATTERN_DILATE (2) + + +/****************************************************************************** + ******* structs ************************************************************** + ******************************************************************************/ +struct Point { + uint16_t x_pix; + uint16_t y_pix; + + double x_mm; + double y_mm; +}; + +struct Pattern_Square { + struct Point pos; + + uint8_t len; +}; + +struct Pattern_Properties { + /* center */ + struct Point center; + struct Point origin; + + /* Angle */ + double angle; + + /* Size */ + uint16_t height; + uint16_t width; + + /* Squares (distance calibration) */ + struct Pattern_Square square [CONTOURS_MAX]; + int squares_n; +}; + +struct Lighter_Properties { + /* position */ + struct Point pos; + + /* Angle */ + double angle; + + /* Area */ + double area_pix2; + double area_mm2; + + /* Perimeter */ + double perimeter_pix; + double perimeter_mm; + + /* type */ + double ratio_p2_a; + double area_rect; + double ratio_a_arect; + double perimeter_rect; + double ratio_p_prect; +}; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ + +/* Static --------------------------------------------------------------------*/ +static std::vector >> contours; +static class cv::Mat hierarchy; +static class cv::RotatedRect rect_rot [1]; +static class cv::Rect_ rect [CONTOURS_MAX]; +static struct Pattern_Properties pattern; +static double ratio_mm_pix; +static struct Lighter_Properties lighter; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_lighter (int status); + +static void pattern_bgr2gray (void); +static int pattern_find (void); +static void pattern_rotation_get (void); +static void pattern_rotation_fix (void); +static void pattern_dimensions_get (void); +static void pattern_dimensions_fix (void); +static void pattern_squares_find (void); +static void pattern_squares_pos_get (void); +static void pattern_squares_len_get (void); +static void pattern_calib_mm_pix (void); + +static void lighter_bgr2gray (void); +static void lighter_rotation_fix (void); +static void lighter_dimensions_fix (void); +static void lighter_segment (void); +static int lighter_contours (void); +static void lighter_position_pix (void); +static void lighter_size_pix (void); +static void lighter_shape (void); +static void lighter_position_mm (void); +static void lighter_size_mm (void); +static void lighter_log (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +int proc_lighter_calibrate (void) +{ + int status; + + proc_save_mem(0); + /* Calibrate angle with the whole pattern */ + { + /* Measure time */ + clock_start(); + + pattern_bgr2gray(); + status = pattern_find(); + if (status) { + result_lighter(status); + return status; + } + pattern_rotation_get(); + pattern_rotation_fix(); + + /* Measure time */ + clock_stop("Calibrate: rotation"); + } + /* Segmentate pattern squares */ + { + /* Measure time */ + clock_start(); + + pattern_dimensions_get(); + pattern_dimensions_fix(); + + /* Measure time */ + clock_stop("Calibrate: dimensions"); + } + /* Find squares */ + { + /* Measure time */ + clock_start(); + + pattern_squares_find(); + pattern_squares_pos_get(); + pattern_squares_len_get(); + pattern_calib_mm_pix(); + + /* Measure time */ + clock_stop("Calibrate (mm per pix)"); + } + + status = LIGHTER_OK; + result_lighter(status); + return status; +} + +int proc_lighter (void) +{ + int status; + + proc_save_mem(0); + /* Align image */ + { + /* Measure time */ + clock_start(); + + lighter_bgr2gray(); + lighter_rotation_fix(); + lighter_dimensions_fix(); + + /* Measure time */ + clock_stop("Align image to pattern"); + } + /* Segment lighter */ + { + /* Measure time */ + clock_start(); + + lighter_segment(); + + /* Measure time */ + clock_stop("Segment lighter"); + } + /* Find lighters positions */ + { + /* Measure time */ + clock_start(); + + status = lighter_contours(); + if (status) { + result_lighter(status); + return status; + } + + /* Measure time */ + clock_stop("Find lighter"); + } + /* Get lighter properties in pixels */ + { + /* Measure time */ + clock_start(); + + lighter_position_pix(); + lighter_position_mm(); + + /* Measure time */ + clock_stop("Lighter position"); + } + /* Get lighter properties in mm */ + { + /* Measure time */ + clock_start(); + + lighter_size_pix(); + lighter_size_mm(); + + /* Measure time */ + clock_stop("Lighter size"); + } + /* Get lighter properties in mm */ + { + /* Measure time */ + clock_start(); + + lighter_shape(); + + /* Measure time */ + clock_stop("Lighter shape"); + } + /* Print properties of lighter into log */ + { + /* Measure time */ + clock_start(); + + lighter_log(); + + /* Measure time */ + clock_stop("Lighter properties (log)"); + } + + status = LIGHTER_OK; + result_lighter(status); + return status; +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_lighter (int status) +{ + /* Cleanup */ + + /* Write result into log */ + switch (status) { + case LIGHTER_OK: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: OK"); + break; + case LIGHTER_NOK_LIGHTER: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK_LIGHTER"); + break; + + case LIGHTER_NOK_SIZE: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK_SIZE"); + break; + default: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK"); + break; + } + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + +/* calibration ---------------------------------------------------------------*/ +static void pattern_bgr2gray (void) +{ + proc_load_mem(0); + + proc_cvt_color(cv::COLOR_BGR2GRAY); + proc_save_mem(1); +} + +static int pattern_find (void) +{ + int status; + + proc_load_mem(1); + + proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU); + proc_erode_dilate(16); + proc_dilate(2); + proc_contours(&contours, &hierarchy); + + /* If no contour is found, error: NOK_PATTERN */ + if (contours.size() != 1) { + status = LIGHTER_NOK_PATTERN; + return status; + } + + status = LIGHTER_OK; + return status; +} + +static void pattern_rotation_get (void) +{ + proc_min_area_rect(&(contours[0]), &(rect_rot[0]), true); + + /* If angle is < -45º, it is taking into account the incorrect side */ + if (rect_rot[0].angle < -45.0) { + rect_rot[0].angle += 90.0; + } + pattern.angle = rect_rot[0].angle; + pattern.center.x_pix = rect_rot[0].center.x; + pattern.center.y_pix = rect_rot[0].center.y; + + /* Write pattern properties into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "pattern angle = %lf DEG", + -pattern.angle); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "pattern center (x) = %i pix", + pattern.center.x_pix); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "pattern center (y) = %i pix", + pattern.center.y_pix); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + +static void pattern_rotation_fix (void) +{ + proc_load_mem(1); + + /* invert image before rotation to avoid black bands */ + proc_not(); + proc_rotate(pattern.center.x_pix, pattern.center.y_pix, pattern.angle); + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_save_mem(2); +} + +static void pattern_dimensions_get (void) +{ + proc_load_mem(2); + + proc_erode_dilate(16); + proc_dilate(PATTERN_DILATE); + proc_contours(&contours, &hierarchy); + proc_bounding_rect(&(contours[0]), &(rect[0]), true); +} + +static void pattern_dimensions_fix (void) +{ + /* Need to correct also pattern dilatation (pattern_dimensions_get()) */ + pattern.origin.x_pix = rect[0].x; + pattern.origin.y_pix = rect[0].y; + pattern.width = rect[0].width; + pattern.height = rect[0].height; + + proc_load_mem(2); + + proc_ROI(pattern.origin.x_pix, pattern.origin.y_pix, + pattern.width, pattern.height); + proc_save_mem(3); +} + +static void pattern_squares_find (void) +{ + proc_load_mem(3); + + proc_distance_transform(); + proc_local_max(); + proc_dilate(6); + proc_save_mem(4); + + proc_contours(&contours, &hierarchy); + pattern.squares_n = contours.size(); +} + +static void pattern_squares_pos_get (void) +{ + int i; + + /* Get position of each contour */ + for (i = 0; i < pattern.squares_n; i++) { + proc_bounding_rect(&(contours[i]), &(rect[i]), true); + + pattern.square[i].pos.x_pix = rect[i].x + rect[i].width/2.0; + pattern.square[i].pos.y_pix = rect[i].y + rect[i].height/2.0; + } +} + +static void pattern_squares_len_get (void) +{ + int i; + + proc_load_mem(4); + + /* Get pattern square side lenght in pixels */ + for (i = 0; i < pattern.squares_n; i++) { + proc_pixel_value(pattern.square[i].pos.x_pix, + pattern.square[i].pos.y_pix, + &(pattern.square[i].len)); + pattern.square[i].len *= 2; + } +} + +static void pattern_calib_mm_pix (void) +{ + int i; + uint8_t pattern_len [CONTOURS_MAX]; + uint8_t median_size; + + for (i = 0; i < pattern.squares_n; i++) { + pattern_len[i] = pattern.square[i].len; + } + + median_size = alx_median_u8(pattern.squares_n, pattern_len); + ratio_mm_pix = PATTERN_SQUARE_LEN_MM / median_size; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "mm/pix = %lf", + ratio_mm_pix); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + +/* process -------------------------------------------------------------------*/ +static void lighter_bgr2gray (void) +{ + proc_load_mem(0); + + proc_cvt_color(cv::COLOR_BGR2GRAY); + proc_save_mem(1); +} + +static void lighter_rotation_fix (void) +{ + proc_load_mem(1); + + /* invert image before rotation to avoid black bands */ + proc_not(); + proc_rotate(pattern.center.x_pix, pattern.center.y_pix, pattern.angle); + proc_save_mem(2); +} + +static void lighter_dimensions_fix (void) +{ + /* Need to correct also pattern dilatation (pattern_dimensions_get()) */ + proc_load_mem(2); + + proc_ROI(pattern.origin.x_pix, pattern.origin.y_pix, + pattern.width, pattern.height); + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_save_mem(3); +} + +static void lighter_segment (void) +{ + proc_load_mem(3); + + proc_dilate_erode(8 / ratio_mm_pix); + proc_save_mem(4); + + proc_distance_transform(); + proc_threshold(cv::THRESH_BINARY_INV, 30); + proc_distance_transform(); + proc_skeleton(); + proc_threshold(cv::THRESH_BINARY_INV, 10); + proc_save_ref(); + proc_save_mem(5); + + proc_load_mem(3); + proc_and_2ref(); + proc_distance_transform(); + proc_threshold(cv::THRESH_BINARY, 10); + proc_save_mem(6); +} + +static int lighter_contours (void) +{ + int status; + + proc_load_mem(6); + + proc_contours(&contours, &hierarchy); + + /* If no contour is found, error: NOK_LIGHTER */ + if (!contours.size()) { + status = LIGHTER_NOK_LIGHTER; + return status; + } + + status = LIGHTER_OK; + return status; +} + +static void lighter_position_pix (void) +{ + int i; + + proc_fit_ellipse(&(contours[0]), &(rect_rot[0]), true); + + lighter.pos.x_pix = rect_rot[0].center.x; + lighter.pos.y_pix = rect_rot[0].center.y; + + lighter.angle = -rect_rot[0].angle + 90.0; + if (lighter.angle < 0) { + lighter.angle += 180.0; + } +} + +static void lighter_position_mm (void) +{ + int i; + + lighter.pos.x_mm = ratio_mm_pix * lighter.pos.x_pix; + lighter.pos.y_mm = ratio_mm_pix * lighter.pos.y_pix; +} + +static void lighter_size_pix (void) +{ + double area; + double perimeter; + int i; + + /* Get size */ + proc_contours_size(&contours, &area, &perimeter); + lighter.area_pix2 = area; + lighter.perimeter_pix = perimeter; +} + +static void lighter_size_mm (void) +{ + int i; + + /* Get size */ + lighter.area_mm2 = pow(ratio_mm_pix, 2) * lighter.area_pix2; + lighter.perimeter_mm = ratio_mm_pix * lighter.perimeter_pix; +} + +static void lighter_shape (void) +{ + int i; + + /* Get shape */ + proc_min_area_rect(&(contours[0]), &(rect_rot[0]), true); + + lighter.ratio_p2_a = pow(lighter.perimeter_pix, 2) / + lighter.area_pix2; + + lighter.area_rect = rect_rot.size.width * rect_rot.size.height; + lighter.perimeter_rect = 2.0 * (rect_rot.size.width + + rect_rot.size.height); + + lighter.ratio_p_prect = lighter.perimeter_pix / + lighter.perimeter_rect; + lighter.ratio_a_arect = lighter.area_pix2 / lighter.area_rect; +} + +static void lighter_log (void) +{ + int i; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Lighter:"); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " pos: (%.1lf, %.1lf) mm", + lighter.pos.x_mm, + lighter.pos.y_mm); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " ang = %.1lf DEG", + lighter.angle); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " A = %.1lf mm2", + lighter.area_mm2); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " P = %.1lf mm", + lighter.perimeter_mm); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " p2/A = %.2lf", + lighter.ratio_p2_a); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " p/p_r = %.2lf", + lighter.ratio_p_prect); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " A/A_r = %.2lf", + lighter.ratio_a_arect); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ -- cgit v1.2.3 From 40c0fa4f843784bce019be3150b9bad60254a234 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 19 Dec 2018 14:00:51 +0100 Subject: Add lighter proc --- modules/proc/inc/proc_lighter.h | 48 ++++++++++++++++++++++++++++++ modules/proc/inc/proc_lighter.hpp | 61 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+) create mode 100644 modules/proc/inc/proc_lighter.h create mode 100644 modules/proc/inc/proc_lighter.hpp diff --git a/modules/proc/inc/proc_lighter.h b/modules/proc/inc/proc_lighter.h new file mode 100644 index 0000000..077bf56 --- /dev/null +++ b/modules/proc/inc/proc_lighter.h @@ -0,0 +1,48 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_LIGHTER_H + # define VA_PROC_LIGHTER_H + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Label { + LIGHTER_OK, + LIGHTER_NOK_LIGHTER, + LIGHTER_NOK_SIZE + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_lighter_calibrate (void); + int proc_lighter (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_lighter.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_lighter.hpp b/modules/proc/inc/proc_lighter.hpp new file mode 100644 index 0000000..9e5529a --- /dev/null +++ b/modules/proc/inc/proc_lighter.hpp @@ -0,0 +1,61 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_LIGHTER_H + # define VA_PROC_LIGHTER_H + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Lighter { + LIGHTER_OK, + LIGHTER_NOK_PATTERN, + LIGHTER_NOK_LIGHTER, + LIGHTER_NOK_SIZE + }; + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_lighter_calibrate (void); + int proc_lighter (void); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_lighter.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ -- cgit v1.2.3 From e47d70e7f6cbb8772ef30c0ba9ede3b3071703a4 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 19 Dec 2018 14:11:43 +0100 Subject: Add lighter proc --- modules/proc/inc/proc_lighter.h | 2 +- modules/proc/src/proc_iface.c | 1 + modules/proc/src/proc_lighter.cpp | 27 ++++++++------------------- modules/proc/tmp/Makefile | 26 ++++++++++++++++++++++++-- 4 files changed, 34 insertions(+), 22 deletions(-) diff --git a/modules/proc/inc/proc_lighter.h b/modules/proc/inc/proc_lighter.h index 077bf56..094e723 100644 --- a/modules/proc/inc/proc_lighter.h +++ b/modules/proc/inc/proc_lighter.h @@ -18,7 +18,7 @@ /****************************************************************************** ******* enums **************************************************************** ******************************************************************************/ - enum Proc_Label { + enum Proc_Lighter { LIGHTER_OK, LIGHTER_NOK_LIGHTER, LIGHTER_NOK_SIZE diff --git a/modules/proc/src/proc_iface.c b/modules/proc/src/proc_iface.c index a90466e..ba29a92 100644 --- a/modules/proc/src/proc_iface.c +++ b/modules/proc/src/proc_iface.c @@ -29,6 +29,7 @@ /* Module --------------------------------------------------------------------*/ #include "proc_label.h" + #include "proc_lighter.h" #include "proc_objects.h" #include "proc_coins.h" #include "proc_resistor.h" diff --git a/modules/proc/src/proc_lighter.cpp b/modules/proc/src/proc_lighter.cpp index 3aa2b2a..9b57e9f 100644 --- a/modules/proc/src/proc_lighter.cpp +++ b/modules/proc/src/proc_lighter.cpp @@ -143,7 +143,7 @@ static void lighter_log (void); /****************************************************************************** ******* global functions ***************************************************** ******************************************************************************/ -int proc_lighter_calibrate (void) +int proc_lighter_calibrate (void) { int status; @@ -195,7 +195,7 @@ int proc_lighter_calibrate (void) return status; } -int proc_lighter (void) +int proc_lighter (void) { int status; @@ -546,8 +546,6 @@ static int lighter_contours (void) static void lighter_position_pix (void) { - int i; - proc_fit_ellipse(&(contours[0]), &(rect_rot[0]), true); lighter.pos.x_pix = rect_rot[0].center.x; @@ -561,8 +559,6 @@ static void lighter_position_pix (void) static void lighter_position_mm (void) { - int i; - lighter.pos.x_mm = ratio_mm_pix * lighter.pos.x_pix; lighter.pos.y_mm = ratio_mm_pix * lighter.pos.y_pix; } @@ -571,7 +567,6 @@ static void lighter_size_pix (void) { double area; double perimeter; - int i; /* Get size */ proc_contours_size(&contours, &area, &perimeter); @@ -581,8 +576,6 @@ static void lighter_size_pix (void) static void lighter_size_mm (void) { - int i; - /* Get size */ lighter.area_mm2 = pow(ratio_mm_pix, 2) * lighter.area_pix2; lighter.perimeter_mm = ratio_mm_pix * lighter.perimeter_pix; @@ -590,27 +583,24 @@ static void lighter_size_mm (void) static void lighter_shape (void) { - int i; - /* Get shape */ proc_min_area_rect(&(contours[0]), &(rect_rot[0]), true); lighter.ratio_p2_a = pow(lighter.perimeter_pix, 2) / - lighter.area_pix2; + lighter.area_pix2; - lighter.area_rect = rect_rot.size.width * rect_rot.size.height; - lighter.perimeter_rect = 2.0 * (rect_rot.size.width + - rect_rot.size.height); + lighter.area_rect = rect_rot[0].size.width * + rect_rot[0].size.height; + lighter.perimeter_rect = 2.0 * (rect_rot[0].size.width + + rect_rot[0].size.height); lighter.ratio_p_prect = lighter.perimeter_pix / - lighter.perimeter_rect; + lighter.perimeter_rect; lighter.ratio_a_arect = lighter.area_pix2 / lighter.area_rect; } static void lighter_log (void) { - int i; - /* Write diameters into log */ snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Lighter:"); @@ -666,7 +656,6 @@ static void lighter_log (void) lighter.ratio_a_arect); user_iface_log.lvl[user_iface_log.len] = 0; (user_iface_log.len)++; - } } diff --git a/modules/proc/tmp/Makefile b/modules/proc/tmp/Makefile index f84422f..120bf48 100644 --- a/modules/proc/tmp/Makefile +++ b/modules/proc/tmp/Makefile @@ -15,8 +15,9 @@ SRC_DIR = $(PROC_DIR)/src/ # dependencies -_ALL = proc_label.o proc_objects.o proc_coins.o \ - proc_resistor.o proc_common.o proc_iface.o +_ALL = proc_label.o proc_lighter.o proc_objects.o \ + proc_coins.o proc_resistor.o \ + proc_common.o proc_iface.o ALL = $(_ALL) proc_mod.o PROC_LAB_INC_IMG = img_iface.hpp @@ -30,6 +31,20 @@ PROC_LAB_INC_DIRS = -I $(INC_DIR) \ -I $(IMG_INC_DIR) \ -I $(USR_INC_DIR) +PROC_LGHT_INC_LIBALX = alx_math.hpp +PROC_LGHT_INC_IMG = img_iface.hpp +PROC_LGHT_INC_USR = user_iface.hpp +PROC_LGHT_INC = proc_lighter.hpp proc_common.hpp +PROC_LGHT_DEPS = $(SRC_DIR)/proc_lighter.cpp \ + $(patsubst %,$(INC_DIR)/%,$(PROC_LGHT_INC)) \ + $(patsubst %,$(IMG_INC_DIR)/%,$(PROC_LGHT_INC_IMG)) \ + $(patsubst %,$(USR_INC_DIR)/%,$(PROC_LGHT_INC_USR)) \ + $(patsubst %,$(LIBALX_INC_DIR)/%,$(PROC_LGHT_INC_LIBALX)) +PROC_LGHT_INC_DIRS = -I $(INC_DIR) \ + -I $(IMG_INC_DIR) \ + -I $(USR_INC_DIR) \ + -I $(LIBALX_INC_DIR) + PROC_OBJS_INC_LIBALX = alx_math.hpp PROC_OBJS_INC_IMG = img_iface.hpp PROC_OBJS_INC_USR = user_iface.hpp @@ -115,6 +130,13 @@ proc_label.o: proc_label.s $(PROC_LAB_DEPS) $(Q)$(AS) $< -o $@ @echo " AS $@" +proc_lighter.s: $(PROC_LGHT_DEPS) + $(Q)$(CXX) $(CXXFLAGS) $(PROC_LGHT_INC_DIRS) -S $< -o $@ + @echo " CXX $@" +proc_lighter.o: proc_lighter.s $(PROC_LGHT_DEPS) + $(Q)$(AS) $< -o $@ + @echo " AS $@" + proc_objects.s: $(PROC_OBJS_DEPS) $(Q)$(CXX) $(CXXFLAGS) $(PROC_OBJS_INC_DIRS) -S $< -o $@ @echo " CXX $@" -- cgit v1.2.3 From c0dbb2268451c89a6eb18fea4d3ac70f1608be85 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 19 Dec 2018 14:14:06 +0100 Subject: Update libalx (new libalx-io.a) --- Makefile | 2 ++ bin/Makefile | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 543b425..c5e2296 100644 --- a/Makefile +++ b/Makefile @@ -214,6 +214,8 @@ PHONY += libalx libalx: @echo ' MAKE libalx-base' $(Q)make base -C $(LIBALX_DIR) + @echo ' MAKE libalx-io' + $(Q)make io -C $(LIBALX_DIR) @echo ' MAKE libalx-curses' $(Q)make curses -C $(LIBALX_DIR) diff --git a/bin/Makefile b/bin/Makefile index e480144..5e0ff01 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -15,12 +15,13 @@ MAIN_OBJ_MODULES = modules.o MAIN_OBJS = $(TMP_DIR)/main.o \ $(patsubst %,$(MODULES_TMP_DIR)/%,$(MAIN_OBJ_MODULES)) -MAIN_LIB_LIBALX = libalx-base.a libalx-curses.a +MAIN_LIB_LIBALX = libalx-base.a libalx-io.a libalx-curses.a MAIN_LIBS = \ $(patsubst %,$(LIBALX_LIB_DIR)/%,$(MAIN_LIB_LIBALX)) # static libs -STATIC_LIB_LIBALX = -L $(LIBALX_LIB_DIR) -l alx-curses -l alx-base +STATIC_LIB_LIBALX = -L $(LIBALX_LIB_DIR) \ + -l alx-curses -l alx-io -l alx-base STATIC_LIBS = $(STATIC_LIB_LIBALX) -- cgit v1.2.3 From 9ec7b1fa49c05a351788634f3d6d22346082770e Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 20 Dec 2018 13:50:37 +0100 Subject: Add lighter proc --- Makefile | 2 +- modules/menu/src/menu_tui.c | 12 +++-- modules/proc/inc/proc_iface.h | 4 +- modules/proc/inc/proc_iface.hpp | 4 +- modules/proc/src/proc_iface.c | 35 ++++++++++---- modules/proc/src/proc_lighter.cpp | 97 +++++++++++++++++++++++++++++++-------- modules/save/inc/save.h | 4 ++ modules/save/inc/save.hpp | 4 ++ modules/save/src/save.cpp | 4 ++ 9 files changed, 131 insertions(+), 35 deletions(-) diff --git a/Makefile b/Makefile index c5e2296..7891c68 100644 --- a/Makefile +++ b/Makefile @@ -131,7 +131,7 @@ CXXFLAGS_W += -Wextra CXXFLAGS_W += -Werror CXXFLAGS_W += -Wno-format-truncation CXXFLAGS_W += -Wno-format-zero-length -#CXXFLAGS_W += -Wno-unused-function +CXXFLAGS_W += -Wno-unused-function CXXFLAGS_W += -Wno-unused-parameter CXXFLAGS_PKG = `pkg-config --cflags ncurses` diff --git a/modules/menu/src/menu_tui.c b/modules/menu/src/menu_tui.c index ec50267..e8ba5ce 100644 --- a/modules/menu/src/menu_tui.c +++ b/modules/menu/src/menu_tui.c @@ -223,13 +223,14 @@ static void menu_tui_series (void) h = 23; w = 80; int N; - N = 5; - struct Alx_Menu mnu[5] = { - {6, 4, "[0] Back"}, + N = 6; + struct Alx_Menu mnu[6] = { + {8, 4, "[0] Back"}, {2, 4, "[1] Label"}, {3, 4, "[2] Objects"}, {4, 4, "[3] Coins"}, - {5, 4, "[4] Resistor"} + {5, 4, "[4] Resistor"}, + {6, 4, "[5] Lighter"} }; /* Menu loop */ @@ -250,6 +251,9 @@ static void menu_tui_series (void) case 4: proc_mode = PROC_MODE_RESISTOR_SERIES; break; + case 5: + proc_mode = PROC_MODE_LIGHTER_SERIES; + break; } } diff --git a/modules/proc/inc/proc_iface.h b/modules/proc/inc/proc_iface.h index 7225f25..44f8a1e 100644 --- a/modules/proc/inc/proc_iface.h +++ b/modules/proc/inc/proc_iface.h @@ -34,7 +34,9 @@ PROC_MODE_COINS_SERIES, PROC_MODE_COINS_CALIB, PROC_MODE_RESISTOR_SERIES, - PROC_MODE_RESISTOR_CALIB + PROC_MODE_RESISTOR_CALIB, + PROC_MODE_LIGHTER_SERIES, + PROC_MODE_LIGHTER_CALIB }; enum Proc_DBG { diff --git a/modules/proc/inc/proc_iface.hpp b/modules/proc/inc/proc_iface.hpp index 941467b..0396615 100644 --- a/modules/proc/inc/proc_iface.hpp +++ b/modules/proc/inc/proc_iface.hpp @@ -34,7 +34,9 @@ PROC_MODE_COINS_SERIES, PROC_MODE_COINS_CALIB, PROC_MODE_RESISTOR_SERIES, - PROC_MODE_RESISTOR_CALIB + PROC_MODE_RESISTOR_CALIB, + PROC_MODE_LIGHTER_SERIES, + PROC_MODE_LIGHTER_CALIB }; enum Proc_DBG { diff --git a/modules/proc/src/proc_iface.c b/modules/proc/src/proc_iface.c index ba29a92..45ccb02 100644 --- a/modules/proc/src/proc_iface.c +++ b/modules/proc/src/proc_iface.c @@ -85,6 +85,12 @@ int proc_iface_single (int action) case PROC_MODE_RESISTOR_SERIES: error = proc_resistor(); break; + case PROC_MODE_LIGHTER_CALIB: + error = proc_lighter_calibrate(); + break; + case PROC_MODE_LIGHTER_SERIES: + error = proc_lighter(); + break; default: error = -1; } @@ -110,7 +116,7 @@ void proc_iface_series (void) bool file_error; int num_len; char file_basename [FILENAME_MAX]; - char file_ext [80]; + char file_ext [FILENAME_MAX]; char file_name [FILENAME_MAX]; bool proc_error; char save_error_as [FILENAME_MAX]; @@ -122,36 +128,45 @@ void proc_iface_series (void) case PROC_MODE_LABEL_SERIES: snprintf(proc_path, FILENAME_MAX, "%s", labels_path); snprintf(proc_fail_path, FILENAME_MAX, "%s", labels_fail_path); - snprintf(file_basename, 80, "b"); + snprintf(file_basename, FILENAME_MAX, "b"); num_len = 4; - snprintf(file_ext, 80, ".BMP"); + snprintf(file_ext, FILENAME_MAX, ".BMP"); i = 1; break; case PROC_MODE_OBJECTS_SERIES: snprintf(proc_path, FILENAME_MAX, "%s", objects_path); snprintf(proc_fail_path, FILENAME_MAX, "%s", objects_fail_path); - snprintf(file_basename, 80, "o"); + snprintf(file_basename, FILENAME_MAX, "o"); num_len = 4; - snprintf(file_ext, 80, ".jpeg"); + snprintf(file_ext, FILENAME_MAX, ".jpeg"); i = 0; proc_mode++; break; case PROC_MODE_COINS_SERIES: snprintf(proc_path, FILENAME_MAX, "%s", coins_path); snprintf(proc_fail_path, FILENAME_MAX, "%s", coins_fail_path); - snprintf(file_basename, 80, "c"); + snprintf(file_basename, FILENAME_MAX, "c"); num_len = 4; - snprintf(file_ext, 80, ".png"); + snprintf(file_ext, FILENAME_MAX, ".jpeg"); i = 1; break; case PROC_MODE_RESISTOR_SERIES: snprintf(proc_path, FILENAME_MAX, "%s", resistors_path); snprintf(proc_fail_path, FILENAME_MAX, "%s", resistors_fail_path); - snprintf(file_basename, 80, "r"); + snprintf(file_basename, FILENAME_MAX, "r"); num_len = 4; - snprintf(file_ext, 80, ".png"); + snprintf(file_ext, FILENAME_MAX, ".png"); i = 1; break; + case PROC_MODE_LIGHTER_SERIES: + snprintf(proc_path, FILENAME_MAX, "%s", lighters_path); + snprintf(proc_fail_path, FILENAME_MAX, "%s", lighters_fail_path); + snprintf(file_basename, FILENAME_MAX, "lighter"); + num_len = 4; + snprintf(file_ext, FILENAME_MAX, ".png"); + i = 0; + proc_mode++; + break; default: return; } @@ -188,7 +203,7 @@ void proc_iface_series (void) /* Show log */ char txt_tmp [80]; - snprintf(txt_tmp, 80, "%04i", i); + snprintf(txt_tmp, FILENAME_MAX, "%04i", i); user_iface_show_log(txt_tmp, "Item"); if (proc_debug >= PROC_DBG_STOP_ITEM) { diff --git a/modules/proc/src/proc_lighter.cpp b/modules/proc/src/proc_lighter.cpp index 9b57e9f..85ffba2 100644 --- a/modules/proc/src/proc_lighter.cpp +++ b/modules/proc/src/proc_lighter.cpp @@ -130,7 +130,10 @@ static void pattern_calib_mm_pix (void); static void lighter_bgr2gray (void); static void lighter_rotation_fix (void); static void lighter_dimensions_fix (void); -static void lighter_segment (void); +static void lighter_segment_full (void); +static int lighter_align (void); +static void lighter_segment_base (void); +static void lighter_crop (void); static int lighter_contours (void); static void lighter_position_pix (void); static void lighter_size_pix (void); @@ -217,12 +220,15 @@ int proc_lighter (void) /* Measure time */ clock_start(); - lighter_segment(); + lighter_segment_full(); + lighter_align(); + lighter_segment_base(); + lighter_crop(); /* Measure time */ clock_stop("Segment lighter"); } - /* Find lighters positions */ +#if 0 /* Find lighters positions */ { /* Measure time */ clock_start(); @@ -278,7 +284,7 @@ int proc_lighter (void) /* Measure time */ clock_stop("Lighter properties (log)"); } - +#endif status = LIGHTER_OK; result_lighter(status); return status; @@ -498,34 +504,89 @@ static void lighter_dimensions_fix (void) /* Need to correct also pattern dilatation (pattern_dimensions_get()) */ proc_load_mem(2); - proc_ROI(pattern.origin.x_pix, pattern.origin.y_pix, - pattern.width, pattern.height); - proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_ROI(pattern.origin.x_pix+200, pattern.origin.y_pix+200, + pattern.width-400, pattern.height-200); proc_save_mem(3); } -static void lighter_segment (void) +static void lighter_segment_full (void) { proc_load_mem(3); - proc_dilate_erode(8 / ratio_mm_pix); + proc_smooth(IMGI_SMOOTH_MEDIAN, 5); + proc_threshold(cv::THRESH_BINARY, 80); proc_save_mem(4); +} + +static int lighter_align (void) +{ + int status; + + proc_load_mem(4); + + proc_dilate_erode(2 / ratio_mm_pix); + proc_erode_dilate(4.5 / ratio_mm_pix); + proc_contours(&contours, &hierarchy); + + /* If no contour is found, error: NOK_RESISTOR */ + if (contours.size() != 1) { + status = LIGHTER_NOK_LIGHTER; + return status; + } + + proc_min_area_rect(&(contours[0]), &rect_rot[0], true); + + /* If width > height, it is taking into acount the incorrect side */ + if (rect_rot[0].size.width > rect_rot[0].size.height) { + int tmp; + rect_rot[0].angle += 90.0; + tmp = rect_rot[0].size.width; + rect_rot[0].size.width = rect_rot[0].size.height; + rect_rot[0].size.height = tmp; + } + + proc_rotate(rect_rot[0].center.x, rect_rot[0].center.y, rect_rot[0].angle); - proc_distance_transform(); - proc_threshold(cv::THRESH_BINARY_INV, 30); - proc_distance_transform(); - proc_skeleton(); - proc_threshold(cv::THRESH_BINARY_INV, 10); - proc_save_ref(); proc_save_mem(5); + status = LIGHTER_OK; + return status; +} + +static void lighter_segment_base (void) +{ proc_load_mem(3); - proc_and_2ref(); - proc_distance_transform(); - proc_threshold(cv::THRESH_BINARY, 10); + + proc_rotate(rect_rot[0].center.x, rect_rot[0].center.y, rect_rot[0].angle); + proc_smooth(IMGI_SMOOTH_MEDIAN, 5); + proc_threshold(cv::THRESH_BINARY, 65); + proc_erode_dilate(rect_rot[0].size.width * 0.43); +// proc_dilate_erode(rect_rot[0].size.width * 0.2); + + proc_contours(&contours, &hierarchy); + proc_bounding_rect(&(contours[0]), &(rect[0]), true); + proc_save_mem(6); } +static void lighter_crop (void) +{ + int x; + int y; + int w; + int h; + + proc_load_mem(3); + + proc_rotate(rect_rot[0].center.x, rect_rot[0].center.y, rect_rot[0].angle); + w = rect[0].width * 1.2; + h = rect[0].width * 0.9; + x = rect[0].x - rect[0].width * 0.1; + y = rect[0].y - h * 0.9; + proc_ROI(x, y, w, h); + proc_save_mem(7); +} + static int lighter_contours (void) { int status; diff --git a/modules/save/inc/save.h b/modules/save/inc/save.h index dc0d850..46cab58 100644 --- a/modules/save/inc/save.h +++ b/modules/save/inc/save.h @@ -27,6 +27,8 @@ # define USER_SAVED_DIR "vision-artificial/saved/" # define USER_LABELS_DIR "vision-artificial/labels/" # define USER_LABELS_FAIL_DIR "vision-artificial/labels/fail" + # define USER_LIGHTERS_DIR "vision-artificial/lighters/" + # define USER_LIGHTERS_FAIL_DIR "vision-artificial/lighters/fail" # define USER_OBJECTS_DIR "vision-artificial/objects/" # define USER_OBJECTS_FAIL_DIR "vision-artificial/objects/fail" # define USER_COINS_DIR "vision-artificial/coins/" @@ -44,6 +46,8 @@ extern char saved_path [FILENAME_MAX]; extern char labels_path [FILENAME_MAX]; extern char labels_fail_path [FILENAME_MAX]; + extern char lighters_path [FILENAME_MAX]; + extern char lighters_fail_path [FILENAME_MAX]; extern char objects_path [FILENAME_MAX]; extern char objects_fail_path [FILENAME_MAX]; extern char coins_path [FILENAME_MAX]; diff --git a/modules/save/inc/save.hpp b/modules/save/inc/save.hpp index edabbf3..5dcf6e5 100644 --- a/modules/save/inc/save.hpp +++ b/modules/save/inc/save.hpp @@ -37,6 +37,8 @@ extern "C" { # define USER_SAVED_DIR "vision-artificial/saved/" # define USER_LABELS_DIR "vision-artificial/labels/" # define USER_LABELS_FAIL_DIR "vision-artificial/labels/fail" + # define USER_LIGHTERS_DIR "vision-artificial/lighters/" + # define USER_LIGHTERS_FAIL_DIR "vision-artificial/lighters/fail" # define USER_OBJECTS_DIR "vision-artificial/objects/" # define USER_OBJECTS_FAIL_DIR "vision-artificial/objects/fail" # define USER_COINS_DIR "vision-artificial/coins/" @@ -55,6 +57,8 @@ extern "C" { extern char saved_path [FILENAME_MAX]; extern char labels_path [FILENAME_MAX]; extern char labels_fail_path [FILENAME_MAX]; + extern char lighters_path [FILENAME_MAX]; + extern char lighters_fail_path [FILENAME_MAX]; extern char objects_path [FILENAME_MAX]; extern char objects_fail_path [FILENAME_MAX]; extern char coins_path [FILENAME_MAX]; diff --git a/modules/save/src/save.cpp b/modules/save/src/save.cpp index 861a06e..e174f8b 100644 --- a/modules/save/src/save.cpp +++ b/modules/save/src/save.cpp @@ -39,6 +39,8 @@ char user_prog_path [FILENAME_MAX]; char saved_path [FILENAME_MAX]; char labels_path [FILENAME_MAX]; char labels_fail_path [FILENAME_MAX]; +char lighters_path [FILENAME_MAX]; +char lighters_fail_path [FILENAME_MAX]; char objects_path [FILENAME_MAX]; char objects_fail_path [FILENAME_MAX]; char coins_path [FILENAME_MAX]; @@ -58,6 +60,8 @@ void save_init (void) snprintf(saved_path, FILENAME_MAX, "%s/%s/", home_path, USER_SAVED_DIR); snprintf(labels_path, FILENAME_MAX, "%s/%s/", home_path, USER_LABELS_DIR); snprintf(labels_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_LABELS_FAIL_DIR); + snprintf(lighters_path, FILENAME_MAX, "%s/%s/", home_path, USER_LIGHTERS_DIR); + snprintf(lighters_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_LIGHTERS_FAIL_DIR); snprintf(objects_path, FILENAME_MAX, "%s/%s/", home_path, USER_OBJECTS_DIR); snprintf(objects_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_OBJECTS_FAIL_DIR); snprintf(coins_path, FILENAME_MAX, "%s/%s/", home_path, USER_COINS_DIR); -- cgit v1.2.3 From 5b017bd7f0c0fa3a59c6e231aced2489d6a5a40f Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Fri, 28 Dec 2018 12:09:52 +0100 Subject: Update libalx --- libalx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libalx b/libalx index 0be5766..6d6b1a6 160000 --- a/libalx +++ b/libalx @@ -1 +1 @@ -Subproject commit 0be5766a2bcea31148de476d3ab13faed680cbef +Subproject commit 6d6b1a657df6110cda6ba806917d2460ea87586f -- cgit v1.2.3 From 9df9e4eff43f3288cb606eb09dcd6f69ccc78fbc Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Fri, 28 Dec 2018 12:11:02 +0100 Subject: Add missing header stddef.h --- modules/ctrl/src/start.c | 1 + modules/image/inc/img_cv.hpp | 2 +- modules/image/inc/img_iface.h | 13 +++++++++++-- modules/image/inc/img_iface.hpp | 9 +++++++++ modules/image/src/img_iface.cpp | 9 +++++---- modules/image/src/img_ocr.c | 1 + modules/image/src/img_zbar.cpp | 1 + modules/menu/src/menu_tui.c | 1 + modules/proc/src/proc_common.cpp | 1 + 9 files changed, 31 insertions(+), 7 deletions(-) diff --git a/modules/ctrl/src/start.c b/modules/ctrl/src/start.c index 2a4c18f..bd801c1 100644 --- a/modules/ctrl/src/start.c +++ b/modules/ctrl/src/start.c @@ -9,6 +9,7 @@ /* Standard C ----------------------------------------------------------------*/ /* errno */ #include + #include /* printf() */ #include diff --git a/modules/image/inc/img_cv.hpp b/modules/image/inc/img_cv.hpp index 8327d67..12b4713 100644 --- a/modules/image/inc/img_cv.hpp +++ b/modules/image/inc/img_cv.hpp @@ -13,7 +13,7 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ - /* openCV */ +/* packages ------------------------------------------------------------------*/ #include diff --git a/modules/image/inc/img_iface.h b/modules/image/inc/img_iface.h index f23991b..1bac46f 100644 --- a/modules/image/inc/img_iface.h +++ b/modules/image/inc/img_iface.h @@ -10,6 +10,13 @@ # define VA_IMG_IFACE_H +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + #include + + /****************************************************************************** ******* macros *************************************************************** ******************************************************************************/ @@ -22,7 +29,10 @@ # define IMG_IFACE_THR_OTSU (-1) /* Functions -----------------------------------------------------------------*/ - # define img_iface_act_nodata(x) img_iface_act(x, NULL); + # define img_iface_act_nodata(x) \ + do { \ + img_iface_act(x, NULL) \ + } while (0) /****************************************************************************** @@ -157,7 +167,6 @@ void img_iface_cleanup_main (void); void img_iface_load (const char *fpath, const char *fname); void img_iface_cleanup (void); - /* data should *always* be NULL */ void img_iface_act (int action, void *data); void img_iface_show_img (void); void img_iface_show_hist_c1 (void); diff --git a/modules/image/inc/img_iface.hpp b/modules/image/inc/img_iface.hpp index f17c609..8e28700 100644 --- a/modules/image/inc/img_iface.hpp +++ b/modules/image/inc/img_iface.hpp @@ -13,6 +13,9 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + #include + /* Standard C++ --------------------------------------------------------------*/ /* class std::vector */ #include @@ -34,6 +37,12 @@ # define IMG_IFACE_THR_OTSU (-1) +/* Functions -----------------------------------------------------------------*/ + # define img_iface_act_nodata(x) \ + do { \ + img_iface_act(x, NULL) \ + } while (0) + /****************************************************************************** ******* enums **************************************************************** diff --git a/modules/image/src/img_iface.cpp b/modules/image/src/img_iface.cpp index 6f80249..25287c0 100644 --- a/modules/image/src/img_iface.cpp +++ b/modules/image/src/img_iface.cpp @@ -6,18 +6,19 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ -/* Standard C++ --------------------------------------------------------------*/ - /* class std::vector */ - #include - /* Standard C ----------------------------------------------------------------*/ /* errno */ #include /* INFINITY */ #include + #include /* snprintf() */ #include +/* Standard C++ --------------------------------------------------------------*/ + /* class std::vector */ + #include + /* Packages ------------------------------------------------------------------*/ /* openCV */ #include diff --git a/modules/image/src/img_ocr.c b/modules/image/src/img_ocr.c index a4d2e91..5aba51e 100644 --- a/modules/image/src/img_ocr.c +++ b/modules/image/src/img_ocr.c @@ -9,6 +9,7 @@ /* Standard C ----------------------------------------------------------------*/ /* INT_MAX */ #include + #include /* snprintf() & FILENAME_MAX */ #include diff --git a/modules/image/src/img_zbar.cpp b/modules/image/src/img_zbar.cpp index 1c9b412..083093b 100644 --- a/modules/image/src/img_zbar.cpp +++ b/modules/image/src/img_zbar.cpp @@ -9,6 +9,7 @@ /* Standard C ----------------------------------------------------------------*/ /* INT_MAX */ #include + #include /* snprintf() */ #include diff --git a/modules/menu/src/menu_tui.c b/modules/menu/src/menu_tui.c index ec50267..abf9636 100644 --- a/modules/menu/src/menu_tui.c +++ b/modules/menu/src/menu_tui.c @@ -9,6 +9,7 @@ /* Standard C ----------------------------------------------------------------*/ #include #include + #include /* libalx --------------------------------------------------------------------*/ #include "alx_ncur.h" diff --git a/modules/proc/src/proc_common.cpp b/modules/proc/src/proc_common.cpp index 7f92e9b..692cbe7 100644 --- a/modules/proc/src/proc_common.cpp +++ b/modules/proc/src/proc_common.cpp @@ -7,6 +7,7 @@ ******* headers ************************************************************** ******************************************************************************/ /* Standard C ----------------------------------------------------------------*/ + #include /* snprintf() & fflush() */ #include /* clock_t & clock() & CLOCKS_PER_SEC */ -- cgit v1.2.3 From 8fe6430027a8a601e9adbd78aa4d3500709c3904 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Fri, 28 Dec 2018 12:48:26 +0100 Subject: Fix build bug: missing libalx-io --- Makefile | 48 +++++++++++++++++++++++++++--------------------- bin/Makefile | 5 +++-- libalx | 2 +- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/Makefile b/Makefile index 543b425..963a034 100644 --- a/Makefile +++ b/Makefile @@ -213,65 +213,71 @@ all: binary PHONY += libalx libalx: @echo ' MAKE libalx-base' - $(Q)make base -C $(LIBALX_DIR) + $(Q)$(MAKE) base -C $(LIBALX_DIR) + @echo ' MAKE libalx-io' + $(Q)$(MAKE) io -C $(LIBALX_DIR) @echo ' MAKE libalx-curses' - $(Q)make curses -C $(LIBALX_DIR) + $(Q)$(MAKE) curses -C $(LIBALX_DIR) PHONY += modules modules: libalx @echo ' MAKE modules' - $(Q)make -C $(MODULES_DIR) + $(Q)$(MAKE) -C $(MODULES_DIR) PHONY += object object: modules libalx @echo ' MAKE objects' - $(Q)make -C $(TMP_DIR) + $(Q)$(MAKE) -C $(TMP_DIR) PHONY += binary binary: object @echo ' MAKE binary' - $(Q)make -C $(BIN_DIR) + $(Q)$(MAKE) -C $(BIN_DIR) PHONY += install install: uninstall - @echo " Install:" - @echo " MKDIR $(INSTALL_BIN_DIR)/" + @echo " Install:" + @echo " MKDIR $(INSTALL_BIN_DIR)/" $(Q)mkdir -p $(DESTDIR)/$(INSTALL_BIN_DIR)/ @echo " CP $(BIN_NAME)" $(Q)cp $(BIN_DIR)/$(BIN_NAME) $(DESTDIR)/$(INSTALL_BIN_DIR)/ - @echo " MKDIR $(INSTALL_SHARE_DIR)/$(SHARE_DIR)/" + @echo " MKDIR $(INSTALL_SHARE_DIR)/$(SHARE_DIR)/" $(Q)mkdir -p $(DESTDIR)/$(INSTALL_SHARE_DIR)/$(SHARE_DIR)/ @echo " CP -r share/*" $(Q)cp -r ./share/* $(DESTDIR)/$(INSTALL_SHARE_DIR)/$(SHARE_DIR)/ - @echo " Done" - @echo "" + @echo " Done" + @echo PHONY += uninstall uninstall: - @echo " Clean old installations:" + @echo " Clean old installations:" @echo ' RM binary' $(Q)rm -f $(DESTDIR)/$(INSTALL_BIN_DIR)/$(BIN_NAME) @echo ' RM share/*' $(Q)rm -f -r $(DESTDIR)/$(INSTALL_SHARE_DIR)/$(SHARE_DIR)/ - @echo " Done" - @echo "" + @echo " Done" + @echo PHONY += clean clean: - @echo ' CLEAN libalx' - $(Q)make clean -C $(LIBALX_DIR) @echo ' CLEAN modules' - $(Q)make clean -C $(MODULES_DIR) + $(Q)$(MAKE) clean -C $(MODULES_DIR) @echo ' CLEAN tmp' - $(Q)make clean -C $(TMP_DIR) + $(Q)$(MAKE) clean -C $(TMP_DIR) @echo ' CLEAN bin' - $(Q)make clean -C $(BIN_DIR) + $(Q)$(MAKE) clean -C $(BIN_DIR) + +PHONY += mrproper +mrproper: clean + @echo ' CLEAN libalx' + $(Q)$(MAKE) clean -C $(LIBALX_DIR) PHONY += help help: @echo 'Cleaning targets:' @echo ' clean - Remove all generated files' - @echo '' + @echo ' mrproper - Remove all generated files (including libraries)' + @echo @echo 'Other generic targets:' @echo ' all - Build all targets marked with [*]' @echo '* libalx - Build the libalx library' @@ -280,9 +286,9 @@ help: @echo '* binary - Build the binary' @echo ' install - Install the program into the filesystem' @echo ' uninstall - Uninstall the program off the filesystem' - @echo '' + @echo @echo ' make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build' - @echo '' + @echo @echo 'Execute "make" or "make all" to build all targets marked with [*] ' @echo 'For further info see the ./README file' diff --git a/bin/Makefile b/bin/Makefile index e480144..5e0ff01 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -15,12 +15,13 @@ MAIN_OBJ_MODULES = modules.o MAIN_OBJS = $(TMP_DIR)/main.o \ $(patsubst %,$(MODULES_TMP_DIR)/%,$(MAIN_OBJ_MODULES)) -MAIN_LIB_LIBALX = libalx-base.a libalx-curses.a +MAIN_LIB_LIBALX = libalx-base.a libalx-io.a libalx-curses.a MAIN_LIBS = \ $(patsubst %,$(LIBALX_LIB_DIR)/%,$(MAIN_LIB_LIBALX)) # static libs -STATIC_LIB_LIBALX = -L $(LIBALX_LIB_DIR) -l alx-curses -l alx-base +STATIC_LIB_LIBALX = -L $(LIBALX_LIB_DIR) \ + -l alx-curses -l alx-io -l alx-base STATIC_LIBS = $(STATIC_LIB_LIBALX) diff --git a/libalx b/libalx index 6d6b1a6..5b2dadf 160000 --- a/libalx +++ b/libalx @@ -1 +1 @@ -Subproject commit 6d6b1a657df6110cda6ba806917d2460ea87586f +Subproject commit 5b2dadf6b85acbab7f7329f4fa531c8aa6413913 -- cgit v1.2.3 From 1a4548fc4ab6125de174f1f589e2c2cedfe4a76f Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Fri, 28 Dec 2018 12:49:23 +0100 Subject: Fix bug: missing ; --- modules/image/inc/img_iface.h | 2 +- modules/image/inc/img_iface.hpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/image/inc/img_iface.h b/modules/image/inc/img_iface.h index 1bac46f..ea14c17 100644 --- a/modules/image/inc/img_iface.h +++ b/modules/image/inc/img_iface.h @@ -31,7 +31,7 @@ /* Functions -----------------------------------------------------------------*/ # define img_iface_act_nodata(x) \ do { \ - img_iface_act(x, NULL) \ + img_iface_act(x, NULL); \ } while (0) diff --git a/modules/image/inc/img_iface.hpp b/modules/image/inc/img_iface.hpp index 8e28700..191d09a 100644 --- a/modules/image/inc/img_iface.hpp +++ b/modules/image/inc/img_iface.hpp @@ -40,7 +40,7 @@ /* Functions -----------------------------------------------------------------*/ # define img_iface_act_nodata(x) \ do { \ - img_iface_act(x, NULL) \ + img_iface_act(x, NULL); \ } while (0) -- cgit v1.2.3 From 7f5f9e6e7b39257f8fa3235e2d6bf2f9ae616ea9 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Fri, 28 Dec 2018 12:49:45 +0100 Subject: Fix bug in build (phony) --- modules/Makefile | 29 +++++++++++++++++++---------- modules/ctrl/Makefile | 16 +++++++++++----- modules/ctrl/tmp/Makefile | 15 ++++++++++++++- modules/image/tmp/Makefile | 19 ++++++++++++++++++- 4 files changed, 62 insertions(+), 17 deletions(-) diff --git a/modules/Makefile b/modules/Makefile index e3169fc..2e41afa 100644 --- a/modules/Makefile +++ b/modules/Makefile @@ -28,31 +28,40 @@ export USR_DIR # target: dependencies # action +PHONY := all all: @echo ' MAKE modules: about' - $(Q)make -C $(ABOUT_DIR) + $(Q)$(MAKE) -C $(ABOUT_DIR) @echo ' MAKE modules: ctrl' - $(Q)make -C $(CTRL_DIR) + $(Q)$(MAKE) -C $(CTRL_DIR) @echo ' MAKE modules: image' - $(Q)make -C $(IMG_DIR) + $(Q)$(MAKE) -C $(IMG_DIR) @echo ' MAKE modules: menu' - $(Q)make -C $(MENU_DIR) + $(Q)$(MAKE) -C $(MENU_DIR) @echo ' MAKE modules: proc' - $(Q)make -C $(PROC_DIR) + $(Q)$(MAKE) -C $(PROC_DIR) @echo ' MAKE modules: save' - $(Q)make -C $(SAVE_DIR) + $(Q)$(MAKE) -C $(SAVE_DIR) @echo ' MAKE modules: usr' - $(Q)make -C $(USR_DIR) + $(Q)$(MAKE) -C $(USR_DIR) @echo ' MAKE modules.o' - $(Q)make -C $(TMP_DIR) - @echo "" + $(Q)$(MAKE) -C $(TMP_DIR) + @echo +PHONY += clean clean: - @echo " RM *.o *.s" + @echo " RM *.o *.s" $(Q)find . -type f -name '*.o' -exec rm '{}' '+' $(Q)find . -type f -name '*.s' -exec rm '{}' '+' +################################################################################ +# Declare the contents of the .PHONY variable as phony. +.PHONY: $(PHONY) + + + + ################################################################################ ######## End of file ########################################################### ################################################################################ diff --git a/modules/ctrl/Makefile b/modules/ctrl/Makefile index 60d7283..966cac1 100644 --- a/modules/ctrl/Makefile +++ b/modules/ctrl/Makefile @@ -9,16 +9,22 @@ TMP_DIR = $(CTRL_DIR)/tmp/ # target: dependencies # action +PHONY := all all: - $(Q)cd $(TMP_DIR) && $(MAKE) && cd .. + $(Q)$(MAKE) -C $(TMP_DIR) + +PHONY += clean clean: - $(Q)cd $(TMP_DIR) && $(MAKE) clean && cd .. + $(Q)$(MAKE) clean -C $(TMP_DIR) ################################################################################ -######## End of file ########################################################### -################################################################################ -######## End of file ########################################################### +# Declare the contents of the .PHONY variable as phony. +.PHONY: $(PHONY) + + + + ################################################################################ ######## End of file ########################################################### ################################################################################ diff --git a/modules/ctrl/tmp/Makefile b/modules/ctrl/tmp/Makefile index c02411f..4859f7c 100644 --- a/modules/ctrl/tmp/Makefile +++ b/modules/ctrl/tmp/Makefile @@ -37,8 +37,9 @@ STRT_INC_DIRS = -I $(INC_DIR) \ # target: dependencies # action +PHONY := all all: $(ALL) - + ctrl_mod.o: $(_ALL) $(Q)$(LD) -r $^ -o $@ @@ -53,5 +54,17 @@ start.o: start.s @echo " AS $@" +PHONY += clean clean: $(Q)rm -f *.o *.s + +################################################################################ +# Declare the contents of the .PHONY variable as phony. +.PHONY: $(PHONY) + + + + +################################################################################ +######## End of file ########################################################### +################################################################################ diff --git a/modules/image/tmp/Makefile b/modules/image/tmp/Makefile index e41df65..e3fba87 100644 --- a/modules/image/tmp/Makefile +++ b/modules/image/tmp/Makefile @@ -70,8 +70,9 @@ IMGI_INC_DIRS = -I $(INC_DIR) \ # target: dependencies # action +PHONY := all all: $(ALL) - + img_mod.o: $(_ALL) $(Q)$(LD) -r $^ -o $@ @@ -127,6 +128,22 @@ img_iface.o: img_iface.s $(Q)$(AS) $< -o $@ @echo " AS $@" + +PHONY += clean +clean: + $(Q)rm -f *.o *.s + +################################################################################ +# Declare the contents of the .PHONY variable as phony. +.PHONY: $(PHONY) + + + + +################################################################################ +######## End of file ########################################################### +################################################################################ + ################################################################################ ######## End of file ########################################################### ################################################################################ -- cgit v1.2.3 From ddfb19f08ae2c9c72dc81e3861994cb63140f54a Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Fri, 28 Dec 2018 13:30:33 +0100 Subject: Minor changes --- Makefile | 14 ++++++-------- libalx | 2 +- tmp/Makefile | 11 ++++++++--- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 963a034..4198819 100644 --- a/Makefile +++ b/Makefile @@ -207,16 +207,14 @@ export BIN_NAME # That's the default target when none is given on the command line PHONY := all -all: binary +all: libalx modules main binary PHONY += libalx libalx: - @echo ' MAKE libalx-base' + @echo ' MAKE libalx' $(Q)$(MAKE) base -C $(LIBALX_DIR) - @echo ' MAKE libalx-io' $(Q)$(MAKE) io -C $(LIBALX_DIR) - @echo ' MAKE libalx-curses' $(Q)$(MAKE) curses -C $(LIBALX_DIR) PHONY += modules @@ -224,13 +222,13 @@ modules: libalx @echo ' MAKE modules' $(Q)$(MAKE) -C $(MODULES_DIR) -PHONY += object -object: modules libalx - @echo ' MAKE objects' +PHONY += main +main: modules libalx + @echo ' MAKE main' $(Q)$(MAKE) -C $(TMP_DIR) PHONY += binary -binary: object +binary: main @echo ' MAKE binary' $(Q)$(MAKE) -C $(BIN_DIR) diff --git a/libalx b/libalx index 5b2dadf..a048f89 160000 --- a/libalx +++ b/libalx @@ -1 +1 @@ -Subproject commit 5b2dadf6b85acbab7f7329f4fa531c8aa6413913 +Subproject commit a048f8967abefbde273e9d88362c960b8cb5c779 diff --git a/tmp/Makefile b/tmp/Makefile index 25df3b9..4755930 100644 --- a/tmp/Makefile +++ b/tmp/Makefile @@ -54,6 +54,7 @@ MAIN_INC_DIRS = -I $(LIBALX_INC_DIR) \ # target: dependencies # action +PHONY := all all: $(ALL) main.s: $(MAIN_DEPS) @@ -65,14 +66,18 @@ main.o: main.s @echo "" +PHONY += clean clean: @echo " RM *.o *.s" $(Q)rm -f *.o *.s ################################################################################ -######## End of file ########################################################### -################################################################################ -######## End of file ########################################################### +# Declare the contents of the .PHONY variable as phony. +.PHONY: $(PHONY) + + + + ################################################################################ ######## End of file ########################################################### ################################################################################ -- cgit v1.2.3 From d65535009a21453a017852f46a8a52a7e6825464 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Fri, 28 Dec 2018 13:34:23 +0100 Subject: Minor changes --- libalx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libalx b/libalx index a048f89..110d0dc 160000 --- a/libalx +++ b/libalx @@ -1 +1 @@ -Subproject commit a048f8967abefbde273e9d88362c960b8cb5c779 +Subproject commit 110d0dc28f2ecdf6d371412d41e5c39de2828155 -- cgit v1.2.3 From fb985fd253b5f346614b43cc9965bb5bcc24ef4f Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 28 Dec 2018 14:56:33 +0100 Subject: Add proc step: find lighter hood --- modules/proc/src/proc_lighter.cpp | 50 ++++++++++++++++++++++++++++++--------- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/modules/proc/src/proc_lighter.cpp b/modules/proc/src/proc_lighter.cpp index 85ffba2..9605342 100644 --- a/modules/proc/src/proc_lighter.cpp +++ b/modules/proc/src/proc_lighter.cpp @@ -132,8 +132,9 @@ static void lighter_rotation_fix (void); static void lighter_dimensions_fix (void); static void lighter_segment_full (void); static int lighter_align (void); -static void lighter_segment_base (void); -static void lighter_crop (void); +static void lighter_segment_body (void); +static void lighter_crop_hood (void); +static void lighter_segment_hood (void); static int lighter_contours (void); static void lighter_position_pix (void); static void lighter_size_pix (void); @@ -222,8 +223,11 @@ int proc_lighter (void) lighter_segment_full(); lighter_align(); - lighter_segment_base(); - lighter_crop(); + lighter_segment_body(); + lighter_crop_hood(); + lighter_segment_hood(); +proc_apply(); +proc_save_file(); /* Measure time */ clock_stop("Segment lighter"); @@ -553,7 +557,7 @@ static int lighter_align (void) return status; } -static void lighter_segment_base (void) +static void lighter_segment_body (void) { proc_load_mem(3); @@ -562,29 +566,53 @@ static void lighter_segment_base (void) proc_threshold(cv::THRESH_BINARY, 65); proc_erode_dilate(rect_rot[0].size.width * 0.43); // proc_dilate_erode(rect_rot[0].size.width * 0.2); + proc_save_mem(6); proc_contours(&contours, &hierarchy); proc_bounding_rect(&(contours[0]), &(rect[0]), true); - proc_save_mem(6); + proc_save_mem(7); } -static void lighter_crop (void) +static void lighter_crop_hood (void) { int x; int y; int w; int h; - proc_load_mem(3); + proc_load_mem(6); + proc_not(); + proc_save_ref(); + proc_load_mem(3); proc_rotate(rect_rot[0].center.x, rect_rot[0].center.y, rect_rot[0].angle); + proc_and_2ref(); w = rect[0].width * 1.2; - h = rect[0].width * 0.9; + h = rect[0].width * 0.75; x = rect[0].x - rect[0].width * 0.1; - y = rect[0].y - h * 0.9; + y = rect[0].y - rect[0].width * 0.7; proc_ROI(x, y, w, h); - proc_save_mem(7); + rect[0].x = x; + rect[0].y = y; + rect[0].width = w; + rect[0].height = h; + proc_save_mem(8); +} + +static void lighter_segment_hood (void) +{ + proc_load_mem(8); +/* + proc_smooth(IMGI_SMOOTH_MEDIAN, 5); + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_dilate_erode(5); + proc_erode_dilate(rect[0].height * 0.25); + + proc_contours(&contours, &hierarchy); + proc_bounding_rect(&(contours[0]), &(rect[0]), true); +*/ + proc_save_mem(9); } static int lighter_contours (void) -- cgit v1.2.3 From 0b2209797f6acd1d6e92d6beacf004040371cb44 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Sat, 29 Dec 2018 14:03:46 +0100 Subject: Fix lighters proc for many lighters --- modules/proc/inc/proc_lighters.h | 47 ++++++ modules/proc/inc/proc_lighters.hpp | 59 +++++++ modules/proc/src/proc_lighters.cpp | 315 +++++++++++++++++++++++++++++++++++++ 3 files changed, 421 insertions(+) create mode 100644 modules/proc/inc/proc_lighters.h create mode 100644 modules/proc/inc/proc_lighters.hpp create mode 100644 modules/proc/src/proc_lighters.cpp diff --git a/modules/proc/inc/proc_lighters.h b/modules/proc/inc/proc_lighters.h new file mode 100644 index 0000000..115d98b --- /dev/null +++ b/modules/proc/inc/proc_lighters.h @@ -0,0 +1,47 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_LIGHTERS_H + # define VA_PROC_LIGHTERS_H + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Lighter { + LIGHTER_OK, + LIGHTER_NOK_LIGHTER, + LIGHTER_NOK_SIZE + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_lighter (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_lighters.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_lighters.hpp b/modules/proc/inc/proc_lighters.hpp new file mode 100644 index 0000000..06c4080 --- /dev/null +++ b/modules/proc/inc/proc_lighters.hpp @@ -0,0 +1,59 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_LIGHTERS_H + # define VA_PROC_LIGHTERS_H + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Lighter { + LIGHTER_OK, + LIGHTER_NOK_LIGHTER, + LIGHTER_NOK_SIZE + }; + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_lighter (void); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_lighters.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/src/proc_lighters.cpp b/modules/proc/src/proc_lighters.cpp new file mode 100644 index 0000000..0f7c848 --- /dev/null +++ b/modules/proc/src/proc_lighters.cpp @@ -0,0 +1,315 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + #include + #include + +/* Packages ------------------------------------------------------------------*/ + /* openCV */ + #include + +/* libalx ------------------------------------------------------------------*/ + /* alx_maximum_u8() */ + #include "alx_math.hpp" + +/* Project -------------------------------------------------------------------*/ + /* constants */ + #include "img_iface.hpp" + /* user_iface_log */ + #include "user_iface.hpp" + +/* Module --------------------------------------------------------------------*/ + #include "proc_common.hpp" + + #include "proc_lighters.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs ************************************************************** + ******************************************************************************/ +struct Point { + uint16_t x; + uint16_t y; +}; + +struct Size { + uint16_t h; + uint16_t w; +}; + +struct Lighter_Properties { + /* position */ + struct Point pos; + struct Size size; + double angle; + + bool fork; + bool valve; + bool hood; + bool wheel; +}; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ + +/* Static --------------------------------------------------------------------*/ +static class std::vector >> contours_all; +static class std::vector >> contours_one; +static class cv::Mat hierarchy; +static class cv::RotatedRect rect_rot [CONTOURS_MAX]; +static class cv::Rect_ rect; +static struct Lighter_Properties lighter [CONTOURS_MAX]; +static unsigned lighters_n; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_lighter (int status); + +static void lighters_bgr2gray (void); +static void lighters_segment_full (void); +static int lighters_find (void); +static void lighter_segment_body (int i); +static void lighter_crop_head (int i); +static void lighter_segment_head (int i); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +int proc_lighter (void) +{ + int status; + int i; + + proc_save_mem(0); + /* Segment lighters */ + { + /* Measure time */ + clock_start(); + + lighters_bgr2gray(); + lighters_segment_full(); + lighters_find(); + + /* Measure time */ + clock_stop("Segment lighten"); + } + for (i = 0; (unsigned)i < lighters_n; i++) { + /* Segment lighter */ + { + /* Measure time */ + clock_start(); + + lighter_segment_body(i); + + /* Measure time */ + clock_stop("Segment lighten"); + } + /* Segment interest zone */ + { + /* Measure time */ + clock_start(); + + lighter_crop_head(i); + lighter_segment_head(i); + + /* Measure time */ + clock_stop("Segment interest zone"); + } + } + + status = LIGHTER_OK; + result_lighter(status); + return status; +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_lighter (int status) +{ + /* Cleanup */ + + /* Write result into log */ + switch (status) { + case LIGHTER_OK: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: OK"); + break; + case LIGHTER_NOK_LIGHTER: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK_LIGHTER"); + break; + + case LIGHTER_NOK_SIZE: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK_SIZE"); + break; + default: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK"); + break; + } + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + +/* process -------------------------------------------------------------------*/ +static void lighters_bgr2gray (void) +{ + proc_load_mem(0); + + proc_cvt_color(cv::COLOR_BGR2GRAY); + proc_not(); + proc_border(100); + proc_save_mem(1); +} + +static void lighters_segment_full (void) +{ + proc_load_mem(1); + + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_erode_dilate(1); + proc_dilate_erode(1); + proc_save_mem(2); +} + +static int lighters_find (void) +{ + int status; + int i; + int tmp; + + proc_load_mem(2); + + proc_contours(&contours_all, &hierarchy); + lighters_n = contours_all.size(); + + /* If no contour is found, error: NOK_RESISTOR */ + if (!lighters_n) { + status = LIGHTER_NOK_LIGHTER; + return status; + } + + for (i = 0; (unsigned)i < lighters_n; i++) { + proc_min_area_rect(&(contours_all[i]), &rect_rot[i], true); + + /* If width > height, it is taking into acount the incorrect side */ + if (rect_rot[i].size.width > rect_rot[i].size.height) { + rect_rot[i].angle += 90.0; + tmp = rect_rot[i].size.width; + rect_rot[i].size.width = rect_rot[i].size.height; + rect_rot[i].size.height = tmp; + } + + lighter[i].pos.x = rect_rot[i].center.x; + lighter[i].pos.y = rect_rot[i].center.y; + lighter[i].angle = rect_rot[i].angle; + lighter[i].size.h = rect_rot[i].size.height; + lighter[i].size.w = rect_rot[i].size.width; + } + + status = LIGHTER_OK; + return status; +} + +static void lighter_segment_body (int i) +{ + int x; + int y; + int w; + int h; + + proc_load_mem(1); + + proc_rotate(lighter[i].pos.x, lighter[i].pos.y, lighter[i].angle); + w = lighter[i].size.w * 1.25; + h = lighter[i].size.h * 1.25; + x = lighter[i].pos.x - (w / 2.0); + y = lighter[i].pos.y - (h / 2.0); + proc_ROI(x, y, w, h); + proc_threshold(cv::THRESH_BINARY, 255 - 165); + + proc_erode_dilate(1); + proc_dilate_erode(1); + proc_erode_dilate(lighter[i].size.w * 0.43); + proc_save_mem(3); + + proc_contours(&contours_one, &hierarchy); + proc_bounding_rect(&(contours_one[0]), &rect, true); +} + +static void lighter_crop_head (int i) +{ + int x; + int y; + int w; + int h; + + proc_load_mem(3); + proc_not(); + proc_erode(1); + proc_save_ref(); + + proc_load_mem(1); + proc_rotate(lighter[i].pos.x, lighter[i].pos.y, lighter[i].angle); + w = lighter[i].size.w * 1.25; + h = lighter[i].size.h * 1.25; + x = lighter[i].pos.x - (w / 2.0); + y = lighter[i].pos.y - (h / 2.0); + proc_ROI(x, y, w, h); + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_and_2ref(); +// + w = rect.width * 1.15; + h = rect.width * 0.65; + x = rect.x - rect.width * 0.075; + y = rect.y - rect.width * 0.65; + proc_ROI(x, y, w, h); + rect.x = x; + rect.y = y; + rect.width = w; + rect.height = h; + proc_save_mem(8); + +proc_apply(); +proc_save_file(); +} + +static void lighter_segment_head (int i) +{ + proc_load_mem(8); +/* + proc_smooth(IMGI_SMOOTH_MEDIAN, 5); + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_dilate_erode(5); + proc_erode_dilate(rect[0].height * 0.25); + + proc_contours(&contours, &hierarchy); + proc_bounding_rect(&(contours[0]), &(rect[0]), true); +*/ + proc_save_mem(9); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ -- cgit v1.2.3 From 7ae244880dae331a45663791b85e7e3bf0799011 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Sat, 29 Dec 2018 14:13:36 +0100 Subject: Change name proc_lighter -> proc_lighters --- modules/proc/tmp/Makefile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/proc/tmp/Makefile b/modules/proc/tmp/Makefile index 120bf48..fcb9d8b 100644 --- a/modules/proc/tmp/Makefile +++ b/modules/proc/tmp/Makefile @@ -15,7 +15,7 @@ SRC_DIR = $(PROC_DIR)/src/ # dependencies -_ALL = proc_label.o proc_lighter.o proc_objects.o \ +_ALL = proc_label.o proc_lighters.o proc_objects.o \ proc_coins.o proc_resistor.o \ proc_common.o proc_iface.o ALL = $(_ALL) proc_mod.o @@ -34,8 +34,8 @@ PROC_LAB_INC_DIRS = -I $(INC_DIR) \ PROC_LGHT_INC_LIBALX = alx_math.hpp PROC_LGHT_INC_IMG = img_iface.hpp PROC_LGHT_INC_USR = user_iface.hpp -PROC_LGHT_INC = proc_lighter.hpp proc_common.hpp -PROC_LGHT_DEPS = $(SRC_DIR)/proc_lighter.cpp \ +PROC_LGHT_INC = proc_lighters.hpp proc_common.hpp +PROC_LGHT_DEPS = $(SRC_DIR)/proc_lighters.cpp \ $(patsubst %,$(INC_DIR)/%,$(PROC_LGHT_INC)) \ $(patsubst %,$(IMG_INC_DIR)/%,$(PROC_LGHT_INC_IMG)) \ $(patsubst %,$(USR_INC_DIR)/%,$(PROC_LGHT_INC_USR)) \ @@ -130,10 +130,10 @@ proc_label.o: proc_label.s $(PROC_LAB_DEPS) $(Q)$(AS) $< -o $@ @echo " AS $@" -proc_lighter.s: $(PROC_LGHT_DEPS) +proc_lighters.s: $(PROC_LGHT_DEPS) $(Q)$(CXX) $(CXXFLAGS) $(PROC_LGHT_INC_DIRS) -S $< -o $@ @echo " CXX $@" -proc_lighter.o: proc_lighter.s $(PROC_LGHT_DEPS) +proc_lighters.o: proc_lighters.s $(PROC_LGHT_DEPS) $(Q)$(AS) $< -o $@ @echo " AS $@" -- cgit v1.2.3 From af371eeec59c44daf6931f1641313581d443336f Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Sat, 29 Dec 2018 14:17:21 +0100 Subject: Don't calibrate proc_lighters --- modules/proc/inc/proc_iface.h | 3 +-- modules/proc/inc/proc_iface.hpp | 3 +-- modules/proc/src/proc_iface.c | 14 +++++--------- 3 files changed, 7 insertions(+), 13 deletions(-) diff --git a/modules/proc/inc/proc_iface.h b/modules/proc/inc/proc_iface.h index 44f8a1e..eefe9c7 100644 --- a/modules/proc/inc/proc_iface.h +++ b/modules/proc/inc/proc_iface.h @@ -35,8 +35,7 @@ PROC_MODE_COINS_CALIB, PROC_MODE_RESISTOR_SERIES, PROC_MODE_RESISTOR_CALIB, - PROC_MODE_LIGHTER_SERIES, - PROC_MODE_LIGHTER_CALIB + PROC_MODE_LIGHTER_SERIES }; enum Proc_DBG { diff --git a/modules/proc/inc/proc_iface.hpp b/modules/proc/inc/proc_iface.hpp index 0396615..cabf958 100644 --- a/modules/proc/inc/proc_iface.hpp +++ b/modules/proc/inc/proc_iface.hpp @@ -35,8 +35,7 @@ PROC_MODE_COINS_CALIB, PROC_MODE_RESISTOR_SERIES, PROC_MODE_RESISTOR_CALIB, - PROC_MODE_LIGHTER_SERIES, - PROC_MODE_LIGHTER_CALIB + PROC_MODE_LIGHTER_SERIES }; enum Proc_DBG { diff --git a/modules/proc/src/proc_iface.c b/modules/proc/src/proc_iface.c index 45ccb02..efb2e52 100644 --- a/modules/proc/src/proc_iface.c +++ b/modules/proc/src/proc_iface.c @@ -29,7 +29,7 @@ /* Module --------------------------------------------------------------------*/ #include "proc_label.h" - #include "proc_lighter.h" + #include "proc_lighters.h" #include "proc_objects.h" #include "proc_coins.h" #include "proc_resistor.h" @@ -85,9 +85,6 @@ int proc_iface_single (int action) case PROC_MODE_RESISTOR_SERIES: error = proc_resistor(); break; - case PROC_MODE_LIGHTER_CALIB: - error = proc_lighter_calibrate(); - break; case PROC_MODE_LIGHTER_SERIES: error = proc_lighter(); break; @@ -123,6 +120,7 @@ void proc_iface_series (void) bool wh; /* if i starts being 0, the camera needs calibration */ int i; + char txt_tmp [80]; switch (proc_mode) { case PROC_MODE_LABEL_SERIES: @@ -161,11 +159,10 @@ void proc_iface_series (void) case PROC_MODE_LIGHTER_SERIES: snprintf(proc_path, FILENAME_MAX, "%s", lighters_path); snprintf(proc_fail_path, FILENAME_MAX, "%s", lighters_fail_path); - snprintf(file_basename, FILENAME_MAX, "lighter"); + snprintf(file_basename, FILENAME_MAX, "lighters"); num_len = 4; - snprintf(file_ext, FILENAME_MAX, ".png"); - i = 0; - proc_mode++; + snprintf(file_ext, FILENAME_MAX, ".jpeg"); + i = 1; break; default: return; @@ -202,7 +199,6 @@ void proc_iface_series (void) } /* Show log */ - char txt_tmp [80]; snprintf(txt_tmp, FILENAME_MAX, "%04i", i); user_iface_show_log(txt_tmp, "Item"); -- cgit v1.2.3 From cc9b5031d2f1cc8528135afdaae002642213b16d Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Sat, 29 Dec 2018 14:18:10 +0100 Subject: Change name proc_lighter -> proc_lighters --- modules/menu/src/menu_tui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/menu/src/menu_tui.c b/modules/menu/src/menu_tui.c index 2ecd173..0d38918 100644 --- a/modules/menu/src/menu_tui.c +++ b/modules/menu/src/menu_tui.c @@ -231,7 +231,7 @@ static void menu_tui_series (void) {3, 4, "[2] Objects"}, {4, 4, "[3] Coins"}, {5, 4, "[4] Resistor"}, - {6, 4, "[5] Lighter"} + {6, 4, "[5] Lighters"} }; /* Menu loop */ -- cgit v1.2.3 From 9e0a652e97d53712480f3542da64ca751954a6ae Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Sat, 29 Dec 2018 14:19:12 +0100 Subject: Change name proc_lighter -> proc_lighters --- modules/proc/inc/proc_lighter.h | 48 --- modules/proc/inc/proc_lighter.hpp | 61 --- modules/proc/src/proc_lighter.cpp | 753 -------------------------------------- 3 files changed, 862 deletions(-) delete mode 100644 modules/proc/inc/proc_lighter.h delete mode 100644 modules/proc/inc/proc_lighter.hpp delete mode 100644 modules/proc/src/proc_lighter.cpp diff --git a/modules/proc/inc/proc_lighter.h b/modules/proc/inc/proc_lighter.h deleted file mode 100644 index 094e723..0000000 --- a/modules/proc/inc/proc_lighter.h +++ /dev/null @@ -1,48 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_LIGHTER_H - # define VA_PROC_LIGHTER_H - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Lighter { - LIGHTER_OK, - LIGHTER_NOK_LIGHTER, - LIGHTER_NOK_SIZE - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - int proc_lighter_calibrate (void); - int proc_lighter (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_lighter.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/inc/proc_lighter.hpp b/modules/proc/inc/proc_lighter.hpp deleted file mode 100644 index 9e5529a..0000000 --- a/modules/proc/inc/proc_lighter.hpp +++ /dev/null @@ -1,61 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_LIGHTER_H - # define VA_PROC_LIGHTER_H - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Lighter { - LIGHTER_OK, - LIGHTER_NOK_PATTERN, - LIGHTER_NOK_LIGHTER, - LIGHTER_NOK_SIZE - }; - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - int proc_lighter_calibrate (void); - int proc_lighter (void); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_lighter.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/src/proc_lighter.cpp b/modules/proc/src/proc_lighter.cpp deleted file mode 100644 index 9605342..0000000 --- a/modules/proc/src/proc_lighter.cpp +++ /dev/null @@ -1,753 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* snprintf() */ - #include - -/* Packages ------------------------------------------------------------------*/ - /* openCV */ - #include - -/* libalx ------------------------------------------------------------------*/ - /* alx_maximum_u8() */ - #include "alx_math.hpp" - -/* Project -------------------------------------------------------------------*/ - /* constants */ - #include "img_iface.hpp" - /* user_iface_log */ - #include "user_iface.hpp" - -/* Module --------------------------------------------------------------------*/ - #include "proc_common.hpp" - - #include "proc_lighter.hpp" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define PATTERN_SQUARE_LEN_MM (10.0) - - # define PATTERN_DILATE (2) - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ -struct Point { - uint16_t x_pix; - uint16_t y_pix; - - double x_mm; - double y_mm; -}; - -struct Pattern_Square { - struct Point pos; - - uint8_t len; -}; - -struct Pattern_Properties { - /* center */ - struct Point center; - struct Point origin; - - /* Angle */ - double angle; - - /* Size */ - uint16_t height; - uint16_t width; - - /* Squares (distance calibration) */ - struct Pattern_Square square [CONTOURS_MAX]; - int squares_n; -}; - -struct Lighter_Properties { - /* position */ - struct Point pos; - - /* Angle */ - double angle; - - /* Area */ - double area_pix2; - double area_mm2; - - /* Perimeter */ - double perimeter_pix; - double perimeter_mm; - - /* type */ - double ratio_p2_a; - double area_rect; - double ratio_a_arect; - double perimeter_rect; - double ratio_p_prect; -}; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ - -/* Static --------------------------------------------------------------------*/ -static std::vector >> contours; -static class cv::Mat hierarchy; -static class cv::RotatedRect rect_rot [1]; -static class cv::Rect_ rect [CONTOURS_MAX]; -static struct Pattern_Properties pattern; -static double ratio_mm_pix; -static struct Lighter_Properties lighter; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_lighter (int status); - -static void pattern_bgr2gray (void); -static int pattern_find (void); -static void pattern_rotation_get (void); -static void pattern_rotation_fix (void); -static void pattern_dimensions_get (void); -static void pattern_dimensions_fix (void); -static void pattern_squares_find (void); -static void pattern_squares_pos_get (void); -static void pattern_squares_len_get (void); -static void pattern_calib_mm_pix (void); - -static void lighter_bgr2gray (void); -static void lighter_rotation_fix (void); -static void lighter_dimensions_fix (void); -static void lighter_segment_full (void); -static int lighter_align (void); -static void lighter_segment_body (void); -static void lighter_crop_hood (void); -static void lighter_segment_hood (void); -static int lighter_contours (void); -static void lighter_position_pix (void); -static void lighter_size_pix (void); -static void lighter_shape (void); -static void lighter_position_mm (void); -static void lighter_size_mm (void); -static void lighter_log (void); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -int proc_lighter_calibrate (void) -{ - int status; - - proc_save_mem(0); - /* Calibrate angle with the whole pattern */ - { - /* Measure time */ - clock_start(); - - pattern_bgr2gray(); - status = pattern_find(); - if (status) { - result_lighter(status); - return status; - } - pattern_rotation_get(); - pattern_rotation_fix(); - - /* Measure time */ - clock_stop("Calibrate: rotation"); - } - /* Segmentate pattern squares */ - { - /* Measure time */ - clock_start(); - - pattern_dimensions_get(); - pattern_dimensions_fix(); - - /* Measure time */ - clock_stop("Calibrate: dimensions"); - } - /* Find squares */ - { - /* Measure time */ - clock_start(); - - pattern_squares_find(); - pattern_squares_pos_get(); - pattern_squares_len_get(); - pattern_calib_mm_pix(); - - /* Measure time */ - clock_stop("Calibrate (mm per pix)"); - } - - status = LIGHTER_OK; - result_lighter(status); - return status; -} - -int proc_lighter (void) -{ - int status; - - proc_save_mem(0); - /* Align image */ - { - /* Measure time */ - clock_start(); - - lighter_bgr2gray(); - lighter_rotation_fix(); - lighter_dimensions_fix(); - - /* Measure time */ - clock_stop("Align image to pattern"); - } - /* Segment lighter */ - { - /* Measure time */ - clock_start(); - - lighter_segment_full(); - lighter_align(); - lighter_segment_body(); - lighter_crop_hood(); - lighter_segment_hood(); -proc_apply(); -proc_save_file(); - - /* Measure time */ - clock_stop("Segment lighter"); - } -#if 0 /* Find lighters positions */ - { - /* Measure time */ - clock_start(); - - status = lighter_contours(); - if (status) { - result_lighter(status); - return status; - } - - /* Measure time */ - clock_stop("Find lighter"); - } - /* Get lighter properties in pixels */ - { - /* Measure time */ - clock_start(); - - lighter_position_pix(); - lighter_position_mm(); - - /* Measure time */ - clock_stop("Lighter position"); - } - /* Get lighter properties in mm */ - { - /* Measure time */ - clock_start(); - - lighter_size_pix(); - lighter_size_mm(); - - /* Measure time */ - clock_stop("Lighter size"); - } - /* Get lighter properties in mm */ - { - /* Measure time */ - clock_start(); - - lighter_shape(); - - /* Measure time */ - clock_stop("Lighter shape"); - } - /* Print properties of lighter into log */ - { - /* Measure time */ - clock_start(); - - lighter_log(); - - /* Measure time */ - clock_stop("Lighter properties (log)"); - } -#endif - status = LIGHTER_OK; - result_lighter(status); - return status; -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_lighter (int status) -{ - /* Cleanup */ - - /* Write result into log */ - switch (status) { - case LIGHTER_OK: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: OK"); - break; - case LIGHTER_NOK_LIGHTER: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK_LIGHTER"); - break; - - case LIGHTER_NOK_SIZE: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK_SIZE"); - break; - default: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK"); - break; - } - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - -/* calibration ---------------------------------------------------------------*/ -static void pattern_bgr2gray (void) -{ - proc_load_mem(0); - - proc_cvt_color(cv::COLOR_BGR2GRAY); - proc_save_mem(1); -} - -static int pattern_find (void) -{ - int status; - - proc_load_mem(1); - - proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU); - proc_erode_dilate(16); - proc_dilate(2); - proc_contours(&contours, &hierarchy); - - /* If no contour is found, error: NOK_PATTERN */ - if (contours.size() != 1) { - status = LIGHTER_NOK_PATTERN; - return status; - } - - status = LIGHTER_OK; - return status; -} - -static void pattern_rotation_get (void) -{ - proc_min_area_rect(&(contours[0]), &(rect_rot[0]), true); - - /* If angle is < -45º, it is taking into account the incorrect side */ - if (rect_rot[0].angle < -45.0) { - rect_rot[0].angle += 90.0; - } - pattern.angle = rect_rot[0].angle; - pattern.center.x_pix = rect_rot[0].center.x; - pattern.center.y_pix = rect_rot[0].center.y; - - /* Write pattern properties into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "pattern angle = %lf DEG", - -pattern.angle); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "pattern center (x) = %i pix", - pattern.center.x_pix); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "pattern center (y) = %i pix", - pattern.center.y_pix); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - -static void pattern_rotation_fix (void) -{ - proc_load_mem(1); - - /* invert image before rotation to avoid black bands */ - proc_not(); - proc_rotate(pattern.center.x_pix, pattern.center.y_pix, pattern.angle); - proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); - proc_save_mem(2); -} - -static void pattern_dimensions_get (void) -{ - proc_load_mem(2); - - proc_erode_dilate(16); - proc_dilate(PATTERN_DILATE); - proc_contours(&contours, &hierarchy); - proc_bounding_rect(&(contours[0]), &(rect[0]), true); -} - -static void pattern_dimensions_fix (void) -{ - /* Need to correct also pattern dilatation (pattern_dimensions_get()) */ - pattern.origin.x_pix = rect[0].x; - pattern.origin.y_pix = rect[0].y; - pattern.width = rect[0].width; - pattern.height = rect[0].height; - - proc_load_mem(2); - - proc_ROI(pattern.origin.x_pix, pattern.origin.y_pix, - pattern.width, pattern.height); - proc_save_mem(3); -} - -static void pattern_squares_find (void) -{ - proc_load_mem(3); - - proc_distance_transform(); - proc_local_max(); - proc_dilate(6); - proc_save_mem(4); - - proc_contours(&contours, &hierarchy); - pattern.squares_n = contours.size(); -} - -static void pattern_squares_pos_get (void) -{ - int i; - - /* Get position of each contour */ - for (i = 0; i < pattern.squares_n; i++) { - proc_bounding_rect(&(contours[i]), &(rect[i]), true); - - pattern.square[i].pos.x_pix = rect[i].x + rect[i].width/2.0; - pattern.square[i].pos.y_pix = rect[i].y + rect[i].height/2.0; - } -} - -static void pattern_squares_len_get (void) -{ - int i; - - proc_load_mem(4); - - /* Get pattern square side lenght in pixels */ - for (i = 0; i < pattern.squares_n; i++) { - proc_pixel_value(pattern.square[i].pos.x_pix, - pattern.square[i].pos.y_pix, - &(pattern.square[i].len)); - pattern.square[i].len *= 2; - } -} - -static void pattern_calib_mm_pix (void) -{ - int i; - uint8_t pattern_len [CONTOURS_MAX]; - uint8_t median_size; - - for (i = 0; i < pattern.squares_n; i++) { - pattern_len[i] = pattern.square[i].len; - } - - median_size = alx_median_u8(pattern.squares_n, pattern_len); - ratio_mm_pix = PATTERN_SQUARE_LEN_MM / median_size; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "mm/pix = %lf", - ratio_mm_pix); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - -/* process -------------------------------------------------------------------*/ -static void lighter_bgr2gray (void) -{ - proc_load_mem(0); - - proc_cvt_color(cv::COLOR_BGR2GRAY); - proc_save_mem(1); -} - -static void lighter_rotation_fix (void) -{ - proc_load_mem(1); - - /* invert image before rotation to avoid black bands */ - proc_not(); - proc_rotate(pattern.center.x_pix, pattern.center.y_pix, pattern.angle); - proc_save_mem(2); -} - -static void lighter_dimensions_fix (void) -{ - /* Need to correct also pattern dilatation (pattern_dimensions_get()) */ - proc_load_mem(2); - - proc_ROI(pattern.origin.x_pix+200, pattern.origin.y_pix+200, - pattern.width-400, pattern.height-200); - proc_save_mem(3); -} - -static void lighter_segment_full (void) -{ - proc_load_mem(3); - - proc_smooth(IMGI_SMOOTH_MEDIAN, 5); - proc_threshold(cv::THRESH_BINARY, 80); - proc_save_mem(4); -} - -static int lighter_align (void) -{ - int status; - - proc_load_mem(4); - - proc_dilate_erode(2 / ratio_mm_pix); - proc_erode_dilate(4.5 / ratio_mm_pix); - proc_contours(&contours, &hierarchy); - - /* If no contour is found, error: NOK_RESISTOR */ - if (contours.size() != 1) { - status = LIGHTER_NOK_LIGHTER; - return status; - } - - proc_min_area_rect(&(contours[0]), &rect_rot[0], true); - - /* If width > height, it is taking into acount the incorrect side */ - if (rect_rot[0].size.width > rect_rot[0].size.height) { - int tmp; - rect_rot[0].angle += 90.0; - tmp = rect_rot[0].size.width; - rect_rot[0].size.width = rect_rot[0].size.height; - rect_rot[0].size.height = tmp; - } - - proc_rotate(rect_rot[0].center.x, rect_rot[0].center.y, rect_rot[0].angle); - - proc_save_mem(5); - - status = LIGHTER_OK; - return status; -} - -static void lighter_segment_body (void) -{ - proc_load_mem(3); - - proc_rotate(rect_rot[0].center.x, rect_rot[0].center.y, rect_rot[0].angle); - proc_smooth(IMGI_SMOOTH_MEDIAN, 5); - proc_threshold(cv::THRESH_BINARY, 65); - proc_erode_dilate(rect_rot[0].size.width * 0.43); -// proc_dilate_erode(rect_rot[0].size.width * 0.2); - proc_save_mem(6); - - proc_contours(&contours, &hierarchy); - proc_bounding_rect(&(contours[0]), &(rect[0]), true); - - proc_save_mem(7); -} - -static void lighter_crop_hood (void) -{ - int x; - int y; - int w; - int h; - - proc_load_mem(6); - proc_not(); - proc_save_ref(); - - proc_load_mem(3); - proc_rotate(rect_rot[0].center.x, rect_rot[0].center.y, rect_rot[0].angle); - proc_and_2ref(); - w = rect[0].width * 1.2; - h = rect[0].width * 0.75; - x = rect[0].x - rect[0].width * 0.1; - y = rect[0].y - rect[0].width * 0.7; - proc_ROI(x, y, w, h); - rect[0].x = x; - rect[0].y = y; - rect[0].width = w; - rect[0].height = h; - proc_save_mem(8); -} - -static void lighter_segment_hood (void) -{ - proc_load_mem(8); -/* - proc_smooth(IMGI_SMOOTH_MEDIAN, 5); - proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); - proc_dilate_erode(5); - proc_erode_dilate(rect[0].height * 0.25); - - proc_contours(&contours, &hierarchy); - proc_bounding_rect(&(contours[0]), &(rect[0]), true); -*/ - proc_save_mem(9); -} - -static int lighter_contours (void) -{ - int status; - - proc_load_mem(6); - - proc_contours(&contours, &hierarchy); - - /* If no contour is found, error: NOK_LIGHTER */ - if (!contours.size()) { - status = LIGHTER_NOK_LIGHTER; - return status; - } - - status = LIGHTER_OK; - return status; -} - -static void lighter_position_pix (void) -{ - proc_fit_ellipse(&(contours[0]), &(rect_rot[0]), true); - - lighter.pos.x_pix = rect_rot[0].center.x; - lighter.pos.y_pix = rect_rot[0].center.y; - - lighter.angle = -rect_rot[0].angle + 90.0; - if (lighter.angle < 0) { - lighter.angle += 180.0; - } -} - -static void lighter_position_mm (void) -{ - lighter.pos.x_mm = ratio_mm_pix * lighter.pos.x_pix; - lighter.pos.y_mm = ratio_mm_pix * lighter.pos.y_pix; -} - -static void lighter_size_pix (void) -{ - double area; - double perimeter; - - /* Get size */ - proc_contours_size(&contours, &area, &perimeter); - lighter.area_pix2 = area; - lighter.perimeter_pix = perimeter; -} - -static void lighter_size_mm (void) -{ - /* Get size */ - lighter.area_mm2 = pow(ratio_mm_pix, 2) * lighter.area_pix2; - lighter.perimeter_mm = ratio_mm_pix * lighter.perimeter_pix; -} - -static void lighter_shape (void) -{ - /* Get shape */ - proc_min_area_rect(&(contours[0]), &(rect_rot[0]), true); - - lighter.ratio_p2_a = pow(lighter.perimeter_pix, 2) / - lighter.area_pix2; - - lighter.area_rect = rect_rot[0].size.width * - rect_rot[0].size.height; - lighter.perimeter_rect = 2.0 * (rect_rot[0].size.width + - rect_rot[0].size.height); - - lighter.ratio_p_prect = lighter.perimeter_pix / - lighter.perimeter_rect; - lighter.ratio_a_arect = lighter.area_pix2 / lighter.area_rect; -} - -static void lighter_log (void) -{ - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Lighter:"); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " pos: (%.1lf, %.1lf) mm", - lighter.pos.x_mm, - lighter.pos.y_mm); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " ang = %.1lf DEG", - lighter.angle); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " A = %.1lf mm2", - lighter.area_mm2); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " P = %.1lf mm", - lighter.perimeter_mm); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " p2/A = %.2lf", - lighter.ratio_p2_a); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " p/p_r = %.2lf", - lighter.ratio_p_prect); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " A/A_r = %.2lf", - lighter.ratio_a_arect); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ -- cgit v1.2.3 From 6492739fdc5c030434b6a1e10be416e06fe0792a Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Sat, 29 Dec 2018 14:21:05 +0100 Subject: Update libalx --- libalx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libalx b/libalx index 99b8f33..110d0dc 160000 --- a/libalx +++ b/libalx @@ -1 +1 @@ -Subproject commit 99b8f338b7dac5db72adb6c042d5e54172ea8c05 +Subproject commit 110d0dc28f2ecdf6d371412d41e5c39de2828155 -- cgit v1.2.3 From 44b013b74aaf7774e3ece7faa6cb9841bece68e1 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Sat, 29 Dec 2018 14:25:10 +0100 Subject: Add function to expand border --- modules/image/inc/img_cv.hpp | 1 + modules/image/inc/img_iface.h | 1 + modules/image/inc/img_iface.hpp | 5 +++ modules/image/src/img_cv.cpp | 80 ++++++++++++++++++++++++++++++++--------- modules/image/src/img_iface.cpp | 41 +++++++++++++++++++++ 5 files changed, 111 insertions(+), 17 deletions(-) diff --git a/modules/image/inc/img_cv.hpp b/modules/image/inc/img_cv.hpp index 86ba2a6..a14371f 100644 --- a/modules/image/inc/img_cv.hpp +++ b/modules/image/inc/img_cv.hpp @@ -34,6 +34,7 @@ IMG_CV_ACT_ERODE, IMG_CV_ACT_SMOOTH, IMG_CV_ACT_SOBEL, + IMG_CV_ACT_BORDER, IMG_CV_ACT_MIRROR, IMG_CV_ACT_ROTATE_ORTO, IMG_CV_ACT_ROTATE, diff --git a/modules/image/inc/img_iface.h b/modules/image/inc/img_iface.h index 39a1fcc..00bf4d6 100644 --- a/modules/image/inc/img_iface.h +++ b/modules/image/inc/img_iface.h @@ -65,6 +65,7 @@ IMG_IFACE_ACT_ERODE_DILATE, IMG_IFACE_ACT_SMOOTH, IMG_IFACE_ACT_SOBEL, + IMG_IFACE_ACT_BORDER, IMG_IFACE_ACT_MIRROR, IMG_IFACE_ACT_ROTATE_ORTO, IMG_IFACE_ACT_ROTATE, diff --git a/modules/image/inc/img_iface.hpp b/modules/image/inc/img_iface.hpp index 5f2109e..a8b3a1f 100644 --- a/modules/image/inc/img_iface.hpp +++ b/modules/image/inc/img_iface.hpp @@ -74,6 +74,7 @@ IMG_IFACE_ACT_ERODE_DILATE, IMG_IFACE_ACT_SMOOTH, IMG_IFACE_ACT_SOBEL, + IMG_IFACE_ACT_BORDER, IMG_IFACE_ACT_MIRROR, IMG_IFACE_ACT_ROTATE_ORTO, IMG_IFACE_ACT_ROTATE, @@ -181,6 +182,10 @@ int ksize; }; + struct Img_Iface_Data_Border { + int size; + }; + struct Img_Iface_Data_Mirror { int axis; }; diff --git a/modules/image/src/img_cv.cpp b/modules/image/src/img_cv.cpp index 1cd11a4..ce3e647 100644 --- a/modules/image/src/img_cv.cpp +++ b/modules/image/src/img_cv.cpp @@ -48,6 +48,7 @@ static void img_cv_dilate (class cv::Mat *imgptr, void *data); static void img_cv_erode (class cv::Mat *imgptr, void *data); static void img_cv_smooth (class cv::Mat *imgptr, void *data); static void img_cv_sobel (class cv::Mat *imgptr, void *data); +static void img_cv_border (class cv::Mat *imgptr, void *data); /* Geometric image transformations */ static void img_cv_mirror (class cv::Mat *imgptr, void *data); static void img_cv_rotate_orto (class cv::Mat *imgptr, void *data); @@ -109,6 +110,9 @@ void img_cv_act (class cv::Mat *imgptr, int action, void *data) case IMG_CV_ACT_SOBEL: img_cv_sobel(imgptr, data); break; + case IMG_CV_ACT_BORDER: + img_cv_border(imgptr, data); + break; case IMG_CV_ACT_MIRROR: img_cv_mirror(imgptr, data); @@ -190,16 +194,26 @@ static void img_cv_pixel_value (class cv::Mat *imgptr, void *data) /* ----- ROI */ static void img_cv_set_ROI (class cv::Mat *imgptr, void *data) { - /* Data */ + class cv::Mat imgtmp; struct Img_Iface_Data_SetROI *data_cast; + class cv::Rect_ *rect; + + /* Data */ data_cast = (struct Img_Iface_Data_SetROI *)data; /* Rectangle */ - class cv::Rect_ *rect; rect = &(data_cast->rect); /* Set ROI */ - *imgptr = (*imgptr)(*rect); + (*imgptr)(*rect).copyTo(imgtmp); + imgtmp.copyTo(*imgptr); + + /* Write tmp into imgptr */ + imgptr->release(); + imgtmp.copyTo(*imgptr); + + /* clean up */ + imgtmp.release(); } /* ----- Operations on arrays */ @@ -226,14 +240,14 @@ static void img_cv_or_2ref (class cv::Mat *imgptr, void *data) static void img_cv_component (class cv::Mat *imgptr, void *data) { - class cv::Mat cmp_img[3]; + class cv::Mat cmp_img[3]; + struct Img_Iface_Data_Component *data_cast; + int cmp; /* Data */ - struct Img_Iface_Data_Component *data_cast; data_cast = (struct Img_Iface_Data_Component *)data; /* Color component */ - int cmp; cmp = data_cast->cmp; /* Write components into cmp_img[] */ @@ -263,7 +277,7 @@ static void img_cv_dilate (class cv::Mat *imgptr, void *data) /* Dilate */ cv::dilate(*imgptr, *imgptr, cv::Mat(), cv::Point(-1,-1), i, - cv::BORDER_REPLICATE); + cv::BORDER_CONSTANT, cv::Scalar(0)); } static void img_cv_erode (class cv::Mat *imgptr, void *data) @@ -278,7 +292,7 @@ static void img_cv_erode (class cv::Mat *imgptr, void *data) /* Erode */ cv::erode(*imgptr, *imgptr, cv::Mat(), cv::Point(-1,-1), i, - cv::BORDER_REPLICATE); + cv::BORDER_CONSTANT, cv::Scalar(0)); } static void img_cv_smooth (class cv::Mat *imgptr, void *data) @@ -335,6 +349,29 @@ static void img_cv_sobel (class cv::Mat *imgptr, void *data) cv::BORDER_DEFAULT); } +static void img_cv_border (class cv::Mat *imgptr, void *data) +{ + class cv::Mat imgtmp; + struct Img_Iface_Data_Border *data_cast; + int size; + + /* Data */ + data_cast = (struct Img_Iface_Data_Border *)data; + + size = data_cast->size; + + imgtmp = cv::Mat(cv::Size(imgptr->cols + size, imgptr->rows + size), + CV_8U); + /* Get transform */ + cv::copyMakeBorder(*imgptr, imgtmp, size, size, size, size, + cv::BORDER_CONSTANT, cv::Scalar(0)); + + imgtmp.copyTo(*imgptr); + + /* Cleanup */ + imgtmp.release(); +} + /* ----- Geometric image transformations */ static void img_cv_mirror (class cv::Mat *imgptr, void *data) { @@ -594,17 +631,19 @@ static void img_cv_histogram_c3 (class cv::Mat *imgptr, void *data) /* ----- Structural analysis and shape descriptors */ static void img_cv_contours (class cv::Mat *imgptr, void *data) { - /* Data */ struct Img_Iface_Data_Contours *data_cast; + class std::vector >> *contours; + class cv::Mat *hierarchy; + + /* Data */ data_cast = (struct Img_Iface_Data_Contours *)data; /* Contours */ - class std::vector >> *contours; contours = data_cast->contours; - class cv::Mat *hierarchy; hierarchy = data_cast->hierarchy; /* Get contours */ + cv::findContours(*imgptr, *contours, *hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE); @@ -618,21 +657,28 @@ static void img_cv_contours (class cv::Mat *imgptr, void *data) static void img_cv_contours_size (void *data) { - /* Data */ struct Img_Iface_Data_Contours_Size *data_cast; + class std::vector >> *contours; + int i; + + /* Data */ data_cast = (struct Img_Iface_Data_Contours_Size *)data; /* Contours */ - class std::vector >> *contours; contours = data_cast->contours; /* Get area and perimeter */ - int i; - for (i = 0; i < (int)contours->size(); i++) { - data_cast->area[i] = cv::contourArea( + if (data_cast->area) { + for (i = 0; i < (int)contours->size(); i++) { + data_cast->area[i] = cv::contourArea( (*contours)[i], false); - data_cast->perimeter[i] = cv::arcLength( + } + } + if (data_cast->perimeter) { + for (i = 0; i < (int)contours->size(); i++) { + data_cast->perimeter[i] = cv::arcLength( (*contours)[i], true); + } } } diff --git a/modules/image/src/img_iface.cpp b/modules/image/src/img_iface.cpp index 51723f3..ce87044 100644 --- a/modules/image/src/img_iface.cpp +++ b/modules/image/src/img_iface.cpp @@ -119,6 +119,7 @@ static void img_iface_dilate_erode (void *data); static void img_iface_erode_dilate (void *data); static void img_iface_smooth (void *data); static void img_iface_sobel (void *data); +static void img_iface_border (void *data); /* Geometric image transformations */ static void img_iface_mirror (void *data); static void img_iface_rotate_orto (void *data); @@ -308,6 +309,9 @@ void img_iface_act (int action, void *data) break; case IMG_IFACE_ACT_SOBEL: img_iface_sobel(data); + break; + case IMG_IFACE_ACT_BORDER: + img_iface_border(data); break; /* Geometric image transformations */ case IMG_IFACE_ACT_MIRROR: @@ -1036,6 +1040,43 @@ static void img_iface_sobel (void *data) img_cv_act(&image_copy_tmp, IMG_CV_ACT_SOBEL, data); } +static void img_iface_border (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Data */ + struct Img_Iface_Data_Border data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Size"); + data_tmp.size = user_iface_getint(1, 1, 0xF000, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Border *data_cast; + data_cast = (struct Img_Iface_Data_Border *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Border size=%i", + data_cast->size); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Add border */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_BORDER, data); +} + /* ----- ------- Geometric image transformations */ static void img_iface_mirror (void *data) { -- cgit v1.2.3 From b5a23b726d7d8cba2b83306dbec9563d11e8e48a Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Sat, 29 Dec 2018 14:26:01 +0100 Subject: Add function to expand border --- modules/user/inc/user_iface.h | 1 + modules/user/inc/user_iface.hpp | 1 + modules/user/src/user_clui.c | 4 ++++ modules/user/src/user_tui.c | 4 ++++ 4 files changed, 10 insertions(+) diff --git a/modules/user/inc/user_iface.h b/modules/user/inc/user_iface.h index 284f4d9..d69978e 100644 --- a/modules/user/inc/user_iface.h +++ b/modules/user/inc/user_iface.h @@ -61,6 +61,7 @@ USER_IFACE_ACT_ERODE_DILATE, USER_IFACE_ACT_SMOOTH, USER_IFACE_ACT_SOBEL, + USER_IFACE_ACT_BORDER, USER_IFACE_ACT_MIRROR, USER_IFACE_ACT_ROTATE_ORTO, USER_IFACE_ACT_ROTATE, diff --git a/modules/user/inc/user_iface.hpp b/modules/user/inc/user_iface.hpp index c291567..bb805f7 100644 --- a/modules/user/inc/user_iface.hpp +++ b/modules/user/inc/user_iface.hpp @@ -61,6 +61,7 @@ USER_IFACE_ACT_ERODE_DILATE, USER_IFACE_ACT_SMOOTH, USER_IFACE_ACT_SOBEL, + USER_IFACE_ACT_BORDER, USER_IFACE_ACT_MIRROR, USER_IFACE_ACT_ROTATE_ORTO, USER_IFACE_ACT_ROTATE, diff --git a/modules/user/src/user_clui.c b/modules/user/src/user_clui.c index 070bf24..ff49e56 100644 --- a/modules/user/src/user_clui.c +++ b/modules/user/src/user_clui.c @@ -333,6 +333,9 @@ static int usr_input (void) case '5': action = USER_IFACE_ACT_SOBEL; break; + case '6': + action = USER_IFACE_ACT_BORDER; + break; default: action = USER_IFACE_ACT_FOO; break; @@ -576,6 +579,7 @@ static void show_help (void) printf(" - E-D: %s\n", "f1103"); printf(" - Smooth: %s\n", "f1104"); printf(" - Sobel: %s\n", "f1105"); + printf(" - Border: %s\n", "f1106"); printf(" - Mirror: %s\n", "f1110"); printf(" - Rotate ortogonally: %s\n", "f1111"); printf(" - Rotate: %s\n", "f1112"); diff --git a/modules/user/src/user_tui.c b/modules/user/src/user_tui.c index eb93ba5..7049255 100644 --- a/modules/user/src/user_tui.c +++ b/modules/user/src/user_tui.c @@ -444,6 +444,9 @@ static int usr_input (void) case '5': action = USER_IFACE_ACT_SOBEL; break; + case '6': + action = USER_IFACE_ACT_BORDER; + break; default: action = USER_IFACE_ACT_FOO; break; @@ -722,6 +725,7 @@ static void show_help (void) mvwprintw(win_help, r++, c, " - E-D: %s", "f1103"); mvwprintw(win_help, r++, c, " - Smooth: %s", "f1104"); mvwprintw(win_help, r++, c, " - Sobel: %s", "f1105"); + mvwprintw(win_help, r++, c, " - Border: %s", "f1106"); mvwprintw(win_help, r++, c, " - Mirror: %s", "f1110"); mvwprintw(win_help, r++, c, " - Rotate ortogonally: %s", "f1111"); mvwprintw(win_help, r++, c, " - Rotate: %s", "f1112"); -- cgit v1.2.3 From a6f3202814a1323c085a0ce65d98f82cc9ae77f8 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Sat, 29 Dec 2018 14:28:48 +0100 Subject: Add function to expand border --- modules/proc/inc/proc_common.hpp | 1 + modules/proc/src/proc_common.cpp | 64 ++++++++++++++++++++++++++++++---------- 2 files changed, 50 insertions(+), 15 deletions(-) diff --git a/modules/proc/inc/proc_common.hpp b/modules/proc/inc/proc_common.hpp index dbc4d95..f31acde 100644 --- a/modules/proc/inc/proc_common.hpp +++ b/modules/proc/inc/proc_common.hpp @@ -58,6 +58,7 @@ extern "C" { void proc_dilate_erode (int size); void proc_erode_dilate (int size); void proc_smooth (int method, int ksize); + void proc_border (int size); void proc_rotate ( double center_x, double center_y, diff --git a/modules/proc/src/proc_common.cpp b/modules/proc/src/proc_common.cpp index 692cbe7..2fc2c35 100644 --- a/modules/proc/src/proc_common.cpp +++ b/modules/proc/src/proc_common.cpp @@ -129,6 +129,7 @@ void proc_pixel_value (int x, int y, unsigned char *val) 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; @@ -162,6 +163,7 @@ void proc_or_2ref (void) void proc_cmp (int cmp) { struct Img_Iface_Data_Component data; + data.cmp = cmp; img_iface_act(IMG_IFACE_ACT_COMPONENT, (void *)&data); @@ -171,6 +173,7 @@ void proc_cmp (int cmp) void proc_dilate (int size) { struct Img_Iface_Data_Dilate_Erode data; + data.i = size; img_iface_act(IMG_IFACE_ACT_DILATE, (void *)&data); @@ -180,6 +183,7 @@ void proc_dilate (int size) void proc_erode (int size) { struct Img_Iface_Data_Dilate_Erode data; + data.i = size; img_iface_act(IMG_IFACE_ACT_ERODE, (void *)&data); @@ -189,6 +193,7 @@ void proc_erode (int size) 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); @@ -198,6 +203,7 @@ void proc_dilate_erode (int size) 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); @@ -207,6 +213,7 @@ void proc_erode_dilate (int size) 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); @@ -214,9 +221,20 @@ void proc_smooth (int method, int ksize) proc_show_img(); } +void proc_border (int size) +{ + struct Img_Iface_Data_Border data; + + data.size = size; + img_iface_act(IMG_IFACE_ACT_BORDER, (void *)&data); + + proc_show_img(); +} + void proc_rotate (double center_x, double center_y, double angle) { struct Img_Iface_Data_Rotate data; + data.center.x = center_x; data.center.y = center_y; data.angle = angle; @@ -228,6 +246,7 @@ void proc_rotate (double center_x, double center_y, double angle) 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; @@ -239,6 +258,7 @@ void proc_adaptive_threshold (int method, int type, int ksize) 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); @@ -248,6 +268,7 @@ void proc_cvt_color (int method) 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); @@ -263,23 +284,28 @@ void proc_distance_transform (void) } void proc_contours ( - std::vector >> *contours, - class cv::Mat *hierarchy) + class std::vector >> *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 >> *contours, - double *area, - double *perimeter) +void proc_contours_size ( + class std::vector >> *contours, + double *area, + double *perimeter +) { struct Img_Iface_Data_Contours_Size data; + data.contours = contours; data.area = area; data.perimeter = perimeter; @@ -287,11 +313,13 @@ void proc_contours_size ( } void proc_bounding_rect ( - std::vector > *contour, - class cv::Rect_ *rect, - bool show) + class std::vector > *contour, + class cv::Rect_ *rect, + bool show +) { struct Img_Iface_Data_Bounding_Rect data; + data.contour = contour; data.rect = rect; data.show = show; @@ -303,11 +331,13 @@ void proc_bounding_rect ( } void proc_fit_ellipse ( - std::vector > *contour, - class cv::RotatedRect *rect, - bool show) + class std::vector > *contour, + class cv::RotatedRect *rect, + bool show +) { struct Img_Iface_Data_MinARect data; + data.contour = contour; data.rect = rect; data.show = show; @@ -320,11 +350,13 @@ void proc_fit_ellipse ( } void proc_min_area_rect ( - std::vector > *contour, - class cv::RotatedRect *rect, - bool show) + class std::vector > *contour, + class cv::RotatedRect *rect, + bool show +) { struct Img_Iface_Data_MinARect data; + data.contour = contour; data.rect = rect; data.show = show; @@ -338,6 +370,7 @@ void proc_min_area_rect ( 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); @@ -346,6 +379,7 @@ void proc_OCR (int lang, int conf) 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); } -- cgit v1.2.3 From 75b459305a60dbbdf82607f8ca837d774b08239a Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Sat, 29 Dec 2018 14:29:11 +0100 Subject: Fix style --- modules/proc/src/proc_coins.cpp | 22 +++++++++++----------- modules/proc/src/proc_label.cpp | 22 +++++++++++----------- modules/proc/src/proc_objects.cpp | 4 +--- modules/proc/src/proc_resistor.cpp | 36 ++++++++++++++++++------------------ 4 files changed, 41 insertions(+), 43 deletions(-) diff --git a/modules/proc/src/proc_coins.cpp b/modules/proc/src/proc_coins.cpp index 35922e3..1b9316e 100644 --- a/modules/proc/src/proc_coins.cpp +++ b/modules/proc/src/proc_coins.cpp @@ -57,7 +57,7 @@ struct Coins_Properties { /* Global --------------------------------------------------------------------*/ /* Static --------------------------------------------------------------------*/ -static std::vector >> contours; +static class std::vector >> contours; static class cv::Mat hierarchy; static class cv::Rect_ rectangle [COINS_MAX]; static int coins_n; @@ -225,6 +225,7 @@ static void coins_segmentate (void) static int coins_positions (void) { int status; + int i; proc_load_mem(1); @@ -238,7 +239,6 @@ static int coins_positions (void) } /* Get position of each contour */ - int i; for (i = 0; i < coins_n; i++) { proc_bounding_rect(&(contours[i]), &(rectangle[i]), true); coins[i].x = rectangle[i].x + rectangle[i].width / 2.0; @@ -251,10 +251,11 @@ static int coins_positions (void) static void coins_diameters_pix (void) { + int i; + proc_load_mem(1); /* Get coins diameters in pixels */ - int i; for (i = 0; i < coins_n; i++) { proc_pixel_value(coins[i].x, coins[i].y, &(coins[i].diameter_pix)); @@ -265,14 +266,14 @@ static void coins_diameters_pix (void) static void calibrate_mm_per_pix (void) { uint8_t coins_size_pix [coins_n]; - int i; + int max_pos; + int max_size; + for (i = 0; i < coins_n; i++) { coins_size_pix[i] = coins[i].diameter_pix; } - int max_pos; - int max_size; max_pos = alx_maximum_u8(coins_n, coins_size_pix); max_size = coins_size_pix[max_pos]; ratio_mm_per_pix = 25.75 / max_size; @@ -280,8 +281,8 @@ static void calibrate_mm_per_pix (void) static void coins_diameters_mm (void) { - /* Get coins diameters in mm */ int i; + for (i = 0; i < coins_n; i++) { coins[i].diameter_mm = ratio_mm_per_pix * coins[i].diameter_pix; @@ -299,9 +300,8 @@ static void coins_diameters_mm (void) static int coins_values (void) { int status; - - /* Get coins values in € (EUR) */ int i; + for (i = 0; i < coins_n; i++) { coins[i].value = coin_value(coins[i].diameter_mm); @@ -356,10 +356,10 @@ static double coin_value (double diameter_mm) static void coins_total_value (void) { + int i; + value_total = 0.00; - /* Get total value in € (EUR) */ - int i; for (i = 0; i < coins_n; i++) { value_total += coins[i].value; } diff --git a/modules/proc/src/proc_label.cpp b/modules/proc/src/proc_label.cpp index 9d4caf6..8615d98 100644 --- a/modules/proc/src/proc_label.cpp +++ b/modules/proc/src/proc_label.cpp @@ -36,7 +36,7 @@ /* Global --------------------------------------------------------------------*/ /* Static --------------------------------------------------------------------*/ -static std::vector >> contours; +static class std::vector >> contours; static class cv::Mat hierarchy; static class cv::RotatedRect rect; @@ -205,6 +205,7 @@ static void result_label (int status) static int label_find (void) { int status; + int tmp; proc_load_mem(0); @@ -231,7 +232,6 @@ static int label_find (void) /* If angle is < -45º, it is taking into acount the incorrect side */ if (rect.angle < -45.0) { - int tmp; rect.angle += 90.0; tmp = rect.size.width; rect.size.width = rect.size.height; @@ -254,13 +254,14 @@ static void label_align (void) static int find_cerdo (void) { int status; - - proc_load_mem(1); - int x; int y; int w; int h; + bool cerdo_nok; + + proc_load_mem(1); + x = rect.center.x - (1.05 * rect.size.width / 2); if (x < 0) { x = 0; @@ -277,7 +278,6 @@ static int find_cerdo (void) proc_OCR(IMG_IFACE_OCR_LANG_ENG, IMG_IFACE_OCR_CONF_NONE); /* Compare Label text to "Cerdo". */ - bool cerdo_nok; cerdo_nok = strncmp(img_ocr_text, "Cerdo", strlen("Cerdo")); @@ -313,8 +313,8 @@ static int barcode_read (void) static int barcode_chk_prod (void) { int status; - bool prod_nok; + prod_nok = strncmp(zb_codes.arr[0].data, "2301703", strlen("2301703")); if (prod_nok) { @@ -328,12 +328,13 @@ static int barcode_chk_prod (void) static void price_read (void) { - proc_load_mem(1); - int x; int y; int w; int h; + + proc_load_mem(1); + x = rect.center.x + (0.33 * rect.size.width / 2); y = rect.center.y + (0.64 * rect.size.height / 2); w = rect.size.width * 0.225; @@ -349,8 +350,8 @@ static void price_read (void) static int price_chk (void) { int status; - char price [80]; + bool price_nok; /* Extract price from barcode */ if (zb_codes.arr[0].data[8] != '0') { @@ -367,7 +368,6 @@ static int price_chk (void) } /* Compare price from barcode and from text */ - bool price_nok; price_nok = strncmp(img_ocr_text, price, strlen(price)); if (price_nok) { diff --git a/modules/proc/src/proc_objects.cpp b/modules/proc/src/proc_objects.cpp index 06d92e9..9b39ce5 100644 --- a/modules/proc/src/proc_objects.cpp +++ b/modules/proc/src/proc_objects.cpp @@ -102,7 +102,7 @@ struct Objects_Properties { /* Global --------------------------------------------------------------------*/ /* Static --------------------------------------------------------------------*/ -static std::vector >> contours; +static class std::vector >> contours; static class cv::Mat hierarchy; static class cv::RotatedRect rect_rot [OBJECTS_MAX]; static class cv::Rect_ rect [OBJECTS_MAX]; @@ -292,8 +292,6 @@ int proc_objects (void) ******************************************************************************/ static void result_objects (int status) { - /* Cleanup */ - /* Write result into log */ switch (status) { case OBJECTS_OK: diff --git a/modules/proc/src/proc_resistor.cpp b/modules/proc/src/proc_resistor.cpp index a3bf80d..18d922c 100644 --- a/modules/proc/src/proc_resistor.cpp +++ b/modules/proc/src/proc_resistor.cpp @@ -49,7 +49,7 @@ struct Resistor_Bands { /* Global --------------------------------------------------------------------*/ /* Static --------------------------------------------------------------------*/ -static std::vector >> contours; +static class std::vector >> contours; static class cv::Mat hierarchy; static class cv::RotatedRect rect_rot; static class cv::Rect_ rect; @@ -97,7 +97,6 @@ int proc_resistor (void) { int status; - proc_save_mem(0); /* Find resistor (position and angle) */ { @@ -253,8 +252,6 @@ int proc_resistor (void) ******************************************************************************/ static void result_resistor (int status) { - /* Cleanup */ - /* Write result into log */ switch (status) { case RESISTOR_OK: @@ -345,12 +342,13 @@ static void resistor_dimensions_0 (void) static void resistor_crop_0 (void) { - proc_load_mem(2); - int x; int y; int w; int h; + + proc_load_mem(2); + w = rect.width; h = rect.height; x = rect.x; @@ -361,8 +359,10 @@ static void resistor_crop_0 (void) static void resistor_bkgd (void) { - /* hue */ uint8_t bkgd_hue; + uint8_t bkgd_sat; + + /* hue */ proc_load_mem(4); proc_cmp(IMG_IFACE_CMP_HUE); proc_median_vertical(); @@ -370,7 +370,6 @@ static void resistor_bkgd (void) proc_pixel_value(0, 0, &bkgd_hue); /* saturation */ - uint8_t bkgd_sat; proc_load_mem(4); proc_cmp(IMG_IFACE_CMP_SATURATION); proc_median_vertical(); @@ -407,12 +406,13 @@ static void resistor_dimensions_1 (void) static void resistor_crop_1 (void) { - proc_load_mem(2); - int x; int y; int w; int h; + + proc_load_mem(2); + w = rect.width * 0.95; h = rect.height * 0.8; x = rect.x + w * (1.0 - 0.95) / 2.0; @@ -653,8 +653,9 @@ static void bands_colors (void) static void bands_code (void) { - /* Init to 0 */ int i; + + /* Init to 0 */ for (i = 0; i < 6; i++) { code[i] = '\0'; } @@ -1307,6 +1308,8 @@ static void bands_code_deduce_1 (void) static int bands_code_deduce_no (void) { int status; + int i; + /* * Not able to segmentate: * q = 1 2 @@ -1318,7 +1321,6 @@ static int bands_code_deduce_no (void) * u = 0 1 8 */ - int i; for (i = 0; i < 5; i++) { switch (code[i]) { case 'q': @@ -1353,6 +1355,8 @@ static int bands_code_deduce_no (void) static void resistor_value (void) { + int power; + /* Base value */ base = code[2] - '0'; if (code[1] != 'n') { @@ -1363,7 +1367,6 @@ static void resistor_value (void) } /* Calculate resistance */ - int power; if ((code[3] > '0') && (code[3] < '9')) { power = code[3] - '0'; } else if (code[3] == 'g') { @@ -1410,15 +1413,12 @@ static int resistor_tolerance (void) static int chk_std_value (void) { int status; - /* Check that base value is a standard value */ int std_values_10 [12] = {10,12,15,18,22,27,33,39,47,56,68,82}; int std_values_5 [12] = {11,13,16,20,24,30,36,43,51,62,75,91}; - - bool std_value_nok; - std_value_nok = true; - + bool std_value_nok = true; int i; + if (bands_n != 1) { for (i = 0; i < 12; i++) { if (base == std_values_10[i]) { -- cgit v1.2.3 From 9f37d0415a001f8cb8649c9d28fc944dccf56045 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Sat, 29 Dec 2018 14:37:55 +0100 Subject: Fix style --- Makefile | 6 ++++++ bin/Makefile | 5 ++--- modules/Makefile | 1 - tmp/Makefile | 7 +++---- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 4198819..a536e76 100644 --- a/Makefile +++ b/Makefile @@ -216,21 +216,25 @@ libalx: $(Q)$(MAKE) base -C $(LIBALX_DIR) $(Q)$(MAKE) io -C $(LIBALX_DIR) $(Q)$(MAKE) curses -C $(LIBALX_DIR) + @echo PHONY += modules modules: libalx @echo ' MAKE modules' $(Q)$(MAKE) -C $(MODULES_DIR) + @echo PHONY += main main: modules libalx @echo ' MAKE main' $(Q)$(MAKE) -C $(TMP_DIR) + @echo PHONY += binary binary: main @echo ' MAKE binary' $(Q)$(MAKE) -C $(BIN_DIR) + @echo PHONY += install install: uninstall @@ -264,11 +268,13 @@ clean: $(Q)$(MAKE) clean -C $(TMP_DIR) @echo ' CLEAN bin' $(Q)$(MAKE) clean -C $(BIN_DIR) + @echo PHONY += mrproper mrproper: clean @echo ' CLEAN libalx' $(Q)$(MAKE) clean -C $(LIBALX_DIR) + @echo PHONY += help help: diff --git a/bin/Makefile b/bin/Makefile index 5e0ff01..79add73 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -33,13 +33,12 @@ all: $(ALL) $(BIN_NAME): $(MAIN_OBJS) $(MAIN_LIBS) + @echo " CXX $@" $(Q)$(CXX) $(MAIN_OBJS) -o $@ $(STATIC_LIBS) $(LIBS) - @echo " CXX $@" - @echo "" clean: - @echo " RM $(ALL)" + @echo " RM $(ALL)" $(Q)rm -f $(ALL) ################################################################################ diff --git a/modules/Makefile b/modules/Makefile index 2e41afa..61b5871 100644 --- a/modules/Makefile +++ b/modules/Makefile @@ -46,7 +46,6 @@ all: $(Q)$(MAKE) -C $(USR_DIR) @echo ' MAKE modules.o' $(Q)$(MAKE) -C $(TMP_DIR) - @echo PHONY += clean diff --git a/tmp/Makefile b/tmp/Makefile index 4755930..553d349 100644 --- a/tmp/Makefile +++ b/tmp/Makefile @@ -58,17 +58,16 @@ PHONY := all all: $(ALL) main.s: $(MAIN_DEPS) + @echo " CXX $@" $(Q)$(CXX) $(CXXFLAGS) $(MAIN_INC_DIRS) -S $< -o $@ - @echo " CXX $@" main.o: main.s + @echo " AS $@" $(Q)$(AS) $< -o $@ - @echo " AS $@" - @echo "" PHONY += clean clean: - @echo " RM *.o *.s" + @echo " RM *.o *.s" $(Q)rm -f *.o *.s ################################################################################ -- cgit v1.2.3 From d46e32b17b7b15f48aa2d48b5bb1de26f2b1dc24 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Thu, 3 Jan 2019 21:55:01 +0100 Subject: Add function to set pixel value --- modules/image/inc/img_cv.hpp | 3 +- modules/image/inc/img_iface.h | 3 +- modules/image/inc/img_iface.hpp | 11 ++++- modules/image/src/img_alx.cpp | 9 +--- modules/image/src/img_cv.cpp | 42 +++++++++++++++---- modules/image/src/img_iface.cpp | 92 +++++++++++++++++++++++++++++++++-------- 6 files changed, 123 insertions(+), 37 deletions(-) diff --git a/modules/image/inc/img_cv.hpp b/modules/image/inc/img_cv.hpp index a14371f..7412f46 100644 --- a/modules/image/inc/img_cv.hpp +++ b/modules/image/inc/img_cv.hpp @@ -24,7 +24,8 @@ IMG_CV_ACT_FOO = 0x000000u, IMG_CV_ACT_CV = 0x000100u, - IMG_CV_ACT_PIXEL_VALUE, + IMG_CV_ACT_PIXEL_GET, + IMG_CV_ACT_PIXEL_SET, IMG_CV_ACT_SET_ROI, IMG_CV_ACT_AND_2REF, IMG_CV_ACT_NOT, diff --git a/modules/image/inc/img_iface.h b/modules/image/inc/img_iface.h index 00bf4d6..bfdbb70 100644 --- a/modules/image/inc/img_iface.h +++ b/modules/image/inc/img_iface.h @@ -52,7 +52,8 @@ IMG_IFACE_ACT_MEDIAN_VERTICAL, IMG_IFACE_ACT_CV = 0x000100u, - IMG_IFACE_ACT_PIXEL_VALUE, + IMG_IFACE_ACT_PIXEL_GET, + IMG_IFACE_ACT_PIXEL_SET, IMG_IFACE_ACT_SET_ROI, IMG_IFACE_ACT_SET_ROI_2RECT, IMG_IFACE_ACT_AND_2REF, diff --git a/modules/image/inc/img_iface.hpp b/modules/image/inc/img_iface.hpp index a8b3a1f..c492537 100644 --- a/modules/image/inc/img_iface.hpp +++ b/modules/image/inc/img_iface.hpp @@ -61,7 +61,8 @@ IMG_IFACE_ACT_MEDIAN_VERTICAL, IMG_IFACE_ACT_CV = 0x000100u, - IMG_IFACE_ACT_PIXEL_VALUE, + IMG_IFACE_ACT_PIXEL_GET, + IMG_IFACE_ACT_PIXEL_SET, IMG_IFACE_ACT_SET_ROI, IMG_IFACE_ACT_SET_ROI_2RECT, IMG_IFACE_ACT_AND_2REF, @@ -153,12 +154,18 @@ ******* structs ************************************************************** ******************************************************************************/ /* img_cv --------------------------------------------------------------------*/ - struct Img_Iface_Data_Pixel_Value { + struct Img_Iface_Data_Pixel_Get { unsigned char *val; int x; int y; }; + struct Img_Iface_Data_Pixel_Set { + unsigned char val; + int x; + int y; + }; + struct Img_Iface_Data_SetROI { class cv::Rect_ rect; }; diff --git a/modules/image/src/img_alx.cpp b/modules/image/src/img_alx.cpp index 6f172fe..9d3c3c5 100644 --- a/modules/image/src/img_alx.cpp +++ b/modules/image/src/img_alx.cpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: (GPL-2.0-only OR LGPL-3.0-only) * ******************************************************************************/ @@ -47,6 +48,7 @@ static void img_alx_median_vertical (class cv::Mat *imgptr); ******************************************************************************/ void img_alx_act (class cv::Mat *imgptr, int action, void *data) { + switch (action) { case IMG_ALX_ACT_LOCAL_MAX: img_alx_local_max(imgptr); @@ -156,7 +158,6 @@ static void img_alx_skeleton (class cv::Mat *imgptr) int cnt_lo [width]; int cnt_hi_or_eq [width]; class cv::Mat imgtmp; - /* pointer to a pixel (in imgptr) */ uint8_t *img_pix; /* pointer to a pixel near img_pix (in imgptr) */ @@ -229,7 +230,6 @@ static void img_alx_lines_horizontal (class cv::Mat *imgptr) int i; int j; bool white; - /* pointer to a pixel (in imgptr) */ uint8_t *img_pix; @@ -258,7 +258,6 @@ static void img_alx_lines_vertical (class cv::Mat *imgptr) int i; int j; bool white; - /* pointer to a pixel (in imgptr) */ uint8_t *img_pix; @@ -288,7 +287,6 @@ static void img_alx_mean_horizontal (class cv::Mat *imgptr) int j; uint32_t tmp; uint8_t mean; - /* pointer to a pixel (in imgptr) */ uint8_t *img_pix; @@ -313,7 +311,6 @@ static void img_alx_mean_vertical (class cv::Mat *imgptr) int j; uint32_t tmp; uint8_t mean; - /* pointer to a pixel (in imgptr) */ uint8_t *img_pix; @@ -338,7 +335,6 @@ static void img_alx_median_horizontal (class cv::Mat *imgptr) int j; uint8_t row [imgptr->cols]; uint8_t median; - /* pointer to a pixel (in imgptr) */ uint8_t *img_pix; @@ -362,7 +358,6 @@ static void img_alx_median_vertical (class cv::Mat *imgptr) int j; uint8_t col [imgptr->rows]; uint8_t median; - /* pointer to a pixel (in imgptr) */ uint8_t *img_pix; diff --git a/modules/image/src/img_cv.cpp b/modules/image/src/img_cv.cpp index ce3e647..3a7c59b 100644 --- a/modules/image/src/img_cv.cpp +++ b/modules/image/src/img_cv.cpp @@ -34,7 +34,8 @@ ******************************************************************************/ /* Core: The core functionality */ /* Pixel */ -static void img_cv_pixel_value (class cv::Mat *imgptr, void *data); +static void img_cv_pixel_get (class cv::Mat *imgptr, void *data); +static void img_cv_pixel_set (class cv::Mat *imgptr, void *data); /* ROI */ static void img_cv_set_ROI (class cv::Mat *imgptr, void *data); /* Operations on Arrays */ @@ -77,8 +78,11 @@ static void img_cv_hough_circles (class cv::Mat *imgptr, void *data); void img_cv_act (class cv::Mat *imgptr, int action, void *data) { switch (action) { - case IMG_CV_ACT_PIXEL_VALUE: - img_cv_pixel_value(imgptr, data); + case IMG_CV_ACT_PIXEL_GET: + img_cv_pixel_get(imgptr, data); + break; + case IMG_CV_ACT_PIXEL_SET: + img_cv_pixel_set(imgptr, data); break; case IMG_CV_ACT_SET_ROI: @@ -172,25 +176,45 @@ void img_cv_act (class cv::Mat *imgptr, int action, void *data) ******************************************************************************/ /* Core: The core functionality */ /* ----- Pixel */ -static void img_cv_pixel_value (class cv::Mat *imgptr, void *data) +static void img_cv_pixel_get (class cv::Mat *imgptr, void *data) { + struct Img_Iface_Data_Pixel_Get *data_cast; + unsigned char *val; + int x; + int y; /* Data */ - struct Img_Iface_Data_Pixel_Value *data_cast; - data_cast = (struct Img_Iface_Data_Pixel_Value *)data; + data_cast = (struct Img_Iface_Data_Pixel_Get *)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(y, x); } +static void img_cv_pixel_set (class cv::Mat *imgptr, void *data) +{ + struct Img_Iface_Data_Pixel_Set *data_cast; + unsigned char val; + int x; + int y; + + /* Data */ + data_cast = (struct Img_Iface_Data_Pixel_Set *)data; + + /* Value */ + val = data_cast->val; + /* Position */ + x = data_cast->x; + y = data_cast->y; + + /* Set value */ + imgptr->at(y, x) = val; +} + /* ----- ROI */ static void img_cv_set_ROI (class cv::Mat *imgptr, void *data) { diff --git a/modules/image/src/img_iface.cpp b/modules/image/src/img_iface.cpp index ce87044..3bdcf09 100644 --- a/modules/image/src/img_iface.cpp +++ b/modules/image/src/img_iface.cpp @@ -102,7 +102,8 @@ static void img_iface_median_vertical (void); /* img_cv */ /* Core: The core functionality */ /* Pixel */ -static void img_iface_pixel_value (void *data); +static void img_iface_pixel_get (void *data); +static void img_iface_pixel_set (void *data); /* ROI */ static void img_iface_set_ROI (void *data); static void img_iface_set_ROI_2rect (void *data); @@ -267,8 +268,11 @@ void img_iface_act (int action, void *data) /* img_cv */ /* Core: The core functionality */ /* Pixel */ - case IMG_IFACE_ACT_PIXEL_VALUE: - img_iface_pixel_value(data); + case IMG_IFACE_ACT_PIXEL_GET: + img_iface_pixel_get(data); + break; + case IMG_IFACE_ACT_PIXEL_SET: + img_iface_pixel_set(data); break; /* ROI */ case IMG_IFACE_ACT_SET_ROI: @@ -631,8 +635,13 @@ static void img_iface_median_vertical (void) /* img_cv --------------------------------------------------------------------*/ /* ----- Core: The core functionality */ /* ----- ------- Pixel */ -static void img_iface_pixel_value (void *data) +static void img_iface_pixel_get (void *data) { + struct Img_Iface_Data_Pixel_Get data_tmp; + struct Img_Iface_Data_Pixel_Get *data_cast; + unsigned char val; + char title [80]; + /* Must have 1 channel */ if (image_copy_tmp.channels() != 1) { /* Write into log */ @@ -645,13 +654,10 @@ 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, @@ -665,14 +671,13 @@ static void img_iface_pixel_value (void *data) data = (void *)&data_tmp; } - /* Contours size */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_PIXEL_VALUE, data); + /* Get pixel value */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_PIXEL_GET, data); /* Write into log */ - struct Img_Iface_Data_Pixel_Value *data_cast; - data_cast = (struct Img_Iface_Data_Pixel_Value *)data; + data_cast = (struct Img_Iface_Data_Pixel_Get *)data; snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Pixel value: (%i, %i): %i", + "Pixel get: (%i, %i): %i", data_cast->x, data_cast->y, *(data_cast->val)); @@ -680,14 +685,67 @@ static void img_iface_pixel_value (void *data) (user_iface_log.len)++; } +static void img_iface_pixel_set (void *data) +{ + struct Img_Iface_Data_Pixel_Set data_tmp; + struct Img_Iface_Data_Pixel_Set *data_cast; + char title [80]; + + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Data */ + if (!data) { + /* Ask user */ + 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); + + snprintf(title, 80, "val:"); + data_tmp.val = user_iface_getint(0, 0, 255, + title, NULL); + + data = (void *)&data_tmp; + } + + /* Set pixel value */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_PIXEL_SET, data); + + /* Write into log */ + data_cast = (struct Img_Iface_Data_Pixel_Set *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Pixel get: (%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)++; +} + /* ----- ------- ROI */ static void img_iface_set_ROI (void *data) { - /* Data */ struct Img_Iface_Data_SetROI data_tmp; + struct Img_Iface_Data_SetROI *data_cast; + char title [80]; + + /* Data */ if (!data) { /* Ask user */ - char title [80]; snprintf(title, 80, "Origin: x:"); data_tmp.rect.x = user_iface_getint(0, 0, image_copy_tmp.cols, @@ -714,7 +772,6 @@ static void img_iface_set_ROI (void *data) } /* Write into log */ - struct Img_Iface_Data_SetROI *data_cast; data_cast = (struct Img_Iface_Data_SetROI *)data; snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "ROI: (%i,%i) w=%i,h=%i", @@ -731,8 +788,10 @@ static void img_iface_set_ROI (void *data) static void img_iface_set_ROI_2rect (void *data) { - /* Data */ struct Img_Iface_Data_SetROI data_tmp; + struct Img_Iface_Data_SetROI *data_cast; + + /* Data */ if (!data) { data_tmp.rect.x = rectangle.x; data_tmp.rect.y = rectangle.y; @@ -743,7 +802,6 @@ static void img_iface_set_ROI_2rect (void *data) } /* Write into log */ - struct Img_Iface_Data_SetROI *data_cast; data_cast = (struct Img_Iface_Data_SetROI *)data; snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "ROI: (%i,%i) w=%i,h=%i", -- cgit v1.2.3 From 56933310070dee18d24e899e5cc6a9b69f6bdbfe Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Thu, 3 Jan 2019 21:56:01 +0100 Subject: Add function to set pixel value --- modules/proc/inc/proc_common.hpp | 118 ++++++++++++++++++------------------- modules/proc/src/proc_coins.cpp | 2 +- modules/proc/src/proc_common.cpp | 15 ++++- modules/proc/src/proc_objects.cpp | 2 +- modules/proc/src/proc_resistor.cpp | 34 +++++------ modules/user/inc/user_iface.h | 3 +- modules/user/inc/user_iface.hpp | 3 +- modules/user/src/user_clui.c | 8 ++- modules/user/src/user_tui.c | 8 ++- 9 files changed, 105 insertions(+), 88 deletions(-) diff --git a/modules/proc/inc/proc_common.hpp b/modules/proc/inc/proc_common.hpp index f31acde..85d5eb3 100644 --- a/modules/proc/inc/proc_common.hpp +++ b/modules/proc/inc/proc_common.hpp @@ -34,66 +34,64 @@ extern "C" { /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ - void proc_apply (void); - void proc_save_mem (int n); - void proc_load_mem (int n); - void proc_save_ref (void); - void proc_save_file (void); - void proc_save_update (void); - - void proc_local_max (void); - void proc_skeleton (void); - void proc_lines_vertical (void); - void proc_median_horizontal (void); - void proc_median_vertical (void); - - void proc_pixel_value (int x, int y, unsigned char *val); - void proc_ROI (int x, int y, int w, int h); - void proc_and_2ref (void); - void proc_not (void); - void proc_or_2ref (void); - void proc_cmp (int cmp); - void proc_dilate (int size); - void proc_erode (int size); - void proc_dilate_erode (int size); - void proc_erode_dilate (int size); - void proc_smooth (int method, int ksize); - void proc_border (int size); - void proc_rotate ( - double center_x, - double center_y, - double angle); - void proc_adaptive_threshold (int method, int type, int ksize); - void proc_cvt_color (int method); - void proc_distance_transform (void); - void proc_threshold (int type, int ksize); - void proc_contours ( - std::vector >> *contours, - class cv::Mat *hierarchy); - void proc_contours_size ( - std::vector >> *contours, - double *area, - double *perimeter); - void proc_bounding_rect ( - std::vector > *contour, - class cv::Rect_ *rect, - bool show); - void proc_fit_ellipse ( - std::vector > *contour, - class cv::RotatedRect *rect, - bool show); - void proc_min_area_rect ( - std::vector > *contour, - class cv::RotatedRect *rect, - bool show); - - void proc_OCR (int lang, int conf); - void proc_zbar (int type); - - void proc_show_img (void); - - void clock_start (void); - void clock_stop (const char *txt); +void proc_apply (void); +void proc_save_mem (int n); +void proc_load_mem (int n); +void proc_save_ref (void); +void proc_save_file (void); +void proc_save_update (void); + +void proc_local_max (void); +void proc_skeleton (void); +void proc_lines_vertical (void); +void proc_median_horizontal (void); +void proc_median_vertical (void); + +void proc_pixel_get (int x, int y, unsigned char *val); +void proc_pixel_set (int x, int y, unsigned char val); +void proc_ROI (int x, int y, int w, int h); +void proc_and_2ref (void); +void proc_not (void); +void proc_or_2ref (void); +void proc_cmp (int cmp); +void proc_dilate (int size); +void proc_erode (int size); +void proc_dilate_erode (int size); +void proc_erode_dilate (int size); +void proc_smooth (int method, int ksize); +void proc_border (int size); +void proc_rotate (double center_x, double center_y, double angle); +void proc_adaptive_threshold (int method, int type, int ksize); +void proc_cvt_color (int method); +void proc_distance_transform (void); +void proc_threshold (int type, int ksize); +void proc_contours ( + std::vector >> *contours, + class cv::Mat *hierarchy); +void proc_contours_size ( + std::vector >> *contours, + double *area, + double *perimeter); +void proc_bounding_rect ( + std::vector > *contour, + class cv::Rect_ *rect, + bool show); +void proc_fit_ellipse ( + std::vector > *contour, + class cv::RotatedRect *rect, + bool show); +void proc_min_area_rect ( + std::vector > *contour, + class cv::RotatedRect *rect, + bool show); + +void proc_OCR (int lang, int conf); +void proc_zbar (int type); + +void proc_show_img (void); + +void clock_start (void); +void clock_stop (const char *txt); /****************************************************************************** diff --git a/modules/proc/src/proc_coins.cpp b/modules/proc/src/proc_coins.cpp index 1b9316e..71bbac2 100644 --- a/modules/proc/src/proc_coins.cpp +++ b/modules/proc/src/proc_coins.cpp @@ -257,7 +257,7 @@ static void coins_diameters_pix (void) /* Get coins diameters in pixels */ for (i = 0; i < coins_n; i++) { - proc_pixel_value(coins[i].x, coins[i].y, + proc_pixel_get(coins[i].x, coins[i].y, &(coins[i].diameter_pix)); coins[i].diameter_pix *= 2; } diff --git a/modules/proc/src/proc_common.cpp b/modules/proc/src/proc_common.cpp index 2fc2c35..86c137a 100644 --- a/modules/proc/src/proc_common.cpp +++ b/modules/proc/src/proc_common.cpp @@ -117,13 +117,22 @@ void proc_median_vertical (void) proc_show_img(); } -void proc_pixel_value (int x, int y, unsigned char *val) +void proc_pixel_get (int x, int y, unsigned char *val) { - struct Img_Iface_Data_Pixel_Value data; + struct Img_Iface_Data_Pixel_Get data; data.x = x; data.y = y; data.val = val; - img_iface_act(IMG_IFACE_ACT_PIXEL_VALUE, (void *)&data); + img_iface_act(IMG_IFACE_ACT_PIXEL_GET, (void *)&data); +} + +void proc_pixel_set (int x, int y, unsigned char val) +{ + struct Img_Iface_Data_Pixel_Set data; + data.x = x; + data.y = y; + data.val = val; + img_iface_act(IMG_IFACE_ACT_PIXEL_SET, (void *)&data); } void proc_ROI (int x, int y, int w, int h) diff --git a/modules/proc/src/proc_objects.cpp b/modules/proc/src/proc_objects.cpp index 9b39ce5..5c30a52 100644 --- a/modules/proc/src/proc_objects.cpp +++ b/modules/proc/src/proc_objects.cpp @@ -446,7 +446,7 @@ static void pattern_squares_len_get (void) /* Get pattern square side lenght in pixels */ for (i = 0; i < squares_n; i++) { - proc_pixel_value(pattern.square[i].pos.x_pix, + proc_pixel_get(pattern.square[i].pos.x_pix, pattern.square[i].pos.y_pix, &(pattern.square[i].len)); pattern.square[i].len *= 2; diff --git a/modules/proc/src/proc_resistor.cpp b/modules/proc/src/proc_resistor.cpp index 18d922c..cdac617 100644 --- a/modules/proc/src/proc_resistor.cpp +++ b/modules/proc/src/proc_resistor.cpp @@ -367,14 +367,14 @@ static void resistor_bkgd (void) proc_cmp(IMG_IFACE_CMP_HUE); proc_median_vertical(); proc_median_horizontal(); - proc_pixel_value(0, 0, &bkgd_hue); + proc_pixel_get(0, 0, &bkgd_hue); /* saturation */ proc_load_mem(4); proc_cmp(IMG_IFACE_CMP_SATURATION); proc_median_vertical(); proc_median_horizontal(); - proc_pixel_value(0, 0, &bkgd_sat); + proc_pixel_get(0, 0, &bkgd_sat); if (bkgd_hue < 50) { /* Beige */ @@ -605,49 +605,49 @@ static void bands_colors (void) /* Hue */ proc_load_mem(9); if (bands_n == 5) { - proc_pixel_value(bands[0].x, bands[0].y, &(bands[0].h)); + proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].h)); } if (bands_n >= 3) { - proc_pixel_value(bands[1].x, bands[1].y, &(bands[1].h)); + proc_pixel_get(bands[1].x, bands[1].y, &(bands[1].h)); } - proc_pixel_value(bands[2].x, bands[2].y, &(bands[2].h)); + proc_pixel_get(bands[2].x, bands[2].y, &(bands[2].h)); if (bands_n >= 3) { - proc_pixel_value(bands[3].x, bands[3].y, &(bands[3].h)); + proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].h)); } if (bands_n > 3) { - proc_pixel_value(bands[4].x, bands[4].y, &(bands[4].h)); + proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].h)); } /* Saturation */ proc_load_mem(10); if (bands_n == 5) { - proc_pixel_value(bands[0].x, bands[0].y, &(bands[0].s)); + proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].s)); } if (bands_n >= 3) { - proc_pixel_value(bands[1].x, bands[1].y, &(bands[1].s)); + proc_pixel_get(bands[1].x, bands[1].y, &(bands[1].s)); } - proc_pixel_value(bands[2].x, bands[2].y, &(bands[2].s)); + proc_pixel_get(bands[2].x, bands[2].y, &(bands[2].s)); if (bands_n >= 3) { - proc_pixel_value(bands[3].x, bands[3].y, &(bands[3].s)); + proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].s)); } if (bands_n > 3) { - proc_pixel_value(bands[4].x, bands[4].y, &(bands[4].s)); + proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].s)); } /* Value */ proc_load_mem(11); if (bands_n == 5) { - proc_pixel_value(bands[0].x, bands[0].y, &(bands[0].v)); + proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].v)); } if (bands_n >= 3) { - proc_pixel_value(bands[1].x, bands[1].y, &(bands[1].v)); + proc_pixel_get(bands[1].x, bands[1].y, &(bands[1].v)); } - proc_pixel_value(bands[2].x, bands[2].y, &(bands[2].v)); + proc_pixel_get(bands[2].x, bands[2].y, &(bands[2].v)); if (bands_n >= 3) { - proc_pixel_value(bands[3].x, bands[3].y, &(bands[3].v)); + proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].v)); } if (bands_n > 3) { - proc_pixel_value(bands[4].x, bands[4].y, &(bands[4].v)); + proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].v)); } } diff --git a/modules/user/inc/user_iface.h b/modules/user/inc/user_iface.h index d69978e..f4511be 100644 --- a/modules/user/inc/user_iface.h +++ b/modules/user/inc/user_iface.h @@ -48,7 +48,8 @@ USER_IFACE_ACT_MEDIAN_VERTICAL, USER_IFACE_ACT_CV = 0x000100u, - USER_IFACE_ACT_PIXEL_VALUE, + USER_IFACE_ACT_PIXEL_GET, + USER_IFACE_ACT_PIXEL_SET, USER_IFACE_ACT_SET_ROI, USER_IFACE_ACT_SET_ROI_2RECT, USER_IFACE_ACT_AND_2REF, diff --git a/modules/user/inc/user_iface.hpp b/modules/user/inc/user_iface.hpp index bb805f7..c127d93 100644 --- a/modules/user/inc/user_iface.hpp +++ b/modules/user/inc/user_iface.hpp @@ -48,7 +48,8 @@ USER_IFACE_ACT_MEDIAN_VERTICAL, USER_IFACE_ACT_CV = 0x000100u, - USER_IFACE_ACT_PIXEL_VALUE, + USER_IFACE_ACT_PIXEL_GET, + USER_IFACE_ACT_PIXEL_SET, USER_IFACE_ACT_SET_ROI, USER_IFACE_ACT_SET_ROI_2RECT, USER_IFACE_ACT_AND_2REF, diff --git a/modules/user/src/user_clui.c b/modules/user/src/user_clui.c index ff49e56..9a4405a 100644 --- a/modules/user/src/user_clui.c +++ b/modules/user/src/user_clui.c @@ -263,7 +263,10 @@ static int usr_input (void) /* Pixel */ switch (ch[4]) { case '0': - action = USER_IFACE_ACT_PIXEL_VALUE; + action = USER_IFACE_ACT_PIXEL_GET; + break; + case '1': + action = USER_IFACE_ACT_PIXEL_SET; break; default: action = USER_IFACE_ACT_FOO; @@ -566,7 +569,8 @@ static void show_help (void) printf(" - Vertical mean: %s\n", "f021"); printf(" - Horizontal median: %s\n", "f022"); printf(" - Vertical median: %s\n", "f023"); - printf(" - Pixel value: %s\n", "f1000"); + printf(" - Pixel get: %s\n", "f1000"); + printf(" - Pixel set: %s\n", "f1001"); printf(" - Set ROI: %s\n", "f1010"); printf(" - Set ROI 2rect: %s\n", "f1011"); printf(" - Bitwise AND 2ref: %s\n", "f1020"); diff --git a/modules/user/src/user_tui.c b/modules/user/src/user_tui.c index 7049255..305e1d2 100644 --- a/modules/user/src/user_tui.c +++ b/modules/user/src/user_tui.c @@ -366,7 +366,10 @@ static int usr_input (void) switch (ch) { case '0': - action = USER_IFACE_ACT_PIXEL_VALUE; + action = USER_IFACE_ACT_PIXEL_GET; + break; + case '1': + action = USER_IFACE_ACT_PIXEL_SET; break; default: action = USER_IFACE_ACT_FOO; @@ -712,7 +715,8 @@ static void show_help (void) mvwprintw(win_help, r++, c, " - Vertical mean: %s", "f021"); mvwprintw(win_help, r++, c, " - Horizontal median: %s", "f022"); mvwprintw(win_help, r++, c, " - Vertical median: %s", "f023"); - mvwprintw(win_help, r++, c, " - Pixel value: %s", "f1000"); + mvwprintw(win_help, r++, c, " - Pixel get: %s", "f1000"); + mvwprintw(win_help, r++, c, " - Pixel set: %s", "f1001"); mvwprintw(win_help, r++, c, " - Set ROI: %s", "f1010"); mvwprintw(win_help, r++, c, " - Set ROI 2rect: %s", "f1011"); mvwprintw(win_help, r++, c, " - Bitwise AND 2ref: %s", "f1020"); -- cgit v1.2.3 From d08a657f1046c3db7142cb855cb7a1897bfd468f Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Thu, 3 Jan 2019 22:02:13 +0100 Subject: Minor changes --- modules/image/src/img_alx.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/image/src/img_alx.cpp b/modules/image/src/img_alx.cpp index 9d3c3c5..54b82bf 100644 --- a/modules/image/src/img_alx.cpp +++ b/modules/image/src/img_alx.cpp @@ -31,7 +31,7 @@ /****************************************************************************** - ******* static functions ***************************************************** + ******* static functions (prototypes) **************************************** ******************************************************************************/ static void img_alx_local_max (class cv::Mat *imgptr); static void img_alx_skeleton (class cv::Mat *imgptr); @@ -44,7 +44,7 @@ static void img_alx_median_vertical (class cv::Mat *imgptr); /****************************************************************************** - ******* main ***************************************************************** + ******* global functions ***************************************************** ******************************************************************************/ void img_alx_act (class cv::Mat *imgptr, int action, void *data) { @@ -81,7 +81,7 @@ void img_alx_act (class cv::Mat *imgptr, int action, void *data) /****************************************************************************** - ******* static functions ***************************************************** + ******* static functions (definitions) *************************************** ******************************************************************************/ static void img_alx_local_max (class cv::Mat *imgptr) { -- cgit v1.2.3 From 4c496f527292468264900c5800a38c8dce07f918 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Thu, 3 Jan 2019 22:10:12 +0100 Subject: Clean code in skeleton function --- modules/image/src/img_alx.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/modules/image/src/img_alx.cpp b/modules/image/src/img_alx.cpp index 54b82bf..cb88d5c 100644 --- a/modules/image/src/img_alx.cpp +++ b/modules/image/src/img_alx.cpp @@ -144,19 +144,13 @@ static void img_alx_local_max (class cv::Mat *imgptr) static void img_alx_skeleton (class cv::Mat *imgptr) { - int i; - int j; - int k; - int l; - int r; - int dist_x; - int dist_y; /* Width of the skeleton */ const int width = 5; - /* Minimum value of the skeleton */ - bool skeleton; - int cnt_lo [width]; - int cnt_hi_or_eq [width]; + int dist_x; + int dist_y; + bool skeleton; + int cnt_lo [width]; + int cnt_hi_or_eq [width]; class cv::Mat imgtmp; /* pointer to a pixel (in imgptr) */ uint8_t *img_pix; @@ -165,6 +159,12 @@ static void img_alx_skeleton (class cv::Mat *imgptr) /* pointer to a pixel (same position as img_pix, but in imgtmp) */ uint8_t *tmp_pix; + int i; + int j; + int k; + int l; + int r; + /* Tmp image copy */ imgptr->copyTo(imgtmp); @@ -182,7 +182,6 @@ static void img_alx_skeleton (class cv::Mat *imgptr) cnt_lo[r] = 0; cnt_hi_or_eq[r] = 0; } - skeleton = false; for (k = i - width; k <= i + width; k++) { for (l = j - width; l <= j + width; l++) { @@ -206,6 +205,7 @@ static void img_alx_skeleton (class cv::Mat *imgptr) } } + skeleton = false; for (r = 0; r < width; r++) { if (cnt_lo[r] > (cnt_hi_or_eq[r] + (1.6) * (r + 1))) { skeleton = true; -- cgit v1.2.3 From ddbe05a3b4bd4ec8b195f7526f886896ac0f9610 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Thu, 3 Jan 2019 22:21:30 +0100 Subject: Improve algorithm for max value --- modules/image/src/img_alx.cpp | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/modules/image/src/img_alx.cpp b/modules/image/src/img_alx.cpp index cb88d5c..093ff69 100644 --- a/modules/image/src/img_alx.cpp +++ b/modules/image/src/img_alx.cpp @@ -89,7 +89,6 @@ static void img_alx_local_max (class cv::Mat *imgptr) int j; int k; int l; - bool local_max; /* Minimum distance between local maxima */ const int dist_min = 16; /* Minimum value of local maxima */ @@ -110,30 +109,30 @@ static void img_alx_local_max (class cv::Mat *imgptr) for (j = 0; j < imgptr->cols; j++) { img_pix = imgptr->data + i * imgptr->step + j; tmp_pix = imgtmp.data + i * imgptr->step + j; - local_max = true; + *tmp_pix = 0; if (*img_pix < val_min) { - local_max = false; + goto next_pixel; } - for (k = i - dist_min; (k < i + dist_min+1) && local_max; k++) { - for (l = j - dist_min; (l < j + dist_min+1) && local_max; l++) { + for (k = (i - dist_min); k < (i + dist_min + 1); k++) { + for (l = (j - dist_min); l < (j + dist_min + 1); l++) { near_pix = imgptr->data + k * imgptr->step + l; if ((k >= 0) && (k < imgptr->rows)) { if ((l >= 0) && (l < imgptr->cols)) { if (*img_pix < *near_pix) { - local_max = false; + goto next_pixel; } } } } } - if (local_max) { - *tmp_pix = *img_pix; - } else { - *tmp_pix = 0; - } + *tmp_pix = *img_pix; + continue; + +next_pixel: + *tmp_pix = 0; } } @@ -144,7 +143,7 @@ static void img_alx_local_max (class cv::Mat *imgptr) static void img_alx_skeleton (class cv::Mat *imgptr) { - /* Width of the skeleton */ + /* (Half of the) width of the skeleton */ const int width = 5; int dist_x; int dist_y; -- cgit v1.2.3 From a4f928523a6b8f18303b00d94500d045f5ac0c62 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Fri, 4 Jan 2019 02:51:32 +0100 Subject: Remove unused initialization --- modules/image/src/img_alx.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/image/src/img_alx.cpp b/modules/image/src/img_alx.cpp index 093ff69..b4db8ee 100644 --- a/modules/image/src/img_alx.cpp +++ b/modules/image/src/img_alx.cpp @@ -109,7 +109,6 @@ static void img_alx_local_max (class cv::Mat *imgptr) for (j = 0; j < imgptr->cols; j++) { img_pix = imgptr->data + i * imgptr->step + j; tmp_pix = imgtmp.data + i * imgptr->step + j; - *tmp_pix = 0; if (*img_pix < val_min) { goto next_pixel; -- cgit v1.2.3 From 4cd8237c148ffdc199e209454813b77bfacec4a6 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Fri, 4 Jan 2019 16:46:45 +0100 Subject: Unix new lines --- modules/about/inc/about.h | 126 +- modules/about/inc/about.hpp | 150 +- modules/about/src/about.c | 176 +- modules/ctrl/inc/start.h | 86 +- modules/ctrl/src/start.c | 210 +- modules/image/inc/img_alx.hpp | 104 +- modules/image/inc/img_calib3d.hpp | 92 +- modules/image/inc/img_cv.hpp | 142 +- modules/image/inc/img_iface.h | 374 ++-- modules/image/inc/img_iface.hpp | 686 +++--- modules/image/inc/img_ocr.h | 76 +- modules/image/inc/img_ocr.hpp | 100 +- modules/image/inc/img_orb.hpp | 92 +- modules/image/inc/img_zbar.hpp | 92 +- modules/image/src/img_alx.cpp | 760 +++---- modules/image/src/img_calib3d.cpp | 284 +-- modules/image/src/img_cv.cpp | 1762 ++++++++-------- modules/image/src/img_iface.cpp | 4020 ++++++++++++++++++------------------ modules/image/src/img_ocr.c | 256 +-- modules/image/src/img_orb.cpp | 252 +-- modules/image/src/img_zbar.cpp | 204 +- modules/menu/inc/menu_clui.h | 54 +- modules/menu/inc/menu_iface.h | 86 +- modules/menu/inc/menu_iface.hpp | 110 +- modules/menu/inc/menu_tui.h | 54 +- modules/menu/inc/parser.h | 54 +- modules/menu/inc/parser.hpp | 78 +- modules/menu/src/menu_clui.c | 232 +-- modules/menu/src/menu_iface.c | 90 +- modules/menu/src/menu_tui.c | 660 +++--- modules/menu/src/parser.c | 280 +-- modules/proc/inc/proc_coins.h | 96 +- modules/proc/inc/proc_coins.hpp | 120 +- modules/proc/inc/proc_common.h | 90 +- modules/proc/inc/proc_common.hpp | 222 +- modules/proc/inc/proc_iface.h | 140 +- modules/proc/inc/proc_iface.hpp | 164 +- modules/proc/inc/proc_label.h | 100 +- modules/proc/inc/proc_label.hpp | 124 +- modules/proc/inc/proc_objects.h | 98 +- modules/proc/inc/proc_objects.hpp | 122 +- modules/proc/inc/proc_resistor.h | 100 +- modules/proc/inc/proc_resistor.hpp | 124 +- modules/proc/src/proc_coins.cpp | 756 +++---- modules/proc/src/proc_common.cpp | 864 ++++---- modules/proc/src/proc_iface.c | 430 ++-- modules/proc/src/proc_label.cpp | 770 +++---- modules/proc/src/proc_objects.cpp | 1394 ++++++------- modules/proc/src/proc_resistor.cpp | 2918 +++++++++++++------------- modules/save/inc/save.h | 148 +- modules/save/inc/save.hpp | 182 +- modules/save/src/save.cpp | 388 ++-- modules/user/inc/user_clui.h | 60 +- modules/user/inc/user_iface.h | 326 +-- modules/user/inc/user_iface.hpp | 350 ++-- modules/user/inc/user_tui.h | 72 +- modules/user/src/user_clui.c | 1244 +++++------ modules/user/src/user_iface.c | 454 ++-- modules/user/src/user_tui.c | 1542 +++++++------- src/main.cpp | 176 +- 60 files changed, 12658 insertions(+), 12658 deletions(-) diff --git a/modules/about/inc/about.h b/modules/about/inc/about.h index 5122d14..62a0963 100644 --- a/modules/about/inc/about.h +++ b/modules/about/inc/about.h @@ -1,63 +1,63 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_ABOUT_H - # define VA_ABOUT_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* FILENAME_MAX */ - #include - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define PROG_NAME "vision-artificial" - # define PROG_YEAR "2018" - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Share_File { - SHARE_COPYRIGHT, - SHARE_DISCLAIMER, - SHARE_HELP, - SHARE_LICENSE, - SHARE_USAGE - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - extern char share_path [FILENAME_MAX]; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void about_init (void); - void snprint_share_file (char *dest, int destsize, int share_file); - void print_share_file (int share_file); - void print_version (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* about.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_ABOUT_H + # define VA_ABOUT_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* FILENAME_MAX */ + #include + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define PROG_NAME "vision-artificial" + # define PROG_YEAR "2018" + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Share_File { + SHARE_COPYRIGHT, + SHARE_DISCLAIMER, + SHARE_HELP, + SHARE_LICENSE, + SHARE_USAGE + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern char share_path [FILENAME_MAX]; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void about_init (void); + void snprint_share_file (char *dest, int destsize, int share_file); + void print_share_file (int share_file); + void print_version (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* about.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/about/inc/about.hpp b/modules/about/inc/about.hpp index 50180ba..a1a9f2e 100644 --- a/modules/about/inc/about.hpp +++ b/modules/about/inc/about.hpp @@ -1,75 +1,75 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_ABOUT_HPP - # define VA_ABOUT_HPP - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* FILENAME_MAX */ - #include - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define PROG_NAME "vision-artificial" - # define PROG_YEAR "2018" - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Share_File { - SHARE_COPYRIGHT, - SHARE_DISCLAIMER, - SHARE_HELP, - SHARE_LICENSE, - SHARE_USAGE - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - extern char share_path [FILENAME_MAX]; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void about_init (void); - void snprint_share_file (char *dest, int destsize, int share_file); - void print_share_file (int share_file); - void print_version (void); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* about.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_ABOUT_HPP + # define VA_ABOUT_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* FILENAME_MAX */ + #include + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define PROG_NAME "vision-artificial" + # define PROG_YEAR "2018" + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Share_File { + SHARE_COPYRIGHT, + SHARE_DISCLAIMER, + SHARE_HELP, + SHARE_LICENSE, + SHARE_USAGE + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern char share_path [FILENAME_MAX]; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void about_init (void); + void snprint_share_file (char *dest, int destsize, int share_file); + void print_share_file (int share_file); + void print_version (void); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* about.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/about/src/about.c b/modules/about/src/about.c index d443e1d..a9561e0 100644 --- a/modules/about/src/about.c +++ b/modules/about/src/about.c @@ -1,88 +1,88 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* printf() */ - #include - -/* libalx --------------------------------------------------------------------*/ - /* alx_snprint_file() */ - #include "alx_file.h" - -/* Module --------------------------------------------------------------------*/ - #include "about.h" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define BUFF_SIZE_TEXT (1048576) - - # define BEGINNING "\n┌──────────────────────────────────────────────────────────────────────────────┐\n" - # define ENDING "└──────────────────────────────────────────────────────────────────────────────┘\n\n" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -char share_path [FILENAME_MAX]; - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void about_init (void) -{ - snprintf(share_path, FILENAME_MAX, "%s/%s/", INSTALL_SHARE_DIR, SHARE_DIR); -} - -void snprint_share_file (char *dest, int destsize, int share_file) -{ - char file_name [FILENAME_MAX]; - - switch (share_file) { - case SHARE_COPYRIGHT: - snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "COPYRIGHT.txt"); - break; - case SHARE_DISCLAIMER: - snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "DISCLAIMER.txt"); - break; - case SHARE_HELP: - snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "HELP.txt"); - break; - case SHARE_LICENSE: - snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "LICENSE.txt"); - break; - case SHARE_USAGE: - snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "USAGE.txt"); - break; - } - - alx_snprint_file(dest, destsize, file_name); -} - -void print_share_file (int share_file) -{ - char str [BUFF_SIZE_TEXT]; - - snprint_share_file(str, BUFF_SIZE_TEXT, share_file); - - printf(BEGINNING); - printf("%s", str); - printf(ENDING); -} - -void print_version (void) -{ - printf("" PROG_NAME " " PROG_VERSION "\n\n"); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* printf() */ + #include + +/* libalx --------------------------------------------------------------------*/ + /* alx_snprint_file() */ + #include "alx_file.h" + +/* Module --------------------------------------------------------------------*/ + #include "about.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define BUFF_SIZE_TEXT (1048576) + + # define BEGINNING "\n┌──────────────────────────────────────────────────────────────────────────────┐\n" + # define ENDING "└──────────────────────────────────────────────────────────────────────────────┘\n\n" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +char share_path [FILENAME_MAX]; + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void about_init (void) +{ + snprintf(share_path, FILENAME_MAX, "%s/%s/", INSTALL_SHARE_DIR, SHARE_DIR); +} + +void snprint_share_file (char *dest, int destsize, int share_file) +{ + char file_name [FILENAME_MAX]; + + switch (share_file) { + case SHARE_COPYRIGHT: + snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "COPYRIGHT.txt"); + break; + case SHARE_DISCLAIMER: + snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "DISCLAIMER.txt"); + break; + case SHARE_HELP: + snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "HELP.txt"); + break; + case SHARE_LICENSE: + snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "LICENSE.txt"); + break; + case SHARE_USAGE: + snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "USAGE.txt"); + break; + } + + alx_snprint_file(dest, destsize, file_name); +} + +void print_share_file (int share_file) +{ + char str [BUFF_SIZE_TEXT]; + + snprint_share_file(str, BUFF_SIZE_TEXT, share_file); + + printf(BEGINNING); + printf("%s", str); + printf(ENDING); +} + +void print_version (void) +{ + printf("" PROG_NAME " " PROG_VERSION "\n\n"); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/ctrl/inc/start.h b/modules/ctrl/inc/start.h index 9b79302..1ef2af6 100644 --- a/modules/ctrl/inc/start.h +++ b/modules/ctrl/inc/start.h @@ -1,43 +1,43 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_START_H - # define VA_START_H - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Start_Mode { - START_FOO = 0, - START_SINGLE, - START_SERIES - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - extern int start_mode; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void start_switch (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* start.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_START_H + # define VA_START_H + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Start_Mode { + START_FOO = 0, + START_SINGLE, + START_SERIES + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern int start_mode; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void start_switch (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* start.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/ctrl/src/start.c b/modules/ctrl/src/start.c index bd801c1..37ea1b4 100644 --- a/modules/ctrl/src/start.c +++ b/modules/ctrl/src/start.c @@ -1,105 +1,105 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* errno */ - #include - #include - /* printf() */ - #include - -/* Project -------------------------------------------------------------------*/ - /* img_iface_load() */ - #include "img_iface.h" - /* proc_iface_series() */ - #include "proc_iface.h" - /* saved_name*/ - #include "save.h" - /* user_iface() */ - #include "user_iface.h" - -/* Module --------------------------------------------------------------------*/ - #include "start.h" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -int start_mode; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void start_foo (void); -static void start_single (void); -static void start_series (void); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void start_switch (void) -{ - switch (start_mode) { - case START_FOO: - start_foo(); - break; - - case START_SINGLE: - start_single(); - break; - - case START_SERIES: - start_series(); - break; - } -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void start_foo (void) -{ - /* empty */ -} - -static void start_single (void) -{ - errno = 0; - img_iface_load(NULL, saved_name); - - if (!errno) { - user_iface_init(); - user_iface(); - user_iface_cleanup(); - } else { - printf("errno:%i\n", errno); - } - - img_iface_cleanup(); -} - -static void start_series (void) -{ - int tmp; - tmp = user_iface_mode; - user_iface_mode = USER_IFACE_CLUI; - - user_iface_init(); - proc_iface_series(); - user_iface_cleanup(); - - user_iface_mode = tmp; -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* errno */ + #include + #include + /* printf() */ + #include + +/* Project -------------------------------------------------------------------*/ + /* img_iface_load() */ + #include "img_iface.h" + /* proc_iface_series() */ + #include "proc_iface.h" + /* saved_name*/ + #include "save.h" + /* user_iface() */ + #include "user_iface.h" + +/* Module --------------------------------------------------------------------*/ + #include "start.h" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +int start_mode; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void start_foo (void); +static void start_single (void); +static void start_series (void); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void start_switch (void) +{ + switch (start_mode) { + case START_FOO: + start_foo(); + break; + + case START_SINGLE: + start_single(); + break; + + case START_SERIES: + start_series(); + break; + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void start_foo (void) +{ + /* empty */ +} + +static void start_single (void) +{ + errno = 0; + img_iface_load(NULL, saved_name); + + if (!errno) { + user_iface_init(); + user_iface(); + user_iface_cleanup(); + } else { + printf("errno:%i\n", errno); + } + + img_iface_cleanup(); +} + +static void start_series (void) +{ + int tmp; + tmp = user_iface_mode; + user_iface_mode = USER_IFACE_CLUI; + + user_iface_init(); + proc_iface_series(); + user_iface_cleanup(); + + user_iface_mode = tmp; +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/inc/img_alx.hpp b/modules/image/inc/img_alx.hpp index 9476ef8..d3867d6 100644 --- a/modules/image/inc/img_alx.hpp +++ b/modules/image/inc/img_alx.hpp @@ -1,52 +1,52 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_ALX_H - # define VA_IMG_ALX_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - /* openCV */ - #include - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_Alx_Action { - IMG_ALX_ACT_FOO = 0x000000u, - - IMG_ALX_ACT_ALX = 0x000010u, - IMG_ALX_ACT_LOCAL_MAX, - IMG_ALX_ACT_SKELETON, - IMG_ALX_ACT_LINES_HORIZONTAL, - IMG_ALX_ACT_LINES_VERTICAL, - IMG_ALX_ACT_MEAN_HORIZONTAL, - IMG_ALX_ACT_MEAN_VERTICAL, - IMG_ALX_ACT_MEDIAN_HORIZONTAL, - IMG_ALX_ACT_MEDIAN_VERTICAL - }; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void img_alx_act (class cv::Mat *imgptr, int action, void *data); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_alx.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_IMG_ALX_H + # define VA_IMG_ALX_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + /* openCV */ + #include + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Img_Alx_Action { + IMG_ALX_ACT_FOO = 0x000000u, + + IMG_ALX_ACT_ALX = 0x000010u, + IMG_ALX_ACT_LOCAL_MAX, + IMG_ALX_ACT_SKELETON, + IMG_ALX_ACT_LINES_HORIZONTAL, + IMG_ALX_ACT_LINES_VERTICAL, + IMG_ALX_ACT_MEAN_HORIZONTAL, + IMG_ALX_ACT_MEAN_VERTICAL, + IMG_ALX_ACT_MEDIAN_HORIZONTAL, + IMG_ALX_ACT_MEDIAN_VERTICAL + }; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void img_alx_act (class cv::Mat *imgptr, int action, void *data); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* img_alx.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/inc/img_calib3d.hpp b/modules/image/inc/img_calib3d.hpp index 777f33c..7079d68 100644 --- a/modules/image/inc/img_calib3d.hpp +++ b/modules/image/inc/img_calib3d.hpp @@ -1,46 +1,46 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_CALIB3D_HPP - # define VA_IMG_CALIB3D_HPP - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - /* openCV */ - #include - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_Calib3d_Action { - IMG_CALIB3D_ACT_FOO = 0x000000u, - - IMG_CALIB3D_ACT_CALIB3D = 0x000400u, - IMG_CALIB3D_ACT_CALIBRATE, - IMG_CALIB3D_ACT_UNDISTORT - }; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void img_calib3d_act (class cv::Mat *imgptr, int action, void *data); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_calib3d.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_IMG_CALIB3D_HPP + # define VA_IMG_CALIB3D_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + /* openCV */ + #include + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Img_Calib3d_Action { + IMG_CALIB3D_ACT_FOO = 0x000000u, + + IMG_CALIB3D_ACT_CALIB3D = 0x000400u, + IMG_CALIB3D_ACT_CALIBRATE, + IMG_CALIB3D_ACT_UNDISTORT + }; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void img_calib3d_act (class cv::Mat *imgptr, int action, void *data); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* img_calib3d.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/inc/img_cv.hpp b/modules/image/inc/img_cv.hpp index 7412f46..61cb78a 100644 --- a/modules/image/inc/img_cv.hpp +++ b/modules/image/inc/img_cv.hpp @@ -1,71 +1,71 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_CV_H - # define VA_IMG_CV_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* packages ------------------------------------------------------------------*/ - #include - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_Cv_Action { - IMG_CV_ACT_FOO = 0x000000u, - - IMG_CV_ACT_CV = 0x000100u, - IMG_CV_ACT_PIXEL_GET, - IMG_CV_ACT_PIXEL_SET, - IMG_CV_ACT_SET_ROI, - IMG_CV_ACT_AND_2REF, - IMG_CV_ACT_NOT, - IMG_CV_ACT_OR_2REF, - IMG_CV_ACT_COMPONENT, - IMG_CV_ACT_DILATE, - IMG_CV_ACT_ERODE, - IMG_CV_ACT_SMOOTH, - IMG_CV_ACT_SOBEL, - IMG_CV_ACT_BORDER, - IMG_CV_ACT_MIRROR, - IMG_CV_ACT_ROTATE_ORTO, - IMG_CV_ACT_ROTATE, - IMG_CV_ACT_ADAPTIVE_THRESHOLD, - IMG_CV_ACT_CVT_COLOR, - IMG_CV_ACT_DISTANCE_TRANSFORM, - IMG_CV_ACT_THRESHOLD, - IMG_CV_ACT_HISTOGRAM, - IMG_CV_ACT_HISTOGRAM_C3, - IMG_CV_ACT_CONTOURS, - IMG_CV_ACT_CONTOURS_SIZE, - IMG_CV_ACT_BOUNDING_RECT, - IMG_CV_ACT_FIT_ELLIPSE, - IMG_CV_ACT_MIN_AREA_RECT, - IMG_CV_ACT_HOUGH_CIRCLES - }; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void img_cv_act (class cv::Mat *imgptr, int action, void *data); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_cv.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_IMG_CV_H + # define VA_IMG_CV_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* packages ------------------------------------------------------------------*/ + #include + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Img_Cv_Action { + IMG_CV_ACT_FOO = 0x000000u, + + IMG_CV_ACT_CV = 0x000100u, + IMG_CV_ACT_PIXEL_GET, + IMG_CV_ACT_PIXEL_SET, + IMG_CV_ACT_SET_ROI, + IMG_CV_ACT_AND_2REF, + IMG_CV_ACT_NOT, + IMG_CV_ACT_OR_2REF, + IMG_CV_ACT_COMPONENT, + IMG_CV_ACT_DILATE, + IMG_CV_ACT_ERODE, + IMG_CV_ACT_SMOOTH, + IMG_CV_ACT_SOBEL, + IMG_CV_ACT_BORDER, + IMG_CV_ACT_MIRROR, + IMG_CV_ACT_ROTATE_ORTO, + IMG_CV_ACT_ROTATE, + IMG_CV_ACT_ADAPTIVE_THRESHOLD, + IMG_CV_ACT_CVT_COLOR, + IMG_CV_ACT_DISTANCE_TRANSFORM, + IMG_CV_ACT_THRESHOLD, + IMG_CV_ACT_HISTOGRAM, + IMG_CV_ACT_HISTOGRAM_C3, + IMG_CV_ACT_CONTOURS, + IMG_CV_ACT_CONTOURS_SIZE, + IMG_CV_ACT_BOUNDING_RECT, + IMG_CV_ACT_FIT_ELLIPSE, + IMG_CV_ACT_MIN_AREA_RECT, + IMG_CV_ACT_HOUGH_CIRCLES + }; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void img_cv_act (class cv::Mat *imgptr, int action, void *data); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* img_cv.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/inc/img_iface.h b/modules/image/inc/img_iface.h index bfdbb70..460db47 100644 --- a/modules/image/inc/img_iface.h +++ b/modules/image/inc/img_iface.h @@ -1,187 +1,187 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_IFACE_H - # define VA_IMG_IFACE_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ -/* Constants -----------------------------------------------------------------*/ - # define CONTOURS_MAX (65536) - # define OCR_TEXT_MAX (1048576) - # define ZB_CODES_MAX (10) - # define ZBAR_LEN_MAX (1048576) - - # define IMG_IFACE_THR_OTSU (-1) - -/* Functions -----------------------------------------------------------------*/ - # define img_iface_act_nodata(x) \ - do { \ - img_iface_act(x, NULL); \ - } while (0) - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_Iface_Action { - IMG_IFACE_ACT_FOO = 0x000000u, - - IMG_IFACE_ACT_ALX = 0x000010u, - IMG_IFACE_ACT_LOCAL_MAX, - IMG_IFACE_ACT_SKELETON, - IMG_IFACE_ACT_LINES_HORIZONTAL, - IMG_IFACE_ACT_LINES_VERTICAL, - IMG_IFACE_ACT_MEAN_HORIZONTAL, - IMG_IFACE_ACT_MEAN_VERTICAL, - IMG_IFACE_ACT_MEDIAN_HORIZONTAL, - IMG_IFACE_ACT_MEDIAN_VERTICAL, - - IMG_IFACE_ACT_CV = 0x000100u, - IMG_IFACE_ACT_PIXEL_GET, - IMG_IFACE_ACT_PIXEL_SET, - IMG_IFACE_ACT_SET_ROI, - IMG_IFACE_ACT_SET_ROI_2RECT, - IMG_IFACE_ACT_AND_2REF, - IMG_IFACE_ACT_NOT, - IMG_IFACE_ACT_OR_2REF, - IMG_IFACE_ACT_COMPONENT, - IMG_IFACE_ACT_DILATE, - IMG_IFACE_ACT_ERODE, - IMG_IFACE_ACT_DILATE_ERODE, - IMG_IFACE_ACT_ERODE_DILATE, - IMG_IFACE_ACT_SMOOTH, - IMG_IFACE_ACT_SOBEL, - IMG_IFACE_ACT_BORDER, - IMG_IFACE_ACT_MIRROR, - IMG_IFACE_ACT_ROTATE_ORTO, - IMG_IFACE_ACT_ROTATE, - IMG_IFACE_ACT_ROTATE_2RECT, - IMG_IFACE_ACT_ADAPTIVE_THRESHOLD, - IMG_IFACE_ACT_CVT_COLOR, - IMG_IFACE_ACT_DISTANCE_TRANSFORM, - IMG_IFACE_ACT_THRESHOLD, - IMG_IFACE_ACT_HISTOGRAM, - IMG_IFACE_ACT_HISTOGRAM_C3, - IMG_IFACE_ACT_CONTOURS, - IMG_IFACE_ACT_CONTOURS_SIZE, - IMG_IFACE_ACT_BOUNDING_RECT, - IMG_IFACE_ACT_FIT_ELLIPSE, - IMG_IFACE_ACT_MIN_AREA_RECT, - IMG_IFACE_ACT_HOUGH_CIRCLES, - - IMG_IFACE_ACT_ORB = 0x000200u, - IMG_IFACE_ACT_ALIGN, - - IMG_IFACE_ACT_CALIB3D = 0x000400u, - IMG_IFACE_ACT_CALIBRATE, - IMG_IFACE_ACT_UNDISTORT, - - IMG_IFACE_ACT_ZB = 0x000800u, - IMG_IFACE_ACT_DECODE, - - IMG_IFACE_ACT_OCR = 0x001000u, - IMG_IFACE_ACT_READ, - - IMG_IFACE_ACT_IMGI = 0x002000u, - IMG_IFACE_ACT_APPLY, - IMG_IFACE_ACT_DISCARD, - IMG_IFACE_ACT_SAVE_MEM, - IMG_IFACE_ACT_LOAD_MEM, - IMG_IFACE_ACT_SAVE_REF, - - IMG_IFACE_ACT_SAVE = 0x004000u, - IMG_IFACE_ACT_SAVE_FILE, - IMG_IFACE_ACT_SAVE_UPDT - }; - - enum Img_Iface_Cmp_BGR { - IMG_IFACE_CMP_BLUE = 0, - IMG_IFACE_CMP_GREEN, - IMG_IFACE_CMP_RED - }; - - enum Img_Iface_Cmp_HSV { - IMG_IFACE_CMP_HUE = 0, - IMG_IFACE_CMP_SATURATION, - IMG_IFACE_CMP_VALUE - }; - - enum ImgI_Smooth { - IMGI_SMOOTH_MEAN = 0, - IMGI_SMOOTH_GAUSS, - IMGI_SMOOTH_MEDIAN - }; - - enum Img_Iface_OCR_Lang { - IMG_IFACE_OCR_LANG_ENG = 0, - IMG_IFACE_OCR_LANG_SPA, - IMG_IFACE_OCR_LANG_CAT, - IMG_IFACE_OCR_LANG_DIGITS, - IMG_IFACE_OCR_LANG_DIGITS_COMMA - }; - - enum Img_Iface_OCR_Conf { - IMG_IFACE_OCR_CONF_NONE = 0, - IMG_IFACE_OCR_CONF_PRICE - }; - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ - struct Img_Iface_Data_Read { - int lang; - int conf; - struct { - void *data; - int width; - int height; - int B_per_pix; - int B_per_line; - } img; - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - extern char img_ocr_text [OCR_TEXT_MAX]; - extern struct Img_Iface_ZB_Codes zb_codes; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void img_iface_cleanup_main (void); - void img_iface_load (const char *fpath, const char *fname); - void img_iface_cleanup (void); - void img_iface_act (int action, void *data); - void img_iface_show_img (void); - void img_iface_show_hist_c1 (void); - void img_iface_show_hist_c3 (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_iface.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_IMG_IFACE_H + # define VA_IMG_IFACE_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + #include + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +/* Constants -----------------------------------------------------------------*/ + # define CONTOURS_MAX (65536) + # define OCR_TEXT_MAX (1048576) + # define ZB_CODES_MAX (10) + # define ZBAR_LEN_MAX (1048576) + + # define IMG_IFACE_THR_OTSU (-1) + +/* Functions -----------------------------------------------------------------*/ + # define img_iface_act_nodata(x) \ + do { \ + img_iface_act(x, NULL); \ + } while (0) + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Img_Iface_Action { + IMG_IFACE_ACT_FOO = 0x000000u, + + IMG_IFACE_ACT_ALX = 0x000010u, + IMG_IFACE_ACT_LOCAL_MAX, + IMG_IFACE_ACT_SKELETON, + IMG_IFACE_ACT_LINES_HORIZONTAL, + IMG_IFACE_ACT_LINES_VERTICAL, + IMG_IFACE_ACT_MEAN_HORIZONTAL, + IMG_IFACE_ACT_MEAN_VERTICAL, + IMG_IFACE_ACT_MEDIAN_HORIZONTAL, + IMG_IFACE_ACT_MEDIAN_VERTICAL, + + IMG_IFACE_ACT_CV = 0x000100u, + IMG_IFACE_ACT_PIXEL_GET, + IMG_IFACE_ACT_PIXEL_SET, + IMG_IFACE_ACT_SET_ROI, + IMG_IFACE_ACT_SET_ROI_2RECT, + IMG_IFACE_ACT_AND_2REF, + IMG_IFACE_ACT_NOT, + IMG_IFACE_ACT_OR_2REF, + IMG_IFACE_ACT_COMPONENT, + IMG_IFACE_ACT_DILATE, + IMG_IFACE_ACT_ERODE, + IMG_IFACE_ACT_DILATE_ERODE, + IMG_IFACE_ACT_ERODE_DILATE, + IMG_IFACE_ACT_SMOOTH, + IMG_IFACE_ACT_SOBEL, + IMG_IFACE_ACT_BORDER, + IMG_IFACE_ACT_MIRROR, + IMG_IFACE_ACT_ROTATE_ORTO, + IMG_IFACE_ACT_ROTATE, + IMG_IFACE_ACT_ROTATE_2RECT, + IMG_IFACE_ACT_ADAPTIVE_THRESHOLD, + IMG_IFACE_ACT_CVT_COLOR, + IMG_IFACE_ACT_DISTANCE_TRANSFORM, + IMG_IFACE_ACT_THRESHOLD, + IMG_IFACE_ACT_HISTOGRAM, + IMG_IFACE_ACT_HISTOGRAM_C3, + IMG_IFACE_ACT_CONTOURS, + IMG_IFACE_ACT_CONTOURS_SIZE, + IMG_IFACE_ACT_BOUNDING_RECT, + IMG_IFACE_ACT_FIT_ELLIPSE, + IMG_IFACE_ACT_MIN_AREA_RECT, + IMG_IFACE_ACT_HOUGH_CIRCLES, + + IMG_IFACE_ACT_ORB = 0x000200u, + IMG_IFACE_ACT_ALIGN, + + IMG_IFACE_ACT_CALIB3D = 0x000400u, + IMG_IFACE_ACT_CALIBRATE, + IMG_IFACE_ACT_UNDISTORT, + + IMG_IFACE_ACT_ZB = 0x000800u, + IMG_IFACE_ACT_DECODE, + + IMG_IFACE_ACT_OCR = 0x001000u, + IMG_IFACE_ACT_READ, + + IMG_IFACE_ACT_IMGI = 0x002000u, + IMG_IFACE_ACT_APPLY, + IMG_IFACE_ACT_DISCARD, + IMG_IFACE_ACT_SAVE_MEM, + IMG_IFACE_ACT_LOAD_MEM, + IMG_IFACE_ACT_SAVE_REF, + + IMG_IFACE_ACT_SAVE = 0x004000u, + IMG_IFACE_ACT_SAVE_FILE, + IMG_IFACE_ACT_SAVE_UPDT + }; + + enum Img_Iface_Cmp_BGR { + IMG_IFACE_CMP_BLUE = 0, + IMG_IFACE_CMP_GREEN, + IMG_IFACE_CMP_RED + }; + + enum Img_Iface_Cmp_HSV { + IMG_IFACE_CMP_HUE = 0, + IMG_IFACE_CMP_SATURATION, + IMG_IFACE_CMP_VALUE + }; + + enum ImgI_Smooth { + IMGI_SMOOTH_MEAN = 0, + IMGI_SMOOTH_GAUSS, + IMGI_SMOOTH_MEDIAN + }; + + enum Img_Iface_OCR_Lang { + IMG_IFACE_OCR_LANG_ENG = 0, + IMG_IFACE_OCR_LANG_SPA, + IMG_IFACE_OCR_LANG_CAT, + IMG_IFACE_OCR_LANG_DIGITS, + IMG_IFACE_OCR_LANG_DIGITS_COMMA + }; + + enum Img_Iface_OCR_Conf { + IMG_IFACE_OCR_CONF_NONE = 0, + IMG_IFACE_OCR_CONF_PRICE + }; + + +/****************************************************************************** + ******* structs ************************************************************** + ******************************************************************************/ + struct Img_Iface_Data_Read { + int lang; + int conf; + struct { + void *data; + int width; + int height; + int B_per_pix; + int B_per_line; + } img; + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern char img_ocr_text [OCR_TEXT_MAX]; + extern struct Img_Iface_ZB_Codes zb_codes; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void img_iface_cleanup_main (void); + void img_iface_load (const char *fpath, const char *fname); + void img_iface_cleanup (void); + void img_iface_act (int action, void *data); + void img_iface_show_img (void); + void img_iface_show_hist_c1 (void); + void img_iface_show_hist_c3 (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* img_iface.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/inc/img_iface.hpp b/modules/image/inc/img_iface.hpp index c492537..6448578 100644 --- a/modules/image/inc/img_iface.hpp +++ b/modules/image/inc/img_iface.hpp @@ -1,343 +1,343 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_IFACE_HPP - # define VA_IMG_IFACE_HPP - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include - -/* Standard C++ --------------------------------------------------------------*/ - /* class std::vector */ - #include - -/* Packages ------------------------------------------------------------------*/ - /* opencv */ - #include - /* zbar */ - #include - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define CONTOURS_MAX (65536) - # define OCR_TEXT_MAX (1048576) - # define ZB_CODES_MAX (10) - # define ZBAR_LEN_MAX (1048576) - - # define IMG_IFACE_THR_OTSU (-1) - -/* Functions -----------------------------------------------------------------*/ - # define img_iface_act_nodata(x) \ - do { \ - img_iface_act(x, NULL); \ - } while (0) - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_Iface_Action { - IMG_IFACE_ACT_FOO = 0x000000u, - - IMG_IFACE_ACT_ALX = 0x000010u, - IMG_IFACE_ACT_LOCAL_MAX, - IMG_IFACE_ACT_SKELETON, - IMG_IFACE_ACT_LINES_HORIZONTAL, - IMG_IFACE_ACT_LINES_VERTICAL, - IMG_IFACE_ACT_MEAN_HORIZONTAL, - IMG_IFACE_ACT_MEAN_VERTICAL, - IMG_IFACE_ACT_MEDIAN_HORIZONTAL, - IMG_IFACE_ACT_MEDIAN_VERTICAL, - - IMG_IFACE_ACT_CV = 0x000100u, - IMG_IFACE_ACT_PIXEL_GET, - IMG_IFACE_ACT_PIXEL_SET, - IMG_IFACE_ACT_SET_ROI, - IMG_IFACE_ACT_SET_ROI_2RECT, - IMG_IFACE_ACT_AND_2REF, - IMG_IFACE_ACT_NOT, - IMG_IFACE_ACT_OR_2REF, - IMG_IFACE_ACT_COMPONENT, - IMG_IFACE_ACT_DILATE, - IMG_IFACE_ACT_ERODE, - IMG_IFACE_ACT_DILATE_ERODE, - IMG_IFACE_ACT_ERODE_DILATE, - IMG_IFACE_ACT_SMOOTH, - IMG_IFACE_ACT_SOBEL, - IMG_IFACE_ACT_BORDER, - IMG_IFACE_ACT_MIRROR, - IMG_IFACE_ACT_ROTATE_ORTO, - IMG_IFACE_ACT_ROTATE, - IMG_IFACE_ACT_ROTATE_2RECT, - IMG_IFACE_ACT_ADAPTIVE_THRESHOLD, - IMG_IFACE_ACT_CVT_COLOR, - IMG_IFACE_ACT_DISTANCE_TRANSFORM, - IMG_IFACE_ACT_THRESHOLD, - IMG_IFACE_ACT_HISTOGRAM, - IMG_IFACE_ACT_HISTOGRAM_C3, - IMG_IFACE_ACT_CONTOURS, - IMG_IFACE_ACT_CONTOURS_SIZE, - IMG_IFACE_ACT_BOUNDING_RECT, - IMG_IFACE_ACT_FIT_ELLIPSE, - IMG_IFACE_ACT_MIN_AREA_RECT, - IMG_IFACE_ACT_HOUGH_CIRCLES, - - IMG_IFACE_ACT_ORB = 0x000200u, - IMG_IFACE_ACT_ALIGN, - - IMG_IFACE_ACT_CALIB3D = 0x000400u, - IMG_IFACE_ACT_CALIBRATE, - IMG_IFACE_ACT_UNDISTORT, - - IMG_IFACE_ACT_ZB = 0x000800u, - IMG_IFACE_ACT_DECODE, - - IMG_IFACE_ACT_OCR = 0x001000u, - IMG_IFACE_ACT_READ, - - IMG_IFACE_ACT_IMGI = 0x002000u, - IMG_IFACE_ACT_APPLY, - IMG_IFACE_ACT_DISCARD, - IMG_IFACE_ACT_SAVE_MEM, - IMG_IFACE_ACT_LOAD_MEM, - IMG_IFACE_ACT_SAVE_REF, - - IMG_IFACE_ACT_SAVE = 0x004000u, - IMG_IFACE_ACT_SAVE_FILE, - IMG_IFACE_ACT_SAVE_UPDT - }; - - enum Img_Iface_Cmp { - IMG_IFACE_CMP_BLUE = 0, - IMG_IFACE_CMP_GREEN, - IMG_IFACE_CMP_RED - }; - - enum Img_Iface_Cmp_HSV { - IMG_IFACE_CMP_HUE = 0, - IMG_IFACE_CMP_SATURATION, - IMG_IFACE_CMP_VALUE - }; - - enum ImgI_Smooth { - IMGI_SMOOTH_MEAN = 1, - IMGI_SMOOTH_GAUSS, - IMGI_SMOOTH_MEDIAN - }; - - enum Img_Iface_OCR_Lang { - IMG_IFACE_OCR_LANG_ENG = 0, - IMG_IFACE_OCR_LANG_SPA, - IMG_IFACE_OCR_LANG_CAT, - IMG_IFACE_OCR_LANG_DIGITS, - IMG_IFACE_OCR_LANG_DIGITS_COMMA - }; - - enum Img_Iface_OCR_Conf { - IMG_IFACE_OCR_CONF_NONE = 0, - IMG_IFACE_OCR_CONF_PRICE - }; - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ -/* img_cv --------------------------------------------------------------------*/ - struct Img_Iface_Data_Pixel_Get { - unsigned char *val; - int x; - int y; - }; - - struct Img_Iface_Data_Pixel_Set { - unsigned char val; - int x; - int y; - }; - - struct Img_Iface_Data_SetROI { - class cv::Rect_ rect; - }; - - struct Img_Iface_Data_Component { - int cmp; - }; - - struct Img_Iface_Data_Dilate_Erode { - int i; - }; - - struct Img_Iface_Data_Smooth { - int method; - int ksize; - }; - - struct Img_Iface_Data_Sobel { - int dx; - int dy; - int ksize; - }; - - struct Img_Iface_Data_Border { - int size; - }; - - struct Img_Iface_Data_Mirror { - int axis; - }; - - struct Img_Iface_Data_Rotate_Orto { - int n; - }; - - struct Img_Iface_Data_Rotate { - class cv::Point_ center; - double angle; - }; - - struct Img_Iface_Data_Adaptive_Thr { - int method; - int thr_typ; - int ksize; - }; - - struct Img_Iface_Data_Cvt_Color { - int method; - }; - - struct Img_Iface_Data_Threshold { - int thr_typ; - int thr_val; - }; - - struct Img_Iface_Data_Histogram { - class cv::Mat *hist_c0; - class cv::Mat *hist_c1; - class cv::Mat *hist_c2; - class cv::Mat *hist_img; - }; - - struct Img_Iface_Data_Contours { - class std::vector >> *contours; - class cv::Mat *hierarchy; - }; - - struct Img_Iface_Data_Contours_Size { - class std::vector >> *contours; - double *area; - double *perimeter; - }; - - struct Img_Iface_Data_Bounding_Rect { - class std::vector > *contour; - class cv::Rect_ *rect; - bool show; - }; - - struct Img_Iface_Data_MinARect { - class std::vector > *contour; - class cv::RotatedRect *rect; - bool show; - }; - - struct Img_Iface_Data_Hough_Circles { - class std::vector > *circles; - double dist_min; - double param_1; - double param_2; - int radius_min; - int radius_max; - }; - -/* img_calib3d ---------------------------------------------------------------*/ - struct Img_Iface_Data_Calibrate { - class cv::Mat *intrinsic_mat; - class cv::Mat *dist_coefs; - class std::vector *rvecs; - class std::vector *tvecs; - }; - - struct Img_Iface_Data_Undistort { - class cv::Mat *intrinsic_mat; - class cv::Mat *dist_coefs; - }; - -/* img_zbar -------------------------------------------------------------------*/ - struct Img_Iface_Data_Decode { - enum zbar::zbar_symbol_type_e code_type; - }; - - struct Img_Iface_ZB_Codes { - int n; - struct { - enum zbar::zbar_symbol_type_e type; - char sym_name [80]; - char data [ZBAR_LEN_MAX]; - } arr [ZB_CODES_MAX]; - }; - -/* img_ocr -------------------------------------------------------------------*/ - struct Img_Iface_Data_Read { - int lang; - int conf; - struct { - void *data; - int width; - int height; - int B_per_pix; - int B_per_line; - } img; - }; - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - extern char img_ocr_text [OCR_TEXT_MAX]; - extern struct Img_Iface_ZB_Codes zb_codes; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void img_iface_cleanup_main (void); - void img_iface_load (const char *fpath, const char *fname); - void img_iface_cleanup (void); - void img_iface_act (int action, void *data); - void img_iface_show_img (void); - void img_iface_show_hist_c1 (void); - void img_iface_show_hist_c3 (void); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_iface.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_IMG_IFACE_HPP + # define VA_IMG_IFACE_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + #include + +/* Standard C++ --------------------------------------------------------------*/ + /* class std::vector */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* opencv */ + #include + /* zbar */ + #include + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define CONTOURS_MAX (65536) + # define OCR_TEXT_MAX (1048576) + # define ZB_CODES_MAX (10) + # define ZBAR_LEN_MAX (1048576) + + # define IMG_IFACE_THR_OTSU (-1) + +/* Functions -----------------------------------------------------------------*/ + # define img_iface_act_nodata(x) \ + do { \ + img_iface_act(x, NULL); \ + } while (0) + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Img_Iface_Action { + IMG_IFACE_ACT_FOO = 0x000000u, + + IMG_IFACE_ACT_ALX = 0x000010u, + IMG_IFACE_ACT_LOCAL_MAX, + IMG_IFACE_ACT_SKELETON, + IMG_IFACE_ACT_LINES_HORIZONTAL, + IMG_IFACE_ACT_LINES_VERTICAL, + IMG_IFACE_ACT_MEAN_HORIZONTAL, + IMG_IFACE_ACT_MEAN_VERTICAL, + IMG_IFACE_ACT_MEDIAN_HORIZONTAL, + IMG_IFACE_ACT_MEDIAN_VERTICAL, + + IMG_IFACE_ACT_CV = 0x000100u, + IMG_IFACE_ACT_PIXEL_GET, + IMG_IFACE_ACT_PIXEL_SET, + IMG_IFACE_ACT_SET_ROI, + IMG_IFACE_ACT_SET_ROI_2RECT, + IMG_IFACE_ACT_AND_2REF, + IMG_IFACE_ACT_NOT, + IMG_IFACE_ACT_OR_2REF, + IMG_IFACE_ACT_COMPONENT, + IMG_IFACE_ACT_DILATE, + IMG_IFACE_ACT_ERODE, + IMG_IFACE_ACT_DILATE_ERODE, + IMG_IFACE_ACT_ERODE_DILATE, + IMG_IFACE_ACT_SMOOTH, + IMG_IFACE_ACT_SOBEL, + IMG_IFACE_ACT_BORDER, + IMG_IFACE_ACT_MIRROR, + IMG_IFACE_ACT_ROTATE_ORTO, + IMG_IFACE_ACT_ROTATE, + IMG_IFACE_ACT_ROTATE_2RECT, + IMG_IFACE_ACT_ADAPTIVE_THRESHOLD, + IMG_IFACE_ACT_CVT_COLOR, + IMG_IFACE_ACT_DISTANCE_TRANSFORM, + IMG_IFACE_ACT_THRESHOLD, + IMG_IFACE_ACT_HISTOGRAM, + IMG_IFACE_ACT_HISTOGRAM_C3, + IMG_IFACE_ACT_CONTOURS, + IMG_IFACE_ACT_CONTOURS_SIZE, + IMG_IFACE_ACT_BOUNDING_RECT, + IMG_IFACE_ACT_FIT_ELLIPSE, + IMG_IFACE_ACT_MIN_AREA_RECT, + IMG_IFACE_ACT_HOUGH_CIRCLES, + + IMG_IFACE_ACT_ORB = 0x000200u, + IMG_IFACE_ACT_ALIGN, + + IMG_IFACE_ACT_CALIB3D = 0x000400u, + IMG_IFACE_ACT_CALIBRATE, + IMG_IFACE_ACT_UNDISTORT, + + IMG_IFACE_ACT_ZB = 0x000800u, + IMG_IFACE_ACT_DECODE, + + IMG_IFACE_ACT_OCR = 0x001000u, + IMG_IFACE_ACT_READ, + + IMG_IFACE_ACT_IMGI = 0x002000u, + IMG_IFACE_ACT_APPLY, + IMG_IFACE_ACT_DISCARD, + IMG_IFACE_ACT_SAVE_MEM, + IMG_IFACE_ACT_LOAD_MEM, + IMG_IFACE_ACT_SAVE_REF, + + IMG_IFACE_ACT_SAVE = 0x004000u, + IMG_IFACE_ACT_SAVE_FILE, + IMG_IFACE_ACT_SAVE_UPDT + }; + + enum Img_Iface_Cmp { + IMG_IFACE_CMP_BLUE = 0, + IMG_IFACE_CMP_GREEN, + IMG_IFACE_CMP_RED + }; + + enum Img_Iface_Cmp_HSV { + IMG_IFACE_CMP_HUE = 0, + IMG_IFACE_CMP_SATURATION, + IMG_IFACE_CMP_VALUE + }; + + enum ImgI_Smooth { + IMGI_SMOOTH_MEAN = 1, + IMGI_SMOOTH_GAUSS, + IMGI_SMOOTH_MEDIAN + }; + + enum Img_Iface_OCR_Lang { + IMG_IFACE_OCR_LANG_ENG = 0, + IMG_IFACE_OCR_LANG_SPA, + IMG_IFACE_OCR_LANG_CAT, + IMG_IFACE_OCR_LANG_DIGITS, + IMG_IFACE_OCR_LANG_DIGITS_COMMA + }; + + enum Img_Iface_OCR_Conf { + IMG_IFACE_OCR_CONF_NONE = 0, + IMG_IFACE_OCR_CONF_PRICE + }; + + +/****************************************************************************** + ******* structs ************************************************************** + ******************************************************************************/ +/* img_cv --------------------------------------------------------------------*/ + struct Img_Iface_Data_Pixel_Get { + unsigned char *val; + int x; + int y; + }; + + struct Img_Iface_Data_Pixel_Set { + unsigned char val; + int x; + int y; + }; + + struct Img_Iface_Data_SetROI { + class cv::Rect_ rect; + }; + + struct Img_Iface_Data_Component { + int cmp; + }; + + struct Img_Iface_Data_Dilate_Erode { + int i; + }; + + struct Img_Iface_Data_Smooth { + int method; + int ksize; + }; + + struct Img_Iface_Data_Sobel { + int dx; + int dy; + int ksize; + }; + + struct Img_Iface_Data_Border { + int size; + }; + + struct Img_Iface_Data_Mirror { + int axis; + }; + + struct Img_Iface_Data_Rotate_Orto { + int n; + }; + + struct Img_Iface_Data_Rotate { + class cv::Point_ center; + double angle; + }; + + struct Img_Iface_Data_Adaptive_Thr { + int method; + int thr_typ; + int ksize; + }; + + struct Img_Iface_Data_Cvt_Color { + int method; + }; + + struct Img_Iface_Data_Threshold { + int thr_typ; + int thr_val; + }; + + struct Img_Iface_Data_Histogram { + class cv::Mat *hist_c0; + class cv::Mat *hist_c1; + class cv::Mat *hist_c2; + class cv::Mat *hist_img; + }; + + struct Img_Iface_Data_Contours { + class std::vector >> *contours; + class cv::Mat *hierarchy; + }; + + struct Img_Iface_Data_Contours_Size { + class std::vector >> *contours; + double *area; + double *perimeter; + }; + + struct Img_Iface_Data_Bounding_Rect { + class std::vector > *contour; + class cv::Rect_ *rect; + bool show; + }; + + struct Img_Iface_Data_MinARect { + class std::vector > *contour; + class cv::RotatedRect *rect; + bool show; + }; + + struct Img_Iface_Data_Hough_Circles { + class std::vector > *circles; + double dist_min; + double param_1; + double param_2; + int radius_min; + int radius_max; + }; + +/* img_calib3d ---------------------------------------------------------------*/ + struct Img_Iface_Data_Calibrate { + class cv::Mat *intrinsic_mat; + class cv::Mat *dist_coefs; + class std::vector *rvecs; + class std::vector *tvecs; + }; + + struct Img_Iface_Data_Undistort { + class cv::Mat *intrinsic_mat; + class cv::Mat *dist_coefs; + }; + +/* img_zbar -------------------------------------------------------------------*/ + struct Img_Iface_Data_Decode { + enum zbar::zbar_symbol_type_e code_type; + }; + + struct Img_Iface_ZB_Codes { + int n; + struct { + enum zbar::zbar_symbol_type_e type; + char sym_name [80]; + char data [ZBAR_LEN_MAX]; + } arr [ZB_CODES_MAX]; + }; + +/* img_ocr -------------------------------------------------------------------*/ + struct Img_Iface_Data_Read { + int lang; + int conf; + struct { + void *data; + int width; + int height; + int B_per_pix; + int B_per_line; + } img; + }; + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern char img_ocr_text [OCR_TEXT_MAX]; + extern struct Img_Iface_ZB_Codes zb_codes; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void img_iface_cleanup_main (void); + void img_iface_load (const char *fpath, const char *fname); + void img_iface_cleanup (void); + void img_iface_act (int action, void *data); + void img_iface_show_img (void); + void img_iface_show_hist_c1 (void); + void img_iface_show_hist_c3 (void); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* img_iface.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/inc/img_ocr.h b/modules/image/inc/img_ocr.h index f2e8742..62d248a 100644 --- a/modules/image/inc/img_ocr.h +++ b/modules/image/inc/img_ocr.h @@ -1,38 +1,38 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_OCR_H - # define VA_IMG_OCR_H - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_OCR_Action { - IMG_OCR_ACT_FOO = 0x000000u, - - IMG_OCR_ACT_OCR = 0x001000u, - IMG_OCR_ACT_READ - }; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void img_ocr_act (int action, void *data); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_ocr.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_IMG_OCR_H + # define VA_IMG_OCR_H + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Img_OCR_Action { + IMG_OCR_ACT_FOO = 0x000000u, + + IMG_OCR_ACT_OCR = 0x001000u, + IMG_OCR_ACT_READ + }; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void img_ocr_act (int action, void *data); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* img_ocr.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/inc/img_ocr.hpp b/modules/image/inc/img_ocr.hpp index 446f986..355a124 100644 --- a/modules/image/inc/img_ocr.hpp +++ b/modules/image/inc/img_ocr.hpp @@ -1,50 +1,50 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_OCR_HPP - # define VA_IMG_OCR_HPP - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_OCR_Action { - IMG_OCR_ACT_FOO = 0x000000u, - - IMG_OCR_ACT_OCR = 0x001000u, - IMG_OCR_ACT_READ - }; - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void img_ocr_act (int action, void *data); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_ocr.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_IMG_OCR_HPP + # define VA_IMG_OCR_HPP + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Img_OCR_Action { + IMG_OCR_ACT_FOO = 0x000000u, + + IMG_OCR_ACT_OCR = 0x001000u, + IMG_OCR_ACT_READ + }; + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void img_ocr_act (int action, void *data); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* img_ocr.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/inc/img_orb.hpp b/modules/image/inc/img_orb.hpp index b29fefa..ce5a914 100644 --- a/modules/image/inc/img_orb.hpp +++ b/modules/image/inc/img_orb.hpp @@ -1,46 +1,46 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_ORB_HPP - # define VA_IMG_ORB_HPP - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - /* openCV */ - #include - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_ORB_Action { - IMG_ORB_ACT_FOO = 0x000000u, - - IMG_ORB_ACT_ORB = 0x000200u, - IMG_ORB_ACT_ALIGN - }; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void img_orb_act (class cv::Mat *pattern, - class cv::Mat *imgptr, int action); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_orb.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_IMG_ORB_HPP + # define VA_IMG_ORB_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + /* openCV */ + #include + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Img_ORB_Action { + IMG_ORB_ACT_FOO = 0x000000u, + + IMG_ORB_ACT_ORB = 0x000200u, + IMG_ORB_ACT_ALIGN + }; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void img_orb_act (class cv::Mat *pattern, + class cv::Mat *imgptr, int action); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* img_orb.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/inc/img_zbar.hpp b/modules/image/inc/img_zbar.hpp index 2019ae3..72f1020 100644 --- a/modules/image/inc/img_zbar.hpp +++ b/modules/image/inc/img_zbar.hpp @@ -1,46 +1,46 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_ZBAR_H - # define VA_IMG_ZBAR_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Packages ------------------------------------------------------------------*/ - /* openCV */ - #include - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_ZB_Action { - IMG_ZB_ACT_FOO = 0x000000u, - - IMG_ZB_ACT_ZB = 0x000800u, - IMG_ZB_ACT_DECODE - }; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void img_zb_act (class cv::Mat *imgptr, int action, void *data); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_zbar.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_IMG_ZBAR_H + # define VA_IMG_ZBAR_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Packages ------------------------------------------------------------------*/ + /* openCV */ + #include + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Img_ZB_Action { + IMG_ZB_ACT_FOO = 0x000000u, + + IMG_ZB_ACT_ZB = 0x000800u, + IMG_ZB_ACT_DECODE + }; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void img_zb_act (class cv::Mat *imgptr, int action, void *data); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* img_zbar.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/src/img_alx.cpp b/modules/image/src/img_alx.cpp index 093ff69..8a65084 100644 --- a/modules/image/src/img_alx.cpp +++ b/modules/image/src/img_alx.cpp @@ -1,380 +1,380 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: (GPL-2.0-only OR LGPL-3.0-only) * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* true & false */ - #include - /* abs() */ - #include - /* snprintf() */ - #include - -/* Packages ------------------------------------------------------------------*/ - /* opencv */ - #include - -/* libalx --------------------------------------------------------------------*/ - /* alx_median_u8() */ - #include "alx_math.hpp" - -/* Module --------------------------------------------------------------------*/ - /* data */ - #include "img_iface.hpp" - - #include "img_alx.hpp" - - -/****************************************************************************** - ******* static functions (prototypes) **************************************** - ******************************************************************************/ -static void img_alx_local_max (class cv::Mat *imgptr); -static void img_alx_skeleton (class cv::Mat *imgptr); -static void img_alx_lines_horizontal (class cv::Mat *imgptr); -static void img_alx_lines_vertical (class cv::Mat *imgptr); -static void img_alx_mean_horizontal (class cv::Mat *imgptr); -static void img_alx_mean_vertical (class cv::Mat *imgptr); -static void img_alx_median_horizontal (class cv::Mat *imgptr); -static void img_alx_median_vertical (class cv::Mat *imgptr); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -void img_alx_act (class cv::Mat *imgptr, int action, void *data) -{ - - switch (action) { - case IMG_ALX_ACT_LOCAL_MAX: - img_alx_local_max(imgptr); - break; - case IMG_ALX_ACT_SKELETON: - img_alx_skeleton(imgptr); - break; - - case IMG_ALX_ACT_LINES_HORIZONTAL: - img_alx_lines_horizontal(imgptr); - break; - case IMG_ALX_ACT_LINES_VERTICAL: - img_alx_lines_vertical(imgptr); - break; - - case IMG_ALX_ACT_MEAN_HORIZONTAL: - img_alx_mean_horizontal(imgptr); - break; - case IMG_ALX_ACT_MEAN_VERTICAL: - img_alx_mean_vertical(imgptr); - break; - case IMG_ALX_ACT_MEDIAN_HORIZONTAL: - img_alx_median_horizontal(imgptr); - break; - case IMG_ALX_ACT_MEDIAN_VERTICAL: - img_alx_median_vertical(imgptr); - break; - } -} - - -/****************************************************************************** - ******* static functions (definitions) *************************************** - ******************************************************************************/ -static void img_alx_local_max (class cv::Mat *imgptr) -{ - int i; - int j; - int k; - int l; - /* Minimum distance between local maxima */ - const int dist_min = 16; - /* Minimum value of local maxima */ - const int val_min = 16; - class cv::Mat imgtmp; - - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - /* pointer to a pixel near img_pix (in imgptr) */ - uint8_t *near_pix; - /* pointer to a pixel (same position as img_pix, but in imgtmp) */ - uint8_t *tmp_pix; - - /* Tmp image copy */ - imgptr->copyTo(imgtmp); - - for (i = 0; i < imgptr->rows; i++) { - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - tmp_pix = imgtmp.data + i * imgptr->step + j; - *tmp_pix = 0; - - if (*img_pix < val_min) { - goto next_pixel; - } - - for (k = (i - dist_min); k < (i + dist_min + 1); k++) { - for (l = (j - dist_min); l < (j + dist_min + 1); l++) { - near_pix = imgptr->data + k * imgptr->step + l; - if ((k >= 0) && (k < imgptr->rows)) { - if ((l >= 0) && (l < imgptr->cols)) { - if (*img_pix < *near_pix) { - goto next_pixel; - } - } - } - } - } - - *tmp_pix = *img_pix; - continue; - -next_pixel: - *tmp_pix = 0; - } - } - - /* Cleanup */ - imgtmp.copyTo(*imgptr); - imgtmp.release(); -} - -static void img_alx_skeleton (class cv::Mat *imgptr) -{ - /* (Half of the) width of the skeleton */ - const int width = 5; - int dist_x; - int dist_y; - bool skeleton; - int cnt_lo [width]; - int cnt_hi_or_eq [width]; - class cv::Mat imgtmp; - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - /* pointer to a pixel near img_pix (in imgptr) */ - uint8_t *near_pix; - /* pointer to a pixel (same position as img_pix, but in imgtmp) */ - uint8_t *tmp_pix; - - int i; - int j; - int k; - int l; - int r; - - /* Tmp image copy */ - imgptr->copyTo(imgtmp); - - for (i = 0; i < imgptr->rows; i++) { - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - tmp_pix = imgtmp.data + i * imgptr->step + j; - - if (!(*img_pix)) { - *tmp_pix = 0; - continue; - } - - for (r = 0; r < width; r++) { - cnt_lo[r] = 0; - cnt_hi_or_eq[r] = 0; - } - - for (k = i - width; k <= i + width; k++) { - for (l = j - width; l <= j + width; l++) { - near_pix = imgptr->data + k * imgptr->step + l; - - dist_x = abs(k - i); - dist_y = abs(l - j); - - if ((k >= 0) && (k < imgptr->rows)) { - if ((l >= 0) && (l < imgptr->cols)) { - if (dist_x || dist_y) { - if (*near_pix < *img_pix) { - cnt_lo[std::max(dist_x, dist_y)]++; - } else { - cnt_hi_or_eq[std::max(dist_x, dist_y)]++; - } - } - } - } - - } - } - - skeleton = false; - for (r = 0; r < width; r++) { - if (cnt_lo[r] > (cnt_hi_or_eq[r] + (1.6) * (r + 1))) { - skeleton = true; - } - } - - if (skeleton) { - *tmp_pix = *img_pix; - } else { - *tmp_pix = 0; - } - } - } - - /* Cleanup */ - imgtmp.copyTo(*imgptr); - imgtmp.release(); -} - -static void img_alx_lines_horizontal (class cv::Mat *imgptr) -{ - int i; - int j; - bool white; - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - - for (i = 0; i < imgptr->rows; i++) { - white = false; - - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - if (*img_pix) { - white = true; - break; - } - } - - if (white) { - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - *img_pix = 255; - } - } - } -} - -static void img_alx_lines_vertical (class cv::Mat *imgptr) -{ - int i; - int j; - bool white; - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - - for (i = 0; i < imgptr->cols; i++) { - white = false; - - for (j = 0; j < imgptr->rows; j++) { - img_pix = imgptr->data + j * imgptr->step + i; - if (*img_pix) { - white = true; - break; - } - } - - if (white) { - for (j = 0; j < imgptr->rows; j++) { - img_pix = imgptr->data + j * imgptr->step + i; - *img_pix = 255; - } - } - } -} - -static void img_alx_mean_horizontal (class cv::Mat *imgptr) -{ - int i; - int j; - uint32_t tmp; - uint8_t mean; - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - - for (i = 0; i < imgptr->rows; i++) { - tmp = 0; - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - tmp += *img_pix; - } - mean = tmp / imgptr->cols; - - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - *img_pix = mean; - } - } -} - -static void img_alx_mean_vertical (class cv::Mat *imgptr) -{ - int i; - int j; - uint32_t tmp; - uint8_t mean; - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - - for (i = 0; i < imgptr->cols; i++) { - tmp = 0; - for (j = 0; j < imgptr->rows; j++) { - img_pix = imgptr->data + j * imgptr->step + i; - tmp += *img_pix; - } - mean = tmp / imgptr->rows; - - for (j = 0; j < imgptr->rows; j++) { - img_pix = imgptr->data + j * imgptr->step + i; - *img_pix = mean; - } - } -} - -static void img_alx_median_horizontal (class cv::Mat *imgptr) -{ - int i; - int j; - uint8_t row [imgptr->cols]; - uint8_t median; - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - - for (i = 0; i < imgptr->rows; i++) { - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - row[j] = *img_pix; - } - median = alx_median_u8(imgptr->cols, row); - - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - *img_pix = median; - } - } -} - -static void img_alx_median_vertical (class cv::Mat *imgptr) -{ - int i; - int j; - uint8_t col [imgptr->rows]; - uint8_t median; - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - - for (i = 0; i < imgptr->cols; i++) { - for (j = 0; j < imgptr->rows; j++) { - img_pix = imgptr->data + j * imgptr->step + i; - col[j] = *img_pix; - } - median = alx_median_u8(imgptr->rows, col); - - for (j = 0; j < imgptr->rows; j++) { - img_pix = imgptr->data + j * imgptr->step + i; - *img_pix = median; - } - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: (GPL-2.0-only OR LGPL-3.0-only) * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* true & false */ + #include + /* abs() */ + #include + /* snprintf() */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* opencv */ + #include + +/* libalx --------------------------------------------------------------------*/ + /* alx_median_u8() */ + #include "alx_math.hpp" + +/* Module --------------------------------------------------------------------*/ + /* data */ + #include "img_iface.hpp" + + #include "img_alx.hpp" + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ +static void img_alx_local_max (class cv::Mat *imgptr); +static void img_alx_skeleton (class cv::Mat *imgptr); +static void img_alx_lines_horizontal (class cv::Mat *imgptr); +static void img_alx_lines_vertical (class cv::Mat *imgptr); +static void img_alx_mean_horizontal (class cv::Mat *imgptr); +static void img_alx_mean_vertical (class cv::Mat *imgptr); +static void img_alx_median_horizontal (class cv::Mat *imgptr); +static void img_alx_median_vertical (class cv::Mat *imgptr); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void img_alx_act (class cv::Mat *imgptr, int action, void *data) +{ + + switch (action) { + case IMG_ALX_ACT_LOCAL_MAX: + img_alx_local_max(imgptr); + break; + case IMG_ALX_ACT_SKELETON: + img_alx_skeleton(imgptr); + break; + + case IMG_ALX_ACT_LINES_HORIZONTAL: + img_alx_lines_horizontal(imgptr); + break; + case IMG_ALX_ACT_LINES_VERTICAL: + img_alx_lines_vertical(imgptr); + break; + + case IMG_ALX_ACT_MEAN_HORIZONTAL: + img_alx_mean_horizontal(imgptr); + break; + case IMG_ALX_ACT_MEAN_VERTICAL: + img_alx_mean_vertical(imgptr); + break; + case IMG_ALX_ACT_MEDIAN_HORIZONTAL: + img_alx_median_horizontal(imgptr); + break; + case IMG_ALX_ACT_MEDIAN_VERTICAL: + img_alx_median_vertical(imgptr); + break; + } +} + + +/****************************************************************************** + ******* static functions (definitions) *************************************** + ******************************************************************************/ +static void img_alx_local_max (class cv::Mat *imgptr) +{ + int i; + int j; + int k; + int l; + /* Minimum distance between local maxima */ + const int dist_min = 16; + /* Minimum value of local maxima */ + const int val_min = 16; + class cv::Mat imgtmp; + + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + /* pointer to a pixel near img_pix (in imgptr) */ + uint8_t *near_pix; + /* pointer to a pixel (same position as img_pix, but in imgtmp) */ + uint8_t *tmp_pix; + + /* Tmp image copy */ + imgptr->copyTo(imgtmp); + + for (i = 0; i < imgptr->rows; i++) { + for (j = 0; j < imgptr->cols; j++) { + img_pix = imgptr->data + i * imgptr->step + j; + tmp_pix = imgtmp.data + i * imgptr->step + j; + *tmp_pix = 0; + + if (*img_pix < val_min) { + goto next_pixel; + } + + for (k = (i - dist_min); k < (i + dist_min + 1); k++) { + for (l = (j - dist_min); l < (j + dist_min + 1); l++) { + near_pix = imgptr->data + k * imgptr->step + l; + if ((k >= 0) && (k < imgptr->rows)) { + if ((l >= 0) && (l < imgptr->cols)) { + if (*img_pix < *near_pix) { + goto next_pixel; + } + } + } + } + } + + *tmp_pix = *img_pix; + continue; + +next_pixel: + *tmp_pix = 0; + } + } + + /* Cleanup */ + imgtmp.copyTo(*imgptr); + imgtmp.release(); +} + +static void img_alx_skeleton (class cv::Mat *imgptr) +{ + /* (Half of the) width of the skeleton */ + const int width = 5; + int dist_x; + int dist_y; + bool skeleton; + int cnt_lo [width]; + int cnt_hi_or_eq [width]; + class cv::Mat imgtmp; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + /* pointer to a pixel near img_pix (in imgptr) */ + uint8_t *near_pix; + /* pointer to a pixel (same position as img_pix, but in imgtmp) */ + uint8_t *tmp_pix; + + int i; + int j; + int k; + int l; + int r; + + /* Tmp image copy */ + imgptr->copyTo(imgtmp); + + for (i = 0; i < imgptr->rows; i++) { + for (j = 0; j < imgptr->cols; j++) { + img_pix = imgptr->data + i * imgptr->step + j; + tmp_pix = imgtmp.data + i * imgptr->step + j; + + if (!(*img_pix)) { + *tmp_pix = 0; + continue; + } + + for (r = 0; r < width; r++) { + cnt_lo[r] = 0; + cnt_hi_or_eq[r] = 0; + } + + for (k = i - width; k <= i + width; k++) { + for (l = j - width; l <= j + width; l++) { + near_pix = imgptr->data + k * imgptr->step + l; + + dist_x = abs(k - i); + dist_y = abs(l - j); + + if ((k >= 0) && (k < imgptr->rows)) { + if ((l >= 0) && (l < imgptr->cols)) { + if (dist_x || dist_y) { + if (*near_pix < *img_pix) { + cnt_lo[std::max(dist_x, dist_y)]++; + } else { + cnt_hi_or_eq[std::max(dist_x, dist_y)]++; + } + } + } + } + + } + } + + skeleton = false; + for (r = 0; r < width; r++) { + if (cnt_lo[r] > (cnt_hi_or_eq[r] + (1.6) * (r + 1))) { + skeleton = true; + } + } + + if (skeleton) { + *tmp_pix = *img_pix; + } else { + *tmp_pix = 0; + } + } + } + + /* Cleanup */ + imgtmp.copyTo(*imgptr); + imgtmp.release(); +} + +static void img_alx_lines_horizontal (class cv::Mat *imgptr) +{ + int i; + int j; + bool white; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + + for (i = 0; i < imgptr->rows; i++) { + white = false; + + for (j = 0; j < imgptr->cols; j++) { + img_pix = imgptr->data + i * imgptr->step + j; + if (*img_pix) { + white = true; + break; + } + } + + if (white) { + for (j = 0; j < imgptr->cols; j++) { + img_pix = imgptr->data + i * imgptr->step + j; + *img_pix = 255; + } + } + } +} + +static void img_alx_lines_vertical (class cv::Mat *imgptr) +{ + int i; + int j; + bool white; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + + for (i = 0; i < imgptr->cols; i++) { + white = false; + + for (j = 0; j < imgptr->rows; j++) { + img_pix = imgptr->data + j * imgptr->step + i; + if (*img_pix) { + white = true; + break; + } + } + + if (white) { + for (j = 0; j < imgptr->rows; j++) { + img_pix = imgptr->data + j * imgptr->step + i; + *img_pix = 255; + } + } + } +} + +static void img_alx_mean_horizontal (class cv::Mat *imgptr) +{ + int i; + int j; + uint32_t tmp; + uint8_t mean; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + + for (i = 0; i < imgptr->rows; i++) { + tmp = 0; + for (j = 0; j < imgptr->cols; j++) { + img_pix = imgptr->data + i * imgptr->step + j; + tmp += *img_pix; + } + mean = tmp / imgptr->cols; + + for (j = 0; j < imgptr->cols; j++) { + img_pix = imgptr->data + i * imgptr->step + j; + *img_pix = mean; + } + } +} + +static void img_alx_mean_vertical (class cv::Mat *imgptr) +{ + int i; + int j; + uint32_t tmp; + uint8_t mean; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + + for (i = 0; i < imgptr->cols; i++) { + tmp = 0; + for (j = 0; j < imgptr->rows; j++) { + img_pix = imgptr->data + j * imgptr->step + i; + tmp += *img_pix; + } + mean = tmp / imgptr->rows; + + for (j = 0; j < imgptr->rows; j++) { + img_pix = imgptr->data + j * imgptr->step + i; + *img_pix = mean; + } + } +} + +static void img_alx_median_horizontal (class cv::Mat *imgptr) +{ + int i; + int j; + uint8_t row [imgptr->cols]; + uint8_t median; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + + for (i = 0; i < imgptr->rows; i++) { + for (j = 0; j < imgptr->cols; j++) { + img_pix = imgptr->data + i * imgptr->step + j; + row[j] = *img_pix; + } + median = alx_median_u8(imgptr->cols, row); + + for (j = 0; j < imgptr->cols; j++) { + img_pix = imgptr->data + i * imgptr->step + j; + *img_pix = median; + } + } +} + +static void img_alx_median_vertical (class cv::Mat *imgptr) +{ + int i; + int j; + uint8_t col [imgptr->rows]; + uint8_t median; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + + for (i = 0; i < imgptr->cols; i++) { + for (j = 0; j < imgptr->rows; j++) { + img_pix = imgptr->data + j * imgptr->step + i; + col[j] = *img_pix; + } + median = alx_median_u8(imgptr->rows, col); + + for (j = 0; j < imgptr->rows; j++) { + img_pix = imgptr->data + j * imgptr->step + i; + *img_pix = median; + } + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/src/img_calib3d.cpp b/modules/image/src/img_calib3d.cpp index da6bb95..63a64f4 100644 --- a/modules/image/src/img_calib3d.cpp +++ b/modules/image/src/img_calib3d.cpp @@ -1,142 +1,142 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C++ --------------------------------------------------------------*/ - /* class std::vector */ - #include - -/* Standard C ----------------------------------------------------------------*/ - /* snprintf() */ - #include - -/* Packages ------------------------------------------------------------------*/ - /* opencv */ - #include - #include - -/* Module -------------------------------------------------------------------*/ - /* data */ - #include "img_iface.hpp" - - #include "img_calib3d.hpp" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define CORNERS_HOR (16) - # define CORNERS_VER (13) - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void img_calib3d_calibrate (class cv::Mat *imgptr, void *data); -static void img_calib3d_undistort (class cv::Mat *imgptr, void *data); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void img_calib3d_act (class cv::Mat *imgptr, int action, void *data) -{ - switch (action) { - case IMG_CALIB3D_ACT_CALIBRATE: - img_calib3d_calibrate(imgptr, data); - break; - - case IMG_CALIB3D_ACT_UNDISTORT: - img_calib3d_undistort(imgptr, data); - break; - } -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void img_calib3d_calibrate (class cv::Mat *imgptr, void *data) -{ - /* Data */ - struct Img_Iface_Data_Calibrate *data_cast; - - class cv::Mat *intrinsic_mat; - class cv::Mat *dist_coefs; - class std::vector *rvecs; - class std::vector *tvecs; - - class cv::Size_ pattern_size; - class std::vector >> object_points; - class std::vector >> image_points; - class std::vector > corners; - class std::vector > obj; - - bool found; - int i; - int j; - - data_cast = (struct Img_Iface_Data_Calibrate *)data; - intrinsic_mat = data_cast->intrinsic_mat; - dist_coefs = data_cast->dist_coefs; - rvecs = data_cast->rvecs; - tvecs = data_cast->tvecs; - - pattern_size = cv::Size(CORNERS_HOR, CORNERS_VER); - *intrinsic_mat = cv::Mat(3, 3, CV_32FC1); - (*intrinsic_mat).ptr(0)[0] = 1; - (*intrinsic_mat).ptr(1)[1] = 1; - - for (i = 0; i < CORNERS_HOR; i++) { - for (j = 0; j < CORNERS_VER; j++) { - obj.push_back(cv::Point3f(i, j * 10.0, 0.0)); - } - } - - found = cv::findChessboardCorners(*imgptr, pattern_size, corners, - CV_CALIB_CB_ADAPTIVE_THRESH | - CV_CALIB_CB_FILTER_QUADS); - - cv::cornerSubPix(*imgptr, corners, cv::Size(11, 11), - cv::Size(-1, -1), - cv::TermCriteria(CV_TERMCRIT_EPS | - CV_TERMCRIT_ITER, 30, 0.1)); - cv::drawChessboardCorners(*imgptr, pattern_size, corners, found); - - image_points.push_back(corners); - object_points.push_back(obj); - - /* Calibrate */ - cv::calibrateCamera(object_points, image_points, imgptr->size(), - *intrinsic_mat, *dist_coefs, *rvecs, *tvecs); -} - -static void img_calib3d_undistort (class cv::Mat *imgptr, void *data) -{ - class cv::Mat imgtmp; - - /* Data */ - struct Img_Iface_Data_Undistort *data_cast; - - class cv::Mat *intrinsic_mat; - class cv::Mat *dist_coefs; - - data_cast = (struct Img_Iface_Data_Undistort *)data; - intrinsic_mat = data_cast->intrinsic_mat; - dist_coefs = data_cast->dist_coefs; - - cv::undistort(*imgptr, imgtmp, *intrinsic_mat, *dist_coefs); - - /* Write tmp into imgptr */ - imgptr->release(); - imgtmp.copyTo(*imgptr); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C++ --------------------------------------------------------------*/ + /* class std::vector */ + #include + +/* Standard C ----------------------------------------------------------------*/ + /* snprintf() */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* opencv */ + #include + #include + +/* Module -------------------------------------------------------------------*/ + /* data */ + #include "img_iface.hpp" + + #include "img_calib3d.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define CORNERS_HOR (16) + # define CORNERS_VER (13) + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void img_calib3d_calibrate (class cv::Mat *imgptr, void *data); +static void img_calib3d_undistort (class cv::Mat *imgptr, void *data); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void img_calib3d_act (class cv::Mat *imgptr, int action, void *data) +{ + switch (action) { + case IMG_CALIB3D_ACT_CALIBRATE: + img_calib3d_calibrate(imgptr, data); + break; + + case IMG_CALIB3D_ACT_UNDISTORT: + img_calib3d_undistort(imgptr, data); + break; + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void img_calib3d_calibrate (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Calibrate *data_cast; + + class cv::Mat *intrinsic_mat; + class cv::Mat *dist_coefs; + class std::vector *rvecs; + class std::vector *tvecs; + + class cv::Size_ pattern_size; + class std::vector >> object_points; + class std::vector >> image_points; + class std::vector > corners; + class std::vector > obj; + + bool found; + int i; + int j; + + data_cast = (struct Img_Iface_Data_Calibrate *)data; + intrinsic_mat = data_cast->intrinsic_mat; + dist_coefs = data_cast->dist_coefs; + rvecs = data_cast->rvecs; + tvecs = data_cast->tvecs; + + pattern_size = cv::Size(CORNERS_HOR, CORNERS_VER); + *intrinsic_mat = cv::Mat(3, 3, CV_32FC1); + (*intrinsic_mat).ptr(0)[0] = 1; + (*intrinsic_mat).ptr(1)[1] = 1; + + for (i = 0; i < CORNERS_HOR; i++) { + for (j = 0; j < CORNERS_VER; j++) { + obj.push_back(cv::Point3f(i, j * 10.0, 0.0)); + } + } + + found = cv::findChessboardCorners(*imgptr, pattern_size, corners, + CV_CALIB_CB_ADAPTIVE_THRESH | + CV_CALIB_CB_FILTER_QUADS); + + cv::cornerSubPix(*imgptr, corners, cv::Size(11, 11), + cv::Size(-1, -1), + cv::TermCriteria(CV_TERMCRIT_EPS | + CV_TERMCRIT_ITER, 30, 0.1)); + cv::drawChessboardCorners(*imgptr, pattern_size, corners, found); + + image_points.push_back(corners); + object_points.push_back(obj); + + /* Calibrate */ + cv::calibrateCamera(object_points, image_points, imgptr->size(), + *intrinsic_mat, *dist_coefs, *rvecs, *tvecs); +} + +static void img_calib3d_undistort (class cv::Mat *imgptr, void *data) +{ + class cv::Mat imgtmp; + + /* Data */ + struct Img_Iface_Data_Undistort *data_cast; + + class cv::Mat *intrinsic_mat; + class cv::Mat *dist_coefs; + + data_cast = (struct Img_Iface_Data_Undistort *)data; + intrinsic_mat = data_cast->intrinsic_mat; + dist_coefs = data_cast->dist_coefs; + + cv::undistort(*imgptr, imgtmp, *intrinsic_mat, *dist_coefs); + + /* Write tmp into imgptr */ + imgptr->release(); + imgtmp.copyTo(*imgptr); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/src/img_cv.cpp b/modules/image/src/img_cv.cpp index 3a7c59b..0d76bb8 100644 --- a/modules/image/src/img_cv.cpp +++ b/modules/image/src/img_cv.cpp @@ -1,881 +1,881 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C++ --------------------------------------------------------------*/ - /* class std::vector */ - #include - -/* Standard C ----------------------------------------------------------------*/ - /* fabs */ - #include - /* true & false */ - #include - /* snprintf() */ - #include - -/* Packages ------------------------------------------------------------------*/ - /* opencv */ - #include - -/* Module --------------------------------------------------------------------*/ - /* data */ - #include "img_iface.hpp" - - #include "img_cv.hpp" - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ - /* Core: The core functionality */ - /* Pixel */ -static void img_cv_pixel_get (class cv::Mat *imgptr, void *data); -static void img_cv_pixel_set (class cv::Mat *imgptr, void *data); - /* ROI */ -static void img_cv_set_ROI (class cv::Mat *imgptr, void *data); - /* Operations on Arrays */ -static void img_cv_and_2ref (class cv::Mat *imgptr, void *data); -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_component (class cv::Mat *imgptr, void *data); - /* Imgproc: Image processing */ - /* Image filtering */ -static void img_cv_dilate (class cv::Mat *imgptr, void *data); -static void img_cv_erode (class cv::Mat *imgptr, void *data); -static void img_cv_smooth (class cv::Mat *imgptr, void *data); -static void img_cv_sobel (class cv::Mat *imgptr, void *data); -static void img_cv_border (class cv::Mat *imgptr, void *data); - /* Geometric image transformations */ -static void img_cv_mirror (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); - /* Miscellaneous image transformations */ -static void img_cv_adaptive_thr (class cv::Mat *imgptr, void *data); -static void img_cv_cvt_color (class cv::Mat *imgptr, void *data); -static void img_cv_distance_transform (class cv::Mat *imgptr); -static void img_cv_threshold (class cv::Mat *imgptr, void *data); - /* Histograms */ -static void img_cv_histogram (class cv::Mat *imgptr, void *data); -static void img_cv_histogram_c3 (class cv::Mat *imgptr, void *data); - /* Structural analysis and shape descriptors */ -static void img_cv_contours (class cv::Mat *imgptr, void *data); -static void img_cv_contours_size (void *data); -static void img_cv_bounding_rect (class cv::Mat *imgptr, void *data); -static void img_cv_fit_ellipse (class cv::Mat *imgptr, void *data); -static void img_cv_min_area_rect (class cv::Mat *imgptr, void *data); - /* Feature detection */ -static void img_cv_hough_circles (class cv::Mat *imgptr, void *data); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void img_cv_act (class cv::Mat *imgptr, int action, void *data) -{ - switch (action) { - case IMG_CV_ACT_PIXEL_GET: - img_cv_pixel_get(imgptr, data); - break; - case IMG_CV_ACT_PIXEL_SET: - img_cv_pixel_set(imgptr, data); - break; - - case IMG_CV_ACT_SET_ROI: - img_cv_set_ROI(imgptr, data); - break; - - case IMG_CV_ACT_AND_2REF: - img_cv_and_2ref(imgptr, data); - break; - 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_COMPONENT: - img_cv_component(imgptr, data); - break; - - case IMG_CV_ACT_DILATE: - img_cv_dilate(imgptr, data); - break; - case IMG_CV_ACT_ERODE: - img_cv_erode(imgptr, data); - break; - case IMG_CV_ACT_SMOOTH: - img_cv_smooth(imgptr, data); - break; - case IMG_CV_ACT_SOBEL: - img_cv_sobel(imgptr, data); - break; - case IMG_CV_ACT_BORDER: - img_cv_border(imgptr, data); - break; - - case IMG_CV_ACT_MIRROR: - img_cv_mirror(imgptr, data); - break; - case IMG_CV_ACT_ROTATE_ORTO: - img_cv_rotate_orto(imgptr, data); - break; - case IMG_CV_ACT_ROTATE: - img_cv_rotate(imgptr, data); - break; - - case IMG_CV_ACT_ADAPTIVE_THRESHOLD: - img_cv_adaptive_thr(imgptr, data); - break; - case IMG_CV_ACT_CVT_COLOR: - img_cv_cvt_color(imgptr, data); - break; - case IMG_CV_ACT_DISTANCE_TRANSFORM: - img_cv_distance_transform(imgptr); - break; - case IMG_CV_ACT_THRESHOLD: - img_cv_threshold(imgptr, data); - break; - - case IMG_CV_ACT_HISTOGRAM: - img_cv_histogram(imgptr, data); - break; - case IMG_CV_ACT_HISTOGRAM_C3: - img_cv_histogram_c3(imgptr, data); - break; - - case IMG_CV_ACT_CONTOURS: - img_cv_contours(imgptr, data); - break; - case IMG_CV_ACT_CONTOURS_SIZE: - img_cv_contours_size(data); - break; - case IMG_CV_ACT_BOUNDING_RECT: - img_cv_bounding_rect(imgptr, data); - break; - case IMG_CV_ACT_FIT_ELLIPSE: - img_cv_fit_ellipse(imgptr, data); - break; - case IMG_CV_ACT_MIN_AREA_RECT: - img_cv_min_area_rect(imgptr, data); - break; - - case IMG_CV_ACT_HOUGH_CIRCLES: - img_cv_hough_circles(imgptr, data); - break; - } -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -/* Core: The core functionality */ -/* ----- Pixel */ -static void img_cv_pixel_get (class cv::Mat *imgptr, void *data) -{ - struct Img_Iface_Data_Pixel_Get *data_cast; - unsigned char *val; - int x; - int y; - /* Data */ - data_cast = (struct Img_Iface_Data_Pixel_Get *)data; - - /* Value */ - val = data_cast->val; - /* Position */ - x = data_cast->x; - y = data_cast->y; - - /* Get value */ - *val = imgptr->at(y, x); -} - -static void img_cv_pixel_set (class cv::Mat *imgptr, void *data) -{ - struct Img_Iface_Data_Pixel_Set *data_cast; - unsigned char val; - int x; - int y; - - /* Data */ - data_cast = (struct Img_Iface_Data_Pixel_Set *)data; - - /* Value */ - val = data_cast->val; - /* Position */ - x = data_cast->x; - y = data_cast->y; - - /* Set value */ - imgptr->at(y, x) = val; -} - -/* ----- ROI */ -static void img_cv_set_ROI (class cv::Mat *imgptr, void *data) -{ - class cv::Mat imgtmp; - struct Img_Iface_Data_SetROI *data_cast; - class cv::Rect_ *rect; - - /* Data */ - data_cast = (struct Img_Iface_Data_SetROI *)data; - - /* Rectangle */ - rect = &(data_cast->rect); - - /* Set ROI */ - (*imgptr)(*rect).copyTo(imgtmp); - imgtmp.copyTo(*imgptr); - - /* Write tmp into imgptr */ - imgptr->release(); - imgtmp.copyTo(*imgptr); - - /* clean up */ - imgtmp.release(); -} - -/* ----- Operations on arrays */ -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_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_component (class cv::Mat *imgptr, void *data) -{ - class cv::Mat cmp_img[3]; - struct Img_Iface_Data_Component *data_cast; - int cmp; - - /* Data */ - data_cast = (struct Img_Iface_Data_Component *)data; - - /* Color component */ - cmp = data_cast->cmp; - - /* Write components into cmp_img[] */ - cv::split(*imgptr, cmp_img); - - /* Write tmp into imgptr */ - imgptr->release(); - cmp_img[cmp].copyTo(*imgptr); - - /* clean up */ - cmp_img[0].release(); - cmp_img[1].release(); - cmp_img[2].release(); -} - -/* Imgproc: Image processing */ -/* ----- Image filtering */ -static void img_cv_dilate (class cv::Mat *imgptr, void *data) -{ - /* Data */ - struct Img_Iface_Data_Dilate_Erode *data_cast; - data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; - - /* Iterations */ - int i; - i = data_cast->i; - - /* Dilate */ - cv::dilate(*imgptr, *imgptr, cv::Mat(), cv::Point(-1,-1), i, - cv::BORDER_CONSTANT, cv::Scalar(0)); -} - -static void img_cv_erode (class cv::Mat *imgptr, void *data) -{ - /* Data */ - struct Img_Iface_Data_Dilate_Erode *data_cast; - data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; - - /* Iterations */ - int i; - i = data_cast->i; - - /* Erode */ - cv::erode(*imgptr, *imgptr, cv::Mat(), cv::Point(-1,-1), i, - cv::BORDER_CONSTANT, cv::Scalar(0)); -} - -static void img_cv_smooth (class cv::Mat *imgptr, void *data) -{ - /* Data */ - struct Img_Iface_Data_Smooth *data_cast; - data_cast = (struct Img_Iface_Data_Smooth *)data; - - /* Smoothing method */ - int method; - method = data_cast->method; - /* Kernel size */ - int ksize; - ksize = data_cast->ksize; - if (!(ksize % 2)) { - ksize++; - } - - switch (method) { - case IMGI_SMOOTH_MEAN: - cv::blur(*imgptr, *imgptr, cv::Size(ksize, ksize), - cv::Point(-1,-1), cv::BORDER_DEFAULT); - break; - case IMGI_SMOOTH_GAUSS: - cv::GaussianBlur(*imgptr, *imgptr, cv::Size(ksize, ksize), - 0, 0, cv::BORDER_DEFAULT); - break; - case IMGI_SMOOTH_MEDIAN: - cv::medianBlur(*imgptr, *imgptr, ksize); - break; - } -} - -static void img_cv_sobel (class cv::Mat *imgptr, void *data) -{ - /* Data */ - struct Img_Iface_Data_Sobel *data_cast; - data_cast = (struct Img_Iface_Data_Sobel *)data; - - /* Order of the derivative x */ - int dx; - dx = data_cast->dx; - /* Order of the derivative y */ - int dy; - dy = data_cast->dy; - /* Size of the extended Sobel kernel */ - int ksize; - ksize = data_cast->ksize; - if (!(ksize % 2)) { - ksize++; - } - - cv::Sobel(*imgptr, *imgptr, -1, dx, dy, ksize, 1, 0, - cv::BORDER_DEFAULT); -} - -static void img_cv_border (class cv::Mat *imgptr, void *data) -{ - class cv::Mat imgtmp; - struct Img_Iface_Data_Border *data_cast; - int size; - - /* Data */ - data_cast = (struct Img_Iface_Data_Border *)data; - - size = data_cast->size; - - imgtmp = cv::Mat(cv::Size(imgptr->cols + size, imgptr->rows + size), - CV_8U); - /* Get transform */ - cv::copyMakeBorder(*imgptr, imgtmp, size, size, size, size, - cv::BORDER_CONSTANT, cv::Scalar(0)); - - imgtmp.copyTo(*imgptr); - - /* Cleanup */ - imgtmp.release(); -} - -/* ----- Geometric image transformations */ -static void img_cv_mirror (class cv::Mat *imgptr, void *data) -{ - struct Img_Iface_Data_Mirror *data_cast; - int axis; - - /* Data */ - data_cast = (struct Img_Iface_Data_Mirror *)data; - - /* Rotate n * pi/2 rad */ - axis = data_cast->axis; - - /* flip around axis */ - cv::flip(*imgptr, *imgptr, axis); -} - -static void img_cv_rotate_orto (class cv::Mat *imgptr, void *data) -{ - /* Data */ - struct Img_Iface_Data_Rotate_Orto *data_cast; - data_cast = (struct Img_Iface_Data_Rotate_Orto *)data; - - /* Rotate n * pi/2 rad */ - int n; - n = data_cast->n; - - switch (n) { - case 1: - /* Rotate: transpose and flip around horizontal axis: flip_mode=0 */ - cv::transpose(*imgptr, *imgptr); - cv::flip(*imgptr, *imgptr, 0); - break; - - case 2: - /* Rotate: Flip both axises: flip_mode=-1 */ - cv::flip(*imgptr, *imgptr, -1); - break; - - case 3: - /* Rotate: transpose and flip around vertical axis: flip_mode=1 */ - cv::transpose(*imgptr, *imgptr); - cv::flip(*imgptr, *imgptr, 1); - break; - } -} - -static void img_cv_rotate (class cv::Mat *imgptr, void *data) -{ - class cv::Mat map_matrix; - - /* Data */ - struct Img_Iface_Data_Rotate *data_cast; - data_cast = (struct Img_Iface_Data_Rotate *)data; - - /* Angle of rotation */ - class cv::Point_ *center; - center = &(data_cast->center); - double angle; - angle = data_cast->angle; - - /* 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)); - - /* clean up */ - map_matrix.release(); -} - -/* ----- Miscellaneous image transformations */ -static void img_cv_adaptive_thr (class cv::Mat *imgptr, void *data) -{ - /* Data */ - struct Img_Iface_Data_Adaptive_Thr *data_cast; - data_cast = (struct Img_Iface_Data_Adaptive_Thr *)data; - - /* Threshold method */ - int method; - method = data_cast->method; - /* Threshold type */ - int thr_typ; - thr_typ = data_cast->thr_typ; - /* Neighbourhood size */ - int ksize; - ksize = data_cast->ksize; - if (!(ksize % 2)) { - ksize++; - } - - /* Apply adaptive threshold */ - cv::adaptiveThreshold(*imgptr, *imgptr, 255, method, thr_typ, ksize, - 0); -} - -static void img_cv_cvt_color (class cv::Mat *imgptr, void *data) -{ - /* Data */ - struct Img_Iface_Data_Cvt_Color *data_cast; - data_cast = (struct Img_Iface_Data_Cvt_Color *)data; - - /* Conversion method */ - int method; - method = data_cast->method; - - cv::cvtColor(*imgptr, *imgptr, method, 0); -} - -static void img_cv_distance_transform (class cv::Mat *imgptr) -{ - class cv::Mat imgtmp; - - /* Get transform */ - cv::distanceTransform(*imgptr, imgtmp, CV_DIST_L2, CV_DIST_MASK_PRECISE); - - /* DistanceTransform gives CV_32F image */ - imgtmp.convertTo(*imgptr, CV_8U); - - /* Cleanup */ - imgtmp.release(); -} - -static void img_cv_threshold (class cv::Mat *imgptr, void *data) -{ - /* Data */ - struct Img_Iface_Data_Threshold *data_cast; - data_cast = (struct Img_Iface_Data_Threshold *)data; - - /* Threshold type */ - int thr_typ; - thr_typ = data_cast->thr_typ; - /* Threshold value */ - int thr_val; - thr_val = data_cast->thr_val; - if (thr_val == -1) { - thr_typ |= cv::THRESH_OTSU; - } - - /* Threshold */ - cv::threshold(*imgptr, *imgptr, thr_val, 0xFF, thr_typ); -} - -/* ----- Histograms */ -static void img_cv_histogram (class cv::Mat *imgptr, void *data) -{ - /* Data */ - struct Img_Iface_Data_Histogram *data_cast; - data_cast = (struct Img_Iface_Data_Histogram *)data; - - /* Contours */ - class cv::Mat *hist; - hist = data_cast->hist_c0; - class cv::Mat *hist_img; - hist_img = data_cast->hist_img; - - /* Write components into cmp_img[] */ - int h_size = 256; - float h_range_arr[] = {0.0, 256.0}; - const float *h_range = {h_range_arr}; - cv::calcHist(imgptr, 1, 0, cv::Mat(), *hist, 1, &h_size, &h_range, - true, false); - - /* Init */ - hist_img->setTo(cv::Scalar(0)); - - /* Normalize the result to [0, hist_img->rows - 1] */ - cv::normalize(*hist, *hist, 0, hist_img->rows - 1, cv::NORM_MINMAX, -1, - cv::Mat()); - - /* Draw hist into hist_img */ - int i; - for(i = 0; i < 256; i++ ) { - cv::line(*hist_img, cv::Point(i, hist_img->rows - 0), - cv::Point(i, hist_img->rows - hist->at(i)), - cv::Scalar(255, 0, 0), 1, 8, 0); - } - - /* Show histogram */ - img_iface_show_hist_c1(); -} - -static void img_cv_histogram_c3 (class cv::Mat *imgptr, void *data) -{ - class cv::Mat cmp_img[3]; - - /* Write components into cmp_img[] */ - cv::split(*imgptr, cmp_img); - - /* Data */ - struct Img_Iface_Data_Histogram *data_cast; - data_cast = (struct Img_Iface_Data_Histogram *)data; - - /* Contours */ - class cv::Mat *hist_c0; - hist_c0 = data_cast->hist_c0; - class cv::Mat *hist_c1; - hist_c1 = data_cast->hist_c1; - class cv::Mat *hist_c2; - hist_c2 = data_cast->hist_c2; - class cv::Mat *hist_img; - hist_img = data_cast->hist_img; - - /* Write components into cmp_img[] */ - int h_size = 256; - float h_range_arr[] = {0.0, 256.0}; - const float *h_range = {h_range_arr}; - cv::calcHist(&cmp_img[0], 1, 0, cv::Mat(), *hist_c0, 1, &h_size, - &h_range, true, false); - cv::calcHist(&cmp_img[1], 1, 0, cv::Mat(), *hist_c1, 1, &h_size, - &h_range, true, false); - cv::calcHist(&cmp_img[2], 1, 0, cv::Mat(), *hist_c2, 1, &h_size, - &h_range, true, false); - - /* Init */ - hist_img->setTo(cv::Scalar(0)); - - /* Normalize the result to [0, hist_img->rows - 1] */ - cv::normalize(*hist_c0, *hist_c0, 0, hist_img->rows - 1, - cv::NORM_MINMAX, -1, cv::Mat()); - cv::normalize(*hist_c1, *hist_c1, 0, hist_img->rows - 1, - cv::NORM_MINMAX, -1, cv::Mat()); - cv::normalize(*hist_c2, *hist_c2, 0, hist_img->rows - 1, - cv::NORM_MINMAX, -1, cv::Mat()); - - /* Draw hist into hist_img */ - int i; - for(i = 0; i < 256; i++ ) { - cv::line(*hist_img, cv::Point(3*i, hist_img->rows - 0), - cv::Point(3*i, - hist_img->rows - hist_c0->at(i)), - cv::Scalar(255, 0, 0), 1, 8, 0); - } - for(i = 0; i < 256; i++ ) { - cv::line(*hist_img, cv::Point(3*i + 1, hist_img->rows - 0), - cv::Point(3*i+1, - hist_img->rows - hist_c1->at(i)), - cv::Scalar(0, 255, 0), 1, 8, 0); - } - for(i = 0; i < 256; i++ ) { - cv::line(*hist_img, cv::Point(3*i + 2, hist_img->rows - 0), - cv::Point(3*i + 2, - hist_img->rows - hist_c2->at(i)), - cv::Scalar(0, 0, 255), 1, 8, 0); - } - - /* Show histogram */ - img_iface_show_hist_c3(); - - /* Cleanup */ - cmp_img[0].release(); - cmp_img[1].release(); - cmp_img[2].release(); -} - -/* ----- Structural analysis and shape descriptors */ -static void img_cv_contours (class cv::Mat *imgptr, void *data) -{ - struct Img_Iface_Data_Contours *data_cast; - class std::vector >> *contours; - class cv::Mat *hierarchy; - - /* Data */ - data_cast = (struct Img_Iface_Data_Contours *)data; - - /* Contours */ - contours = data_cast->contours; - hierarchy = data_cast->hierarchy; - - /* Get contours */ - - cv::findContours(*imgptr, *contours, *hierarchy, CV_RETR_EXTERNAL, - CV_CHAIN_APPROX_SIMPLE); - - /* Set image to black */ - imgptr->setTo(cv::Scalar(0)); - - /* Draw contours in color */ - cv::drawContours(*imgptr, *contours, -1, cv::Scalar(255), 1, 8, - *hierarchy, 1, cvPoint(0, 0)); -} - -static void img_cv_contours_size (void *data) -{ - struct Img_Iface_Data_Contours_Size *data_cast; - class std::vector >> *contours; - int i; - - /* Data */ - data_cast = (struct Img_Iface_Data_Contours_Size *)data; - - /* Contours */ - contours = data_cast->contours; - - /* Get area and perimeter */ - if (data_cast->area) { - for (i = 0; i < (int)contours->size(); i++) { - data_cast->area[i] = cv::contourArea( - (*contours)[i], false); - } - } - if (data_cast->perimeter) { - for (i = 0; i < (int)contours->size(); i++) { - data_cast->perimeter[i] = cv::arcLength( - (*contours)[i], true); - } - } -} - -static void img_cv_bounding_rect (class cv::Mat *imgptr, void *data) -{ - /* Data */ - struct Img_Iface_Data_Bounding_Rect *data_cast; - data_cast = (struct Img_Iface_Data_Bounding_Rect *)data; - - /* Contours */ - class std::vector > *contour; - contour = data_cast->contour; - /* Rotated rectangle */ - class cv::Rect_ *rect; - rect = data_cast->rect; - /* Show rectangle ? */ - bool show; - show = data_cast->show; - - /* Get rectangle */ - *rect = cv::boundingRect(*contour); - - /* Draw rectangle */ - class cv::Point_ vertices[4]; - if (show) { - vertices[0].x = rect->x; - vertices[0].y = rect->y; - vertices[1].x = rect->x + rect->width; - vertices[1].y = rect->y; - vertices[2].x = rect->x + rect->width; - vertices[2].y = rect->y + rect->height; - vertices[3].x = rect->x; - vertices[3].y = rect->y + rect->height; - 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) -{ - /* Data */ - struct Img_Iface_Data_MinARect *data_cast; - data_cast = (struct Img_Iface_Data_MinARect *)data; - - /* Contours */ - class std::vector > *contour; - contour = data_cast->contour; - /* Rotated rectangle */ - class cv::RotatedRect *rect; - rect = data_cast->rect; - /* Show rectangle ? */ - bool show; - show = data_cast->show; - - /* Get rectangle */ - *rect = cv::fitEllipse(*contour); - - /* Draw rectangle */ - class cv::Point_ vertices[4]; - 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_min_area_rect (class cv::Mat *imgptr, void *data) -{ - /* Data */ - struct Img_Iface_Data_MinARect *data_cast; - data_cast = (struct Img_Iface_Data_MinARect *)data; - - /* Contours */ - class std::vector > *contour; - contour = data_cast->contour; - /* 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_ vertices[4]; - 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); - } -} - -/* ----- Feature detection */ -static void img_cv_hough_circles (class cv::Mat *imgptr, void *data) -{ - /* Data */ - struct Img_Iface_Data_Hough_Circles *data_cast; - data_cast = (struct Img_Iface_Data_Hough_Circles *)data; - - /* Contours */ - class std::vector > *circles; - circles = data_cast->circles; - /* Parameters */ - double dist_min; - double param_1; - double param_2; - int radius_min; - int radius_max; - dist_min = data_cast->dist_min; - param_1 = data_cast->param_1; - param_2 = data_cast->param_2; - radius_min = data_cast->radius_min; - radius_max = data_cast->radius_max; - - /* Get circles */ - cv::HoughCircles(*imgptr, *circles, CV_HOUGH_GRADIENT, 1, dist_min, - param_1, param_2, radius_min, radius_max); - - /* Set image to black */ - imgptr->setTo(cv::Scalar(0)); - - /* Draw circles */ - class cv::Point_ center; - int radius; - int i; - for (i = 0; i < (int)circles->size(); i++) { - center.x = cvRound((*circles)[i][0]); - center.y = cvRound((*circles)[i][1]); - radius = cvRound((*circles)[i][2]); - - /* Draw the circle center */ -/* cv::circle(*imgptr, center, 3, - cv::Scalar(0, 255, 0), -1, 8, 0);*/ - - /* Draw the circle outline */ - cv::circle(*imgptr, center, radius, - cv::Scalar(250), 1, 8, 0); - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C++ --------------------------------------------------------------*/ + /* class std::vector */ + #include + +/* Standard C ----------------------------------------------------------------*/ + /* fabs */ + #include + /* true & false */ + #include + /* snprintf() */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* opencv */ + #include + +/* Module --------------------------------------------------------------------*/ + /* data */ + #include "img_iface.hpp" + + #include "img_cv.hpp" + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ + /* Core: The core functionality */ + /* Pixel */ +static void img_cv_pixel_get (class cv::Mat *imgptr, void *data); +static void img_cv_pixel_set (class cv::Mat *imgptr, void *data); + /* ROI */ +static void img_cv_set_ROI (class cv::Mat *imgptr, void *data); + /* Operations on Arrays */ +static void img_cv_and_2ref (class cv::Mat *imgptr, void *data); +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_component (class cv::Mat *imgptr, void *data); + /* Imgproc: Image processing */ + /* Image filtering */ +static void img_cv_dilate (class cv::Mat *imgptr, void *data); +static void img_cv_erode (class cv::Mat *imgptr, void *data); +static void img_cv_smooth (class cv::Mat *imgptr, void *data); +static void img_cv_sobel (class cv::Mat *imgptr, void *data); +static void img_cv_border (class cv::Mat *imgptr, void *data); + /* Geometric image transformations */ +static void img_cv_mirror (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); + /* Miscellaneous image transformations */ +static void img_cv_adaptive_thr (class cv::Mat *imgptr, void *data); +static void img_cv_cvt_color (class cv::Mat *imgptr, void *data); +static void img_cv_distance_transform (class cv::Mat *imgptr); +static void img_cv_threshold (class cv::Mat *imgptr, void *data); + /* Histograms */ +static void img_cv_histogram (class cv::Mat *imgptr, void *data); +static void img_cv_histogram_c3 (class cv::Mat *imgptr, void *data); + /* Structural analysis and shape descriptors */ +static void img_cv_contours (class cv::Mat *imgptr, void *data); +static void img_cv_contours_size (void *data); +static void img_cv_bounding_rect (class cv::Mat *imgptr, void *data); +static void img_cv_fit_ellipse (class cv::Mat *imgptr, void *data); +static void img_cv_min_area_rect (class cv::Mat *imgptr, void *data); + /* Feature detection */ +static void img_cv_hough_circles (class cv::Mat *imgptr, void *data); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void img_cv_act (class cv::Mat *imgptr, int action, void *data) +{ + switch (action) { + case IMG_CV_ACT_PIXEL_GET: + img_cv_pixel_get(imgptr, data); + break; + case IMG_CV_ACT_PIXEL_SET: + img_cv_pixel_set(imgptr, data); + break; + + case IMG_CV_ACT_SET_ROI: + img_cv_set_ROI(imgptr, data); + break; + + case IMG_CV_ACT_AND_2REF: + img_cv_and_2ref(imgptr, data); + break; + 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_COMPONENT: + img_cv_component(imgptr, data); + break; + + case IMG_CV_ACT_DILATE: + img_cv_dilate(imgptr, data); + break; + case IMG_CV_ACT_ERODE: + img_cv_erode(imgptr, data); + break; + case IMG_CV_ACT_SMOOTH: + img_cv_smooth(imgptr, data); + break; + case IMG_CV_ACT_SOBEL: + img_cv_sobel(imgptr, data); + break; + case IMG_CV_ACT_BORDER: + img_cv_border(imgptr, data); + break; + + case IMG_CV_ACT_MIRROR: + img_cv_mirror(imgptr, data); + break; + case IMG_CV_ACT_ROTATE_ORTO: + img_cv_rotate_orto(imgptr, data); + break; + case IMG_CV_ACT_ROTATE: + img_cv_rotate(imgptr, data); + break; + + case IMG_CV_ACT_ADAPTIVE_THRESHOLD: + img_cv_adaptive_thr(imgptr, data); + break; + case IMG_CV_ACT_CVT_COLOR: + img_cv_cvt_color(imgptr, data); + break; + case IMG_CV_ACT_DISTANCE_TRANSFORM: + img_cv_distance_transform(imgptr); + break; + case IMG_CV_ACT_THRESHOLD: + img_cv_threshold(imgptr, data); + break; + + case IMG_CV_ACT_HISTOGRAM: + img_cv_histogram(imgptr, data); + break; + case IMG_CV_ACT_HISTOGRAM_C3: + img_cv_histogram_c3(imgptr, data); + break; + + case IMG_CV_ACT_CONTOURS: + img_cv_contours(imgptr, data); + break; + case IMG_CV_ACT_CONTOURS_SIZE: + img_cv_contours_size(data); + break; + case IMG_CV_ACT_BOUNDING_RECT: + img_cv_bounding_rect(imgptr, data); + break; + case IMG_CV_ACT_FIT_ELLIPSE: + img_cv_fit_ellipse(imgptr, data); + break; + case IMG_CV_ACT_MIN_AREA_RECT: + img_cv_min_area_rect(imgptr, data); + break; + + case IMG_CV_ACT_HOUGH_CIRCLES: + img_cv_hough_circles(imgptr, data); + break; + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +/* Core: The core functionality */ +/* ----- Pixel */ +static void img_cv_pixel_get (class cv::Mat *imgptr, void *data) +{ + struct Img_Iface_Data_Pixel_Get *data_cast; + unsigned char *val; + int x; + int y; + /* Data */ + data_cast = (struct Img_Iface_Data_Pixel_Get *)data; + + /* Value */ + val = data_cast->val; + /* Position */ + x = data_cast->x; + y = data_cast->y; + + /* Get value */ + *val = imgptr->at(y, x); +} + +static void img_cv_pixel_set (class cv::Mat *imgptr, void *data) +{ + struct Img_Iface_Data_Pixel_Set *data_cast; + unsigned char val; + int x; + int y; + + /* Data */ + data_cast = (struct Img_Iface_Data_Pixel_Set *)data; + + /* Value */ + val = data_cast->val; + /* Position */ + x = data_cast->x; + y = data_cast->y; + + /* Set value */ + imgptr->at(y, x) = val; +} + +/* ----- ROI */ +static void img_cv_set_ROI (class cv::Mat *imgptr, void *data) +{ + class cv::Mat imgtmp; + struct Img_Iface_Data_SetROI *data_cast; + class cv::Rect_ *rect; + + /* Data */ + data_cast = (struct Img_Iface_Data_SetROI *)data; + + /* Rectangle */ + rect = &(data_cast->rect); + + /* Set ROI */ + (*imgptr)(*rect).copyTo(imgtmp); + imgtmp.copyTo(*imgptr); + + /* Write tmp into imgptr */ + imgptr->release(); + imgtmp.copyTo(*imgptr); + + /* clean up */ + imgtmp.release(); +} + +/* ----- Operations on arrays */ +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_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_component (class cv::Mat *imgptr, void *data) +{ + class cv::Mat cmp_img[3]; + struct Img_Iface_Data_Component *data_cast; + int cmp; + + /* Data */ + data_cast = (struct Img_Iface_Data_Component *)data; + + /* Color component */ + cmp = data_cast->cmp; + + /* Write components into cmp_img[] */ + cv::split(*imgptr, cmp_img); + + /* Write tmp into imgptr */ + imgptr->release(); + cmp_img[cmp].copyTo(*imgptr); + + /* clean up */ + cmp_img[0].release(); + cmp_img[1].release(); + cmp_img[2].release(); +} + +/* Imgproc: Image processing */ +/* ----- Image filtering */ +static void img_cv_dilate (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Dilate_Erode *data_cast; + data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; + + /* Iterations */ + int i; + i = data_cast->i; + + /* Dilate */ + cv::dilate(*imgptr, *imgptr, cv::Mat(), cv::Point(-1,-1), i, + cv::BORDER_CONSTANT, cv::Scalar(0)); +} + +static void img_cv_erode (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Dilate_Erode *data_cast; + data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; + + /* Iterations */ + int i; + i = data_cast->i; + + /* Erode */ + cv::erode(*imgptr, *imgptr, cv::Mat(), cv::Point(-1,-1), i, + cv::BORDER_CONSTANT, cv::Scalar(0)); +} + +static void img_cv_smooth (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Smooth *data_cast; + data_cast = (struct Img_Iface_Data_Smooth *)data; + + /* Smoothing method */ + int method; + method = data_cast->method; + /* Kernel size */ + int ksize; + ksize = data_cast->ksize; + if (!(ksize % 2)) { + ksize++; + } + + switch (method) { + case IMGI_SMOOTH_MEAN: + cv::blur(*imgptr, *imgptr, cv::Size(ksize, ksize), + cv::Point(-1,-1), cv::BORDER_DEFAULT); + break; + case IMGI_SMOOTH_GAUSS: + cv::GaussianBlur(*imgptr, *imgptr, cv::Size(ksize, ksize), + 0, 0, cv::BORDER_DEFAULT); + break; + case IMGI_SMOOTH_MEDIAN: + cv::medianBlur(*imgptr, *imgptr, ksize); + break; + } +} + +static void img_cv_sobel (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Sobel *data_cast; + data_cast = (struct Img_Iface_Data_Sobel *)data; + + /* Order of the derivative x */ + int dx; + dx = data_cast->dx; + /* Order of the derivative y */ + int dy; + dy = data_cast->dy; + /* Size of the extended Sobel kernel */ + int ksize; + ksize = data_cast->ksize; + if (!(ksize % 2)) { + ksize++; + } + + cv::Sobel(*imgptr, *imgptr, -1, dx, dy, ksize, 1, 0, + cv::BORDER_DEFAULT); +} + +static void img_cv_border (class cv::Mat *imgptr, void *data) +{ + class cv::Mat imgtmp; + struct Img_Iface_Data_Border *data_cast; + int size; + + /* Data */ + data_cast = (struct Img_Iface_Data_Border *)data; + + size = data_cast->size; + + imgtmp = cv::Mat(cv::Size(imgptr->cols + size, imgptr->rows + size), + CV_8U); + /* Get transform */ + cv::copyMakeBorder(*imgptr, imgtmp, size, size, size, size, + cv::BORDER_CONSTANT, cv::Scalar(0)); + + imgtmp.copyTo(*imgptr); + + /* Cleanup */ + imgtmp.release(); +} + +/* ----- Geometric image transformations */ +static void img_cv_mirror (class cv::Mat *imgptr, void *data) +{ + struct Img_Iface_Data_Mirror *data_cast; + int axis; + + /* Data */ + data_cast = (struct Img_Iface_Data_Mirror *)data; + + /* Rotate n * pi/2 rad */ + axis = data_cast->axis; + + /* flip around axis */ + cv::flip(*imgptr, *imgptr, axis); +} + +static void img_cv_rotate_orto (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Rotate_Orto *data_cast; + data_cast = (struct Img_Iface_Data_Rotate_Orto *)data; + + /* Rotate n * pi/2 rad */ + int n; + n = data_cast->n; + + switch (n) { + case 1: + /* Rotate: transpose and flip around horizontal axis: flip_mode=0 */ + cv::transpose(*imgptr, *imgptr); + cv::flip(*imgptr, *imgptr, 0); + break; + + case 2: + /* Rotate: Flip both axises: flip_mode=-1 */ + cv::flip(*imgptr, *imgptr, -1); + break; + + case 3: + /* Rotate: transpose and flip around vertical axis: flip_mode=1 */ + cv::transpose(*imgptr, *imgptr); + cv::flip(*imgptr, *imgptr, 1); + break; + } +} + +static void img_cv_rotate (class cv::Mat *imgptr, void *data) +{ + class cv::Mat map_matrix; + + /* Data */ + struct Img_Iface_Data_Rotate *data_cast; + data_cast = (struct Img_Iface_Data_Rotate *)data; + + /* Angle of rotation */ + class cv::Point_ *center; + center = &(data_cast->center); + double angle; + angle = data_cast->angle; + + /* 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)); + + /* clean up */ + map_matrix.release(); +} + +/* ----- Miscellaneous image transformations */ +static void img_cv_adaptive_thr (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Adaptive_Thr *data_cast; + data_cast = (struct Img_Iface_Data_Adaptive_Thr *)data; + + /* Threshold method */ + int method; + method = data_cast->method; + /* Threshold type */ + int thr_typ; + thr_typ = data_cast->thr_typ; + /* Neighbourhood size */ + int ksize; + ksize = data_cast->ksize; + if (!(ksize % 2)) { + ksize++; + } + + /* Apply adaptive threshold */ + cv::adaptiveThreshold(*imgptr, *imgptr, 255, method, thr_typ, ksize, + 0); +} + +static void img_cv_cvt_color (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Cvt_Color *data_cast; + data_cast = (struct Img_Iface_Data_Cvt_Color *)data; + + /* Conversion method */ + int method; + method = data_cast->method; + + cv::cvtColor(*imgptr, *imgptr, method, 0); +} + +static void img_cv_distance_transform (class cv::Mat *imgptr) +{ + class cv::Mat imgtmp; + + /* Get transform */ + cv::distanceTransform(*imgptr, imgtmp, CV_DIST_L2, CV_DIST_MASK_PRECISE); + + /* DistanceTransform gives CV_32F image */ + imgtmp.convertTo(*imgptr, CV_8U); + + /* Cleanup */ + imgtmp.release(); +} + +static void img_cv_threshold (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Threshold *data_cast; + data_cast = (struct Img_Iface_Data_Threshold *)data; + + /* Threshold type */ + int thr_typ; + thr_typ = data_cast->thr_typ; + /* Threshold value */ + int thr_val; + thr_val = data_cast->thr_val; + if (thr_val == -1) { + thr_typ |= cv::THRESH_OTSU; + } + + /* Threshold */ + cv::threshold(*imgptr, *imgptr, thr_val, 0xFF, thr_typ); +} + +/* ----- Histograms */ +static void img_cv_histogram (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Histogram *data_cast; + data_cast = (struct Img_Iface_Data_Histogram *)data; + + /* Contours */ + class cv::Mat *hist; + hist = data_cast->hist_c0; + class cv::Mat *hist_img; + hist_img = data_cast->hist_img; + + /* Write components into cmp_img[] */ + int h_size = 256; + float h_range_arr[] = {0.0, 256.0}; + const float *h_range = {h_range_arr}; + cv::calcHist(imgptr, 1, 0, cv::Mat(), *hist, 1, &h_size, &h_range, + true, false); + + /* Init */ + hist_img->setTo(cv::Scalar(0)); + + /* Normalize the result to [0, hist_img->rows - 1] */ + cv::normalize(*hist, *hist, 0, hist_img->rows - 1, cv::NORM_MINMAX, -1, + cv::Mat()); + + /* Draw hist into hist_img */ + int i; + for(i = 0; i < 256; i++ ) { + cv::line(*hist_img, cv::Point(i, hist_img->rows - 0), + cv::Point(i, hist_img->rows - hist->at(i)), + cv::Scalar(255, 0, 0), 1, 8, 0); + } + + /* Show histogram */ + img_iface_show_hist_c1(); +} + +static void img_cv_histogram_c3 (class cv::Mat *imgptr, void *data) +{ + class cv::Mat cmp_img[3]; + + /* Write components into cmp_img[] */ + cv::split(*imgptr, cmp_img); + + /* Data */ + struct Img_Iface_Data_Histogram *data_cast; + data_cast = (struct Img_Iface_Data_Histogram *)data; + + /* Contours */ + class cv::Mat *hist_c0; + hist_c0 = data_cast->hist_c0; + class cv::Mat *hist_c1; + hist_c1 = data_cast->hist_c1; + class cv::Mat *hist_c2; + hist_c2 = data_cast->hist_c2; + class cv::Mat *hist_img; + hist_img = data_cast->hist_img; + + /* Write components into cmp_img[] */ + int h_size = 256; + float h_range_arr[] = {0.0, 256.0}; + const float *h_range = {h_range_arr}; + cv::calcHist(&cmp_img[0], 1, 0, cv::Mat(), *hist_c0, 1, &h_size, + &h_range, true, false); + cv::calcHist(&cmp_img[1], 1, 0, cv::Mat(), *hist_c1, 1, &h_size, + &h_range, true, false); + cv::calcHist(&cmp_img[2], 1, 0, cv::Mat(), *hist_c2, 1, &h_size, + &h_range, true, false); + + /* Init */ + hist_img->setTo(cv::Scalar(0)); + + /* Normalize the result to [0, hist_img->rows - 1] */ + cv::normalize(*hist_c0, *hist_c0, 0, hist_img->rows - 1, + cv::NORM_MINMAX, -1, cv::Mat()); + cv::normalize(*hist_c1, *hist_c1, 0, hist_img->rows - 1, + cv::NORM_MINMAX, -1, cv::Mat()); + cv::normalize(*hist_c2, *hist_c2, 0, hist_img->rows - 1, + cv::NORM_MINMAX, -1, cv::Mat()); + + /* Draw hist into hist_img */ + int i; + for(i = 0; i < 256; i++ ) { + cv::line(*hist_img, cv::Point(3*i, hist_img->rows - 0), + cv::Point(3*i, + hist_img->rows - hist_c0->at(i)), + cv::Scalar(255, 0, 0), 1, 8, 0); + } + for(i = 0; i < 256; i++ ) { + cv::line(*hist_img, cv::Point(3*i + 1, hist_img->rows - 0), + cv::Point(3*i+1, + hist_img->rows - hist_c1->at(i)), + cv::Scalar(0, 255, 0), 1, 8, 0); + } + for(i = 0; i < 256; i++ ) { + cv::line(*hist_img, cv::Point(3*i + 2, hist_img->rows - 0), + cv::Point(3*i + 2, + hist_img->rows - hist_c2->at(i)), + cv::Scalar(0, 0, 255), 1, 8, 0); + } + + /* Show histogram */ + img_iface_show_hist_c3(); + + /* Cleanup */ + cmp_img[0].release(); + cmp_img[1].release(); + cmp_img[2].release(); +} + +/* ----- Structural analysis and shape descriptors */ +static void img_cv_contours (class cv::Mat *imgptr, void *data) +{ + struct Img_Iface_Data_Contours *data_cast; + class std::vector >> *contours; + class cv::Mat *hierarchy; + + /* Data */ + data_cast = (struct Img_Iface_Data_Contours *)data; + + /* Contours */ + contours = data_cast->contours; + hierarchy = data_cast->hierarchy; + + /* Get contours */ + + cv::findContours(*imgptr, *contours, *hierarchy, CV_RETR_EXTERNAL, + CV_CHAIN_APPROX_SIMPLE); + + /* Set image to black */ + imgptr->setTo(cv::Scalar(0)); + + /* Draw contours in color */ + cv::drawContours(*imgptr, *contours, -1, cv::Scalar(255), 1, 8, + *hierarchy, 1, cvPoint(0, 0)); +} + +static void img_cv_contours_size (void *data) +{ + struct Img_Iface_Data_Contours_Size *data_cast; + class std::vector >> *contours; + int i; + + /* Data */ + data_cast = (struct Img_Iface_Data_Contours_Size *)data; + + /* Contours */ + contours = data_cast->contours; + + /* Get area and perimeter */ + if (data_cast->area) { + for (i = 0; i < (int)contours->size(); i++) { + data_cast->area[i] = cv::contourArea( + (*contours)[i], false); + } + } + if (data_cast->perimeter) { + for (i = 0; i < (int)contours->size(); i++) { + data_cast->perimeter[i] = cv::arcLength( + (*contours)[i], true); + } + } +} + +static void img_cv_bounding_rect (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Bounding_Rect *data_cast; + data_cast = (struct Img_Iface_Data_Bounding_Rect *)data; + + /* Contours */ + class std::vector > *contour; + contour = data_cast->contour; + /* Rotated rectangle */ + class cv::Rect_ *rect; + rect = data_cast->rect; + /* Show rectangle ? */ + bool show; + show = data_cast->show; + + /* Get rectangle */ + *rect = cv::boundingRect(*contour); + + /* Draw rectangle */ + class cv::Point_ vertices[4]; + if (show) { + vertices[0].x = rect->x; + vertices[0].y = rect->y; + vertices[1].x = rect->x + rect->width; + vertices[1].y = rect->y; + vertices[2].x = rect->x + rect->width; + vertices[2].y = rect->y + rect->height; + vertices[3].x = rect->x; + vertices[3].y = rect->y + rect->height; + 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) +{ + /* Data */ + struct Img_Iface_Data_MinARect *data_cast; + data_cast = (struct Img_Iface_Data_MinARect *)data; + + /* Contours */ + class std::vector > *contour; + contour = data_cast->contour; + /* Rotated rectangle */ + class cv::RotatedRect *rect; + rect = data_cast->rect; + /* Show rectangle ? */ + bool show; + show = data_cast->show; + + /* Get rectangle */ + *rect = cv::fitEllipse(*contour); + + /* Draw rectangle */ + class cv::Point_ vertices[4]; + 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_min_area_rect (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_MinARect *data_cast; + data_cast = (struct Img_Iface_Data_MinARect *)data; + + /* Contours */ + class std::vector > *contour; + contour = data_cast->contour; + /* 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_ vertices[4]; + 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); + } +} + +/* ----- Feature detection */ +static void img_cv_hough_circles (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Hough_Circles *data_cast; + data_cast = (struct Img_Iface_Data_Hough_Circles *)data; + + /* Contours */ + class std::vector > *circles; + circles = data_cast->circles; + /* Parameters */ + double dist_min; + double param_1; + double param_2; + int radius_min; + int radius_max; + dist_min = data_cast->dist_min; + param_1 = data_cast->param_1; + param_2 = data_cast->param_2; + radius_min = data_cast->radius_min; + radius_max = data_cast->radius_max; + + /* Get circles */ + cv::HoughCircles(*imgptr, *circles, CV_HOUGH_GRADIENT, 1, dist_min, + param_1, param_2, radius_min, radius_max); + + /* Set image to black */ + imgptr->setTo(cv::Scalar(0)); + + /* Draw circles */ + class cv::Point_ center; + int radius; + int i; + for (i = 0; i < (int)circles->size(); i++) { + center.x = cvRound((*circles)[i][0]); + center.y = cvRound((*circles)[i][1]); + radius = cvRound((*circles)[i][2]); + + /* Draw the circle center */ +/* cv::circle(*imgptr, center, 3, + cv::Scalar(0, 255, 0), -1, 8, 0);*/ + + /* Draw the circle outline */ + cv::circle(*imgptr, center, radius, + cv::Scalar(250), 1, 8, 0); + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/src/img_iface.cpp b/modules/image/src/img_iface.cpp index 3bdcf09..c252916 100644 --- a/modules/image/src/img_iface.cpp +++ b/modules/image/src/img_iface.cpp @@ -1,2010 +1,2010 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* errno */ - #include - /* INFINITY */ - #include - #include - /* snprintf() */ - #include - -/* Standard C++ --------------------------------------------------------------*/ - /* class std::vector */ - #include - -/* Packages ------------------------------------------------------------------*/ - /* openCV */ - #include - -/* Project -------------------------------------------------------------------*/ - /* load_image_file() */ - #include "save.hpp" - /* user_iface_log */ - #include "user_iface.hpp" - -/* Module --------------------------------------------------------------------*/ - /* img_alx_act() */ - #include "img_alx.hpp" - /* img_cv_act() */ - #include "img_cv.hpp" - /* img_orb_act() */ - #include "img_orb.hpp" - /* img_calib3d_act() */ - #include "img_calib3d.hpp" - /* img_zb_act() */ - #include "img_zbar.hpp" - /* img_ocr_act() */ - #include "img_ocr.hpp" - - #include "img_iface.hpp" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define IMG_MEM_SIZE (20) - - # define WIN_NAME_IMG "Image" - # define WIN_NAME_HIST "Hist" - # define WIN_TIMEOUT (500) - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ - char img_ocr_text [OCR_TEXT_MAX]; - struct Img_Iface_ZB_Codes zb_codes; - -/* Static --------------------------------------------------------------------*/ -static class cv::Mat image_copy_old; -static class cv::Mat image_copy_tmp; -static class cv::Mat image_mem [IMG_MEM_SIZE]; -static class cv::Mat image_ref; -static class cv::Mat histogram_c0; -static class cv::Mat histogram_c1; -static class cv::Mat histogram_c2; -static class cv::Mat hist_img_c1; -static class cv::Mat hist_img_c3; -static class std::vector >> contours; -static double area [CONTOURS_MAX]; -static double perimeter [CONTOURS_MAX]; -static class cv::Mat hierarchy; -static class cv::Rect_ rectangle; -static class cv::RotatedRect rectangle_rot; -static class std::vector > circles; -static class cv::Mat intrinsic_mat; -static class cv::Mat dist_coefs; -static class std::vector rvecs; -static class std::vector tvecs; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ - /* img_alx */ -static void img_iface_local_max (void); -static void img_iface_skeleton (void); -static void img_iface_lines_horizontal (void); -static void img_iface_lines_vertical (void); -static void img_iface_mean_horizontal (void); -static void img_iface_mean_vertical (void); -static void img_iface_median_horizontal (void); -static void img_iface_median_vertical (void); - - /* img_cv */ - /* Core: The core functionality */ - /* Pixel */ -static void img_iface_pixel_get (void *data); -static void img_iface_pixel_set (void *data); - /* ROI */ -static void img_iface_set_ROI (void *data); -static void img_iface_set_ROI_2rect (void *data); - /* Operations on Arrays */ -static void img_iface_and_2ref (void); -static void img_iface_not (void); -static void img_iface_or_2ref (void); -static void img_iface_component (void *data); - /* Imgproc: Image processing */ - /* Image filtering */ -static void img_iface_dilate (void *data); -static void img_iface_erode (void *data); -static void img_iface_dilate_erode (void *data); -static void img_iface_erode_dilate (void *data); -static void img_iface_smooth (void *data); -static void img_iface_sobel (void *data); -static void img_iface_border (void *data); - /* Geometric image transformations */ -static void img_iface_mirror (void *data); -static void img_iface_rotate_orto (void *data); -static void img_iface_rotate (void *data); -static void img_iface_rotate_2rect (void *data); - /* Miscellaneous image transformations */ -static void img_iface_adaptive_thr (void *data); -static void img_iface_cvt_color (void *data); -static void img_iface_distance_transform (void); -static void img_iface_threshold (void *data); - /* Histograms */ -static void img_iface_histogram (void *data); -static void img_iface_histogram_c3 (void *data); - /* Structural analysis and shape descriptors */ -static void img_iface_contours (void *data); -static void img_iface_contours_size (void *data); -static void img_iface_bounding_rect (void *data); -static void img_iface_fit_ellipse (void *data); -static void img_iface_min_area_rect (void *data); - /* Feature detection */ -static void img_iface_hough_circles (void *data); - - /* img_orb */ -static void img_iface_align (void); - /* img_calib3d */ -static void img_iface_calibrate (void *data); -static void img_iface_undistort (void *data); - - /* img_zbar */ -static void img_iface_decode (void *data); - /* img_ocr */ -static void img_iface_read (void *data); - - /* img_iface */ -static void img_iface_apply (void); -static void img_iface_discard (void); -static void img_iface_save_mem (void *data); -static void img_iface_load_mem (void *data); -static void img_iface_save_ref (void); - /* save */ -static void img_iface_save_file (void); -static void img_iface_save_update (void); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -void img_iface_init (void) -{ - 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); - hist_img_c3.release(); - hist_img_c3 = cv::Mat::zeros(cv::Size(256 * 3, 100), CV_8UC3); -} - -void img_iface_cleanup_main (void) -{ - int i; - - for (i = 0; i < IMG_MEM_SIZE; i++) { - image_mem[i].release(); - } - image_ref.release(); - - cv::destroyAllWindows(); -} - -void img_iface_load (const char *fpath, const char *fname) -{ - char file_path [FILENAME_MAX]; - char file_name [FILENAME_MAX]; - - /* Init */ - img_iface_init(); - - /* Set file_path */ - if (!fpath) { - snprintf(file_path, FILENAME_MAX, "%s", saved_path); - } else { - snprintf(file_path, FILENAME_MAX, "%s", fpath); - } - - /* Set file_name */ - if (!fname) { - /* Request file name */ - user_iface_fname(file_path, file_name); - } else { - snprintf(file_name, FILENAME_MAX, "%s", fname); - } - - /* Load file */ - errno = 0; - load_image_file(file_path, file_name); - - if (!errno) { - /* Make a static copy of image */ - image.copyTo(image_copy_old); - image.copyTo(image_copy_tmp); - } -} - -void img_iface_cleanup (void) -{ - image_copy_old.release(); - image_copy_tmp.release(); - histogram_c0.release(); - histogram_c1.release(); - histogram_c2.release(); - hist_img_c1.release(); - hist_img_c3.release(); -} - -void img_iface_act (int action, void *data) -{ - switch (action) { - /* img_alx */ - case IMG_IFACE_ACT_LOCAL_MAX: - img_iface_local_max(); - break; - case IMG_IFACE_ACT_SKELETON: - img_iface_skeleton(); - break; - case IMG_IFACE_ACT_LINES_HORIZONTAL: - img_iface_lines_horizontal(); - break; - case IMG_IFACE_ACT_LINES_VERTICAL: - img_iface_lines_vertical(); - break; - case IMG_IFACE_ACT_MEAN_HORIZONTAL: - img_iface_mean_horizontal(); - break; - case IMG_IFACE_ACT_MEAN_VERTICAL: - img_iface_mean_vertical(); - break; - case IMG_IFACE_ACT_MEDIAN_HORIZONTAL: - img_iface_median_horizontal(); - break; - case IMG_IFACE_ACT_MEDIAN_VERTICAL: - img_iface_median_vertical(); - break; - - /* img_cv */ - /* Core: The core functionality */ - /* Pixel */ - case IMG_IFACE_ACT_PIXEL_GET: - img_iface_pixel_get(data); - break; - case IMG_IFACE_ACT_PIXEL_SET: - img_iface_pixel_set(data); - break; - /* ROI */ - case IMG_IFACE_ACT_SET_ROI: - img_iface_set_ROI(data); - break; - case IMG_IFACE_ACT_SET_ROI_2RECT: - img_iface_set_ROI_2rect(data); - break; - /* Operations on Arrays */ - case IMG_IFACE_ACT_AND_2REF: - img_iface_and_2ref(); - break; - case IMG_IFACE_ACT_NOT: - img_iface_not(); - break; - case IMG_IFACE_ACT_OR_2REF: - img_iface_or_2ref(); - break; - case IMG_IFACE_ACT_COMPONENT: - img_iface_component(data); - break; - /* Imgproc: Image processing */ - /* Image filtering */ - case IMG_IFACE_ACT_DILATE: - img_iface_dilate(data); - break; - case IMG_IFACE_ACT_ERODE: - img_iface_erode(data); - break; - case IMG_IFACE_ACT_DILATE_ERODE: - img_iface_dilate_erode(data); - break; - case IMG_IFACE_ACT_ERODE_DILATE: - img_iface_erode_dilate(data); - break; - case IMG_IFACE_ACT_SMOOTH: - img_iface_smooth(data); - break; - case IMG_IFACE_ACT_SOBEL: - img_iface_sobel(data); - break; - case IMG_IFACE_ACT_BORDER: - img_iface_border(data); - break; - /* Geometric image transformations */ - case IMG_IFACE_ACT_MIRROR: - img_iface_mirror(data); - break; - case IMG_IFACE_ACT_ROTATE_ORTO: - img_iface_rotate_orto(data); - break; - case IMG_IFACE_ACT_ROTATE: - img_iface_rotate(data); - break; - case IMG_IFACE_ACT_ROTATE_2RECT: - img_iface_rotate_2rect(data); - break; - /* Miscellaneous image transformations */ - case IMG_IFACE_ACT_ADAPTIVE_THRESHOLD: - img_iface_adaptive_thr(data); - break; - case IMG_IFACE_ACT_CVT_COLOR: - img_iface_cvt_color(data); - break; - case IMG_IFACE_ACT_DISTANCE_TRANSFORM: - img_iface_distance_transform(); - break; - case IMG_IFACE_ACT_THRESHOLD: - img_iface_threshold(data); - break; - /* Histograms */ - case IMG_IFACE_ACT_HISTOGRAM: - img_iface_histogram(data); - break; - case IMG_IFACE_ACT_HISTOGRAM_C3: - img_iface_histogram_c3(data); - break; - /* Structural analysis and shape descriptors */ - case IMG_IFACE_ACT_CONTOURS: - img_iface_contours(data); - break; - case IMG_IFACE_ACT_CONTOURS_SIZE: - img_iface_contours_size(data); - break; - case IMG_IFACE_ACT_BOUNDING_RECT: - img_iface_bounding_rect(data); - break; - case IMG_IFACE_ACT_FIT_ELLIPSE: - img_iface_fit_ellipse(data); - break; - case IMG_IFACE_ACT_MIN_AREA_RECT: - img_iface_min_area_rect(data); - break; - /* Feature detection */ - case IMG_IFACE_ACT_HOUGH_CIRCLES: - img_iface_hough_circles(data); - break; - - /* img_orb */ - case IMG_IFACE_ACT_ALIGN: - img_iface_align(); - break; - - /* img_calib3d */ - case IMG_IFACE_ACT_CALIBRATE: - img_iface_calibrate(data); - break; - case IMG_IFACE_ACT_UNDISTORT: - img_iface_undistort(data); - break; - - /* img_zbar */ - case IMG_IFACE_ACT_DECODE: - img_iface_decode(data); - break; - - /* img_ocr */ - case IMG_IFACE_ACT_READ: - img_iface_read(data); - break; - - /* img_iface */ - case IMG_IFACE_ACT_APPLY: - img_iface_apply(); - break; - case IMG_IFACE_ACT_DISCARD: - img_iface_discard(); - break; - case IMG_IFACE_ACT_SAVE_MEM: - img_iface_save_mem(data); - break; - case IMG_IFACE_ACT_LOAD_MEM: - img_iface_load_mem(data); - break; - case IMG_IFACE_ACT_SAVE_REF: - img_iface_save_ref(); - break; - - /* save */ - case IMG_IFACE_ACT_SAVE_FILE: - img_iface_save_file(); - break; - case IMG_IFACE_ACT_SAVE_UPDT: - img_iface_save_update(); - break; - - default: - /* Invalid action */ - break; - } -} - -void img_iface_show_img (void) -{ - cv::imshow(WIN_NAME_IMG, image_copy_tmp); - cv::waitKey(WIN_TIMEOUT); -} - -void img_iface_show_hist_c1 (void) -{ - cv::imshow(WIN_NAME_HIST, hist_img_c1); - cv::waitKey(WIN_TIMEOUT); -} - -void img_iface_show_hist_c3 (void) -{ - cv::imshow(WIN_NAME_HIST, hist_img_c3); - cv::waitKey(WIN_TIMEOUT); -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -/* img_alx --------------------------------------------------------------------*/ -static void img_iface_local_max (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Local maxima */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_LOCAL_MAX, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Local maxima"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_skeleton (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Skeleton */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_SKELETON, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Skeleton"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_lines_horizontal (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Horizontal lines */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_LINES_HORIZONTAL, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Horizontal lines"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_lines_vertical (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Vertical lines */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_LINES_VERTICAL, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Vertical lines"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_mean_horizontal (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Horizontal lines */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEAN_HORIZONTAL, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Horizontal mean"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_mean_vertical (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Horizontal lines */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEAN_VERTICAL, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Vertical mean"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_median_horizontal (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Horizontal lines */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEDIAN_HORIZONTAL, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Horizontal median"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_median_vertical (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Horizontal lines */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEDIAN_VERTICAL, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Vertical median"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -/* img_cv --------------------------------------------------------------------*/ -/* ----- Core: The core functionality */ -/* ----- ------- Pixel */ -static void img_iface_pixel_get (void *data) -{ - struct Img_Iface_Data_Pixel_Get data_tmp; - struct Img_Iface_Data_Pixel_Get *data_cast; - unsigned char val; - char title [80]; - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - if (!data) { - data_tmp.val = &val; - - /* Ask user */ - 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; - } - - /* Get pixel value */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_PIXEL_GET, data); - - /* Write into log */ - data_cast = (struct Img_Iface_Data_Pixel_Get *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Pixel get: (%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)++; -} - -static void img_iface_pixel_set (void *data) -{ - struct Img_Iface_Data_Pixel_Set data_tmp; - struct Img_Iface_Data_Pixel_Set *data_cast; - char title [80]; - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - if (!data) { - /* Ask user */ - 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); - - snprintf(title, 80, "val:"); - data_tmp.val = user_iface_getint(0, 0, 255, - title, NULL); - - data = (void *)&data_tmp; - } - - /* Set pixel value */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_PIXEL_SET, data); - - /* Write into log */ - data_cast = (struct Img_Iface_Data_Pixel_Set *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Pixel get: (%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)++; -} - -/* ----- ------- ROI */ -static void img_iface_set_ROI (void *data) -{ - struct Img_Iface_Data_SetROI data_tmp; - struct Img_Iface_Data_SetROI *data_cast; - char title [80]; - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Origin: x:"); - data_tmp.rect.x = user_iface_getint(0, 0, - image_copy_tmp.cols, - title, NULL); - - snprintf(title, 80, "Origin: y:"); - data_tmp.rect.y = user_iface_getint(0, 0, - image_copy_tmp.rows, - title, NULL); - - snprintf(title, 80, "Width:"); - data_tmp.rect.width = user_iface_getint(1, - image_copy_tmp.cols - data_tmp.rect.x, - image_copy_tmp.cols - data_tmp.rect.x, - title, NULL); - - snprintf(title, 80, "Height:"); - data_tmp.rect.height = user_iface_getint(1, - image_copy_tmp.rows - data_tmp.rect.y, - image_copy_tmp.rows - data_tmp.rect.y, - title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - data_cast = (struct Img_Iface_Data_SetROI *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "ROI: (%i,%i) w=%i,h=%i", - data_cast->rect.x, - data_cast->rect.y, - data_cast->rect.width, - data_cast->rect.height); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Set ROI */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_SET_ROI, data); -} - -static void img_iface_set_ROI_2rect (void *data) -{ - struct Img_Iface_Data_SetROI data_tmp; - struct Img_Iface_Data_SetROI *data_cast; - - /* Data */ - if (!data) { - data_tmp.rect.x = rectangle.x; - data_tmp.rect.y = rectangle.y; - data_tmp.rect.width = rectangle.width; - data_tmp.rect.height = rectangle.height; - - data = (void *)&data_tmp; - } - - /* Write into log */ - data_cast = (struct Img_Iface_Data_SetROI *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "ROI: (%i,%i) w=%i,h=%i", - data_cast->rect.x, - data_cast->rect.y, - data_cast->rect.width, - data_cast->rect.height); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Set ROI */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_SET_ROI, data); -} - -/* ----- ------- Operations on arrays */ -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_not (void) -{ - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Invert color"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* 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_component (void *data) -{ - /* Must have at least 3 channels */ - if (image_copy_tmp.channels() < 3) { - /* 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; - } - - /* Data */ - struct Img_Iface_Data_Component data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Component:"); - data_tmp.cmp = user_iface_getint(0, 0, - image_copy_tmp.channels() - 1, - title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Component *data_cast; - data_cast = (struct Img_Iface_Data_Component *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Component %i", - data_cast->cmp); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Filter: extract component */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_COMPONENT, data); -} - -/* ----- Imgproc: Image processing */ -/* ----- ------- Image filtering */ -static void img_iface_dilate (void *data) -{ - /* Data */ - struct Img_Iface_Data_Dilate_Erode data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Iterations:"); - data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Dilate_Erode *data_cast; - data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Dilate i=%i", - data_cast->i); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Dilate */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data); -} - -static void img_iface_erode (void *data) -{ - /* Data */ - struct Img_Iface_Data_Dilate_Erode data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Iterations:"); - data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Dilate_Erode *data_cast; - data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Erode i=%i", - data_cast->i); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Erode */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data); -} - -static void img_iface_dilate_erode (void *data) -{ - /* Data */ - struct Img_Iface_Data_Dilate_Erode data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Iterations:"); - data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Dilate_Erode *data_cast; - data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Dilate-erode i=%i", - data_cast->i); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Dilate */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data); - img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data); -} - -static void img_iface_erode_dilate (void *data) -{ - /* Data */ - struct Img_Iface_Data_Dilate_Erode data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Iterations:"); - data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Dilate_Erode *data_cast; - data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Erode-dilate i=%i", - data_cast->i); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Dilate */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data); - img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data); -} - -static void img_iface_smooth (void *data) -{ - /* Data */ - struct Img_Iface_Data_Smooth data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Method: MEAN=1, GAUSS=2, MEDIAN=3"); - data_tmp.method = user_iface_getint(1, 3, 3, title, NULL); - - snprintf(title, 80, "Kernel size: 3, 5, 7, ..."); - data_tmp.ksize = user_iface_getint(3, 3, INFINITY, title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Smooth *data_cast; - data_cast = (struct Img_Iface_Data_Smooth *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Smooth mth=%i [%ix%i]", - data_cast->method, - data_cast->ksize, - data_cast->ksize); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Filter: smooth */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_SMOOTH, data); -} - -static void img_iface_sobel (void *data) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - struct Img_Iface_Data_Sobel data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Order of the derivative x"); - data_tmp.dx = user_iface_getint(0, 1, 10, title, NULL); - - snprintf(title, 80, "Order of the derivative y"); - data_tmp.dy = user_iface_getint(0, 1, 10, title, NULL); - - snprintf(title, 80, "Size of the extended Sobel kernel (-1 -> Scharr"); - data_tmp.ksize = user_iface_getint(-1, 3, 7, title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Sobel *data_cast; - data_cast = (struct Img_Iface_Data_Sobel *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Sobel dx=%i;dy=%i [ks=%i]", - data_cast->dx, - data_cast->dy, - data_cast->ksize); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Filter: sobel */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_SOBEL, data); -} - -static void img_iface_border (void *data) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - struct Img_Iface_Data_Border data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Size"); - data_tmp.size = user_iface_getint(1, 1, 0xF000, title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Border *data_cast; - data_cast = (struct Img_Iface_Data_Border *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Border size=%i", - data_cast->size); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Add border */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_BORDER, data); -} - -/* ----- ------- Geometric image transformations */ -static void img_iface_mirror (void *data) -{ - /* Data */ - struct Img_Iface_Data_Mirror data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Axis: 0=x; 1=y"); - data_tmp.axis = user_iface_getint(0, 1, 1, title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Mirror *data_cast; - data_cast = (struct Img_Iface_Data_Mirror *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Mirror axis: %i", - data_cast->axis); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Mirror */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_MIRROR, data); -} - -static void img_iface_rotate_orto (void *data) -{ - /* Data */ - struct Img_Iface_Data_Rotate_Orto data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Rotate (counterclockwise) n * pi/2 rad; n:"); - data_tmp.n = user_iface_getint(1, 1, 3, title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Rotate_Orto *data_cast; - data_cast = (struct Img_Iface_Data_Rotate_Orto *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Rotate %i * pi/2 rad", - data_cast->n); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Rotate ortogonally */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE_ORTO, data); -} - -static void img_iface_rotate (void *data) -{ - /* Data */ - struct Img_Iface_Data_Rotate data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Center: x:"); - data_tmp.center.x = user_iface_getdbl(0, 0, INFINITY, title, NULL); - - snprintf(title, 80, "Center: y:"); - data_tmp.center.y = user_iface_getdbl(0, 0, INFINITY, title, NULL); - - snprintf(title, 80, "Angle: (deg)"); - data_tmp.angle = user_iface_getdbl(-INFINITY, 0, INFINITY, title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Rotate *data_cast; - data_cast = (struct Img_Iface_Data_Rotate *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Rotate (%.2f,%.2f) %lfº", - data_cast->center.x, - data_cast->center.y, - data_cast->angle); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Rotate ortogonally */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE, data); -} - -static void img_iface_rotate_2rect (void *data) -{ - /* Data */ - struct Img_Iface_Data_Rotate data_tmp; - if (!data) { - data_tmp.center.x = rectangle_rot.center.x; - data_tmp.center.y = rectangle_rot.center.y; - data_tmp.angle = rectangle_rot.angle; - - /* If angle is < -45º, it is taking into acount the incorrect side */ - if (data_tmp.angle < -45.0) { - data_tmp.angle += 90.0; - } - - data = (void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Rotate to rectangle"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Rotate ortogonally */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE, data); -} - -/* ----- ------- Miscellaneous image transformations */ -static void img_iface_adaptive_thr (void *data) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - struct Img_Iface_Data_Adaptive_Thr data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Method: MEAN=0, GAUSS=1"); - data_tmp.method = user_iface_getint(0, 1, 1, title, NULL); - - snprintf(title, 80, "Type: BIN=0, BIN_INV=1"); - data_tmp.thr_typ = user_iface_getint(0, 0, 1, title, NULL); - - snprintf(title, 80, "Kernel size: 3, 5, 7, ..."); - data_tmp.ksize = user_iface_getint(3, 3, INFINITY, title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Adaptive_Thr *data_cast; - data_cast = (struct Img_Iface_Data_Adaptive_Thr *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Threshold mth=%i, typ=%i, ks=%i", - data_cast->method, - data_cast->thr_typ, - data_cast->ksize); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Filter: adaptive threshold */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_ADAPTIVE_THRESHOLD, data); -} - -static void img_iface_cvt_color (void *data) -{ - /* Must have at least 3 channels */ - if (image_copy_tmp.channels() < 3) { - /* 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; - } - - /* Data */ - struct Img_Iface_Data_Cvt_Color data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Method: BGR2GRAY = 6, BGR2HSV = 40"); - data_tmp.method = user_iface_getint(0, 0, - cv::COLOR_COLORCVT_MAX, - title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Cvt_Color *data_cast; - data_cast = (struct Img_Iface_Data_Cvt_Color *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Convert color %i", - data_cast->method); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Filter: BGR to gray */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_CVT_COLOR, data); -} - -static void img_iface_distance_transform (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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, - "Distance transform"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Distance transform */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_DISTANCE_TRANSFORM, NULL); -} - -static void img_iface_threshold (void *data) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - struct Img_Iface_Data_Threshold data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Type: BIN=0, BIN_INV=1, TRUNC=2, TOZ=3, TOZ_INV=4"); - data_tmp.thr_typ = user_iface_getint(0, 0, 4, title, NULL); - - snprintf(title, 80, "Value: 0 to 255 (or -1 for Otsu's algorithm)"); - data_tmp.thr_val = user_iface_getint(-1, 0, 255, title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Threshold *data_cast; - data_cast = (struct Img_Iface_Data_Threshold *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Threshold typ=%i, val=%i", - data_cast->thr_typ, - data_cast->thr_val); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Filter: threshold */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_THRESHOLD, data); -} - -/* ----- ------- Histograms */ -static void img_iface_histogram (void *data) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - struct Img_Iface_Data_Histogram data_tmp; - if (!data) { - data_tmp.hist_c0 = &histogram_c0; - data_tmp.hist_img = &hist_img_c1; - - data = (void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Histogram"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Histogram */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_HISTOGRAM, data); -} - -static void img_iface_histogram_c3 (void *data) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 3) { - /* 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; - } - - /* Data */ - struct Img_Iface_Data_Histogram data_tmp; - if (!data) { - data_tmp.hist_c0 = &histogram_c0; - data_tmp.hist_c1 = &histogram_c1; - data_tmp.hist_c2 = &histogram_c2; - data_tmp.hist_img = &hist_img_c3; - - data = (void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Histogram (3 channels)"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Histogram */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_HISTOGRAM_C3, data); -} - -/* ----- ------- Structural analysis and shape descriptors */ -static void img_iface_contours (void *data) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - struct Img_Iface_Data_Contours data_tmp; - if (!data) { - data_tmp.contours = &contours; - data_tmp.hierarchy = &hierarchy; - - data = (void *)&data_tmp; - } - - /* Contours */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_CONTOURS, data); - - /* Write into log */ - struct Img_Iface_Data_Contours *data_cast; - data_cast = (struct Img_Iface_Data_Contours *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Contours n=%i", - (int)data_cast->contours->size()); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_contours_size (void *data) -{ - /* 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; - } - - /* Contours size */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_CONTOURS_SIZE, data); - - /* Write into log */ - struct Img_Iface_Data_Contours_Size *data_cast; - data_cast = (struct Img_Iface_Data_Contours_Size *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Contours size:"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - int i; - for (i = 0; i < (int)data_cast->contours->size(); i++) { - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "cnt[%i]: A=%lf; P=%lf;", - i, - data_cast->area[i], - data_cast->perimeter[i]); - user_iface_log.lvl[user_iface_log.len] = 2; - (user_iface_log.len)++; - } -} - -static void img_iface_bounding_rect (void *data) -{ - /* Data */ - struct Img_Iface_Data_Bounding_Rect data_tmp; - if (!data) { - if(!contours.size()) { - /* 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; - } - data_tmp.contour = &(contours[0]); - data_tmp.rect = &rectangle; - data_tmp.show = true; - - data = (void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Bounding rectangle"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Enclosing rectangle */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_BOUNDING_RECT, data); -} - -static void img_iface_fit_ellipse (void *data) -{ - /* Data */ - struct Img_Iface_Data_MinARect data_tmp; - if (!data) { - if(!contours.size()) { - /* 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; - } - data_tmp.contour = &(contours[0]); - - data_tmp.rect = &rectangle_rot; - - data = (void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Fit ellipse"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Enclosing rectangle */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_FIT_ELLIPSE, data); -} - -static void img_iface_min_area_rect (void *data) -{ - /* Data */ - struct Img_Iface_Data_MinARect data_tmp; - if (!data) { - if(!contours.size()) { - /* 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; - } - data_tmp.contour = &(contours[0]); - data_tmp.rect = &rectangle_rot; - data_tmp.show = true; - - data = (void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Min area rectangle"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Enclosing rectangle */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_MIN_AREA_RECT, data); -} - -/* ----- ------- Feature detection */ -static void img_iface_hough_circles (void *data) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - struct Img_Iface_Data_Hough_Circles data_tmp; - if (!data) { - data_tmp.circles = &circles; - - /* Ask user */ - char title [80]; - snprintf(title, 80, "Minimum distance:"); - data_tmp.dist_min = user_iface_getdbl(0, 5, INFINITY, title, NULL); - - snprintf(title, 80, "param 1:"); - data_tmp.param_1 = user_iface_getdbl(0, 200, INFINITY, title, NULL); - - snprintf(title, 80, "param 2:"); - data_tmp.param_2 = user_iface_getdbl(0, 100, INFINITY, title, NULL); - - snprintf(title, 80, "Minimum radius"); - data_tmp.radius_min = user_iface_getint(0, 10, INFINITY, title, NULL); - - snprintf(title, 80, "Maximum radius"); - data_tmp.radius_max = user_iface_getint(0, 0, INFINITY, title, NULL); - - data = (void *)&data_tmp; - } - - /* Circles */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_HOUGH_CIRCLES, data); - - /* Write into log */ - struct Img_Iface_Data_Hough_Circles *data_cast; - data_cast = (struct Img_Iface_Data_Hough_Circles *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Circles n=%i", - (int)data_cast->circles->size()); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -/* img_orb -------------------------------------------------------------------*/ -static void img_iface_align (void) -{ - /* Must have defined a reference */ - if (image_ref.empty()) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Reference is NULL"); - 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, - "Align to reference"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Align to reference image_ref */ - img_orb_act(&image_ref, &image_copy_tmp, IMG_ORB_ACT_ALIGN); -} - -/* img_calib3d ---------------------------------------------------------------*/ -static void img_iface_calibrate (void *data) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - struct Img_Iface_Data_Calibrate data_tmp; - if (!data) { - data_tmp.intrinsic_mat = &intrinsic_mat; - data_tmp.dist_coefs = &dist_coefs; - data_tmp.rvecs = &rvecs; - data_tmp.tvecs = &tvecs; - - data = (void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Calibrate"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Contours */ - img_calib3d_act(&image_copy_tmp, IMG_CALIB3D_ACT_CALIBRATE, data); -} - -static void img_iface_undistort (void *data) -{ - /* Data */ - struct Img_Iface_Data_Undistort data_tmp; - if (!data) { - data_tmp.intrinsic_mat = &intrinsic_mat; - data_tmp.dist_coefs = &dist_coefs; - - data = (void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Undistort"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Contours */ - img_calib3d_act(&image_copy_tmp, IMG_CALIB3D_ACT_UNDISTORT, data); -} - -/* img_zbar ------------------------------------------------------------------*/ -static void img_iface_decode (void *data) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - struct Img_Iface_Data_Decode data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Type of code: (0 for all)"); - data_tmp.code_type = (enum zbar::zbar_symbol_type_e) - user_iface_getint(0, 0, INT_MAX, - title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Decode *data_cast; - data_cast = (struct Img_Iface_Data_Decode *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Detect codes c=%i", - data_cast->code_type); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Decode */ - img_zb_act(&image_copy_tmp, IMG_ZB_ACT_DECODE, data); - - /* Results */ - if (!zb_codes.n) { - /* No text found */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! No code detected"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - } else { - /* Write results into log */ - int i; - for (i = 0; i < zb_codes.n; i++) { - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "%s -- '%s'", - zb_codes.arr[i].sym_name, - zb_codes.arr[i].data); - user_iface_log.lvl[user_iface_log.len] = 2; - (user_iface_log.len)++; - } - } -} - -/* img_ocr -------------------------------------------------------------------*/ -static void img_iface_read (void *data) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - struct Img_Iface_Data_Read data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Language: ENG = 0, SPA = 1, CAT = 2"); - data_tmp.lang = user_iface_getint(0, 1, 2, title, NULL); - - snprintf(title, 80, "Config: none = 0, Price = 1"); - data_tmp.conf = user_iface_getint(0, 1, 2, title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Read *data_cast; - data_cast = (struct Img_Iface_Data_Read *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "OCR (lang=%i) [c=%i]", - data_cast->lang, - data_cast->conf); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Adapt image data */ - data_cast->img.data = image_copy_tmp.data; - data_cast->img.width = image_copy_tmp.size().width; - data_cast->img.height = image_copy_tmp.size().height; - data_cast->img.B_per_pix = image_copy_tmp.channels(); - data_cast->img.B_per_line = image_copy_tmp.step1(); - - /* OCR */ - img_ocr_act(IMG_OCR_ACT_READ, data); - - /* Results */ - if (img_ocr_text[0] == '\0') { - /* No text found */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! No text detected"); - user_iface_log.lvl[user_iface_log.len] = 2; - (user_iface_log.len)++; - } -} - -/* img_iface -----------------------------------------------------------------*/ -static void img_iface_apply (void) -{ - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Apply changes"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Write tmp into old */ - image_copy_old.release(); - image_copy_tmp.copyTo(image_copy_old); -} - -static void img_iface_discard (void) -{ - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Discard changes"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Discard tmp image copy */ - image_copy_tmp.release(); - image_copy_old.copyTo(image_copy_tmp); -} - -static void img_iface_save_mem (void *data) -{ - /* Which memory to use */ - int x; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "mem_X; X:"); - x = user_iface_getint(0, 0, IMG_MEM_SIZE - 1, title, NULL); - } else { - x = *(int *)data; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Save to mem_%i", x); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Write into mem */ - image_mem[x].release(); - image_copy_tmp.copyTo(image_mem[x]); -} - -static void img_iface_load_mem (void *data) -{ - /* Which memory to use */ - int x; - if (!data) { - /* Ask user which memory to use */ - char title [80]; - snprintf(title, 80, "mem_X; X:"); - x = user_iface_getint(0, 0, IMG_MEM_SIZE - 1, title, NULL); - } else { - x = *(int *)data; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Load from mem_%i", x); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - if (!image_mem[x].empty()) { - /* Discard tmp image copy */ - image_copy_tmp.release(); - - /* Load from mem */ - image_mem[x].copyTo(image_copy_tmp); - } -} - -static void img_iface_save_ref (void) -{ - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Save to reference"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Write into ref */ - image_ref.release(); - image_copy_tmp.copyTo(image_ref); - image_ref = image_copy_tmp; -} - -/* save ----------------------------------------------------------------------*/ -static void img_iface_save_file (void) -{ - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Save as..."); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Write into image struct (save.c) */ - image.release(); - image_copy_tmp.copyTo(image); - - /* Save into file */ - save_image_file(NULL, NULL); -} - -static void img_iface_save_update (void) -{ - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Save: update img"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Write into image struct (save.c) */ - image.release(); - image_copy_tmp.copyTo(image); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* errno */ + #include + /* INFINITY */ + #include + #include + /* snprintf() */ + #include + +/* Standard C++ --------------------------------------------------------------*/ + /* class std::vector */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* openCV */ + #include + +/* Project -------------------------------------------------------------------*/ + /* load_image_file() */ + #include "save.hpp" + /* user_iface_log */ + #include "user_iface.hpp" + +/* Module --------------------------------------------------------------------*/ + /* img_alx_act() */ + #include "img_alx.hpp" + /* img_cv_act() */ + #include "img_cv.hpp" + /* img_orb_act() */ + #include "img_orb.hpp" + /* img_calib3d_act() */ + #include "img_calib3d.hpp" + /* img_zb_act() */ + #include "img_zbar.hpp" + /* img_ocr_act() */ + #include "img_ocr.hpp" + + #include "img_iface.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define IMG_MEM_SIZE (20) + + # define WIN_NAME_IMG "Image" + # define WIN_NAME_HIST "Hist" + # define WIN_TIMEOUT (500) + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ + char img_ocr_text [OCR_TEXT_MAX]; + struct Img_Iface_ZB_Codes zb_codes; + +/* Static --------------------------------------------------------------------*/ +static class cv::Mat image_copy_old; +static class cv::Mat image_copy_tmp; +static class cv::Mat image_mem [IMG_MEM_SIZE]; +static class cv::Mat image_ref; +static class cv::Mat histogram_c0; +static class cv::Mat histogram_c1; +static class cv::Mat histogram_c2; +static class cv::Mat hist_img_c1; +static class cv::Mat hist_img_c3; +static class std::vector >> contours; +static double area [CONTOURS_MAX]; +static double perimeter [CONTOURS_MAX]; +static class cv::Mat hierarchy; +static class cv::Rect_ rectangle; +static class cv::RotatedRect rectangle_rot; +static class std::vector > circles; +static class cv::Mat intrinsic_mat; +static class cv::Mat dist_coefs; +static class std::vector rvecs; +static class std::vector tvecs; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ + /* img_alx */ +static void img_iface_local_max (void); +static void img_iface_skeleton (void); +static void img_iface_lines_horizontal (void); +static void img_iface_lines_vertical (void); +static void img_iface_mean_horizontal (void); +static void img_iface_mean_vertical (void); +static void img_iface_median_horizontal (void); +static void img_iface_median_vertical (void); + + /* img_cv */ + /* Core: The core functionality */ + /* Pixel */ +static void img_iface_pixel_get (void *data); +static void img_iface_pixel_set (void *data); + /* ROI */ +static void img_iface_set_ROI (void *data); +static void img_iface_set_ROI_2rect (void *data); + /* Operations on Arrays */ +static void img_iface_and_2ref (void); +static void img_iface_not (void); +static void img_iface_or_2ref (void); +static void img_iface_component (void *data); + /* Imgproc: Image processing */ + /* Image filtering */ +static void img_iface_dilate (void *data); +static void img_iface_erode (void *data); +static void img_iface_dilate_erode (void *data); +static void img_iface_erode_dilate (void *data); +static void img_iface_smooth (void *data); +static void img_iface_sobel (void *data); +static void img_iface_border (void *data); + /* Geometric image transformations */ +static void img_iface_mirror (void *data); +static void img_iface_rotate_orto (void *data); +static void img_iface_rotate (void *data); +static void img_iface_rotate_2rect (void *data); + /* Miscellaneous image transformations */ +static void img_iface_adaptive_thr (void *data); +static void img_iface_cvt_color (void *data); +static void img_iface_distance_transform (void); +static void img_iface_threshold (void *data); + /* Histograms */ +static void img_iface_histogram (void *data); +static void img_iface_histogram_c3 (void *data); + /* Structural analysis and shape descriptors */ +static void img_iface_contours (void *data); +static void img_iface_contours_size (void *data); +static void img_iface_bounding_rect (void *data); +static void img_iface_fit_ellipse (void *data); +static void img_iface_min_area_rect (void *data); + /* Feature detection */ +static void img_iface_hough_circles (void *data); + + /* img_orb */ +static void img_iface_align (void); + /* img_calib3d */ +static void img_iface_calibrate (void *data); +static void img_iface_undistort (void *data); + + /* img_zbar */ +static void img_iface_decode (void *data); + /* img_ocr */ +static void img_iface_read (void *data); + + /* img_iface */ +static void img_iface_apply (void); +static void img_iface_discard (void); +static void img_iface_save_mem (void *data); +static void img_iface_load_mem (void *data); +static void img_iface_save_ref (void); + /* save */ +static void img_iface_save_file (void); +static void img_iface_save_update (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void img_iface_init (void) +{ + 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); + hist_img_c3.release(); + hist_img_c3 = cv::Mat::zeros(cv::Size(256 * 3, 100), CV_8UC3); +} + +void img_iface_cleanup_main (void) +{ + int i; + + for (i = 0; i < IMG_MEM_SIZE; i++) { + image_mem[i].release(); + } + image_ref.release(); + + cv::destroyAllWindows(); +} + +void img_iface_load (const char *fpath, const char *fname) +{ + char file_path [FILENAME_MAX]; + char file_name [FILENAME_MAX]; + + /* Init */ + img_iface_init(); + + /* Set file_path */ + if (!fpath) { + snprintf(file_path, FILENAME_MAX, "%s", saved_path); + } else { + snprintf(file_path, FILENAME_MAX, "%s", fpath); + } + + /* Set file_name */ + if (!fname) { + /* Request file name */ + user_iface_fname(file_path, file_name); + } else { + snprintf(file_name, FILENAME_MAX, "%s", fname); + } + + /* Load file */ + errno = 0; + load_image_file(file_path, file_name); + + if (!errno) { + /* Make a static copy of image */ + image.copyTo(image_copy_old); + image.copyTo(image_copy_tmp); + } +} + +void img_iface_cleanup (void) +{ + image_copy_old.release(); + image_copy_tmp.release(); + histogram_c0.release(); + histogram_c1.release(); + histogram_c2.release(); + hist_img_c1.release(); + hist_img_c3.release(); +} + +void img_iface_act (int action, void *data) +{ + switch (action) { + /* img_alx */ + case IMG_IFACE_ACT_LOCAL_MAX: + img_iface_local_max(); + break; + case IMG_IFACE_ACT_SKELETON: + img_iface_skeleton(); + break; + case IMG_IFACE_ACT_LINES_HORIZONTAL: + img_iface_lines_horizontal(); + break; + case IMG_IFACE_ACT_LINES_VERTICAL: + img_iface_lines_vertical(); + break; + case IMG_IFACE_ACT_MEAN_HORIZONTAL: + img_iface_mean_horizontal(); + break; + case IMG_IFACE_ACT_MEAN_VERTICAL: + img_iface_mean_vertical(); + break; + case IMG_IFACE_ACT_MEDIAN_HORIZONTAL: + img_iface_median_horizontal(); + break; + case IMG_IFACE_ACT_MEDIAN_VERTICAL: + img_iface_median_vertical(); + break; + + /* img_cv */ + /* Core: The core functionality */ + /* Pixel */ + case IMG_IFACE_ACT_PIXEL_GET: + img_iface_pixel_get(data); + break; + case IMG_IFACE_ACT_PIXEL_SET: + img_iface_pixel_set(data); + break; + /* ROI */ + case IMG_IFACE_ACT_SET_ROI: + img_iface_set_ROI(data); + break; + case IMG_IFACE_ACT_SET_ROI_2RECT: + img_iface_set_ROI_2rect(data); + break; + /* Operations on Arrays */ + case IMG_IFACE_ACT_AND_2REF: + img_iface_and_2ref(); + break; + case IMG_IFACE_ACT_NOT: + img_iface_not(); + break; + case IMG_IFACE_ACT_OR_2REF: + img_iface_or_2ref(); + break; + case IMG_IFACE_ACT_COMPONENT: + img_iface_component(data); + break; + /* Imgproc: Image processing */ + /* Image filtering */ + case IMG_IFACE_ACT_DILATE: + img_iface_dilate(data); + break; + case IMG_IFACE_ACT_ERODE: + img_iface_erode(data); + break; + case IMG_IFACE_ACT_DILATE_ERODE: + img_iface_dilate_erode(data); + break; + case IMG_IFACE_ACT_ERODE_DILATE: + img_iface_erode_dilate(data); + break; + case IMG_IFACE_ACT_SMOOTH: + img_iface_smooth(data); + break; + case IMG_IFACE_ACT_SOBEL: + img_iface_sobel(data); + break; + case IMG_IFACE_ACT_BORDER: + img_iface_border(data); + break; + /* Geometric image transformations */ + case IMG_IFACE_ACT_MIRROR: + img_iface_mirror(data); + break; + case IMG_IFACE_ACT_ROTATE_ORTO: + img_iface_rotate_orto(data); + break; + case IMG_IFACE_ACT_ROTATE: + img_iface_rotate(data); + break; + case IMG_IFACE_ACT_ROTATE_2RECT: + img_iface_rotate_2rect(data); + break; + /* Miscellaneous image transformations */ + case IMG_IFACE_ACT_ADAPTIVE_THRESHOLD: + img_iface_adaptive_thr(data); + break; + case IMG_IFACE_ACT_CVT_COLOR: + img_iface_cvt_color(data); + break; + case IMG_IFACE_ACT_DISTANCE_TRANSFORM: + img_iface_distance_transform(); + break; + case IMG_IFACE_ACT_THRESHOLD: + img_iface_threshold(data); + break; + /* Histograms */ + case IMG_IFACE_ACT_HISTOGRAM: + img_iface_histogram(data); + break; + case IMG_IFACE_ACT_HISTOGRAM_C3: + img_iface_histogram_c3(data); + break; + /* Structural analysis and shape descriptors */ + case IMG_IFACE_ACT_CONTOURS: + img_iface_contours(data); + break; + case IMG_IFACE_ACT_CONTOURS_SIZE: + img_iface_contours_size(data); + break; + case IMG_IFACE_ACT_BOUNDING_RECT: + img_iface_bounding_rect(data); + break; + case IMG_IFACE_ACT_FIT_ELLIPSE: + img_iface_fit_ellipse(data); + break; + case IMG_IFACE_ACT_MIN_AREA_RECT: + img_iface_min_area_rect(data); + break; + /* Feature detection */ + case IMG_IFACE_ACT_HOUGH_CIRCLES: + img_iface_hough_circles(data); + break; + + /* img_orb */ + case IMG_IFACE_ACT_ALIGN: + img_iface_align(); + break; + + /* img_calib3d */ + case IMG_IFACE_ACT_CALIBRATE: + img_iface_calibrate(data); + break; + case IMG_IFACE_ACT_UNDISTORT: + img_iface_undistort(data); + break; + + /* img_zbar */ + case IMG_IFACE_ACT_DECODE: + img_iface_decode(data); + break; + + /* img_ocr */ + case IMG_IFACE_ACT_READ: + img_iface_read(data); + break; + + /* img_iface */ + case IMG_IFACE_ACT_APPLY: + img_iface_apply(); + break; + case IMG_IFACE_ACT_DISCARD: + img_iface_discard(); + break; + case IMG_IFACE_ACT_SAVE_MEM: + img_iface_save_mem(data); + break; + case IMG_IFACE_ACT_LOAD_MEM: + img_iface_load_mem(data); + break; + case IMG_IFACE_ACT_SAVE_REF: + img_iface_save_ref(); + break; + + /* save */ + case IMG_IFACE_ACT_SAVE_FILE: + img_iface_save_file(); + break; + case IMG_IFACE_ACT_SAVE_UPDT: + img_iface_save_update(); + break; + + default: + /* Invalid action */ + break; + } +} + +void img_iface_show_img (void) +{ + cv::imshow(WIN_NAME_IMG, image_copy_tmp); + cv::waitKey(WIN_TIMEOUT); +} + +void img_iface_show_hist_c1 (void) +{ + cv::imshow(WIN_NAME_HIST, hist_img_c1); + cv::waitKey(WIN_TIMEOUT); +} + +void img_iface_show_hist_c3 (void) +{ + cv::imshow(WIN_NAME_HIST, hist_img_c3); + cv::waitKey(WIN_TIMEOUT); +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +/* img_alx --------------------------------------------------------------------*/ +static void img_iface_local_max (void) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Local maxima */ + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_LOCAL_MAX, NULL); + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Local maxima"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +static void img_iface_skeleton (void) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Skeleton */ + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_SKELETON, NULL); + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Skeleton"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +static void img_iface_lines_horizontal (void) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Horizontal lines */ + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_LINES_HORIZONTAL, NULL); + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Horizontal lines"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +static void img_iface_lines_vertical (void) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Vertical lines */ + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_LINES_VERTICAL, NULL); + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Vertical lines"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +static void img_iface_mean_horizontal (void) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Horizontal lines */ + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEAN_HORIZONTAL, NULL); + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Horizontal mean"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +static void img_iface_mean_vertical (void) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Horizontal lines */ + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEAN_VERTICAL, NULL); + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Vertical mean"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +static void img_iface_median_horizontal (void) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Horizontal lines */ + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEDIAN_HORIZONTAL, NULL); + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Horizontal median"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +static void img_iface_median_vertical (void) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Horizontal lines */ + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEDIAN_VERTICAL, NULL); + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Vertical median"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +/* img_cv --------------------------------------------------------------------*/ +/* ----- Core: The core functionality */ +/* ----- ------- Pixel */ +static void img_iface_pixel_get (void *data) +{ + struct Img_Iface_Data_Pixel_Get data_tmp; + struct Img_Iface_Data_Pixel_Get *data_cast; + unsigned char val; + char title [80]; + + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Data */ + if (!data) { + data_tmp.val = &val; + + /* Ask user */ + 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; + } + + /* Get pixel value */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_PIXEL_GET, data); + + /* Write into log */ + data_cast = (struct Img_Iface_Data_Pixel_Get *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Pixel get: (%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)++; +} + +static void img_iface_pixel_set (void *data) +{ + struct Img_Iface_Data_Pixel_Set data_tmp; + struct Img_Iface_Data_Pixel_Set *data_cast; + char title [80]; + + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Data */ + if (!data) { + /* Ask user */ + 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); + + snprintf(title, 80, "val:"); + data_tmp.val = user_iface_getint(0, 0, 255, + title, NULL); + + data = (void *)&data_tmp; + } + + /* Set pixel value */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_PIXEL_SET, data); + + /* Write into log */ + data_cast = (struct Img_Iface_Data_Pixel_Set *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Pixel get: (%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)++; +} + +/* ----- ------- ROI */ +static void img_iface_set_ROI (void *data) +{ + struct Img_Iface_Data_SetROI data_tmp; + struct Img_Iface_Data_SetROI *data_cast; + char title [80]; + + /* Data */ + if (!data) { + /* Ask user */ + snprintf(title, 80, "Origin: x:"); + data_tmp.rect.x = user_iface_getint(0, 0, + image_copy_tmp.cols, + title, NULL); + + snprintf(title, 80, "Origin: y:"); + data_tmp.rect.y = user_iface_getint(0, 0, + image_copy_tmp.rows, + title, NULL); + + snprintf(title, 80, "Width:"); + data_tmp.rect.width = user_iface_getint(1, + image_copy_tmp.cols - data_tmp.rect.x, + image_copy_tmp.cols - data_tmp.rect.x, + title, NULL); + + snprintf(title, 80, "Height:"); + data_tmp.rect.height = user_iface_getint(1, + image_copy_tmp.rows - data_tmp.rect.y, + image_copy_tmp.rows - data_tmp.rect.y, + title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + data_cast = (struct Img_Iface_Data_SetROI *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "ROI: (%i,%i) w=%i,h=%i", + data_cast->rect.x, + data_cast->rect.y, + data_cast->rect.width, + data_cast->rect.height); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Set ROI */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_SET_ROI, data); +} + +static void img_iface_set_ROI_2rect (void *data) +{ + struct Img_Iface_Data_SetROI data_tmp; + struct Img_Iface_Data_SetROI *data_cast; + + /* Data */ + if (!data) { + data_tmp.rect.x = rectangle.x; + data_tmp.rect.y = rectangle.y; + data_tmp.rect.width = rectangle.width; + data_tmp.rect.height = rectangle.height; + + data = (void *)&data_tmp; + } + + /* Write into log */ + data_cast = (struct Img_Iface_Data_SetROI *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "ROI: (%i,%i) w=%i,h=%i", + data_cast->rect.x, + data_cast->rect.y, + data_cast->rect.width, + data_cast->rect.height); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Set ROI */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_SET_ROI, data); +} + +/* ----- ------- Operations on arrays */ +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_not (void) +{ + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Invert color"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* 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_component (void *data) +{ + /* Must have at least 3 channels */ + if (image_copy_tmp.channels() < 3) { + /* 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; + } + + /* Data */ + struct Img_Iface_Data_Component data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Component:"); + data_tmp.cmp = user_iface_getint(0, 0, + image_copy_tmp.channels() - 1, + title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Component *data_cast; + data_cast = (struct Img_Iface_Data_Component *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Component %i", + data_cast->cmp); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Filter: extract component */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_COMPONENT, data); +} + +/* ----- Imgproc: Image processing */ +/* ----- ------- Image filtering */ +static void img_iface_dilate (void *data) +{ + /* Data */ + struct Img_Iface_Data_Dilate_Erode data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Iterations:"); + data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Dilate_Erode *data_cast; + data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Dilate i=%i", + data_cast->i); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Dilate */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data); +} + +static void img_iface_erode (void *data) +{ + /* Data */ + struct Img_Iface_Data_Dilate_Erode data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Iterations:"); + data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Dilate_Erode *data_cast; + data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Erode i=%i", + data_cast->i); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Erode */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data); +} + +static void img_iface_dilate_erode (void *data) +{ + /* Data */ + struct Img_Iface_Data_Dilate_Erode data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Iterations:"); + data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Dilate_Erode *data_cast; + data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Dilate-erode i=%i", + data_cast->i); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Dilate */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data); + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data); +} + +static void img_iface_erode_dilate (void *data) +{ + /* Data */ + struct Img_Iface_Data_Dilate_Erode data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Iterations:"); + data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Dilate_Erode *data_cast; + data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Erode-dilate i=%i", + data_cast->i); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Dilate */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data); + img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data); +} + +static void img_iface_smooth (void *data) +{ + /* Data */ + struct Img_Iface_Data_Smooth data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Method: MEAN=1, GAUSS=2, MEDIAN=3"); + data_tmp.method = user_iface_getint(1, 3, 3, title, NULL); + + snprintf(title, 80, "Kernel size: 3, 5, 7, ..."); + data_tmp.ksize = user_iface_getint(3, 3, INFINITY, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Smooth *data_cast; + data_cast = (struct Img_Iface_Data_Smooth *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Smooth mth=%i [%ix%i]", + data_cast->method, + data_cast->ksize, + data_cast->ksize); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Filter: smooth */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_SMOOTH, data); +} + +static void img_iface_sobel (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Data */ + struct Img_Iface_Data_Sobel data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Order of the derivative x"); + data_tmp.dx = user_iface_getint(0, 1, 10, title, NULL); + + snprintf(title, 80, "Order of the derivative y"); + data_tmp.dy = user_iface_getint(0, 1, 10, title, NULL); + + snprintf(title, 80, "Size of the extended Sobel kernel (-1 -> Scharr"); + data_tmp.ksize = user_iface_getint(-1, 3, 7, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Sobel *data_cast; + data_cast = (struct Img_Iface_Data_Sobel *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Sobel dx=%i;dy=%i [ks=%i]", + data_cast->dx, + data_cast->dy, + data_cast->ksize); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Filter: sobel */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_SOBEL, data); +} + +static void img_iface_border (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Data */ + struct Img_Iface_Data_Border data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Size"); + data_tmp.size = user_iface_getint(1, 1, 0xF000, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Border *data_cast; + data_cast = (struct Img_Iface_Data_Border *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Border size=%i", + data_cast->size); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Add border */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_BORDER, data); +} + +/* ----- ------- Geometric image transformations */ +static void img_iface_mirror (void *data) +{ + /* Data */ + struct Img_Iface_Data_Mirror data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Axis: 0=x; 1=y"); + data_tmp.axis = user_iface_getint(0, 1, 1, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Mirror *data_cast; + data_cast = (struct Img_Iface_Data_Mirror *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Mirror axis: %i", + data_cast->axis); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Mirror */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_MIRROR, data); +} + +static void img_iface_rotate_orto (void *data) +{ + /* Data */ + struct Img_Iface_Data_Rotate_Orto data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Rotate (counterclockwise) n * pi/2 rad; n:"); + data_tmp.n = user_iface_getint(1, 1, 3, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Rotate_Orto *data_cast; + data_cast = (struct Img_Iface_Data_Rotate_Orto *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Rotate %i * pi/2 rad", + data_cast->n); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Rotate ortogonally */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE_ORTO, data); +} + +static void img_iface_rotate (void *data) +{ + /* Data */ + struct Img_Iface_Data_Rotate data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Center: x:"); + data_tmp.center.x = user_iface_getdbl(0, 0, INFINITY, title, NULL); + + snprintf(title, 80, "Center: y:"); + data_tmp.center.y = user_iface_getdbl(0, 0, INFINITY, title, NULL); + + snprintf(title, 80, "Angle: (deg)"); + data_tmp.angle = user_iface_getdbl(-INFINITY, 0, INFINITY, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Rotate *data_cast; + data_cast = (struct Img_Iface_Data_Rotate *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Rotate (%.2f,%.2f) %lfº", + data_cast->center.x, + data_cast->center.y, + data_cast->angle); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Rotate ortogonally */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE, data); +} + +static void img_iface_rotate_2rect (void *data) +{ + /* Data */ + struct Img_Iface_Data_Rotate data_tmp; + if (!data) { + data_tmp.center.x = rectangle_rot.center.x; + data_tmp.center.y = rectangle_rot.center.y; + data_tmp.angle = rectangle_rot.angle; + + /* If angle is < -45º, it is taking into acount the incorrect side */ + if (data_tmp.angle < -45.0) { + data_tmp.angle += 90.0; + } + + data = (void *)&data_tmp; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Rotate to rectangle"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Rotate ortogonally */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE, data); +} + +/* ----- ------- Miscellaneous image transformations */ +static void img_iface_adaptive_thr (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Data */ + struct Img_Iface_Data_Adaptive_Thr data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Method: MEAN=0, GAUSS=1"); + data_tmp.method = user_iface_getint(0, 1, 1, title, NULL); + + snprintf(title, 80, "Type: BIN=0, BIN_INV=1"); + data_tmp.thr_typ = user_iface_getint(0, 0, 1, title, NULL); + + snprintf(title, 80, "Kernel size: 3, 5, 7, ..."); + data_tmp.ksize = user_iface_getint(3, 3, INFINITY, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Adaptive_Thr *data_cast; + data_cast = (struct Img_Iface_Data_Adaptive_Thr *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Threshold mth=%i, typ=%i, ks=%i", + data_cast->method, + data_cast->thr_typ, + data_cast->ksize); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Filter: adaptive threshold */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ADAPTIVE_THRESHOLD, data); +} + +static void img_iface_cvt_color (void *data) +{ + /* Must have at least 3 channels */ + if (image_copy_tmp.channels() < 3) { + /* 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; + } + + /* Data */ + struct Img_Iface_Data_Cvt_Color data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Method: BGR2GRAY = 6, BGR2HSV = 40"); + data_tmp.method = user_iface_getint(0, 0, + cv::COLOR_COLORCVT_MAX, + title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Cvt_Color *data_cast; + data_cast = (struct Img_Iface_Data_Cvt_Color *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Convert color %i", + data_cast->method); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Filter: BGR to gray */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_CVT_COLOR, data); +} + +static void img_iface_distance_transform (void) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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, + "Distance transform"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Distance transform */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_DISTANCE_TRANSFORM, NULL); +} + +static void img_iface_threshold (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Data */ + struct Img_Iface_Data_Threshold data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Type: BIN=0, BIN_INV=1, TRUNC=2, TOZ=3, TOZ_INV=4"); + data_tmp.thr_typ = user_iface_getint(0, 0, 4, title, NULL); + + snprintf(title, 80, "Value: 0 to 255 (or -1 for Otsu's algorithm)"); + data_tmp.thr_val = user_iface_getint(-1, 0, 255, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Threshold *data_cast; + data_cast = (struct Img_Iface_Data_Threshold *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Threshold typ=%i, val=%i", + data_cast->thr_typ, + data_cast->thr_val); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Filter: threshold */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_THRESHOLD, data); +} + +/* ----- ------- Histograms */ +static void img_iface_histogram (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Data */ + struct Img_Iface_Data_Histogram data_tmp; + if (!data) { + data_tmp.hist_c0 = &histogram_c0; + data_tmp.hist_img = &hist_img_c1; + + data = (void *)&data_tmp; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Histogram"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Histogram */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_HISTOGRAM, data); +} + +static void img_iface_histogram_c3 (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 3) { + /* 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; + } + + /* Data */ + struct Img_Iface_Data_Histogram data_tmp; + if (!data) { + data_tmp.hist_c0 = &histogram_c0; + data_tmp.hist_c1 = &histogram_c1; + data_tmp.hist_c2 = &histogram_c2; + data_tmp.hist_img = &hist_img_c3; + + data = (void *)&data_tmp; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Histogram (3 channels)"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Histogram */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_HISTOGRAM_C3, data); +} + +/* ----- ------- Structural analysis and shape descriptors */ +static void img_iface_contours (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Data */ + struct Img_Iface_Data_Contours data_tmp; + if (!data) { + data_tmp.contours = &contours; + data_tmp.hierarchy = &hierarchy; + + data = (void *)&data_tmp; + } + + /* Contours */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_CONTOURS, data); + + /* Write into log */ + struct Img_Iface_Data_Contours *data_cast; + data_cast = (struct Img_Iface_Data_Contours *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Contours n=%i", + (int)data_cast->contours->size()); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +static void img_iface_contours_size (void *data) +{ + /* 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; + } + + /* Contours size */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_CONTOURS_SIZE, data); + + /* Write into log */ + struct Img_Iface_Data_Contours_Size *data_cast; + data_cast = (struct Img_Iface_Data_Contours_Size *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Contours size:"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + int i; + for (i = 0; i < (int)data_cast->contours->size(); i++) { + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "cnt[%i]: A=%lf; P=%lf;", + i, + data_cast->area[i], + data_cast->perimeter[i]); + user_iface_log.lvl[user_iface_log.len] = 2; + (user_iface_log.len)++; + } +} + +static void img_iface_bounding_rect (void *data) +{ + /* Data */ + struct Img_Iface_Data_Bounding_Rect data_tmp; + if (!data) { + if(!contours.size()) { + /* 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; + } + data_tmp.contour = &(contours[0]); + data_tmp.rect = &rectangle; + data_tmp.show = true; + + data = (void *)&data_tmp; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Bounding rectangle"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Enclosing rectangle */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_BOUNDING_RECT, data); +} + +static void img_iface_fit_ellipse (void *data) +{ + /* Data */ + struct Img_Iface_Data_MinARect data_tmp; + if (!data) { + if(!contours.size()) { + /* 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; + } + data_tmp.contour = &(contours[0]); + + data_tmp.rect = &rectangle_rot; + + data = (void *)&data_tmp; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Fit ellipse"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Enclosing rectangle */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_FIT_ELLIPSE, data); +} + +static void img_iface_min_area_rect (void *data) +{ + /* Data */ + struct Img_Iface_Data_MinARect data_tmp; + if (!data) { + if(!contours.size()) { + /* 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; + } + data_tmp.contour = &(contours[0]); + data_tmp.rect = &rectangle_rot; + data_tmp.show = true; + + data = (void *)&data_tmp; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Min area rectangle"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Enclosing rectangle */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_MIN_AREA_RECT, data); +} + +/* ----- ------- Feature detection */ +static void img_iface_hough_circles (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Data */ + struct Img_Iface_Data_Hough_Circles data_tmp; + if (!data) { + data_tmp.circles = &circles; + + /* Ask user */ + char title [80]; + snprintf(title, 80, "Minimum distance:"); + data_tmp.dist_min = user_iface_getdbl(0, 5, INFINITY, title, NULL); + + snprintf(title, 80, "param 1:"); + data_tmp.param_1 = user_iface_getdbl(0, 200, INFINITY, title, NULL); + + snprintf(title, 80, "param 2:"); + data_tmp.param_2 = user_iface_getdbl(0, 100, INFINITY, title, NULL); + + snprintf(title, 80, "Minimum radius"); + data_tmp.radius_min = user_iface_getint(0, 10, INFINITY, title, NULL); + + snprintf(title, 80, "Maximum radius"); + data_tmp.radius_max = user_iface_getint(0, 0, INFINITY, title, NULL); + + data = (void *)&data_tmp; + } + + /* Circles */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_HOUGH_CIRCLES, data); + + /* Write into log */ + struct Img_Iface_Data_Hough_Circles *data_cast; + data_cast = (struct Img_Iface_Data_Hough_Circles *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Circles n=%i", + (int)data_cast->circles->size()); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +/* img_orb -------------------------------------------------------------------*/ +static void img_iface_align (void) +{ + /* Must have defined a reference */ + if (image_ref.empty()) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! Reference is NULL"); + 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, + "Align to reference"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Align to reference image_ref */ + img_orb_act(&image_ref, &image_copy_tmp, IMG_ORB_ACT_ALIGN); +} + +/* img_calib3d ---------------------------------------------------------------*/ +static void img_iface_calibrate (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Data */ + struct Img_Iface_Data_Calibrate data_tmp; + if (!data) { + data_tmp.intrinsic_mat = &intrinsic_mat; + data_tmp.dist_coefs = &dist_coefs; + data_tmp.rvecs = &rvecs; + data_tmp.tvecs = &tvecs; + + data = (void *)&data_tmp; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Calibrate"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Contours */ + img_calib3d_act(&image_copy_tmp, IMG_CALIB3D_ACT_CALIBRATE, data); +} + +static void img_iface_undistort (void *data) +{ + /* Data */ + struct Img_Iface_Data_Undistort data_tmp; + if (!data) { + data_tmp.intrinsic_mat = &intrinsic_mat; + data_tmp.dist_coefs = &dist_coefs; + + data = (void *)&data_tmp; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Undistort"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Contours */ + img_calib3d_act(&image_copy_tmp, IMG_CALIB3D_ACT_UNDISTORT, data); +} + +/* img_zbar ------------------------------------------------------------------*/ +static void img_iface_decode (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Data */ + struct Img_Iface_Data_Decode data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Type of code: (0 for all)"); + data_tmp.code_type = (enum zbar::zbar_symbol_type_e) + user_iface_getint(0, 0, INT_MAX, + title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Decode *data_cast; + data_cast = (struct Img_Iface_Data_Decode *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Detect codes c=%i", + data_cast->code_type); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Decode */ + img_zb_act(&image_copy_tmp, IMG_ZB_ACT_DECODE, data); + + /* Results */ + if (!zb_codes.n) { + /* No text found */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! No code detected"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + } else { + /* Write results into log */ + int i; + for (i = 0; i < zb_codes.n; i++) { + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "%s -- '%s'", + zb_codes.arr[i].sym_name, + zb_codes.arr[i].data); + user_iface_log.lvl[user_iface_log.len] = 2; + (user_iface_log.len)++; + } + } +} + +/* img_ocr -------------------------------------------------------------------*/ +static void img_iface_read (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Data */ + struct Img_Iface_Data_Read data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Language: ENG = 0, SPA = 1, CAT = 2"); + data_tmp.lang = user_iface_getint(0, 1, 2, title, NULL); + + snprintf(title, 80, "Config: none = 0, Price = 1"); + data_tmp.conf = user_iface_getint(0, 1, 2, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Read *data_cast; + data_cast = (struct Img_Iface_Data_Read *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "OCR (lang=%i) [c=%i]", + data_cast->lang, + data_cast->conf); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Adapt image data */ + data_cast->img.data = image_copy_tmp.data; + data_cast->img.width = image_copy_tmp.size().width; + data_cast->img.height = image_copy_tmp.size().height; + data_cast->img.B_per_pix = image_copy_tmp.channels(); + data_cast->img.B_per_line = image_copy_tmp.step1(); + + /* OCR */ + img_ocr_act(IMG_OCR_ACT_READ, data); + + /* Results */ + if (img_ocr_text[0] == '\0') { + /* No text found */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! No text detected"); + user_iface_log.lvl[user_iface_log.len] = 2; + (user_iface_log.len)++; + } +} + +/* img_iface -----------------------------------------------------------------*/ +static void img_iface_apply (void) +{ + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Apply changes"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Write tmp into old */ + image_copy_old.release(); + image_copy_tmp.copyTo(image_copy_old); +} + +static void img_iface_discard (void) +{ + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Discard changes"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Discard tmp image copy */ + image_copy_tmp.release(); + image_copy_old.copyTo(image_copy_tmp); +} + +static void img_iface_save_mem (void *data) +{ + /* Which memory to use */ + int x; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "mem_X; X:"); + x = user_iface_getint(0, 0, IMG_MEM_SIZE - 1, title, NULL); + } else { + x = *(int *)data; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Save to mem_%i", x); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Write into mem */ + image_mem[x].release(); + image_copy_tmp.copyTo(image_mem[x]); +} + +static void img_iface_load_mem (void *data) +{ + /* Which memory to use */ + int x; + if (!data) { + /* Ask user which memory to use */ + char title [80]; + snprintf(title, 80, "mem_X; X:"); + x = user_iface_getint(0, 0, IMG_MEM_SIZE - 1, title, NULL); + } else { + x = *(int *)data; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Load from mem_%i", x); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + if (!image_mem[x].empty()) { + /* Discard tmp image copy */ + image_copy_tmp.release(); + + /* Load from mem */ + image_mem[x].copyTo(image_copy_tmp); + } +} + +static void img_iface_save_ref (void) +{ + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Save to reference"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Write into ref */ + image_ref.release(); + image_copy_tmp.copyTo(image_ref); + image_ref = image_copy_tmp; +} + +/* save ----------------------------------------------------------------------*/ +static void img_iface_save_file (void) +{ + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Save as..."); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Write into image struct (save.c) */ + image.release(); + image_copy_tmp.copyTo(image); + + /* Save into file */ + save_image_file(NULL, NULL); +} + +static void img_iface_save_update (void) +{ + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Save: update img"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Write into image struct (save.c) */ + image.release(); + image_copy_tmp.copyTo(image); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/src/img_ocr.c b/modules/image/src/img_ocr.c index 5aba51e..c406abf 100644 --- a/modules/image/src/img_ocr.c +++ b/modules/image/src/img_ocr.c @@ -1,128 +1,128 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* INT_MAX */ - #include - #include - /* snprintf() & FILENAME_MAX */ - #include - -/* Packages ------------------------------------------------------------------*/ - /* OCR Tesseract */ - #include - -/* Project -------------------------------------------------------------------*/ - /* share_path */ - #include "about.h" - -/* Module --------------------------------------------------------------------*/ - /* data & img_ocr_text & OCR_TEXT_MAX */ - #include "img_iface.h" - - #include "img_ocr.h" - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void img_ocr_read (void *data); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void img_ocr_act (int action, void *data) -{ - switch (action) { - case IMG_OCR_ACT_READ: - img_ocr_read(data); - break; - } -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void img_ocr_read (void *data) -{ - struct TessBaseAPI *handle_ocr; - - /* Data */ - struct Img_Iface_Data_Read *data_cast; - data_cast = (struct Img_Iface_Data_Read *)data; - - /* Language */ - int lang; - char lang_str [20 + 1]; - lang = data_cast->lang; - switch (lang) { - case IMG_IFACE_OCR_LANG_ENG: - sprintf(lang_str, "eng"); - break; - case IMG_IFACE_OCR_LANG_SPA: - sprintf(lang_str, "spa"); - break; - case IMG_IFACE_OCR_LANG_CAT: - sprintf(lang_str, "cat"); - break; - case IMG_IFACE_OCR_LANG_DIGITS: - sprintf(lang_str, "digits"); - break; - case IMG_IFACE_OCR_LANG_DIGITS_COMMA: - sprintf(lang_str, "digits_comma"); - break; - } - - /* Config file */ - int conf; - char conf_str [FILENAME_MAX]; - conf = data_cast->conf; - switch (conf) { - case IMG_IFACE_OCR_CONF_PRICE: - snprintf(conf_str, 6, "%s/%s", share_path, "price"); - break; - } - - /* init OCR */ - handle_ocr = TessBaseAPICreate(); - TessBaseAPIInit2(handle_ocr, NULL, lang_str, -#ifdef OEM_LSTM_ONLY - OEM_LSTM_ONLY); -#else - OEM_DEFAULT); -#endif -// OEM_TESSERACT_LSTM_COMBINED); - if (conf) { - /* Configure OCR (whitelist chars) */ - TessBaseAPIReadConfigFile(handle_ocr, conf_str); - } - - /* scan image for text */ - TessBaseAPISetImage(handle_ocr, data_cast->img.data, - data_cast->img.width, data_cast->img.height, - data_cast->img.B_per_pix, - data_cast->img.B_per_line); - TessBaseAPIRecognize(handle_ocr, NULL); - char *txt; - txt = TessBaseAPIGetUTF8Text(handle_ocr); - - /* Copy text to global variable */ - snprintf(img_ocr_text, OCR_TEXT_MAX, "%s", txt); - - /* cleanup */ - TessDeleteText(txt); - TessBaseAPIEnd(handle_ocr); - TessBaseAPIDelete(handle_ocr); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* INT_MAX */ + #include + #include + /* snprintf() & FILENAME_MAX */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* OCR Tesseract */ + #include + +/* Project -------------------------------------------------------------------*/ + /* share_path */ + #include "about.h" + +/* Module --------------------------------------------------------------------*/ + /* data & img_ocr_text & OCR_TEXT_MAX */ + #include "img_iface.h" + + #include "img_ocr.h" + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void img_ocr_read (void *data); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void img_ocr_act (int action, void *data) +{ + switch (action) { + case IMG_OCR_ACT_READ: + img_ocr_read(data); + break; + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void img_ocr_read (void *data) +{ + struct TessBaseAPI *handle_ocr; + + /* Data */ + struct Img_Iface_Data_Read *data_cast; + data_cast = (struct Img_Iface_Data_Read *)data; + + /* Language */ + int lang; + char lang_str [20 + 1]; + lang = data_cast->lang; + switch (lang) { + case IMG_IFACE_OCR_LANG_ENG: + sprintf(lang_str, "eng"); + break; + case IMG_IFACE_OCR_LANG_SPA: + sprintf(lang_str, "spa"); + break; + case IMG_IFACE_OCR_LANG_CAT: + sprintf(lang_str, "cat"); + break; + case IMG_IFACE_OCR_LANG_DIGITS: + sprintf(lang_str, "digits"); + break; + case IMG_IFACE_OCR_LANG_DIGITS_COMMA: + sprintf(lang_str, "digits_comma"); + break; + } + + /* Config file */ + int conf; + char conf_str [FILENAME_MAX]; + conf = data_cast->conf; + switch (conf) { + case IMG_IFACE_OCR_CONF_PRICE: + snprintf(conf_str, 6, "%s/%s", share_path, "price"); + break; + } + + /* init OCR */ + handle_ocr = TessBaseAPICreate(); + TessBaseAPIInit2(handle_ocr, NULL, lang_str, +#ifdef OEM_LSTM_ONLY + OEM_LSTM_ONLY); +#else + OEM_DEFAULT); +#endif +// OEM_TESSERACT_LSTM_COMBINED); + if (conf) { + /* Configure OCR (whitelist chars) */ + TessBaseAPIReadConfigFile(handle_ocr, conf_str); + } + + /* scan image for text */ + TessBaseAPISetImage(handle_ocr, data_cast->img.data, + data_cast->img.width, data_cast->img.height, + data_cast->img.B_per_pix, + data_cast->img.B_per_line); + TessBaseAPIRecognize(handle_ocr, NULL); + char *txt; + txt = TessBaseAPIGetUTF8Text(handle_ocr); + + /* Copy text to global variable */ + snprintf(img_ocr_text, OCR_TEXT_MAX, "%s", txt); + + /* cleanup */ + TessDeleteText(txt); + TessBaseAPIEnd(handle_ocr); + TessBaseAPIDelete(handle_ocr); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/src/img_orb.cpp b/modules/image/src/img_orb.cpp index f62203c..6d91085 100644 --- a/modules/image/src/img_orb.cpp +++ b/modules/image/src/img_orb.cpp @@ -1,126 +1,126 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C++ --------------------------------------------------------------*/ - /* class std::vector */ - #include - -/* Standard C ----------------------------------------------------------------*/ - /* snprintf() */ - #include - -/* Packages ------------------------------------------------------------------*/ - /* opencv */ - #include - #include - -/* Module -------------------------------------------------------------------*/ - #include "img_orb.hpp" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define MAX_FEATURES (50000) - # define GOOD_MATCH_P (0.25) - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void img_orb_align (class cv::Mat *img_0, - class cv::Mat *img_1); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void img_orb_act (class cv::Mat *img_ref, - class cv::Mat *imgptr, int action) -{ - switch (action) { - case IMG_ORB_ACT_ALIGN: - img_orb_align(img_ref, imgptr); - break; - } -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void img_orb_align (class cv::Mat *img_0, - class cv::Mat *img_1) -{ - /* Variables to store keypoints & descriptors */ - class std::vector keypoints_0; - class std::vector keypoints_1; - class cv::Mat descriptors_0; - class cv::Mat descriptors_1; - - /* Detect ORB features & compute descriptors */ -#if 1 - /* OpenCV 2.x */ - class cv::ORB orb; - orb(*img_0, cv::Mat(), keypoints_0, descriptors_0); - orb(*img_1, cv::Mat(), keypoints_1, descriptors_1); -#else - /* OpenCV 3.x */ - class cv::Ptr orb; - orb = cv::ORB::create(MAX_FEATURES); - orb->detectAndCompute(*img_0, cv::Mat(), keypoints_0, descriptors_0); - orb->detectAndCompute(*img_1, cv::Mat(), keypoints_1, descriptors_1); -#endif - - - /* Match structures */ - class std::vector matches; - cv::Ptr matcher; - matcher = cv::DescriptorMatcher::create("BruteForce-Hamming"); - matcher->match(descriptors_1, descriptors_0, matches, cv::Mat()); - - /* Sort matches by score */ - std::sort(matches.begin(), matches.end()); - - /* Remove not so good matches */ - int good_matches; - good_matches = GOOD_MATCH_P * matches.size(); - matches.erase(matches.begin() + good_matches, matches.end()); - - /* Draw top matches */ - class cv::Mat img_matches; - cv::drawMatches(*img_1, keypoints_1, *img_0, keypoints_0, matches, - img_matches); - cv::imwrite("matches.jpg", img_matches); - - /* Extract location of good matches */ - class std::vector > points_0; - class std::vector > points_1; - int i; - for (i = 0; i < (int)matches.size(); i++) { - points_1.push_back(keypoints_1[matches[i].queryIdx].pt); - points_0.push_back(keypoints_0[matches[i].trainIdx].pt); - } - - /* Find homography */ - class cv::Mat img_hg; - img_hg = cv::findHomography(points_1, points_0, CV_RANSAC); - - /* Use homography to warp image */ - class cv::Mat img_align; - cv::warpPerspective(*img_1, img_align, img_hg, img_0->size()); - - /* Write img_align into img_1 */ - *img_1 = img_align; - img_align.release(); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C++ --------------------------------------------------------------*/ + /* class std::vector */ + #include + +/* Standard C ----------------------------------------------------------------*/ + /* snprintf() */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* opencv */ + #include + #include + +/* Module -------------------------------------------------------------------*/ + #include "img_orb.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define MAX_FEATURES (50000) + # define GOOD_MATCH_P (0.25) + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void img_orb_align (class cv::Mat *img_0, + class cv::Mat *img_1); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void img_orb_act (class cv::Mat *img_ref, + class cv::Mat *imgptr, int action) +{ + switch (action) { + case IMG_ORB_ACT_ALIGN: + img_orb_align(img_ref, imgptr); + break; + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void img_orb_align (class cv::Mat *img_0, + class cv::Mat *img_1) +{ + /* Variables to store keypoints & descriptors */ + class std::vector keypoints_0; + class std::vector keypoints_1; + class cv::Mat descriptors_0; + class cv::Mat descriptors_1; + + /* Detect ORB features & compute descriptors */ +#if 1 + /* OpenCV 2.x */ + class cv::ORB orb; + orb(*img_0, cv::Mat(), keypoints_0, descriptors_0); + orb(*img_1, cv::Mat(), keypoints_1, descriptors_1); +#else + /* OpenCV 3.x */ + class cv::Ptr orb; + orb = cv::ORB::create(MAX_FEATURES); + orb->detectAndCompute(*img_0, cv::Mat(), keypoints_0, descriptors_0); + orb->detectAndCompute(*img_1, cv::Mat(), keypoints_1, descriptors_1); +#endif + + + /* Match structures */ + class std::vector matches; + cv::Ptr matcher; + matcher = cv::DescriptorMatcher::create("BruteForce-Hamming"); + matcher->match(descriptors_1, descriptors_0, matches, cv::Mat()); + + /* Sort matches by score */ + std::sort(matches.begin(), matches.end()); + + /* Remove not so good matches */ + int good_matches; + good_matches = GOOD_MATCH_P * matches.size(); + matches.erase(matches.begin() + good_matches, matches.end()); + + /* Draw top matches */ + class cv::Mat img_matches; + cv::drawMatches(*img_1, keypoints_1, *img_0, keypoints_0, matches, + img_matches); + cv::imwrite("matches.jpg", img_matches); + + /* Extract location of good matches */ + class std::vector > points_0; + class std::vector > points_1; + int i; + for (i = 0; i < (int)matches.size(); i++) { + points_1.push_back(keypoints_1[matches[i].queryIdx].pt); + points_0.push_back(keypoints_0[matches[i].trainIdx].pt); + } + + /* Find homography */ + class cv::Mat img_hg; + img_hg = cv::findHomography(points_1, points_0, CV_RANSAC); + + /* Use homography to warp image */ + class cv::Mat img_align; + cv::warpPerspective(*img_1, img_align, img_hg, img_0->size()); + + /* Write img_align into img_1 */ + *img_1 = img_align; + img_align.release(); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/src/img_zbar.cpp b/modules/image/src/img_zbar.cpp index 083093b..5a976a6 100644 --- a/modules/image/src/img_zbar.cpp +++ b/modules/image/src/img_zbar.cpp @@ -1,102 +1,102 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* INT_MAX */ - #include - #include - /* snprintf() */ - #include - -/* Packages ------------------------------------------------------------------*/ - /* opencv */ - #include - /* zbar */ - #include - -/* Module --------------------------------------------------------------------*/ - /* data & zb_codes */ - #include "img_iface.hpp" - - #include "img_zbar.hpp" - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void img_zb_decode (class cv::Mat *imgptr, void *data); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void img_zb_act (class cv::Mat *imgptr, int action, void *data) -{ - switch (action) { - case IMG_ZB_ACT_DECODE: - img_zb_decode(imgptr, data); - break; - } -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void img_zb_decode (class cv::Mat *imgptr, void *data) -{ - struct zbar::zbar_image_scanner_s *scanner; - struct zbar::zbar_image_s *image_zb; - const struct zbar::zbar_symbol_s *symbol; - - /* Type of code to scan */ - enum zbar::zbar_symbol_type_e code_type; - code_type = ((struct Img_Iface_Data_Decode *)data)->code_type; - - /* create & configure a reader */ - scanner = zbar::zbar_image_scanner_create(); - zbar::zbar_image_scanner_set_config(scanner, code_type, - zbar::ZBAR_CFG_ENABLE, 1); - - /* wrap image data */ - image_zb = zbar::zbar_image_create(); - zbar::zbar_image_set_format(image_zb, *(int*)"GREY"); - zbar::zbar_image_set_size(image_zb, imgptr->cols, imgptr->rows); - zbar::zbar_image_set_data(image_zb, (void *)(imgptr->data), - (imgptr->cols * imgptr->rows), - NULL); - - /* scan the image for barcodes */ - int i; - zb_codes.n = zbar::zbar_scan_image(scanner, image_zb); - if (zb_codes.n) { - /* extract results */ - symbol = zbar::zbar_image_first_symbol(image_zb); - for (i = 0; i < ZB_CODES_MAX && symbol; i++) { - /* Write results into array */ - zb_codes.arr[i].type = zbar::zbar_symbol_get_type(symbol); - snprintf(zb_codes.arr[i].sym_name, 80, "%s", - zbar::zbar_get_symbol_name( - zb_codes.arr[i].type)); - snprintf(zb_codes.arr[i].data, ZBAR_LEN_MAX, "%s", - zbar::zbar_symbol_get_data(symbol)); - - /* Load next symbol */ - symbol = zbar::zbar_symbol_next(symbol); - } - } - - /* clean up */ - zbar::zbar_image_destroy(image_zb); - zbar::zbar_image_scanner_destroy(scanner); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* INT_MAX */ + #include + #include + /* snprintf() */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* opencv */ + #include + /* zbar */ + #include + +/* Module --------------------------------------------------------------------*/ + /* data & zb_codes */ + #include "img_iface.hpp" + + #include "img_zbar.hpp" + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void img_zb_decode (class cv::Mat *imgptr, void *data); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void img_zb_act (class cv::Mat *imgptr, int action, void *data) +{ + switch (action) { + case IMG_ZB_ACT_DECODE: + img_zb_decode(imgptr, data); + break; + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void img_zb_decode (class cv::Mat *imgptr, void *data) +{ + struct zbar::zbar_image_scanner_s *scanner; + struct zbar::zbar_image_s *image_zb; + const struct zbar::zbar_symbol_s *symbol; + + /* Type of code to scan */ + enum zbar::zbar_symbol_type_e code_type; + code_type = ((struct Img_Iface_Data_Decode *)data)->code_type; + + /* create & configure a reader */ + scanner = zbar::zbar_image_scanner_create(); + zbar::zbar_image_scanner_set_config(scanner, code_type, + zbar::ZBAR_CFG_ENABLE, 1); + + /* wrap image data */ + image_zb = zbar::zbar_image_create(); + zbar::zbar_image_set_format(image_zb, *(int*)"GREY"); + zbar::zbar_image_set_size(image_zb, imgptr->cols, imgptr->rows); + zbar::zbar_image_set_data(image_zb, (void *)(imgptr->data), + (imgptr->cols * imgptr->rows), + NULL); + + /* scan the image for barcodes */ + int i; + zb_codes.n = zbar::zbar_scan_image(scanner, image_zb); + if (zb_codes.n) { + /* extract results */ + symbol = zbar::zbar_image_first_symbol(image_zb); + for (i = 0; i < ZB_CODES_MAX && symbol; i++) { + /* Write results into array */ + zb_codes.arr[i].type = zbar::zbar_symbol_get_type(symbol); + snprintf(zb_codes.arr[i].sym_name, 80, "%s", + zbar::zbar_get_symbol_name( + zb_codes.arr[i].type)); + snprintf(zb_codes.arr[i].data, ZBAR_LEN_MAX, "%s", + zbar::zbar_symbol_get_data(symbol)); + + /* Load next symbol */ + symbol = zbar::zbar_symbol_next(symbol); + } + } + + /* clean up */ + zbar::zbar_image_destroy(image_zb); + zbar::zbar_image_scanner_destroy(scanner); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/menu/inc/menu_clui.h b/modules/menu/inc/menu_clui.h index ae982a8..49de943 100644 --- a/modules/menu/inc/menu_clui.h +++ b/modules/menu/inc/menu_clui.h @@ -1,27 +1,27 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_MENU_CLUI_H - # define VA_MENU_CLUI_H - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void menu_clui (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* menu_clui.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_MENU_CLUI_H + # define VA_MENU_CLUI_H + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void menu_clui (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* menu_clui.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/menu/inc/menu_iface.h b/modules/menu/inc/menu_iface.h index 320cbd4..09a1164 100644 --- a/modules/menu/inc/menu_iface.h +++ b/modules/menu/inc/menu_iface.h @@ -1,43 +1,43 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_MENU_IFACE_H - # define VA_MENU_IFACE_H - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Menu_Iface_Mode { - MENU_IFACE_FOO = 0, - MENU_IFACE_CLUI, - MENU_IFACE_TUI - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern int menu_iface_mode; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void menu_iface (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* menu_iface.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_MENU_IFACE_H + # define VA_MENU_IFACE_H + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Menu_Iface_Mode { + MENU_IFACE_FOO = 0, + MENU_IFACE_CLUI, + MENU_IFACE_TUI + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +extern int menu_iface_mode; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void menu_iface (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* menu_iface.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/menu/inc/menu_iface.hpp b/modules/menu/inc/menu_iface.hpp index a1fbb25..1b5b60c 100644 --- a/modules/menu/inc/menu_iface.hpp +++ b/modules/menu/inc/menu_iface.hpp @@ -1,55 +1,55 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_MENU_IFACE_HPP - # define VA_MENU_IFACE_HPP - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Menu_Iface_Mode { - MENU_IFACE_FOO = 0, - MENU_IFACE_CLUI, - MENU_IFACE_TUI - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - extern int menu_iface_mode; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void menu_iface (void); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* menu_iface.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_MENU_IFACE_HPP + # define VA_MENU_IFACE_HPP + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Menu_Iface_Mode { + MENU_IFACE_FOO = 0, + MENU_IFACE_CLUI, + MENU_IFACE_TUI + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern int menu_iface_mode; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void menu_iface (void); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* menu_iface.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/menu/inc/menu_tui.h b/modules/menu/inc/menu_tui.h index 5ccaebd..74cfd5f 100644 --- a/modules/menu/inc/menu_tui.h +++ b/modules/menu/inc/menu_tui.h @@ -1,27 +1,27 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_MENU_TUI_H - # define VA_MENU_TUI_H - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void menu_tui (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* menu_tui.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_MENU_TUI_H + # define VA_MENU_TUI_H + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void menu_tui (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* menu_tui.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/menu/inc/parser.h b/modules/menu/inc/parser.h index 836385c..a29afcd 100644 --- a/modules/menu/inc/parser.h +++ b/modules/menu/inc/parser.h @@ -1,27 +1,27 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PARSER_H - # define VA_PARSER_H - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void parser (int argc, char *argv[]); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* parser.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PARSER_H + # define VA_PARSER_H + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void parser (int argc, char *argv[]); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* parser.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/menu/inc/parser.hpp b/modules/menu/inc/parser.hpp index ff40d1f..700a0aa 100644 --- a/modules/menu/inc/parser.hpp +++ b/modules/menu/inc/parser.hpp @@ -1,39 +1,39 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PARSER_HPP - # define VA_PARSER_HPP - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void parser (int argc, char *argv[]); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* parser.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PARSER_HPP + # define VA_PARSER_HPP + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void parser (int argc, char *argv[]); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* parser.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/menu/src/menu_clui.c b/modules/menu/src/menu_clui.c index 49c58e2..db2a11e 100644 --- a/modules/menu/src/menu_clui.c +++ b/modules/menu/src/menu_clui.c @@ -1,116 +1,116 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - #include "alx_input.h" - - #include "about.h" -// #include "save.h" - /* start_switch() */ - #include "start.h" - - #include "menu_clui.h" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define BUFF_SIZE (1024) - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -//static void menu_clui_rand (void); -//static void menu_clui_custom (void); -static void menu_clui_load (void); -static void menu_clui_start (void); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void menu_clui (void) -{ - char buff [BUFF_SIZE]; - char ch; - - ch = 'n'; - printf("Read 'Disclaimer of warranty'? (yes/NO): "); - fgets(buff, BUFF_SIZE, stdin); - sscanf(buff, " %c", &ch); - if (ch == 'y' || ch == 'Y') { - puts (" >yes"); - print_share_file(SHARE_DISCLAIMER); - } else { - puts (" >NO"); - } - - ch = 'n'; - printf("Read 'License'? (yes/NO): "); - fgets(buff, BUFF_SIZE, stdin); - sscanf(buff, " %c", &ch); - if (ch == 'y' || ch == 'Y') { - puts (" >yes"); - print_share_file(SHARE_LICENSE); - } else { - puts (" >NO"); - } -#if 0 - printf("Game interface? (NCURSES/text): "); - scanf(" %c%*s ", &ch); - if (ch == 't' || ch == 'T') { - puts (" >text"); - // FIXME - } else { - puts (" >NCURSES"); - // FIXME - } -#endif - menu_clui_load(); -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void menu_clui_load (void) -{ -#if 0 - /* File name */ // FIXME - alx_w_getfname(USER_SAVED_DIR, saved_name, "File name:", saved_name, NULL); -#endif - menu_clui_start(); -} - -static void menu_clui_start (void) -{ - puts(" >>START:"); - start_switch(); - - char buff [BUFF_SIZE]; - char ch; - - ch = 'm'; - printf("Load again? (MENU/load/exit): "); - fgets(buff, BUFF_SIZE, stdin); - sscanf(buff, " %c", &ch); - if (ch == 'p' || ch == 'P') { - puts (" >load"); - menu_clui_start(); - } else if (ch == 'e' || ch == 'E') { - puts (" >exit!"); - } else { - puts (" >MENU"); - menu_clui(); - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + #include "alx_input.h" + + #include "about.h" +// #include "save.h" + /* start_switch() */ + #include "start.h" + + #include "menu_clui.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define BUFF_SIZE (1024) + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +//static void menu_clui_rand (void); +//static void menu_clui_custom (void); +static void menu_clui_load (void); +static void menu_clui_start (void); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void menu_clui (void) +{ + char buff [BUFF_SIZE]; + char ch; + + ch = 'n'; + printf("Read 'Disclaimer of warranty'? (yes/NO): "); + fgets(buff, BUFF_SIZE, stdin); + sscanf(buff, " %c", &ch); + if (ch == 'y' || ch == 'Y') { + puts (" >yes"); + print_share_file(SHARE_DISCLAIMER); + } else { + puts (" >NO"); + } + + ch = 'n'; + printf("Read 'License'? (yes/NO): "); + fgets(buff, BUFF_SIZE, stdin); + sscanf(buff, " %c", &ch); + if (ch == 'y' || ch == 'Y') { + puts (" >yes"); + print_share_file(SHARE_LICENSE); + } else { + puts (" >NO"); + } +#if 0 + printf("Game interface? (NCURSES/text): "); + scanf(" %c%*s ", &ch); + if (ch == 't' || ch == 'T') { + puts (" >text"); + // FIXME + } else { + puts (" >NCURSES"); + // FIXME + } +#endif + menu_clui_load(); +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void menu_clui_load (void) +{ +#if 0 + /* File name */ // FIXME + alx_w_getfname(USER_SAVED_DIR, saved_name, "File name:", saved_name, NULL); +#endif + menu_clui_start(); +} + +static void menu_clui_start (void) +{ + puts(" >>START:"); + start_switch(); + + char buff [BUFF_SIZE]; + char ch; + + ch = 'm'; + printf("Load again? (MENU/load/exit): "); + fgets(buff, BUFF_SIZE, stdin); + sscanf(buff, " %c", &ch); + if (ch == 'p' || ch == 'P') { + puts (" >load"); + menu_clui_start(); + } else if (ch == 'e' || ch == 'E') { + puts (" >exit!"); + } else { + puts (" >MENU"); + menu_clui(); + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/menu/src/menu_iface.c b/modules/menu/src/menu_iface.c index 1a00c29..03b1413 100644 --- a/modules/menu/src/menu_iface.c +++ b/modules/menu/src/menu_iface.c @@ -1,45 +1,45 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - /* menu_clui() */ - #include "menu_clui.h" - /* menu_tui() */ - #include "menu_tui.h" - - #include "menu_iface.h" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -int menu_iface_mode; - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void menu_iface (void) -{ - switch (menu_iface_mode) { - case MENU_IFACE_FOO: - break; - - case MENU_IFACE_CLUI: - menu_clui(); - break; - - case MENU_IFACE_TUI: - menu_tui(); - break; - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + /* menu_clui() */ + #include "menu_clui.h" + /* menu_tui() */ + #include "menu_tui.h" + + #include "menu_iface.h" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +int menu_iface_mode; + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void menu_iface (void) +{ + switch (menu_iface_mode) { + case MENU_IFACE_FOO: + break; + + case MENU_IFACE_CLUI: + menu_clui(); + break; + + case MENU_IFACE_TUI: + menu_tui(); + break; + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/menu/src/menu_tui.c b/modules/menu/src/menu_tui.c index abf9636..72c7764 100644 --- a/modules/menu/src/menu_tui.c +++ b/modules/menu/src/menu_tui.c @@ -1,330 +1,330 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include - #include - #include - -/* libalx --------------------------------------------------------------------*/ - #include "alx_ncur.h" - -/* Project -------------------------------------------------------------------*/ - /* printf_share_file() */ - #include "about.h" - /* proc_debug */ - #include "proc_iface.h" - /* saved_name */ - #include "save.h" - /* start_switch() */ - #include "start.h" - /* user_iface_log */ - #include "user_iface.h" - -/* Module --------------------------------------------------------------------*/ - #include "menu_tui.h" - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void menu_tui_continue (void); -static void menu_tui_select (void); -static void menu_tui_series (void); -static void menu_tui_devel (void); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void menu_tui (void) -{ - alx_resume_curses(); - - /* Menu dimensions & options */ - int h; - int w; - h = 23; - w = 80; - int N; - N = 4; - struct Alx_Menu mnu[4] = { - {7, 4, "[0] Exit program"}, - {2, 4, "[1] Continue"}, - {4, 4, "[2] Disclaimer of warranty"}, - {5, 4, "[3] Terms and conditions"} - }; - - /* Menu */ - bool wh; - int sw; - wh = true; - while (wh) { - /* Menu loop */ - sw = alx_menu(h, w, N, mnu, "MENU:"); - - /* Selection */ - switch (sw) { - case 0: - wh = false; - break; - - case 1: - menu_tui_continue(); - break; - - case 2: - alx_pause_curses(); - print_share_file(SHARE_DISCLAIMER); - getchar(); - alx_resume_curses(); - break; - - case 3: - alx_pause_curses(); - print_share_file(SHARE_LICENSE); - getchar(); - alx_resume_curses(); - break; - } - } - - alx_pause_curses(); -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void menu_tui_continue (void) -{ - /* Menu dimensions & options */ - WINDOW *win; - int h; - int w; - int r; - int c; - h = 23; - w = 80; - r = 1; - c = (80 - w) / 2; - int N; - N = 6; - struct Alx_Menu mnu[6] = { - {8, 4, "[0] Back"}, - {2, 4, "[1] Start"}, - {3, 4, "[2] Select"}, - {4, 4, "[3] Series"}, - {5, 4, "[4] Change file name"}, - {6, 4, "[5] DEVEL"} - }; - - /* Input box */ - int w2; - int r2; - w2 = w - 8; - r2 = r + h - 5; - char *txt[] = {"File name:"}; - - /* Menu */ - bool wh; - int sw; - wh = true; - while (wh) { - /* Menu loop */ - win = newwin(h, w, r, c); - mvwprintw(win, mnu[1].r, mnu[1].c, "%s (File: \"%s\")", - mnu[1].t, saved_name); - wrefresh(win); - sw = alx_menu_2(win, N, mnu, "CONTINUE:"); - - /* Selection */ - switch (sw) { - case 0: - wh = false; - break; - - case 1: - alx_win_del(win); - alx_pause_curses(); - start_switch(); - alx_resume_curses(); - break; - - case 2: - alx_win_del(win); - menu_tui_select(); - break; - - case 3: - alx_win_del(win); - menu_tui_series(); - break; - - case 4: - save_clr(); - alx_w_getfname(saved_path, saved_name, true, w2, r2, - txt[0], NULL); - alx_win_del(win); - break; - - case 5: - alx_win_del(win); - menu_tui_devel(); - break; - } - } - - /* Cleanup */ - alx_win_del(win); -} - -static void menu_tui_select (void) -{ - /* Menu dimensions & options */ - int h; - int w; - h = 23; - w = 80; - int N; - N = 3; - struct Alx_Menu mnu[3] = { - {6, 4, "[0] Back"}, - {2, 4, "[1] Single image"}, - {4, 4, "[2] Series"} - }; - - /* Menu loop */ - int sw; - sw = alx_menu(h, w, N, mnu, "SELECT MODE:"); - - /* Selection */ - switch (sw) { - case 1: - start_mode = START_SINGLE; - break; - - case 2: - start_mode = START_SERIES; - break; - } - -} - -static void menu_tui_series (void) -{ - /* Menu dimensions & options */ - int h; - int w; - h = 23; - w = 80; - int N; - N = 5; - struct Alx_Menu mnu[5] = { - {6, 4, "[0] Back"}, - {2, 4, "[1] Label"}, - {3, 4, "[2] Objects"}, - {4, 4, "[3] Coins"}, - {5, 4, "[4] Resistor"} - }; - - /* Menu loop */ - int sw; - sw = alx_menu(h, w, N, mnu, "SELECT LEVEL:"); - - /* Selection */ - switch (sw) { - case 1: - proc_mode = PROC_MODE_LABEL_SERIES; - break; - case 2: - proc_mode = PROC_MODE_OBJECTS_SERIES; - break; - case 3: - proc_mode = PROC_MODE_COINS_SERIES; - break; - case 4: - proc_mode = PROC_MODE_RESISTOR_SERIES; - break; - } - -} - -static void menu_tui_devel (void) -{ - WINDOW *win; - int h; - int w; - int r; - int c; - h = 23; - w = 80; - r = 1; - c = (80 - w) / 2; - int N; - N = 4; - struct Alx_Menu mnu[4] = { - {6, 4, "[0] Back"}, - {2, 4, "[1] Change process mode"}, - {3, 4, "[2] Change log mode"}, - {4, 4, "[3] Change user iface mode"} - }; - - /* Input box */ - int w2; - int r2; - w2 = w - 8; - r2 = r + h - 5; - char *txt[] = { - "Modes: 0=Auto; 1=Stop@prod; 2=Delay@step; 3=Stop@step", - "Modes: 0=Results; 1=Operations; 2=All", - "Modes: 1=CLUI; 2=TUI" - }; - - /* Menu */ - win = newwin(h, w, r, c); - - /* Menu loop */ - bool wh; - int sw; - wh = true; - while (wh) { - /* Selection */ - sw = alx_menu_2(win, N, mnu, "DEVELOPER OPTIONS:"); - - switch (sw) { - case 0: - wh = false; - break; - - case 1: - proc_debug = alx_w_getint(w2, r2, txt[0], - PROC_DBG_NO, 0, PROC_DBG_STOP_STEP, - NULL); - break; - - case 2: - user_iface_log.visible = alx_w_getint(w2, r2, txt[1], - 0, 2, 2, NULL); - break; - - case 3: - user_iface_mode = alx_w_getint(w2, r2, txt[2], - 1, 2, 2, NULL); - break; - } - } - - /* Cleanup */ - alx_win_del(win); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + #include + #include + #include + +/* libalx --------------------------------------------------------------------*/ + #include "alx_ncur.h" + +/* Project -------------------------------------------------------------------*/ + /* printf_share_file() */ + #include "about.h" + /* proc_debug */ + #include "proc_iface.h" + /* saved_name */ + #include "save.h" + /* start_switch() */ + #include "start.h" + /* user_iface_log */ + #include "user_iface.h" + +/* Module --------------------------------------------------------------------*/ + #include "menu_tui.h" + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void menu_tui_continue (void); +static void menu_tui_select (void); +static void menu_tui_series (void); +static void menu_tui_devel (void); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void menu_tui (void) +{ + alx_resume_curses(); + + /* Menu dimensions & options */ + int h; + int w; + h = 23; + w = 80; + int N; + N = 4; + struct Alx_Menu mnu[4] = { + {7, 4, "[0] Exit program"}, + {2, 4, "[1] Continue"}, + {4, 4, "[2] Disclaimer of warranty"}, + {5, 4, "[3] Terms and conditions"} + }; + + /* Menu */ + bool wh; + int sw; + wh = true; + while (wh) { + /* Menu loop */ + sw = alx_menu(h, w, N, mnu, "MENU:"); + + /* Selection */ + switch (sw) { + case 0: + wh = false; + break; + + case 1: + menu_tui_continue(); + break; + + case 2: + alx_pause_curses(); + print_share_file(SHARE_DISCLAIMER); + getchar(); + alx_resume_curses(); + break; + + case 3: + alx_pause_curses(); + print_share_file(SHARE_LICENSE); + getchar(); + alx_resume_curses(); + break; + } + } + + alx_pause_curses(); +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void menu_tui_continue (void) +{ + /* Menu dimensions & options */ + WINDOW *win; + int h; + int w; + int r; + int c; + h = 23; + w = 80; + r = 1; + c = (80 - w) / 2; + int N; + N = 6; + struct Alx_Menu mnu[6] = { + {8, 4, "[0] Back"}, + {2, 4, "[1] Start"}, + {3, 4, "[2] Select"}, + {4, 4, "[3] Series"}, + {5, 4, "[4] Change file name"}, + {6, 4, "[5] DEVEL"} + }; + + /* Input box */ + int w2; + int r2; + w2 = w - 8; + r2 = r + h - 5; + char *txt[] = {"File name:"}; + + /* Menu */ + bool wh; + int sw; + wh = true; + while (wh) { + /* Menu loop */ + win = newwin(h, w, r, c); + mvwprintw(win, mnu[1].r, mnu[1].c, "%s (File: \"%s\")", + mnu[1].t, saved_name); + wrefresh(win); + sw = alx_menu_2(win, N, mnu, "CONTINUE:"); + + /* Selection */ + switch (sw) { + case 0: + wh = false; + break; + + case 1: + alx_win_del(win); + alx_pause_curses(); + start_switch(); + alx_resume_curses(); + break; + + case 2: + alx_win_del(win); + menu_tui_select(); + break; + + case 3: + alx_win_del(win); + menu_tui_series(); + break; + + case 4: + save_clr(); + alx_w_getfname(saved_path, saved_name, true, w2, r2, + txt[0], NULL); + alx_win_del(win); + break; + + case 5: + alx_win_del(win); + menu_tui_devel(); + break; + } + } + + /* Cleanup */ + alx_win_del(win); +} + +static void menu_tui_select (void) +{ + /* Menu dimensions & options */ + int h; + int w; + h = 23; + w = 80; + int N; + N = 3; + struct Alx_Menu mnu[3] = { + {6, 4, "[0] Back"}, + {2, 4, "[1] Single image"}, + {4, 4, "[2] Series"} + }; + + /* Menu loop */ + int sw; + sw = alx_menu(h, w, N, mnu, "SELECT MODE:"); + + /* Selection */ + switch (sw) { + case 1: + start_mode = START_SINGLE; + break; + + case 2: + start_mode = START_SERIES; + break; + } + +} + +static void menu_tui_series (void) +{ + /* Menu dimensions & options */ + int h; + int w; + h = 23; + w = 80; + int N; + N = 5; + struct Alx_Menu mnu[5] = { + {6, 4, "[0] Back"}, + {2, 4, "[1] Label"}, + {3, 4, "[2] Objects"}, + {4, 4, "[3] Coins"}, + {5, 4, "[4] Resistor"} + }; + + /* Menu loop */ + int sw; + sw = alx_menu(h, w, N, mnu, "SELECT LEVEL:"); + + /* Selection */ + switch (sw) { + case 1: + proc_mode = PROC_MODE_LABEL_SERIES; + break; + case 2: + proc_mode = PROC_MODE_OBJECTS_SERIES; + break; + case 3: + proc_mode = PROC_MODE_COINS_SERIES; + break; + case 4: + proc_mode = PROC_MODE_RESISTOR_SERIES; + break; + } + +} + +static void menu_tui_devel (void) +{ + WINDOW *win; + int h; + int w; + int r; + int c; + h = 23; + w = 80; + r = 1; + c = (80 - w) / 2; + int N; + N = 4; + struct Alx_Menu mnu[4] = { + {6, 4, "[0] Back"}, + {2, 4, "[1] Change process mode"}, + {3, 4, "[2] Change log mode"}, + {4, 4, "[3] Change user iface mode"} + }; + + /* Input box */ + int w2; + int r2; + w2 = w - 8; + r2 = r + h - 5; + char *txt[] = { + "Modes: 0=Auto; 1=Stop@prod; 2=Delay@step; 3=Stop@step", + "Modes: 0=Results; 1=Operations; 2=All", + "Modes: 1=CLUI; 2=TUI" + }; + + /* Menu */ + win = newwin(h, w, r, c); + + /* Menu loop */ + bool wh; + int sw; + wh = true; + while (wh) { + /* Selection */ + sw = alx_menu_2(win, N, mnu, "DEVELOPER OPTIONS:"); + + switch (sw) { + case 0: + wh = false; + break; + + case 1: + proc_debug = alx_w_getint(w2, r2, txt[0], + PROC_DBG_NO, 0, PROC_DBG_STOP_STEP, + NULL); + break; + + case 2: + user_iface_log.visible = alx_w_getint(w2, r2, txt[1], + 0, 2, 2, NULL); + break; + + case 3: + user_iface_mode = alx_w_getint(w2, r2, txt[2], + 1, 2, 2, NULL); + break; + } + } + + /* Cleanup */ + alx_win_del(win); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/menu/src/parser.c b/modules/menu/src/parser.c index 6b03264..ef8cec9 100644 --- a/modules/menu/src/parser.c +++ b/modules/menu/src/parser.c @@ -1,140 +1,140 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include - /* FILE & fopen() & snprintf() & FILENAME_MAX */ - #include - /* exit() */ - #include - -/* Project -------------------------------------------------------------------*/ - /* print_share_...() */ - #include "about.h" - /* user_iface_mode */ - #include "user_iface.h" - /* saved_name */ - #include "save.h" - -/* Module --------------------------------------------------------------------*/ - /* menu_iface_mode */ - #include "menu_iface.h" - - #include "parser.h" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define OPT_LIST "hLuv""f:i:" - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void parse_file (char* argument); -static void parse_iface (char* argument); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void parser (int argc, char *argv[]) -{ - int opt = 0; - int opt_index = 0; - - struct option long_options[] = { - /* Standard */ - {"help", no_argument, 0, 'h'}, - {"license", no_argument, 0, 'L'}, - {"usage", no_argument, 0, 'u'}, - {"version", no_argument, 0, 'v'}, - /* Non-standard */ - {"file", required_argument, 0, 'f'}, - {"iface", required_argument, 0, 'i'}, - /* Null */ - {0, 0, 0, 0} - }; - - while ((opt = getopt_long(argc, argv, OPT_LIST, long_options, - &opt_index)) != -1) { - - switch (opt) { - /* Standard */ - case 'h': - print_share_file(SHARE_HELP); - exit(EXIT_SUCCESS); - - case 'L': - print_share_file(SHARE_LICENSE); - exit(EXIT_SUCCESS); - - case 'u': - print_share_file(SHARE_USAGE); - exit(EXIT_SUCCESS); - - case 'v': - print_version(); - exit(EXIT_SUCCESS); - - /* Non-standard */ - case 'f': - parse_file(optarg); - break; - - case 'i': - parse_iface(optarg); - break; - - case '?': - /* getopt_long already printed an error message. */ - - default: - print_share_file(SHARE_USAGE); - exit(EXIT_FAILURE); - } - } -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void parse_file (char* argument) -{ - // FIXME - FILE *fp; - fp = fopen(argument, "r"); - if (!fp) { - printf("--file argument not valid\n"); - printf("It must be a valid file name (relative to saved dir)\n"); - exit(EXIT_FAILURE); - } else { - fclose(fp); - - sprintf(saved_path, ""); - snprintf(saved_name, FILENAME_MAX, "%s", argument); - } -} - -static void parse_iface (char* argument) -{ - menu_iface_mode = atoi(argument); - user_iface_mode = menu_iface_mode; - if (menu_iface_mode < MENU_IFACE_CLUI || menu_iface_mode > MENU_IFACE_TUI) { - printf("--iface argument not valid\n"); - printf("It must be an integer [%i U %i]\n", MENU_IFACE_CLUI, MENU_IFACE_TUI); - exit(EXIT_FAILURE); - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + #include + /* FILE & fopen() & snprintf() & FILENAME_MAX */ + #include + /* exit() */ + #include + +/* Project -------------------------------------------------------------------*/ + /* print_share_...() */ + #include "about.h" + /* user_iface_mode */ + #include "user_iface.h" + /* saved_name */ + #include "save.h" + +/* Module --------------------------------------------------------------------*/ + /* menu_iface_mode */ + #include "menu_iface.h" + + #include "parser.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define OPT_LIST "hLuv""f:i:" + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void parse_file (char* argument); +static void parse_iface (char* argument); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void parser (int argc, char *argv[]) +{ + int opt = 0; + int opt_index = 0; + + struct option long_options[] = { + /* Standard */ + {"help", no_argument, 0, 'h'}, + {"license", no_argument, 0, 'L'}, + {"usage", no_argument, 0, 'u'}, + {"version", no_argument, 0, 'v'}, + /* Non-standard */ + {"file", required_argument, 0, 'f'}, + {"iface", required_argument, 0, 'i'}, + /* Null */ + {0, 0, 0, 0} + }; + + while ((opt = getopt_long(argc, argv, OPT_LIST, long_options, + &opt_index)) != -1) { + + switch (opt) { + /* Standard */ + case 'h': + print_share_file(SHARE_HELP); + exit(EXIT_SUCCESS); + + case 'L': + print_share_file(SHARE_LICENSE); + exit(EXIT_SUCCESS); + + case 'u': + print_share_file(SHARE_USAGE); + exit(EXIT_SUCCESS); + + case 'v': + print_version(); + exit(EXIT_SUCCESS); + + /* Non-standard */ + case 'f': + parse_file(optarg); + break; + + case 'i': + parse_iface(optarg); + break; + + case '?': + /* getopt_long already printed an error message. */ + + default: + print_share_file(SHARE_USAGE); + exit(EXIT_FAILURE); + } + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void parse_file (char* argument) +{ + // FIXME + FILE *fp; + fp = fopen(argument, "r"); + if (!fp) { + printf("--file argument not valid\n"); + printf("It must be a valid file name (relative to saved dir)\n"); + exit(EXIT_FAILURE); + } else { + fclose(fp); + + sprintf(saved_path, ""); + snprintf(saved_name, FILENAME_MAX, "%s", argument); + } +} + +static void parse_iface (char* argument) +{ + menu_iface_mode = atoi(argument); + user_iface_mode = menu_iface_mode; + if (menu_iface_mode < MENU_IFACE_CLUI || menu_iface_mode > MENU_IFACE_TUI) { + printf("--iface argument not valid\n"); + printf("It must be an integer [%i U %i]\n", MENU_IFACE_CLUI, MENU_IFACE_TUI); + exit(EXIT_FAILURE); + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_coins.h b/modules/proc/inc/proc_coins.h index 211971c..7e29d7d 100644 --- a/modules/proc/inc/proc_coins.h +++ b/modules/proc/inc/proc_coins.h @@ -1,48 +1,48 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_COINS_H - # define VA_PROC_COINS_H - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Coins { - COINS_OK, - COINS_NOK_COINS, - COINS_NOK_OVERLAP, - COINS_NOK_SIZE - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - int proc_coins (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_coins.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_COINS_H + # define VA_PROC_COINS_H + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Coins { + COINS_OK, + COINS_NOK_COINS, + COINS_NOK_OVERLAP, + COINS_NOK_SIZE + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_coins (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_coins.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_coins.hpp b/modules/proc/inc/proc_coins.hpp index 5b64870..9315324 100644 --- a/modules/proc/inc/proc_coins.hpp +++ b/modules/proc/inc/proc_coins.hpp @@ -1,60 +1,60 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_COINS_HPP - # define VA_PROC_COINS_HPP - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Coins { - COINS_OK, - COINS_NOK_COINS, - COINS_NOK_OVERLAP, - COINS_NOK_SIZE - }; - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - int proc_coins (void); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_coins.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_COINS_HPP + # define VA_PROC_COINS_HPP + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Coins { + COINS_OK, + COINS_NOK_COINS, + COINS_NOK_OVERLAP, + COINS_NOK_SIZE + }; + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_coins (void); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_coins.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_common.h b/modules/proc/inc/proc_common.h index e0a6e36..1d4077e 100644 --- a/modules/proc/inc/proc_common.h +++ b/modules/proc/inc/proc_common.h @@ -1,45 +1,45 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_COMMON_H - # define VA_PROC_COMMON_H - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void proc_show_img (void); - - void clock_start (void); - void clock_stop (const char *txt); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_common.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_COMMON_H + # define VA_PROC_COMMON_H + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void proc_show_img (void); + + void clock_start (void); + void clock_stop (const char *txt); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_common.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_common.hpp b/modules/proc/inc/proc_common.hpp index 85d5eb3..7332b84 100644 --- a/modules/proc/inc/proc_common.hpp +++ b/modules/proc/inc/proc_common.hpp @@ -1,111 +1,111 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_COMMON_HPP - # define VA_PROC_COMMON_HPP - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void proc_apply (void); -void proc_save_mem (int n); -void proc_load_mem (int n); -void proc_save_ref (void); -void proc_save_file (void); -void proc_save_update (void); - -void proc_local_max (void); -void proc_skeleton (void); -void proc_lines_vertical (void); -void proc_median_horizontal (void); -void proc_median_vertical (void); - -void proc_pixel_get (int x, int y, unsigned char *val); -void proc_pixel_set (int x, int y, unsigned char val); -void proc_ROI (int x, int y, int w, int h); -void proc_and_2ref (void); -void proc_not (void); -void proc_or_2ref (void); -void proc_cmp (int cmp); -void proc_dilate (int size); -void proc_erode (int size); -void proc_dilate_erode (int size); -void proc_erode_dilate (int size); -void proc_smooth (int method, int ksize); -void proc_border (int size); -void proc_rotate (double center_x, double center_y, double angle); -void proc_adaptive_threshold (int method, int type, int ksize); -void proc_cvt_color (int method); -void proc_distance_transform (void); -void proc_threshold (int type, int ksize); -void proc_contours ( - std::vector >> *contours, - class cv::Mat *hierarchy); -void proc_contours_size ( - std::vector >> *contours, - double *area, - double *perimeter); -void proc_bounding_rect ( - std::vector > *contour, - class cv::Rect_ *rect, - bool show); -void proc_fit_ellipse ( - std::vector > *contour, - class cv::RotatedRect *rect, - bool show); -void proc_min_area_rect ( - std::vector > *contour, - class cv::RotatedRect *rect, - bool show); - -void proc_OCR (int lang, int conf); -void proc_zbar (int type); - -void proc_show_img (void); - -void clock_start (void); -void clock_stop (const char *txt); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_common.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_COMMON_HPP + # define VA_PROC_COMMON_HPP + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void proc_apply (void); +void proc_save_mem (int n); +void proc_load_mem (int n); +void proc_save_ref (void); +void proc_save_file (void); +void proc_save_update (void); + +void proc_local_max (void); +void proc_skeleton (void); +void proc_lines_vertical (void); +void proc_median_horizontal (void); +void proc_median_vertical (void); + +void proc_pixel_get (int x, int y, unsigned char *val); +void proc_pixel_set (int x, int y, unsigned char val); +void proc_ROI (int x, int y, int w, int h); +void proc_and_2ref (void); +void proc_not (void); +void proc_or_2ref (void); +void proc_cmp (int cmp); +void proc_dilate (int size); +void proc_erode (int size); +void proc_dilate_erode (int size); +void proc_erode_dilate (int size); +void proc_smooth (int method, int ksize); +void proc_border (int size); +void proc_rotate (double center_x, double center_y, double angle); +void proc_adaptive_threshold (int method, int type, int ksize); +void proc_cvt_color (int method); +void proc_distance_transform (void); +void proc_threshold (int type, int ksize); +void proc_contours ( + std::vector >> *contours, + class cv::Mat *hierarchy); +void proc_contours_size ( + std::vector >> *contours, + double *area, + double *perimeter); +void proc_bounding_rect ( + std::vector > *contour, + class cv::Rect_ *rect, + bool show); +void proc_fit_ellipse ( + std::vector > *contour, + class cv::RotatedRect *rect, + bool show); +void proc_min_area_rect ( + std::vector > *contour, + class cv::RotatedRect *rect, + bool show); + +void proc_OCR (int lang, int conf); +void proc_zbar (int type); + +void proc_show_img (void); + +void clock_start (void); +void clock_stop (const char *txt); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_common.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_iface.h b/modules/proc/inc/proc_iface.h index 7225f25..df62bfb 100644 --- a/modules/proc/inc/proc_iface.h +++ b/modules/proc/inc/proc_iface.h @@ -1,70 +1,70 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_IFACE_H - # define VA_PROC_IFACE_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Mode { - PROC_MODE_FOO, - - PROC_MODE = 0x008000u, - PROC_MODE_LABEL_SERIES, - PROC_MODE_LABEL_CALIB, - PROC_MODE_OBJECTS_SERIES, - PROC_MODE_OBJECTS_CALIB, - PROC_MODE_COINS_SERIES, - PROC_MODE_COINS_CALIB, - PROC_MODE_RESISTOR_SERIES, - PROC_MODE_RESISTOR_CALIB - }; - - enum Proc_DBG { - PROC_DBG_NO, - PROC_DBG_STOP_ITEM, - PROC_DBG_DELAY_STEP, - PROC_DBG_STOP_STEP - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - extern int proc_debug; - extern int proc_mode; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - int proc_iface_single (int action); - void proc_iface_series (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_iface.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_IFACE_H + # define VA_PROC_IFACE_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Mode { + PROC_MODE_FOO, + + PROC_MODE = 0x008000u, + PROC_MODE_LABEL_SERIES, + PROC_MODE_LABEL_CALIB, + PROC_MODE_OBJECTS_SERIES, + PROC_MODE_OBJECTS_CALIB, + PROC_MODE_COINS_SERIES, + PROC_MODE_COINS_CALIB, + PROC_MODE_RESISTOR_SERIES, + PROC_MODE_RESISTOR_CALIB + }; + + enum Proc_DBG { + PROC_DBG_NO, + PROC_DBG_STOP_ITEM, + PROC_DBG_DELAY_STEP, + PROC_DBG_STOP_STEP + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern int proc_debug; + extern int proc_mode; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_iface_single (int action); + void proc_iface_series (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_iface.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_iface.hpp b/modules/proc/inc/proc_iface.hpp index 941467b..534dec1 100644 --- a/modules/proc/inc/proc_iface.hpp +++ b/modules/proc/inc/proc_iface.hpp @@ -1,82 +1,82 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_IFACE_H - # define VA_PROC_IFACE_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Mode { - PROC_MODE_FOO, - - PROC_MODE = 0x008000u, - PROC_MODE_LABEL_SERIES, - PROC_MODE_LABEL_CALIB, - PROC_MODE_OBJECTS_SERIES, - PROC_MODE_OBJECTS_CALIB, - PROC_MODE_COINS_SERIES, - PROC_MODE_COINS_CALIB, - PROC_MODE_RESISTOR_SERIES, - PROC_MODE_RESISTOR_CALIB - }; - - enum Proc_DBG { - PROC_DBG_NO, - PROC_DBG_STOP_ITEM, - PROC_DBG_DELAY_STEP, - PROC_DBG_STOP_STEP - }; - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - extern int proc_debug; - extern int proc_mode; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - int proc_iface_single (int action); - void proc_iface_series (void); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_iface.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_IFACE_H + # define VA_PROC_IFACE_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Mode { + PROC_MODE_FOO, + + PROC_MODE = 0x008000u, + PROC_MODE_LABEL_SERIES, + PROC_MODE_LABEL_CALIB, + PROC_MODE_OBJECTS_SERIES, + PROC_MODE_OBJECTS_CALIB, + PROC_MODE_COINS_SERIES, + PROC_MODE_COINS_CALIB, + PROC_MODE_RESISTOR_SERIES, + PROC_MODE_RESISTOR_CALIB + }; + + enum Proc_DBG { + PROC_DBG_NO, + PROC_DBG_STOP_ITEM, + PROC_DBG_DELAY_STEP, + PROC_DBG_STOP_STEP + }; + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern int proc_debug; + extern int proc_mode; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_iface_single (int action); + void proc_iface_series (void); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_iface.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_label.h b/modules/proc/inc/proc_label.h index 1792e43..a1091b8 100644 --- a/modules/proc/inc/proc_label.h +++ b/modules/proc/inc/proc_label.h @@ -1,50 +1,50 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_LABEL_H - # define VA_PROC_LABEL_H - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Label { - LABEL_OK, - LABEL_NOK_LABEL, - LABEL_NOK_CERDO, - LABEL_NOK_BCODE, - LABEL_NOK_PRODUCT, - LABEL_NOK_PRICE - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - int proc_label (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_label.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_LABEL_H + # define VA_PROC_LABEL_H + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Label { + LABEL_OK, + LABEL_NOK_LABEL, + LABEL_NOK_CERDO, + LABEL_NOK_BCODE, + LABEL_NOK_PRODUCT, + LABEL_NOK_PRICE + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_label (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_label.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_label.hpp b/modules/proc/inc/proc_label.hpp index eb5dd66..b456a55 100644 --- a/modules/proc/inc/proc_label.hpp +++ b/modules/proc/inc/proc_label.hpp @@ -1,62 +1,62 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_LABEL_HPP - # define VA_PROC_LABEL_HPP - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Label { - LABEL_OK, - LABEL_NOK_LABEL, - LABEL_NOK_CERDO, - LABEL_NOK_BCODE, - LABEL_NOK_PRODUCT, - LABEL_NOK_PRICE - }; - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - int proc_label (void); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_label.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_LABEL_HPP + # define VA_PROC_LABEL_HPP + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Label { + LABEL_OK, + LABEL_NOK_LABEL, + LABEL_NOK_CERDO, + LABEL_NOK_BCODE, + LABEL_NOK_PRODUCT, + LABEL_NOK_PRICE + }; + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_label (void); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_label.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_objects.h b/modules/proc/inc/proc_objects.h index fb53ac4..be841ba 100644 --- a/modules/proc/inc/proc_objects.h +++ b/modules/proc/inc/proc_objects.h @@ -1,49 +1,49 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_OBJECTS_H - # define VA_PROC_OBJECTS_H - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Objects { - OBJECTS_OK, - OBJECTS_NOK_PATTERN, - OBJECTS_NOK_OBJECTS, - OBJECTS_NOK_SIZE - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - int proc_objects_calibrate (void); - int proc_objects (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_objects.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_OBJECTS_H + # define VA_PROC_OBJECTS_H + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Objects { + OBJECTS_OK, + OBJECTS_NOK_PATTERN, + OBJECTS_NOK_OBJECTS, + OBJECTS_NOK_SIZE + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_objects_calibrate (void); + int proc_objects (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_objects.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_objects.hpp b/modules/proc/inc/proc_objects.hpp index 300e625..1a3084f 100644 --- a/modules/proc/inc/proc_objects.hpp +++ b/modules/proc/inc/proc_objects.hpp @@ -1,61 +1,61 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_OBJECTS_HPP - # define VA_PROC_OBJECTS_HPP - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Objects { - OBJECTS_OK, - OBJECTS_NOK_PATTERN, - OBJECTS_NOK_OBJECTS, - OBJECTS_NOK_SIZE - }; - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - int proc_objects_calibrate (void); - int proc_objects (void); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_objects.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_OBJECTS_HPP + # define VA_PROC_OBJECTS_HPP + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Objects { + OBJECTS_OK, + OBJECTS_NOK_PATTERN, + OBJECTS_NOK_OBJECTS, + OBJECTS_NOK_SIZE + }; + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_objects_calibrate (void); + int proc_objects (void); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_objects.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_resistor.h b/modules/proc/inc/proc_resistor.h index 7784ebb..ca60a8a 100644 --- a/modules/proc/inc/proc_resistor.h +++ b/modules/proc/inc/proc_resistor.h @@ -1,50 +1,50 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_RESISTOR_H - # define VA_PROC_RESISTOR_H - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Resistor { - RESISTOR_OK, - RESISTOR_NOK_RESISTOR, - RESISTOR_NOK_BANDS, - RESISTOR_NOK_COLOR, - RESISTOR_NOK_STD_VALUE, - RESISTOR_NOK_TOLERANCE - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - int proc_resistor (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_resistor.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_RESISTOR_H + # define VA_PROC_RESISTOR_H + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Resistor { + RESISTOR_OK, + RESISTOR_NOK_RESISTOR, + RESISTOR_NOK_BANDS, + RESISTOR_NOK_COLOR, + RESISTOR_NOK_STD_VALUE, + RESISTOR_NOK_TOLERANCE + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_resistor (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_resistor.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_resistor.hpp b/modules/proc/inc/proc_resistor.hpp index 9982e6f..fce85d8 100644 --- a/modules/proc/inc/proc_resistor.hpp +++ b/modules/proc/inc/proc_resistor.hpp @@ -1,62 +1,62 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_RESISTOR_HPP - # define VA_PROC_RESISTOR_HPP - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Resistor { - RESISTOR_OK, - RESISTOR_NOK_RESISTOR, - RESISTOR_NOK_BANDS, - RESISTOR_NOK_COLOR, - RESISTOR_NOK_STD_VALUE, - RESISTOR_NOK_TOLERANCE - }; - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - int proc_resistor (void); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_resistor.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_RESISTOR_HPP + # define VA_PROC_RESISTOR_HPP + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Resistor { + RESISTOR_OK, + RESISTOR_NOK_RESISTOR, + RESISTOR_NOK_BANDS, + RESISTOR_NOK_COLOR, + RESISTOR_NOK_STD_VALUE, + RESISTOR_NOK_TOLERANCE + }; + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_resistor (void); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_resistor.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/src/proc_coins.cpp b/modules/proc/src/proc_coins.cpp index 71bbac2..8f26e71 100644 --- a/modules/proc/src/proc_coins.cpp +++ b/modules/proc/src/proc_coins.cpp @@ -1,378 +1,378 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* snprintf() & fflush() */ - #include - -/* Packages ------------------------------------------------------------------*/ - /* openCV */ - #include - -/* libalx ------------------------------------------------------------------*/ - /* alx_maximum_u8() */ - #include "alx_math.hpp" - -/* Project -------------------------------------------------------------------*/ - /* constants */ - #include "img_iface.hpp" - /* user_iface_log */ - #include "user_iface.hpp" - -/* Module --------------------------------------------------------------------*/ - #include "proc_common.hpp" - - #include "proc_coins.hpp" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define COINS_MAX 1024 - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ -struct Coins_Properties { - /* position */ - int x; - int y; - - /* value */ - uint8_t diameter_pix; - double diameter_mm; - double value; -}; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ - -/* Static --------------------------------------------------------------------*/ -static class std::vector >> contours; -static class cv::Mat hierarchy; -static class cv::Rect_ rectangle [COINS_MAX]; -static int coins_n; -static struct Coins_Properties coins [COINS_MAX]; -static double ratio_mm_per_pix; -static double value_total; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_coins (int status); - -static void coins_segmentate (void); -static int coins_positions (void); -static void coins_diameters_pix (void); -static void calibrate_mm_per_pix (void); -static void coins_diameters_mm (void); -static int coins_values (void); -static double coin_value (double diameter_mm); -static void coins_total_value (void); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -int proc_coins (void) -{ - int status; - - proc_save_mem(0); - /* Segmentate coins */ - { - /* Measure time */ - clock_start(); - - coins_segmentate(); - - /* Measure time */ - clock_stop("Segmentate coins"); - } - /* Find coins positions */ - { - /* Measure time */ - clock_start(); - - status = coins_positions(); - if (status) { - result_coins(status); - return status; - } - - /* Measure time */ - clock_stop("Find coins positions"); - } - /* Get coin diameters in pixels */ - { - /* Measure time */ - clock_start(); - - coins_diameters_pix(); - - /* Measure time */ - clock_stop("Coins diameters in pixels"); - } - /* Calibrate with the biggest coin; every img should have a 2 € coin */ - { - /* Measure time */ - clock_start(); - - calibrate_mm_per_pix(); - - /* Measure time */ - clock_stop("Calibrate (mm per pix)"); - } - /* Get coins diameters in mm */ - { - /* Measure time */ - clock_start(); - - coins_diameters_mm(); - - /* Measure time */ - clock_stop("Coins diameters in mm"); - } - /* Get coins values (by their sizes) */ - { - /* Measure time */ - clock_start(); - - status = coins_values(); - if (status) { - result_coins(status); - return status; - } - - /* Measure time */ - clock_stop("Coins values"); - } - /* Add total value */ - { - /* Measure time */ - clock_start(); - - coins_total_value(); - - /* Measure time */ - clock_stop("Total value"); - } - - status = COINS_OK; - result_coins(status); - return status; -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_coins (int status) -{ - /* Cleanup */ - - /* Write result into log */ - switch (status) { - case COINS_OK: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: OK"); - break; - case COINS_NOK_COINS: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK_COINS"); - break; -#if 0 - case COINS_NOK_OVERLAP: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK_OVERLAP"); - break; -#endif - case COINS_NOK_SIZE: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK_SIZE"); - break; - default: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK"); - break; - } - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - -static void coins_segmentate (void) -{ - proc_load_mem(0); - - proc_cmp(IMG_IFACE_CMP_BLUE); - proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU); - proc_distance_transform(); - proc_local_max(); - proc_dilate(6); - proc_save_mem(1); -} - -static int coins_positions (void) -{ - int status; - int i; - - proc_load_mem(1); - - proc_contours(&contours, &hierarchy); - coins_n = contours.size(); - - /* If no contour is found, error: NOK_COINS */ - if (!coins_n) { - status = COINS_NOK_COINS; - return status; - } - - /* Get position of each contour */ - for (i = 0; i < coins_n; i++) { - proc_bounding_rect(&(contours[i]), &(rectangle[i]), true); - coins[i].x = rectangle[i].x + rectangle[i].width / 2.0; - coins[i].y = rectangle[i].y + rectangle[i].height / 2.0; - } - - status = COINS_OK; - return status; -} - -static void coins_diameters_pix (void) -{ - int i; - - proc_load_mem(1); - - /* Get coins diameters in pixels */ - for (i = 0; i < coins_n; i++) { - proc_pixel_get(coins[i].x, coins[i].y, - &(coins[i].diameter_pix)); - coins[i].diameter_pix *= 2; - } -} - -static void calibrate_mm_per_pix (void) -{ - uint8_t coins_size_pix [coins_n]; - int i; - int max_pos; - int max_size; - - for (i = 0; i < coins_n; i++) { - coins_size_pix[i] = coins[i].diameter_pix; - } - - max_pos = alx_maximum_u8(coins_n, coins_size_pix); - max_size = coins_size_pix[max_pos]; - ratio_mm_per_pix = 25.75 / max_size; -} - -static void coins_diameters_mm (void) -{ - int i; - - for (i = 0; i < coins_n; i++) { - coins[i].diameter_mm = ratio_mm_per_pix * - coins[i].diameter_pix; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin[%i]: %.2lf mm", - i, - coins[i].diameter_mm); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - } -} - -static int coins_values (void) -{ - int status; - int i; - - for (i = 0; i < coins_n; i++) { - coins[i].value = coin_value(coins[i].diameter_mm); - - /* If a coin is of invalid size, error: NOK_SIZE */ - if (coins[i].value < 0) { - status = COINS_NOK_SIZE; - return status; - } - - /* Write values into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin[%i]: %.2lf EUR", - i, - coins[i].value); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - } - - status = COINS_OK; - return status; -} - -static double coin_value (double diameter_mm) -{ - double value; - - /* Get coin value by its diameter in mm */ - if (diameter_mm > 27.00) { - value = -1; - } else if (diameter_mm > 25.00) { - value = 2.00; - } else if (diameter_mm > 23.75) { - value = 0.50; - } else if (diameter_mm > 22.75) { - value = 1.00; - } else if (diameter_mm > 21.75) { - value = 0.20; - } else if (diameter_mm > 20.50) { - value = 0.05; - } else if (diameter_mm > 19.25) { - value = 0.10; - } else if (diameter_mm > 17.50) { - value = 0.02; - } else if (diameter_mm > 15.00) { - value = 0.01; - } else { - value = -1; - } - - return value; -} - -static void coins_total_value (void) -{ - int i; - - value_total = 0.00; - - for (i = 0; i < coins_n; i++) { - value_total += coins[i].value; - } - - /* Write total value into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Total value: %.2lf EUR", - value_total); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* snprintf() & fflush() */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* openCV */ + #include + +/* libalx ------------------------------------------------------------------*/ + /* alx_maximum_u8() */ + #include "alx_math.hpp" + +/* Project -------------------------------------------------------------------*/ + /* constants */ + #include "img_iface.hpp" + /* user_iface_log */ + #include "user_iface.hpp" + +/* Module --------------------------------------------------------------------*/ + #include "proc_common.hpp" + + #include "proc_coins.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define COINS_MAX 1024 + + +/****************************************************************************** + ******* structs ************************************************************** + ******************************************************************************/ +struct Coins_Properties { + /* position */ + int x; + int y; + + /* value */ + uint8_t diameter_pix; + double diameter_mm; + double value; +}; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ + +/* Static --------------------------------------------------------------------*/ +static class std::vector >> contours; +static class cv::Mat hierarchy; +static class cv::Rect_ rectangle [COINS_MAX]; +static int coins_n; +static struct Coins_Properties coins [COINS_MAX]; +static double ratio_mm_per_pix; +static double value_total; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_coins (int status); + +static void coins_segmentate (void); +static int coins_positions (void); +static void coins_diameters_pix (void); +static void calibrate_mm_per_pix (void); +static void coins_diameters_mm (void); +static int coins_values (void); +static double coin_value (double diameter_mm); +static void coins_total_value (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +int proc_coins (void) +{ + int status; + + proc_save_mem(0); + /* Segmentate coins */ + { + /* Measure time */ + clock_start(); + + coins_segmentate(); + + /* Measure time */ + clock_stop("Segmentate coins"); + } + /* Find coins positions */ + { + /* Measure time */ + clock_start(); + + status = coins_positions(); + if (status) { + result_coins(status); + return status; + } + + /* Measure time */ + clock_stop("Find coins positions"); + } + /* Get coin diameters in pixels */ + { + /* Measure time */ + clock_start(); + + coins_diameters_pix(); + + /* Measure time */ + clock_stop("Coins diameters in pixels"); + } + /* Calibrate with the biggest coin; every img should have a 2 € coin */ + { + /* Measure time */ + clock_start(); + + calibrate_mm_per_pix(); + + /* Measure time */ + clock_stop("Calibrate (mm per pix)"); + } + /* Get coins diameters in mm */ + { + /* Measure time */ + clock_start(); + + coins_diameters_mm(); + + /* Measure time */ + clock_stop("Coins diameters in mm"); + } + /* Get coins values (by their sizes) */ + { + /* Measure time */ + clock_start(); + + status = coins_values(); + if (status) { + result_coins(status); + return status; + } + + /* Measure time */ + clock_stop("Coins values"); + } + /* Add total value */ + { + /* Measure time */ + clock_start(); + + coins_total_value(); + + /* Measure time */ + clock_stop("Total value"); + } + + status = COINS_OK; + result_coins(status); + return status; +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_coins (int status) +{ + /* Cleanup */ + + /* Write result into log */ + switch (status) { + case COINS_OK: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: OK"); + break; + case COINS_NOK_COINS: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK_COINS"); + break; +#if 0 + case COINS_NOK_OVERLAP: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK_OVERLAP"); + break; +#endif + case COINS_NOK_SIZE: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK_SIZE"); + break; + default: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK"); + break; + } + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + +static void coins_segmentate (void) +{ + proc_load_mem(0); + + proc_cmp(IMG_IFACE_CMP_BLUE); + proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU); + proc_distance_transform(); + proc_local_max(); + proc_dilate(6); + proc_save_mem(1); +} + +static int coins_positions (void) +{ + int status; + int i; + + proc_load_mem(1); + + proc_contours(&contours, &hierarchy); + coins_n = contours.size(); + + /* If no contour is found, error: NOK_COINS */ + if (!coins_n) { + status = COINS_NOK_COINS; + return status; + } + + /* Get position of each contour */ + for (i = 0; i < coins_n; i++) { + proc_bounding_rect(&(contours[i]), &(rectangle[i]), true); + coins[i].x = rectangle[i].x + rectangle[i].width / 2.0; + coins[i].y = rectangle[i].y + rectangle[i].height / 2.0; + } + + status = COINS_OK; + return status; +} + +static void coins_diameters_pix (void) +{ + int i; + + proc_load_mem(1); + + /* Get coins diameters in pixels */ + for (i = 0; i < coins_n; i++) { + proc_pixel_get(coins[i].x, coins[i].y, + &(coins[i].diameter_pix)); + coins[i].diameter_pix *= 2; + } +} + +static void calibrate_mm_per_pix (void) +{ + uint8_t coins_size_pix [coins_n]; + int i; + int max_pos; + int max_size; + + for (i = 0; i < coins_n; i++) { + coins_size_pix[i] = coins[i].diameter_pix; + } + + max_pos = alx_maximum_u8(coins_n, coins_size_pix); + max_size = coins_size_pix[max_pos]; + ratio_mm_per_pix = 25.75 / max_size; +} + +static void coins_diameters_mm (void) +{ + int i; + + for (i = 0; i < coins_n; i++) { + coins[i].diameter_mm = ratio_mm_per_pix * + coins[i].diameter_pix; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin[%i]: %.2lf mm", + i, + coins[i].diameter_mm); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + } +} + +static int coins_values (void) +{ + int status; + int i; + + for (i = 0; i < coins_n; i++) { + coins[i].value = coin_value(coins[i].diameter_mm); + + /* If a coin is of invalid size, error: NOK_SIZE */ + if (coins[i].value < 0) { + status = COINS_NOK_SIZE; + return status; + } + + /* Write values into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin[%i]: %.2lf EUR", + i, + coins[i].value); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + } + + status = COINS_OK; + return status; +} + +static double coin_value (double diameter_mm) +{ + double value; + + /* Get coin value by its diameter in mm */ + if (diameter_mm > 27.00) { + value = -1; + } else if (diameter_mm > 25.00) { + value = 2.00; + } else if (diameter_mm > 23.75) { + value = 0.50; + } else if (diameter_mm > 22.75) { + value = 1.00; + } else if (diameter_mm > 21.75) { + value = 0.20; + } else if (diameter_mm > 20.50) { + value = 0.05; + } else if (diameter_mm > 19.25) { + value = 0.10; + } else if (diameter_mm > 17.50) { + value = 0.02; + } else if (diameter_mm > 15.00) { + value = 0.01; + } else { + value = -1; + } + + return value; +} + +static void coins_total_value (void) +{ + int i; + + value_total = 0.00; + + for (i = 0; i < coins_n; i++) { + value_total += coins[i].value; + } + + /* Write total value into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Total value: %.2lf EUR", + value_total); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/src/proc_common.cpp b/modules/proc/src/proc_common.cpp index 86c137a..96b66f1 100644 --- a/modules/proc/src/proc_common.cpp +++ b/modules/proc/src/proc_common.cpp @@ -1,432 +1,432 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include - /* snprintf() & fflush() */ - #include - /* clock_t & clock() & CLOCKS_PER_SEC */ - #include - -/* Packages ------------------------------------------------------------------*/ - /* openCV */ - #include - /* enum zbar::zbar_symbol_type_e */ - #include - -/* 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_skeleton (void) -{ - img_iface_act(IMG_IFACE_ACT_SKELETON, 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_get (int x, int y, unsigned char *val) -{ - struct Img_Iface_Data_Pixel_Get data; - data.x = x; - data.y = y; - data.val = val; - img_iface_act(IMG_IFACE_ACT_PIXEL_GET, (void *)&data); -} - -void proc_pixel_set (int x, int y, unsigned char val) -{ - struct Img_Iface_Data_Pixel_Set data; - data.x = x; - data.y = y; - data.val = val; - img_iface_act(IMG_IFACE_ACT_PIXEL_SET, (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_border (int size) -{ - struct Img_Iface_Data_Border data; - - data.size = size; - img_iface_act(IMG_IFACE_ACT_BORDER, (void *)&data); - - proc_show_img(); -} - -void proc_rotate (double center_x, double center_y, double angle) -{ - struct Img_Iface_Data_Rotate data; - - data.center.x = center_x; - data.center.y = center_y; - data.angle = 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 ( - class std::vector >> *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 ( - class std::vector >> *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 ( - class std::vector > *contour, - class cv::Rect_ *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 ( - class std::vector > *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 ( - class std::vector > *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)", - time_diff, txt); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + #include + /* snprintf() & fflush() */ + #include + /* clock_t & clock() & CLOCKS_PER_SEC */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* openCV */ + #include + /* enum zbar::zbar_symbol_type_e */ + #include + +/* 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_skeleton (void) +{ + img_iface_act(IMG_IFACE_ACT_SKELETON, 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_get (int x, int y, unsigned char *val) +{ + struct Img_Iface_Data_Pixel_Get data; + data.x = x; + data.y = y; + data.val = val; + img_iface_act(IMG_IFACE_ACT_PIXEL_GET, (void *)&data); +} + +void proc_pixel_set (int x, int y, unsigned char val) +{ + struct Img_Iface_Data_Pixel_Set data; + data.x = x; + data.y = y; + data.val = val; + img_iface_act(IMG_IFACE_ACT_PIXEL_SET, (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_border (int size) +{ + struct Img_Iface_Data_Border data; + + data.size = size; + img_iface_act(IMG_IFACE_ACT_BORDER, (void *)&data); + + proc_show_img(); +} + +void proc_rotate (double center_x, double center_y, double angle) +{ + struct Img_Iface_Data_Rotate data; + + data.center.x = center_x; + data.center.y = center_y; + data.angle = 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 ( + class std::vector >> *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 ( + class std::vector >> *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 ( + class std::vector > *contour, + class cv::Rect_ *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 ( + class std::vector > *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 ( + class std::vector > *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)", + time_diff, txt); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/src/proc_iface.c b/modules/proc/src/proc_iface.c index a90466e..240b766 100644 --- a/modules/proc/src/proc_iface.c +++ b/modules/proc/src/proc_iface.c @@ -1,215 +1,215 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* errno */ - #include - #include - /* snprintf() & fflush() */ - #include - /* clock_t & clock() & CLOCKS_PER_SEC */ - #include - -/* libalx -------------------------------------------------------------------*/ - /* alx_sscan_fname() */ - #include "alx_input.h" - -/* Project -------------------------------------------------------------------*/ - /* img_iface_load() */ - #include "img_iface.h" - /* user_iface_log */ - #include "user_iface.h" - /* saved_path */ - #include "save.h" - -/* Module --------------------------------------------------------------------*/ - #include "proc_label.h" - #include "proc_objects.h" - #include "proc_coins.h" - #include "proc_resistor.h" - #include "proc_common.h" - - #include "proc_iface.h" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ - int proc_debug; - int proc_mode; - -/* Static --------------------------------------------------------------------*/ -static char proc_path [FILENAME_MAX]; -static char proc_fail_path [FILENAME_MAX]; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -int proc_iface_single (int action) -{ - int error; - clock_t time_0; - clock_t time_1; - double time_tot; - - /* Init timer */ - time_0 = clock(); - - /* Process */ - switch (action) { - case PROC_MODE_LABEL_SERIES: - error = proc_label(); - break; - case PROC_MODE_OBJECTS_CALIB: - error = proc_objects_calibrate(); - break; - case PROC_MODE_OBJECTS_SERIES: - error = proc_objects(); - break; - case PROC_MODE_COINS_SERIES: - error = proc_coins(); - break; - case PROC_MODE_RESISTOR_SERIES: - error = proc_resistor(); - break; - default: - error = -1; - } - - /* End timer */ - time_1 = clock(); - - /* Calculate time in seconds */ - time_tot = ((double) time_1 - time_0) / CLOCKS_PER_SEC; - - /* Write time into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Item total time: %.3lf", - time_tot); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - return error; -} - -void proc_iface_series (void) -{ - bool file_error; - int num_len; - char file_basename [FILENAME_MAX]; - char file_ext [80]; - char file_name [FILENAME_MAX]; - bool proc_error; - char save_error_as [FILENAME_MAX]; - bool wh; - /* if i starts being 0, the camera needs calibration */ - int i; - - switch (proc_mode) { - case PROC_MODE_LABEL_SERIES: - snprintf(proc_path, FILENAME_MAX, "%s", labels_path); - snprintf(proc_fail_path, FILENAME_MAX, "%s", labels_fail_path); - snprintf(file_basename, 80, "b"); - num_len = 4; - snprintf(file_ext, 80, ".BMP"); - i = 1; - break; - case PROC_MODE_OBJECTS_SERIES: - snprintf(proc_path, FILENAME_MAX, "%s", objects_path); - snprintf(proc_fail_path, FILENAME_MAX, "%s", objects_fail_path); - snprintf(file_basename, 80, "o"); - num_len = 4; - snprintf(file_ext, 80, ".jpeg"); - i = 0; - proc_mode++; - break; - case PROC_MODE_COINS_SERIES: - snprintf(proc_path, FILENAME_MAX, "%s", coins_path); - snprintf(proc_fail_path, FILENAME_MAX, "%s", coins_fail_path); - snprintf(file_basename, 80, "c"); - num_len = 4; - snprintf(file_ext, 80, ".png"); - i = 1; - break; - case PROC_MODE_RESISTOR_SERIES: - snprintf(proc_path, FILENAME_MAX, "%s", resistors_path); - snprintf(proc_fail_path, FILENAME_MAX, "%s", resistors_fail_path); - snprintf(file_basename, 80, "r"); - num_len = 4; - snprintf(file_ext, 80, ".png"); - i = 1; - break; - default: - return; - } - - wh = true; - for (; wh; i++) { - snprintf(file_name, FILENAME_MAX, "%s%04i%s", - file_basename, i, file_ext); - - file_error = alx_sscan_fname(proc_path, file_name, - true, file_name); - - if (file_error) { - wh = false; - } else { - errno = 0; - img_iface_load(proc_path, file_name); - - if (!errno) { - /* Process */ - proc_error = proc_iface_single(proc_mode); - - if (proc_error) { - /* Save failed image into file */ - proc_show_img(); - snprintf(save_error_as, FILENAME_MAX, - "%s%0*i_err%s", - file_basename, - num_len, i, - file_ext); - save_image_file(proc_fail_path, - save_error_as); - } - - /* Show log */ - char txt_tmp [80]; - snprintf(txt_tmp, 80, "%04i", i); - user_iface_show_log(txt_tmp, "Item"); - - if (proc_debug >= PROC_DBG_STOP_ITEM) { - getchar(); - } - } else { - printf("errno:%i\n", errno); - } - } - - if (!i) { - proc_mode--; - } - } -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* errno */ + #include + #include + /* snprintf() & fflush() */ + #include + /* clock_t & clock() & CLOCKS_PER_SEC */ + #include + +/* libalx -------------------------------------------------------------------*/ + /* alx_sscan_fname() */ + #include "alx_input.h" + +/* Project -------------------------------------------------------------------*/ + /* img_iface_load() */ + #include "img_iface.h" + /* user_iface_log */ + #include "user_iface.h" + /* saved_path */ + #include "save.h" + +/* Module --------------------------------------------------------------------*/ + #include "proc_label.h" + #include "proc_objects.h" + #include "proc_coins.h" + #include "proc_resistor.h" + #include "proc_common.h" + + #include "proc_iface.h" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ + int proc_debug; + int proc_mode; + +/* Static --------------------------------------------------------------------*/ +static char proc_path [FILENAME_MAX]; +static char proc_fail_path [FILENAME_MAX]; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +int proc_iface_single (int action) +{ + int error; + clock_t time_0; + clock_t time_1; + double time_tot; + + /* Init timer */ + time_0 = clock(); + + /* Process */ + switch (action) { + case PROC_MODE_LABEL_SERIES: + error = proc_label(); + break; + case PROC_MODE_OBJECTS_CALIB: + error = proc_objects_calibrate(); + break; + case PROC_MODE_OBJECTS_SERIES: + error = proc_objects(); + break; + case PROC_MODE_COINS_SERIES: + error = proc_coins(); + break; + case PROC_MODE_RESISTOR_SERIES: + error = proc_resistor(); + break; + default: + error = -1; + } + + /* End timer */ + time_1 = clock(); + + /* Calculate time in seconds */ + time_tot = ((double) time_1 - time_0) / CLOCKS_PER_SEC; + + /* Write time into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Item total time: %.3lf", + time_tot); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + return error; +} + +void proc_iface_series (void) +{ + bool file_error; + int num_len; + char file_basename [FILENAME_MAX]; + char file_ext [80]; + char file_name [FILENAME_MAX]; + bool proc_error; + char save_error_as [FILENAME_MAX]; + bool wh; + /* if i starts being 0, the camera needs calibration */ + int i; + + switch (proc_mode) { + case PROC_MODE_LABEL_SERIES: + snprintf(proc_path, FILENAME_MAX, "%s", labels_path); + snprintf(proc_fail_path, FILENAME_MAX, "%s", labels_fail_path); + snprintf(file_basename, 80, "b"); + num_len = 4; + snprintf(file_ext, 80, ".BMP"); + i = 1; + break; + case PROC_MODE_OBJECTS_SERIES: + snprintf(proc_path, FILENAME_MAX, "%s", objects_path); + snprintf(proc_fail_path, FILENAME_MAX, "%s", objects_fail_path); + snprintf(file_basename, 80, "o"); + num_len = 4; + snprintf(file_ext, 80, ".jpeg"); + i = 0; + proc_mode++; + break; + case PROC_MODE_COINS_SERIES: + snprintf(proc_path, FILENAME_MAX, "%s", coins_path); + snprintf(proc_fail_path, FILENAME_MAX, "%s", coins_fail_path); + snprintf(file_basename, 80, "c"); + num_len = 4; + snprintf(file_ext, 80, ".png"); + i = 1; + break; + case PROC_MODE_RESISTOR_SERIES: + snprintf(proc_path, FILENAME_MAX, "%s", resistors_path); + snprintf(proc_fail_path, FILENAME_MAX, "%s", resistors_fail_path); + snprintf(file_basename, 80, "r"); + num_len = 4; + snprintf(file_ext, 80, ".png"); + i = 1; + break; + default: + return; + } + + wh = true; + for (; wh; i++) { + snprintf(file_name, FILENAME_MAX, "%s%04i%s", + file_basename, i, file_ext); + + file_error = alx_sscan_fname(proc_path, file_name, + true, file_name); + + if (file_error) { + wh = false; + } else { + errno = 0; + img_iface_load(proc_path, file_name); + + if (!errno) { + /* Process */ + proc_error = proc_iface_single(proc_mode); + + if (proc_error) { + /* Save failed image into file */ + proc_show_img(); + snprintf(save_error_as, FILENAME_MAX, + "%s%0*i_err%s", + file_basename, + num_len, i, + file_ext); + save_image_file(proc_fail_path, + save_error_as); + } + + /* Show log */ + char txt_tmp [80]; + snprintf(txt_tmp, 80, "%04i", i); + user_iface_show_log(txt_tmp, "Item"); + + if (proc_debug >= PROC_DBG_STOP_ITEM) { + getchar(); + } + } else { + printf("errno:%i\n", errno); + } + } + + if (!i) { + proc_mode--; + } + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/src/proc_label.cpp b/modules/proc/src/proc_label.cpp index 8615d98..57acf09 100644 --- a/modules/proc/src/proc_label.cpp +++ b/modules/proc/src/proc_label.cpp @@ -1,385 +1,385 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* snprintf() */ - #include - /* strcmp() */ - #include - -/* Packages ------------------------------------------------------------------*/ - /* openCV */ - #include - /* zbar::ZBAR_EAN13 */ - #include - -/* Project -------------------------------------------------------------------*/ - /* zb_codes */ - #include "img_iface.hpp" - /* user_iface_log */ - #include "user_iface.hpp" - -/* Module --------------------------------------------------------------------*/ - #include "proc_common.hpp" - - #include "proc_label.hpp" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ - -/* Static --------------------------------------------------------------------*/ -static class std::vector >> contours; -static class cv::Mat hierarchy; -static class cv::RotatedRect rect; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_label (int status); - -static int label_find (void); -static void label_align (void); -static int find_cerdo (void); -static int barcode_read (void); -static int barcode_chk_prod (void); -static void price_read (void); -static int price_chk (void); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -int proc_label (void) -{ - int status; - - proc_save_mem(0); - /* Find label (position and angle) */ - { - /* Measure time */ - clock_start(); - - status = label_find(); - if (status) { - result_label(status); - return status; - } - - /* Measure time */ - clock_stop("Find label"); - } - /* Align label and extract green component */ - { - /* Measure time */ - clock_start(); - - label_align(); - - /* Measure time */ - clock_stop("Align label"); - } - /* Find "Cerdo" in aligned image */ - { - /* Measure time */ - clock_start(); - - status = find_cerdo(); - if (status) { - result_label(status); - return status; - } - - /* Measure time */ - clock_stop("Find cerdo (OCR)"); - } - /* Read barcode in original image */ - { - /* Measure time */ - clock_start(); - - status = barcode_read(); - if (status) { - result_label(status); - return status; - } - - /* Measure time */ - clock_stop("Read barcode (zbar)"); - } - /* Check product code in barcode */ - { - /* Measure time */ - clock_start(); - - status = barcode_chk_prod(); - if (status) { - result_label(status); - return status; - } - - /* Measure time */ - clock_stop("Chk product code"); - } - /* Read price in aligned image (green component) */ - { - /* Measure time */ - clock_start(); - - price_read(); - - /* Measure time */ - clock_stop("Read price (OCR)"); - } - /* Check label price with barcode price */ - { - /* Measure time */ - clock_start(); - - status = price_chk(); - if (status) { - result_label(status); - return status; - } - - /* Measure time */ - clock_stop("Check price"); - } - - status = LABEL_OK; - result_label(status); - return status; -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_label (int status) -{ - /* Cleanup */ - - /* Write result into log */ - switch (status) { - case LABEL_OK: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Label: OK"); - break; - case LABEL_NOK_LABEL: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Label: NOK_LABEL"); - break; - case LABEL_NOK_CERDO: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Label: NOK_CERDO"); - break; - case LABEL_NOK_BCODE: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Label: NOK_BCODE"); - break; - case LABEL_NOK_PRODUCT: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Label: NOK_PRODUCT"); - break; - case LABEL_NOK_PRICE: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Label: NOK_PRICE"); - break; - default: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Label: NOK"); - break; - } - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - -static int label_find (void) -{ - int status; - int tmp; - - proc_load_mem(0); - - 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_not(); -#endif - proc_smooth(IMGI_SMOOTH_MEAN, 21); - proc_threshold(cv::THRESH_BINARY_INV, 2); - proc_dilate_erode(100); - proc_contours(&contours, &hierarchy); - - /* If no contour is found, error: NOK_LABEL */ - if (!contours.size()) { - status = LABEL_NOK_LABEL; - return status; - } - - 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) { - rect.angle += 90.0; - tmp = rect.size.width; - rect.size.width = rect.size.height; - rect.size.height = tmp; - } - - status = LABEL_OK; - return status; -} - -static void label_align (void) -{ - proc_load_mem(0); - - proc_rotate(rect.center.x, rect.center.y, rect.angle); - proc_cmp(IMG_IFACE_CMP_GREEN); - proc_save_mem(1); -} - -static int find_cerdo (void) -{ - int status; - int x; - int y; - int w; - int h; - bool cerdo_nok; - - proc_load_mem(1); - - x = rect.center.x - (1.05 * rect.size.width / 2); - if (x < 0) { - x = 0; - } - y = rect.center.y - (1.47 * rect.size.height / 2); - if (y < 0) { - y = 0; - } - w = rect.size.width / 2; - h = rect.size.height * 0.20; - proc_ROI(x, y, w, h); - proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); - proc_erode(1); - proc_OCR(IMG_IFACE_OCR_LANG_ENG, IMG_IFACE_OCR_CONF_NONE); - - /* Compare Label text to "Cerdo". */ - cerdo_nok = strncmp(img_ocr_text, "Cerdo", - strlen("Cerdo")); - - /* If string doesn't match, error: NOK_CERDO */ - if (cerdo_nok) { - status = LABEL_NOK_CERDO; - return status; - } - - status = LABEL_OK; - return status; -} - -static int barcode_read (void) -{ - int status; - - proc_load_mem(0); - - proc_cmp(IMG_IFACE_CMP_GREEN); - proc_zbar(zbar::ZBAR_EAN13); - - /* Check that 1 and only 1 bcode is read. */ - if (zb_codes.n != 1) { - status = LABEL_NOK_BCODE; - return status; - } - - status = LABEL_OK; - return status; -} - -static int barcode_chk_prod (void) -{ - int status; - bool prod_nok; - - prod_nok = strncmp(zb_codes.arr[0].data, "2301703", - strlen("2301703")); - if (prod_nok) { - status = LABEL_NOK_PRODUCT; - return status; - } - - status = LABEL_OK; - return status; -} - -static void price_read (void) -{ - int x; - int y; - int w; - int h; - - proc_load_mem(1); - - x = rect.center.x + (0.33 * rect.size.width / 2); - y = rect.center.y + (0.64 * rect.size.height / 2); - w = rect.size.width * 0.225; - h = rect.size.height * 0.15; - proc_ROI(x, y, w, h); - proc_smooth(IMGI_SMOOTH_MEAN, 3); - proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); - proc_dilate_erode(1); - proc_threshold(cv::THRESH_BINARY, 1); - proc_OCR(IMG_IFACE_OCR_LANG_DIGITS, IMG_IFACE_OCR_CONF_PRICE); -} - -static int price_chk (void) -{ - int status; - char price [80]; - bool price_nok; - - /* Extract price from barcode */ - if (zb_codes.arr[0].data[8] != '0') { - snprintf(price, 80, "%c%c.%c%c", - zb_codes.arr[0].data[8], - zb_codes.arr[0].data[9], - zb_codes.arr[0].data[10], - zb_codes.arr[0].data[11]); - } else { - snprintf(price, 80, "%c.%c%c", - zb_codes.arr[0].data[9], - zb_codes.arr[0].data[10], - zb_codes.arr[0].data[11]); - } - - /* Compare price from barcode and from text */ - price_nok = strncmp(img_ocr_text, price, strlen(price)); - - if (price_nok) { - status = LABEL_NOK_PRICE; - return status; - } - - status = LABEL_OK; - return status; -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* snprintf() */ + #include + /* strcmp() */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* openCV */ + #include + /* zbar::ZBAR_EAN13 */ + #include + +/* Project -------------------------------------------------------------------*/ + /* zb_codes */ + #include "img_iface.hpp" + /* user_iface_log */ + #include "user_iface.hpp" + +/* Module --------------------------------------------------------------------*/ + #include "proc_common.hpp" + + #include "proc_label.hpp" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ + +/* Static --------------------------------------------------------------------*/ +static class std::vector >> contours; +static class cv::Mat hierarchy; +static class cv::RotatedRect rect; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_label (int status); + +static int label_find (void); +static void label_align (void); +static int find_cerdo (void); +static int barcode_read (void); +static int barcode_chk_prod (void); +static void price_read (void); +static int price_chk (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +int proc_label (void) +{ + int status; + + proc_save_mem(0); + /* Find label (position and angle) */ + { + /* Measure time */ + clock_start(); + + status = label_find(); + if (status) { + result_label(status); + return status; + } + + /* Measure time */ + clock_stop("Find label"); + } + /* Align label and extract green component */ + { + /* Measure time */ + clock_start(); + + label_align(); + + /* Measure time */ + clock_stop("Align label"); + } + /* Find "Cerdo" in aligned image */ + { + /* Measure time */ + clock_start(); + + status = find_cerdo(); + if (status) { + result_label(status); + return status; + } + + /* Measure time */ + clock_stop("Find cerdo (OCR)"); + } + /* Read barcode in original image */ + { + /* Measure time */ + clock_start(); + + status = barcode_read(); + if (status) { + result_label(status); + return status; + } + + /* Measure time */ + clock_stop("Read barcode (zbar)"); + } + /* Check product code in barcode */ + { + /* Measure time */ + clock_start(); + + status = barcode_chk_prod(); + if (status) { + result_label(status); + return status; + } + + /* Measure time */ + clock_stop("Chk product code"); + } + /* Read price in aligned image (green component) */ + { + /* Measure time */ + clock_start(); + + price_read(); + + /* Measure time */ + clock_stop("Read price (OCR)"); + } + /* Check label price with barcode price */ + { + /* Measure time */ + clock_start(); + + status = price_chk(); + if (status) { + result_label(status); + return status; + } + + /* Measure time */ + clock_stop("Check price"); + } + + status = LABEL_OK; + result_label(status); + return status; +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_label (int status) +{ + /* Cleanup */ + + /* Write result into log */ + switch (status) { + case LABEL_OK: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Label: OK"); + break; + case LABEL_NOK_LABEL: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Label: NOK_LABEL"); + break; + case LABEL_NOK_CERDO: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Label: NOK_CERDO"); + break; + case LABEL_NOK_BCODE: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Label: NOK_BCODE"); + break; + case LABEL_NOK_PRODUCT: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Label: NOK_PRODUCT"); + break; + case LABEL_NOK_PRICE: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Label: NOK_PRICE"); + break; + default: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Label: NOK"); + break; + } + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + +static int label_find (void) +{ + int status; + int tmp; + + proc_load_mem(0); + + 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_not(); +#endif + proc_smooth(IMGI_SMOOTH_MEAN, 21); + proc_threshold(cv::THRESH_BINARY_INV, 2); + proc_dilate_erode(100); + proc_contours(&contours, &hierarchy); + + /* If no contour is found, error: NOK_LABEL */ + if (!contours.size()) { + status = LABEL_NOK_LABEL; + return status; + } + + 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) { + rect.angle += 90.0; + tmp = rect.size.width; + rect.size.width = rect.size.height; + rect.size.height = tmp; + } + + status = LABEL_OK; + return status; +} + +static void label_align (void) +{ + proc_load_mem(0); + + proc_rotate(rect.center.x, rect.center.y, rect.angle); + proc_cmp(IMG_IFACE_CMP_GREEN); + proc_save_mem(1); +} + +static int find_cerdo (void) +{ + int status; + int x; + int y; + int w; + int h; + bool cerdo_nok; + + proc_load_mem(1); + + x = rect.center.x - (1.05 * rect.size.width / 2); + if (x < 0) { + x = 0; + } + y = rect.center.y - (1.47 * rect.size.height / 2); + if (y < 0) { + y = 0; + } + w = rect.size.width / 2; + h = rect.size.height * 0.20; + proc_ROI(x, y, w, h); + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_erode(1); + proc_OCR(IMG_IFACE_OCR_LANG_ENG, IMG_IFACE_OCR_CONF_NONE); + + /* Compare Label text to "Cerdo". */ + cerdo_nok = strncmp(img_ocr_text, "Cerdo", + strlen("Cerdo")); + + /* If string doesn't match, error: NOK_CERDO */ + if (cerdo_nok) { + status = LABEL_NOK_CERDO; + return status; + } + + status = LABEL_OK; + return status; +} + +static int barcode_read (void) +{ + int status; + + proc_load_mem(0); + + proc_cmp(IMG_IFACE_CMP_GREEN); + proc_zbar(zbar::ZBAR_EAN13); + + /* Check that 1 and only 1 bcode is read. */ + if (zb_codes.n != 1) { + status = LABEL_NOK_BCODE; + return status; + } + + status = LABEL_OK; + return status; +} + +static int barcode_chk_prod (void) +{ + int status; + bool prod_nok; + + prod_nok = strncmp(zb_codes.arr[0].data, "2301703", + strlen("2301703")); + if (prod_nok) { + status = LABEL_NOK_PRODUCT; + return status; + } + + status = LABEL_OK; + return status; +} + +static void price_read (void) +{ + int x; + int y; + int w; + int h; + + proc_load_mem(1); + + x = rect.center.x + (0.33 * rect.size.width / 2); + y = rect.center.y + (0.64 * rect.size.height / 2); + w = rect.size.width * 0.225; + h = rect.size.height * 0.15; + proc_ROI(x, y, w, h); + proc_smooth(IMGI_SMOOTH_MEAN, 3); + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_dilate_erode(1); + proc_threshold(cv::THRESH_BINARY, 1); + proc_OCR(IMG_IFACE_OCR_LANG_DIGITS, IMG_IFACE_OCR_CONF_PRICE); +} + +static int price_chk (void) +{ + int status; + char price [80]; + bool price_nok; + + /* Extract price from barcode */ + if (zb_codes.arr[0].data[8] != '0') { + snprintf(price, 80, "%c%c.%c%c", + zb_codes.arr[0].data[8], + zb_codes.arr[0].data[9], + zb_codes.arr[0].data[10], + zb_codes.arr[0].data[11]); + } else { + snprintf(price, 80, "%c.%c%c", + zb_codes.arr[0].data[9], + zb_codes.arr[0].data[10], + zb_codes.arr[0].data[11]); + } + + /* Compare price from barcode and from text */ + price_nok = strncmp(img_ocr_text, price, strlen(price)); + + if (price_nok) { + status = LABEL_NOK_PRICE; + return status; + } + + status = LABEL_OK; + return status; +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/src/proc_objects.cpp b/modules/proc/src/proc_objects.cpp index 5c30a52..026cb25 100644 --- a/modules/proc/src/proc_objects.cpp +++ b/modules/proc/src/proc_objects.cpp @@ -1,697 +1,697 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* snprintf() */ - #include - -/* Packages ------------------------------------------------------------------*/ - /* openCV */ - #include - -/* libalx ------------------------------------------------------------------*/ - /* alx_maximum_u8() */ - #include "alx_math.hpp" - -/* Project -------------------------------------------------------------------*/ - /* constants */ - #include "img_iface.hpp" - /* user_iface_log */ - #include "user_iface.hpp" - -/* Module --------------------------------------------------------------------*/ - #include "proc_common.hpp" - - #include "proc_objects.hpp" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define OBJECTS_MAX (1024) - # define PATTERN_SQUARE_LEN_MM (10.0) - - # define PATTERN_DILATE (2) - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ -struct Point { - uint16_t x_pix; - uint16_t y_pix; - - double x_mm; - double y_mm; -}; - -struct Pattern_Square { - struct Point pos; - - uint8_t len; -}; - -struct Pattern_Properties { - /* center */ - struct Point center; - struct Point origin; - - /* Angle */ - double angle; - - /* Size */ - uint16_t height; - uint16_t width; - - /* Squares (distance calibration) */ - struct Pattern_Square square [OBJECTS_MAX]; -}; - -struct Objects_Properties { - /* position */ - struct Point pos; - - /* Angle */ - double angle; - - /* Area */ - double area_pix2; - double area_mm2; - - /* Perimeter */ - double perimeter_pix; - double perimeter_mm; - - /* type */ - double ratio_p2_a; - double area_rect; - double ratio_a_arect; - double perimeter_rect; - double ratio_p_prect; -}; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ - -/* Static --------------------------------------------------------------------*/ -static class std::vector >> contours; -static class cv::Mat hierarchy; -static class cv::RotatedRect rect_rot [OBJECTS_MAX]; -static class cv::Rect_ rect [OBJECTS_MAX]; -static struct Pattern_Properties pattern; -static int squares_n; -static double ratio_mm_pix; -static int objects_n; -static struct Objects_Properties objects [OBJECTS_MAX]; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_objects (int status); - -static void pattern_bgr2gray (void); -static int pattern_find (void); -static void pattern_rotation_get (void); -static void pattern_rotation_fix (void); -static void pattern_dimensions_get (void); -static void pattern_dimensions_fix (void); -static void pattern_squares_find (void); -static void pattern_squares_pos_get (void); -static void pattern_squares_len_get (void); -static void pattern_calib_mm_pix (void); - -static void objects_bgr2gray (void); -static void objects_rotation_fix (void); -static void objects_dimensions_fix (void); -static void objects_segment (void); -static int objects_contours (void); -static void objects_position_pix (void); -static void objects_size_pix (void); -static void objects_shape (void); -static void objects_position_mm (void); -static void objects_size_mm (void); -static void objects_log (void); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -int proc_objects_calibrate (void) -{ - int status; - - proc_save_mem(0); - /* Calibrate angle with the whole pattern */ - { - /* Measure time */ - clock_start(); - - pattern_bgr2gray(); - status = pattern_find(); - if (status) { - result_objects(status); - return status; - } - pattern_rotation_get(); - pattern_rotation_fix(); - - /* Measure time */ - clock_stop("Calibrate: rotation"); - } - /* Segmentate pattern squares */ - { - /* Measure time */ - clock_start(); - - pattern_dimensions_get(); - pattern_dimensions_fix(); - - /* Measure time */ - clock_stop("Calibrate: dimensions"); - } - /* Find squares */ - { - /* Measure time */ - clock_start(); - - pattern_squares_find(); - pattern_squares_pos_get(); - pattern_squares_len_get(); - pattern_calib_mm_pix(); - - /* Measure time */ - clock_stop("Calibrate (mm per pix)"); - } - - status = OBJECTS_OK; - result_objects(status); - return status; -} - -int proc_objects (void) -{ - int status; - - proc_save_mem(0); - /* Align image */ - { - /* Measure time */ - clock_start(); - - objects_bgr2gray(); - objects_rotation_fix(); - objects_dimensions_fix(); - - /* Measure time */ - clock_stop("Align image to pattern"); - } - /* Segment objects */ - { - /* Measure time */ - clock_start(); - - objects_segment(); - - /* Measure time */ - clock_stop("Segment objects"); - } - /* Find objects positions */ - { - /* Measure time */ - clock_start(); - - status = objects_contours(); - if (status) { - result_objects(status); - return status; - } - - /* Measure time */ - clock_stop("Find objects"); - } - /* Get objects properties in pixels */ - { - /* Measure time */ - clock_start(); - - objects_position_pix(); - objects_position_mm(); - - /* Measure time */ - clock_stop("Objects positions"); - } - /* Get objects properties in mm */ - { - /* Measure time */ - clock_start(); - - objects_size_pix(); - objects_size_mm(); - - /* Measure time */ - clock_stop("Objects sizes"); - } - /* Get objects properties in mm */ - { - /* Measure time */ - clock_start(); - - objects_shape(); - - /* Measure time */ - clock_stop("Objects shapes"); - } - /* Print properties of objects into log */ - { - /* Measure time */ - clock_start(); - - objects_log(); - - /* Measure time */ - clock_stop("Objects properties (log)"); - } - - status = OBJECTS_OK; - result_objects(status); - return status; -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_objects (int status) -{ - /* Write result into log */ - switch (status) { - case OBJECTS_OK: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: OK"); - break; - case OBJECTS_NOK_OBJECTS: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK_OBJECTS"); - break; - - case OBJECTS_NOK_SIZE: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK_SIZE"); - break; - default: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK"); - break; - } - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - -/* calibration ---------------------------------------------------------------*/ -static void pattern_bgr2gray (void) -{ - proc_load_mem(0); - - proc_cvt_color(cv::COLOR_BGR2GRAY); - proc_save_mem(1); -} - -static int pattern_find (void) -{ - int status; - - proc_load_mem(1); - - proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU); - proc_erode_dilate(16); - proc_dilate(2); - proc_contours(&contours, &hierarchy); - - /* If no contour is found, error: NOK_PATTERN */ - if (contours.size() != 1) { - status = OBJECTS_NOK_PATTERN; - return status; - } - - status = OBJECTS_OK; - return status; -} - -static void pattern_rotation_get (void) -{ - proc_min_area_rect(&(contours[0]), &(rect_rot[0]), true); - - /* If angle is < -45º, it is taking into account the incorrect side */ - if (rect_rot[0].angle < -45.0) { - rect_rot[0].angle += 90.0; - } - pattern.angle = rect_rot[0].angle; - pattern.center.x_pix = rect_rot[0].center.x; - pattern.center.y_pix = rect_rot[0].center.y; - - /* Write pattern properties into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "pattern angle = %lf DEG", - -pattern.angle); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "pattern center (x) = %i pix", - pattern.center.x_pix); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "pattern center (y) = %i pix", - pattern.center.y_pix); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - -static void pattern_rotation_fix (void) -{ - proc_load_mem(1); - - /* invert image before rotation to avoid black bands */ - proc_not(); - proc_rotate(pattern.center.x_pix, pattern.center.y_pix, pattern.angle); - proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); - proc_save_mem(2); -} - -static void pattern_dimensions_get (void) -{ - proc_load_mem(2); - - proc_erode_dilate(16); - proc_dilate(PATTERN_DILATE); - proc_contours(&contours, &hierarchy); - proc_bounding_rect(&(contours[0]), &(rect[0]), true); -} - -static void pattern_dimensions_fix (void) -{ - /* Need to correct also pattern dilatation (pattern_dimensions_get()) */ - pattern.origin.x_pix = rect[0].x; - pattern.origin.y_pix = rect[0].y; - pattern.width = rect[0].width; - pattern.height = rect[0].height; - - proc_load_mem(2); - - proc_ROI(pattern.origin.x_pix, pattern.origin.y_pix, - pattern.width, pattern.height); - proc_save_mem(3); -} - -static void pattern_squares_find (void) -{ - proc_load_mem(3); - - proc_distance_transform(); - proc_local_max(); - proc_dilate(6); - proc_save_mem(4); - - proc_contours(&contours, &hierarchy); - squares_n = contours.size(); -} - -static void pattern_squares_pos_get (void) -{ - int i; - - /* Get position of each contour */ - for (i = 0; i < squares_n; i++) { - proc_bounding_rect(&(contours[i]), &(rect[i]), true); - - pattern.square[i].pos.x_pix = rect[i].x + rect[i].width/2.0; - pattern.square[i].pos.y_pix = rect[i].y + rect[i].height/2.0; - } -} - -static void pattern_squares_len_get (void) -{ - int i; - - proc_load_mem(4); - - /* Get pattern square side lenght in pixels */ - for (i = 0; i < squares_n; i++) { - proc_pixel_get(pattern.square[i].pos.x_pix, - pattern.square[i].pos.y_pix, - &(pattern.square[i].len)); - pattern.square[i].len *= 2; - } -} - -static void pattern_calib_mm_pix (void) -{ - int i; - uint8_t pattern_len [OBJECTS_MAX]; - uint8_t median_size; - - for (i = 0; i < squares_n; i++) { - pattern_len[i] = pattern.square[i].len; - } - - median_size = alx_median_u8(squares_n, pattern_len); - ratio_mm_pix = PATTERN_SQUARE_LEN_MM / median_size; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "mm/pix = %lf", - ratio_mm_pix); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - -/* process -------------------------------------------------------------------*/ -static void objects_bgr2gray (void) -{ - proc_load_mem(0); - - proc_cvt_color(cv::COLOR_BGR2GRAY); - proc_save_mem(1); -} - -static void objects_rotation_fix (void) -{ - proc_load_mem(1); - - /* invert image before rotation to avoid black bands */ - proc_not(); - proc_rotate(pattern.center.x_pix, pattern.center.y_pix, pattern.angle); - proc_save_mem(2); -} - -static void objects_dimensions_fix (void) -{ - /* Need to correct also pattern dilatation (pattern_dimensions_get()) */ - proc_load_mem(2); - - proc_ROI(pattern.origin.x_pix, pattern.origin.y_pix, - pattern.width, pattern.height); - proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); - proc_save_mem(3); -} - -static void objects_segment (void) -{ - proc_load_mem(3); - - proc_dilate_erode(3); - proc_erode_dilate(3); - proc_save_mem(4); - - proc_distance_transform(); - proc_threshold(cv::THRESH_BINARY_INV, 30); - proc_distance_transform(); - proc_skeleton(); - proc_threshold(cv::THRESH_BINARY_INV, 10); - proc_save_ref(); - proc_save_mem(5); - - proc_load_mem(3); - proc_and_2ref(); - proc_distance_transform(); - proc_threshold(cv::THRESH_BINARY, 10); - proc_save_mem(6); -} - -static int objects_contours (void) -{ - int status; - - proc_load_mem(6); - - proc_contours(&contours, &hierarchy); - objects_n = contours.size(); - - /* If no contour is found, error: NOK_OBJECTS */ - if (!objects_n) { - status = OBJECTS_NOK_OBJECTS; - return status; - } - - status = OBJECTS_OK; - return status; -} - -static void objects_position_pix (void) -{ - int i; - - /* Get position of each contour */ - for (i = 0; i < objects_n; i++) { - proc_fit_ellipse(&(contours[i]), &(rect_rot[i]), true); - - objects[i].pos.x_pix = rect_rot[i].center.x; - objects[i].pos.y_pix = rect_rot[i].center.y; - - objects[i].angle = -rect_rot[i].angle + 90.0; - if (objects[i].angle < 0) { - objects[i].angle += 180.0; - } - } -} - -static void objects_position_mm (void) -{ - int i; - - /* Get position of each contour */ - for (i = 0; i < objects_n; i++) { - objects[i].pos.x_mm = ratio_mm_pix * objects[i].pos.x_pix; - objects[i].pos.y_mm = ratio_mm_pix * objects[i].pos.y_pix; - } -} - -static void objects_size_pix (void) -{ - double area [OBJECTS_MAX]; - double perimeter [OBJECTS_MAX]; - int i; - - /* Get size of each contour */ - proc_contours_size(&contours, area, perimeter); - for (i = 0; i < objects_n; i++) { - objects[i].area_pix2 = area[i]; - objects[i].perimeter_pix = perimeter[i]; - } -} - -static void objects_size_mm (void) -{ - int i; - - /* Get position of each contour */ - for (i = 0; i < objects_n; i++) { - objects[i].area_mm2 = pow(ratio_mm_pix, 2) * - objects[i].area_pix2; - objects[i].perimeter_mm = ratio_mm_pix * - objects[i].perimeter_pix; - } -} - -static void objects_shape (void) -{ - int i; - - /* Get shape of each contour */ - for (i = 0; i < objects_n; i++) { - proc_min_area_rect(&(contours[i]), &(rect_rot[i]), true); - - objects[i].ratio_p2_a = pow(objects[i].perimeter_pix, 2) / - objects[i].area_pix2; - - objects[i].area_rect = rect_rot[i].size.width * - rect_rot[i].size.height; - objects[i].perimeter_rect = 2.0 * - (rect_rot[i].size.width + - rect_rot[i].size.height); - - objects[i].ratio_p_prect = objects[i].perimeter_pix / - objects[i].perimeter_rect; - objects[i].ratio_a_arect = objects[i].area_pix2 / - objects[i].area_rect; - } -} - -static void objects_log (void) -{ - int i; - - /* Get coins diameters in mm */ - for (i = 0; i < objects_n; i++) { - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Object[%i]:", - i); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " pos: (%.1lf, %.1lf) mm", - objects[i].pos.x_mm, - objects[i].pos.y_mm); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " ang = %.1lf DEG", - objects[i].angle); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " A = %.1lf mm2", - objects[i].area_mm2); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " P = %.1lf mm", - objects[i].perimeter_mm); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " p2/A = %.2lf", - objects[i].ratio_p2_a); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " p/p_r = %.2lf", - objects[i].ratio_p_prect); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " A/A_r = %.2lf", - objects[i].ratio_a_arect); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* snprintf() */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* openCV */ + #include + +/* libalx ------------------------------------------------------------------*/ + /* alx_maximum_u8() */ + #include "alx_math.hpp" + +/* Project -------------------------------------------------------------------*/ + /* constants */ + #include "img_iface.hpp" + /* user_iface_log */ + #include "user_iface.hpp" + +/* Module --------------------------------------------------------------------*/ + #include "proc_common.hpp" + + #include "proc_objects.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define OBJECTS_MAX (1024) + # define PATTERN_SQUARE_LEN_MM (10.0) + + # define PATTERN_DILATE (2) + + +/****************************************************************************** + ******* structs ************************************************************** + ******************************************************************************/ +struct Point { + uint16_t x_pix; + uint16_t y_pix; + + double x_mm; + double y_mm; +}; + +struct Pattern_Square { + struct Point pos; + + uint8_t len; +}; + +struct Pattern_Properties { + /* center */ + struct Point center; + struct Point origin; + + /* Angle */ + double angle; + + /* Size */ + uint16_t height; + uint16_t width; + + /* Squares (distance calibration) */ + struct Pattern_Square square [OBJECTS_MAX]; +}; + +struct Objects_Properties { + /* position */ + struct Point pos; + + /* Angle */ + double angle; + + /* Area */ + double area_pix2; + double area_mm2; + + /* Perimeter */ + double perimeter_pix; + double perimeter_mm; + + /* type */ + double ratio_p2_a; + double area_rect; + double ratio_a_arect; + double perimeter_rect; + double ratio_p_prect; +}; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ + +/* Static --------------------------------------------------------------------*/ +static class std::vector >> contours; +static class cv::Mat hierarchy; +static class cv::RotatedRect rect_rot [OBJECTS_MAX]; +static class cv::Rect_ rect [OBJECTS_MAX]; +static struct Pattern_Properties pattern; +static int squares_n; +static double ratio_mm_pix; +static int objects_n; +static struct Objects_Properties objects [OBJECTS_MAX]; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_objects (int status); + +static void pattern_bgr2gray (void); +static int pattern_find (void); +static void pattern_rotation_get (void); +static void pattern_rotation_fix (void); +static void pattern_dimensions_get (void); +static void pattern_dimensions_fix (void); +static void pattern_squares_find (void); +static void pattern_squares_pos_get (void); +static void pattern_squares_len_get (void); +static void pattern_calib_mm_pix (void); + +static void objects_bgr2gray (void); +static void objects_rotation_fix (void); +static void objects_dimensions_fix (void); +static void objects_segment (void); +static int objects_contours (void); +static void objects_position_pix (void); +static void objects_size_pix (void); +static void objects_shape (void); +static void objects_position_mm (void); +static void objects_size_mm (void); +static void objects_log (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +int proc_objects_calibrate (void) +{ + int status; + + proc_save_mem(0); + /* Calibrate angle with the whole pattern */ + { + /* Measure time */ + clock_start(); + + pattern_bgr2gray(); + status = pattern_find(); + if (status) { + result_objects(status); + return status; + } + pattern_rotation_get(); + pattern_rotation_fix(); + + /* Measure time */ + clock_stop("Calibrate: rotation"); + } + /* Segmentate pattern squares */ + { + /* Measure time */ + clock_start(); + + pattern_dimensions_get(); + pattern_dimensions_fix(); + + /* Measure time */ + clock_stop("Calibrate: dimensions"); + } + /* Find squares */ + { + /* Measure time */ + clock_start(); + + pattern_squares_find(); + pattern_squares_pos_get(); + pattern_squares_len_get(); + pattern_calib_mm_pix(); + + /* Measure time */ + clock_stop("Calibrate (mm per pix)"); + } + + status = OBJECTS_OK; + result_objects(status); + return status; +} + +int proc_objects (void) +{ + int status; + + proc_save_mem(0); + /* Align image */ + { + /* Measure time */ + clock_start(); + + objects_bgr2gray(); + objects_rotation_fix(); + objects_dimensions_fix(); + + /* Measure time */ + clock_stop("Align image to pattern"); + } + /* Segment objects */ + { + /* Measure time */ + clock_start(); + + objects_segment(); + + /* Measure time */ + clock_stop("Segment objects"); + } + /* Find objects positions */ + { + /* Measure time */ + clock_start(); + + status = objects_contours(); + if (status) { + result_objects(status); + return status; + } + + /* Measure time */ + clock_stop("Find objects"); + } + /* Get objects properties in pixels */ + { + /* Measure time */ + clock_start(); + + objects_position_pix(); + objects_position_mm(); + + /* Measure time */ + clock_stop("Objects positions"); + } + /* Get objects properties in mm */ + { + /* Measure time */ + clock_start(); + + objects_size_pix(); + objects_size_mm(); + + /* Measure time */ + clock_stop("Objects sizes"); + } + /* Get objects properties in mm */ + { + /* Measure time */ + clock_start(); + + objects_shape(); + + /* Measure time */ + clock_stop("Objects shapes"); + } + /* Print properties of objects into log */ + { + /* Measure time */ + clock_start(); + + objects_log(); + + /* Measure time */ + clock_stop("Objects properties (log)"); + } + + status = OBJECTS_OK; + result_objects(status); + return status; +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_objects (int status) +{ + /* Write result into log */ + switch (status) { + case OBJECTS_OK: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: OK"); + break; + case OBJECTS_NOK_OBJECTS: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK_OBJECTS"); + break; + + case OBJECTS_NOK_SIZE: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK_SIZE"); + break; + default: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK"); + break; + } + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + +/* calibration ---------------------------------------------------------------*/ +static void pattern_bgr2gray (void) +{ + proc_load_mem(0); + + proc_cvt_color(cv::COLOR_BGR2GRAY); + proc_save_mem(1); +} + +static int pattern_find (void) +{ + int status; + + proc_load_mem(1); + + proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU); + proc_erode_dilate(16); + proc_dilate(2); + proc_contours(&contours, &hierarchy); + + /* If no contour is found, error: NOK_PATTERN */ + if (contours.size() != 1) { + status = OBJECTS_NOK_PATTERN; + return status; + } + + status = OBJECTS_OK; + return status; +} + +static void pattern_rotation_get (void) +{ + proc_min_area_rect(&(contours[0]), &(rect_rot[0]), true); + + /* If angle is < -45º, it is taking into account the incorrect side */ + if (rect_rot[0].angle < -45.0) { + rect_rot[0].angle += 90.0; + } + pattern.angle = rect_rot[0].angle; + pattern.center.x_pix = rect_rot[0].center.x; + pattern.center.y_pix = rect_rot[0].center.y; + + /* Write pattern properties into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "pattern angle = %lf DEG", + -pattern.angle); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "pattern center (x) = %i pix", + pattern.center.x_pix); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "pattern center (y) = %i pix", + pattern.center.y_pix); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + +static void pattern_rotation_fix (void) +{ + proc_load_mem(1); + + /* invert image before rotation to avoid black bands */ + proc_not(); + proc_rotate(pattern.center.x_pix, pattern.center.y_pix, pattern.angle); + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_save_mem(2); +} + +static void pattern_dimensions_get (void) +{ + proc_load_mem(2); + + proc_erode_dilate(16); + proc_dilate(PATTERN_DILATE); + proc_contours(&contours, &hierarchy); + proc_bounding_rect(&(contours[0]), &(rect[0]), true); +} + +static void pattern_dimensions_fix (void) +{ + /* Need to correct also pattern dilatation (pattern_dimensions_get()) */ + pattern.origin.x_pix = rect[0].x; + pattern.origin.y_pix = rect[0].y; + pattern.width = rect[0].width; + pattern.height = rect[0].height; + + proc_load_mem(2); + + proc_ROI(pattern.origin.x_pix, pattern.origin.y_pix, + pattern.width, pattern.height); + proc_save_mem(3); +} + +static void pattern_squares_find (void) +{ + proc_load_mem(3); + + proc_distance_transform(); + proc_local_max(); + proc_dilate(6); + proc_save_mem(4); + + proc_contours(&contours, &hierarchy); + squares_n = contours.size(); +} + +static void pattern_squares_pos_get (void) +{ + int i; + + /* Get position of each contour */ + for (i = 0; i < squares_n; i++) { + proc_bounding_rect(&(contours[i]), &(rect[i]), true); + + pattern.square[i].pos.x_pix = rect[i].x + rect[i].width/2.0; + pattern.square[i].pos.y_pix = rect[i].y + rect[i].height/2.0; + } +} + +static void pattern_squares_len_get (void) +{ + int i; + + proc_load_mem(4); + + /* Get pattern square side lenght in pixels */ + for (i = 0; i < squares_n; i++) { + proc_pixel_get(pattern.square[i].pos.x_pix, + pattern.square[i].pos.y_pix, + &(pattern.square[i].len)); + pattern.square[i].len *= 2; + } +} + +static void pattern_calib_mm_pix (void) +{ + int i; + uint8_t pattern_len [OBJECTS_MAX]; + uint8_t median_size; + + for (i = 0; i < squares_n; i++) { + pattern_len[i] = pattern.square[i].len; + } + + median_size = alx_median_u8(squares_n, pattern_len); + ratio_mm_pix = PATTERN_SQUARE_LEN_MM / median_size; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "mm/pix = %lf", + ratio_mm_pix); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + +/* process -------------------------------------------------------------------*/ +static void objects_bgr2gray (void) +{ + proc_load_mem(0); + + proc_cvt_color(cv::COLOR_BGR2GRAY); + proc_save_mem(1); +} + +static void objects_rotation_fix (void) +{ + proc_load_mem(1); + + /* invert image before rotation to avoid black bands */ + proc_not(); + proc_rotate(pattern.center.x_pix, pattern.center.y_pix, pattern.angle); + proc_save_mem(2); +} + +static void objects_dimensions_fix (void) +{ + /* Need to correct also pattern dilatation (pattern_dimensions_get()) */ + proc_load_mem(2); + + proc_ROI(pattern.origin.x_pix, pattern.origin.y_pix, + pattern.width, pattern.height); + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_save_mem(3); +} + +static void objects_segment (void) +{ + proc_load_mem(3); + + proc_dilate_erode(3); + proc_erode_dilate(3); + proc_save_mem(4); + + proc_distance_transform(); + proc_threshold(cv::THRESH_BINARY_INV, 30); + proc_distance_transform(); + proc_skeleton(); + proc_threshold(cv::THRESH_BINARY_INV, 10); + proc_save_ref(); + proc_save_mem(5); + + proc_load_mem(3); + proc_and_2ref(); + proc_distance_transform(); + proc_threshold(cv::THRESH_BINARY, 10); + proc_save_mem(6); +} + +static int objects_contours (void) +{ + int status; + + proc_load_mem(6); + + proc_contours(&contours, &hierarchy); + objects_n = contours.size(); + + /* If no contour is found, error: NOK_OBJECTS */ + if (!objects_n) { + status = OBJECTS_NOK_OBJECTS; + return status; + } + + status = OBJECTS_OK; + return status; +} + +static void objects_position_pix (void) +{ + int i; + + /* Get position of each contour */ + for (i = 0; i < objects_n; i++) { + proc_fit_ellipse(&(contours[i]), &(rect_rot[i]), true); + + objects[i].pos.x_pix = rect_rot[i].center.x; + objects[i].pos.y_pix = rect_rot[i].center.y; + + objects[i].angle = -rect_rot[i].angle + 90.0; + if (objects[i].angle < 0) { + objects[i].angle += 180.0; + } + } +} + +static void objects_position_mm (void) +{ + int i; + + /* Get position of each contour */ + for (i = 0; i < objects_n; i++) { + objects[i].pos.x_mm = ratio_mm_pix * objects[i].pos.x_pix; + objects[i].pos.y_mm = ratio_mm_pix * objects[i].pos.y_pix; + } +} + +static void objects_size_pix (void) +{ + double area [OBJECTS_MAX]; + double perimeter [OBJECTS_MAX]; + int i; + + /* Get size of each contour */ + proc_contours_size(&contours, area, perimeter); + for (i = 0; i < objects_n; i++) { + objects[i].area_pix2 = area[i]; + objects[i].perimeter_pix = perimeter[i]; + } +} + +static void objects_size_mm (void) +{ + int i; + + /* Get position of each contour */ + for (i = 0; i < objects_n; i++) { + objects[i].area_mm2 = pow(ratio_mm_pix, 2) * + objects[i].area_pix2; + objects[i].perimeter_mm = ratio_mm_pix * + objects[i].perimeter_pix; + } +} + +static void objects_shape (void) +{ + int i; + + /* Get shape of each contour */ + for (i = 0; i < objects_n; i++) { + proc_min_area_rect(&(contours[i]), &(rect_rot[i]), true); + + objects[i].ratio_p2_a = pow(objects[i].perimeter_pix, 2) / + objects[i].area_pix2; + + objects[i].area_rect = rect_rot[i].size.width * + rect_rot[i].size.height; + objects[i].perimeter_rect = 2.0 * + (rect_rot[i].size.width + + rect_rot[i].size.height); + + objects[i].ratio_p_prect = objects[i].perimeter_pix / + objects[i].perimeter_rect; + objects[i].ratio_a_arect = objects[i].area_pix2 / + objects[i].area_rect; + } +} + +static void objects_log (void) +{ + int i; + + /* Get coins diameters in mm */ + for (i = 0; i < objects_n; i++) { + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Object[%i]:", + i); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " pos: (%.1lf, %.1lf) mm", + objects[i].pos.x_mm, + objects[i].pos.y_mm); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " ang = %.1lf DEG", + objects[i].angle); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " A = %.1lf mm2", + objects[i].area_mm2); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " P = %.1lf mm", + objects[i].perimeter_mm); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " p2/A = %.2lf", + objects[i].ratio_p2_a); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " p/p_r = %.2lf", + objects[i].ratio_p_prect); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " A/A_r = %.2lf", + objects[i].ratio_a_arect); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/src/proc_resistor.cpp b/modules/proc/src/proc_resistor.cpp index cdac617..58f1fe4 100644 --- a/modules/proc/src/proc_resistor.cpp +++ b/modules/proc/src/proc_resistor.cpp @@ -1,1459 +1,1459 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* pow() */ - #include - /* snprintf() & fflush() */ - #include - -/* Packages ------------------------------------------------------------------*/ - /* openCV */ - #include - -/* Project -------------------------------------------------------------------*/ - /* CONSTANTS */ - #include "img_iface.hpp" - /* user_iface_log */ - #include "user_iface.hpp" - -/* Module --------------------------------------------------------------------*/ - #include "proc_common.hpp" - - #include "proc_resistor.hpp" - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ -struct Resistor_Bands { - /* position */ - int x; - int y; - - /* value */ - unsigned char h; - unsigned char s; - unsigned char v; -}; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ - -/* Static --------------------------------------------------------------------*/ -static class std::vector >> contours; -static class cv::Mat hierarchy; -static class cv::RotatedRect rect_rot; -static class cv::Rect_ rect; -static int bkgd; -static int bands_n; -static struct Resistor_Bands bands [5]; -static char code [6]; -static int base; -static float resistance; -static int tolerance; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_resistor (int status); - -static int resistor_find (void); -static void resistor_align (void); -static void resistor_dimensions_0 (void); -static void resistor_crop_0 (void); -static void resistor_bkgd (void); -static void resistor_dimensions_1 (void); -static void resistor_crop_1 (void); -static void separate_bkgd_bands_h (void); -static void separate_bkgd_bands_s (void); -static void separate_bkgd_bands_v (void); -static void bkgd_find (void); -static int bands_find (void); -static void bands_colors (void); -static void bands_code (void); -static char band_hsv2code (struct Resistor_Bands *band); -static void bands_code_deduce_0 (void); -static void bands_code_deduce_1 (void); -static int bands_code_deduce_no (void); -static void resistor_value (void); -static int resistor_tolerance (void); -static int chk_std_value (void); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -int proc_resistor (void) -{ - int status; - - proc_save_mem(0); - /* Find resistor (position and angle) */ - { - /* Measure time */ - clock_start(); - - status = resistor_find(); - if (status) { - result_resistor(status); - return status; - } - - /* Measure time */ - clock_stop("Find resistor"); - } - /* Align resistor, find its dimensions, and crop */ - { - /* Measure time */ - clock_start(); - - resistor_align(); - resistor_dimensions_0(); - resistor_crop_0(); - - /* Measure time */ - clock_stop("Align, dimensions, & crop"); - } - /* Find backgroung color */ - { - /* Measure time */ - clock_start(); - - resistor_bkgd(); - - /* Measure time */ - clock_stop("Background color"); - } - /* Crop more */ - { - /* Measure time */ - clock_start(); - - resistor_dimensions_1(); - resistor_crop_1(); - - /* Measure time */ - clock_stop("Crop more"); - } - /* Separate background (BK) and lines (WH) */ - { - /* Measure time */ - clock_start(); - - separate_bkgd_bands_h(); - separate_bkgd_bands_s(); - separate_bkgd_bands_v(); - bkgd_find(); - - /* Measure time */ - clock_stop("Separate bkgd from bands"); - } - /* Find bands: contours -> rectangles */ - { - /* Measure time */ - clock_start(); - - status = bands_find(); - if (status) { - result_resistor(status); - return status; - } - - /* Measure time */ - clock_stop("Find bands"); - } - /* Read values on the center of each band */ - { - /* Measure time */ - clock_start(); - - bands_colors(); - - /* Measure time */ - clock_stop("Bands' colors"); - } - /* Interpret colors */ - { - /* Measure time */ - clock_start(); - - bands_code(); - bands_code_deduce_0(); - bands_code_deduce_1(); - status = bands_code_deduce_no(); - if (status) { - result_resistor(status); - return status; - } - - /* Measure time */ - clock_stop("Interpret colors"); - } - /* Calculate resistor value & tolerance */ - { - /* Measure time */ - clock_start(); - - resistor_value(); - status = resistor_tolerance(); - if (status) { - result_resistor(status); - return status; - } - - /* Write resistor value into log */ - if (bands_n != 1) { - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistance: %.2E ± %i%% Ohm", - resistance, tolerance); - } else { - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistance: 0 Ohm"); - } - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Measure time */ - clock_stop("Calculate resistance & tolerance"); - } - /* Check STD value */ - { - /* Measure time */ - clock_start(); - - status = chk_std_value(); - if (status) { - result_resistor(status); - return status; - } - - /* Measure time */ - clock_stop("Chk STD values"); - } - - status = RESISTOR_OK; - result_resistor(status); - return status; -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_resistor (int status) -{ - /* Write result into log */ - switch (status) { - case RESISTOR_OK: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistor: OK"); - break; - case RESISTOR_NOK_RESISTOR: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistor: NOK_RESISTOR"); - break; - case RESISTOR_NOK_BANDS: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistor: NOK_BANDS"); - break; - case RESISTOR_NOK_COLOR: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistor: NOK_COLOR"); - break; - case RESISTOR_NOK_STD_VALUE: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistor: NOK_STD_VALUE"); - break; - case RESISTOR_NOK_TOLERANCE: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistor: NOK_TOLERANCE"); - break; - default: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistor: NOK"); - break; - } - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - -static int resistor_find (void) -{ - int status; - - proc_load_mem(0); - - /* BGR -> HSV */ - proc_cvt_color(cv::COLOR_BGR2HSV); - proc_save_mem(19); - - proc_cmp(IMG_IFACE_CMP_SATURATION); - proc_smooth(IMGI_SMOOTH_MEDIAN, 7); - proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); - proc_save_mem(1); - proc_dilate_erode(10); - proc_contours(&contours, &hierarchy); - - /* If no contour is found, error: NOK_RESISTOR */ - if (!contours.size()) { - status = RESISTOR_NOK_RESISTOR; - return status; - } - - proc_min_area_rect(&(contours[0]), &rect_rot, true); - - /* If angle is < -45º, it is taking into acount the incorrect side */ - if (rect_rot.angle < -45.0) { - rect_rot.angle += 90.0; - } - - status = RESISTOR_OK; - return status; -} - -static void resistor_align (void) -{ - proc_load_mem(19); - proc_rotate(rect_rot.center.x, rect_rot.center.y, rect_rot.angle); - proc_save_mem(2); - proc_load_mem(1); - proc_rotate(rect_rot.center.x, rect_rot.center.y, rect_rot.angle); - proc_save_mem(3); -} - -static void resistor_dimensions_0 (void) -{ - proc_load_mem(3); - - proc_dilate_erode(10); - proc_contours(&contours, &hierarchy); - proc_bounding_rect(&(contours[0]), &rect, true); -} - -static void resistor_crop_0 (void) -{ - int x; - int y; - int w; - int h; - - proc_load_mem(2); - - w = rect.width; - h = rect.height; - x = rect.x; - y = rect.y; - proc_ROI(x, y, w, h); - proc_save_mem(4); -} - -static void resistor_bkgd (void) -{ - uint8_t bkgd_hue; - uint8_t bkgd_sat; - - /* hue */ - proc_load_mem(4); - proc_cmp(IMG_IFACE_CMP_HUE); - proc_median_vertical(); - proc_median_horizontal(); - proc_pixel_get(0, 0, &bkgd_hue); - - /* saturation */ - proc_load_mem(4); - proc_cmp(IMG_IFACE_CMP_SATURATION); - proc_median_vertical(); - proc_median_horizontal(); - proc_pixel_get(0, 0, &bkgd_sat); - - if (bkgd_hue < 50) { - /* Beige */ - bkgd = 0; - } else { - /* Blue */ - if ((bkgd_hue < 90) || (bkgd_sat < 100)) { - /* Teal blue */ - bkgd = 1; - } else if (bkgd_hue >= 105) { - /* Dark blue */ - bkgd = 2; - } else { - /* Normal blue */ - bkgd = 3; - } - } -} - -static void resistor_dimensions_1 (void) -{ - proc_load_mem(3); - - proc_dilate_erode(10); - proc_erode_dilate((rect.height * 0.67) / 2); - proc_contours(&contours, &hierarchy); - proc_bounding_rect(&(contours[0]), &rect, true); -} - -static void resistor_crop_1 (void) -{ - int x; - int y; - int w; - int h; - - proc_load_mem(2); - - w = rect.width * 0.95; - h = rect.height * 0.8; - x = rect.x + w * (1.0 - 0.95) / 2.0; - y = rect.y + h * (1.0 - 0.8) / 2.0; - proc_ROI(x, y, w, h); - proc_save_mem(4); -} - -static void separate_bkgd_bands_h (void) -{ - proc_load_mem(4); - - proc_cmp(IMG_IFACE_CMP_HUE); - proc_median_vertical(); - proc_save_mem(9); - - switch (bkgd) { - case 0: - proc_threshold(cv::THRESH_TOZERO_INV, 20); - proc_threshold(cv::THRESH_TOZERO, 5); - break; - case 1: - proc_threshold(cv::THRESH_TOZERO_INV, 100); - proc_threshold(cv::THRESH_TOZERO, 70); - break; - case 2: - proc_threshold(cv::THRESH_TOZERO_INV, 115); - proc_threshold(cv::THRESH_TOZERO, 100); - break; - case 3: - proc_threshold(cv::THRESH_TOZERO_INV, 110); - proc_threshold(cv::THRESH_TOZERO, 90); - break; - } - proc_threshold(cv::THRESH_BINARY_INV, 1); - proc_save_mem(5); -} - -static void separate_bkgd_bands_s (void) -{ - proc_load_mem(4); - - proc_cmp(IMG_IFACE_CMP_SATURATION); - proc_median_vertical(); - proc_save_mem(10); - - switch (bkgd) { - - case 0: - proc_threshold(cv::THRESH_TOZERO_INV, 160); - proc_threshold(cv::THRESH_TOZERO, 110); - break; - case 1: - proc_threshold(cv::THRESH_TOZERO_INV, 180); - proc_threshold(cv::THRESH_TOZERO, 30); - break; - case 2: - proc_threshold(cv::THRESH_TOZERO_INV, 190); - proc_threshold(cv::THRESH_TOZERO, 170); - break; - case 3: - proc_threshold(cv::THRESH_TOZERO_INV, 210); - proc_threshold(cv::THRESH_TOZERO, 120); - break; - } - proc_threshold(cv::THRESH_BINARY_INV, 1); - proc_save_mem(6); -} - -static void separate_bkgd_bands_v (void) -{ - proc_load_mem(4); - - proc_cmp(IMG_IFACE_CMP_VALUE); - proc_median_vertical(); - proc_save_mem(11); - - switch (bkgd) { - case 0: - proc_threshold(cv::THRESH_TOZERO_INV, 170); - proc_threshold(cv::THRESH_TOZERO, 100); - break; - - case 1: - proc_threshold(cv::THRESH_TOZERO_INV, 180); - proc_threshold(cv::THRESH_TOZERO, 100); - break; - case 2: - proc_threshold(cv::THRESH_TOZERO_INV, 180); - proc_threshold(cv::THRESH_TOZERO, 150); - break; - case 3: - proc_threshold(cv::THRESH_TOZERO_INV, 190); - proc_threshold(cv::THRESH_TOZERO, 90); - break; - } - proc_threshold(cv::THRESH_BINARY_INV, 1); - proc_save_mem(7); -} - -static void bkgd_find (void) -{ - /* Merge the components: H | S | V */ - proc_load_mem(7); - proc_save_ref(); - proc_load_mem(6); - proc_or_2ref(); - proc_save_ref(); - proc_load_mem(5); - proc_or_2ref(); - if (rect.width * 0.95 > 80) { - proc_dilate_erode(1); - } - proc_save_mem(8); -} - -static int bands_find (void) -{ - int status; - - proc_load_mem(8); - - /* Contours */ - proc_contours(&contours, &hierarchy); - if (contours.size() > 5) { - proc_load_mem(8); - proc_dilate_erode(1); - proc_contours(&contours, &hierarchy); - } - - bands_n = contours.size(); - if ((bands_n == 0) || (bands_n == 2) || (bands_n > 5)) { - status = RESISTOR_NOK_BANDS; - return status; - } - - /* Band 0 (hundreds) */ - if (bands_n == 5) { - proc_bounding_rect(&(contours[4]), &rect, true); - bands[0].x = rect.x + rect.width / 2.0; - bands[0].y = rect.y + rect.height / 2.0; - } - - /* Band 1 (tens) */ - if (bands_n >= 3) { - if (bands_n > 3) { - proc_bounding_rect(&(contours[3]), &rect, true); - } else { - proc_bounding_rect(&(contours[2]), &rect, true); - } - bands[1].x = rect.x + rect.width / 2.0; - bands[1].y = rect.y + rect.height / 2.0; - } - - /* Band 2 (units) */ - if (bands_n > 3) { - proc_bounding_rect(&(contours[2]), &rect, true); - } else if (bands_n == 3) { - proc_bounding_rect(&(contours[1]), &rect, true); - } else { /* bands_n == 1 */ - proc_bounding_rect(&(contours[0]), &rect, true); - } - bands[2].x = rect.x + rect.width / 2.0; - bands[2].y = rect.y + rect.height / 2.0; - - /* Band 3 (multiplier) */ - if (bands_n >= 3) { - if (bands_n > 3) { - proc_bounding_rect(&(contours[1]), &rect, true); - } else { - proc_bounding_rect(&(contours[0]), &rect, true); - } - bands[3].x = rect.x + rect.width / 2.0; - bands[3].y = rect.y + rect.height / 2.0; - } - - /* Band 4 (tolerance) */ - if (bands_n > 3) { - proc_bounding_rect(&(contours[0]), &rect, true); - bands[4].x = rect.x + rect.width / 2.0; - bands[4].y = rect.y + rect.height / 2.0; - } - - status = RESISTOR_OK; - return status; -} - -static void bands_colors (void) -{ - /* Hue */ - proc_load_mem(9); - if (bands_n == 5) { - proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].h)); - } - if (bands_n >= 3) { - proc_pixel_get(bands[1].x, bands[1].y, &(bands[1].h)); - } - proc_pixel_get(bands[2].x, bands[2].y, &(bands[2].h)); - if (bands_n >= 3) { - proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].h)); - } - if (bands_n > 3) { - proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].h)); - } - - /* Saturation */ - proc_load_mem(10); - if (bands_n == 5) { - proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].s)); - } - if (bands_n >= 3) { - proc_pixel_get(bands[1].x, bands[1].y, &(bands[1].s)); - } - proc_pixel_get(bands[2].x, bands[2].y, &(bands[2].s)); - if (bands_n >= 3) { - proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].s)); - } - if (bands_n > 3) { - proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].s)); - } - - /* Value */ - proc_load_mem(11); - if (bands_n == 5) { - proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].v)); - } - if (bands_n >= 3) { - proc_pixel_get(bands[1].x, bands[1].y, &(bands[1].v)); - } - proc_pixel_get(bands[2].x, bands[2].y, &(bands[2].v)); - if (bands_n >= 3) { - proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].v)); - } - if (bands_n > 3) { - proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].v)); - } -} - -static void bands_code (void) -{ - int i; - - /* Init to 0 */ - for (i = 0; i < 6; i++) { - code[i] = '\0'; - } - - /* Band 0 (hundreds) */ - if (bands_n == 5) { - code[0] = band_hsv2code(&bands[0]); - } else { - code[0] = 'n'; - } - - - /* Band 1 (tens) */ - if (bands_n != 1) { - code[1] = band_hsv2code(&bands[1]); - } else { - code[1] = 'n'; - } - - /* Band 2 (units) */ - code[2] = band_hsv2code(&bands[2]); - - /* Band 3 (multiplier) */ - if (bands_n != 1) { - code[3] = band_hsv2code(&bands[3]); - } else { - code[3] = 'n'; - } - - /* Band 4 (tolerance) */ - if (bands_n > 3) { - code[4] = band_hsv2code(&bands[4]); - } else { - code[4] = 'n'; - } - - /* 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)++; -} - -static char band_hsv2code (struct Resistor_Bands *band) -{ - char ch; - - /* - * Not able to segmentate: - * q = 1 2 - * w = 2 3 - * e = 3 g - * r = 3 4 - * t = 1 8 - * y = 0 1 - * u = 0 1 8 - */ - - if (band->h < 10) { - // 1 2 3 - if (band->s < 90) { - // 1 3 - if (band->v < 85) { - ch = '1'; - } else { - ch = '3'; - } - } else if (band->s < 140) { - // 1 2 3 - if (band->v < 60) { - ch = '1'; - } else if (band->v < 85) { - // 1 2 - ch = 'q'; - } else if (band->v < 90) { - ch = '2'; - } else if (band->v < 150) { - // 2 3 - ch = 'w'; - } else { - ch = '3'; - } - } else if (band->s < 210) { - // 2 3 - if (band->v < 90) { - ch = '2'; - } else if (band->v < 150) { - // 2 3 - ch = 'w'; - } else { - ch = '3'; - } - } else { - ch = '3'; - } - } else if (band->h < 35) { - // 1 3 g - if (band->s < 130) { - // 1 3 - if (band->v < 85) { - ch = '1'; - } else { - ch = '3'; - } - } else if (band->s < 140) { - // 1 3 g - if (band->v < 85) { - ch = '1'; - } else if (band->v < 120) { - ch = '3'; - } else { - // 3 g - ch = 'e'; - } - } else if (band->s < 180) { - // 3 g - if (band->v < 120) { - ch = '3'; - } else { - // 3 g - ch = 'e'; - } - } else { - ch = '3'; - } - } else if (band->h < 50) { - // 1 3 - if (band->s < 140) { - // 1 3 - if (band->v < 85) { - ch = '1'; - } else { - ch = '3'; - } - } else { - ch = '3'; - } - } else if (band->h < 60) { - // 1 3 4 - if (band->s < 140) { - // 1 3 - if (band->v < 85) { - ch = '1'; - } else { - ch = '3'; - } - } else if (band->s < 160) { - ch = '3'; - } else if (band->s < 180) { - // 3 4 - if (band->v < 110) { - // 3 4 - ch = 'r'; - } else { - ch = '3'; - } - } else { - ch = '3'; - } - } else if (band->h < 80) { - // 1 5 - if (band->s < 165) { - ch = '1'; - } else { - ch = '5'; - } - } else if (band->h < 90) { - ch = '1'; - } else if (band->h < 100) { - // 0 1 8 9 - if (band->s < 40) { - // 1 8 9 - if (band->v < 55) { - ch = '1'; - } else if (band->v < 80) { - // 1 8 - ch = 't'; - } else if (band->v < 125) { - ch = '1'; - } else { - ch = '9'; - } - } else if (band->s < 70) { - // 0 1 8 9 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 55) { - // 0 1 - ch = 'y'; - } else if (band->v < 75) { - // 0 1 8 - ch = 'u'; - } else if (band->v < 80) { - // 1 8 - ch = 't'; - } else if (band->v < 125) { - ch = '1'; - } else { - ch = '9'; - } - } else if (band->s < 100) { - // 0 1 8 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 55) { - // 0 1 - ch = 'y'; - } else if (band->v < 75) { - // 0 1 8 - ch = 'u'; - } else if (band->v < 80) { - // 1 8 - ch = 't'; - } else { - ch = '1'; - } - } else if (band->s < 140) { - // 0 1 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else { - ch = '1'; - } - } else { - ch = '0'; - } - } else if (band->h < 110) { - // 0 1 6 8 - if (band->s < 40) { - // 1 8 - if (band->v < 55) { - ch = '1'; - } else if (band->v < 80) { - // 1 8 - ch = 't'; - } else { - ch = '1'; - } - } else if (band->s < 100) { - // 0 1 8 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 55) { - // 0 1 - ch = 'y'; - } else if (band->v < 75) { - // 0 1 8 - ch = 'u'; - } else if (band->v < 80) { - // 1 8 - ch = 't'; - } else { - ch = '1'; - } - } else if (band->s < 140) { - // 0 1 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else { - ch = '1'; - } - } else if (band->s < 200) { - ch = '0'; - } else { - ch = '6'; - } - } else if (band->h < 120) { - // 0 1 6 7 - if (band->s < 40) { - ch = '1'; - } else if (band->s < 90) { - // 0 1 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else { - ch = '1'; - } - } else if (band->s < 110) { - // 0 1 7 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else if (band->v < 120) { - ch = '1'; - } else { - ch = '7'; - } - } else if (band->s < 140) { - // 0 1 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else { - ch = '1'; - } - } else if (band->s < 200) { - ch = '0'; - } else { - ch = '6'; - } - } else if (band->h < 130) { - // 0 1 7 - if (band->s < 40) { - ch = '1'; - } else if (band->s < 90) { - // 0 1 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else { - ch = '1'; - } - } else if (band->s < 110) { - // 0 1 7 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else if (band->v < 120) { - ch = '1'; - } else { - ch = '7'; - } - } else if (band->s < 140) { - // 0 1 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else { - ch = '1'; - } - } else { - ch = '0'; - } - } else if (band->h < 140) { - // 0 1 - if (band->s < 40) { - ch = '1'; - } else if (band->s < 140) { - // 0 1 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else { - ch = '1'; - } - } else { - ch = '0'; - } - } else if (band->h < 150) { - ch = '0'; - } else { - ch = '2'; - } - - return ch; -} - -static void bands_code_deduce_0 (void) -{ - /* - * Not able to segmentate: - * q = 1 2 - * w = 2 3 - * e = 3 g - * r = 3 4 - * t = 1 8 - * y = 0 1 - * u = 0 1 8 - */ - - /* Band 0 (hundreds) */ - switch (code[0]) { - case 'e': - code[0] = '3'; - break; - case 'y': - code[0] = '1'; - break; - case 'u': - code[0] = 't'; - break; - } - - /* Band 2 (units) */ - switch (code[2]) { - case 'e': - code[2] = '3'; - break; - } - - /* Band 3 (multiplier) */ - switch (code[3]) { - case 't': - code[3] = '1'; - break; - case 'u': - code[3] = 'y'; - break; - } - - /* Band 4 (tolerance) */ - switch (code[4]) { - case 'w': - code[4] = '2'; - break; - case 'e': - code[4] = 'g'; - break; - case 't': - code[4] = '1'; - break; - case 'y': - code[4] = '1'; - break; - case 'u': - code[4] = '1'; - break; - } - - /* 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)++; -} - -static void bands_code_deduce_1 (void) -{ - /* - * Not able to segmentate: - - * q = 1 2 - * w = 2 3 - * e = 3 g - * r = 3 4 - * t = 1 8 - * y = 0 1 - - * u = 0 1 8 - */ - - /* Band 0 (hundreds) */ - switch (code[0]) { - case 'q': - switch (code[1]) { - case '1': - case '3': - case '5': - case '6': - case '8': - code[0] = '1'; - break; - case '2': - case '4': - case '7': - code[0] = '2'; - break; - case '0': - // q - break; - } - break; - case 'w': - switch (code[1]) { - case '2': - case '4': - case '7': - code[0] = '2'; - break; - case '3': - case '6': - case '9': - code[0] = '3'; - break; - case '0': - // w - break; - } - break; - case 'r': - switch (code[1]) { - case '0': - case '6': - case '9': - code[0] = '3'; - break; - case '7': - code[0] = '4'; - break; - case '3': - // r - break; - } - break; - case 't': - switch (code[1]) { - case '0': - case '1': - case '3': - case '5': - case '6': - case '8': - code[0] = '1'; - break; - case '2': - // t - break; - } - break; - } - - /* Band 1 (tens) */ - switch (code[1]) { - case 'q': - switch (code[0]) { - case '5': - case '9': - code[1] = '1'; - break; - case '2': - case '6': - case '8': - code[1] = '2'; - break; - case '1': - // q - break; - } - break; - case 'w': - switch (code[0]) { - case '2': - case '6': - case '8': - code[1] = '2'; - break; - case '3': - case '4': - code[1] = '3'; - break; - case '1': - // w - break; - } - break; - case 't': - switch (code[0]) { - case '5': - case '9': - code[1] = '1'; - break; - case '6': - code[1] = '8'; - break; - case '1': - // t - break; - } - break; - case 'y': - switch (code[0]) { - case '2': - case '3': - code[1] = '0'; - break; - case '5': - case '9': - code[1] = '1'; - break; - case '1': - // y - break; - } - break; - case 'u': - switch (code[0]) { - case '2': - case '3': - code[1] = '0'; - break; - case '5': - case '9': - code[1] = '1'; - break; - case '6': - code[1] = '8'; - break; - case '1': - // u - break; - } - break; - } - - /* Band 2 (units) */ - switch (code[2]) { - case 'y': - code[2] = '0'; - break; - case 'u': - code[2] = '0'; - break; - } - - /* Band 3 (multiplier) */ - switch (code[3]) { - case 'y': - code[3] = '0'; - break; - } - - /* Band 4 (tolerance) */ - switch (code[4]) { - case 'q': - code[4] = '2'; - break; - } - - /* 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)++; -} - -static int bands_code_deduce_no (void) -{ - int status; - int i; - - /* - * Not able to segmentate: - * q = 1 2 - * w = 2 3 - * e = 3 g - * r = 3 4 - * t = 1 8 - * y = 0 1 - * u = 0 1 8 - */ - - for (i = 0; i < 5; i++) { - switch (code[i]) { - case 'q': - case 'w': - case 'e': - case 'r': - case 't': - case 'y': - case 'u': - code[i] = '?'; - break; - } - } - - for (i = 0; i < 5; i++) { - if (code[i] == '?') { - status = RESISTOR_NOK_COLOR; - return status; - } - } - - /* 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)++; - - status = RESISTOR_OK; - return status; -} - -static void resistor_value (void) -{ - int power; - - /* Base value */ - base = code[2] - '0'; - if (code[1] != 'n') { - base += (code[1] - '0') * 10; - } - if (code[0] != 'n') { - base += (code[0] - '0') * 100; - } - - /* Calculate resistance */ - if ((code[3] > '0') && (code[3] < '9')) { - power = code[3] - '0'; - } else if (code[3] == 'g') { - power = -1; - } else if (code[3] == 's') { - power = -2; - } else { - // error - return; - } - resistance = base * pow(10, power); -} - -static int resistor_tolerance (void) -{ - int status; - - if (bands_n != 1) { - switch (code[4]) { - case '1': - tolerance = 1; - break; - case '2': - tolerance = 2; - break; - case '4': - case 'g': - case 'n': - tolerance = 5; - break; - case '8': - tolerance = 10; - break; - default: - status = RESISTOR_NOK_TOLERANCE; - return status; - } - } - - status = RESISTOR_OK; - return status; -} - -static int chk_std_value (void) -{ - int status; - /* Check that base value is a standard value */ - int std_values_10 [12] = {10,12,15,18,22,27,33,39,47,56,68,82}; - int std_values_5 [12] = {11,13,16,20,24,30,36,43,51,62,75,91}; - bool std_value_nok = true; - int i; - - if (bands_n != 1) { - for (i = 0; i < 12; i++) { - if (base == std_values_10[i]) { - std_value_nok = false; - } - if (base == (std_values_10[i] * 10)) { - std_value_nok = false; - } - } - if (tolerance <= 5) { - for (i = 0; i < 12; i++) { - if (base == std_values_5[i]) { - std_value_nok = false; - } - if (base == (std_values_5[i] * 10)) { - std_value_nok = false; - } - } - } - } else { - if (base == 0) { - std_value_nok = false; - } - } - - if (std_value_nok) { - status = RESISTOR_NOK_STD_VALUE; - return status; - } - - status = RESISTOR_OK; - return status; -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* pow() */ + #include + /* snprintf() & fflush() */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* openCV */ + #include + +/* Project -------------------------------------------------------------------*/ + /* CONSTANTS */ + #include "img_iface.hpp" + /* user_iface_log */ + #include "user_iface.hpp" + +/* Module --------------------------------------------------------------------*/ + #include "proc_common.hpp" + + #include "proc_resistor.hpp" + + +/****************************************************************************** + ******* structs ************************************************************** + ******************************************************************************/ +struct Resistor_Bands { + /* position */ + int x; + int y; + + /* value */ + unsigned char h; + unsigned char s; + unsigned char v; +}; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ + +/* Static --------------------------------------------------------------------*/ +static class std::vector >> contours; +static class cv::Mat hierarchy; +static class cv::RotatedRect rect_rot; +static class cv::Rect_ rect; +static int bkgd; +static int bands_n; +static struct Resistor_Bands bands [5]; +static char code [6]; +static int base; +static float resistance; +static int tolerance; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_resistor (int status); + +static int resistor_find (void); +static void resistor_align (void); +static void resistor_dimensions_0 (void); +static void resistor_crop_0 (void); +static void resistor_bkgd (void); +static void resistor_dimensions_1 (void); +static void resistor_crop_1 (void); +static void separate_bkgd_bands_h (void); +static void separate_bkgd_bands_s (void); +static void separate_bkgd_bands_v (void); +static void bkgd_find (void); +static int bands_find (void); +static void bands_colors (void); +static void bands_code (void); +static char band_hsv2code (struct Resistor_Bands *band); +static void bands_code_deduce_0 (void); +static void bands_code_deduce_1 (void); +static int bands_code_deduce_no (void); +static void resistor_value (void); +static int resistor_tolerance (void); +static int chk_std_value (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +int proc_resistor (void) +{ + int status; + + proc_save_mem(0); + /* Find resistor (position and angle) */ + { + /* Measure time */ + clock_start(); + + status = resistor_find(); + if (status) { + result_resistor(status); + return status; + } + + /* Measure time */ + clock_stop("Find resistor"); + } + /* Align resistor, find its dimensions, and crop */ + { + /* Measure time */ + clock_start(); + + resistor_align(); + resistor_dimensions_0(); + resistor_crop_0(); + + /* Measure time */ + clock_stop("Align, dimensions, & crop"); + } + /* Find backgroung color */ + { + /* Measure time */ + clock_start(); + + resistor_bkgd(); + + /* Measure time */ + clock_stop("Background color"); + } + /* Crop more */ + { + /* Measure time */ + clock_start(); + + resistor_dimensions_1(); + resistor_crop_1(); + + /* Measure time */ + clock_stop("Crop more"); + } + /* Separate background (BK) and lines (WH) */ + { + /* Measure time */ + clock_start(); + + separate_bkgd_bands_h(); + separate_bkgd_bands_s(); + separate_bkgd_bands_v(); + bkgd_find(); + + /* Measure time */ + clock_stop("Separate bkgd from bands"); + } + /* Find bands: contours -> rectangles */ + { + /* Measure time */ + clock_start(); + + status = bands_find(); + if (status) { + result_resistor(status); + return status; + } + + /* Measure time */ + clock_stop("Find bands"); + } + /* Read values on the center of each band */ + { + /* Measure time */ + clock_start(); + + bands_colors(); + + /* Measure time */ + clock_stop("Bands' colors"); + } + /* Interpret colors */ + { + /* Measure time */ + clock_start(); + + bands_code(); + bands_code_deduce_0(); + bands_code_deduce_1(); + status = bands_code_deduce_no(); + if (status) { + result_resistor(status); + return status; + } + + /* Measure time */ + clock_stop("Interpret colors"); + } + /* Calculate resistor value & tolerance */ + { + /* Measure time */ + clock_start(); + + resistor_value(); + status = resistor_tolerance(); + if (status) { + result_resistor(status); + return status; + } + + /* Write resistor value into log */ + if (bands_n != 1) { + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Resistance: %.2E ± %i%% Ohm", + resistance, tolerance); + } else { + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Resistance: 0 Ohm"); + } + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Measure time */ + clock_stop("Calculate resistance & tolerance"); + } + /* Check STD value */ + { + /* Measure time */ + clock_start(); + + status = chk_std_value(); + if (status) { + result_resistor(status); + return status; + } + + /* Measure time */ + clock_stop("Chk STD values"); + } + + status = RESISTOR_OK; + result_resistor(status); + return status; +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_resistor (int status) +{ + /* Write result into log */ + switch (status) { + case RESISTOR_OK: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Resistor: OK"); + break; + case RESISTOR_NOK_RESISTOR: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Resistor: NOK_RESISTOR"); + break; + case RESISTOR_NOK_BANDS: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Resistor: NOK_BANDS"); + break; + case RESISTOR_NOK_COLOR: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Resistor: NOK_COLOR"); + break; + case RESISTOR_NOK_STD_VALUE: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Resistor: NOK_STD_VALUE"); + break; + case RESISTOR_NOK_TOLERANCE: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Resistor: NOK_TOLERANCE"); + break; + default: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Resistor: NOK"); + break; + } + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + +static int resistor_find (void) +{ + int status; + + proc_load_mem(0); + + /* BGR -> HSV */ + proc_cvt_color(cv::COLOR_BGR2HSV); + proc_save_mem(19); + + proc_cmp(IMG_IFACE_CMP_SATURATION); + proc_smooth(IMGI_SMOOTH_MEDIAN, 7); + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_save_mem(1); + proc_dilate_erode(10); + proc_contours(&contours, &hierarchy); + + /* If no contour is found, error: NOK_RESISTOR */ + if (!contours.size()) { + status = RESISTOR_NOK_RESISTOR; + return status; + } + + proc_min_area_rect(&(contours[0]), &rect_rot, true); + + /* If angle is < -45º, it is taking into acount the incorrect side */ + if (rect_rot.angle < -45.0) { + rect_rot.angle += 90.0; + } + + status = RESISTOR_OK; + return status; +} + +static void resistor_align (void) +{ + proc_load_mem(19); + proc_rotate(rect_rot.center.x, rect_rot.center.y, rect_rot.angle); + proc_save_mem(2); + proc_load_mem(1); + proc_rotate(rect_rot.center.x, rect_rot.center.y, rect_rot.angle); + proc_save_mem(3); +} + +static void resistor_dimensions_0 (void) +{ + proc_load_mem(3); + + proc_dilate_erode(10); + proc_contours(&contours, &hierarchy); + proc_bounding_rect(&(contours[0]), &rect, true); +} + +static void resistor_crop_0 (void) +{ + int x; + int y; + int w; + int h; + + proc_load_mem(2); + + w = rect.width; + h = rect.height; + x = rect.x; + y = rect.y; + proc_ROI(x, y, w, h); + proc_save_mem(4); +} + +static void resistor_bkgd (void) +{ + uint8_t bkgd_hue; + uint8_t bkgd_sat; + + /* hue */ + proc_load_mem(4); + proc_cmp(IMG_IFACE_CMP_HUE); + proc_median_vertical(); + proc_median_horizontal(); + proc_pixel_get(0, 0, &bkgd_hue); + + /* saturation */ + proc_load_mem(4); + proc_cmp(IMG_IFACE_CMP_SATURATION); + proc_median_vertical(); + proc_median_horizontal(); + proc_pixel_get(0, 0, &bkgd_sat); + + if (bkgd_hue < 50) { + /* Beige */ + bkgd = 0; + } else { + /* Blue */ + if ((bkgd_hue < 90) || (bkgd_sat < 100)) { + /* Teal blue */ + bkgd = 1; + } else if (bkgd_hue >= 105) { + /* Dark blue */ + bkgd = 2; + } else { + /* Normal blue */ + bkgd = 3; + } + } +} + +static void resistor_dimensions_1 (void) +{ + proc_load_mem(3); + + proc_dilate_erode(10); + proc_erode_dilate((rect.height * 0.67) / 2); + proc_contours(&contours, &hierarchy); + proc_bounding_rect(&(contours[0]), &rect, true); +} + +static void resistor_crop_1 (void) +{ + int x; + int y; + int w; + int h; + + proc_load_mem(2); + + w = rect.width * 0.95; + h = rect.height * 0.8; + x = rect.x + w * (1.0 - 0.95) / 2.0; + y = rect.y + h * (1.0 - 0.8) / 2.0; + proc_ROI(x, y, w, h); + proc_save_mem(4); +} + +static void separate_bkgd_bands_h (void) +{ + proc_load_mem(4); + + proc_cmp(IMG_IFACE_CMP_HUE); + proc_median_vertical(); + proc_save_mem(9); + + switch (bkgd) { + case 0: + proc_threshold(cv::THRESH_TOZERO_INV, 20); + proc_threshold(cv::THRESH_TOZERO, 5); + break; + case 1: + proc_threshold(cv::THRESH_TOZERO_INV, 100); + proc_threshold(cv::THRESH_TOZERO, 70); + break; + case 2: + proc_threshold(cv::THRESH_TOZERO_INV, 115); + proc_threshold(cv::THRESH_TOZERO, 100); + break; + case 3: + proc_threshold(cv::THRESH_TOZERO_INV, 110); + proc_threshold(cv::THRESH_TOZERO, 90); + break; + } + proc_threshold(cv::THRESH_BINARY_INV, 1); + proc_save_mem(5); +} + +static void separate_bkgd_bands_s (void) +{ + proc_load_mem(4); + + proc_cmp(IMG_IFACE_CMP_SATURATION); + proc_median_vertical(); + proc_save_mem(10); + + switch (bkgd) { + + case 0: + proc_threshold(cv::THRESH_TOZERO_INV, 160); + proc_threshold(cv::THRESH_TOZERO, 110); + break; + case 1: + proc_threshold(cv::THRESH_TOZERO_INV, 180); + proc_threshold(cv::THRESH_TOZERO, 30); + break; + case 2: + proc_threshold(cv::THRESH_TOZERO_INV, 190); + proc_threshold(cv::THRESH_TOZERO, 170); + break; + case 3: + proc_threshold(cv::THRESH_TOZERO_INV, 210); + proc_threshold(cv::THRESH_TOZERO, 120); + break; + } + proc_threshold(cv::THRESH_BINARY_INV, 1); + proc_save_mem(6); +} + +static void separate_bkgd_bands_v (void) +{ + proc_load_mem(4); + + proc_cmp(IMG_IFACE_CMP_VALUE); + proc_median_vertical(); + proc_save_mem(11); + + switch (bkgd) { + case 0: + proc_threshold(cv::THRESH_TOZERO_INV, 170); + proc_threshold(cv::THRESH_TOZERO, 100); + break; + + case 1: + proc_threshold(cv::THRESH_TOZERO_INV, 180); + proc_threshold(cv::THRESH_TOZERO, 100); + break; + case 2: + proc_threshold(cv::THRESH_TOZERO_INV, 180); + proc_threshold(cv::THRESH_TOZERO, 150); + break; + case 3: + proc_threshold(cv::THRESH_TOZERO_INV, 190); + proc_threshold(cv::THRESH_TOZERO, 90); + break; + } + proc_threshold(cv::THRESH_BINARY_INV, 1); + proc_save_mem(7); +} + +static void bkgd_find (void) +{ + /* Merge the components: H | S | V */ + proc_load_mem(7); + proc_save_ref(); + proc_load_mem(6); + proc_or_2ref(); + proc_save_ref(); + proc_load_mem(5); + proc_or_2ref(); + if (rect.width * 0.95 > 80) { + proc_dilate_erode(1); + } + proc_save_mem(8); +} + +static int bands_find (void) +{ + int status; + + proc_load_mem(8); + + /* Contours */ + proc_contours(&contours, &hierarchy); + if (contours.size() > 5) { + proc_load_mem(8); + proc_dilate_erode(1); + proc_contours(&contours, &hierarchy); + } + + bands_n = contours.size(); + if ((bands_n == 0) || (bands_n == 2) || (bands_n > 5)) { + status = RESISTOR_NOK_BANDS; + return status; + } + + /* Band 0 (hundreds) */ + if (bands_n == 5) { + proc_bounding_rect(&(contours[4]), &rect, true); + bands[0].x = rect.x + rect.width / 2.0; + bands[0].y = rect.y + rect.height / 2.0; + } + + /* Band 1 (tens) */ + if (bands_n >= 3) { + if (bands_n > 3) { + proc_bounding_rect(&(contours[3]), &rect, true); + } else { + proc_bounding_rect(&(contours[2]), &rect, true); + } + bands[1].x = rect.x + rect.width / 2.0; + bands[1].y = rect.y + rect.height / 2.0; + } + + /* Band 2 (units) */ + if (bands_n > 3) { + proc_bounding_rect(&(contours[2]), &rect, true); + } else if (bands_n == 3) { + proc_bounding_rect(&(contours[1]), &rect, true); + } else { /* bands_n == 1 */ + proc_bounding_rect(&(contours[0]), &rect, true); + } + bands[2].x = rect.x + rect.width / 2.0; + bands[2].y = rect.y + rect.height / 2.0; + + /* Band 3 (multiplier) */ + if (bands_n >= 3) { + if (bands_n > 3) { + proc_bounding_rect(&(contours[1]), &rect, true); + } else { + proc_bounding_rect(&(contours[0]), &rect, true); + } + bands[3].x = rect.x + rect.width / 2.0; + bands[3].y = rect.y + rect.height / 2.0; + } + + /* Band 4 (tolerance) */ + if (bands_n > 3) { + proc_bounding_rect(&(contours[0]), &rect, true); + bands[4].x = rect.x + rect.width / 2.0; + bands[4].y = rect.y + rect.height / 2.0; + } + + status = RESISTOR_OK; + return status; +} + +static void bands_colors (void) +{ + /* Hue */ + proc_load_mem(9); + if (bands_n == 5) { + proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].h)); + } + if (bands_n >= 3) { + proc_pixel_get(bands[1].x, bands[1].y, &(bands[1].h)); + } + proc_pixel_get(bands[2].x, bands[2].y, &(bands[2].h)); + if (bands_n >= 3) { + proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].h)); + } + if (bands_n > 3) { + proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].h)); + } + + /* Saturation */ + proc_load_mem(10); + if (bands_n == 5) { + proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].s)); + } + if (bands_n >= 3) { + proc_pixel_get(bands[1].x, bands[1].y, &(bands[1].s)); + } + proc_pixel_get(bands[2].x, bands[2].y, &(bands[2].s)); + if (bands_n >= 3) { + proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].s)); + } + if (bands_n > 3) { + proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].s)); + } + + /* Value */ + proc_load_mem(11); + if (bands_n == 5) { + proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].v)); + } + if (bands_n >= 3) { + proc_pixel_get(bands[1].x, bands[1].y, &(bands[1].v)); + } + proc_pixel_get(bands[2].x, bands[2].y, &(bands[2].v)); + if (bands_n >= 3) { + proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].v)); + } + if (bands_n > 3) { + proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].v)); + } +} + +static void bands_code (void) +{ + int i; + + /* Init to 0 */ + for (i = 0; i < 6; i++) { + code[i] = '\0'; + } + + /* Band 0 (hundreds) */ + if (bands_n == 5) { + code[0] = band_hsv2code(&bands[0]); + } else { + code[0] = 'n'; + } + + + /* Band 1 (tens) */ + if (bands_n != 1) { + code[1] = band_hsv2code(&bands[1]); + } else { + code[1] = 'n'; + } + + /* Band 2 (units) */ + code[2] = band_hsv2code(&bands[2]); + + /* Band 3 (multiplier) */ + if (bands_n != 1) { + code[3] = band_hsv2code(&bands[3]); + } else { + code[3] = 'n'; + } + + /* Band 4 (tolerance) */ + if (bands_n > 3) { + code[4] = band_hsv2code(&bands[4]); + } else { + code[4] = 'n'; + } + + /* 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)++; +} + +static char band_hsv2code (struct Resistor_Bands *band) +{ + char ch; + + /* + * Not able to segmentate: + * q = 1 2 + * w = 2 3 + * e = 3 g + * r = 3 4 + * t = 1 8 + * y = 0 1 + * u = 0 1 8 + */ + + if (band->h < 10) { + // 1 2 3 + if (band->s < 90) { + // 1 3 + if (band->v < 85) { + ch = '1'; + } else { + ch = '3'; + } + } else if (band->s < 140) { + // 1 2 3 + if (band->v < 60) { + ch = '1'; + } else if (band->v < 85) { + // 1 2 + ch = 'q'; + } else if (band->v < 90) { + ch = '2'; + } else if (band->v < 150) { + // 2 3 + ch = 'w'; + } else { + ch = '3'; + } + } else if (band->s < 210) { + // 2 3 + if (band->v < 90) { + ch = '2'; + } else if (band->v < 150) { + // 2 3 + ch = 'w'; + } else { + ch = '3'; + } + } else { + ch = '3'; + } + } else if (band->h < 35) { + // 1 3 g + if (band->s < 130) { + // 1 3 + if (band->v < 85) { + ch = '1'; + } else { + ch = '3'; + } + } else if (band->s < 140) { + // 1 3 g + if (band->v < 85) { + ch = '1'; + } else if (band->v < 120) { + ch = '3'; + } else { + // 3 g + ch = 'e'; + } + } else if (band->s < 180) { + // 3 g + if (band->v < 120) { + ch = '3'; + } else { + // 3 g + ch = 'e'; + } + } else { + ch = '3'; + } + } else if (band->h < 50) { + // 1 3 + if (band->s < 140) { + // 1 3 + if (band->v < 85) { + ch = '1'; + } else { + ch = '3'; + } + } else { + ch = '3'; + } + } else if (band->h < 60) { + // 1 3 4 + if (band->s < 140) { + // 1 3 + if (band->v < 85) { + ch = '1'; + } else { + ch = '3'; + } + } else if (band->s < 160) { + ch = '3'; + } else if (band->s < 180) { + // 3 4 + if (band->v < 110) { + // 3 4 + ch = 'r'; + } else { + ch = '3'; + } + } else { + ch = '3'; + } + } else if (band->h < 80) { + // 1 5 + if (band->s < 165) { + ch = '1'; + } else { + ch = '5'; + } + } else if (band->h < 90) { + ch = '1'; + } else if (band->h < 100) { + // 0 1 8 9 + if (band->s < 40) { + // 1 8 9 + if (band->v < 55) { + ch = '1'; + } else if (band->v < 80) { + // 1 8 + ch = 't'; + } else if (band->v < 125) { + ch = '1'; + } else { + ch = '9'; + } + } else if (band->s < 70) { + // 0 1 8 9 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 55) { + // 0 1 + ch = 'y'; + } else if (band->v < 75) { + // 0 1 8 + ch = 'u'; + } else if (band->v < 80) { + // 1 8 + ch = 't'; + } else if (band->v < 125) { + ch = '1'; + } else { + ch = '9'; + } + } else if (band->s < 100) { + // 0 1 8 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 55) { + // 0 1 + ch = 'y'; + } else if (band->v < 75) { + // 0 1 8 + ch = 'u'; + } else if (band->v < 80) { + // 1 8 + ch = 't'; + } else { + ch = '1'; + } + } else if (band->s < 140) { + // 0 1 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 75) { + // 0 1 + ch = 'y'; + } else { + ch = '1'; + } + } else { + ch = '0'; + } + } else if (band->h < 110) { + // 0 1 6 8 + if (band->s < 40) { + // 1 8 + if (band->v < 55) { + ch = '1'; + } else if (band->v < 80) { + // 1 8 + ch = 't'; + } else { + ch = '1'; + } + } else if (band->s < 100) { + // 0 1 8 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 55) { + // 0 1 + ch = 'y'; + } else if (band->v < 75) { + // 0 1 8 + ch = 'u'; + } else if (band->v < 80) { + // 1 8 + ch = 't'; + } else { + ch = '1'; + } + } else if (band->s < 140) { + // 0 1 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 75) { + // 0 1 + ch = 'y'; + } else { + ch = '1'; + } + } else if (band->s < 200) { + ch = '0'; + } else { + ch = '6'; + } + } else if (band->h < 120) { + // 0 1 6 7 + if (band->s < 40) { + ch = '1'; + } else if (band->s < 90) { + // 0 1 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 75) { + // 0 1 + ch = 'y'; + } else { + ch = '1'; + } + } else if (band->s < 110) { + // 0 1 7 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 75) { + // 0 1 + ch = 'y'; + } else if (band->v < 120) { + ch = '1'; + } else { + ch = '7'; + } + } else if (band->s < 140) { + // 0 1 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 75) { + // 0 1 + ch = 'y'; + } else { + ch = '1'; + } + } else if (band->s < 200) { + ch = '0'; + } else { + ch = '6'; + } + } else if (band->h < 130) { + // 0 1 7 + if (band->s < 40) { + ch = '1'; + } else if (band->s < 90) { + // 0 1 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 75) { + // 0 1 + ch = 'y'; + } else { + ch = '1'; + } + } else if (band->s < 110) { + // 0 1 7 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 75) { + // 0 1 + ch = 'y'; + } else if (band->v < 120) { + ch = '1'; + } else { + ch = '7'; + } + } else if (band->s < 140) { + // 0 1 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 75) { + // 0 1 + ch = 'y'; + } else { + ch = '1'; + } + } else { + ch = '0'; + } + } else if (band->h < 140) { + // 0 1 + if (band->s < 40) { + ch = '1'; + } else if (band->s < 140) { + // 0 1 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 75) { + // 0 1 + ch = 'y'; + } else { + ch = '1'; + } + } else { + ch = '0'; + } + } else if (band->h < 150) { + ch = '0'; + } else { + ch = '2'; + } + + return ch; +} + +static void bands_code_deduce_0 (void) +{ + /* + * Not able to segmentate: + * q = 1 2 + * w = 2 3 + * e = 3 g + * r = 3 4 + * t = 1 8 + * y = 0 1 + * u = 0 1 8 + */ + + /* Band 0 (hundreds) */ + switch (code[0]) { + case 'e': + code[0] = '3'; + break; + case 'y': + code[0] = '1'; + break; + case 'u': + code[0] = 't'; + break; + } + + /* Band 2 (units) */ + switch (code[2]) { + case 'e': + code[2] = '3'; + break; + } + + /* Band 3 (multiplier) */ + switch (code[3]) { + case 't': + code[3] = '1'; + break; + case 'u': + code[3] = 'y'; + break; + } + + /* Band 4 (tolerance) */ + switch (code[4]) { + case 'w': + code[4] = '2'; + break; + case 'e': + code[4] = 'g'; + break; + case 't': + code[4] = '1'; + break; + case 'y': + code[4] = '1'; + break; + case 'u': + code[4] = '1'; + break; + } + + /* 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)++; +} + +static void bands_code_deduce_1 (void) +{ + /* + * Not able to segmentate: + + * q = 1 2 + * w = 2 3 + * e = 3 g + * r = 3 4 + * t = 1 8 + * y = 0 1 + + * u = 0 1 8 + */ + + /* Band 0 (hundreds) */ + switch (code[0]) { + case 'q': + switch (code[1]) { + case '1': + case '3': + case '5': + case '6': + case '8': + code[0] = '1'; + break; + case '2': + case '4': + case '7': + code[0] = '2'; + break; + case '0': + // q + break; + } + break; + case 'w': + switch (code[1]) { + case '2': + case '4': + case '7': + code[0] = '2'; + break; + case '3': + case '6': + case '9': + code[0] = '3'; + break; + case '0': + // w + break; + } + break; + case 'r': + switch (code[1]) { + case '0': + case '6': + case '9': + code[0] = '3'; + break; + case '7': + code[0] = '4'; + break; + case '3': + // r + break; + } + break; + case 't': + switch (code[1]) { + case '0': + case '1': + case '3': + case '5': + case '6': + case '8': + code[0] = '1'; + break; + case '2': + // t + break; + } + break; + } + + /* Band 1 (tens) */ + switch (code[1]) { + case 'q': + switch (code[0]) { + case '5': + case '9': + code[1] = '1'; + break; + case '2': + case '6': + case '8': + code[1] = '2'; + break; + case '1': + // q + break; + } + break; + case 'w': + switch (code[0]) { + case '2': + case '6': + case '8': + code[1] = '2'; + break; + case '3': + case '4': + code[1] = '3'; + break; + case '1': + // w + break; + } + break; + case 't': + switch (code[0]) { + case '5': + case '9': + code[1] = '1'; + break; + case '6': + code[1] = '8'; + break; + case '1': + // t + break; + } + break; + case 'y': + switch (code[0]) { + case '2': + case '3': + code[1] = '0'; + break; + case '5': + case '9': + code[1] = '1'; + break; + case '1': + // y + break; + } + break; + case 'u': + switch (code[0]) { + case '2': + case '3': + code[1] = '0'; + break; + case '5': + case '9': + code[1] = '1'; + break; + case '6': + code[1] = '8'; + break; + case '1': + // u + break; + } + break; + } + + /* Band 2 (units) */ + switch (code[2]) { + case 'y': + code[2] = '0'; + break; + case 'u': + code[2] = '0'; + break; + } + + /* Band 3 (multiplier) */ + switch (code[3]) { + case 'y': + code[3] = '0'; + break; + } + + /* Band 4 (tolerance) */ + switch (code[4]) { + case 'q': + code[4] = '2'; + break; + } + + /* 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)++; +} + +static int bands_code_deduce_no (void) +{ + int status; + int i; + + /* + * Not able to segmentate: + * q = 1 2 + * w = 2 3 + * e = 3 g + * r = 3 4 + * t = 1 8 + * y = 0 1 + * u = 0 1 8 + */ + + for (i = 0; i < 5; i++) { + switch (code[i]) { + case 'q': + case 'w': + case 'e': + case 'r': + case 't': + case 'y': + case 'u': + code[i] = '?'; + break; + } + } + + for (i = 0; i < 5; i++) { + if (code[i] == '?') { + status = RESISTOR_NOK_COLOR; + return status; + } + } + + /* 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)++; + + status = RESISTOR_OK; + return status; +} + +static void resistor_value (void) +{ + int power; + + /* Base value */ + base = code[2] - '0'; + if (code[1] != 'n') { + base += (code[1] - '0') * 10; + } + if (code[0] != 'n') { + base += (code[0] - '0') * 100; + } + + /* Calculate resistance */ + if ((code[3] > '0') && (code[3] < '9')) { + power = code[3] - '0'; + } else if (code[3] == 'g') { + power = -1; + } else if (code[3] == 's') { + power = -2; + } else { + // error + return; + } + resistance = base * pow(10, power); +} + +static int resistor_tolerance (void) +{ + int status; + + if (bands_n != 1) { + switch (code[4]) { + case '1': + tolerance = 1; + break; + case '2': + tolerance = 2; + break; + case '4': + case 'g': + case 'n': + tolerance = 5; + break; + case '8': + tolerance = 10; + break; + default: + status = RESISTOR_NOK_TOLERANCE; + return status; + } + } + + status = RESISTOR_OK; + return status; +} + +static int chk_std_value (void) +{ + int status; + /* Check that base value is a standard value */ + int std_values_10 [12] = {10,12,15,18,22,27,33,39,47,56,68,82}; + int std_values_5 [12] = {11,13,16,20,24,30,36,43,51,62,75,91}; + bool std_value_nok = true; + int i; + + if (bands_n != 1) { + for (i = 0; i < 12; i++) { + if (base == std_values_10[i]) { + std_value_nok = false; + } + if (base == (std_values_10[i] * 10)) { + std_value_nok = false; + } + } + if (tolerance <= 5) { + for (i = 0; i < 12; i++) { + if (base == std_values_5[i]) { + std_value_nok = false; + } + if (base == (std_values_5[i] * 10)) { + std_value_nok = false; + } + } + } + } else { + if (base == 0) { + std_value_nok = false; + } + } + + if (std_value_nok) { + status = RESISTOR_NOK_STD_VALUE; + return status; + } + + status = RESISTOR_OK; + return status; +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/save/inc/save.h b/modules/save/inc/save.h index dc0d850..d398a0b 100644 --- a/modules/save/inc/save.h +++ b/modules/save/inc/save.h @@ -1,74 +1,74 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_SAVE_H - # define VA_SAVE_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* FILENAME_MAX */ - #include - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define ENV_HOME "HOME" - - # define USER_PROG_DIR "vision-artificial/" - # define USER_SAVED_DIR "vision-artificial/saved/" - # define USER_LABELS_DIR "vision-artificial/labels/" - # define USER_LABELS_FAIL_DIR "vision-artificial/labels/fail" - # define USER_OBJECTS_DIR "vision-artificial/objects/" - # define USER_OBJECTS_FAIL_DIR "vision-artificial/objects/fail" - # define USER_COINS_DIR "vision-artificial/coins/" - # define USER_COINS_FAIL_DIR "vision-artificial/coins/fail" - # define USER_RESISTORS_DIR "vision-artificial/resistors/" - # define USER_RESISTORS_FAIL_DIR "vision-artificial/resistors/fail" - # define SAVED_NAME_DEFAULT "saved" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - extern char home_path [FILENAME_MAX]; - extern char user_prog_path [FILENAME_MAX]; - extern char saved_path [FILENAME_MAX]; - extern char labels_path [FILENAME_MAX]; - extern char labels_fail_path [FILENAME_MAX]; - extern char objects_path [FILENAME_MAX]; - extern char objects_fail_path [FILENAME_MAX]; - extern char coins_path [FILENAME_MAX]; - extern char coins_fail_path [FILENAME_MAX]; - extern char resistors_path [FILENAME_MAX]; - extern char resistors_fail_path [FILENAME_MAX]; - extern char saved_name [FILENAME_MAX]; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void save_init (void); - void save_cleanup (void); - void save_clr (void); - void load_image_file (const char *fpath, const char *fname); - void save_image_file (const char *fpath, const char *save_as); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* save.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_SAVE_H + # define VA_SAVE_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* FILENAME_MAX */ + #include + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define ENV_HOME "HOME" + + # define USER_PROG_DIR "vision-artificial/" + # define USER_SAVED_DIR "vision-artificial/saved/" + # define USER_LABELS_DIR "vision-artificial/labels/" + # define USER_LABELS_FAIL_DIR "vision-artificial/labels/fail" + # define USER_OBJECTS_DIR "vision-artificial/objects/" + # define USER_OBJECTS_FAIL_DIR "vision-artificial/objects/fail" + # define USER_COINS_DIR "vision-artificial/coins/" + # define USER_COINS_FAIL_DIR "vision-artificial/coins/fail" + # define USER_RESISTORS_DIR "vision-artificial/resistors/" + # define USER_RESISTORS_FAIL_DIR "vision-artificial/resistors/fail" + # define SAVED_NAME_DEFAULT "saved" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern char home_path [FILENAME_MAX]; + extern char user_prog_path [FILENAME_MAX]; + extern char saved_path [FILENAME_MAX]; + extern char labels_path [FILENAME_MAX]; + extern char labels_fail_path [FILENAME_MAX]; + extern char objects_path [FILENAME_MAX]; + extern char objects_fail_path [FILENAME_MAX]; + extern char coins_path [FILENAME_MAX]; + extern char coins_fail_path [FILENAME_MAX]; + extern char resistors_path [FILENAME_MAX]; + extern char resistors_fail_path [FILENAME_MAX]; + extern char saved_name [FILENAME_MAX]; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void save_init (void); + void save_cleanup (void); + void save_clr (void); + void load_image_file (const char *fpath, const char *fname); + void save_image_file (const char *fpath, const char *save_as); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* save.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/save/inc/save.hpp b/modules/save/inc/save.hpp index edabbf3..70025ad 100644 --- a/modules/save/inc/save.hpp +++ b/modules/save/inc/save.hpp @@ -1,91 +1,91 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_SAVE_HPP - # define VA_SAVE_HPP - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* FILENAME_MAX */ - #include - -/* Project -------------------------------------------------------------------*/ - /* opencv */ - #include - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define ENV_HOME "HOME" - - # define USER_PROG_DIR "vision-artificial/" - # define USER_SAVED_DIR "vision-artificial/saved/" - # define USER_LABELS_DIR "vision-artificial/labels/" - # define USER_LABELS_FAIL_DIR "vision-artificial/labels/fail" - # define USER_OBJECTS_DIR "vision-artificial/objects/" - # define USER_OBJECTS_FAIL_DIR "vision-artificial/objects/fail" - # define USER_COINS_DIR "vision-artificial/coins/" - # define USER_COINS_FAIL_DIR "vision-artificial/coins/fail" - # define USER_RESISTORS_DIR "vision-artificial/resistors/" - # define USER_RESISTORS_FAIL_DIR "vision-artificial/resistors/fail" - # define SAVED_NAME_DEFAULT "saved" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - extern class cv::Mat image; - extern char home_path [FILENAME_MAX]; - extern char user_prog_path [FILENAME_MAX]; - extern char saved_path [FILENAME_MAX]; - extern char labels_path [FILENAME_MAX]; - extern char labels_fail_path [FILENAME_MAX]; - extern char objects_path [FILENAME_MAX]; - extern char objects_fail_path [FILENAME_MAX]; - extern char coins_path [FILENAME_MAX]; - extern char coins_fail_path [FILENAME_MAX]; - extern char resistors_path [FILENAME_MAX]; - extern char resistors_fail_path [FILENAME_MAX]; - extern char saved_name [FILENAME_MAX]; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void save_init (void); - void save_cleanup (void); - void save_clr (void); - void load_image_file (const char *fpath, const char *fname); - void save_image_file (const char *fpath, const char *save_as); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* save.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_SAVE_HPP + # define VA_SAVE_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* FILENAME_MAX */ + #include + +/* Project -------------------------------------------------------------------*/ + /* opencv */ + #include + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define ENV_HOME "HOME" + + # define USER_PROG_DIR "vision-artificial/" + # define USER_SAVED_DIR "vision-artificial/saved/" + # define USER_LABELS_DIR "vision-artificial/labels/" + # define USER_LABELS_FAIL_DIR "vision-artificial/labels/fail" + # define USER_OBJECTS_DIR "vision-artificial/objects/" + # define USER_OBJECTS_FAIL_DIR "vision-artificial/objects/fail" + # define USER_COINS_DIR "vision-artificial/coins/" + # define USER_COINS_FAIL_DIR "vision-artificial/coins/fail" + # define USER_RESISTORS_DIR "vision-artificial/resistors/" + # define USER_RESISTORS_FAIL_DIR "vision-artificial/resistors/fail" + # define SAVED_NAME_DEFAULT "saved" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern class cv::Mat image; + extern char home_path [FILENAME_MAX]; + extern char user_prog_path [FILENAME_MAX]; + extern char saved_path [FILENAME_MAX]; + extern char labels_path [FILENAME_MAX]; + extern char labels_fail_path [FILENAME_MAX]; + extern char objects_path [FILENAME_MAX]; + extern char objects_fail_path [FILENAME_MAX]; + extern char coins_path [FILENAME_MAX]; + extern char coins_fail_path [FILENAME_MAX]; + extern char resistors_path [FILENAME_MAX]; + extern char resistors_fail_path [FILENAME_MAX]; + extern char saved_name [FILENAME_MAX]; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void save_init (void); + void save_cleanup (void); + void save_clr (void); + void load_image_file (const char *fpath, const char *fname); + void save_image_file (const char *fpath, const char *save_as); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* save.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/save/src/save.cpp b/modules/save/src/save.cpp index 861a06e..0255a43 100644 --- a/modules/save/src/save.cpp +++ b/modules/save/src/save.cpp @@ -1,194 +1,194 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* errno */ - #include - /* fscanf() & fprintf() & FILE & FILENAME_MAX & snprintf() */ - #include - /* getenv() */ - #include - -/* Linux ---------------------------------------------------------------------*/ - /* mkdir */ - #include - -/* Packages ------------------------------------------------------------------*/ - /* opencv */ - #include - -/* Project -------------------------------------------------------------------*/ - /* user_iface_save_name() */ - #include "user_iface.hpp" - -/* Module --------------------------------------------------------------------*/ - #include "save.hpp" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -class cv::Mat image; -char home_path [FILENAME_MAX]; -char user_prog_path [FILENAME_MAX]; -char saved_path [FILENAME_MAX]; -char labels_path [FILENAME_MAX]; -char labels_fail_path [FILENAME_MAX]; -char objects_path [FILENAME_MAX]; -char objects_fail_path [FILENAME_MAX]; -char coins_path [FILENAME_MAX]; -char coins_fail_path [FILENAME_MAX]; -char resistors_path [FILENAME_MAX]; -char resistors_fail_path [FILENAME_MAX]; -char saved_name [FILENAME_MAX]; - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void save_init (void) -{ - snprintf(home_path, FILENAME_MAX, "%s/", getenv(ENV_HOME)); - snprintf(user_prog_path, FILENAME_MAX, "%s/%s/", home_path, USER_PROG_DIR); - snprintf(saved_path, FILENAME_MAX, "%s/%s/", home_path, USER_SAVED_DIR); - snprintf(labels_path, FILENAME_MAX, "%s/%s/", home_path, USER_LABELS_DIR); - snprintf(labels_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_LABELS_FAIL_DIR); - snprintf(objects_path, FILENAME_MAX, "%s/%s/", home_path, USER_OBJECTS_DIR); - snprintf(objects_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_OBJECTS_FAIL_DIR); - snprintf(coins_path, FILENAME_MAX, "%s/%s/", home_path, USER_COINS_DIR); - snprintf(coins_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_COINS_FAIL_DIR); - snprintf(resistors_path, FILENAME_MAX, "%s/%s/", home_path, USER_RESISTORS_DIR); - snprintf(resistors_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_RESISTORS_FAIL_DIR); - sprintf(saved_name, ""); - - int err; - err = mkdir(user_prog_path, 0700); - - if (!err) { - } else { - - switch (errno) { - case EACCES: - printf("err = EACCES"); -// exit(EXIT_FAILURE); - break; - - case EEXIST: - /* OK */ - break; - - default: - printf("WTF?!"); -// exit(EXIT_FAILURE); - } - } - - mkdir(saved_path, 0700); - mkdir(labels_path, 0700); - mkdir(labels_fail_path, 0700); -} - -void save_clr (void) -{ - snprintf(saved_path, FILENAME_MAX, "%s/%s/", home_path, USER_SAVED_DIR); -} - -void load_image_file (const char *fpath, const char *fname) -{ - char file_path [FILENAME_MAX]; - char file_name [FILENAME_MAX]; - - /* Free old image */ - image.release(); - - /* Set file_path */ - if (!fpath) { - /* Default path */ - save_clr(); - snprintf(file_path, FILENAME_MAX, "%s", saved_path); - } else { - snprintf(file_path, FILENAME_MAX, "%s", fpath); - } - - /* Set file_name */ - if (!fname) { - /* Request file name */ - user_iface_fname(file_path, saved_name); - } else { - snprintf(saved_name, FILENAME_MAX, "%s", fname); - } - - /* File name */ - snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name); - - /* Load image */ - image = cv::imread(file_name, CV_LOAD_IMAGE_COLOR); - - /* Manage load error */ - if (image.empty()) { - printf("Could not load file: %s\n", file_name); -// exit(0); - } -} - -void save_cleanup (void) -{ - /* Free old image */ - image.release(); -} - -void save_image_file (const char *fpath, const char *save_as) -{ - char file_path [FILENAME_MAX]; - char file_name [FILENAME_MAX]; - FILE *fp; - - /* Set file_path */ - if (!fpath) { - /* Default path */ - save_clr(); - snprintf(file_path, FILENAME_MAX, "%s", saved_path); - } else { - snprintf(file_path, FILENAME_MAX, "%s", fpath); - } - - /* Set file_name */ - if (!save_as) { - /* Default name */ - snprintf(saved_name, FILENAME_MAX, "%s", SAVED_NAME_DEFAULT); - /* Request file name */ - user_iface_fname(saved_path, saved_name); - } else { - snprintf(saved_name, FILENAME_MAX, "%s", save_as); - } - - /* Prepend the path */ - snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name); - - fp = fopen(file_name, "r"); - if (fp) { - /* Name in use; ask once more */ - fclose(fp); - user_iface_fname(saved_path, saved_name); - snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name); - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "%s", saved_name); - user_iface_log.lvl[user_iface_log.len] = 2; - (user_iface_log.len)++; - - - /* Write to a new file */ - cv::imwrite(file_name, image); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* errno */ + #include + /* fscanf() & fprintf() & FILE & FILENAME_MAX & snprintf() */ + #include + /* getenv() */ + #include + +/* Linux ---------------------------------------------------------------------*/ + /* mkdir */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* opencv */ + #include + +/* Project -------------------------------------------------------------------*/ + /* user_iface_save_name() */ + #include "user_iface.hpp" + +/* Module --------------------------------------------------------------------*/ + #include "save.hpp" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +class cv::Mat image; +char home_path [FILENAME_MAX]; +char user_prog_path [FILENAME_MAX]; +char saved_path [FILENAME_MAX]; +char labels_path [FILENAME_MAX]; +char labels_fail_path [FILENAME_MAX]; +char objects_path [FILENAME_MAX]; +char objects_fail_path [FILENAME_MAX]; +char coins_path [FILENAME_MAX]; +char coins_fail_path [FILENAME_MAX]; +char resistors_path [FILENAME_MAX]; +char resistors_fail_path [FILENAME_MAX]; +char saved_name [FILENAME_MAX]; + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void save_init (void) +{ + snprintf(home_path, FILENAME_MAX, "%s/", getenv(ENV_HOME)); + snprintf(user_prog_path, FILENAME_MAX, "%s/%s/", home_path, USER_PROG_DIR); + snprintf(saved_path, FILENAME_MAX, "%s/%s/", home_path, USER_SAVED_DIR); + snprintf(labels_path, FILENAME_MAX, "%s/%s/", home_path, USER_LABELS_DIR); + snprintf(labels_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_LABELS_FAIL_DIR); + snprintf(objects_path, FILENAME_MAX, "%s/%s/", home_path, USER_OBJECTS_DIR); + snprintf(objects_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_OBJECTS_FAIL_DIR); + snprintf(coins_path, FILENAME_MAX, "%s/%s/", home_path, USER_COINS_DIR); + snprintf(coins_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_COINS_FAIL_DIR); + snprintf(resistors_path, FILENAME_MAX, "%s/%s/", home_path, USER_RESISTORS_DIR); + snprintf(resistors_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_RESISTORS_FAIL_DIR); + sprintf(saved_name, ""); + + int err; + err = mkdir(user_prog_path, 0700); + + if (!err) { + } else { + + switch (errno) { + case EACCES: + printf("err = EACCES"); +// exit(EXIT_FAILURE); + break; + + case EEXIST: + /* OK */ + break; + + default: + printf("WTF?!"); +// exit(EXIT_FAILURE); + } + } + + mkdir(saved_path, 0700); + mkdir(labels_path, 0700); + mkdir(labels_fail_path, 0700); +} + +void save_clr (void) +{ + snprintf(saved_path, FILENAME_MAX, "%s/%s/", home_path, USER_SAVED_DIR); +} + +void load_image_file (const char *fpath, const char *fname) +{ + char file_path [FILENAME_MAX]; + char file_name [FILENAME_MAX]; + + /* Free old image */ + image.release(); + + /* Set file_path */ + if (!fpath) { + /* Default path */ + save_clr(); + snprintf(file_path, FILENAME_MAX, "%s", saved_path); + } else { + snprintf(file_path, FILENAME_MAX, "%s", fpath); + } + + /* Set file_name */ + if (!fname) { + /* Request file name */ + user_iface_fname(file_path, saved_name); + } else { + snprintf(saved_name, FILENAME_MAX, "%s", fname); + } + + /* File name */ + snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name); + + /* Load image */ + image = cv::imread(file_name, CV_LOAD_IMAGE_COLOR); + + /* Manage load error */ + if (image.empty()) { + printf("Could not load file: %s\n", file_name); +// exit(0); + } +} + +void save_cleanup (void) +{ + /* Free old image */ + image.release(); +} + +void save_image_file (const char *fpath, const char *save_as) +{ + char file_path [FILENAME_MAX]; + char file_name [FILENAME_MAX]; + FILE *fp; + + /* Set file_path */ + if (!fpath) { + /* Default path */ + save_clr(); + snprintf(file_path, FILENAME_MAX, "%s", saved_path); + } else { + snprintf(file_path, FILENAME_MAX, "%s", fpath); + } + + /* Set file_name */ + if (!save_as) { + /* Default name */ + snprintf(saved_name, FILENAME_MAX, "%s", SAVED_NAME_DEFAULT); + /* Request file name */ + user_iface_fname(saved_path, saved_name); + } else { + snprintf(saved_name, FILENAME_MAX, "%s", save_as); + } + + /* Prepend the path */ + snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name); + + fp = fopen(file_name, "r"); + if (fp) { + /* Name in use; ask once more */ + fclose(fp); + user_iface_fname(saved_path, saved_name); + snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name); + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "%s", saved_name); + user_iface_log.lvl[user_iface_log.len] = 2; + (user_iface_log.len)++; + + + /* Write to a new file */ + cv::imwrite(file_name, image); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/user/inc/user_clui.h b/modules/user/inc/user_clui.h index dffc625..916fe00 100644 --- a/modules/user/inc/user_clui.h +++ b/modules/user/inc/user_clui.h @@ -1,30 +1,30 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_USER_CLUI_H - # define VA_USER_CLUI_H - - -/****************************************************************************** - ******* 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); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* user_clui.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_USER_CLUI_H + # define VA_USER_CLUI_H + + +/****************************************************************************** + ******* 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); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* user_clui.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/user/inc/user_iface.h b/modules/user/inc/user_iface.h index f4511be..f65d708 100644 --- a/modules/user/inc/user_iface.h +++ b/modules/user/inc/user_iface.h @@ -1,163 +1,163 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_USER_IFACE_H - # define VA_USER_IFACE_H - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define LOG_LEN (1048576) - # define LOG_LINE_LEN (80) - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* intX_t */ - #include - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Player_Iface_Mode { - USER_IFACE_FOO, - USER_IFACE_CLUI, - USER_IFACE_TUI - }; - - enum Player_Iface_Action { - USER_IFACE_ACT_FOO = 0x000000u, - - USER_IFACE_ACT_ALX = 0x000010u, - USER_IFACE_ACT_LOCAL_MAX, - USER_IFACE_ACT_SKELETON, - USER_IFACE_ACT_LINES_HORIZONTAL, - USER_IFACE_ACT_LINES_VERTICAL, - USER_IFACE_ACT_MEAN_HORIZONTAL, - USER_IFACE_ACT_MEAN_VERTICAL, - USER_IFACE_ACT_MEDIAN_HORIZONTAL, - USER_IFACE_ACT_MEDIAN_VERTICAL, - - USER_IFACE_ACT_CV = 0x000100u, - USER_IFACE_ACT_PIXEL_GET, - USER_IFACE_ACT_PIXEL_SET, - USER_IFACE_ACT_SET_ROI, - USER_IFACE_ACT_SET_ROI_2RECT, - USER_IFACE_ACT_AND_2REF, - USER_IFACE_ACT_NOT, - USER_IFACE_ACT_OR_2REF, - USER_IFACE_ACT_COMPONENT, - USER_IFACE_ACT_DILATE, - USER_IFACE_ACT_ERODE, - USER_IFACE_ACT_DILATE_ERODE, - USER_IFACE_ACT_ERODE_DILATE, - USER_IFACE_ACT_SMOOTH, - USER_IFACE_ACT_SOBEL, - USER_IFACE_ACT_BORDER, - USER_IFACE_ACT_MIRROR, - USER_IFACE_ACT_ROTATE_ORTO, - USER_IFACE_ACT_ROTATE, - USER_IFACE_ACT_ROTATE_2RECT, - USER_IFACE_ACT_ADAPTIVE_THRESHOLD, - USER_IFACE_ACT_CVT_COLOR, - USER_IFACE_ACT_DISTANCE_TRANSFORM, - USER_IFACE_ACT_THRESHOLD, - USER_IFACE_ACT_HISTOGRAM, - USER_IFACE_ACT_HISTOGRAM_C3, - USER_IFACE_ACT_CONTOURS, - USER_IFACE_ACT_CONTOURS_SIZE, - USER_IFACE_ACT_BOUNDING_RECT, - USER_IFACE_ACT_FIT_ELLIPSE, - USER_IFACE_ACT_MIN_AREA_RECT, - USER_IFACE_ACT_HOUGH_CIRCLES, - - USER_IFACE_ACT_ORB = 0x000200u, - USER_IFACE_ACT_ALIGN, - - USER_IFACE_ACT_CALIB3D = 0x000400u, - USER_IFACE_ACT_CALIBRATE, - USER_IFACE_ACT_UNDISTORT, - - USER_IFACE_ACT_ZB = 0x000800u, - USER_IFACE_ACT_DECODE, - - USER_IFACE_ACT_OCR = 0x001000u, - USER_IFACE_ACT_READ, - - USER_IFACE_ACT_IMGI = 0x002000u, - USER_IFACE_ACT_APPLY, - USER_IFACE_ACT_DISCARD, - USER_IFACE_ACT_SAVE_MEM, - USER_IFACE_ACT_LOAD_MEM, - USER_IFACE_ACT_SAVE_REF, - - USER_IFACE_ACT_SAVE = 0x004000u, - USER_IFACE_ACT_SAVE_FILE, - USER_IFACE_ACT_SAVE_UPDT, - - USER_IFACE_ACT_PROC = 0x008000u, - USER_IFACE_ACT_PROC_LABEL_SERIES, - USER_IFACE_ACT_PROC_LABEL_CALIB, - USER_IFACE_ACT_PROC_OBJECTS_SERIES, - USER_IFACE_ACT_PROC_OBJECTS_CALIB, - USER_IFACE_ACT_PROC_COINS_SERIES, - USER_IFACE_ACT_PROC_COINS_CALIB, - USER_IFACE_ACT_PROC_RESISTOR_SERIES, - USER_IFACE_ACT_PROC_RESISTOR_CALIB, - - USER_IFACE_ACT_USRI = 0x010000u, - USER_IFACE_ACT_SHOW_OCR, - USER_IFACE_ACT_QUIT - }; - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ - struct User_Iface_Log { - int len; - char line [LOG_LEN] [LOG_LINE_LEN]; - int lvl [LOG_LEN]; - int visible; - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - extern int user_iface_mode; - extern struct User_Iface_Log user_iface_log; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void user_iface_init (void); - void user_iface_cleanup (void); - void user_iface (void); - void user_iface_show_log (const char *title, const char *subtitle); - void user_iface_fname (const char *filepath, char *filename); - double user_iface_getdbl (double m, double def, double M, - const char *title, const char *help); - int64_t user_iface_getint (double m, int64_t def, double M, - const char *title, const char *help); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* user_iface.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_USER_IFACE_H + # define VA_USER_IFACE_H + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define LOG_LEN (1048576) + # define LOG_LINE_LEN (80) + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* intX_t */ + #include + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Player_Iface_Mode { + USER_IFACE_FOO, + USER_IFACE_CLUI, + USER_IFACE_TUI + }; + + enum Player_Iface_Action { + USER_IFACE_ACT_FOO = 0x000000u, + + USER_IFACE_ACT_ALX = 0x000010u, + USER_IFACE_ACT_LOCAL_MAX, + USER_IFACE_ACT_SKELETON, + USER_IFACE_ACT_LINES_HORIZONTAL, + USER_IFACE_ACT_LINES_VERTICAL, + USER_IFACE_ACT_MEAN_HORIZONTAL, + USER_IFACE_ACT_MEAN_VERTICAL, + USER_IFACE_ACT_MEDIAN_HORIZONTAL, + USER_IFACE_ACT_MEDIAN_VERTICAL, + + USER_IFACE_ACT_CV = 0x000100u, + USER_IFACE_ACT_PIXEL_GET, + USER_IFACE_ACT_PIXEL_SET, + USER_IFACE_ACT_SET_ROI, + USER_IFACE_ACT_SET_ROI_2RECT, + USER_IFACE_ACT_AND_2REF, + USER_IFACE_ACT_NOT, + USER_IFACE_ACT_OR_2REF, + USER_IFACE_ACT_COMPONENT, + USER_IFACE_ACT_DILATE, + USER_IFACE_ACT_ERODE, + USER_IFACE_ACT_DILATE_ERODE, + USER_IFACE_ACT_ERODE_DILATE, + USER_IFACE_ACT_SMOOTH, + USER_IFACE_ACT_SOBEL, + USER_IFACE_ACT_BORDER, + USER_IFACE_ACT_MIRROR, + USER_IFACE_ACT_ROTATE_ORTO, + USER_IFACE_ACT_ROTATE, + USER_IFACE_ACT_ROTATE_2RECT, + USER_IFACE_ACT_ADAPTIVE_THRESHOLD, + USER_IFACE_ACT_CVT_COLOR, + USER_IFACE_ACT_DISTANCE_TRANSFORM, + USER_IFACE_ACT_THRESHOLD, + USER_IFACE_ACT_HISTOGRAM, + USER_IFACE_ACT_HISTOGRAM_C3, + USER_IFACE_ACT_CONTOURS, + USER_IFACE_ACT_CONTOURS_SIZE, + USER_IFACE_ACT_BOUNDING_RECT, + USER_IFACE_ACT_FIT_ELLIPSE, + USER_IFACE_ACT_MIN_AREA_RECT, + USER_IFACE_ACT_HOUGH_CIRCLES, + + USER_IFACE_ACT_ORB = 0x000200u, + USER_IFACE_ACT_ALIGN, + + USER_IFACE_ACT_CALIB3D = 0x000400u, + USER_IFACE_ACT_CALIBRATE, + USER_IFACE_ACT_UNDISTORT, + + USER_IFACE_ACT_ZB = 0x000800u, + USER_IFACE_ACT_DECODE, + + USER_IFACE_ACT_OCR = 0x001000u, + USER_IFACE_ACT_READ, + + USER_IFACE_ACT_IMGI = 0x002000u, + USER_IFACE_ACT_APPLY, + USER_IFACE_ACT_DISCARD, + USER_IFACE_ACT_SAVE_MEM, + USER_IFACE_ACT_LOAD_MEM, + USER_IFACE_ACT_SAVE_REF, + + USER_IFACE_ACT_SAVE = 0x004000u, + USER_IFACE_ACT_SAVE_FILE, + USER_IFACE_ACT_SAVE_UPDT, + + USER_IFACE_ACT_PROC = 0x008000u, + USER_IFACE_ACT_PROC_LABEL_SERIES, + USER_IFACE_ACT_PROC_LABEL_CALIB, + USER_IFACE_ACT_PROC_OBJECTS_SERIES, + USER_IFACE_ACT_PROC_OBJECTS_CALIB, + USER_IFACE_ACT_PROC_COINS_SERIES, + USER_IFACE_ACT_PROC_COINS_CALIB, + USER_IFACE_ACT_PROC_RESISTOR_SERIES, + USER_IFACE_ACT_PROC_RESISTOR_CALIB, + + USER_IFACE_ACT_USRI = 0x010000u, + USER_IFACE_ACT_SHOW_OCR, + USER_IFACE_ACT_QUIT + }; + + +/****************************************************************************** + ******* structs ************************************************************** + ******************************************************************************/ + struct User_Iface_Log { + int len; + char line [LOG_LEN] [LOG_LINE_LEN]; + int lvl [LOG_LEN]; + int visible; + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern int user_iface_mode; + extern struct User_Iface_Log user_iface_log; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void user_iface_init (void); + void user_iface_cleanup (void); + void user_iface (void); + void user_iface_show_log (const char *title, const char *subtitle); + void user_iface_fname (const char *filepath, char *filename); + double user_iface_getdbl (double m, double def, double M, + const char *title, const char *help); + int64_t user_iface_getint (double m, int64_t def, double M, + const char *title, const char *help); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* user_iface.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/user/inc/user_iface.hpp b/modules/user/inc/user_iface.hpp index c127d93..134f5dd 100644 --- a/modules/user/inc/user_iface.hpp +++ b/modules/user/inc/user_iface.hpp @@ -1,175 +1,175 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_USER_IFACE_HPP - # define VA_USER_IFACE_HPP - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define LOG_LEN (1048576) - # define LOG_LINE_LEN (80) - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* intX_t */ - #include - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Player_Iface_Mode { - USER_IFACE_FOO, - USER_IFACE_CLUI, - USER_IFACE_TUI - }; - - enum Player_Iface_Action { - USER_IFACE_ACT_FOO = 0x000000u, - - USER_IFACE_ACT_ALX = 0x000010u, - USER_IFACE_ACT_LOCAL_MAX, - USER_IFACE_ACT_SKELETON, - USER_IFACE_ACT_LINES_HORIZONTAL, - USER_IFACE_ACT_LINES_VERTICAL, - USER_IFACE_ACT_MEAN_HORIZONTAL, - USER_IFACE_ACT_MEAN_VERTICAL, - USER_IFACE_ACT_MEDIAN_HORIZONTAL, - USER_IFACE_ACT_MEDIAN_VERTICAL, - - USER_IFACE_ACT_CV = 0x000100u, - USER_IFACE_ACT_PIXEL_GET, - USER_IFACE_ACT_PIXEL_SET, - USER_IFACE_ACT_SET_ROI, - USER_IFACE_ACT_SET_ROI_2RECT, - USER_IFACE_ACT_AND_2REF, - USER_IFACE_ACT_NOT, - USER_IFACE_ACT_OR_2REF, - USER_IFACE_ACT_COMPONENT, - USER_IFACE_ACT_DILATE, - USER_IFACE_ACT_ERODE, - USER_IFACE_ACT_DILATE_ERODE, - USER_IFACE_ACT_ERODE_DILATE, - USER_IFACE_ACT_SMOOTH, - USER_IFACE_ACT_SOBEL, - USER_IFACE_ACT_BORDER, - USER_IFACE_ACT_MIRROR, - USER_IFACE_ACT_ROTATE_ORTO, - USER_IFACE_ACT_ROTATE, - USER_IFACE_ACT_ROTATE_2RECT, - USER_IFACE_ACT_ADAPTIVE_THRESHOLD, - USER_IFACE_ACT_CVT_COLOR, - USER_IFACE_ACT_DISTANCE_TRANSFORM, - USER_IFACE_ACT_THRESHOLD, - USER_IFACE_ACT_HISTOGRAM, - USER_IFACE_ACT_HISTOGRAM_C3, - USER_IFACE_ACT_CONTOURS, - USER_IFACE_ACT_CONTOURS_SIZE, - USER_IFACE_ACT_BOUNDING_RECT, - USER_IFACE_ACT_FIT_ELLIPSE, - USER_IFACE_ACT_MIN_AREA_RECT, - USER_IFACE_ACT_HOUGH_CIRCLES, - - USER_IFACE_ACT_ORB = 0x000200u, - USER_IFACE_ACT_ALIGN, - - USER_IFACE_ACT_CALIB3D = 0x000400u, - USER_IFACE_ACT_CALIBRATE, - USER_IFACE_ACT_UNDISTORT, - - USER_IFACE_ACT_ZB = 0x000800u, - USER_IFACE_ACT_DECODE, - - USER_IFACE_ACT_OCR = 0x001000u, - USER_IFACE_ACT_READ, - - USER_IFACE_ACT_IMGI = 0x002000u, - USER_IFACE_ACT_APPLY, - USER_IFACE_ACT_DISCARD, - USER_IFACE_ACT_SAVE_MEM, - USER_IFACE_ACT_LOAD_MEM, - USER_IFACE_ACT_SAVE_REF, - - USER_IFACE_ACT_SAVE = 0x004000u, - USER_IFACE_ACT_SAVE_FILE, - USER_IFACE_ACT_SAVE_UPDT, - - USER_IFACE_ACT_PROC = 0x008000u, - USER_IFACE_ACT_PROC_LABEL_SERIES, - USER_IFACE_ACT_PROC_LABEL_CALIB, - USER_IFACE_ACT_PROC_OBJECTS_SERIES, - USER_IFACE_ACT_PROC_OBJECTS_CALIB, - USER_IFACE_ACT_PROC_COINS_SERIES, - USER_IFACE_ACT_PROC_COINS_CALIB, - USER_IFACE_ACT_PROC_RESISTOR_SERIES, - USER_IFACE_ACT_PROC_RESISTOR_CALIB, - - USER_IFACE_ACT_USRI = 0x010000u, - USER_IFACE_ACT_SHOW_OCR, - USER_IFACE_ACT_QUIT - }; - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ - struct User_Iface_Log { - int len; - char line [LOG_LEN] [LOG_LINE_LEN]; - int lvl [LOG_LEN]; - int visible; - }; - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - extern int user_iface_mode; - extern struct User_Iface_Log user_iface_log; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void user_iface_init (void); - void user_iface_cleanup (void); - void user_iface (void); - void user_iface_show_log (const char *title, const char *subtitle); - void user_iface_fname (const char *filepath, char *filename); - double user_iface_getdbl (double m, double def, double M, - const char *title, const char *help); - int64_t user_iface_getint (double m, int64_t def, double M, - const char *title, const char *help); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* user_iface.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_USER_IFACE_HPP + # define VA_USER_IFACE_HPP + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define LOG_LEN (1048576) + # define LOG_LINE_LEN (80) + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* intX_t */ + #include + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Player_Iface_Mode { + USER_IFACE_FOO, + USER_IFACE_CLUI, + USER_IFACE_TUI + }; + + enum Player_Iface_Action { + USER_IFACE_ACT_FOO = 0x000000u, + + USER_IFACE_ACT_ALX = 0x000010u, + USER_IFACE_ACT_LOCAL_MAX, + USER_IFACE_ACT_SKELETON, + USER_IFACE_ACT_LINES_HORIZONTAL, + USER_IFACE_ACT_LINES_VERTICAL, + USER_IFACE_ACT_MEAN_HORIZONTAL, + USER_IFACE_ACT_MEAN_VERTICAL, + USER_IFACE_ACT_MEDIAN_HORIZONTAL, + USER_IFACE_ACT_MEDIAN_VERTICAL, + + USER_IFACE_ACT_CV = 0x000100u, + USER_IFACE_ACT_PIXEL_GET, + USER_IFACE_ACT_PIXEL_SET, + USER_IFACE_ACT_SET_ROI, + USER_IFACE_ACT_SET_ROI_2RECT, + USER_IFACE_ACT_AND_2REF, + USER_IFACE_ACT_NOT, + USER_IFACE_ACT_OR_2REF, + USER_IFACE_ACT_COMPONENT, + USER_IFACE_ACT_DILATE, + USER_IFACE_ACT_ERODE, + USER_IFACE_ACT_DILATE_ERODE, + USER_IFACE_ACT_ERODE_DILATE, + USER_IFACE_ACT_SMOOTH, + USER_IFACE_ACT_SOBEL, + USER_IFACE_ACT_BORDER, + USER_IFACE_ACT_MIRROR, + USER_IFACE_ACT_ROTATE_ORTO, + USER_IFACE_ACT_ROTATE, + USER_IFACE_ACT_ROTATE_2RECT, + USER_IFACE_ACT_ADAPTIVE_THRESHOLD, + USER_IFACE_ACT_CVT_COLOR, + USER_IFACE_ACT_DISTANCE_TRANSFORM, + USER_IFACE_ACT_THRESHOLD, + USER_IFACE_ACT_HISTOGRAM, + USER_IFACE_ACT_HISTOGRAM_C3, + USER_IFACE_ACT_CONTOURS, + USER_IFACE_ACT_CONTOURS_SIZE, + USER_IFACE_ACT_BOUNDING_RECT, + USER_IFACE_ACT_FIT_ELLIPSE, + USER_IFACE_ACT_MIN_AREA_RECT, + USER_IFACE_ACT_HOUGH_CIRCLES, + + USER_IFACE_ACT_ORB = 0x000200u, + USER_IFACE_ACT_ALIGN, + + USER_IFACE_ACT_CALIB3D = 0x000400u, + USER_IFACE_ACT_CALIBRATE, + USER_IFACE_ACT_UNDISTORT, + + USER_IFACE_ACT_ZB = 0x000800u, + USER_IFACE_ACT_DECODE, + + USER_IFACE_ACT_OCR = 0x001000u, + USER_IFACE_ACT_READ, + + USER_IFACE_ACT_IMGI = 0x002000u, + USER_IFACE_ACT_APPLY, + USER_IFACE_ACT_DISCARD, + USER_IFACE_ACT_SAVE_MEM, + USER_IFACE_ACT_LOAD_MEM, + USER_IFACE_ACT_SAVE_REF, + + USER_IFACE_ACT_SAVE = 0x004000u, + USER_IFACE_ACT_SAVE_FILE, + USER_IFACE_ACT_SAVE_UPDT, + + USER_IFACE_ACT_PROC = 0x008000u, + USER_IFACE_ACT_PROC_LABEL_SERIES, + USER_IFACE_ACT_PROC_LABEL_CALIB, + USER_IFACE_ACT_PROC_OBJECTS_SERIES, + USER_IFACE_ACT_PROC_OBJECTS_CALIB, + USER_IFACE_ACT_PROC_COINS_SERIES, + USER_IFACE_ACT_PROC_COINS_CALIB, + USER_IFACE_ACT_PROC_RESISTOR_SERIES, + USER_IFACE_ACT_PROC_RESISTOR_CALIB, + + USER_IFACE_ACT_USRI = 0x010000u, + USER_IFACE_ACT_SHOW_OCR, + USER_IFACE_ACT_QUIT + }; + + +/****************************************************************************** + ******* structs ************************************************************** + ******************************************************************************/ + struct User_Iface_Log { + int len; + char line [LOG_LEN] [LOG_LINE_LEN]; + int lvl [LOG_LEN]; + int visible; + }; + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern int user_iface_mode; + extern struct User_Iface_Log user_iface_log; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void user_iface_init (void); + void user_iface_cleanup (void); + void user_iface (void); + void user_iface_show_log (const char *title, const char *subtitle); + void user_iface_fname (const char *filepath, char *filename); + double user_iface_getdbl (double m, double def, double M, + const char *title, const char *help); + int64_t user_iface_getint (double m, int64_t def, double M, + const char *title, const char *help); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* user_iface.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/user/inc/user_tui.h b/modules/user/inc/user_tui.h index d8f9a3c..c9c027c 100644 --- a/modules/user/inc/user_tui.h +++ b/modules/user/inc/user_tui.h @@ -1,36 +1,36 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_USER_TUI_H - # define VA_USER_TUI_H - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void user_tui_init (void); -void user_tui_cleanup (void); -int user_tui (const char *title, const char *subtitle); -void user_tui_show_log (const char *title, const char *subtitle); -void user_tui_fname (const char *filepath, char *filename); -double user_tui_getdbl (double m, double def, double M, - const char *title, const char *help); -int64_t user_tui_getint (double m, int64_t def, double M, - const char *title, const char *help); -void user_tui_show_ocr (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* user_tui.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_USER_TUI_H + # define VA_USER_TUI_H + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void user_tui_init (void); +void user_tui_cleanup (void); +int user_tui (const char *title, const char *subtitle); +void user_tui_show_log (const char *title, const char *subtitle); +void user_tui_fname (const char *filepath, char *filename); +double user_tui_getdbl (double m, double def, double M, + const char *title, const char *help); +int64_t user_tui_getint (double m, int64_t def, double M, + const char *title, const char *help); +void user_tui_show_ocr (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* user_tui.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/user/src/user_clui.c b/modules/user/src/user_clui.c index 9a4405a..0799df3 100644 --- a/modules/user/src/user_clui.c +++ b/modules/user/src/user_clui.c @@ -1,622 +1,622 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* printf() & fgets() & sscanf() */ - #include - -/* Project -------------------------------------------------------------------*/ - /*img_ocr_text */ - #include "img_iface.h" - -/* libalx --------------------------------------------------------------------*/ - /* alx_sscan_fname() */ - #include "alx_input.h" - -/* Module --------------------------------------------------------------------*/ - /* user_iface_log */ - #include "user_iface.h" - - #include "user_clui.h" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define BUFF_SIZE (1024) - - -/****************************************************************************** - ******* static variables ***************************************************** - ******************************************************************************/ -static int log_pos; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ - /* Log */ -static void log_loop (void); - /* Input */ -static int usr_input (void); - /* Help */ -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; - - /* User action */ - show_help(); - user_clui_show_log(title, subtitle); - action = usr_input(); - - return action; -} - -void user_clui_fname (const char *filepath, char *filename) -{ - puts("File name:"); - puts("Valid extensions: .bmp .dib .jpeg .png .pbm .pgm .ppm .tiff"); - fgets(filename, FILENAME_MAX, stdin); - alx_sscan_fname(filepath, filename, false, filename); -} - -void user_clui_show_log (const char *title, const char *subtitle) -{ - puts("________________________________________________________________________________"); - - /* Board */ - log_loop(); - - /* Subtitle & title */ - printf("%s - %s\n", subtitle, title); - puts("--------------------------------------------------------------------------------"); - -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -/* Log -----------------------------------------------------------------------*/ -static void log_loop (void) -{ - int lvl; - - putchar('\n'); - 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[log_pos]); - } - } - putchar('\n'); -} - -/* Input ---------------------------------------------------------------------*/ -static int usr_input (void) -{ - int action; - - char buff [BUFF_SIZE]; - char ch [10]; - - int i; - for (i = 0; i < 10; i++) { - ch[i] = '\0'; - } - buff[0] = '\0'; - - /* Wait for input */ - fgets(buff, BUFF_SIZE, stdin); - - /* Interpret input */ - sscanf(buff, " %c%c%c%c%c", &ch[0], &ch[1], &ch[2], &ch[3], &ch[4]); - switch (ch[0]) { - case '+': - action = USER_IFACE_ACT_APPLY; - break; - - case '-': - action = USER_IFACE_ACT_DISCARD; - break; - - case 'e': - /* Exercises from class */ - switch (ch[1]) { - case '1': - /* Label */ - switch (ch[2]) { - case '1': - action = USER_IFACE_ACT_PROC_LABEL_SERIES; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '2': - /* Objects */ - switch (ch[2]) { - case '0': - action = USER_IFACE_ACT_PROC_OBJECTS_CALIB; - break; - case '1': - action = USER_IFACE_ACT_PROC_OBJECTS_SERIES; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '3': - /* Coins */ - switch (ch[2]) { - case '1': - action = USER_IFACE_ACT_PROC_COINS_SERIES; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '4': - /* Resistor */ - switch (ch[2]) { - case '1': - action = USER_IFACE_ACT_PROC_RESISTOR_SERIES; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - - case 'f': - /* Use simple funtions */ - switch (ch[1]) { - case '0': - /* img_alx */ - switch (ch[2]) { - case '0': - /* Distance transform postprocessing */ - switch (ch[3]) { - case '0': - action = USER_IFACE_ACT_LOCAL_MAX; - break; - case '1': - action = USER_IFACE_ACT_SKELETON; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '1': - /* Lines */ - switch (ch[3]) { - case '0': - action = USER_IFACE_ACT_LINES_HORIZONTAL; - break; - case '1': - action = USER_IFACE_ACT_LINES_VERTICAL; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '2': - /* Smooth */ - switch (ch[3]) { - case '0': - action = USER_IFACE_ACT_MEAN_HORIZONTAL; - break; - case '1': - action = USER_IFACE_ACT_MEAN_VERTICAL; - break; - case '2': - action = USER_IFACE_ACT_MEDIAN_HORIZONTAL; - break; - case '3': - action = USER_IFACE_ACT_MEDIAN_VERTICAL; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '1': - /* img_cv */ - switch (ch[2]) { - case '0': - /* Core: The core functionality */ - switch (ch[3]) { - case '0': - /* Pixel */ - switch (ch[4]) { - case '0': - action = USER_IFACE_ACT_PIXEL_GET; - break; - case '1': - action = USER_IFACE_ACT_PIXEL_SET; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '1': - /* ROI */ - switch (ch[4]) { - case '0': - action = USER_IFACE_ACT_SET_ROI; - break; - case '1': - action = USER_IFACE_ACT_SET_ROI_2RECT; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '2': - /* Operations on Arrays */ - switch (ch[4]) { - case '0': - action = USER_IFACE_ACT_AND_2REF; - break; - case '1': - action = USER_IFACE_ACT_NOT; - break; - case '2': - action = USER_IFACE_ACT_OR_2REF; - break; - case '3': - action = USER_IFACE_ACT_COMPONENT; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '1': - /* Imgproc: Image processing */ - switch (ch[3]) { - case '0': - /* Image filtering */ - switch (ch[4]) { - case '0': - action = USER_IFACE_ACT_DILATE; - break; - case '1': - action = USER_IFACE_ACT_ERODE; - break; - case '2': - action = USER_IFACE_ACT_DILATE_ERODE; - break; - case '3': - action = USER_IFACE_ACT_ERODE_DILATE; - break; - case '4': - action = USER_IFACE_ACT_SMOOTH; - break; - case '5': - action = USER_IFACE_ACT_SOBEL; - break; - case '6': - action = USER_IFACE_ACT_BORDER; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '1': - /* Geometric image transformations */ - switch (ch[4]) { - case '0': - action = USER_IFACE_ACT_MIRROR; - break; - case '1': - action = USER_IFACE_ACT_ROTATE_ORTO; - break; - case '2': - action = USER_IFACE_ACT_ROTATE; - break; - case '3': - action = USER_IFACE_ACT_ROTATE_2RECT; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '2': - /* Miscellaneous image transformations */ - switch (ch[4]) { - case '0': - action = USER_IFACE_ACT_ADAPTIVE_THRESHOLD; - break; - case '1': - action = USER_IFACE_ACT_CVT_COLOR; - break; - case '2': - action = USER_IFACE_ACT_DISTANCE_TRANSFORM; - break; - case '3': - action = USER_IFACE_ACT_THRESHOLD; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '3': - /* Histograms */ - switch (ch[4]) { - case '0': - action = USER_IFACE_ACT_HISTOGRAM; - break; - case '1': - action = USER_IFACE_ACT_HISTOGRAM_C3; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '4': - /* Structural analysis and shape descriptors */ - switch (ch[4]) { - case '0': - action = USER_IFACE_ACT_CONTOURS; - break; - case '1': - action = USER_IFACE_ACT_CONTOURS_SIZE; - break; - case '2': - action = USER_IFACE_ACT_BOUNDING_RECT; - break; - case '3': - action = USER_IFACE_ACT_FIT_ELLIPSE; - break; - case '4': - action = USER_IFACE_ACT_MIN_AREA_RECT; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '5': - /* Feature detection */ - switch (ch[4]) { - case '0': - action = USER_IFACE_ACT_HOUGH_CIRCLES; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '2': - /* img_orb */ - switch (ch[2]) { - case '0': - action = USER_IFACE_ACT_ALIGN; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '3': - /* img_calib3d */ - switch (ch[2]) { - case '0': - action = USER_IFACE_ACT_CALIBRATE; - break; - case '1': - action = USER_IFACE_ACT_UNDISTORT; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '4': - /* img_zbar */ - switch (ch[2]) { - case '0': - action = USER_IFACE_ACT_DECODE; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '5': - /* img_ocr */ - switch (ch[2]) { - case '0': - action = USER_IFACE_ACT_READ; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - - case 'l': - action = USER_IFACE_ACT_LOAD_MEM; - break; - - case 'm': - action = USER_IFACE_ACT_SAVE_MEM; - break; - - case 'q': - action = USER_IFACE_ACT_QUIT; - break; - - case 'r': - action = USER_IFACE_ACT_SAVE_REF; - break; - - case 's': - action = USER_IFACE_ACT_SAVE_FILE; - break; - - case 'u': - /* User iface actions */ - switch (ch[1]) { - case '1': - action = USER_IFACE_ACT_SHOW_OCR; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - - case 'x': - /* Special sequence "xyzzy" */ - if (ch[1] == 'y') { - if (ch[2] == 'z') { - if (ch[3] == 'z') { - if (ch[4] == 'y') { - action = USER_IFACE_ACT_FOO; - } - } - } - } - break; - - default: - action = USER_IFACE_ACT_FOO; - break; - } - - return action; -} - -/* * * * * * * * * * - * * * Help * * * * * * * - * * * * * * * * * */ -static void show_help (void) -{ - // FIXME - printf("Apply: %s\n", "Space"); - printf("Discard: %s\n", "Backspace"); - printf("Save to mem: %c\n", 'm'); - printf("Load from mem: %c\n", 'l'); - printf("Save to ref: %c\n", 'r'); - printf("Save to file: %c\n", 's'); - printf("Functions:\n"); - printf(" - Local maxima: %s\n", "f000"); - printf(" - Skeleton: %s\n", "f001"); - printf(" - Horizontal lines: %s\n", "f010"); - printf(" - Vertical lines: %s\n", "f011"); - printf(" - Horizontal mean: %s\n", "f020"); - printf(" - Vertical mean: %s\n", "f021"); - printf(" - Horizontal median: %s\n", "f022"); - printf(" - Vertical median: %s\n", "f023"); - printf(" - Pixel get: %s\n", "f1000"); - printf(" - Pixel set: %s\n", "f1001"); - printf(" - Set ROI: %s\n", "f1010"); - printf(" - Set ROI 2rect: %s\n", "f1011"); - printf(" - Bitwise AND 2ref: %s\n", "f1020"); - printf(" - Bitwise NOT: %s\n", "f1021"); - printf(" - Bitwise OR 2ref: %s\n", "f1022"); - printf(" - Component: %s\n", "f1023"); - printf(" - Dilate: %s\n", "f1100"); - printf(" - Erode: %s\n", "f1101"); - printf(" - D-E: %s\n", "f1102"); - printf(" - E-D: %s\n", "f1103"); - printf(" - Smooth: %s\n", "f1104"); - printf(" - Sobel: %s\n", "f1105"); - printf(" - Border: %s\n", "f1106"); - printf(" - Mirror: %s\n", "f1110"); - printf(" - Rotate ortogonally: %s\n", "f1111"); - printf(" - Rotate: %s\n", "f1112"); - printf(" - Rotate 2rect_rot: %s\n", "f1113"); - printf(" - Adaptive threshold: %s\n", "f1120"); - printf(" - Cvt color: %s\n", "f1121"); - printf(" - Distance transform: %s\n", "f1122"); - printf(" - Threshold: %s\n", "f1123"); - printf(" - Histogram: %s\n", "f1130"); - printf(" - Histogram (3 chan): %s\n", "f1131"); - printf(" - Contours: %s\n", "f1140"); - printf(" - Contours size: %s\n", "f1141"); - printf(" - Bounding rectangle: %s\n", "f1142"); - printf(" - Fit ellipse: %s\n", "f1143"); - printf(" - Min. area rectangle: %s\n", "f1144"); - printf(" - Hough circles: %s\n", "f1150"); - printf(" - Align 2ref (ORB): %s\n", "f20"); - printf(" - Calibrate (Calib3d): %s\n", "f30"); - printf(" - Undistort (Calib3d): %s\n", "f31"); - printf(" - Scan codes (ZBAR): %s\n", "f40"); - printf(" - Scan text (OCR): %s\n", "f50"); - printf("Exercises:\n"); - printf(" - Label: %s\n", "e11"); - printf(" - Objects (calib): %s\n", "e20"); - printf(" - Objects: %s\n", "e21"); - printf(" - Coins: %s\n", "e31"); - printf(" - Resistor: %s\n", "e41"); - printf("Other:\n"); - printf(" - Show OCR text: %s\n", "u1"); - printf("Quit: %c\n", 'q'); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* printf() & fgets() & sscanf() */ + #include + +/* Project -------------------------------------------------------------------*/ + /*img_ocr_text */ + #include "img_iface.h" + +/* libalx --------------------------------------------------------------------*/ + /* alx_sscan_fname() */ + #include "alx_input.h" + +/* Module --------------------------------------------------------------------*/ + /* user_iface_log */ + #include "user_iface.h" + + #include "user_clui.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define BUFF_SIZE (1024) + + +/****************************************************************************** + ******* static variables ***************************************************** + ******************************************************************************/ +static int log_pos; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ + /* Log */ +static void log_loop (void); + /* Input */ +static int usr_input (void); + /* Help */ +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; + + /* User action */ + show_help(); + user_clui_show_log(title, subtitle); + action = usr_input(); + + return action; +} + +void user_clui_fname (const char *filepath, char *filename) +{ + puts("File name:"); + puts("Valid extensions: .bmp .dib .jpeg .png .pbm .pgm .ppm .tiff"); + fgets(filename, FILENAME_MAX, stdin); + alx_sscan_fname(filepath, filename, false, filename); +} + +void user_clui_show_log (const char *title, const char *subtitle) +{ + puts("________________________________________________________________________________"); + + /* Board */ + log_loop(); + + /* Subtitle & title */ + printf("%s - %s\n", subtitle, title); + puts("--------------------------------------------------------------------------------"); + +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +/* Log -----------------------------------------------------------------------*/ +static void log_loop (void) +{ + int lvl; + + putchar('\n'); + 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[log_pos]); + } + } + putchar('\n'); +} + +/* Input ---------------------------------------------------------------------*/ +static int usr_input (void) +{ + int action; + + char buff [BUFF_SIZE]; + char ch [10]; + + int i; + for (i = 0; i < 10; i++) { + ch[i] = '\0'; + } + buff[0] = '\0'; + + /* Wait for input */ + fgets(buff, BUFF_SIZE, stdin); + + /* Interpret input */ + sscanf(buff, " %c%c%c%c%c", &ch[0], &ch[1], &ch[2], &ch[3], &ch[4]); + switch (ch[0]) { + case '+': + action = USER_IFACE_ACT_APPLY; + break; + + case '-': + action = USER_IFACE_ACT_DISCARD; + break; + + case 'e': + /* Exercises from class */ + switch (ch[1]) { + case '1': + /* Label */ + switch (ch[2]) { + case '1': + action = USER_IFACE_ACT_PROC_LABEL_SERIES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* Objects */ + switch (ch[2]) { + case '0': + action = USER_IFACE_ACT_PROC_OBJECTS_CALIB; + break; + case '1': + action = USER_IFACE_ACT_PROC_OBJECTS_SERIES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '3': + /* Coins */ + switch (ch[2]) { + case '1': + action = USER_IFACE_ACT_PROC_COINS_SERIES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '4': + /* Resistor */ + switch (ch[2]) { + case '1': + action = USER_IFACE_ACT_PROC_RESISTOR_SERIES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + + case 'f': + /* Use simple funtions */ + switch (ch[1]) { + case '0': + /* img_alx */ + switch (ch[2]) { + case '0': + /* Distance transform postprocessing */ + switch (ch[3]) { + case '0': + action = USER_IFACE_ACT_LOCAL_MAX; + break; + case '1': + action = USER_IFACE_ACT_SKELETON; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '1': + /* Lines */ + switch (ch[3]) { + case '0': + action = USER_IFACE_ACT_LINES_HORIZONTAL; + break; + case '1': + action = USER_IFACE_ACT_LINES_VERTICAL; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* Smooth */ + switch (ch[3]) { + case '0': + action = USER_IFACE_ACT_MEAN_HORIZONTAL; + break; + case '1': + action = USER_IFACE_ACT_MEAN_VERTICAL; + break; + case '2': + action = USER_IFACE_ACT_MEDIAN_HORIZONTAL; + break; + case '3': + action = USER_IFACE_ACT_MEDIAN_VERTICAL; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '1': + /* img_cv */ + switch (ch[2]) { + case '0': + /* Core: The core functionality */ + switch (ch[3]) { + case '0': + /* Pixel */ + switch (ch[4]) { + case '0': + action = USER_IFACE_ACT_PIXEL_GET; + break; + case '1': + action = USER_IFACE_ACT_PIXEL_SET; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '1': + /* ROI */ + switch (ch[4]) { + case '0': + action = USER_IFACE_ACT_SET_ROI; + break; + case '1': + action = USER_IFACE_ACT_SET_ROI_2RECT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* Operations on Arrays */ + switch (ch[4]) { + case '0': + action = USER_IFACE_ACT_AND_2REF; + break; + case '1': + action = USER_IFACE_ACT_NOT; + break; + case '2': + action = USER_IFACE_ACT_OR_2REF; + break; + case '3': + action = USER_IFACE_ACT_COMPONENT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '1': + /* Imgproc: Image processing */ + switch (ch[3]) { + case '0': + /* Image filtering */ + switch (ch[4]) { + case '0': + action = USER_IFACE_ACT_DILATE; + break; + case '1': + action = USER_IFACE_ACT_ERODE; + break; + case '2': + action = USER_IFACE_ACT_DILATE_ERODE; + break; + case '3': + action = USER_IFACE_ACT_ERODE_DILATE; + break; + case '4': + action = USER_IFACE_ACT_SMOOTH; + break; + case '5': + action = USER_IFACE_ACT_SOBEL; + break; + case '6': + action = USER_IFACE_ACT_BORDER; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '1': + /* Geometric image transformations */ + switch (ch[4]) { + case '0': + action = USER_IFACE_ACT_MIRROR; + break; + case '1': + action = USER_IFACE_ACT_ROTATE_ORTO; + break; + case '2': + action = USER_IFACE_ACT_ROTATE; + break; + case '3': + action = USER_IFACE_ACT_ROTATE_2RECT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* Miscellaneous image transformations */ + switch (ch[4]) { + case '0': + action = USER_IFACE_ACT_ADAPTIVE_THRESHOLD; + break; + case '1': + action = USER_IFACE_ACT_CVT_COLOR; + break; + case '2': + action = USER_IFACE_ACT_DISTANCE_TRANSFORM; + break; + case '3': + action = USER_IFACE_ACT_THRESHOLD; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '3': + /* Histograms */ + switch (ch[4]) { + case '0': + action = USER_IFACE_ACT_HISTOGRAM; + break; + case '1': + action = USER_IFACE_ACT_HISTOGRAM_C3; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '4': + /* Structural analysis and shape descriptors */ + switch (ch[4]) { + case '0': + action = USER_IFACE_ACT_CONTOURS; + break; + case '1': + action = USER_IFACE_ACT_CONTOURS_SIZE; + break; + case '2': + action = USER_IFACE_ACT_BOUNDING_RECT; + break; + case '3': + action = USER_IFACE_ACT_FIT_ELLIPSE; + break; + case '4': + action = USER_IFACE_ACT_MIN_AREA_RECT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '5': + /* Feature detection */ + switch (ch[4]) { + case '0': + action = USER_IFACE_ACT_HOUGH_CIRCLES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* img_orb */ + switch (ch[2]) { + case '0': + action = USER_IFACE_ACT_ALIGN; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '3': + /* img_calib3d */ + switch (ch[2]) { + case '0': + action = USER_IFACE_ACT_CALIBRATE; + break; + case '1': + action = USER_IFACE_ACT_UNDISTORT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '4': + /* img_zbar */ + switch (ch[2]) { + case '0': + action = USER_IFACE_ACT_DECODE; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '5': + /* img_ocr */ + switch (ch[2]) { + case '0': + action = USER_IFACE_ACT_READ; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + + case 'l': + action = USER_IFACE_ACT_LOAD_MEM; + break; + + case 'm': + action = USER_IFACE_ACT_SAVE_MEM; + break; + + case 'q': + action = USER_IFACE_ACT_QUIT; + break; + + case 'r': + action = USER_IFACE_ACT_SAVE_REF; + break; + + case 's': + action = USER_IFACE_ACT_SAVE_FILE; + break; + + case 'u': + /* User iface actions */ + switch (ch[1]) { + case '1': + action = USER_IFACE_ACT_SHOW_OCR; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + + case 'x': + /* Special sequence "xyzzy" */ + if (ch[1] == 'y') { + if (ch[2] == 'z') { + if (ch[3] == 'z') { + if (ch[4] == 'y') { + action = USER_IFACE_ACT_FOO; + } + } + } + } + break; + + default: + action = USER_IFACE_ACT_FOO; + break; + } + + return action; +} + +/* * * * * * * * * * + * * * Help * * * * * * * + * * * * * * * * * */ +static void show_help (void) +{ + // FIXME + printf("Apply: %s\n", "Space"); + printf("Discard: %s\n", "Backspace"); + printf("Save to mem: %c\n", 'm'); + printf("Load from mem: %c\n", 'l'); + printf("Save to ref: %c\n", 'r'); + printf("Save to file: %c\n", 's'); + printf("Functions:\n"); + printf(" - Local maxima: %s\n", "f000"); + printf(" - Skeleton: %s\n", "f001"); + printf(" - Horizontal lines: %s\n", "f010"); + printf(" - Vertical lines: %s\n", "f011"); + printf(" - Horizontal mean: %s\n", "f020"); + printf(" - Vertical mean: %s\n", "f021"); + printf(" - Horizontal median: %s\n", "f022"); + printf(" - Vertical median: %s\n", "f023"); + printf(" - Pixel get: %s\n", "f1000"); + printf(" - Pixel set: %s\n", "f1001"); + printf(" - Set ROI: %s\n", "f1010"); + printf(" - Set ROI 2rect: %s\n", "f1011"); + printf(" - Bitwise AND 2ref: %s\n", "f1020"); + printf(" - Bitwise NOT: %s\n", "f1021"); + printf(" - Bitwise OR 2ref: %s\n", "f1022"); + printf(" - Component: %s\n", "f1023"); + printf(" - Dilate: %s\n", "f1100"); + printf(" - Erode: %s\n", "f1101"); + printf(" - D-E: %s\n", "f1102"); + printf(" - E-D: %s\n", "f1103"); + printf(" - Smooth: %s\n", "f1104"); + printf(" - Sobel: %s\n", "f1105"); + printf(" - Border: %s\n", "f1106"); + printf(" - Mirror: %s\n", "f1110"); + printf(" - Rotate ortogonally: %s\n", "f1111"); + printf(" - Rotate: %s\n", "f1112"); + printf(" - Rotate 2rect_rot: %s\n", "f1113"); + printf(" - Adaptive threshold: %s\n", "f1120"); + printf(" - Cvt color: %s\n", "f1121"); + printf(" - Distance transform: %s\n", "f1122"); + printf(" - Threshold: %s\n", "f1123"); + printf(" - Histogram: %s\n", "f1130"); + printf(" - Histogram (3 chan): %s\n", "f1131"); + printf(" - Contours: %s\n", "f1140"); + printf(" - Contours size: %s\n", "f1141"); + printf(" - Bounding rectangle: %s\n", "f1142"); + printf(" - Fit ellipse: %s\n", "f1143"); + printf(" - Min. area rectangle: %s\n", "f1144"); + printf(" - Hough circles: %s\n", "f1150"); + printf(" - Align 2ref (ORB): %s\n", "f20"); + printf(" - Calibrate (Calib3d): %s\n", "f30"); + printf(" - Undistort (Calib3d): %s\n", "f31"); + printf(" - Scan codes (ZBAR): %s\n", "f40"); + printf(" - Scan text (OCR): %s\n", "f50"); + printf("Exercises:\n"); + printf(" - Label: %s\n", "e11"); + printf(" - Objects (calib): %s\n", "e20"); + printf(" - Objects: %s\n", "e21"); + printf(" - Coins: %s\n", "e31"); + printf(" - Resistor: %s\n", "e41"); + printf("Other:\n"); + printf(" - Show OCR text: %s\n", "u1"); + printf("Quit: %c\n", 'q'); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/user/src/user_iface.c b/modules/user/src/user_iface.c index 629dfd8..f465944 100644 --- a/modules/user/src/user_iface.c +++ b/modules/user/src/user_iface.c @@ -1,227 +1,227 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* intX_t */ - #include - /* snprintf() & fflush() */ - #include - -/* Project -------------------------------------------------------------------*/ - /* img_iface_act_nodata() */ - #include "img_iface.h" - /* proc_iface() */ - #include "proc_iface.h" - -/* Module --------------------------------------------------------------------*/ - /* user_clui() & ...save_name() */ - #include "user_clui.h" - /* user_tui() & ...init() & ...cleanup() & ...save_name() */ - #include "user_tui.h" - - #include "user_iface.h" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define TITLE_SIZE (20) - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -int user_iface_mode; -struct User_Iface_Log user_iface_log; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -void user_iface_act (int action); -void user_iface_show_ocr (void); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void user_iface_init (void) -{ - user_iface_log.len = 0; - - switch (user_iface_mode) { - case USER_IFACE_CLUI: - user_clui_init(); - break; - - case USER_IFACE_TUI: - user_tui_init(); - break; - } -} - -void user_iface_cleanup (void) -{ - switch (user_iface_mode) { - case USER_IFACE_CLUI: - break; - - case USER_IFACE_TUI: - user_tui_cleanup(); - break; - } - - fflush(stdout); -} - -void user_iface (void) -{ - char title[TITLE_SIZE]; - char subtitle[TITLE_SIZE]; - int user_action; - - snprintf(title, TITLE_SIZE, "Title"); - snprintf(subtitle, TITLE_SIZE, "Subtitle"); - - do { - /* Display image */ - img_iface_show_img(); - - /* Request user action */ - switch (user_iface_mode) { - case USER_IFACE_CLUI: - user_action = user_clui(title, subtitle); - break; - - case USER_IFACE_TUI: - user_action = user_tui(title, subtitle); - break; - - default: - user_action = USER_IFACE_ACT_FOO; - break; - } - - /* Do action */ - user_iface_act(user_action); - } while (user_action != USER_IFACE_ACT_QUIT); -} - -void user_iface_show_log (const char *title, const char *subtitle) -{ - switch (user_iface_mode) { - case USER_IFACE_CLUI: - user_clui_show_log(title, subtitle); - break; - - case USER_IFACE_TUI: - user_tui_show_log(title, subtitle); - break; - } -} - -void user_iface_fname (const char *filepath, char *filename) -{ - switch (user_iface_mode) { - case USER_IFACE_CLUI: - user_clui_fname(filepath, filename); - break; - - case USER_IFACE_TUI: - user_tui_fname(filepath, filename); - break; - } -} - -int64_t user_iface_getint (double m, int64_t def, double M, - const char *title, const char *help) -{ - int64_t i; - - switch (user_iface_mode) { - case USER_IFACE_CLUI: - // FIXME - i = 1; - break; - - case USER_IFACE_TUI: - i = user_tui_getint(m, def, M, title, help); - break; - - default: - i = 1; - break; - } - - return i; -} - -double user_iface_getdbl (double m, double def, double M, - const char *title, const char *help) -{ - int64_t i; - - switch (user_iface_mode) { - case USER_IFACE_CLUI: - // FIXME - i = 1; - break; - - case USER_IFACE_TUI: - i = user_tui_getdbl(m, def, M, title, help); - break; - - default: - i = 1; - break; - } - - return i; -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -void user_iface_act (int action) -{ - if (action & USER_IFACE_ACT_USRI) { - switch (action) { - case USER_IFACE_ACT_SHOW_OCR: - user_iface_show_ocr(); - break; - case USER_IFACE_ACT_QUIT: - /* do nothing */ - break; - } - - } else if (action & USER_IFACE_ACT_PROC) { - proc_iface_single(action); - - } else { - img_iface_act_nodata(action); - } -} - -void user_iface_show_ocr (void) -{ - switch (user_iface_mode) { - case USER_IFACE_CLUI: - // FIXME - break; - - case USER_IFACE_TUI: - user_tui_show_ocr(); - break; - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* intX_t */ + #include + /* snprintf() & fflush() */ + #include + +/* Project -------------------------------------------------------------------*/ + /* img_iface_act_nodata() */ + #include "img_iface.h" + /* proc_iface() */ + #include "proc_iface.h" + +/* Module --------------------------------------------------------------------*/ + /* user_clui() & ...save_name() */ + #include "user_clui.h" + /* user_tui() & ...init() & ...cleanup() & ...save_name() */ + #include "user_tui.h" + + #include "user_iface.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define TITLE_SIZE (20) + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +int user_iface_mode; +struct User_Iface_Log user_iface_log; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +void user_iface_act (int action); +void user_iface_show_ocr (void); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void user_iface_init (void) +{ + user_iface_log.len = 0; + + switch (user_iface_mode) { + case USER_IFACE_CLUI: + user_clui_init(); + break; + + case USER_IFACE_TUI: + user_tui_init(); + break; + } +} + +void user_iface_cleanup (void) +{ + switch (user_iface_mode) { + case USER_IFACE_CLUI: + break; + + case USER_IFACE_TUI: + user_tui_cleanup(); + break; + } + + fflush(stdout); +} + +void user_iface (void) +{ + char title[TITLE_SIZE]; + char subtitle[TITLE_SIZE]; + int user_action; + + snprintf(title, TITLE_SIZE, "Title"); + snprintf(subtitle, TITLE_SIZE, "Subtitle"); + + do { + /* Display image */ + img_iface_show_img(); + + /* Request user action */ + switch (user_iface_mode) { + case USER_IFACE_CLUI: + user_action = user_clui(title, subtitle); + break; + + case USER_IFACE_TUI: + user_action = user_tui(title, subtitle); + break; + + default: + user_action = USER_IFACE_ACT_FOO; + break; + } + + /* Do action */ + user_iface_act(user_action); + } while (user_action != USER_IFACE_ACT_QUIT); +} + +void user_iface_show_log (const char *title, const char *subtitle) +{ + switch (user_iface_mode) { + case USER_IFACE_CLUI: + user_clui_show_log(title, subtitle); + break; + + case USER_IFACE_TUI: + user_tui_show_log(title, subtitle); + break; + } +} + +void user_iface_fname (const char *filepath, char *filename) +{ + switch (user_iface_mode) { + case USER_IFACE_CLUI: + user_clui_fname(filepath, filename); + break; + + case USER_IFACE_TUI: + user_tui_fname(filepath, filename); + break; + } +} + +int64_t user_iface_getint (double m, int64_t def, double M, + const char *title, const char *help) +{ + int64_t i; + + switch (user_iface_mode) { + case USER_IFACE_CLUI: + // FIXME + i = 1; + break; + + case USER_IFACE_TUI: + i = user_tui_getint(m, def, M, title, help); + break; + + default: + i = 1; + break; + } + + return i; +} + +double user_iface_getdbl (double m, double def, double M, + const char *title, const char *help) +{ + int64_t i; + + switch (user_iface_mode) { + case USER_IFACE_CLUI: + // FIXME + i = 1; + break; + + case USER_IFACE_TUI: + i = user_tui_getdbl(m, def, M, title, help); + break; + + default: + i = 1; + break; + } + + return i; +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +void user_iface_act (int action) +{ + if (action & USER_IFACE_ACT_USRI) { + switch (action) { + case USER_IFACE_ACT_SHOW_OCR: + user_iface_show_ocr(); + break; + case USER_IFACE_ACT_QUIT: + /* do nothing */ + break; + } + + } else if (action & USER_IFACE_ACT_PROC) { + proc_iface_single(action); + + } else { + img_iface_act_nodata(action); + } +} + +void user_iface_show_ocr (void) +{ + switch (user_iface_mode) { + case USER_IFACE_CLUI: + // FIXME + break; + + case USER_IFACE_TUI: + user_tui_show_ocr(); + break; + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/user/src/user_tui.c b/modules/user/src/user_tui.c index 305e1d2..4c10dc6 100644 --- a/modules/user/src/user_tui.c +++ b/modules/user/src/user_tui.c @@ -1,771 +1,771 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include - /* WINDOW & wgetch() & KEY_... & ... */ - #include - -/* libalx --------------------------------------------------------------------*/ - /* alx_..._curses() & alx_ncur_prn_...() */ - #include "alx_ncur.h" - -/* Project -------------------------------------------------------------------*/ - /*img_ocr_text */ - #include "img_iface.h" - -/* Module --------------------------------------------------------------------*/ - /* user_iface_log */ - #include "user_iface.h" - - #include "user_tui.h" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -static WINDOW *win_log; -static WINDOW *win_help; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ - /* Log */ -static void log_loop (void); - /* Input */ -static int usr_input (void); - /* Help */ -static void show_help (void); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void user_tui_init (void) -{ - /* Use curses mode */ - alx_resume_curses(); - - /* Dimensions: log */ - const int h1 = 54; - const int w1 = 40; - const int r1 = 0; - const int c1 = 30; - win_log = newwin(h1, w1, r1, c1); - - /* Dimensions: help */ - const int h2 = 54; - const int w2 = 40; - const int r2 = 0; - const int c2 = 0; - win_help = newwin(h2, w2, r2, c2); - - /* Activate keypad, don't echo input */ - keypad(win_log, true); - noecho(); -} - -void user_tui_cleanup (void) -{ - /* Del wins & return to terminal mode */ - alx_win_del(win_log); - alx_win_del(win_help); - alx_pause_curses(); -} - -int user_tui (const char *title, const char *subtitle) -{ - int action; -// action = USER_IFACE_ACT_FOO; - - show_help(); - user_tui_show_log(title, subtitle); - action = usr_input(); - - return action; -} - -void user_tui_fname (const char *filepath, char *filename) -{ - /* Input box */ - int w; - int r; - w = 75; - r = 10; - - /* Request name */ - alx_w_getfname(filepath, filename, false, w, r, "File name:", - "Valid extensions: .bmp .dib .jpeg .png .pbm .pgm .ppm .tiff"); -} - -void user_tui_show_log (const char *title, const char *subtitle) -{ - /* Clear & box */ - werase(win_log); - box(win_log, 0, 0); - - /* Title */ - alx_ncur_prn_title(win_log, title); - /* Subtitle */ - alx_ncur_prn_subtitle(win_log, subtitle); - - /* Log */ - log_loop(); - - /* Refresh */ - wrefresh(win_log); -} - -double user_tui_getdbl (double m, double def, double M, - const char *title, const char *help) -{ - /* Input box */ - int w; - int r; - w = 75; - r = 10; - - /* Request int */ - double R; - R = alx_w_getdbl(w, r, title, m, def, M, help); - return R; -} - -int64_t user_tui_getint (double m, int64_t def, double M, - const char *title, const char *help) -{ - /* Input box */ - int w; - int r; - w = 75; - r = 10; - - /* Request int */ - int64_t i; - i = alx_w_getint(w, r, title, m, def, M, help); - return i; -} - -void user_tui_show_ocr (void) -{ - alx_pause_curses(); - - printf("%s", img_ocr_text); - getchar(); - - alx_resume_curses(); -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -/* Log -----------------------------------------------------------------------*/ -static void log_loop (void) -{ - int i; - int i_0; - int l; - int l_0; - - if (user_iface_log.len > 51) { - i_0 = user_iface_log.len - 51; - l_0 = 1; - mvwprintw(win_log, 1, 10, "..."); - } else { - i_0 = 0; - l_0 = 0; - } - - l = l_0; - for (i = i_0; i < user_iface_log.len; i++) { - if (user_iface_log.lvl[i] <= user_iface_log.visible) { - mvwprintw(win_log, (1 + l), - (1 + 4 * user_iface_log.lvl[i]), - "%.*s", - 40 - 2 - 4 * user_iface_log.lvl[i], - user_iface_log.line[i]); - l++; - } - } -} - -/* Input ---------------------------------------------------------------------*/ -static int usr_input (void) -{ - int action; - wchar_t ch; - - /* Interpret input */ - ch = wgetch(win_log); - switch (ch) { - case ' ': - action = USER_IFACE_ACT_APPLY; - break; - - /* ASCII 0x08 is BS */ - case KEY_BACKSPACE: - case 0x08: - action = USER_IFACE_ACT_DISCARD; - break; - - case 'e': - /* Exercises from class */ - ch = wgetch(win_log); - - switch (ch) { - case '1': - /* Label */ - ch = wgetch(win_log); - - switch (ch) { - case '1': - action = USER_IFACE_ACT_PROC_LABEL_SERIES; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '2': - /* Objects */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_PROC_OBJECTS_CALIB; - break; - case '1': - action = USER_IFACE_ACT_PROC_OBJECTS_SERIES; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '3': - /* Coins */ - ch = wgetch(win_log); - - switch (ch) { - case '1': - action = USER_IFACE_ACT_PROC_COINS_SERIES; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '4': - /* Resistor */ - ch = wgetch(win_log); - - switch (ch) { - case '1': - action = USER_IFACE_ACT_PROC_RESISTOR_SERIES; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - - case 'f': - /* Use simple funtions */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - /* img_alx */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - /* Distance transform postprocessing */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_LOCAL_MAX; - break; - case '1': - action = USER_IFACE_ACT_SKELETON; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '1': - /* Lines */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_LINES_HORIZONTAL; - break; - case '1': - action = USER_IFACE_ACT_LINES_VERTICAL; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '2': - /* Smooth */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_MEAN_HORIZONTAL; - break; - case '1': - action = USER_IFACE_ACT_MEAN_VERTICAL; - break; - case '2': - action = USER_IFACE_ACT_MEDIAN_HORIZONTAL; - break; - case '3': - action = USER_IFACE_ACT_MEDIAN_VERTICAL; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '1': - /* img_cv */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - /* Core: The core functionality */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - /* Pixel */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_PIXEL_GET; - break; - case '1': - action = USER_IFACE_ACT_PIXEL_SET; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '1': - /* ROI */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_SET_ROI; - break; - case '1': - action = USER_IFACE_ACT_SET_ROI_2RECT; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '2': - /* Operations on Arrays */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_AND_2REF; - break; - case '1': - action = USER_IFACE_ACT_NOT; - break; - case '2': - action = USER_IFACE_ACT_OR_2REF; - break; - case '3': - action = USER_IFACE_ACT_COMPONENT; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '1': - /* Imgproc: Image processing */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - /* Image filtering */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_DILATE; - break; - case '1': - action = USER_IFACE_ACT_ERODE; - break; - case '2': - action = USER_IFACE_ACT_DILATE_ERODE; - break; - case '3': - action = USER_IFACE_ACT_ERODE_DILATE; - break; - case '4': - action = USER_IFACE_ACT_SMOOTH; - break; - case '5': - action = USER_IFACE_ACT_SOBEL; - break; - case '6': - action = USER_IFACE_ACT_BORDER; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '1': - /* Geometric image transformations */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_MIRROR; - break; - case '1': - action = USER_IFACE_ACT_ROTATE_ORTO; - break; - case '2': - action = USER_IFACE_ACT_ROTATE; - break; - case '3': - action = USER_IFACE_ACT_ROTATE_2RECT; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '2': - /* Miscellaneous image transformations */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_ADAPTIVE_THRESHOLD; - break; - case '1': - action = USER_IFACE_ACT_CVT_COLOR; - break; - case '2': - action = USER_IFACE_ACT_DISTANCE_TRANSFORM; - break; - case '3': - action = USER_IFACE_ACT_THRESHOLD; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '3': - /* Histograms */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_HISTOGRAM; - break; - case '1': - action = USER_IFACE_ACT_HISTOGRAM_C3; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '4': - /* Structural analysis and shape descriptors */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_CONTOURS; - break; - case '1': - action = USER_IFACE_ACT_CONTOURS_SIZE; - break; - case '2': - action = USER_IFACE_ACT_BOUNDING_RECT; - break; - case '3': - action = USER_IFACE_ACT_FIT_ELLIPSE; - break; - case '4': - action = USER_IFACE_ACT_MIN_AREA_RECT; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '5': - /* Feature detection */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_HOUGH_CIRCLES; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '2': - /* img_orb */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_ALIGN; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '3': - /* img_calib3d */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_CALIBRATE; - break; - case '1': - action = USER_IFACE_ACT_UNDISTORT; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '4': - /* img_zbar */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_DECODE; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '5': - /* img_ocr */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_READ; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - - case 'l': - action = USER_IFACE_ACT_LOAD_MEM; - break; - - case 'm': - action = USER_IFACE_ACT_SAVE_MEM; - break; - - case 'q': - action = USER_IFACE_ACT_QUIT; - break; - - case 'r': - action = USER_IFACE_ACT_SAVE_REF; - break; - - case 's': - action = USER_IFACE_ACT_SAVE_FILE; - break; - - case 'u': - /* User iface actions */ - ch = wgetch(win_log); - - switch (ch) { - case '1': - action = USER_IFACE_ACT_SHOW_OCR; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - - case 'x': - action = USER_IFACE_ACT_FOO; - - /* Special sequence "xyzzy" */ - ch = wgetch(win_log); - if (ch == 'y') { - ch = wgetch(win_log); - if (ch == 'z') { - - ch = wgetch(win_log); - if (ch == 'z') { - - ch = wgetch(win_log); - if (ch == 'y') { - action = USER_IFACE_ACT_FOO; - } - } - } - } - break; - - default: - action = USER_IFACE_ACT_FOO; - break; - } - - return action; -} - -/* * * * * * * * * * - * * * Help * * * * * * * - * * * * * * * * * */ -static void show_help (void) -{ - /* Clear */ - werase(win_help); - - int r; - int c; - - r = 0; - c = 0; - mvwprintw(win_help, r++, c, "Apply: %s", "Space"); - mvwprintw(win_help, r++, c, "Discard: %s", "BS"); - mvwprintw(win_help, r++, c, "Save to mem: %c", 'm'); - mvwprintw(win_help, r++, c, "Load from mem: %c", 'l'); - 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, " - Local maxima: %s", "f000"); - mvwprintw(win_help, r++, c, " - Skeleton: %s", "f001"); - mvwprintw(win_help, r++, c, " - Horizontal lines: %s", "f010"); - mvwprintw(win_help, r++, c, " - Vertical lines: %s", "f011"); - mvwprintw(win_help, r++, c, " - Horizontal mean: %s", "f020"); - mvwprintw(win_help, r++, c, " - Vertical mean: %s", "f021"); - mvwprintw(win_help, r++, c, " - Horizontal median: %s", "f022"); - mvwprintw(win_help, r++, c, " - Vertical median: %s", "f023"); - mvwprintw(win_help, r++, c, " - Pixel get: %s", "f1000"); - mvwprintw(win_help, r++, c, " - Pixel set: %s", "f1001"); - mvwprintw(win_help, r++, c, " - Set ROI: %s", "f1010"); - mvwprintw(win_help, r++, c, " - Set ROI 2rect: %s", "f1011"); - mvwprintw(win_help, r++, c, " - Bitwise AND 2ref: %s", "f1020"); - mvwprintw(win_help, r++, c, " - Bitwise NOT: %s", "f1021"); - mvwprintw(win_help, r++, c, " - Bitwise OR 2ref: %s", "f1022"); - mvwprintw(win_help, r++, c, " - Component: %s", "f1023"); - mvwprintw(win_help, r++, c, " - Dilate: %s", "f1100"); - mvwprintw(win_help, r++, c, " - Erode: %s", "f1101"); - mvwprintw(win_help, r++, c, " - D-E: %s", "f1102"); - mvwprintw(win_help, r++, c, " - E-D: %s", "f1103"); - mvwprintw(win_help, r++, c, " - Smooth: %s", "f1104"); - mvwprintw(win_help, r++, c, " - Sobel: %s", "f1105"); - mvwprintw(win_help, r++, c, " - Border: %s", "f1106"); - mvwprintw(win_help, r++, c, " - Mirror: %s", "f1110"); - mvwprintw(win_help, r++, c, " - Rotate ortogonally: %s", "f1111"); - mvwprintw(win_help, r++, c, " - Rotate: %s", "f1112"); - mvwprintw(win_help, r++, c, " - Rotate 2rect_rot: %s", "f1113"); - mvwprintw(win_help, r++, c, " - Adaptive threshold: %s", "f1120"); - mvwprintw(win_help, r++, c, " - Cvt color: %s", "f1121"); - mvwprintw(win_help, r++, c, " - Distance transform: %s", "f1122"); - mvwprintw(win_help, r++, c, " - Threshold: %s", "f1123"); - mvwprintw(win_help, r++, c, " - Histogram: %s", "f1130"); - mvwprintw(win_help, r++, c, " - Histogram (3 chan): %s", "f1131"); - mvwprintw(win_help, r++, c, " - Contours: %s", "f1140"); - mvwprintw(win_help, r++, c, " - Contours size: %s", "f1141"); - mvwprintw(win_help, r++, c, " - Bounding rectangle: %s", "f1142"); - mvwprintw(win_help, r++, c, " - Fit ellipse: %s", "f1143"); - mvwprintw(win_help, r++, c, " - Min. area rectangle: %s", "f1144"); - mvwprintw(win_help, r++, c, " - Hough circles: %s", "f1150"); - mvwprintw(win_help, r++, c, " - Align 2ref (ORB): %s", "f20"); - mvwprintw(win_help, r++, c, " - Calibrate (Calib3d): %s", "f30"); - mvwprintw(win_help, r++, c, " - Undistort (Calib3d): %s", "f31"); - mvwprintw(win_help, r++, c, " - Scan codes (ZBAR): %s", "f40"); - mvwprintw(win_help, r++, c, " - Scan text (OCR): %s", "f50"); - mvwprintw(win_help, r++, c, "Exercises:"); - mvwprintw(win_help, r++, c, " - Label: %s", "e11"); - mvwprintw(win_help, r++, c, " - Objects (calib): %s", "e20"); - mvwprintw(win_help, r++, c, " - Objects: %s", "e21"); - mvwprintw(win_help, r++, c, " - Coins: %s", "e31"); - mvwprintw(win_help, r++, c, " - Resistor: %s", "e41"); - mvwprintw(win_help, r++, c, "Other:"); - mvwprintw(win_help, r++, c, " - Show OCR: %s", "u1"); - mvwprintw(win_help, r++, c, "Quit: %c", 'q'); - - /* Refresh */ - wrefresh(win_help); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + #include + /* WINDOW & wgetch() & KEY_... & ... */ + #include + +/* libalx --------------------------------------------------------------------*/ + /* alx_..._curses() & alx_ncur_prn_...() */ + #include "alx_ncur.h" + +/* Project -------------------------------------------------------------------*/ + /*img_ocr_text */ + #include "img_iface.h" + +/* Module --------------------------------------------------------------------*/ + /* user_iface_log */ + #include "user_iface.h" + + #include "user_tui.h" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +static WINDOW *win_log; +static WINDOW *win_help; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ + /* Log */ +static void log_loop (void); + /* Input */ +static int usr_input (void); + /* Help */ +static void show_help (void); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void user_tui_init (void) +{ + /* Use curses mode */ + alx_resume_curses(); + + /* Dimensions: log */ + const int h1 = 54; + const int w1 = 40; + const int r1 = 0; + const int c1 = 30; + win_log = newwin(h1, w1, r1, c1); + + /* Dimensions: help */ + const int h2 = 54; + const int w2 = 40; + const int r2 = 0; + const int c2 = 0; + win_help = newwin(h2, w2, r2, c2); + + /* Activate keypad, don't echo input */ + keypad(win_log, true); + noecho(); +} + +void user_tui_cleanup (void) +{ + /* Del wins & return to terminal mode */ + alx_win_del(win_log); + alx_win_del(win_help); + alx_pause_curses(); +} + +int user_tui (const char *title, const char *subtitle) +{ + int action; +// action = USER_IFACE_ACT_FOO; + + show_help(); + user_tui_show_log(title, subtitle); + action = usr_input(); + + return action; +} + +void user_tui_fname (const char *filepath, char *filename) +{ + /* Input box */ + int w; + int r; + w = 75; + r = 10; + + /* Request name */ + alx_w_getfname(filepath, filename, false, w, r, "File name:", + "Valid extensions: .bmp .dib .jpeg .png .pbm .pgm .ppm .tiff"); +} + +void user_tui_show_log (const char *title, const char *subtitle) +{ + /* Clear & box */ + werase(win_log); + box(win_log, 0, 0); + + /* Title */ + alx_ncur_prn_title(win_log, title); + /* Subtitle */ + alx_ncur_prn_subtitle(win_log, subtitle); + + /* Log */ + log_loop(); + + /* Refresh */ + wrefresh(win_log); +} + +double user_tui_getdbl (double m, double def, double M, + const char *title, const char *help) +{ + /* Input box */ + int w; + int r; + w = 75; + r = 10; + + /* Request int */ + double R; + R = alx_w_getdbl(w, r, title, m, def, M, help); + return R; +} + +int64_t user_tui_getint (double m, int64_t def, double M, + const char *title, const char *help) +{ + /* Input box */ + int w; + int r; + w = 75; + r = 10; + + /* Request int */ + int64_t i; + i = alx_w_getint(w, r, title, m, def, M, help); + return i; +} + +void user_tui_show_ocr (void) +{ + alx_pause_curses(); + + printf("%s", img_ocr_text); + getchar(); + + alx_resume_curses(); +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +/* Log -----------------------------------------------------------------------*/ +static void log_loop (void) +{ + int i; + int i_0; + int l; + int l_0; + + if (user_iface_log.len > 51) { + i_0 = user_iface_log.len - 51; + l_0 = 1; + mvwprintw(win_log, 1, 10, "..."); + } else { + i_0 = 0; + l_0 = 0; + } + + l = l_0; + for (i = i_0; i < user_iface_log.len; i++) { + if (user_iface_log.lvl[i] <= user_iface_log.visible) { + mvwprintw(win_log, (1 + l), + (1 + 4 * user_iface_log.lvl[i]), + "%.*s", + 40 - 2 - 4 * user_iface_log.lvl[i], + user_iface_log.line[i]); + l++; + } + } +} + +/* Input ---------------------------------------------------------------------*/ +static int usr_input (void) +{ + int action; + wchar_t ch; + + /* Interpret input */ + ch = wgetch(win_log); + switch (ch) { + case ' ': + action = USER_IFACE_ACT_APPLY; + break; + + /* ASCII 0x08 is BS */ + case KEY_BACKSPACE: + case 0x08: + action = USER_IFACE_ACT_DISCARD; + break; + + case 'e': + /* Exercises from class */ + ch = wgetch(win_log); + + switch (ch) { + case '1': + /* Label */ + ch = wgetch(win_log); + + switch (ch) { + case '1': + action = USER_IFACE_ACT_PROC_LABEL_SERIES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* Objects */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_PROC_OBJECTS_CALIB; + break; + case '1': + action = USER_IFACE_ACT_PROC_OBJECTS_SERIES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '3': + /* Coins */ + ch = wgetch(win_log); + + switch (ch) { + case '1': + action = USER_IFACE_ACT_PROC_COINS_SERIES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '4': + /* Resistor */ + ch = wgetch(win_log); + + switch (ch) { + case '1': + action = USER_IFACE_ACT_PROC_RESISTOR_SERIES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + + case 'f': + /* Use simple funtions */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + /* img_alx */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + /* Distance transform postprocessing */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_LOCAL_MAX; + break; + case '1': + action = USER_IFACE_ACT_SKELETON; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '1': + /* Lines */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_LINES_HORIZONTAL; + break; + case '1': + action = USER_IFACE_ACT_LINES_VERTICAL; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* Smooth */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_MEAN_HORIZONTAL; + break; + case '1': + action = USER_IFACE_ACT_MEAN_VERTICAL; + break; + case '2': + action = USER_IFACE_ACT_MEDIAN_HORIZONTAL; + break; + case '3': + action = USER_IFACE_ACT_MEDIAN_VERTICAL; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '1': + /* img_cv */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + /* Core: The core functionality */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + /* Pixel */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_PIXEL_GET; + break; + case '1': + action = USER_IFACE_ACT_PIXEL_SET; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '1': + /* ROI */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_SET_ROI; + break; + case '1': + action = USER_IFACE_ACT_SET_ROI_2RECT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* Operations on Arrays */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_AND_2REF; + break; + case '1': + action = USER_IFACE_ACT_NOT; + break; + case '2': + action = USER_IFACE_ACT_OR_2REF; + break; + case '3': + action = USER_IFACE_ACT_COMPONENT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '1': + /* Imgproc: Image processing */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + /* Image filtering */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_DILATE; + break; + case '1': + action = USER_IFACE_ACT_ERODE; + break; + case '2': + action = USER_IFACE_ACT_DILATE_ERODE; + break; + case '3': + action = USER_IFACE_ACT_ERODE_DILATE; + break; + case '4': + action = USER_IFACE_ACT_SMOOTH; + break; + case '5': + action = USER_IFACE_ACT_SOBEL; + break; + case '6': + action = USER_IFACE_ACT_BORDER; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '1': + /* Geometric image transformations */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_MIRROR; + break; + case '1': + action = USER_IFACE_ACT_ROTATE_ORTO; + break; + case '2': + action = USER_IFACE_ACT_ROTATE; + break; + case '3': + action = USER_IFACE_ACT_ROTATE_2RECT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* Miscellaneous image transformations */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_ADAPTIVE_THRESHOLD; + break; + case '1': + action = USER_IFACE_ACT_CVT_COLOR; + break; + case '2': + action = USER_IFACE_ACT_DISTANCE_TRANSFORM; + break; + case '3': + action = USER_IFACE_ACT_THRESHOLD; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '3': + /* Histograms */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_HISTOGRAM; + break; + case '1': + action = USER_IFACE_ACT_HISTOGRAM_C3; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '4': + /* Structural analysis and shape descriptors */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_CONTOURS; + break; + case '1': + action = USER_IFACE_ACT_CONTOURS_SIZE; + break; + case '2': + action = USER_IFACE_ACT_BOUNDING_RECT; + break; + case '3': + action = USER_IFACE_ACT_FIT_ELLIPSE; + break; + case '4': + action = USER_IFACE_ACT_MIN_AREA_RECT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '5': + /* Feature detection */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_HOUGH_CIRCLES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* img_orb */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_ALIGN; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '3': + /* img_calib3d */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_CALIBRATE; + break; + case '1': + action = USER_IFACE_ACT_UNDISTORT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '4': + /* img_zbar */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_DECODE; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '5': + /* img_ocr */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_READ; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + + case 'l': + action = USER_IFACE_ACT_LOAD_MEM; + break; + + case 'm': + action = USER_IFACE_ACT_SAVE_MEM; + break; + + case 'q': + action = USER_IFACE_ACT_QUIT; + break; + + case 'r': + action = USER_IFACE_ACT_SAVE_REF; + break; + + case 's': + action = USER_IFACE_ACT_SAVE_FILE; + break; + + case 'u': + /* User iface actions */ + ch = wgetch(win_log); + + switch (ch) { + case '1': + action = USER_IFACE_ACT_SHOW_OCR; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + + case 'x': + action = USER_IFACE_ACT_FOO; + + /* Special sequence "xyzzy" */ + ch = wgetch(win_log); + if (ch == 'y') { + ch = wgetch(win_log); + if (ch == 'z') { + + ch = wgetch(win_log); + if (ch == 'z') { + + ch = wgetch(win_log); + if (ch == 'y') { + action = USER_IFACE_ACT_FOO; + } + } + } + } + break; + + default: + action = USER_IFACE_ACT_FOO; + break; + } + + return action; +} + +/* * * * * * * * * * + * * * Help * * * * * * * + * * * * * * * * * */ +static void show_help (void) +{ + /* Clear */ + werase(win_help); + + int r; + int c; + + r = 0; + c = 0; + mvwprintw(win_help, r++, c, "Apply: %s", "Space"); + mvwprintw(win_help, r++, c, "Discard: %s", "BS"); + mvwprintw(win_help, r++, c, "Save to mem: %c", 'm'); + mvwprintw(win_help, r++, c, "Load from mem: %c", 'l'); + 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, " - Local maxima: %s", "f000"); + mvwprintw(win_help, r++, c, " - Skeleton: %s", "f001"); + mvwprintw(win_help, r++, c, " - Horizontal lines: %s", "f010"); + mvwprintw(win_help, r++, c, " - Vertical lines: %s", "f011"); + mvwprintw(win_help, r++, c, " - Horizontal mean: %s", "f020"); + mvwprintw(win_help, r++, c, " - Vertical mean: %s", "f021"); + mvwprintw(win_help, r++, c, " - Horizontal median: %s", "f022"); + mvwprintw(win_help, r++, c, " - Vertical median: %s", "f023"); + mvwprintw(win_help, r++, c, " - Pixel get: %s", "f1000"); + mvwprintw(win_help, r++, c, " - Pixel set: %s", "f1001"); + mvwprintw(win_help, r++, c, " - Set ROI: %s", "f1010"); + mvwprintw(win_help, r++, c, " - Set ROI 2rect: %s", "f1011"); + mvwprintw(win_help, r++, c, " - Bitwise AND 2ref: %s", "f1020"); + mvwprintw(win_help, r++, c, " - Bitwise NOT: %s", "f1021"); + mvwprintw(win_help, r++, c, " - Bitwise OR 2ref: %s", "f1022"); + mvwprintw(win_help, r++, c, " - Component: %s", "f1023"); + mvwprintw(win_help, r++, c, " - Dilate: %s", "f1100"); + mvwprintw(win_help, r++, c, " - Erode: %s", "f1101"); + mvwprintw(win_help, r++, c, " - D-E: %s", "f1102"); + mvwprintw(win_help, r++, c, " - E-D: %s", "f1103"); + mvwprintw(win_help, r++, c, " - Smooth: %s", "f1104"); + mvwprintw(win_help, r++, c, " - Sobel: %s", "f1105"); + mvwprintw(win_help, r++, c, " - Border: %s", "f1106"); + mvwprintw(win_help, r++, c, " - Mirror: %s", "f1110"); + mvwprintw(win_help, r++, c, " - Rotate ortogonally: %s", "f1111"); + mvwprintw(win_help, r++, c, " - Rotate: %s", "f1112"); + mvwprintw(win_help, r++, c, " - Rotate 2rect_rot: %s", "f1113"); + mvwprintw(win_help, r++, c, " - Adaptive threshold: %s", "f1120"); + mvwprintw(win_help, r++, c, " - Cvt color: %s", "f1121"); + mvwprintw(win_help, r++, c, " - Distance transform: %s", "f1122"); + mvwprintw(win_help, r++, c, " - Threshold: %s", "f1123"); + mvwprintw(win_help, r++, c, " - Histogram: %s", "f1130"); + mvwprintw(win_help, r++, c, " - Histogram (3 chan): %s", "f1131"); + mvwprintw(win_help, r++, c, " - Contours: %s", "f1140"); + mvwprintw(win_help, r++, c, " - Contours size: %s", "f1141"); + mvwprintw(win_help, r++, c, " - Bounding rectangle: %s", "f1142"); + mvwprintw(win_help, r++, c, " - Fit ellipse: %s", "f1143"); + mvwprintw(win_help, r++, c, " - Min. area rectangle: %s", "f1144"); + mvwprintw(win_help, r++, c, " - Hough circles: %s", "f1150"); + mvwprintw(win_help, r++, c, " - Align 2ref (ORB): %s", "f20"); + mvwprintw(win_help, r++, c, " - Calibrate (Calib3d): %s", "f30"); + mvwprintw(win_help, r++, c, " - Undistort (Calib3d): %s", "f31"); + mvwprintw(win_help, r++, c, " - Scan codes (ZBAR): %s", "f40"); + mvwprintw(win_help, r++, c, " - Scan text (OCR): %s", "f50"); + mvwprintw(win_help, r++, c, "Exercises:"); + mvwprintw(win_help, r++, c, " - Label: %s", "e11"); + mvwprintw(win_help, r++, c, " - Objects (calib): %s", "e20"); + mvwprintw(win_help, r++, c, " - Objects: %s", "e21"); + mvwprintw(win_help, r++, c, " - Coins: %s", "e31"); + mvwprintw(win_help, r++, c, " - Resistor: %s", "e41"); + mvwprintw(win_help, r++, c, "Other:"); + mvwprintw(win_help, r++, c, " - Show OCR: %s", "u1"); + mvwprintw(win_help, r++, c, "Quit: %c", 'q'); + + /* Refresh */ + wrefresh(win_help); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/main.cpp b/src/main.cpp index 875cfbd..f672b68 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,88 +1,88 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* getchar() */ - #include - -/* libalx --------------------------------------------------------------------*/ - #include "alx_ncur.hpp" - -/* Project -------------------------------------------------------------------*/ - /* about_init() & print_cpright() */ - #include "about.hpp" - #include "img_iface.hpp" - #include "menu_iface.hpp" - #include "user_iface.hpp" - #include "parser.hpp" - #include "save.hpp" - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void init_all (int *argc, char *(*argv[])); -static void cleanup (void); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -int main (int argc, char *argv[]) -{ - init_all(&argc, &argv); - - /* Print copyright () and wait for any key to continue */ - print_share_file(SHARE_COPYRIGHT); - getchar(); - - /* Menu () */ - menu_iface(); - - cleanup(); - - return 0; -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void init_all (int *argc, char *(*argv[])) -{ - /* Init curses */ - alx_start_curses(); - alx_pause_curses(); - - /* Init modules */ - about_init(); - save_init(); - - /* Modes */ - menu_iface_mode = MENU_IFACE_TUI; - user_iface_mode = USER_IFACE_TUI; - user_iface_log.visible = 2; - - /* Parse command line options */ - parser(*argc, *argv); -} - -static void cleanup (void) -{ - /* Clean img buffers */ - img_iface_cleanup_main(); - - /* End curses */ - alx_resume_curses(); - alx_end_curses(); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* getchar() */ + #include + +/* libalx --------------------------------------------------------------------*/ + #include "alx_ncur.hpp" + +/* Project -------------------------------------------------------------------*/ + /* about_init() & print_cpright() */ + #include "about.hpp" + #include "img_iface.hpp" + #include "menu_iface.hpp" + #include "user_iface.hpp" + #include "parser.hpp" + #include "save.hpp" + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void init_all (int *argc, char *(*argv[])); +static void cleanup (void); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +int main (int argc, char *argv[]) +{ + init_all(&argc, &argv); + + /* Print copyright () and wait for any key to continue */ + print_share_file(SHARE_COPYRIGHT); + getchar(); + + /* Menu () */ + menu_iface(); + + cleanup(); + + return 0; +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void init_all (int *argc, char *(*argv[])) +{ + /* Init curses */ + alx_start_curses(); + alx_pause_curses(); + + /* Init modules */ + about_init(); + save_init(); + + /* Modes */ + menu_iface_mode = MENU_IFACE_TUI; + user_iface_mode = USER_IFACE_TUI; + user_iface_log.visible = 2; + + /* Parse command line options */ + parser(*argc, *argv); +} + +static void cleanup (void) +{ + /* Clean img buffers */ + img_iface_cleanup_main(); + + /* End curses */ + alx_resume_curses(); + alx_end_curses(); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ -- cgit v1.2.3 From f4016f64fb994db1227fd8725496a8344157ac91 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Fri, 4 Jan 2019 16:50:46 +0100 Subject: Unix new lines --- modules/about/inc/about.h | 126 +- modules/about/inc/about.hpp | 150 +- modules/about/src/about.c | 176 +- modules/ctrl/inc/start.h | 86 +- modules/ctrl/src/start.c | 210 +- modules/image/inc/img_alx.hpp | 104 +- modules/image/inc/img_calib3d.hpp | 92 +- modules/image/inc/img_cv.hpp | 142 +- modules/image/inc/img_iface.h | 374 ++-- modules/image/inc/img_iface.hpp | 686 +++--- modules/image/inc/img_ocr.h | 76 +- modules/image/inc/img_ocr.hpp | 100 +- modules/image/inc/img_orb.hpp | 92 +- modules/image/inc/img_zbar.hpp | 92 +- modules/image/src/img_alx.cpp | 758 +++---- modules/image/src/img_calib3d.cpp | 284 +-- modules/image/src/img_cv.cpp | 1762 ++++++++-------- modules/image/src/img_iface.cpp | 4020 ++++++++++++++++++------------------ modules/image/src/img_ocr.c | 256 +-- modules/image/src/img_orb.cpp | 252 +-- modules/image/src/img_zbar.cpp | 204 +- modules/menu/inc/menu_clui.h | 54 +- modules/menu/inc/menu_iface.h | 86 +- modules/menu/inc/menu_iface.hpp | 110 +- modules/menu/inc/menu_tui.h | 54 +- modules/menu/inc/parser.h | 54 +- modules/menu/inc/parser.hpp | 78 +- modules/menu/src/menu_clui.c | 232 +-- modules/menu/src/menu_iface.c | 90 +- modules/menu/src/menu_tui.c | 668 +++--- modules/menu/src/parser.c | 280 +-- modules/proc/inc/proc_coins.h | 96 +- modules/proc/inc/proc_coins.hpp | 120 +- modules/proc/inc/proc_common.h | 90 +- modules/proc/inc/proc_common.hpp | 222 +- modules/proc/inc/proc_iface.h | 142 +- modules/proc/inc/proc_iface.hpp | 166 +- modules/proc/inc/proc_label.h | 100 +- modules/proc/inc/proc_label.hpp | 124 +- modules/proc/inc/proc_lighters.h | 94 +- modules/proc/inc/proc_lighters.hpp | 118 +- modules/proc/inc/proc_objects.h | 98 +- modules/proc/inc/proc_objects.hpp | 122 +- modules/proc/inc/proc_resistor.h | 100 +- modules/proc/inc/proc_resistor.hpp | 124 +- modules/proc/src/proc_coins.cpp | 756 +++---- modules/proc/src/proc_common.cpp | 864 ++++---- modules/proc/src/proc_iface.c | 454 ++-- modules/proc/src/proc_label.cpp | 770 +++---- modules/proc/src/proc_lighters.cpp | 683 +++--- modules/proc/src/proc_objects.cpp | 1394 ++++++------- modules/proc/src/proc_resistor.cpp | 2918 +++++++++++++------------- modules/save/inc/save.h | 156 +- modules/save/inc/save.hpp | 190 +- modules/save/src/save.cpp | 396 ++-- modules/user/inc/user_clui.h | 60 +- modules/user/inc/user_iface.h | 326 +-- modules/user/inc/user_iface.hpp | 350 ++-- modules/user/inc/user_tui.h | 72 +- modules/user/src/user_clui.c | 1244 +++++------ modules/user/src/user_iface.c | 454 ++-- modules/user/src/user_tui.c | 1542 +++++++------- src/main.cpp | 176 +- 63 files changed, 13161 insertions(+), 13108 deletions(-) diff --git a/modules/about/inc/about.h b/modules/about/inc/about.h index 5122d14..62a0963 100644 --- a/modules/about/inc/about.h +++ b/modules/about/inc/about.h @@ -1,63 +1,63 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_ABOUT_H - # define VA_ABOUT_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* FILENAME_MAX */ - #include - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define PROG_NAME "vision-artificial" - # define PROG_YEAR "2018" - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Share_File { - SHARE_COPYRIGHT, - SHARE_DISCLAIMER, - SHARE_HELP, - SHARE_LICENSE, - SHARE_USAGE - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - extern char share_path [FILENAME_MAX]; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void about_init (void); - void snprint_share_file (char *dest, int destsize, int share_file); - void print_share_file (int share_file); - void print_version (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* about.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_ABOUT_H + # define VA_ABOUT_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* FILENAME_MAX */ + #include + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define PROG_NAME "vision-artificial" + # define PROG_YEAR "2018" + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Share_File { + SHARE_COPYRIGHT, + SHARE_DISCLAIMER, + SHARE_HELP, + SHARE_LICENSE, + SHARE_USAGE + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern char share_path [FILENAME_MAX]; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void about_init (void); + void snprint_share_file (char *dest, int destsize, int share_file); + void print_share_file (int share_file); + void print_version (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* about.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/about/inc/about.hpp b/modules/about/inc/about.hpp index 50180ba..a1a9f2e 100644 --- a/modules/about/inc/about.hpp +++ b/modules/about/inc/about.hpp @@ -1,75 +1,75 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_ABOUT_HPP - # define VA_ABOUT_HPP - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* FILENAME_MAX */ - #include - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define PROG_NAME "vision-artificial" - # define PROG_YEAR "2018" - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Share_File { - SHARE_COPYRIGHT, - SHARE_DISCLAIMER, - SHARE_HELP, - SHARE_LICENSE, - SHARE_USAGE - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - extern char share_path [FILENAME_MAX]; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void about_init (void); - void snprint_share_file (char *dest, int destsize, int share_file); - void print_share_file (int share_file); - void print_version (void); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* about.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_ABOUT_HPP + # define VA_ABOUT_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* FILENAME_MAX */ + #include + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define PROG_NAME "vision-artificial" + # define PROG_YEAR "2018" + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Share_File { + SHARE_COPYRIGHT, + SHARE_DISCLAIMER, + SHARE_HELP, + SHARE_LICENSE, + SHARE_USAGE + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern char share_path [FILENAME_MAX]; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void about_init (void); + void snprint_share_file (char *dest, int destsize, int share_file); + void print_share_file (int share_file); + void print_version (void); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* about.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/about/src/about.c b/modules/about/src/about.c index d443e1d..a9561e0 100644 --- a/modules/about/src/about.c +++ b/modules/about/src/about.c @@ -1,88 +1,88 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* printf() */ - #include - -/* libalx --------------------------------------------------------------------*/ - /* alx_snprint_file() */ - #include "alx_file.h" - -/* Module --------------------------------------------------------------------*/ - #include "about.h" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define BUFF_SIZE_TEXT (1048576) - - # define BEGINNING "\n┌──────────────────────────────────────────────────────────────────────────────┐\n" - # define ENDING "└──────────────────────────────────────────────────────────────────────────────┘\n\n" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -char share_path [FILENAME_MAX]; - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void about_init (void) -{ - snprintf(share_path, FILENAME_MAX, "%s/%s/", INSTALL_SHARE_DIR, SHARE_DIR); -} - -void snprint_share_file (char *dest, int destsize, int share_file) -{ - char file_name [FILENAME_MAX]; - - switch (share_file) { - case SHARE_COPYRIGHT: - snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "COPYRIGHT.txt"); - break; - case SHARE_DISCLAIMER: - snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "DISCLAIMER.txt"); - break; - case SHARE_HELP: - snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "HELP.txt"); - break; - case SHARE_LICENSE: - snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "LICENSE.txt"); - break; - case SHARE_USAGE: - snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "USAGE.txt"); - break; - } - - alx_snprint_file(dest, destsize, file_name); -} - -void print_share_file (int share_file) -{ - char str [BUFF_SIZE_TEXT]; - - snprint_share_file(str, BUFF_SIZE_TEXT, share_file); - - printf(BEGINNING); - printf("%s", str); - printf(ENDING); -} - -void print_version (void) -{ - printf("" PROG_NAME " " PROG_VERSION "\n\n"); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* printf() */ + #include + +/* libalx --------------------------------------------------------------------*/ + /* alx_snprint_file() */ + #include "alx_file.h" + +/* Module --------------------------------------------------------------------*/ + #include "about.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define BUFF_SIZE_TEXT (1048576) + + # define BEGINNING "\n┌──────────────────────────────────────────────────────────────────────────────┐\n" + # define ENDING "└──────────────────────────────────────────────────────────────────────────────┘\n\n" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +char share_path [FILENAME_MAX]; + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void about_init (void) +{ + snprintf(share_path, FILENAME_MAX, "%s/%s/", INSTALL_SHARE_DIR, SHARE_DIR); +} + +void snprint_share_file (char *dest, int destsize, int share_file) +{ + char file_name [FILENAME_MAX]; + + switch (share_file) { + case SHARE_COPYRIGHT: + snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "COPYRIGHT.txt"); + break; + case SHARE_DISCLAIMER: + snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "DISCLAIMER.txt"); + break; + case SHARE_HELP: + snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "HELP.txt"); + break; + case SHARE_LICENSE: + snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "LICENSE.txt"); + break; + case SHARE_USAGE: + snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "USAGE.txt"); + break; + } + + alx_snprint_file(dest, destsize, file_name); +} + +void print_share_file (int share_file) +{ + char str [BUFF_SIZE_TEXT]; + + snprint_share_file(str, BUFF_SIZE_TEXT, share_file); + + printf(BEGINNING); + printf("%s", str); + printf(ENDING); +} + +void print_version (void) +{ + printf("" PROG_NAME " " PROG_VERSION "\n\n"); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/ctrl/inc/start.h b/modules/ctrl/inc/start.h index 9b79302..1ef2af6 100644 --- a/modules/ctrl/inc/start.h +++ b/modules/ctrl/inc/start.h @@ -1,43 +1,43 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_START_H - # define VA_START_H - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Start_Mode { - START_FOO = 0, - START_SINGLE, - START_SERIES - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - extern int start_mode; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void start_switch (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* start.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_START_H + # define VA_START_H + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Start_Mode { + START_FOO = 0, + START_SINGLE, + START_SERIES + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern int start_mode; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void start_switch (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* start.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/ctrl/src/start.c b/modules/ctrl/src/start.c index bd801c1..37ea1b4 100644 --- a/modules/ctrl/src/start.c +++ b/modules/ctrl/src/start.c @@ -1,105 +1,105 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* errno */ - #include - #include - /* printf() */ - #include - -/* Project -------------------------------------------------------------------*/ - /* img_iface_load() */ - #include "img_iface.h" - /* proc_iface_series() */ - #include "proc_iface.h" - /* saved_name*/ - #include "save.h" - /* user_iface() */ - #include "user_iface.h" - -/* Module --------------------------------------------------------------------*/ - #include "start.h" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -int start_mode; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void start_foo (void); -static void start_single (void); -static void start_series (void); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void start_switch (void) -{ - switch (start_mode) { - case START_FOO: - start_foo(); - break; - - case START_SINGLE: - start_single(); - break; - - case START_SERIES: - start_series(); - break; - } -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void start_foo (void) -{ - /* empty */ -} - -static void start_single (void) -{ - errno = 0; - img_iface_load(NULL, saved_name); - - if (!errno) { - user_iface_init(); - user_iface(); - user_iface_cleanup(); - } else { - printf("errno:%i\n", errno); - } - - img_iface_cleanup(); -} - -static void start_series (void) -{ - int tmp; - tmp = user_iface_mode; - user_iface_mode = USER_IFACE_CLUI; - - user_iface_init(); - proc_iface_series(); - user_iface_cleanup(); - - user_iface_mode = tmp; -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* errno */ + #include + #include + /* printf() */ + #include + +/* Project -------------------------------------------------------------------*/ + /* img_iface_load() */ + #include "img_iface.h" + /* proc_iface_series() */ + #include "proc_iface.h" + /* saved_name*/ + #include "save.h" + /* user_iface() */ + #include "user_iface.h" + +/* Module --------------------------------------------------------------------*/ + #include "start.h" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +int start_mode; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void start_foo (void); +static void start_single (void); +static void start_series (void); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void start_switch (void) +{ + switch (start_mode) { + case START_FOO: + start_foo(); + break; + + case START_SINGLE: + start_single(); + break; + + case START_SERIES: + start_series(); + break; + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void start_foo (void) +{ + /* empty */ +} + +static void start_single (void) +{ + errno = 0; + img_iface_load(NULL, saved_name); + + if (!errno) { + user_iface_init(); + user_iface(); + user_iface_cleanup(); + } else { + printf("errno:%i\n", errno); + } + + img_iface_cleanup(); +} + +static void start_series (void) +{ + int tmp; + tmp = user_iface_mode; + user_iface_mode = USER_IFACE_CLUI; + + user_iface_init(); + proc_iface_series(); + user_iface_cleanup(); + + user_iface_mode = tmp; +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/inc/img_alx.hpp b/modules/image/inc/img_alx.hpp index 9476ef8..d3867d6 100644 --- a/modules/image/inc/img_alx.hpp +++ b/modules/image/inc/img_alx.hpp @@ -1,52 +1,52 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_ALX_H - # define VA_IMG_ALX_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - /* openCV */ - #include - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_Alx_Action { - IMG_ALX_ACT_FOO = 0x000000u, - - IMG_ALX_ACT_ALX = 0x000010u, - IMG_ALX_ACT_LOCAL_MAX, - IMG_ALX_ACT_SKELETON, - IMG_ALX_ACT_LINES_HORIZONTAL, - IMG_ALX_ACT_LINES_VERTICAL, - IMG_ALX_ACT_MEAN_HORIZONTAL, - IMG_ALX_ACT_MEAN_VERTICAL, - IMG_ALX_ACT_MEDIAN_HORIZONTAL, - IMG_ALX_ACT_MEDIAN_VERTICAL - }; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void img_alx_act (class cv::Mat *imgptr, int action, void *data); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_alx.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_IMG_ALX_H + # define VA_IMG_ALX_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + /* openCV */ + #include + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Img_Alx_Action { + IMG_ALX_ACT_FOO = 0x000000u, + + IMG_ALX_ACT_ALX = 0x000010u, + IMG_ALX_ACT_LOCAL_MAX, + IMG_ALX_ACT_SKELETON, + IMG_ALX_ACT_LINES_HORIZONTAL, + IMG_ALX_ACT_LINES_VERTICAL, + IMG_ALX_ACT_MEAN_HORIZONTAL, + IMG_ALX_ACT_MEAN_VERTICAL, + IMG_ALX_ACT_MEDIAN_HORIZONTAL, + IMG_ALX_ACT_MEDIAN_VERTICAL + }; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void img_alx_act (class cv::Mat *imgptr, int action, void *data); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* img_alx.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/inc/img_calib3d.hpp b/modules/image/inc/img_calib3d.hpp index 777f33c..7079d68 100644 --- a/modules/image/inc/img_calib3d.hpp +++ b/modules/image/inc/img_calib3d.hpp @@ -1,46 +1,46 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_CALIB3D_HPP - # define VA_IMG_CALIB3D_HPP - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - /* openCV */ - #include - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_Calib3d_Action { - IMG_CALIB3D_ACT_FOO = 0x000000u, - - IMG_CALIB3D_ACT_CALIB3D = 0x000400u, - IMG_CALIB3D_ACT_CALIBRATE, - IMG_CALIB3D_ACT_UNDISTORT - }; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void img_calib3d_act (class cv::Mat *imgptr, int action, void *data); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_calib3d.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_IMG_CALIB3D_HPP + # define VA_IMG_CALIB3D_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + /* openCV */ + #include + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Img_Calib3d_Action { + IMG_CALIB3D_ACT_FOO = 0x000000u, + + IMG_CALIB3D_ACT_CALIB3D = 0x000400u, + IMG_CALIB3D_ACT_CALIBRATE, + IMG_CALIB3D_ACT_UNDISTORT + }; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void img_calib3d_act (class cv::Mat *imgptr, int action, void *data); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* img_calib3d.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/inc/img_cv.hpp b/modules/image/inc/img_cv.hpp index 7412f46..61cb78a 100644 --- a/modules/image/inc/img_cv.hpp +++ b/modules/image/inc/img_cv.hpp @@ -1,71 +1,71 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_CV_H - # define VA_IMG_CV_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* packages ------------------------------------------------------------------*/ - #include - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_Cv_Action { - IMG_CV_ACT_FOO = 0x000000u, - - IMG_CV_ACT_CV = 0x000100u, - IMG_CV_ACT_PIXEL_GET, - IMG_CV_ACT_PIXEL_SET, - IMG_CV_ACT_SET_ROI, - IMG_CV_ACT_AND_2REF, - IMG_CV_ACT_NOT, - IMG_CV_ACT_OR_2REF, - IMG_CV_ACT_COMPONENT, - IMG_CV_ACT_DILATE, - IMG_CV_ACT_ERODE, - IMG_CV_ACT_SMOOTH, - IMG_CV_ACT_SOBEL, - IMG_CV_ACT_BORDER, - IMG_CV_ACT_MIRROR, - IMG_CV_ACT_ROTATE_ORTO, - IMG_CV_ACT_ROTATE, - IMG_CV_ACT_ADAPTIVE_THRESHOLD, - IMG_CV_ACT_CVT_COLOR, - IMG_CV_ACT_DISTANCE_TRANSFORM, - IMG_CV_ACT_THRESHOLD, - IMG_CV_ACT_HISTOGRAM, - IMG_CV_ACT_HISTOGRAM_C3, - IMG_CV_ACT_CONTOURS, - IMG_CV_ACT_CONTOURS_SIZE, - IMG_CV_ACT_BOUNDING_RECT, - IMG_CV_ACT_FIT_ELLIPSE, - IMG_CV_ACT_MIN_AREA_RECT, - IMG_CV_ACT_HOUGH_CIRCLES - }; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void img_cv_act (class cv::Mat *imgptr, int action, void *data); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_cv.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_IMG_CV_H + # define VA_IMG_CV_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* packages ------------------------------------------------------------------*/ + #include + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Img_Cv_Action { + IMG_CV_ACT_FOO = 0x000000u, + + IMG_CV_ACT_CV = 0x000100u, + IMG_CV_ACT_PIXEL_GET, + IMG_CV_ACT_PIXEL_SET, + IMG_CV_ACT_SET_ROI, + IMG_CV_ACT_AND_2REF, + IMG_CV_ACT_NOT, + IMG_CV_ACT_OR_2REF, + IMG_CV_ACT_COMPONENT, + IMG_CV_ACT_DILATE, + IMG_CV_ACT_ERODE, + IMG_CV_ACT_SMOOTH, + IMG_CV_ACT_SOBEL, + IMG_CV_ACT_BORDER, + IMG_CV_ACT_MIRROR, + IMG_CV_ACT_ROTATE_ORTO, + IMG_CV_ACT_ROTATE, + IMG_CV_ACT_ADAPTIVE_THRESHOLD, + IMG_CV_ACT_CVT_COLOR, + IMG_CV_ACT_DISTANCE_TRANSFORM, + IMG_CV_ACT_THRESHOLD, + IMG_CV_ACT_HISTOGRAM, + IMG_CV_ACT_HISTOGRAM_C3, + IMG_CV_ACT_CONTOURS, + IMG_CV_ACT_CONTOURS_SIZE, + IMG_CV_ACT_BOUNDING_RECT, + IMG_CV_ACT_FIT_ELLIPSE, + IMG_CV_ACT_MIN_AREA_RECT, + IMG_CV_ACT_HOUGH_CIRCLES + }; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void img_cv_act (class cv::Mat *imgptr, int action, void *data); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* img_cv.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/inc/img_iface.h b/modules/image/inc/img_iface.h index bfdbb70..460db47 100644 --- a/modules/image/inc/img_iface.h +++ b/modules/image/inc/img_iface.h @@ -1,187 +1,187 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_IFACE_H - # define VA_IMG_IFACE_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ -/* Constants -----------------------------------------------------------------*/ - # define CONTOURS_MAX (65536) - # define OCR_TEXT_MAX (1048576) - # define ZB_CODES_MAX (10) - # define ZBAR_LEN_MAX (1048576) - - # define IMG_IFACE_THR_OTSU (-1) - -/* Functions -----------------------------------------------------------------*/ - # define img_iface_act_nodata(x) \ - do { \ - img_iface_act(x, NULL); \ - } while (0) - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_Iface_Action { - IMG_IFACE_ACT_FOO = 0x000000u, - - IMG_IFACE_ACT_ALX = 0x000010u, - IMG_IFACE_ACT_LOCAL_MAX, - IMG_IFACE_ACT_SKELETON, - IMG_IFACE_ACT_LINES_HORIZONTAL, - IMG_IFACE_ACT_LINES_VERTICAL, - IMG_IFACE_ACT_MEAN_HORIZONTAL, - IMG_IFACE_ACT_MEAN_VERTICAL, - IMG_IFACE_ACT_MEDIAN_HORIZONTAL, - IMG_IFACE_ACT_MEDIAN_VERTICAL, - - IMG_IFACE_ACT_CV = 0x000100u, - IMG_IFACE_ACT_PIXEL_GET, - IMG_IFACE_ACT_PIXEL_SET, - IMG_IFACE_ACT_SET_ROI, - IMG_IFACE_ACT_SET_ROI_2RECT, - IMG_IFACE_ACT_AND_2REF, - IMG_IFACE_ACT_NOT, - IMG_IFACE_ACT_OR_2REF, - IMG_IFACE_ACT_COMPONENT, - IMG_IFACE_ACT_DILATE, - IMG_IFACE_ACT_ERODE, - IMG_IFACE_ACT_DILATE_ERODE, - IMG_IFACE_ACT_ERODE_DILATE, - IMG_IFACE_ACT_SMOOTH, - IMG_IFACE_ACT_SOBEL, - IMG_IFACE_ACT_BORDER, - IMG_IFACE_ACT_MIRROR, - IMG_IFACE_ACT_ROTATE_ORTO, - IMG_IFACE_ACT_ROTATE, - IMG_IFACE_ACT_ROTATE_2RECT, - IMG_IFACE_ACT_ADAPTIVE_THRESHOLD, - IMG_IFACE_ACT_CVT_COLOR, - IMG_IFACE_ACT_DISTANCE_TRANSFORM, - IMG_IFACE_ACT_THRESHOLD, - IMG_IFACE_ACT_HISTOGRAM, - IMG_IFACE_ACT_HISTOGRAM_C3, - IMG_IFACE_ACT_CONTOURS, - IMG_IFACE_ACT_CONTOURS_SIZE, - IMG_IFACE_ACT_BOUNDING_RECT, - IMG_IFACE_ACT_FIT_ELLIPSE, - IMG_IFACE_ACT_MIN_AREA_RECT, - IMG_IFACE_ACT_HOUGH_CIRCLES, - - IMG_IFACE_ACT_ORB = 0x000200u, - IMG_IFACE_ACT_ALIGN, - - IMG_IFACE_ACT_CALIB3D = 0x000400u, - IMG_IFACE_ACT_CALIBRATE, - IMG_IFACE_ACT_UNDISTORT, - - IMG_IFACE_ACT_ZB = 0x000800u, - IMG_IFACE_ACT_DECODE, - - IMG_IFACE_ACT_OCR = 0x001000u, - IMG_IFACE_ACT_READ, - - IMG_IFACE_ACT_IMGI = 0x002000u, - IMG_IFACE_ACT_APPLY, - IMG_IFACE_ACT_DISCARD, - IMG_IFACE_ACT_SAVE_MEM, - IMG_IFACE_ACT_LOAD_MEM, - IMG_IFACE_ACT_SAVE_REF, - - IMG_IFACE_ACT_SAVE = 0x004000u, - IMG_IFACE_ACT_SAVE_FILE, - IMG_IFACE_ACT_SAVE_UPDT - }; - - enum Img_Iface_Cmp_BGR { - IMG_IFACE_CMP_BLUE = 0, - IMG_IFACE_CMP_GREEN, - IMG_IFACE_CMP_RED - }; - - enum Img_Iface_Cmp_HSV { - IMG_IFACE_CMP_HUE = 0, - IMG_IFACE_CMP_SATURATION, - IMG_IFACE_CMP_VALUE - }; - - enum ImgI_Smooth { - IMGI_SMOOTH_MEAN = 0, - IMGI_SMOOTH_GAUSS, - IMGI_SMOOTH_MEDIAN - }; - - enum Img_Iface_OCR_Lang { - IMG_IFACE_OCR_LANG_ENG = 0, - IMG_IFACE_OCR_LANG_SPA, - IMG_IFACE_OCR_LANG_CAT, - IMG_IFACE_OCR_LANG_DIGITS, - IMG_IFACE_OCR_LANG_DIGITS_COMMA - }; - - enum Img_Iface_OCR_Conf { - IMG_IFACE_OCR_CONF_NONE = 0, - IMG_IFACE_OCR_CONF_PRICE - }; - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ - struct Img_Iface_Data_Read { - int lang; - int conf; - struct { - void *data; - int width; - int height; - int B_per_pix; - int B_per_line; - } img; - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - extern char img_ocr_text [OCR_TEXT_MAX]; - extern struct Img_Iface_ZB_Codes zb_codes; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void img_iface_cleanup_main (void); - void img_iface_load (const char *fpath, const char *fname); - void img_iface_cleanup (void); - void img_iface_act (int action, void *data); - void img_iface_show_img (void); - void img_iface_show_hist_c1 (void); - void img_iface_show_hist_c3 (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_iface.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_IMG_IFACE_H + # define VA_IMG_IFACE_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + #include + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +/* Constants -----------------------------------------------------------------*/ + # define CONTOURS_MAX (65536) + # define OCR_TEXT_MAX (1048576) + # define ZB_CODES_MAX (10) + # define ZBAR_LEN_MAX (1048576) + + # define IMG_IFACE_THR_OTSU (-1) + +/* Functions -----------------------------------------------------------------*/ + # define img_iface_act_nodata(x) \ + do { \ + img_iface_act(x, NULL); \ + } while (0) + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Img_Iface_Action { + IMG_IFACE_ACT_FOO = 0x000000u, + + IMG_IFACE_ACT_ALX = 0x000010u, + IMG_IFACE_ACT_LOCAL_MAX, + IMG_IFACE_ACT_SKELETON, + IMG_IFACE_ACT_LINES_HORIZONTAL, + IMG_IFACE_ACT_LINES_VERTICAL, + IMG_IFACE_ACT_MEAN_HORIZONTAL, + IMG_IFACE_ACT_MEAN_VERTICAL, + IMG_IFACE_ACT_MEDIAN_HORIZONTAL, + IMG_IFACE_ACT_MEDIAN_VERTICAL, + + IMG_IFACE_ACT_CV = 0x000100u, + IMG_IFACE_ACT_PIXEL_GET, + IMG_IFACE_ACT_PIXEL_SET, + IMG_IFACE_ACT_SET_ROI, + IMG_IFACE_ACT_SET_ROI_2RECT, + IMG_IFACE_ACT_AND_2REF, + IMG_IFACE_ACT_NOT, + IMG_IFACE_ACT_OR_2REF, + IMG_IFACE_ACT_COMPONENT, + IMG_IFACE_ACT_DILATE, + IMG_IFACE_ACT_ERODE, + IMG_IFACE_ACT_DILATE_ERODE, + IMG_IFACE_ACT_ERODE_DILATE, + IMG_IFACE_ACT_SMOOTH, + IMG_IFACE_ACT_SOBEL, + IMG_IFACE_ACT_BORDER, + IMG_IFACE_ACT_MIRROR, + IMG_IFACE_ACT_ROTATE_ORTO, + IMG_IFACE_ACT_ROTATE, + IMG_IFACE_ACT_ROTATE_2RECT, + IMG_IFACE_ACT_ADAPTIVE_THRESHOLD, + IMG_IFACE_ACT_CVT_COLOR, + IMG_IFACE_ACT_DISTANCE_TRANSFORM, + IMG_IFACE_ACT_THRESHOLD, + IMG_IFACE_ACT_HISTOGRAM, + IMG_IFACE_ACT_HISTOGRAM_C3, + IMG_IFACE_ACT_CONTOURS, + IMG_IFACE_ACT_CONTOURS_SIZE, + IMG_IFACE_ACT_BOUNDING_RECT, + IMG_IFACE_ACT_FIT_ELLIPSE, + IMG_IFACE_ACT_MIN_AREA_RECT, + IMG_IFACE_ACT_HOUGH_CIRCLES, + + IMG_IFACE_ACT_ORB = 0x000200u, + IMG_IFACE_ACT_ALIGN, + + IMG_IFACE_ACT_CALIB3D = 0x000400u, + IMG_IFACE_ACT_CALIBRATE, + IMG_IFACE_ACT_UNDISTORT, + + IMG_IFACE_ACT_ZB = 0x000800u, + IMG_IFACE_ACT_DECODE, + + IMG_IFACE_ACT_OCR = 0x001000u, + IMG_IFACE_ACT_READ, + + IMG_IFACE_ACT_IMGI = 0x002000u, + IMG_IFACE_ACT_APPLY, + IMG_IFACE_ACT_DISCARD, + IMG_IFACE_ACT_SAVE_MEM, + IMG_IFACE_ACT_LOAD_MEM, + IMG_IFACE_ACT_SAVE_REF, + + IMG_IFACE_ACT_SAVE = 0x004000u, + IMG_IFACE_ACT_SAVE_FILE, + IMG_IFACE_ACT_SAVE_UPDT + }; + + enum Img_Iface_Cmp_BGR { + IMG_IFACE_CMP_BLUE = 0, + IMG_IFACE_CMP_GREEN, + IMG_IFACE_CMP_RED + }; + + enum Img_Iface_Cmp_HSV { + IMG_IFACE_CMP_HUE = 0, + IMG_IFACE_CMP_SATURATION, + IMG_IFACE_CMP_VALUE + }; + + enum ImgI_Smooth { + IMGI_SMOOTH_MEAN = 0, + IMGI_SMOOTH_GAUSS, + IMGI_SMOOTH_MEDIAN + }; + + enum Img_Iface_OCR_Lang { + IMG_IFACE_OCR_LANG_ENG = 0, + IMG_IFACE_OCR_LANG_SPA, + IMG_IFACE_OCR_LANG_CAT, + IMG_IFACE_OCR_LANG_DIGITS, + IMG_IFACE_OCR_LANG_DIGITS_COMMA + }; + + enum Img_Iface_OCR_Conf { + IMG_IFACE_OCR_CONF_NONE = 0, + IMG_IFACE_OCR_CONF_PRICE + }; + + +/****************************************************************************** + ******* structs ************************************************************** + ******************************************************************************/ + struct Img_Iface_Data_Read { + int lang; + int conf; + struct { + void *data; + int width; + int height; + int B_per_pix; + int B_per_line; + } img; + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern char img_ocr_text [OCR_TEXT_MAX]; + extern struct Img_Iface_ZB_Codes zb_codes; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void img_iface_cleanup_main (void); + void img_iface_load (const char *fpath, const char *fname); + void img_iface_cleanup (void); + void img_iface_act (int action, void *data); + void img_iface_show_img (void); + void img_iface_show_hist_c1 (void); + void img_iface_show_hist_c3 (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* img_iface.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/inc/img_iface.hpp b/modules/image/inc/img_iface.hpp index c492537..6448578 100644 --- a/modules/image/inc/img_iface.hpp +++ b/modules/image/inc/img_iface.hpp @@ -1,343 +1,343 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_IFACE_HPP - # define VA_IMG_IFACE_HPP - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include - -/* Standard C++ --------------------------------------------------------------*/ - /* class std::vector */ - #include - -/* Packages ------------------------------------------------------------------*/ - /* opencv */ - #include - /* zbar */ - #include - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define CONTOURS_MAX (65536) - # define OCR_TEXT_MAX (1048576) - # define ZB_CODES_MAX (10) - # define ZBAR_LEN_MAX (1048576) - - # define IMG_IFACE_THR_OTSU (-1) - -/* Functions -----------------------------------------------------------------*/ - # define img_iface_act_nodata(x) \ - do { \ - img_iface_act(x, NULL); \ - } while (0) - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_Iface_Action { - IMG_IFACE_ACT_FOO = 0x000000u, - - IMG_IFACE_ACT_ALX = 0x000010u, - IMG_IFACE_ACT_LOCAL_MAX, - IMG_IFACE_ACT_SKELETON, - IMG_IFACE_ACT_LINES_HORIZONTAL, - IMG_IFACE_ACT_LINES_VERTICAL, - IMG_IFACE_ACT_MEAN_HORIZONTAL, - IMG_IFACE_ACT_MEAN_VERTICAL, - IMG_IFACE_ACT_MEDIAN_HORIZONTAL, - IMG_IFACE_ACT_MEDIAN_VERTICAL, - - IMG_IFACE_ACT_CV = 0x000100u, - IMG_IFACE_ACT_PIXEL_GET, - IMG_IFACE_ACT_PIXEL_SET, - IMG_IFACE_ACT_SET_ROI, - IMG_IFACE_ACT_SET_ROI_2RECT, - IMG_IFACE_ACT_AND_2REF, - IMG_IFACE_ACT_NOT, - IMG_IFACE_ACT_OR_2REF, - IMG_IFACE_ACT_COMPONENT, - IMG_IFACE_ACT_DILATE, - IMG_IFACE_ACT_ERODE, - IMG_IFACE_ACT_DILATE_ERODE, - IMG_IFACE_ACT_ERODE_DILATE, - IMG_IFACE_ACT_SMOOTH, - IMG_IFACE_ACT_SOBEL, - IMG_IFACE_ACT_BORDER, - IMG_IFACE_ACT_MIRROR, - IMG_IFACE_ACT_ROTATE_ORTO, - IMG_IFACE_ACT_ROTATE, - IMG_IFACE_ACT_ROTATE_2RECT, - IMG_IFACE_ACT_ADAPTIVE_THRESHOLD, - IMG_IFACE_ACT_CVT_COLOR, - IMG_IFACE_ACT_DISTANCE_TRANSFORM, - IMG_IFACE_ACT_THRESHOLD, - IMG_IFACE_ACT_HISTOGRAM, - IMG_IFACE_ACT_HISTOGRAM_C3, - IMG_IFACE_ACT_CONTOURS, - IMG_IFACE_ACT_CONTOURS_SIZE, - IMG_IFACE_ACT_BOUNDING_RECT, - IMG_IFACE_ACT_FIT_ELLIPSE, - IMG_IFACE_ACT_MIN_AREA_RECT, - IMG_IFACE_ACT_HOUGH_CIRCLES, - - IMG_IFACE_ACT_ORB = 0x000200u, - IMG_IFACE_ACT_ALIGN, - - IMG_IFACE_ACT_CALIB3D = 0x000400u, - IMG_IFACE_ACT_CALIBRATE, - IMG_IFACE_ACT_UNDISTORT, - - IMG_IFACE_ACT_ZB = 0x000800u, - IMG_IFACE_ACT_DECODE, - - IMG_IFACE_ACT_OCR = 0x001000u, - IMG_IFACE_ACT_READ, - - IMG_IFACE_ACT_IMGI = 0x002000u, - IMG_IFACE_ACT_APPLY, - IMG_IFACE_ACT_DISCARD, - IMG_IFACE_ACT_SAVE_MEM, - IMG_IFACE_ACT_LOAD_MEM, - IMG_IFACE_ACT_SAVE_REF, - - IMG_IFACE_ACT_SAVE = 0x004000u, - IMG_IFACE_ACT_SAVE_FILE, - IMG_IFACE_ACT_SAVE_UPDT - }; - - enum Img_Iface_Cmp { - IMG_IFACE_CMP_BLUE = 0, - IMG_IFACE_CMP_GREEN, - IMG_IFACE_CMP_RED - }; - - enum Img_Iface_Cmp_HSV { - IMG_IFACE_CMP_HUE = 0, - IMG_IFACE_CMP_SATURATION, - IMG_IFACE_CMP_VALUE - }; - - enum ImgI_Smooth { - IMGI_SMOOTH_MEAN = 1, - IMGI_SMOOTH_GAUSS, - IMGI_SMOOTH_MEDIAN - }; - - enum Img_Iface_OCR_Lang { - IMG_IFACE_OCR_LANG_ENG = 0, - IMG_IFACE_OCR_LANG_SPA, - IMG_IFACE_OCR_LANG_CAT, - IMG_IFACE_OCR_LANG_DIGITS, - IMG_IFACE_OCR_LANG_DIGITS_COMMA - }; - - enum Img_Iface_OCR_Conf { - IMG_IFACE_OCR_CONF_NONE = 0, - IMG_IFACE_OCR_CONF_PRICE - }; - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ -/* img_cv --------------------------------------------------------------------*/ - struct Img_Iface_Data_Pixel_Get { - unsigned char *val; - int x; - int y; - }; - - struct Img_Iface_Data_Pixel_Set { - unsigned char val; - int x; - int y; - }; - - struct Img_Iface_Data_SetROI { - class cv::Rect_ rect; - }; - - struct Img_Iface_Data_Component { - int cmp; - }; - - struct Img_Iface_Data_Dilate_Erode { - int i; - }; - - struct Img_Iface_Data_Smooth { - int method; - int ksize; - }; - - struct Img_Iface_Data_Sobel { - int dx; - int dy; - int ksize; - }; - - struct Img_Iface_Data_Border { - int size; - }; - - struct Img_Iface_Data_Mirror { - int axis; - }; - - struct Img_Iface_Data_Rotate_Orto { - int n; - }; - - struct Img_Iface_Data_Rotate { - class cv::Point_ center; - double angle; - }; - - struct Img_Iface_Data_Adaptive_Thr { - int method; - int thr_typ; - int ksize; - }; - - struct Img_Iface_Data_Cvt_Color { - int method; - }; - - struct Img_Iface_Data_Threshold { - int thr_typ; - int thr_val; - }; - - struct Img_Iface_Data_Histogram { - class cv::Mat *hist_c0; - class cv::Mat *hist_c1; - class cv::Mat *hist_c2; - class cv::Mat *hist_img; - }; - - struct Img_Iface_Data_Contours { - class std::vector >> *contours; - class cv::Mat *hierarchy; - }; - - struct Img_Iface_Data_Contours_Size { - class std::vector >> *contours; - double *area; - double *perimeter; - }; - - struct Img_Iface_Data_Bounding_Rect { - class std::vector > *contour; - class cv::Rect_ *rect; - bool show; - }; - - struct Img_Iface_Data_MinARect { - class std::vector > *contour; - class cv::RotatedRect *rect; - bool show; - }; - - struct Img_Iface_Data_Hough_Circles { - class std::vector > *circles; - double dist_min; - double param_1; - double param_2; - int radius_min; - int radius_max; - }; - -/* img_calib3d ---------------------------------------------------------------*/ - struct Img_Iface_Data_Calibrate { - class cv::Mat *intrinsic_mat; - class cv::Mat *dist_coefs; - class std::vector *rvecs; - class std::vector *tvecs; - }; - - struct Img_Iface_Data_Undistort { - class cv::Mat *intrinsic_mat; - class cv::Mat *dist_coefs; - }; - -/* img_zbar -------------------------------------------------------------------*/ - struct Img_Iface_Data_Decode { - enum zbar::zbar_symbol_type_e code_type; - }; - - struct Img_Iface_ZB_Codes { - int n; - struct { - enum zbar::zbar_symbol_type_e type; - char sym_name [80]; - char data [ZBAR_LEN_MAX]; - } arr [ZB_CODES_MAX]; - }; - -/* img_ocr -------------------------------------------------------------------*/ - struct Img_Iface_Data_Read { - int lang; - int conf; - struct { - void *data; - int width; - int height; - int B_per_pix; - int B_per_line; - } img; - }; - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - extern char img_ocr_text [OCR_TEXT_MAX]; - extern struct Img_Iface_ZB_Codes zb_codes; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void img_iface_cleanup_main (void); - void img_iface_load (const char *fpath, const char *fname); - void img_iface_cleanup (void); - void img_iface_act (int action, void *data); - void img_iface_show_img (void); - void img_iface_show_hist_c1 (void); - void img_iface_show_hist_c3 (void); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_iface.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_IMG_IFACE_HPP + # define VA_IMG_IFACE_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + #include + +/* Standard C++ --------------------------------------------------------------*/ + /* class std::vector */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* opencv */ + #include + /* zbar */ + #include + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define CONTOURS_MAX (65536) + # define OCR_TEXT_MAX (1048576) + # define ZB_CODES_MAX (10) + # define ZBAR_LEN_MAX (1048576) + + # define IMG_IFACE_THR_OTSU (-1) + +/* Functions -----------------------------------------------------------------*/ + # define img_iface_act_nodata(x) \ + do { \ + img_iface_act(x, NULL); \ + } while (0) + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Img_Iface_Action { + IMG_IFACE_ACT_FOO = 0x000000u, + + IMG_IFACE_ACT_ALX = 0x000010u, + IMG_IFACE_ACT_LOCAL_MAX, + IMG_IFACE_ACT_SKELETON, + IMG_IFACE_ACT_LINES_HORIZONTAL, + IMG_IFACE_ACT_LINES_VERTICAL, + IMG_IFACE_ACT_MEAN_HORIZONTAL, + IMG_IFACE_ACT_MEAN_VERTICAL, + IMG_IFACE_ACT_MEDIAN_HORIZONTAL, + IMG_IFACE_ACT_MEDIAN_VERTICAL, + + IMG_IFACE_ACT_CV = 0x000100u, + IMG_IFACE_ACT_PIXEL_GET, + IMG_IFACE_ACT_PIXEL_SET, + IMG_IFACE_ACT_SET_ROI, + IMG_IFACE_ACT_SET_ROI_2RECT, + IMG_IFACE_ACT_AND_2REF, + IMG_IFACE_ACT_NOT, + IMG_IFACE_ACT_OR_2REF, + IMG_IFACE_ACT_COMPONENT, + IMG_IFACE_ACT_DILATE, + IMG_IFACE_ACT_ERODE, + IMG_IFACE_ACT_DILATE_ERODE, + IMG_IFACE_ACT_ERODE_DILATE, + IMG_IFACE_ACT_SMOOTH, + IMG_IFACE_ACT_SOBEL, + IMG_IFACE_ACT_BORDER, + IMG_IFACE_ACT_MIRROR, + IMG_IFACE_ACT_ROTATE_ORTO, + IMG_IFACE_ACT_ROTATE, + IMG_IFACE_ACT_ROTATE_2RECT, + IMG_IFACE_ACT_ADAPTIVE_THRESHOLD, + IMG_IFACE_ACT_CVT_COLOR, + IMG_IFACE_ACT_DISTANCE_TRANSFORM, + IMG_IFACE_ACT_THRESHOLD, + IMG_IFACE_ACT_HISTOGRAM, + IMG_IFACE_ACT_HISTOGRAM_C3, + IMG_IFACE_ACT_CONTOURS, + IMG_IFACE_ACT_CONTOURS_SIZE, + IMG_IFACE_ACT_BOUNDING_RECT, + IMG_IFACE_ACT_FIT_ELLIPSE, + IMG_IFACE_ACT_MIN_AREA_RECT, + IMG_IFACE_ACT_HOUGH_CIRCLES, + + IMG_IFACE_ACT_ORB = 0x000200u, + IMG_IFACE_ACT_ALIGN, + + IMG_IFACE_ACT_CALIB3D = 0x000400u, + IMG_IFACE_ACT_CALIBRATE, + IMG_IFACE_ACT_UNDISTORT, + + IMG_IFACE_ACT_ZB = 0x000800u, + IMG_IFACE_ACT_DECODE, + + IMG_IFACE_ACT_OCR = 0x001000u, + IMG_IFACE_ACT_READ, + + IMG_IFACE_ACT_IMGI = 0x002000u, + IMG_IFACE_ACT_APPLY, + IMG_IFACE_ACT_DISCARD, + IMG_IFACE_ACT_SAVE_MEM, + IMG_IFACE_ACT_LOAD_MEM, + IMG_IFACE_ACT_SAVE_REF, + + IMG_IFACE_ACT_SAVE = 0x004000u, + IMG_IFACE_ACT_SAVE_FILE, + IMG_IFACE_ACT_SAVE_UPDT + }; + + enum Img_Iface_Cmp { + IMG_IFACE_CMP_BLUE = 0, + IMG_IFACE_CMP_GREEN, + IMG_IFACE_CMP_RED + }; + + enum Img_Iface_Cmp_HSV { + IMG_IFACE_CMP_HUE = 0, + IMG_IFACE_CMP_SATURATION, + IMG_IFACE_CMP_VALUE + }; + + enum ImgI_Smooth { + IMGI_SMOOTH_MEAN = 1, + IMGI_SMOOTH_GAUSS, + IMGI_SMOOTH_MEDIAN + }; + + enum Img_Iface_OCR_Lang { + IMG_IFACE_OCR_LANG_ENG = 0, + IMG_IFACE_OCR_LANG_SPA, + IMG_IFACE_OCR_LANG_CAT, + IMG_IFACE_OCR_LANG_DIGITS, + IMG_IFACE_OCR_LANG_DIGITS_COMMA + }; + + enum Img_Iface_OCR_Conf { + IMG_IFACE_OCR_CONF_NONE = 0, + IMG_IFACE_OCR_CONF_PRICE + }; + + +/****************************************************************************** + ******* structs ************************************************************** + ******************************************************************************/ +/* img_cv --------------------------------------------------------------------*/ + struct Img_Iface_Data_Pixel_Get { + unsigned char *val; + int x; + int y; + }; + + struct Img_Iface_Data_Pixel_Set { + unsigned char val; + int x; + int y; + }; + + struct Img_Iface_Data_SetROI { + class cv::Rect_ rect; + }; + + struct Img_Iface_Data_Component { + int cmp; + }; + + struct Img_Iface_Data_Dilate_Erode { + int i; + }; + + struct Img_Iface_Data_Smooth { + int method; + int ksize; + }; + + struct Img_Iface_Data_Sobel { + int dx; + int dy; + int ksize; + }; + + struct Img_Iface_Data_Border { + int size; + }; + + struct Img_Iface_Data_Mirror { + int axis; + }; + + struct Img_Iface_Data_Rotate_Orto { + int n; + }; + + struct Img_Iface_Data_Rotate { + class cv::Point_ center; + double angle; + }; + + struct Img_Iface_Data_Adaptive_Thr { + int method; + int thr_typ; + int ksize; + }; + + struct Img_Iface_Data_Cvt_Color { + int method; + }; + + struct Img_Iface_Data_Threshold { + int thr_typ; + int thr_val; + }; + + struct Img_Iface_Data_Histogram { + class cv::Mat *hist_c0; + class cv::Mat *hist_c1; + class cv::Mat *hist_c2; + class cv::Mat *hist_img; + }; + + struct Img_Iface_Data_Contours { + class std::vector >> *contours; + class cv::Mat *hierarchy; + }; + + struct Img_Iface_Data_Contours_Size { + class std::vector >> *contours; + double *area; + double *perimeter; + }; + + struct Img_Iface_Data_Bounding_Rect { + class std::vector > *contour; + class cv::Rect_ *rect; + bool show; + }; + + struct Img_Iface_Data_MinARect { + class std::vector > *contour; + class cv::RotatedRect *rect; + bool show; + }; + + struct Img_Iface_Data_Hough_Circles { + class std::vector > *circles; + double dist_min; + double param_1; + double param_2; + int radius_min; + int radius_max; + }; + +/* img_calib3d ---------------------------------------------------------------*/ + struct Img_Iface_Data_Calibrate { + class cv::Mat *intrinsic_mat; + class cv::Mat *dist_coefs; + class std::vector *rvecs; + class std::vector *tvecs; + }; + + struct Img_Iface_Data_Undistort { + class cv::Mat *intrinsic_mat; + class cv::Mat *dist_coefs; + }; + +/* img_zbar -------------------------------------------------------------------*/ + struct Img_Iface_Data_Decode { + enum zbar::zbar_symbol_type_e code_type; + }; + + struct Img_Iface_ZB_Codes { + int n; + struct { + enum zbar::zbar_symbol_type_e type; + char sym_name [80]; + char data [ZBAR_LEN_MAX]; + } arr [ZB_CODES_MAX]; + }; + +/* img_ocr -------------------------------------------------------------------*/ + struct Img_Iface_Data_Read { + int lang; + int conf; + struct { + void *data; + int width; + int height; + int B_per_pix; + int B_per_line; + } img; + }; + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern char img_ocr_text [OCR_TEXT_MAX]; + extern struct Img_Iface_ZB_Codes zb_codes; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void img_iface_cleanup_main (void); + void img_iface_load (const char *fpath, const char *fname); + void img_iface_cleanup (void); + void img_iface_act (int action, void *data); + void img_iface_show_img (void); + void img_iface_show_hist_c1 (void); + void img_iface_show_hist_c3 (void); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* img_iface.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/inc/img_ocr.h b/modules/image/inc/img_ocr.h index f2e8742..62d248a 100644 --- a/modules/image/inc/img_ocr.h +++ b/modules/image/inc/img_ocr.h @@ -1,38 +1,38 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_OCR_H - # define VA_IMG_OCR_H - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_OCR_Action { - IMG_OCR_ACT_FOO = 0x000000u, - - IMG_OCR_ACT_OCR = 0x001000u, - IMG_OCR_ACT_READ - }; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void img_ocr_act (int action, void *data); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_ocr.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_IMG_OCR_H + # define VA_IMG_OCR_H + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Img_OCR_Action { + IMG_OCR_ACT_FOO = 0x000000u, + + IMG_OCR_ACT_OCR = 0x001000u, + IMG_OCR_ACT_READ + }; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void img_ocr_act (int action, void *data); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* img_ocr.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/inc/img_ocr.hpp b/modules/image/inc/img_ocr.hpp index 446f986..355a124 100644 --- a/modules/image/inc/img_ocr.hpp +++ b/modules/image/inc/img_ocr.hpp @@ -1,50 +1,50 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_OCR_HPP - # define VA_IMG_OCR_HPP - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_OCR_Action { - IMG_OCR_ACT_FOO = 0x000000u, - - IMG_OCR_ACT_OCR = 0x001000u, - IMG_OCR_ACT_READ - }; - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void img_ocr_act (int action, void *data); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_ocr.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_IMG_OCR_HPP + # define VA_IMG_OCR_HPP + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Img_OCR_Action { + IMG_OCR_ACT_FOO = 0x000000u, + + IMG_OCR_ACT_OCR = 0x001000u, + IMG_OCR_ACT_READ + }; + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void img_ocr_act (int action, void *data); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* img_ocr.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/inc/img_orb.hpp b/modules/image/inc/img_orb.hpp index b29fefa..ce5a914 100644 --- a/modules/image/inc/img_orb.hpp +++ b/modules/image/inc/img_orb.hpp @@ -1,46 +1,46 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_ORB_HPP - # define VA_IMG_ORB_HPP - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - /* openCV */ - #include - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_ORB_Action { - IMG_ORB_ACT_FOO = 0x000000u, - - IMG_ORB_ACT_ORB = 0x000200u, - IMG_ORB_ACT_ALIGN - }; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void img_orb_act (class cv::Mat *pattern, - class cv::Mat *imgptr, int action); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_orb.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_IMG_ORB_HPP + # define VA_IMG_ORB_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + /* openCV */ + #include + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Img_ORB_Action { + IMG_ORB_ACT_FOO = 0x000000u, + + IMG_ORB_ACT_ORB = 0x000200u, + IMG_ORB_ACT_ALIGN + }; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void img_orb_act (class cv::Mat *pattern, + class cv::Mat *imgptr, int action); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* img_orb.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/inc/img_zbar.hpp b/modules/image/inc/img_zbar.hpp index 2019ae3..72f1020 100644 --- a/modules/image/inc/img_zbar.hpp +++ b/modules/image/inc/img_zbar.hpp @@ -1,46 +1,46 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_ZBAR_H - # define VA_IMG_ZBAR_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Packages ------------------------------------------------------------------*/ - /* openCV */ - #include - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_ZB_Action { - IMG_ZB_ACT_FOO = 0x000000u, - - IMG_ZB_ACT_ZB = 0x000800u, - IMG_ZB_ACT_DECODE - }; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void img_zb_act (class cv::Mat *imgptr, int action, void *data); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_zbar.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_IMG_ZBAR_H + # define VA_IMG_ZBAR_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Packages ------------------------------------------------------------------*/ + /* openCV */ + #include + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Img_ZB_Action { + IMG_ZB_ACT_FOO = 0x000000u, + + IMG_ZB_ACT_ZB = 0x000800u, + IMG_ZB_ACT_DECODE + }; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void img_zb_act (class cv::Mat *imgptr, int action, void *data); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* img_zbar.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/src/img_alx.cpp b/modules/image/src/img_alx.cpp index b4db8ee..7a3662e 100644 --- a/modules/image/src/img_alx.cpp +++ b/modules/image/src/img_alx.cpp @@ -1,379 +1,379 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: (GPL-2.0-only OR LGPL-3.0-only) * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* true & false */ - #include - /* abs() */ - #include - /* snprintf() */ - #include - -/* Packages ------------------------------------------------------------------*/ - /* opencv */ - #include - -/* libalx --------------------------------------------------------------------*/ - /* alx_median_u8() */ - #include "alx_math.hpp" - -/* Module --------------------------------------------------------------------*/ - /* data */ - #include "img_iface.hpp" - - #include "img_alx.hpp" - - -/****************************************************************************** - ******* static functions (prototypes) **************************************** - ******************************************************************************/ -static void img_alx_local_max (class cv::Mat *imgptr); -static void img_alx_skeleton (class cv::Mat *imgptr); -static void img_alx_lines_horizontal (class cv::Mat *imgptr); -static void img_alx_lines_vertical (class cv::Mat *imgptr); -static void img_alx_mean_horizontal (class cv::Mat *imgptr); -static void img_alx_mean_vertical (class cv::Mat *imgptr); -static void img_alx_median_horizontal (class cv::Mat *imgptr); -static void img_alx_median_vertical (class cv::Mat *imgptr); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -void img_alx_act (class cv::Mat *imgptr, int action, void *data) -{ - - switch (action) { - case IMG_ALX_ACT_LOCAL_MAX: - img_alx_local_max(imgptr); - break; - case IMG_ALX_ACT_SKELETON: - img_alx_skeleton(imgptr); - break; - - case IMG_ALX_ACT_LINES_HORIZONTAL: - img_alx_lines_horizontal(imgptr); - break; - case IMG_ALX_ACT_LINES_VERTICAL: - img_alx_lines_vertical(imgptr); - break; - - case IMG_ALX_ACT_MEAN_HORIZONTAL: - img_alx_mean_horizontal(imgptr); - break; - case IMG_ALX_ACT_MEAN_VERTICAL: - img_alx_mean_vertical(imgptr); - break; - case IMG_ALX_ACT_MEDIAN_HORIZONTAL: - img_alx_median_horizontal(imgptr); - break; - case IMG_ALX_ACT_MEDIAN_VERTICAL: - img_alx_median_vertical(imgptr); - break; - } -} - - -/****************************************************************************** - ******* static functions (definitions) *************************************** - ******************************************************************************/ -static void img_alx_local_max (class cv::Mat *imgptr) -{ - int i; - int j; - int k; - int l; - /* Minimum distance between local maxima */ - const int dist_min = 16; - /* Minimum value of local maxima */ - const int val_min = 16; - class cv::Mat imgtmp; - - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - /* pointer to a pixel near img_pix (in imgptr) */ - uint8_t *near_pix; - /* pointer to a pixel (same position as img_pix, but in imgtmp) */ - uint8_t *tmp_pix; - - /* Tmp image copy */ - imgptr->copyTo(imgtmp); - - for (i = 0; i < imgptr->rows; i++) { - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - tmp_pix = imgtmp.data + i * imgptr->step + j; - - if (*img_pix < val_min) { - goto next_pixel; - } - - for (k = (i - dist_min); k < (i + dist_min + 1); k++) { - for (l = (j - dist_min); l < (j + dist_min + 1); l++) { - near_pix = imgptr->data + k * imgptr->step + l; - if ((k >= 0) && (k < imgptr->rows)) { - if ((l >= 0) && (l < imgptr->cols)) { - if (*img_pix < *near_pix) { - goto next_pixel; - } - } - } - } - } - - *tmp_pix = *img_pix; - continue; - -next_pixel: - *tmp_pix = 0; - } - } - - /* Cleanup */ - imgtmp.copyTo(*imgptr); - imgtmp.release(); -} - -static void img_alx_skeleton (class cv::Mat *imgptr) -{ - /* (Half of the) width of the skeleton */ - const int width = 5; - int dist_x; - int dist_y; - bool skeleton; - int cnt_lo [width]; - int cnt_hi_or_eq [width]; - class cv::Mat imgtmp; - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - /* pointer to a pixel near img_pix (in imgptr) */ - uint8_t *near_pix; - /* pointer to a pixel (same position as img_pix, but in imgtmp) */ - uint8_t *tmp_pix; - - int i; - int j; - int k; - int l; - int r; - - /* Tmp image copy */ - imgptr->copyTo(imgtmp); - - for (i = 0; i < imgptr->rows; i++) { - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - tmp_pix = imgtmp.data + i * imgptr->step + j; - - if (!(*img_pix)) { - *tmp_pix = 0; - continue; - } - - for (r = 0; r < width; r++) { - cnt_lo[r] = 0; - cnt_hi_or_eq[r] = 0; - } - - for (k = i - width; k <= i + width; k++) { - for (l = j - width; l <= j + width; l++) { - near_pix = imgptr->data + k * imgptr->step + l; - - dist_x = abs(k - i); - dist_y = abs(l - j); - - if ((k >= 0) && (k < imgptr->rows)) { - if ((l >= 0) && (l < imgptr->cols)) { - if (dist_x || dist_y) { - if (*near_pix < *img_pix) { - cnt_lo[std::max(dist_x, dist_y)]++; - } else { - cnt_hi_or_eq[std::max(dist_x, dist_y)]++; - } - } - } - } - - } - } - - skeleton = false; - for (r = 0; r < width; r++) { - if (cnt_lo[r] > (cnt_hi_or_eq[r] + (1.6) * (r + 1))) { - skeleton = true; - } - } - - if (skeleton) { - *tmp_pix = *img_pix; - } else { - *tmp_pix = 0; - } - } - } - - /* Cleanup */ - imgtmp.copyTo(*imgptr); - imgtmp.release(); -} - -static void img_alx_lines_horizontal (class cv::Mat *imgptr) -{ - int i; - int j; - bool white; - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - - for (i = 0; i < imgptr->rows; i++) { - white = false; - - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - if (*img_pix) { - white = true; - break; - } - } - - if (white) { - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - *img_pix = 255; - } - } - } -} - -static void img_alx_lines_vertical (class cv::Mat *imgptr) -{ - int i; - int j; - bool white; - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - - for (i = 0; i < imgptr->cols; i++) { - white = false; - - for (j = 0; j < imgptr->rows; j++) { - img_pix = imgptr->data + j * imgptr->step + i; - if (*img_pix) { - white = true; - break; - } - } - - if (white) { - for (j = 0; j < imgptr->rows; j++) { - img_pix = imgptr->data + j * imgptr->step + i; - *img_pix = 255; - } - } - } -} - -static void img_alx_mean_horizontal (class cv::Mat *imgptr) -{ - int i; - int j; - uint32_t tmp; - uint8_t mean; - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - - for (i = 0; i < imgptr->rows; i++) { - tmp = 0; - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - tmp += *img_pix; - } - mean = tmp / imgptr->cols; - - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - *img_pix = mean; - } - } -} - -static void img_alx_mean_vertical (class cv::Mat *imgptr) -{ - int i; - int j; - uint32_t tmp; - uint8_t mean; - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - - for (i = 0; i < imgptr->cols; i++) { - tmp = 0; - for (j = 0; j < imgptr->rows; j++) { - img_pix = imgptr->data + j * imgptr->step + i; - tmp += *img_pix; - } - mean = tmp / imgptr->rows; - - for (j = 0; j < imgptr->rows; j++) { - img_pix = imgptr->data + j * imgptr->step + i; - *img_pix = mean; - } - } -} - -static void img_alx_median_horizontal (class cv::Mat *imgptr) -{ - int i; - int j; - uint8_t row [imgptr->cols]; - uint8_t median; - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - - for (i = 0; i < imgptr->rows; i++) { - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - row[j] = *img_pix; - } - median = alx_median_u8(imgptr->cols, row); - - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - *img_pix = median; - } - } -} - -static void img_alx_median_vertical (class cv::Mat *imgptr) -{ - int i; - int j; - uint8_t col [imgptr->rows]; - uint8_t median; - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - - for (i = 0; i < imgptr->cols; i++) { - for (j = 0; j < imgptr->rows; j++) { - img_pix = imgptr->data + j * imgptr->step + i; - col[j] = *img_pix; - } - median = alx_median_u8(imgptr->rows, col); - - for (j = 0; j < imgptr->rows; j++) { - img_pix = imgptr->data + j * imgptr->step + i; - *img_pix = median; - } - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: (GPL-2.0-only OR LGPL-3.0-only) * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* true & false */ + #include + /* abs() */ + #include + /* snprintf() */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* opencv */ + #include + +/* libalx --------------------------------------------------------------------*/ + /* alx_median_u8() */ + #include "alx_math.hpp" + +/* Module --------------------------------------------------------------------*/ + /* data */ + #include "img_iface.hpp" + + #include "img_alx.hpp" + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ +static void img_alx_local_max (class cv::Mat *imgptr); +static void img_alx_skeleton (class cv::Mat *imgptr); +static void img_alx_lines_horizontal (class cv::Mat *imgptr); +static void img_alx_lines_vertical (class cv::Mat *imgptr); +static void img_alx_mean_horizontal (class cv::Mat *imgptr); +static void img_alx_mean_vertical (class cv::Mat *imgptr); +static void img_alx_median_horizontal (class cv::Mat *imgptr); +static void img_alx_median_vertical (class cv::Mat *imgptr); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void img_alx_act (class cv::Mat *imgptr, int action, void *data) +{ + + switch (action) { + case IMG_ALX_ACT_LOCAL_MAX: + img_alx_local_max(imgptr); + break; + case IMG_ALX_ACT_SKELETON: + img_alx_skeleton(imgptr); + break; + + case IMG_ALX_ACT_LINES_HORIZONTAL: + img_alx_lines_horizontal(imgptr); + break; + case IMG_ALX_ACT_LINES_VERTICAL: + img_alx_lines_vertical(imgptr); + break; + + case IMG_ALX_ACT_MEAN_HORIZONTAL: + img_alx_mean_horizontal(imgptr); + break; + case IMG_ALX_ACT_MEAN_VERTICAL: + img_alx_mean_vertical(imgptr); + break; + case IMG_ALX_ACT_MEDIAN_HORIZONTAL: + img_alx_median_horizontal(imgptr); + break; + case IMG_ALX_ACT_MEDIAN_VERTICAL: + img_alx_median_vertical(imgptr); + break; + } +} + + +/****************************************************************************** + ******* static functions (definitions) *************************************** + ******************************************************************************/ +static void img_alx_local_max (class cv::Mat *imgptr) +{ + int i; + int j; + int k; + int l; + /* Minimum distance between local maxima */ + const int dist_min = 16; + /* Minimum value of local maxima */ + const int val_min = 16; + class cv::Mat imgtmp; + + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + /* pointer to a pixel near img_pix (in imgptr) */ + uint8_t *near_pix; + /* pointer to a pixel (same position as img_pix, but in imgtmp) */ + uint8_t *tmp_pix; + + /* Tmp image copy */ + imgptr->copyTo(imgtmp); + + for (i = 0; i < imgptr->rows; i++) { + for (j = 0; j < imgptr->cols; j++) { + img_pix = imgptr->data + i * imgptr->step + j; + tmp_pix = imgtmp.data + i * imgptr->step + j; + + if (*img_pix < val_min) { + goto next_pixel; + } + + for (k = (i - dist_min); k < (i + dist_min + 1); k++) { + for (l = (j - dist_min); l < (j + dist_min + 1); l++) { + near_pix = imgptr->data + k * imgptr->step + l; + if ((k >= 0) && (k < imgptr->rows)) { + if ((l >= 0) && (l < imgptr->cols)) { + if (*img_pix < *near_pix) { + goto next_pixel; + } + } + } + } + } + + *tmp_pix = *img_pix; + continue; + +next_pixel: + *tmp_pix = 0; + } + } + + /* Cleanup */ + imgtmp.copyTo(*imgptr); + imgtmp.release(); +} + +static void img_alx_skeleton (class cv::Mat *imgptr) +{ + /* (Half of the) width of the skeleton */ + const int width = 5; + int dist_x; + int dist_y; + bool skeleton; + int cnt_lo [width]; + int cnt_hi_or_eq [width]; + class cv::Mat imgtmp; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + /* pointer to a pixel near img_pix (in imgptr) */ + uint8_t *near_pix; + /* pointer to a pixel (same position as img_pix, but in imgtmp) */ + uint8_t *tmp_pix; + + int i; + int j; + int k; + int l; + int r; + + /* Tmp image copy */ + imgptr->copyTo(imgtmp); + + for (i = 0; i < imgptr->rows; i++) { + for (j = 0; j < imgptr->cols; j++) { + img_pix = imgptr->data + i * imgptr->step + j; + tmp_pix = imgtmp.data + i * imgptr->step + j; + + if (!(*img_pix)) { + *tmp_pix = 0; + continue; + } + + for (r = 0; r < width; r++) { + cnt_lo[r] = 0; + cnt_hi_or_eq[r] = 0; + } + + for (k = i - width; k <= i + width; k++) { + for (l = j - width; l <= j + width; l++) { + near_pix = imgptr->data + k * imgptr->step + l; + + dist_x = abs(k - i); + dist_y = abs(l - j); + + if ((k >= 0) && (k < imgptr->rows)) { + if ((l >= 0) && (l < imgptr->cols)) { + if (dist_x || dist_y) { + if (*near_pix < *img_pix) { + cnt_lo[std::max(dist_x, dist_y)]++; + } else { + cnt_hi_or_eq[std::max(dist_x, dist_y)]++; + } + } + } + } + + } + } + + skeleton = false; + for (r = 0; r < width; r++) { + if (cnt_lo[r] > (cnt_hi_or_eq[r] + (1.6) * (r + 1))) { + skeleton = true; + } + } + + if (skeleton) { + *tmp_pix = *img_pix; + } else { + *tmp_pix = 0; + } + } + } + + /* Cleanup */ + imgtmp.copyTo(*imgptr); + imgtmp.release(); +} + +static void img_alx_lines_horizontal (class cv::Mat *imgptr) +{ + int i; + int j; + bool white; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + + for (i = 0; i < imgptr->rows; i++) { + white = false; + + for (j = 0; j < imgptr->cols; j++) { + img_pix = imgptr->data + i * imgptr->step + j; + if (*img_pix) { + white = true; + break; + } + } + + if (white) { + for (j = 0; j < imgptr->cols; j++) { + img_pix = imgptr->data + i * imgptr->step + j; + *img_pix = 255; + } + } + } +} + +static void img_alx_lines_vertical (class cv::Mat *imgptr) +{ + int i; + int j; + bool white; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + + for (i = 0; i < imgptr->cols; i++) { + white = false; + + for (j = 0; j < imgptr->rows; j++) { + img_pix = imgptr->data + j * imgptr->step + i; + if (*img_pix) { + white = true; + break; + } + } + + if (white) { + for (j = 0; j < imgptr->rows; j++) { + img_pix = imgptr->data + j * imgptr->step + i; + *img_pix = 255; + } + } + } +} + +static void img_alx_mean_horizontal (class cv::Mat *imgptr) +{ + int i; + int j; + uint32_t tmp; + uint8_t mean; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + + for (i = 0; i < imgptr->rows; i++) { + tmp = 0; + for (j = 0; j < imgptr->cols; j++) { + img_pix = imgptr->data + i * imgptr->step + j; + tmp += *img_pix; + } + mean = tmp / imgptr->cols; + + for (j = 0; j < imgptr->cols; j++) { + img_pix = imgptr->data + i * imgptr->step + j; + *img_pix = mean; + } + } +} + +static void img_alx_mean_vertical (class cv::Mat *imgptr) +{ + int i; + int j; + uint32_t tmp; + uint8_t mean; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + + for (i = 0; i < imgptr->cols; i++) { + tmp = 0; + for (j = 0; j < imgptr->rows; j++) { + img_pix = imgptr->data + j * imgptr->step + i; + tmp += *img_pix; + } + mean = tmp / imgptr->rows; + + for (j = 0; j < imgptr->rows; j++) { + img_pix = imgptr->data + j * imgptr->step + i; + *img_pix = mean; + } + } +} + +static void img_alx_median_horizontal (class cv::Mat *imgptr) +{ + int i; + int j; + uint8_t row [imgptr->cols]; + uint8_t median; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + + for (i = 0; i < imgptr->rows; i++) { + for (j = 0; j < imgptr->cols; j++) { + img_pix = imgptr->data + i * imgptr->step + j; + row[j] = *img_pix; + } + median = alx_median_u8(imgptr->cols, row); + + for (j = 0; j < imgptr->cols; j++) { + img_pix = imgptr->data + i * imgptr->step + j; + *img_pix = median; + } + } +} + +static void img_alx_median_vertical (class cv::Mat *imgptr) +{ + int i; + int j; + uint8_t col [imgptr->rows]; + uint8_t median; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + + for (i = 0; i < imgptr->cols; i++) { + for (j = 0; j < imgptr->rows; j++) { + img_pix = imgptr->data + j * imgptr->step + i; + col[j] = *img_pix; + } + median = alx_median_u8(imgptr->rows, col); + + for (j = 0; j < imgptr->rows; j++) { + img_pix = imgptr->data + j * imgptr->step + i; + *img_pix = median; + } + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/src/img_calib3d.cpp b/modules/image/src/img_calib3d.cpp index da6bb95..63a64f4 100644 --- a/modules/image/src/img_calib3d.cpp +++ b/modules/image/src/img_calib3d.cpp @@ -1,142 +1,142 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C++ --------------------------------------------------------------*/ - /* class std::vector */ - #include - -/* Standard C ----------------------------------------------------------------*/ - /* snprintf() */ - #include - -/* Packages ------------------------------------------------------------------*/ - /* opencv */ - #include - #include - -/* Module -------------------------------------------------------------------*/ - /* data */ - #include "img_iface.hpp" - - #include "img_calib3d.hpp" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define CORNERS_HOR (16) - # define CORNERS_VER (13) - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void img_calib3d_calibrate (class cv::Mat *imgptr, void *data); -static void img_calib3d_undistort (class cv::Mat *imgptr, void *data); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void img_calib3d_act (class cv::Mat *imgptr, int action, void *data) -{ - switch (action) { - case IMG_CALIB3D_ACT_CALIBRATE: - img_calib3d_calibrate(imgptr, data); - break; - - case IMG_CALIB3D_ACT_UNDISTORT: - img_calib3d_undistort(imgptr, data); - break; - } -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void img_calib3d_calibrate (class cv::Mat *imgptr, void *data) -{ - /* Data */ - struct Img_Iface_Data_Calibrate *data_cast; - - class cv::Mat *intrinsic_mat; - class cv::Mat *dist_coefs; - class std::vector *rvecs; - class std::vector *tvecs; - - class cv::Size_ pattern_size; - class std::vector >> object_points; - class std::vector >> image_points; - class std::vector > corners; - class std::vector > obj; - - bool found; - int i; - int j; - - data_cast = (struct Img_Iface_Data_Calibrate *)data; - intrinsic_mat = data_cast->intrinsic_mat; - dist_coefs = data_cast->dist_coefs; - rvecs = data_cast->rvecs; - tvecs = data_cast->tvecs; - - pattern_size = cv::Size(CORNERS_HOR, CORNERS_VER); - *intrinsic_mat = cv::Mat(3, 3, CV_32FC1); - (*intrinsic_mat).ptr(0)[0] = 1; - (*intrinsic_mat).ptr(1)[1] = 1; - - for (i = 0; i < CORNERS_HOR; i++) { - for (j = 0; j < CORNERS_VER; j++) { - obj.push_back(cv::Point3f(i, j * 10.0, 0.0)); - } - } - - found = cv::findChessboardCorners(*imgptr, pattern_size, corners, - CV_CALIB_CB_ADAPTIVE_THRESH | - CV_CALIB_CB_FILTER_QUADS); - - cv::cornerSubPix(*imgptr, corners, cv::Size(11, 11), - cv::Size(-1, -1), - cv::TermCriteria(CV_TERMCRIT_EPS | - CV_TERMCRIT_ITER, 30, 0.1)); - cv::drawChessboardCorners(*imgptr, pattern_size, corners, found); - - image_points.push_back(corners); - object_points.push_back(obj); - - /* Calibrate */ - cv::calibrateCamera(object_points, image_points, imgptr->size(), - *intrinsic_mat, *dist_coefs, *rvecs, *tvecs); -} - -static void img_calib3d_undistort (class cv::Mat *imgptr, void *data) -{ - class cv::Mat imgtmp; - - /* Data */ - struct Img_Iface_Data_Undistort *data_cast; - - class cv::Mat *intrinsic_mat; - class cv::Mat *dist_coefs; - - data_cast = (struct Img_Iface_Data_Undistort *)data; - intrinsic_mat = data_cast->intrinsic_mat; - dist_coefs = data_cast->dist_coefs; - - cv::undistort(*imgptr, imgtmp, *intrinsic_mat, *dist_coefs); - - /* Write tmp into imgptr */ - imgptr->release(); - imgtmp.copyTo(*imgptr); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C++ --------------------------------------------------------------*/ + /* class std::vector */ + #include + +/* Standard C ----------------------------------------------------------------*/ + /* snprintf() */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* opencv */ + #include + #include + +/* Module -------------------------------------------------------------------*/ + /* data */ + #include "img_iface.hpp" + + #include "img_calib3d.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define CORNERS_HOR (16) + # define CORNERS_VER (13) + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void img_calib3d_calibrate (class cv::Mat *imgptr, void *data); +static void img_calib3d_undistort (class cv::Mat *imgptr, void *data); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void img_calib3d_act (class cv::Mat *imgptr, int action, void *data) +{ + switch (action) { + case IMG_CALIB3D_ACT_CALIBRATE: + img_calib3d_calibrate(imgptr, data); + break; + + case IMG_CALIB3D_ACT_UNDISTORT: + img_calib3d_undistort(imgptr, data); + break; + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void img_calib3d_calibrate (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Calibrate *data_cast; + + class cv::Mat *intrinsic_mat; + class cv::Mat *dist_coefs; + class std::vector *rvecs; + class std::vector *tvecs; + + class cv::Size_ pattern_size; + class std::vector >> object_points; + class std::vector >> image_points; + class std::vector > corners; + class std::vector > obj; + + bool found; + int i; + int j; + + data_cast = (struct Img_Iface_Data_Calibrate *)data; + intrinsic_mat = data_cast->intrinsic_mat; + dist_coefs = data_cast->dist_coefs; + rvecs = data_cast->rvecs; + tvecs = data_cast->tvecs; + + pattern_size = cv::Size(CORNERS_HOR, CORNERS_VER); + *intrinsic_mat = cv::Mat(3, 3, CV_32FC1); + (*intrinsic_mat).ptr(0)[0] = 1; + (*intrinsic_mat).ptr(1)[1] = 1; + + for (i = 0; i < CORNERS_HOR; i++) { + for (j = 0; j < CORNERS_VER; j++) { + obj.push_back(cv::Point3f(i, j * 10.0, 0.0)); + } + } + + found = cv::findChessboardCorners(*imgptr, pattern_size, corners, + CV_CALIB_CB_ADAPTIVE_THRESH | + CV_CALIB_CB_FILTER_QUADS); + + cv::cornerSubPix(*imgptr, corners, cv::Size(11, 11), + cv::Size(-1, -1), + cv::TermCriteria(CV_TERMCRIT_EPS | + CV_TERMCRIT_ITER, 30, 0.1)); + cv::drawChessboardCorners(*imgptr, pattern_size, corners, found); + + image_points.push_back(corners); + object_points.push_back(obj); + + /* Calibrate */ + cv::calibrateCamera(object_points, image_points, imgptr->size(), + *intrinsic_mat, *dist_coefs, *rvecs, *tvecs); +} + +static void img_calib3d_undistort (class cv::Mat *imgptr, void *data) +{ + class cv::Mat imgtmp; + + /* Data */ + struct Img_Iface_Data_Undistort *data_cast; + + class cv::Mat *intrinsic_mat; + class cv::Mat *dist_coefs; + + data_cast = (struct Img_Iface_Data_Undistort *)data; + intrinsic_mat = data_cast->intrinsic_mat; + dist_coefs = data_cast->dist_coefs; + + cv::undistort(*imgptr, imgtmp, *intrinsic_mat, *dist_coefs); + + /* Write tmp into imgptr */ + imgptr->release(); + imgtmp.copyTo(*imgptr); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/src/img_cv.cpp b/modules/image/src/img_cv.cpp index 3a7c59b..0d76bb8 100644 --- a/modules/image/src/img_cv.cpp +++ b/modules/image/src/img_cv.cpp @@ -1,881 +1,881 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C++ --------------------------------------------------------------*/ - /* class std::vector */ - #include - -/* Standard C ----------------------------------------------------------------*/ - /* fabs */ - #include - /* true & false */ - #include - /* snprintf() */ - #include - -/* Packages ------------------------------------------------------------------*/ - /* opencv */ - #include - -/* Module --------------------------------------------------------------------*/ - /* data */ - #include "img_iface.hpp" - - #include "img_cv.hpp" - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ - /* Core: The core functionality */ - /* Pixel */ -static void img_cv_pixel_get (class cv::Mat *imgptr, void *data); -static void img_cv_pixel_set (class cv::Mat *imgptr, void *data); - /* ROI */ -static void img_cv_set_ROI (class cv::Mat *imgptr, void *data); - /* Operations on Arrays */ -static void img_cv_and_2ref (class cv::Mat *imgptr, void *data); -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_component (class cv::Mat *imgptr, void *data); - /* Imgproc: Image processing */ - /* Image filtering */ -static void img_cv_dilate (class cv::Mat *imgptr, void *data); -static void img_cv_erode (class cv::Mat *imgptr, void *data); -static void img_cv_smooth (class cv::Mat *imgptr, void *data); -static void img_cv_sobel (class cv::Mat *imgptr, void *data); -static void img_cv_border (class cv::Mat *imgptr, void *data); - /* Geometric image transformations */ -static void img_cv_mirror (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); - /* Miscellaneous image transformations */ -static void img_cv_adaptive_thr (class cv::Mat *imgptr, void *data); -static void img_cv_cvt_color (class cv::Mat *imgptr, void *data); -static void img_cv_distance_transform (class cv::Mat *imgptr); -static void img_cv_threshold (class cv::Mat *imgptr, void *data); - /* Histograms */ -static void img_cv_histogram (class cv::Mat *imgptr, void *data); -static void img_cv_histogram_c3 (class cv::Mat *imgptr, void *data); - /* Structural analysis and shape descriptors */ -static void img_cv_contours (class cv::Mat *imgptr, void *data); -static void img_cv_contours_size (void *data); -static void img_cv_bounding_rect (class cv::Mat *imgptr, void *data); -static void img_cv_fit_ellipse (class cv::Mat *imgptr, void *data); -static void img_cv_min_area_rect (class cv::Mat *imgptr, void *data); - /* Feature detection */ -static void img_cv_hough_circles (class cv::Mat *imgptr, void *data); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void img_cv_act (class cv::Mat *imgptr, int action, void *data) -{ - switch (action) { - case IMG_CV_ACT_PIXEL_GET: - img_cv_pixel_get(imgptr, data); - break; - case IMG_CV_ACT_PIXEL_SET: - img_cv_pixel_set(imgptr, data); - break; - - case IMG_CV_ACT_SET_ROI: - img_cv_set_ROI(imgptr, data); - break; - - case IMG_CV_ACT_AND_2REF: - img_cv_and_2ref(imgptr, data); - break; - 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_COMPONENT: - img_cv_component(imgptr, data); - break; - - case IMG_CV_ACT_DILATE: - img_cv_dilate(imgptr, data); - break; - case IMG_CV_ACT_ERODE: - img_cv_erode(imgptr, data); - break; - case IMG_CV_ACT_SMOOTH: - img_cv_smooth(imgptr, data); - break; - case IMG_CV_ACT_SOBEL: - img_cv_sobel(imgptr, data); - break; - case IMG_CV_ACT_BORDER: - img_cv_border(imgptr, data); - break; - - case IMG_CV_ACT_MIRROR: - img_cv_mirror(imgptr, data); - break; - case IMG_CV_ACT_ROTATE_ORTO: - img_cv_rotate_orto(imgptr, data); - break; - case IMG_CV_ACT_ROTATE: - img_cv_rotate(imgptr, data); - break; - - case IMG_CV_ACT_ADAPTIVE_THRESHOLD: - img_cv_adaptive_thr(imgptr, data); - break; - case IMG_CV_ACT_CVT_COLOR: - img_cv_cvt_color(imgptr, data); - break; - case IMG_CV_ACT_DISTANCE_TRANSFORM: - img_cv_distance_transform(imgptr); - break; - case IMG_CV_ACT_THRESHOLD: - img_cv_threshold(imgptr, data); - break; - - case IMG_CV_ACT_HISTOGRAM: - img_cv_histogram(imgptr, data); - break; - case IMG_CV_ACT_HISTOGRAM_C3: - img_cv_histogram_c3(imgptr, data); - break; - - case IMG_CV_ACT_CONTOURS: - img_cv_contours(imgptr, data); - break; - case IMG_CV_ACT_CONTOURS_SIZE: - img_cv_contours_size(data); - break; - case IMG_CV_ACT_BOUNDING_RECT: - img_cv_bounding_rect(imgptr, data); - break; - case IMG_CV_ACT_FIT_ELLIPSE: - img_cv_fit_ellipse(imgptr, data); - break; - case IMG_CV_ACT_MIN_AREA_RECT: - img_cv_min_area_rect(imgptr, data); - break; - - case IMG_CV_ACT_HOUGH_CIRCLES: - img_cv_hough_circles(imgptr, data); - break; - } -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -/* Core: The core functionality */ -/* ----- Pixel */ -static void img_cv_pixel_get (class cv::Mat *imgptr, void *data) -{ - struct Img_Iface_Data_Pixel_Get *data_cast; - unsigned char *val; - int x; - int y; - /* Data */ - data_cast = (struct Img_Iface_Data_Pixel_Get *)data; - - /* Value */ - val = data_cast->val; - /* Position */ - x = data_cast->x; - y = data_cast->y; - - /* Get value */ - *val = imgptr->at(y, x); -} - -static void img_cv_pixel_set (class cv::Mat *imgptr, void *data) -{ - struct Img_Iface_Data_Pixel_Set *data_cast; - unsigned char val; - int x; - int y; - - /* Data */ - data_cast = (struct Img_Iface_Data_Pixel_Set *)data; - - /* Value */ - val = data_cast->val; - /* Position */ - x = data_cast->x; - y = data_cast->y; - - /* Set value */ - imgptr->at(y, x) = val; -} - -/* ----- ROI */ -static void img_cv_set_ROI (class cv::Mat *imgptr, void *data) -{ - class cv::Mat imgtmp; - struct Img_Iface_Data_SetROI *data_cast; - class cv::Rect_ *rect; - - /* Data */ - data_cast = (struct Img_Iface_Data_SetROI *)data; - - /* Rectangle */ - rect = &(data_cast->rect); - - /* Set ROI */ - (*imgptr)(*rect).copyTo(imgtmp); - imgtmp.copyTo(*imgptr); - - /* Write tmp into imgptr */ - imgptr->release(); - imgtmp.copyTo(*imgptr); - - /* clean up */ - imgtmp.release(); -} - -/* ----- Operations on arrays */ -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_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_component (class cv::Mat *imgptr, void *data) -{ - class cv::Mat cmp_img[3]; - struct Img_Iface_Data_Component *data_cast; - int cmp; - - /* Data */ - data_cast = (struct Img_Iface_Data_Component *)data; - - /* Color component */ - cmp = data_cast->cmp; - - /* Write components into cmp_img[] */ - cv::split(*imgptr, cmp_img); - - /* Write tmp into imgptr */ - imgptr->release(); - cmp_img[cmp].copyTo(*imgptr); - - /* clean up */ - cmp_img[0].release(); - cmp_img[1].release(); - cmp_img[2].release(); -} - -/* Imgproc: Image processing */ -/* ----- Image filtering */ -static void img_cv_dilate (class cv::Mat *imgptr, void *data) -{ - /* Data */ - struct Img_Iface_Data_Dilate_Erode *data_cast; - data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; - - /* Iterations */ - int i; - i = data_cast->i; - - /* Dilate */ - cv::dilate(*imgptr, *imgptr, cv::Mat(), cv::Point(-1,-1), i, - cv::BORDER_CONSTANT, cv::Scalar(0)); -} - -static void img_cv_erode (class cv::Mat *imgptr, void *data) -{ - /* Data */ - struct Img_Iface_Data_Dilate_Erode *data_cast; - data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; - - /* Iterations */ - int i; - i = data_cast->i; - - /* Erode */ - cv::erode(*imgptr, *imgptr, cv::Mat(), cv::Point(-1,-1), i, - cv::BORDER_CONSTANT, cv::Scalar(0)); -} - -static void img_cv_smooth (class cv::Mat *imgptr, void *data) -{ - /* Data */ - struct Img_Iface_Data_Smooth *data_cast; - data_cast = (struct Img_Iface_Data_Smooth *)data; - - /* Smoothing method */ - int method; - method = data_cast->method; - /* Kernel size */ - int ksize; - ksize = data_cast->ksize; - if (!(ksize % 2)) { - ksize++; - } - - switch (method) { - case IMGI_SMOOTH_MEAN: - cv::blur(*imgptr, *imgptr, cv::Size(ksize, ksize), - cv::Point(-1,-1), cv::BORDER_DEFAULT); - break; - case IMGI_SMOOTH_GAUSS: - cv::GaussianBlur(*imgptr, *imgptr, cv::Size(ksize, ksize), - 0, 0, cv::BORDER_DEFAULT); - break; - case IMGI_SMOOTH_MEDIAN: - cv::medianBlur(*imgptr, *imgptr, ksize); - break; - } -} - -static void img_cv_sobel (class cv::Mat *imgptr, void *data) -{ - /* Data */ - struct Img_Iface_Data_Sobel *data_cast; - data_cast = (struct Img_Iface_Data_Sobel *)data; - - /* Order of the derivative x */ - int dx; - dx = data_cast->dx; - /* Order of the derivative y */ - int dy; - dy = data_cast->dy; - /* Size of the extended Sobel kernel */ - int ksize; - ksize = data_cast->ksize; - if (!(ksize % 2)) { - ksize++; - } - - cv::Sobel(*imgptr, *imgptr, -1, dx, dy, ksize, 1, 0, - cv::BORDER_DEFAULT); -} - -static void img_cv_border (class cv::Mat *imgptr, void *data) -{ - class cv::Mat imgtmp; - struct Img_Iface_Data_Border *data_cast; - int size; - - /* Data */ - data_cast = (struct Img_Iface_Data_Border *)data; - - size = data_cast->size; - - imgtmp = cv::Mat(cv::Size(imgptr->cols + size, imgptr->rows + size), - CV_8U); - /* Get transform */ - cv::copyMakeBorder(*imgptr, imgtmp, size, size, size, size, - cv::BORDER_CONSTANT, cv::Scalar(0)); - - imgtmp.copyTo(*imgptr); - - /* Cleanup */ - imgtmp.release(); -} - -/* ----- Geometric image transformations */ -static void img_cv_mirror (class cv::Mat *imgptr, void *data) -{ - struct Img_Iface_Data_Mirror *data_cast; - int axis; - - /* Data */ - data_cast = (struct Img_Iface_Data_Mirror *)data; - - /* Rotate n * pi/2 rad */ - axis = data_cast->axis; - - /* flip around axis */ - cv::flip(*imgptr, *imgptr, axis); -} - -static void img_cv_rotate_orto (class cv::Mat *imgptr, void *data) -{ - /* Data */ - struct Img_Iface_Data_Rotate_Orto *data_cast; - data_cast = (struct Img_Iface_Data_Rotate_Orto *)data; - - /* Rotate n * pi/2 rad */ - int n; - n = data_cast->n; - - switch (n) { - case 1: - /* Rotate: transpose and flip around horizontal axis: flip_mode=0 */ - cv::transpose(*imgptr, *imgptr); - cv::flip(*imgptr, *imgptr, 0); - break; - - case 2: - /* Rotate: Flip both axises: flip_mode=-1 */ - cv::flip(*imgptr, *imgptr, -1); - break; - - case 3: - /* Rotate: transpose and flip around vertical axis: flip_mode=1 */ - cv::transpose(*imgptr, *imgptr); - cv::flip(*imgptr, *imgptr, 1); - break; - } -} - -static void img_cv_rotate (class cv::Mat *imgptr, void *data) -{ - class cv::Mat map_matrix; - - /* Data */ - struct Img_Iface_Data_Rotate *data_cast; - data_cast = (struct Img_Iface_Data_Rotate *)data; - - /* Angle of rotation */ - class cv::Point_ *center; - center = &(data_cast->center); - double angle; - angle = data_cast->angle; - - /* 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)); - - /* clean up */ - map_matrix.release(); -} - -/* ----- Miscellaneous image transformations */ -static void img_cv_adaptive_thr (class cv::Mat *imgptr, void *data) -{ - /* Data */ - struct Img_Iface_Data_Adaptive_Thr *data_cast; - data_cast = (struct Img_Iface_Data_Adaptive_Thr *)data; - - /* Threshold method */ - int method; - method = data_cast->method; - /* Threshold type */ - int thr_typ; - thr_typ = data_cast->thr_typ; - /* Neighbourhood size */ - int ksize; - ksize = data_cast->ksize; - if (!(ksize % 2)) { - ksize++; - } - - /* Apply adaptive threshold */ - cv::adaptiveThreshold(*imgptr, *imgptr, 255, method, thr_typ, ksize, - 0); -} - -static void img_cv_cvt_color (class cv::Mat *imgptr, void *data) -{ - /* Data */ - struct Img_Iface_Data_Cvt_Color *data_cast; - data_cast = (struct Img_Iface_Data_Cvt_Color *)data; - - /* Conversion method */ - int method; - method = data_cast->method; - - cv::cvtColor(*imgptr, *imgptr, method, 0); -} - -static void img_cv_distance_transform (class cv::Mat *imgptr) -{ - class cv::Mat imgtmp; - - /* Get transform */ - cv::distanceTransform(*imgptr, imgtmp, CV_DIST_L2, CV_DIST_MASK_PRECISE); - - /* DistanceTransform gives CV_32F image */ - imgtmp.convertTo(*imgptr, CV_8U); - - /* Cleanup */ - imgtmp.release(); -} - -static void img_cv_threshold (class cv::Mat *imgptr, void *data) -{ - /* Data */ - struct Img_Iface_Data_Threshold *data_cast; - data_cast = (struct Img_Iface_Data_Threshold *)data; - - /* Threshold type */ - int thr_typ; - thr_typ = data_cast->thr_typ; - /* Threshold value */ - int thr_val; - thr_val = data_cast->thr_val; - if (thr_val == -1) { - thr_typ |= cv::THRESH_OTSU; - } - - /* Threshold */ - cv::threshold(*imgptr, *imgptr, thr_val, 0xFF, thr_typ); -} - -/* ----- Histograms */ -static void img_cv_histogram (class cv::Mat *imgptr, void *data) -{ - /* Data */ - struct Img_Iface_Data_Histogram *data_cast; - data_cast = (struct Img_Iface_Data_Histogram *)data; - - /* Contours */ - class cv::Mat *hist; - hist = data_cast->hist_c0; - class cv::Mat *hist_img; - hist_img = data_cast->hist_img; - - /* Write components into cmp_img[] */ - int h_size = 256; - float h_range_arr[] = {0.0, 256.0}; - const float *h_range = {h_range_arr}; - cv::calcHist(imgptr, 1, 0, cv::Mat(), *hist, 1, &h_size, &h_range, - true, false); - - /* Init */ - hist_img->setTo(cv::Scalar(0)); - - /* Normalize the result to [0, hist_img->rows - 1] */ - cv::normalize(*hist, *hist, 0, hist_img->rows - 1, cv::NORM_MINMAX, -1, - cv::Mat()); - - /* Draw hist into hist_img */ - int i; - for(i = 0; i < 256; i++ ) { - cv::line(*hist_img, cv::Point(i, hist_img->rows - 0), - cv::Point(i, hist_img->rows - hist->at(i)), - cv::Scalar(255, 0, 0), 1, 8, 0); - } - - /* Show histogram */ - img_iface_show_hist_c1(); -} - -static void img_cv_histogram_c3 (class cv::Mat *imgptr, void *data) -{ - class cv::Mat cmp_img[3]; - - /* Write components into cmp_img[] */ - cv::split(*imgptr, cmp_img); - - /* Data */ - struct Img_Iface_Data_Histogram *data_cast; - data_cast = (struct Img_Iface_Data_Histogram *)data; - - /* Contours */ - class cv::Mat *hist_c0; - hist_c0 = data_cast->hist_c0; - class cv::Mat *hist_c1; - hist_c1 = data_cast->hist_c1; - class cv::Mat *hist_c2; - hist_c2 = data_cast->hist_c2; - class cv::Mat *hist_img; - hist_img = data_cast->hist_img; - - /* Write components into cmp_img[] */ - int h_size = 256; - float h_range_arr[] = {0.0, 256.0}; - const float *h_range = {h_range_arr}; - cv::calcHist(&cmp_img[0], 1, 0, cv::Mat(), *hist_c0, 1, &h_size, - &h_range, true, false); - cv::calcHist(&cmp_img[1], 1, 0, cv::Mat(), *hist_c1, 1, &h_size, - &h_range, true, false); - cv::calcHist(&cmp_img[2], 1, 0, cv::Mat(), *hist_c2, 1, &h_size, - &h_range, true, false); - - /* Init */ - hist_img->setTo(cv::Scalar(0)); - - /* Normalize the result to [0, hist_img->rows - 1] */ - cv::normalize(*hist_c0, *hist_c0, 0, hist_img->rows - 1, - cv::NORM_MINMAX, -1, cv::Mat()); - cv::normalize(*hist_c1, *hist_c1, 0, hist_img->rows - 1, - cv::NORM_MINMAX, -1, cv::Mat()); - cv::normalize(*hist_c2, *hist_c2, 0, hist_img->rows - 1, - cv::NORM_MINMAX, -1, cv::Mat()); - - /* Draw hist into hist_img */ - int i; - for(i = 0; i < 256; i++ ) { - cv::line(*hist_img, cv::Point(3*i, hist_img->rows - 0), - cv::Point(3*i, - hist_img->rows - hist_c0->at(i)), - cv::Scalar(255, 0, 0), 1, 8, 0); - } - for(i = 0; i < 256; i++ ) { - cv::line(*hist_img, cv::Point(3*i + 1, hist_img->rows - 0), - cv::Point(3*i+1, - hist_img->rows - hist_c1->at(i)), - cv::Scalar(0, 255, 0), 1, 8, 0); - } - for(i = 0; i < 256; i++ ) { - cv::line(*hist_img, cv::Point(3*i + 2, hist_img->rows - 0), - cv::Point(3*i + 2, - hist_img->rows - hist_c2->at(i)), - cv::Scalar(0, 0, 255), 1, 8, 0); - } - - /* Show histogram */ - img_iface_show_hist_c3(); - - /* Cleanup */ - cmp_img[0].release(); - cmp_img[1].release(); - cmp_img[2].release(); -} - -/* ----- Structural analysis and shape descriptors */ -static void img_cv_contours (class cv::Mat *imgptr, void *data) -{ - struct Img_Iface_Data_Contours *data_cast; - class std::vector >> *contours; - class cv::Mat *hierarchy; - - /* Data */ - data_cast = (struct Img_Iface_Data_Contours *)data; - - /* Contours */ - contours = data_cast->contours; - hierarchy = data_cast->hierarchy; - - /* Get contours */ - - cv::findContours(*imgptr, *contours, *hierarchy, CV_RETR_EXTERNAL, - CV_CHAIN_APPROX_SIMPLE); - - /* Set image to black */ - imgptr->setTo(cv::Scalar(0)); - - /* Draw contours in color */ - cv::drawContours(*imgptr, *contours, -1, cv::Scalar(255), 1, 8, - *hierarchy, 1, cvPoint(0, 0)); -} - -static void img_cv_contours_size (void *data) -{ - struct Img_Iface_Data_Contours_Size *data_cast; - class std::vector >> *contours; - int i; - - /* Data */ - data_cast = (struct Img_Iface_Data_Contours_Size *)data; - - /* Contours */ - contours = data_cast->contours; - - /* Get area and perimeter */ - if (data_cast->area) { - for (i = 0; i < (int)contours->size(); i++) { - data_cast->area[i] = cv::contourArea( - (*contours)[i], false); - } - } - if (data_cast->perimeter) { - for (i = 0; i < (int)contours->size(); i++) { - data_cast->perimeter[i] = cv::arcLength( - (*contours)[i], true); - } - } -} - -static void img_cv_bounding_rect (class cv::Mat *imgptr, void *data) -{ - /* Data */ - struct Img_Iface_Data_Bounding_Rect *data_cast; - data_cast = (struct Img_Iface_Data_Bounding_Rect *)data; - - /* Contours */ - class std::vector > *contour; - contour = data_cast->contour; - /* Rotated rectangle */ - class cv::Rect_ *rect; - rect = data_cast->rect; - /* Show rectangle ? */ - bool show; - show = data_cast->show; - - /* Get rectangle */ - *rect = cv::boundingRect(*contour); - - /* Draw rectangle */ - class cv::Point_ vertices[4]; - if (show) { - vertices[0].x = rect->x; - vertices[0].y = rect->y; - vertices[1].x = rect->x + rect->width; - vertices[1].y = rect->y; - vertices[2].x = rect->x + rect->width; - vertices[2].y = rect->y + rect->height; - vertices[3].x = rect->x; - vertices[3].y = rect->y + rect->height; - 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) -{ - /* Data */ - struct Img_Iface_Data_MinARect *data_cast; - data_cast = (struct Img_Iface_Data_MinARect *)data; - - /* Contours */ - class std::vector > *contour; - contour = data_cast->contour; - /* Rotated rectangle */ - class cv::RotatedRect *rect; - rect = data_cast->rect; - /* Show rectangle ? */ - bool show; - show = data_cast->show; - - /* Get rectangle */ - *rect = cv::fitEllipse(*contour); - - /* Draw rectangle */ - class cv::Point_ vertices[4]; - 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_min_area_rect (class cv::Mat *imgptr, void *data) -{ - /* Data */ - struct Img_Iface_Data_MinARect *data_cast; - data_cast = (struct Img_Iface_Data_MinARect *)data; - - /* Contours */ - class std::vector > *contour; - contour = data_cast->contour; - /* 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_ vertices[4]; - 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); - } -} - -/* ----- Feature detection */ -static void img_cv_hough_circles (class cv::Mat *imgptr, void *data) -{ - /* Data */ - struct Img_Iface_Data_Hough_Circles *data_cast; - data_cast = (struct Img_Iface_Data_Hough_Circles *)data; - - /* Contours */ - class std::vector > *circles; - circles = data_cast->circles; - /* Parameters */ - double dist_min; - double param_1; - double param_2; - int radius_min; - int radius_max; - dist_min = data_cast->dist_min; - param_1 = data_cast->param_1; - param_2 = data_cast->param_2; - radius_min = data_cast->radius_min; - radius_max = data_cast->radius_max; - - /* Get circles */ - cv::HoughCircles(*imgptr, *circles, CV_HOUGH_GRADIENT, 1, dist_min, - param_1, param_2, radius_min, radius_max); - - /* Set image to black */ - imgptr->setTo(cv::Scalar(0)); - - /* Draw circles */ - class cv::Point_ center; - int radius; - int i; - for (i = 0; i < (int)circles->size(); i++) { - center.x = cvRound((*circles)[i][0]); - center.y = cvRound((*circles)[i][1]); - radius = cvRound((*circles)[i][2]); - - /* Draw the circle center */ -/* cv::circle(*imgptr, center, 3, - cv::Scalar(0, 255, 0), -1, 8, 0);*/ - - /* Draw the circle outline */ - cv::circle(*imgptr, center, radius, - cv::Scalar(250), 1, 8, 0); - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C++ --------------------------------------------------------------*/ + /* class std::vector */ + #include + +/* Standard C ----------------------------------------------------------------*/ + /* fabs */ + #include + /* true & false */ + #include + /* snprintf() */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* opencv */ + #include + +/* Module --------------------------------------------------------------------*/ + /* data */ + #include "img_iface.hpp" + + #include "img_cv.hpp" + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ + /* Core: The core functionality */ + /* Pixel */ +static void img_cv_pixel_get (class cv::Mat *imgptr, void *data); +static void img_cv_pixel_set (class cv::Mat *imgptr, void *data); + /* ROI */ +static void img_cv_set_ROI (class cv::Mat *imgptr, void *data); + /* Operations on Arrays */ +static void img_cv_and_2ref (class cv::Mat *imgptr, void *data); +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_component (class cv::Mat *imgptr, void *data); + /* Imgproc: Image processing */ + /* Image filtering */ +static void img_cv_dilate (class cv::Mat *imgptr, void *data); +static void img_cv_erode (class cv::Mat *imgptr, void *data); +static void img_cv_smooth (class cv::Mat *imgptr, void *data); +static void img_cv_sobel (class cv::Mat *imgptr, void *data); +static void img_cv_border (class cv::Mat *imgptr, void *data); + /* Geometric image transformations */ +static void img_cv_mirror (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); + /* Miscellaneous image transformations */ +static void img_cv_adaptive_thr (class cv::Mat *imgptr, void *data); +static void img_cv_cvt_color (class cv::Mat *imgptr, void *data); +static void img_cv_distance_transform (class cv::Mat *imgptr); +static void img_cv_threshold (class cv::Mat *imgptr, void *data); + /* Histograms */ +static void img_cv_histogram (class cv::Mat *imgptr, void *data); +static void img_cv_histogram_c3 (class cv::Mat *imgptr, void *data); + /* Structural analysis and shape descriptors */ +static void img_cv_contours (class cv::Mat *imgptr, void *data); +static void img_cv_contours_size (void *data); +static void img_cv_bounding_rect (class cv::Mat *imgptr, void *data); +static void img_cv_fit_ellipse (class cv::Mat *imgptr, void *data); +static void img_cv_min_area_rect (class cv::Mat *imgptr, void *data); + /* Feature detection */ +static void img_cv_hough_circles (class cv::Mat *imgptr, void *data); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void img_cv_act (class cv::Mat *imgptr, int action, void *data) +{ + switch (action) { + case IMG_CV_ACT_PIXEL_GET: + img_cv_pixel_get(imgptr, data); + break; + case IMG_CV_ACT_PIXEL_SET: + img_cv_pixel_set(imgptr, data); + break; + + case IMG_CV_ACT_SET_ROI: + img_cv_set_ROI(imgptr, data); + break; + + case IMG_CV_ACT_AND_2REF: + img_cv_and_2ref(imgptr, data); + break; + 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_COMPONENT: + img_cv_component(imgptr, data); + break; + + case IMG_CV_ACT_DILATE: + img_cv_dilate(imgptr, data); + break; + case IMG_CV_ACT_ERODE: + img_cv_erode(imgptr, data); + break; + case IMG_CV_ACT_SMOOTH: + img_cv_smooth(imgptr, data); + break; + case IMG_CV_ACT_SOBEL: + img_cv_sobel(imgptr, data); + break; + case IMG_CV_ACT_BORDER: + img_cv_border(imgptr, data); + break; + + case IMG_CV_ACT_MIRROR: + img_cv_mirror(imgptr, data); + break; + case IMG_CV_ACT_ROTATE_ORTO: + img_cv_rotate_orto(imgptr, data); + break; + case IMG_CV_ACT_ROTATE: + img_cv_rotate(imgptr, data); + break; + + case IMG_CV_ACT_ADAPTIVE_THRESHOLD: + img_cv_adaptive_thr(imgptr, data); + break; + case IMG_CV_ACT_CVT_COLOR: + img_cv_cvt_color(imgptr, data); + break; + case IMG_CV_ACT_DISTANCE_TRANSFORM: + img_cv_distance_transform(imgptr); + break; + case IMG_CV_ACT_THRESHOLD: + img_cv_threshold(imgptr, data); + break; + + case IMG_CV_ACT_HISTOGRAM: + img_cv_histogram(imgptr, data); + break; + case IMG_CV_ACT_HISTOGRAM_C3: + img_cv_histogram_c3(imgptr, data); + break; + + case IMG_CV_ACT_CONTOURS: + img_cv_contours(imgptr, data); + break; + case IMG_CV_ACT_CONTOURS_SIZE: + img_cv_contours_size(data); + break; + case IMG_CV_ACT_BOUNDING_RECT: + img_cv_bounding_rect(imgptr, data); + break; + case IMG_CV_ACT_FIT_ELLIPSE: + img_cv_fit_ellipse(imgptr, data); + break; + case IMG_CV_ACT_MIN_AREA_RECT: + img_cv_min_area_rect(imgptr, data); + break; + + case IMG_CV_ACT_HOUGH_CIRCLES: + img_cv_hough_circles(imgptr, data); + break; + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +/* Core: The core functionality */ +/* ----- Pixel */ +static void img_cv_pixel_get (class cv::Mat *imgptr, void *data) +{ + struct Img_Iface_Data_Pixel_Get *data_cast; + unsigned char *val; + int x; + int y; + /* Data */ + data_cast = (struct Img_Iface_Data_Pixel_Get *)data; + + /* Value */ + val = data_cast->val; + /* Position */ + x = data_cast->x; + y = data_cast->y; + + /* Get value */ + *val = imgptr->at(y, x); +} + +static void img_cv_pixel_set (class cv::Mat *imgptr, void *data) +{ + struct Img_Iface_Data_Pixel_Set *data_cast; + unsigned char val; + int x; + int y; + + /* Data */ + data_cast = (struct Img_Iface_Data_Pixel_Set *)data; + + /* Value */ + val = data_cast->val; + /* Position */ + x = data_cast->x; + y = data_cast->y; + + /* Set value */ + imgptr->at(y, x) = val; +} + +/* ----- ROI */ +static void img_cv_set_ROI (class cv::Mat *imgptr, void *data) +{ + class cv::Mat imgtmp; + struct Img_Iface_Data_SetROI *data_cast; + class cv::Rect_ *rect; + + /* Data */ + data_cast = (struct Img_Iface_Data_SetROI *)data; + + /* Rectangle */ + rect = &(data_cast->rect); + + /* Set ROI */ + (*imgptr)(*rect).copyTo(imgtmp); + imgtmp.copyTo(*imgptr); + + /* Write tmp into imgptr */ + imgptr->release(); + imgtmp.copyTo(*imgptr); + + /* clean up */ + imgtmp.release(); +} + +/* ----- Operations on arrays */ +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_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_component (class cv::Mat *imgptr, void *data) +{ + class cv::Mat cmp_img[3]; + struct Img_Iface_Data_Component *data_cast; + int cmp; + + /* Data */ + data_cast = (struct Img_Iface_Data_Component *)data; + + /* Color component */ + cmp = data_cast->cmp; + + /* Write components into cmp_img[] */ + cv::split(*imgptr, cmp_img); + + /* Write tmp into imgptr */ + imgptr->release(); + cmp_img[cmp].copyTo(*imgptr); + + /* clean up */ + cmp_img[0].release(); + cmp_img[1].release(); + cmp_img[2].release(); +} + +/* Imgproc: Image processing */ +/* ----- Image filtering */ +static void img_cv_dilate (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Dilate_Erode *data_cast; + data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; + + /* Iterations */ + int i; + i = data_cast->i; + + /* Dilate */ + cv::dilate(*imgptr, *imgptr, cv::Mat(), cv::Point(-1,-1), i, + cv::BORDER_CONSTANT, cv::Scalar(0)); +} + +static void img_cv_erode (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Dilate_Erode *data_cast; + data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; + + /* Iterations */ + int i; + i = data_cast->i; + + /* Erode */ + cv::erode(*imgptr, *imgptr, cv::Mat(), cv::Point(-1,-1), i, + cv::BORDER_CONSTANT, cv::Scalar(0)); +} + +static void img_cv_smooth (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Smooth *data_cast; + data_cast = (struct Img_Iface_Data_Smooth *)data; + + /* Smoothing method */ + int method; + method = data_cast->method; + /* Kernel size */ + int ksize; + ksize = data_cast->ksize; + if (!(ksize % 2)) { + ksize++; + } + + switch (method) { + case IMGI_SMOOTH_MEAN: + cv::blur(*imgptr, *imgptr, cv::Size(ksize, ksize), + cv::Point(-1,-1), cv::BORDER_DEFAULT); + break; + case IMGI_SMOOTH_GAUSS: + cv::GaussianBlur(*imgptr, *imgptr, cv::Size(ksize, ksize), + 0, 0, cv::BORDER_DEFAULT); + break; + case IMGI_SMOOTH_MEDIAN: + cv::medianBlur(*imgptr, *imgptr, ksize); + break; + } +} + +static void img_cv_sobel (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Sobel *data_cast; + data_cast = (struct Img_Iface_Data_Sobel *)data; + + /* Order of the derivative x */ + int dx; + dx = data_cast->dx; + /* Order of the derivative y */ + int dy; + dy = data_cast->dy; + /* Size of the extended Sobel kernel */ + int ksize; + ksize = data_cast->ksize; + if (!(ksize % 2)) { + ksize++; + } + + cv::Sobel(*imgptr, *imgptr, -1, dx, dy, ksize, 1, 0, + cv::BORDER_DEFAULT); +} + +static void img_cv_border (class cv::Mat *imgptr, void *data) +{ + class cv::Mat imgtmp; + struct Img_Iface_Data_Border *data_cast; + int size; + + /* Data */ + data_cast = (struct Img_Iface_Data_Border *)data; + + size = data_cast->size; + + imgtmp = cv::Mat(cv::Size(imgptr->cols + size, imgptr->rows + size), + CV_8U); + /* Get transform */ + cv::copyMakeBorder(*imgptr, imgtmp, size, size, size, size, + cv::BORDER_CONSTANT, cv::Scalar(0)); + + imgtmp.copyTo(*imgptr); + + /* Cleanup */ + imgtmp.release(); +} + +/* ----- Geometric image transformations */ +static void img_cv_mirror (class cv::Mat *imgptr, void *data) +{ + struct Img_Iface_Data_Mirror *data_cast; + int axis; + + /* Data */ + data_cast = (struct Img_Iface_Data_Mirror *)data; + + /* Rotate n * pi/2 rad */ + axis = data_cast->axis; + + /* flip around axis */ + cv::flip(*imgptr, *imgptr, axis); +} + +static void img_cv_rotate_orto (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Rotate_Orto *data_cast; + data_cast = (struct Img_Iface_Data_Rotate_Orto *)data; + + /* Rotate n * pi/2 rad */ + int n; + n = data_cast->n; + + switch (n) { + case 1: + /* Rotate: transpose and flip around horizontal axis: flip_mode=0 */ + cv::transpose(*imgptr, *imgptr); + cv::flip(*imgptr, *imgptr, 0); + break; + + case 2: + /* Rotate: Flip both axises: flip_mode=-1 */ + cv::flip(*imgptr, *imgptr, -1); + break; + + case 3: + /* Rotate: transpose and flip around vertical axis: flip_mode=1 */ + cv::transpose(*imgptr, *imgptr); + cv::flip(*imgptr, *imgptr, 1); + break; + } +} + +static void img_cv_rotate (class cv::Mat *imgptr, void *data) +{ + class cv::Mat map_matrix; + + /* Data */ + struct Img_Iface_Data_Rotate *data_cast; + data_cast = (struct Img_Iface_Data_Rotate *)data; + + /* Angle of rotation */ + class cv::Point_ *center; + center = &(data_cast->center); + double angle; + angle = data_cast->angle; + + /* 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)); + + /* clean up */ + map_matrix.release(); +} + +/* ----- Miscellaneous image transformations */ +static void img_cv_adaptive_thr (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Adaptive_Thr *data_cast; + data_cast = (struct Img_Iface_Data_Adaptive_Thr *)data; + + /* Threshold method */ + int method; + method = data_cast->method; + /* Threshold type */ + int thr_typ; + thr_typ = data_cast->thr_typ; + /* Neighbourhood size */ + int ksize; + ksize = data_cast->ksize; + if (!(ksize % 2)) { + ksize++; + } + + /* Apply adaptive threshold */ + cv::adaptiveThreshold(*imgptr, *imgptr, 255, method, thr_typ, ksize, + 0); +} + +static void img_cv_cvt_color (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Cvt_Color *data_cast; + data_cast = (struct Img_Iface_Data_Cvt_Color *)data; + + /* Conversion method */ + int method; + method = data_cast->method; + + cv::cvtColor(*imgptr, *imgptr, method, 0); +} + +static void img_cv_distance_transform (class cv::Mat *imgptr) +{ + class cv::Mat imgtmp; + + /* Get transform */ + cv::distanceTransform(*imgptr, imgtmp, CV_DIST_L2, CV_DIST_MASK_PRECISE); + + /* DistanceTransform gives CV_32F image */ + imgtmp.convertTo(*imgptr, CV_8U); + + /* Cleanup */ + imgtmp.release(); +} + +static void img_cv_threshold (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Threshold *data_cast; + data_cast = (struct Img_Iface_Data_Threshold *)data; + + /* Threshold type */ + int thr_typ; + thr_typ = data_cast->thr_typ; + /* Threshold value */ + int thr_val; + thr_val = data_cast->thr_val; + if (thr_val == -1) { + thr_typ |= cv::THRESH_OTSU; + } + + /* Threshold */ + cv::threshold(*imgptr, *imgptr, thr_val, 0xFF, thr_typ); +} + +/* ----- Histograms */ +static void img_cv_histogram (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Histogram *data_cast; + data_cast = (struct Img_Iface_Data_Histogram *)data; + + /* Contours */ + class cv::Mat *hist; + hist = data_cast->hist_c0; + class cv::Mat *hist_img; + hist_img = data_cast->hist_img; + + /* Write components into cmp_img[] */ + int h_size = 256; + float h_range_arr[] = {0.0, 256.0}; + const float *h_range = {h_range_arr}; + cv::calcHist(imgptr, 1, 0, cv::Mat(), *hist, 1, &h_size, &h_range, + true, false); + + /* Init */ + hist_img->setTo(cv::Scalar(0)); + + /* Normalize the result to [0, hist_img->rows - 1] */ + cv::normalize(*hist, *hist, 0, hist_img->rows - 1, cv::NORM_MINMAX, -1, + cv::Mat()); + + /* Draw hist into hist_img */ + int i; + for(i = 0; i < 256; i++ ) { + cv::line(*hist_img, cv::Point(i, hist_img->rows - 0), + cv::Point(i, hist_img->rows - hist->at(i)), + cv::Scalar(255, 0, 0), 1, 8, 0); + } + + /* Show histogram */ + img_iface_show_hist_c1(); +} + +static void img_cv_histogram_c3 (class cv::Mat *imgptr, void *data) +{ + class cv::Mat cmp_img[3]; + + /* Write components into cmp_img[] */ + cv::split(*imgptr, cmp_img); + + /* Data */ + struct Img_Iface_Data_Histogram *data_cast; + data_cast = (struct Img_Iface_Data_Histogram *)data; + + /* Contours */ + class cv::Mat *hist_c0; + hist_c0 = data_cast->hist_c0; + class cv::Mat *hist_c1; + hist_c1 = data_cast->hist_c1; + class cv::Mat *hist_c2; + hist_c2 = data_cast->hist_c2; + class cv::Mat *hist_img; + hist_img = data_cast->hist_img; + + /* Write components into cmp_img[] */ + int h_size = 256; + float h_range_arr[] = {0.0, 256.0}; + const float *h_range = {h_range_arr}; + cv::calcHist(&cmp_img[0], 1, 0, cv::Mat(), *hist_c0, 1, &h_size, + &h_range, true, false); + cv::calcHist(&cmp_img[1], 1, 0, cv::Mat(), *hist_c1, 1, &h_size, + &h_range, true, false); + cv::calcHist(&cmp_img[2], 1, 0, cv::Mat(), *hist_c2, 1, &h_size, + &h_range, true, false); + + /* Init */ + hist_img->setTo(cv::Scalar(0)); + + /* Normalize the result to [0, hist_img->rows - 1] */ + cv::normalize(*hist_c0, *hist_c0, 0, hist_img->rows - 1, + cv::NORM_MINMAX, -1, cv::Mat()); + cv::normalize(*hist_c1, *hist_c1, 0, hist_img->rows - 1, + cv::NORM_MINMAX, -1, cv::Mat()); + cv::normalize(*hist_c2, *hist_c2, 0, hist_img->rows - 1, + cv::NORM_MINMAX, -1, cv::Mat()); + + /* Draw hist into hist_img */ + int i; + for(i = 0; i < 256; i++ ) { + cv::line(*hist_img, cv::Point(3*i, hist_img->rows - 0), + cv::Point(3*i, + hist_img->rows - hist_c0->at(i)), + cv::Scalar(255, 0, 0), 1, 8, 0); + } + for(i = 0; i < 256; i++ ) { + cv::line(*hist_img, cv::Point(3*i + 1, hist_img->rows - 0), + cv::Point(3*i+1, + hist_img->rows - hist_c1->at(i)), + cv::Scalar(0, 255, 0), 1, 8, 0); + } + for(i = 0; i < 256; i++ ) { + cv::line(*hist_img, cv::Point(3*i + 2, hist_img->rows - 0), + cv::Point(3*i + 2, + hist_img->rows - hist_c2->at(i)), + cv::Scalar(0, 0, 255), 1, 8, 0); + } + + /* Show histogram */ + img_iface_show_hist_c3(); + + /* Cleanup */ + cmp_img[0].release(); + cmp_img[1].release(); + cmp_img[2].release(); +} + +/* ----- Structural analysis and shape descriptors */ +static void img_cv_contours (class cv::Mat *imgptr, void *data) +{ + struct Img_Iface_Data_Contours *data_cast; + class std::vector >> *contours; + class cv::Mat *hierarchy; + + /* Data */ + data_cast = (struct Img_Iface_Data_Contours *)data; + + /* Contours */ + contours = data_cast->contours; + hierarchy = data_cast->hierarchy; + + /* Get contours */ + + cv::findContours(*imgptr, *contours, *hierarchy, CV_RETR_EXTERNAL, + CV_CHAIN_APPROX_SIMPLE); + + /* Set image to black */ + imgptr->setTo(cv::Scalar(0)); + + /* Draw contours in color */ + cv::drawContours(*imgptr, *contours, -1, cv::Scalar(255), 1, 8, + *hierarchy, 1, cvPoint(0, 0)); +} + +static void img_cv_contours_size (void *data) +{ + struct Img_Iface_Data_Contours_Size *data_cast; + class std::vector >> *contours; + int i; + + /* Data */ + data_cast = (struct Img_Iface_Data_Contours_Size *)data; + + /* Contours */ + contours = data_cast->contours; + + /* Get area and perimeter */ + if (data_cast->area) { + for (i = 0; i < (int)contours->size(); i++) { + data_cast->area[i] = cv::contourArea( + (*contours)[i], false); + } + } + if (data_cast->perimeter) { + for (i = 0; i < (int)contours->size(); i++) { + data_cast->perimeter[i] = cv::arcLength( + (*contours)[i], true); + } + } +} + +static void img_cv_bounding_rect (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Bounding_Rect *data_cast; + data_cast = (struct Img_Iface_Data_Bounding_Rect *)data; + + /* Contours */ + class std::vector > *contour; + contour = data_cast->contour; + /* Rotated rectangle */ + class cv::Rect_ *rect; + rect = data_cast->rect; + /* Show rectangle ? */ + bool show; + show = data_cast->show; + + /* Get rectangle */ + *rect = cv::boundingRect(*contour); + + /* Draw rectangle */ + class cv::Point_ vertices[4]; + if (show) { + vertices[0].x = rect->x; + vertices[0].y = rect->y; + vertices[1].x = rect->x + rect->width; + vertices[1].y = rect->y; + vertices[2].x = rect->x + rect->width; + vertices[2].y = rect->y + rect->height; + vertices[3].x = rect->x; + vertices[3].y = rect->y + rect->height; + 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) +{ + /* Data */ + struct Img_Iface_Data_MinARect *data_cast; + data_cast = (struct Img_Iface_Data_MinARect *)data; + + /* Contours */ + class std::vector > *contour; + contour = data_cast->contour; + /* Rotated rectangle */ + class cv::RotatedRect *rect; + rect = data_cast->rect; + /* Show rectangle ? */ + bool show; + show = data_cast->show; + + /* Get rectangle */ + *rect = cv::fitEllipse(*contour); + + /* Draw rectangle */ + class cv::Point_ vertices[4]; + 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_min_area_rect (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_MinARect *data_cast; + data_cast = (struct Img_Iface_Data_MinARect *)data; + + /* Contours */ + class std::vector > *contour; + contour = data_cast->contour; + /* 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_ vertices[4]; + 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); + } +} + +/* ----- Feature detection */ +static void img_cv_hough_circles (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Hough_Circles *data_cast; + data_cast = (struct Img_Iface_Data_Hough_Circles *)data; + + /* Contours */ + class std::vector > *circles; + circles = data_cast->circles; + /* Parameters */ + double dist_min; + double param_1; + double param_2; + int radius_min; + int radius_max; + dist_min = data_cast->dist_min; + param_1 = data_cast->param_1; + param_2 = data_cast->param_2; + radius_min = data_cast->radius_min; + radius_max = data_cast->radius_max; + + /* Get circles */ + cv::HoughCircles(*imgptr, *circles, CV_HOUGH_GRADIENT, 1, dist_min, + param_1, param_2, radius_min, radius_max); + + /* Set image to black */ + imgptr->setTo(cv::Scalar(0)); + + /* Draw circles */ + class cv::Point_ center; + int radius; + int i; + for (i = 0; i < (int)circles->size(); i++) { + center.x = cvRound((*circles)[i][0]); + center.y = cvRound((*circles)[i][1]); + radius = cvRound((*circles)[i][2]); + + /* Draw the circle center */ +/* cv::circle(*imgptr, center, 3, + cv::Scalar(0, 255, 0), -1, 8, 0);*/ + + /* Draw the circle outline */ + cv::circle(*imgptr, center, radius, + cv::Scalar(250), 1, 8, 0); + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/src/img_iface.cpp b/modules/image/src/img_iface.cpp index 3bdcf09..c252916 100644 --- a/modules/image/src/img_iface.cpp +++ b/modules/image/src/img_iface.cpp @@ -1,2010 +1,2010 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* errno */ - #include - /* INFINITY */ - #include - #include - /* snprintf() */ - #include - -/* Standard C++ --------------------------------------------------------------*/ - /* class std::vector */ - #include - -/* Packages ------------------------------------------------------------------*/ - /* openCV */ - #include - -/* Project -------------------------------------------------------------------*/ - /* load_image_file() */ - #include "save.hpp" - /* user_iface_log */ - #include "user_iface.hpp" - -/* Module --------------------------------------------------------------------*/ - /* img_alx_act() */ - #include "img_alx.hpp" - /* img_cv_act() */ - #include "img_cv.hpp" - /* img_orb_act() */ - #include "img_orb.hpp" - /* img_calib3d_act() */ - #include "img_calib3d.hpp" - /* img_zb_act() */ - #include "img_zbar.hpp" - /* img_ocr_act() */ - #include "img_ocr.hpp" - - #include "img_iface.hpp" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define IMG_MEM_SIZE (20) - - # define WIN_NAME_IMG "Image" - # define WIN_NAME_HIST "Hist" - # define WIN_TIMEOUT (500) - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ - char img_ocr_text [OCR_TEXT_MAX]; - struct Img_Iface_ZB_Codes zb_codes; - -/* Static --------------------------------------------------------------------*/ -static class cv::Mat image_copy_old; -static class cv::Mat image_copy_tmp; -static class cv::Mat image_mem [IMG_MEM_SIZE]; -static class cv::Mat image_ref; -static class cv::Mat histogram_c0; -static class cv::Mat histogram_c1; -static class cv::Mat histogram_c2; -static class cv::Mat hist_img_c1; -static class cv::Mat hist_img_c3; -static class std::vector >> contours; -static double area [CONTOURS_MAX]; -static double perimeter [CONTOURS_MAX]; -static class cv::Mat hierarchy; -static class cv::Rect_ rectangle; -static class cv::RotatedRect rectangle_rot; -static class std::vector > circles; -static class cv::Mat intrinsic_mat; -static class cv::Mat dist_coefs; -static class std::vector rvecs; -static class std::vector tvecs; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ - /* img_alx */ -static void img_iface_local_max (void); -static void img_iface_skeleton (void); -static void img_iface_lines_horizontal (void); -static void img_iface_lines_vertical (void); -static void img_iface_mean_horizontal (void); -static void img_iface_mean_vertical (void); -static void img_iface_median_horizontal (void); -static void img_iface_median_vertical (void); - - /* img_cv */ - /* Core: The core functionality */ - /* Pixel */ -static void img_iface_pixel_get (void *data); -static void img_iface_pixel_set (void *data); - /* ROI */ -static void img_iface_set_ROI (void *data); -static void img_iface_set_ROI_2rect (void *data); - /* Operations on Arrays */ -static void img_iface_and_2ref (void); -static void img_iface_not (void); -static void img_iface_or_2ref (void); -static void img_iface_component (void *data); - /* Imgproc: Image processing */ - /* Image filtering */ -static void img_iface_dilate (void *data); -static void img_iface_erode (void *data); -static void img_iface_dilate_erode (void *data); -static void img_iface_erode_dilate (void *data); -static void img_iface_smooth (void *data); -static void img_iface_sobel (void *data); -static void img_iface_border (void *data); - /* Geometric image transformations */ -static void img_iface_mirror (void *data); -static void img_iface_rotate_orto (void *data); -static void img_iface_rotate (void *data); -static void img_iface_rotate_2rect (void *data); - /* Miscellaneous image transformations */ -static void img_iface_adaptive_thr (void *data); -static void img_iface_cvt_color (void *data); -static void img_iface_distance_transform (void); -static void img_iface_threshold (void *data); - /* Histograms */ -static void img_iface_histogram (void *data); -static void img_iface_histogram_c3 (void *data); - /* Structural analysis and shape descriptors */ -static void img_iface_contours (void *data); -static void img_iface_contours_size (void *data); -static void img_iface_bounding_rect (void *data); -static void img_iface_fit_ellipse (void *data); -static void img_iface_min_area_rect (void *data); - /* Feature detection */ -static void img_iface_hough_circles (void *data); - - /* img_orb */ -static void img_iface_align (void); - /* img_calib3d */ -static void img_iface_calibrate (void *data); -static void img_iface_undistort (void *data); - - /* img_zbar */ -static void img_iface_decode (void *data); - /* img_ocr */ -static void img_iface_read (void *data); - - /* img_iface */ -static void img_iface_apply (void); -static void img_iface_discard (void); -static void img_iface_save_mem (void *data); -static void img_iface_load_mem (void *data); -static void img_iface_save_ref (void); - /* save */ -static void img_iface_save_file (void); -static void img_iface_save_update (void); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -void img_iface_init (void) -{ - 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); - hist_img_c3.release(); - hist_img_c3 = cv::Mat::zeros(cv::Size(256 * 3, 100), CV_8UC3); -} - -void img_iface_cleanup_main (void) -{ - int i; - - for (i = 0; i < IMG_MEM_SIZE; i++) { - image_mem[i].release(); - } - image_ref.release(); - - cv::destroyAllWindows(); -} - -void img_iface_load (const char *fpath, const char *fname) -{ - char file_path [FILENAME_MAX]; - char file_name [FILENAME_MAX]; - - /* Init */ - img_iface_init(); - - /* Set file_path */ - if (!fpath) { - snprintf(file_path, FILENAME_MAX, "%s", saved_path); - } else { - snprintf(file_path, FILENAME_MAX, "%s", fpath); - } - - /* Set file_name */ - if (!fname) { - /* Request file name */ - user_iface_fname(file_path, file_name); - } else { - snprintf(file_name, FILENAME_MAX, "%s", fname); - } - - /* Load file */ - errno = 0; - load_image_file(file_path, file_name); - - if (!errno) { - /* Make a static copy of image */ - image.copyTo(image_copy_old); - image.copyTo(image_copy_tmp); - } -} - -void img_iface_cleanup (void) -{ - image_copy_old.release(); - image_copy_tmp.release(); - histogram_c0.release(); - histogram_c1.release(); - histogram_c2.release(); - hist_img_c1.release(); - hist_img_c3.release(); -} - -void img_iface_act (int action, void *data) -{ - switch (action) { - /* img_alx */ - case IMG_IFACE_ACT_LOCAL_MAX: - img_iface_local_max(); - break; - case IMG_IFACE_ACT_SKELETON: - img_iface_skeleton(); - break; - case IMG_IFACE_ACT_LINES_HORIZONTAL: - img_iface_lines_horizontal(); - break; - case IMG_IFACE_ACT_LINES_VERTICAL: - img_iface_lines_vertical(); - break; - case IMG_IFACE_ACT_MEAN_HORIZONTAL: - img_iface_mean_horizontal(); - break; - case IMG_IFACE_ACT_MEAN_VERTICAL: - img_iface_mean_vertical(); - break; - case IMG_IFACE_ACT_MEDIAN_HORIZONTAL: - img_iface_median_horizontal(); - break; - case IMG_IFACE_ACT_MEDIAN_VERTICAL: - img_iface_median_vertical(); - break; - - /* img_cv */ - /* Core: The core functionality */ - /* Pixel */ - case IMG_IFACE_ACT_PIXEL_GET: - img_iface_pixel_get(data); - break; - case IMG_IFACE_ACT_PIXEL_SET: - img_iface_pixel_set(data); - break; - /* ROI */ - case IMG_IFACE_ACT_SET_ROI: - img_iface_set_ROI(data); - break; - case IMG_IFACE_ACT_SET_ROI_2RECT: - img_iface_set_ROI_2rect(data); - break; - /* Operations on Arrays */ - case IMG_IFACE_ACT_AND_2REF: - img_iface_and_2ref(); - break; - case IMG_IFACE_ACT_NOT: - img_iface_not(); - break; - case IMG_IFACE_ACT_OR_2REF: - img_iface_or_2ref(); - break; - case IMG_IFACE_ACT_COMPONENT: - img_iface_component(data); - break; - /* Imgproc: Image processing */ - /* Image filtering */ - case IMG_IFACE_ACT_DILATE: - img_iface_dilate(data); - break; - case IMG_IFACE_ACT_ERODE: - img_iface_erode(data); - break; - case IMG_IFACE_ACT_DILATE_ERODE: - img_iface_dilate_erode(data); - break; - case IMG_IFACE_ACT_ERODE_DILATE: - img_iface_erode_dilate(data); - break; - case IMG_IFACE_ACT_SMOOTH: - img_iface_smooth(data); - break; - case IMG_IFACE_ACT_SOBEL: - img_iface_sobel(data); - break; - case IMG_IFACE_ACT_BORDER: - img_iface_border(data); - break; - /* Geometric image transformations */ - case IMG_IFACE_ACT_MIRROR: - img_iface_mirror(data); - break; - case IMG_IFACE_ACT_ROTATE_ORTO: - img_iface_rotate_orto(data); - break; - case IMG_IFACE_ACT_ROTATE: - img_iface_rotate(data); - break; - case IMG_IFACE_ACT_ROTATE_2RECT: - img_iface_rotate_2rect(data); - break; - /* Miscellaneous image transformations */ - case IMG_IFACE_ACT_ADAPTIVE_THRESHOLD: - img_iface_adaptive_thr(data); - break; - case IMG_IFACE_ACT_CVT_COLOR: - img_iface_cvt_color(data); - break; - case IMG_IFACE_ACT_DISTANCE_TRANSFORM: - img_iface_distance_transform(); - break; - case IMG_IFACE_ACT_THRESHOLD: - img_iface_threshold(data); - break; - /* Histograms */ - case IMG_IFACE_ACT_HISTOGRAM: - img_iface_histogram(data); - break; - case IMG_IFACE_ACT_HISTOGRAM_C3: - img_iface_histogram_c3(data); - break; - /* Structural analysis and shape descriptors */ - case IMG_IFACE_ACT_CONTOURS: - img_iface_contours(data); - break; - case IMG_IFACE_ACT_CONTOURS_SIZE: - img_iface_contours_size(data); - break; - case IMG_IFACE_ACT_BOUNDING_RECT: - img_iface_bounding_rect(data); - break; - case IMG_IFACE_ACT_FIT_ELLIPSE: - img_iface_fit_ellipse(data); - break; - case IMG_IFACE_ACT_MIN_AREA_RECT: - img_iface_min_area_rect(data); - break; - /* Feature detection */ - case IMG_IFACE_ACT_HOUGH_CIRCLES: - img_iface_hough_circles(data); - break; - - /* img_orb */ - case IMG_IFACE_ACT_ALIGN: - img_iface_align(); - break; - - /* img_calib3d */ - case IMG_IFACE_ACT_CALIBRATE: - img_iface_calibrate(data); - break; - case IMG_IFACE_ACT_UNDISTORT: - img_iface_undistort(data); - break; - - /* img_zbar */ - case IMG_IFACE_ACT_DECODE: - img_iface_decode(data); - break; - - /* img_ocr */ - case IMG_IFACE_ACT_READ: - img_iface_read(data); - break; - - /* img_iface */ - case IMG_IFACE_ACT_APPLY: - img_iface_apply(); - break; - case IMG_IFACE_ACT_DISCARD: - img_iface_discard(); - break; - case IMG_IFACE_ACT_SAVE_MEM: - img_iface_save_mem(data); - break; - case IMG_IFACE_ACT_LOAD_MEM: - img_iface_load_mem(data); - break; - case IMG_IFACE_ACT_SAVE_REF: - img_iface_save_ref(); - break; - - /* save */ - case IMG_IFACE_ACT_SAVE_FILE: - img_iface_save_file(); - break; - case IMG_IFACE_ACT_SAVE_UPDT: - img_iface_save_update(); - break; - - default: - /* Invalid action */ - break; - } -} - -void img_iface_show_img (void) -{ - cv::imshow(WIN_NAME_IMG, image_copy_tmp); - cv::waitKey(WIN_TIMEOUT); -} - -void img_iface_show_hist_c1 (void) -{ - cv::imshow(WIN_NAME_HIST, hist_img_c1); - cv::waitKey(WIN_TIMEOUT); -} - -void img_iface_show_hist_c3 (void) -{ - cv::imshow(WIN_NAME_HIST, hist_img_c3); - cv::waitKey(WIN_TIMEOUT); -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -/* img_alx --------------------------------------------------------------------*/ -static void img_iface_local_max (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Local maxima */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_LOCAL_MAX, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Local maxima"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_skeleton (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Skeleton */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_SKELETON, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Skeleton"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_lines_horizontal (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Horizontal lines */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_LINES_HORIZONTAL, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Horizontal lines"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_lines_vertical (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Vertical lines */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_LINES_VERTICAL, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Vertical lines"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_mean_horizontal (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Horizontal lines */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEAN_HORIZONTAL, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Horizontal mean"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_mean_vertical (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Horizontal lines */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEAN_VERTICAL, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Vertical mean"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_median_horizontal (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Horizontal lines */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEDIAN_HORIZONTAL, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Horizontal median"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_median_vertical (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Horizontal lines */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEDIAN_VERTICAL, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Vertical median"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -/* img_cv --------------------------------------------------------------------*/ -/* ----- Core: The core functionality */ -/* ----- ------- Pixel */ -static void img_iface_pixel_get (void *data) -{ - struct Img_Iface_Data_Pixel_Get data_tmp; - struct Img_Iface_Data_Pixel_Get *data_cast; - unsigned char val; - char title [80]; - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - if (!data) { - data_tmp.val = &val; - - /* Ask user */ - 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; - } - - /* Get pixel value */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_PIXEL_GET, data); - - /* Write into log */ - data_cast = (struct Img_Iface_Data_Pixel_Get *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Pixel get: (%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)++; -} - -static void img_iface_pixel_set (void *data) -{ - struct Img_Iface_Data_Pixel_Set data_tmp; - struct Img_Iface_Data_Pixel_Set *data_cast; - char title [80]; - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - if (!data) { - /* Ask user */ - 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); - - snprintf(title, 80, "val:"); - data_tmp.val = user_iface_getint(0, 0, 255, - title, NULL); - - data = (void *)&data_tmp; - } - - /* Set pixel value */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_PIXEL_SET, data); - - /* Write into log */ - data_cast = (struct Img_Iface_Data_Pixel_Set *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Pixel get: (%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)++; -} - -/* ----- ------- ROI */ -static void img_iface_set_ROI (void *data) -{ - struct Img_Iface_Data_SetROI data_tmp; - struct Img_Iface_Data_SetROI *data_cast; - char title [80]; - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Origin: x:"); - data_tmp.rect.x = user_iface_getint(0, 0, - image_copy_tmp.cols, - title, NULL); - - snprintf(title, 80, "Origin: y:"); - data_tmp.rect.y = user_iface_getint(0, 0, - image_copy_tmp.rows, - title, NULL); - - snprintf(title, 80, "Width:"); - data_tmp.rect.width = user_iface_getint(1, - image_copy_tmp.cols - data_tmp.rect.x, - image_copy_tmp.cols - data_tmp.rect.x, - title, NULL); - - snprintf(title, 80, "Height:"); - data_tmp.rect.height = user_iface_getint(1, - image_copy_tmp.rows - data_tmp.rect.y, - image_copy_tmp.rows - data_tmp.rect.y, - title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - data_cast = (struct Img_Iface_Data_SetROI *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "ROI: (%i,%i) w=%i,h=%i", - data_cast->rect.x, - data_cast->rect.y, - data_cast->rect.width, - data_cast->rect.height); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Set ROI */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_SET_ROI, data); -} - -static void img_iface_set_ROI_2rect (void *data) -{ - struct Img_Iface_Data_SetROI data_tmp; - struct Img_Iface_Data_SetROI *data_cast; - - /* Data */ - if (!data) { - data_tmp.rect.x = rectangle.x; - data_tmp.rect.y = rectangle.y; - data_tmp.rect.width = rectangle.width; - data_tmp.rect.height = rectangle.height; - - data = (void *)&data_tmp; - } - - /* Write into log */ - data_cast = (struct Img_Iface_Data_SetROI *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "ROI: (%i,%i) w=%i,h=%i", - data_cast->rect.x, - data_cast->rect.y, - data_cast->rect.width, - data_cast->rect.height); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Set ROI */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_SET_ROI, data); -} - -/* ----- ------- Operations on arrays */ -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_not (void) -{ - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Invert color"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* 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_component (void *data) -{ - /* Must have at least 3 channels */ - if (image_copy_tmp.channels() < 3) { - /* 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; - } - - /* Data */ - struct Img_Iface_Data_Component data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Component:"); - data_tmp.cmp = user_iface_getint(0, 0, - image_copy_tmp.channels() - 1, - title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Component *data_cast; - data_cast = (struct Img_Iface_Data_Component *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Component %i", - data_cast->cmp); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Filter: extract component */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_COMPONENT, data); -} - -/* ----- Imgproc: Image processing */ -/* ----- ------- Image filtering */ -static void img_iface_dilate (void *data) -{ - /* Data */ - struct Img_Iface_Data_Dilate_Erode data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Iterations:"); - data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Dilate_Erode *data_cast; - data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Dilate i=%i", - data_cast->i); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Dilate */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data); -} - -static void img_iface_erode (void *data) -{ - /* Data */ - struct Img_Iface_Data_Dilate_Erode data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Iterations:"); - data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Dilate_Erode *data_cast; - data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Erode i=%i", - data_cast->i); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Erode */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data); -} - -static void img_iface_dilate_erode (void *data) -{ - /* Data */ - struct Img_Iface_Data_Dilate_Erode data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Iterations:"); - data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Dilate_Erode *data_cast; - data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Dilate-erode i=%i", - data_cast->i); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Dilate */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data); - img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data); -} - -static void img_iface_erode_dilate (void *data) -{ - /* Data */ - struct Img_Iface_Data_Dilate_Erode data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Iterations:"); - data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Dilate_Erode *data_cast; - data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Erode-dilate i=%i", - data_cast->i); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Dilate */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data); - img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data); -} - -static void img_iface_smooth (void *data) -{ - /* Data */ - struct Img_Iface_Data_Smooth data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Method: MEAN=1, GAUSS=2, MEDIAN=3"); - data_tmp.method = user_iface_getint(1, 3, 3, title, NULL); - - snprintf(title, 80, "Kernel size: 3, 5, 7, ..."); - data_tmp.ksize = user_iface_getint(3, 3, INFINITY, title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Smooth *data_cast; - data_cast = (struct Img_Iface_Data_Smooth *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Smooth mth=%i [%ix%i]", - data_cast->method, - data_cast->ksize, - data_cast->ksize); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Filter: smooth */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_SMOOTH, data); -} - -static void img_iface_sobel (void *data) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - struct Img_Iface_Data_Sobel data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Order of the derivative x"); - data_tmp.dx = user_iface_getint(0, 1, 10, title, NULL); - - snprintf(title, 80, "Order of the derivative y"); - data_tmp.dy = user_iface_getint(0, 1, 10, title, NULL); - - snprintf(title, 80, "Size of the extended Sobel kernel (-1 -> Scharr"); - data_tmp.ksize = user_iface_getint(-1, 3, 7, title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Sobel *data_cast; - data_cast = (struct Img_Iface_Data_Sobel *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Sobel dx=%i;dy=%i [ks=%i]", - data_cast->dx, - data_cast->dy, - data_cast->ksize); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Filter: sobel */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_SOBEL, data); -} - -static void img_iface_border (void *data) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - struct Img_Iface_Data_Border data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Size"); - data_tmp.size = user_iface_getint(1, 1, 0xF000, title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Border *data_cast; - data_cast = (struct Img_Iface_Data_Border *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Border size=%i", - data_cast->size); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Add border */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_BORDER, data); -} - -/* ----- ------- Geometric image transformations */ -static void img_iface_mirror (void *data) -{ - /* Data */ - struct Img_Iface_Data_Mirror data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Axis: 0=x; 1=y"); - data_tmp.axis = user_iface_getint(0, 1, 1, title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Mirror *data_cast; - data_cast = (struct Img_Iface_Data_Mirror *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Mirror axis: %i", - data_cast->axis); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Mirror */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_MIRROR, data); -} - -static void img_iface_rotate_orto (void *data) -{ - /* Data */ - struct Img_Iface_Data_Rotate_Orto data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Rotate (counterclockwise) n * pi/2 rad; n:"); - data_tmp.n = user_iface_getint(1, 1, 3, title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Rotate_Orto *data_cast; - data_cast = (struct Img_Iface_Data_Rotate_Orto *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Rotate %i * pi/2 rad", - data_cast->n); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Rotate ortogonally */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE_ORTO, data); -} - -static void img_iface_rotate (void *data) -{ - /* Data */ - struct Img_Iface_Data_Rotate data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Center: x:"); - data_tmp.center.x = user_iface_getdbl(0, 0, INFINITY, title, NULL); - - snprintf(title, 80, "Center: y:"); - data_tmp.center.y = user_iface_getdbl(0, 0, INFINITY, title, NULL); - - snprintf(title, 80, "Angle: (deg)"); - data_tmp.angle = user_iface_getdbl(-INFINITY, 0, INFINITY, title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Rotate *data_cast; - data_cast = (struct Img_Iface_Data_Rotate *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Rotate (%.2f,%.2f) %lfº", - data_cast->center.x, - data_cast->center.y, - data_cast->angle); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Rotate ortogonally */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE, data); -} - -static void img_iface_rotate_2rect (void *data) -{ - /* Data */ - struct Img_Iface_Data_Rotate data_tmp; - if (!data) { - data_tmp.center.x = rectangle_rot.center.x; - data_tmp.center.y = rectangle_rot.center.y; - data_tmp.angle = rectangle_rot.angle; - - /* If angle is < -45º, it is taking into acount the incorrect side */ - if (data_tmp.angle < -45.0) { - data_tmp.angle += 90.0; - } - - data = (void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Rotate to rectangle"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Rotate ortogonally */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE, data); -} - -/* ----- ------- Miscellaneous image transformations */ -static void img_iface_adaptive_thr (void *data) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - struct Img_Iface_Data_Adaptive_Thr data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Method: MEAN=0, GAUSS=1"); - data_tmp.method = user_iface_getint(0, 1, 1, title, NULL); - - snprintf(title, 80, "Type: BIN=0, BIN_INV=1"); - data_tmp.thr_typ = user_iface_getint(0, 0, 1, title, NULL); - - snprintf(title, 80, "Kernel size: 3, 5, 7, ..."); - data_tmp.ksize = user_iface_getint(3, 3, INFINITY, title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Adaptive_Thr *data_cast; - data_cast = (struct Img_Iface_Data_Adaptive_Thr *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Threshold mth=%i, typ=%i, ks=%i", - data_cast->method, - data_cast->thr_typ, - data_cast->ksize); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Filter: adaptive threshold */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_ADAPTIVE_THRESHOLD, data); -} - -static void img_iface_cvt_color (void *data) -{ - /* Must have at least 3 channels */ - if (image_copy_tmp.channels() < 3) { - /* 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; - } - - /* Data */ - struct Img_Iface_Data_Cvt_Color data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Method: BGR2GRAY = 6, BGR2HSV = 40"); - data_tmp.method = user_iface_getint(0, 0, - cv::COLOR_COLORCVT_MAX, - title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Cvt_Color *data_cast; - data_cast = (struct Img_Iface_Data_Cvt_Color *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Convert color %i", - data_cast->method); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Filter: BGR to gray */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_CVT_COLOR, data); -} - -static void img_iface_distance_transform (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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, - "Distance transform"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Distance transform */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_DISTANCE_TRANSFORM, NULL); -} - -static void img_iface_threshold (void *data) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - struct Img_Iface_Data_Threshold data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Type: BIN=0, BIN_INV=1, TRUNC=2, TOZ=3, TOZ_INV=4"); - data_tmp.thr_typ = user_iface_getint(0, 0, 4, title, NULL); - - snprintf(title, 80, "Value: 0 to 255 (or -1 for Otsu's algorithm)"); - data_tmp.thr_val = user_iface_getint(-1, 0, 255, title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Threshold *data_cast; - data_cast = (struct Img_Iface_Data_Threshold *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Threshold typ=%i, val=%i", - data_cast->thr_typ, - data_cast->thr_val); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Filter: threshold */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_THRESHOLD, data); -} - -/* ----- ------- Histograms */ -static void img_iface_histogram (void *data) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - struct Img_Iface_Data_Histogram data_tmp; - if (!data) { - data_tmp.hist_c0 = &histogram_c0; - data_tmp.hist_img = &hist_img_c1; - - data = (void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Histogram"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Histogram */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_HISTOGRAM, data); -} - -static void img_iface_histogram_c3 (void *data) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 3) { - /* 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; - } - - /* Data */ - struct Img_Iface_Data_Histogram data_tmp; - if (!data) { - data_tmp.hist_c0 = &histogram_c0; - data_tmp.hist_c1 = &histogram_c1; - data_tmp.hist_c2 = &histogram_c2; - data_tmp.hist_img = &hist_img_c3; - - data = (void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Histogram (3 channels)"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Histogram */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_HISTOGRAM_C3, data); -} - -/* ----- ------- Structural analysis and shape descriptors */ -static void img_iface_contours (void *data) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - struct Img_Iface_Data_Contours data_tmp; - if (!data) { - data_tmp.contours = &contours; - data_tmp.hierarchy = &hierarchy; - - data = (void *)&data_tmp; - } - - /* Contours */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_CONTOURS, data); - - /* Write into log */ - struct Img_Iface_Data_Contours *data_cast; - data_cast = (struct Img_Iface_Data_Contours *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Contours n=%i", - (int)data_cast->contours->size()); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_contours_size (void *data) -{ - /* 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; - } - - /* Contours size */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_CONTOURS_SIZE, data); - - /* Write into log */ - struct Img_Iface_Data_Contours_Size *data_cast; - data_cast = (struct Img_Iface_Data_Contours_Size *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Contours size:"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - int i; - for (i = 0; i < (int)data_cast->contours->size(); i++) { - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "cnt[%i]: A=%lf; P=%lf;", - i, - data_cast->area[i], - data_cast->perimeter[i]); - user_iface_log.lvl[user_iface_log.len] = 2; - (user_iface_log.len)++; - } -} - -static void img_iface_bounding_rect (void *data) -{ - /* Data */ - struct Img_Iface_Data_Bounding_Rect data_tmp; - if (!data) { - if(!contours.size()) { - /* 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; - } - data_tmp.contour = &(contours[0]); - data_tmp.rect = &rectangle; - data_tmp.show = true; - - data = (void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Bounding rectangle"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Enclosing rectangle */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_BOUNDING_RECT, data); -} - -static void img_iface_fit_ellipse (void *data) -{ - /* Data */ - struct Img_Iface_Data_MinARect data_tmp; - if (!data) { - if(!contours.size()) { - /* 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; - } - data_tmp.contour = &(contours[0]); - - data_tmp.rect = &rectangle_rot; - - data = (void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Fit ellipse"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Enclosing rectangle */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_FIT_ELLIPSE, data); -} - -static void img_iface_min_area_rect (void *data) -{ - /* Data */ - struct Img_Iface_Data_MinARect data_tmp; - if (!data) { - if(!contours.size()) { - /* 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; - } - data_tmp.contour = &(contours[0]); - data_tmp.rect = &rectangle_rot; - data_tmp.show = true; - - data = (void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Min area rectangle"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Enclosing rectangle */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_MIN_AREA_RECT, data); -} - -/* ----- ------- Feature detection */ -static void img_iface_hough_circles (void *data) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - struct Img_Iface_Data_Hough_Circles data_tmp; - if (!data) { - data_tmp.circles = &circles; - - /* Ask user */ - char title [80]; - snprintf(title, 80, "Minimum distance:"); - data_tmp.dist_min = user_iface_getdbl(0, 5, INFINITY, title, NULL); - - snprintf(title, 80, "param 1:"); - data_tmp.param_1 = user_iface_getdbl(0, 200, INFINITY, title, NULL); - - snprintf(title, 80, "param 2:"); - data_tmp.param_2 = user_iface_getdbl(0, 100, INFINITY, title, NULL); - - snprintf(title, 80, "Minimum radius"); - data_tmp.radius_min = user_iface_getint(0, 10, INFINITY, title, NULL); - - snprintf(title, 80, "Maximum radius"); - data_tmp.radius_max = user_iface_getint(0, 0, INFINITY, title, NULL); - - data = (void *)&data_tmp; - } - - /* Circles */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_HOUGH_CIRCLES, data); - - /* Write into log */ - struct Img_Iface_Data_Hough_Circles *data_cast; - data_cast = (struct Img_Iface_Data_Hough_Circles *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Circles n=%i", - (int)data_cast->circles->size()); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -/* img_orb -------------------------------------------------------------------*/ -static void img_iface_align (void) -{ - /* Must have defined a reference */ - if (image_ref.empty()) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Reference is NULL"); - 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, - "Align to reference"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Align to reference image_ref */ - img_orb_act(&image_ref, &image_copy_tmp, IMG_ORB_ACT_ALIGN); -} - -/* img_calib3d ---------------------------------------------------------------*/ -static void img_iface_calibrate (void *data) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - struct Img_Iface_Data_Calibrate data_tmp; - if (!data) { - data_tmp.intrinsic_mat = &intrinsic_mat; - data_tmp.dist_coefs = &dist_coefs; - data_tmp.rvecs = &rvecs; - data_tmp.tvecs = &tvecs; - - data = (void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Calibrate"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Contours */ - img_calib3d_act(&image_copy_tmp, IMG_CALIB3D_ACT_CALIBRATE, data); -} - -static void img_iface_undistort (void *data) -{ - /* Data */ - struct Img_Iface_Data_Undistort data_tmp; - if (!data) { - data_tmp.intrinsic_mat = &intrinsic_mat; - data_tmp.dist_coefs = &dist_coefs; - - data = (void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Undistort"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Contours */ - img_calib3d_act(&image_copy_tmp, IMG_CALIB3D_ACT_UNDISTORT, data); -} - -/* img_zbar ------------------------------------------------------------------*/ -static void img_iface_decode (void *data) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - struct Img_Iface_Data_Decode data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Type of code: (0 for all)"); - data_tmp.code_type = (enum zbar::zbar_symbol_type_e) - user_iface_getint(0, 0, INT_MAX, - title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Decode *data_cast; - data_cast = (struct Img_Iface_Data_Decode *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Detect codes c=%i", - data_cast->code_type); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Decode */ - img_zb_act(&image_copy_tmp, IMG_ZB_ACT_DECODE, data); - - /* Results */ - if (!zb_codes.n) { - /* No text found */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! No code detected"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - } else { - /* Write results into log */ - int i; - for (i = 0; i < zb_codes.n; i++) { - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "%s -- '%s'", - zb_codes.arr[i].sym_name, - zb_codes.arr[i].data); - user_iface_log.lvl[user_iface_log.len] = 2; - (user_iface_log.len)++; - } - } -} - -/* img_ocr -------------------------------------------------------------------*/ -static void img_iface_read (void *data) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - struct Img_Iface_Data_Read data_tmp; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Language: ENG = 0, SPA = 1, CAT = 2"); - data_tmp.lang = user_iface_getint(0, 1, 2, title, NULL); - - snprintf(title, 80, "Config: none = 0, Price = 1"); - data_tmp.conf = user_iface_getint(0, 1, 2, title, NULL); - - data = (void *)&data_tmp; - } - - /* Write into log */ - struct Img_Iface_Data_Read *data_cast; - data_cast = (struct Img_Iface_Data_Read *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "OCR (lang=%i) [c=%i]", - data_cast->lang, - data_cast->conf); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Adapt image data */ - data_cast->img.data = image_copy_tmp.data; - data_cast->img.width = image_copy_tmp.size().width; - data_cast->img.height = image_copy_tmp.size().height; - data_cast->img.B_per_pix = image_copy_tmp.channels(); - data_cast->img.B_per_line = image_copy_tmp.step1(); - - /* OCR */ - img_ocr_act(IMG_OCR_ACT_READ, data); - - /* Results */ - if (img_ocr_text[0] == '\0') { - /* No text found */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! No text detected"); - user_iface_log.lvl[user_iface_log.len] = 2; - (user_iface_log.len)++; - } -} - -/* img_iface -----------------------------------------------------------------*/ -static void img_iface_apply (void) -{ - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Apply changes"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Write tmp into old */ - image_copy_old.release(); - image_copy_tmp.copyTo(image_copy_old); -} - -static void img_iface_discard (void) -{ - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Discard changes"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Discard tmp image copy */ - image_copy_tmp.release(); - image_copy_old.copyTo(image_copy_tmp); -} - -static void img_iface_save_mem (void *data) -{ - /* Which memory to use */ - int x; - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "mem_X; X:"); - x = user_iface_getint(0, 0, IMG_MEM_SIZE - 1, title, NULL); - } else { - x = *(int *)data; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Save to mem_%i", x); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Write into mem */ - image_mem[x].release(); - image_copy_tmp.copyTo(image_mem[x]); -} - -static void img_iface_load_mem (void *data) -{ - /* Which memory to use */ - int x; - if (!data) { - /* Ask user which memory to use */ - char title [80]; - snprintf(title, 80, "mem_X; X:"); - x = user_iface_getint(0, 0, IMG_MEM_SIZE - 1, title, NULL); - } else { - x = *(int *)data; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Load from mem_%i", x); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - if (!image_mem[x].empty()) { - /* Discard tmp image copy */ - image_copy_tmp.release(); - - /* Load from mem */ - image_mem[x].copyTo(image_copy_tmp); - } -} - -static void img_iface_save_ref (void) -{ - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Save to reference"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Write into ref */ - image_ref.release(); - image_copy_tmp.copyTo(image_ref); - image_ref = image_copy_tmp; -} - -/* save ----------------------------------------------------------------------*/ -static void img_iface_save_file (void) -{ - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Save as..."); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Write into image struct (save.c) */ - image.release(); - image_copy_tmp.copyTo(image); - - /* Save into file */ - save_image_file(NULL, NULL); -} - -static void img_iface_save_update (void) -{ - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Save: update img"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Write into image struct (save.c) */ - image.release(); - image_copy_tmp.copyTo(image); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* errno */ + #include + /* INFINITY */ + #include + #include + /* snprintf() */ + #include + +/* Standard C++ --------------------------------------------------------------*/ + /* class std::vector */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* openCV */ + #include + +/* Project -------------------------------------------------------------------*/ + /* load_image_file() */ + #include "save.hpp" + /* user_iface_log */ + #include "user_iface.hpp" + +/* Module --------------------------------------------------------------------*/ + /* img_alx_act() */ + #include "img_alx.hpp" + /* img_cv_act() */ + #include "img_cv.hpp" + /* img_orb_act() */ + #include "img_orb.hpp" + /* img_calib3d_act() */ + #include "img_calib3d.hpp" + /* img_zb_act() */ + #include "img_zbar.hpp" + /* img_ocr_act() */ + #include "img_ocr.hpp" + + #include "img_iface.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define IMG_MEM_SIZE (20) + + # define WIN_NAME_IMG "Image" + # define WIN_NAME_HIST "Hist" + # define WIN_TIMEOUT (500) + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ + char img_ocr_text [OCR_TEXT_MAX]; + struct Img_Iface_ZB_Codes zb_codes; + +/* Static --------------------------------------------------------------------*/ +static class cv::Mat image_copy_old; +static class cv::Mat image_copy_tmp; +static class cv::Mat image_mem [IMG_MEM_SIZE]; +static class cv::Mat image_ref; +static class cv::Mat histogram_c0; +static class cv::Mat histogram_c1; +static class cv::Mat histogram_c2; +static class cv::Mat hist_img_c1; +static class cv::Mat hist_img_c3; +static class std::vector >> contours; +static double area [CONTOURS_MAX]; +static double perimeter [CONTOURS_MAX]; +static class cv::Mat hierarchy; +static class cv::Rect_ rectangle; +static class cv::RotatedRect rectangle_rot; +static class std::vector > circles; +static class cv::Mat intrinsic_mat; +static class cv::Mat dist_coefs; +static class std::vector rvecs; +static class std::vector tvecs; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ + /* img_alx */ +static void img_iface_local_max (void); +static void img_iface_skeleton (void); +static void img_iface_lines_horizontal (void); +static void img_iface_lines_vertical (void); +static void img_iface_mean_horizontal (void); +static void img_iface_mean_vertical (void); +static void img_iface_median_horizontal (void); +static void img_iface_median_vertical (void); + + /* img_cv */ + /* Core: The core functionality */ + /* Pixel */ +static void img_iface_pixel_get (void *data); +static void img_iface_pixel_set (void *data); + /* ROI */ +static void img_iface_set_ROI (void *data); +static void img_iface_set_ROI_2rect (void *data); + /* Operations on Arrays */ +static void img_iface_and_2ref (void); +static void img_iface_not (void); +static void img_iface_or_2ref (void); +static void img_iface_component (void *data); + /* Imgproc: Image processing */ + /* Image filtering */ +static void img_iface_dilate (void *data); +static void img_iface_erode (void *data); +static void img_iface_dilate_erode (void *data); +static void img_iface_erode_dilate (void *data); +static void img_iface_smooth (void *data); +static void img_iface_sobel (void *data); +static void img_iface_border (void *data); + /* Geometric image transformations */ +static void img_iface_mirror (void *data); +static void img_iface_rotate_orto (void *data); +static void img_iface_rotate (void *data); +static void img_iface_rotate_2rect (void *data); + /* Miscellaneous image transformations */ +static void img_iface_adaptive_thr (void *data); +static void img_iface_cvt_color (void *data); +static void img_iface_distance_transform (void); +static void img_iface_threshold (void *data); + /* Histograms */ +static void img_iface_histogram (void *data); +static void img_iface_histogram_c3 (void *data); + /* Structural analysis and shape descriptors */ +static void img_iface_contours (void *data); +static void img_iface_contours_size (void *data); +static void img_iface_bounding_rect (void *data); +static void img_iface_fit_ellipse (void *data); +static void img_iface_min_area_rect (void *data); + /* Feature detection */ +static void img_iface_hough_circles (void *data); + + /* img_orb */ +static void img_iface_align (void); + /* img_calib3d */ +static void img_iface_calibrate (void *data); +static void img_iface_undistort (void *data); + + /* img_zbar */ +static void img_iface_decode (void *data); + /* img_ocr */ +static void img_iface_read (void *data); + + /* img_iface */ +static void img_iface_apply (void); +static void img_iface_discard (void); +static void img_iface_save_mem (void *data); +static void img_iface_load_mem (void *data); +static void img_iface_save_ref (void); + /* save */ +static void img_iface_save_file (void); +static void img_iface_save_update (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void img_iface_init (void) +{ + 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); + hist_img_c3.release(); + hist_img_c3 = cv::Mat::zeros(cv::Size(256 * 3, 100), CV_8UC3); +} + +void img_iface_cleanup_main (void) +{ + int i; + + for (i = 0; i < IMG_MEM_SIZE; i++) { + image_mem[i].release(); + } + image_ref.release(); + + cv::destroyAllWindows(); +} + +void img_iface_load (const char *fpath, const char *fname) +{ + char file_path [FILENAME_MAX]; + char file_name [FILENAME_MAX]; + + /* Init */ + img_iface_init(); + + /* Set file_path */ + if (!fpath) { + snprintf(file_path, FILENAME_MAX, "%s", saved_path); + } else { + snprintf(file_path, FILENAME_MAX, "%s", fpath); + } + + /* Set file_name */ + if (!fname) { + /* Request file name */ + user_iface_fname(file_path, file_name); + } else { + snprintf(file_name, FILENAME_MAX, "%s", fname); + } + + /* Load file */ + errno = 0; + load_image_file(file_path, file_name); + + if (!errno) { + /* Make a static copy of image */ + image.copyTo(image_copy_old); + image.copyTo(image_copy_tmp); + } +} + +void img_iface_cleanup (void) +{ + image_copy_old.release(); + image_copy_tmp.release(); + histogram_c0.release(); + histogram_c1.release(); + histogram_c2.release(); + hist_img_c1.release(); + hist_img_c3.release(); +} + +void img_iface_act (int action, void *data) +{ + switch (action) { + /* img_alx */ + case IMG_IFACE_ACT_LOCAL_MAX: + img_iface_local_max(); + break; + case IMG_IFACE_ACT_SKELETON: + img_iface_skeleton(); + break; + case IMG_IFACE_ACT_LINES_HORIZONTAL: + img_iface_lines_horizontal(); + break; + case IMG_IFACE_ACT_LINES_VERTICAL: + img_iface_lines_vertical(); + break; + case IMG_IFACE_ACT_MEAN_HORIZONTAL: + img_iface_mean_horizontal(); + break; + case IMG_IFACE_ACT_MEAN_VERTICAL: + img_iface_mean_vertical(); + break; + case IMG_IFACE_ACT_MEDIAN_HORIZONTAL: + img_iface_median_horizontal(); + break; + case IMG_IFACE_ACT_MEDIAN_VERTICAL: + img_iface_median_vertical(); + break; + + /* img_cv */ + /* Core: The core functionality */ + /* Pixel */ + case IMG_IFACE_ACT_PIXEL_GET: + img_iface_pixel_get(data); + break; + case IMG_IFACE_ACT_PIXEL_SET: + img_iface_pixel_set(data); + break; + /* ROI */ + case IMG_IFACE_ACT_SET_ROI: + img_iface_set_ROI(data); + break; + case IMG_IFACE_ACT_SET_ROI_2RECT: + img_iface_set_ROI_2rect(data); + break; + /* Operations on Arrays */ + case IMG_IFACE_ACT_AND_2REF: + img_iface_and_2ref(); + break; + case IMG_IFACE_ACT_NOT: + img_iface_not(); + break; + case IMG_IFACE_ACT_OR_2REF: + img_iface_or_2ref(); + break; + case IMG_IFACE_ACT_COMPONENT: + img_iface_component(data); + break; + /* Imgproc: Image processing */ + /* Image filtering */ + case IMG_IFACE_ACT_DILATE: + img_iface_dilate(data); + break; + case IMG_IFACE_ACT_ERODE: + img_iface_erode(data); + break; + case IMG_IFACE_ACT_DILATE_ERODE: + img_iface_dilate_erode(data); + break; + case IMG_IFACE_ACT_ERODE_DILATE: + img_iface_erode_dilate(data); + break; + case IMG_IFACE_ACT_SMOOTH: + img_iface_smooth(data); + break; + case IMG_IFACE_ACT_SOBEL: + img_iface_sobel(data); + break; + case IMG_IFACE_ACT_BORDER: + img_iface_border(data); + break; + /* Geometric image transformations */ + case IMG_IFACE_ACT_MIRROR: + img_iface_mirror(data); + break; + case IMG_IFACE_ACT_ROTATE_ORTO: + img_iface_rotate_orto(data); + break; + case IMG_IFACE_ACT_ROTATE: + img_iface_rotate(data); + break; + case IMG_IFACE_ACT_ROTATE_2RECT: + img_iface_rotate_2rect(data); + break; + /* Miscellaneous image transformations */ + case IMG_IFACE_ACT_ADAPTIVE_THRESHOLD: + img_iface_adaptive_thr(data); + break; + case IMG_IFACE_ACT_CVT_COLOR: + img_iface_cvt_color(data); + break; + case IMG_IFACE_ACT_DISTANCE_TRANSFORM: + img_iface_distance_transform(); + break; + case IMG_IFACE_ACT_THRESHOLD: + img_iface_threshold(data); + break; + /* Histograms */ + case IMG_IFACE_ACT_HISTOGRAM: + img_iface_histogram(data); + break; + case IMG_IFACE_ACT_HISTOGRAM_C3: + img_iface_histogram_c3(data); + break; + /* Structural analysis and shape descriptors */ + case IMG_IFACE_ACT_CONTOURS: + img_iface_contours(data); + break; + case IMG_IFACE_ACT_CONTOURS_SIZE: + img_iface_contours_size(data); + break; + case IMG_IFACE_ACT_BOUNDING_RECT: + img_iface_bounding_rect(data); + break; + case IMG_IFACE_ACT_FIT_ELLIPSE: + img_iface_fit_ellipse(data); + break; + case IMG_IFACE_ACT_MIN_AREA_RECT: + img_iface_min_area_rect(data); + break; + /* Feature detection */ + case IMG_IFACE_ACT_HOUGH_CIRCLES: + img_iface_hough_circles(data); + break; + + /* img_orb */ + case IMG_IFACE_ACT_ALIGN: + img_iface_align(); + break; + + /* img_calib3d */ + case IMG_IFACE_ACT_CALIBRATE: + img_iface_calibrate(data); + break; + case IMG_IFACE_ACT_UNDISTORT: + img_iface_undistort(data); + break; + + /* img_zbar */ + case IMG_IFACE_ACT_DECODE: + img_iface_decode(data); + break; + + /* img_ocr */ + case IMG_IFACE_ACT_READ: + img_iface_read(data); + break; + + /* img_iface */ + case IMG_IFACE_ACT_APPLY: + img_iface_apply(); + break; + case IMG_IFACE_ACT_DISCARD: + img_iface_discard(); + break; + case IMG_IFACE_ACT_SAVE_MEM: + img_iface_save_mem(data); + break; + case IMG_IFACE_ACT_LOAD_MEM: + img_iface_load_mem(data); + break; + case IMG_IFACE_ACT_SAVE_REF: + img_iface_save_ref(); + break; + + /* save */ + case IMG_IFACE_ACT_SAVE_FILE: + img_iface_save_file(); + break; + case IMG_IFACE_ACT_SAVE_UPDT: + img_iface_save_update(); + break; + + default: + /* Invalid action */ + break; + } +} + +void img_iface_show_img (void) +{ + cv::imshow(WIN_NAME_IMG, image_copy_tmp); + cv::waitKey(WIN_TIMEOUT); +} + +void img_iface_show_hist_c1 (void) +{ + cv::imshow(WIN_NAME_HIST, hist_img_c1); + cv::waitKey(WIN_TIMEOUT); +} + +void img_iface_show_hist_c3 (void) +{ + cv::imshow(WIN_NAME_HIST, hist_img_c3); + cv::waitKey(WIN_TIMEOUT); +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +/* img_alx --------------------------------------------------------------------*/ +static void img_iface_local_max (void) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Local maxima */ + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_LOCAL_MAX, NULL); + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Local maxima"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +static void img_iface_skeleton (void) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Skeleton */ + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_SKELETON, NULL); + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Skeleton"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +static void img_iface_lines_horizontal (void) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Horizontal lines */ + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_LINES_HORIZONTAL, NULL); + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Horizontal lines"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +static void img_iface_lines_vertical (void) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Vertical lines */ + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_LINES_VERTICAL, NULL); + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Vertical lines"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +static void img_iface_mean_horizontal (void) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Horizontal lines */ + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEAN_HORIZONTAL, NULL); + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Horizontal mean"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +static void img_iface_mean_vertical (void) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Horizontal lines */ + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEAN_VERTICAL, NULL); + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Vertical mean"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +static void img_iface_median_horizontal (void) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Horizontal lines */ + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEDIAN_HORIZONTAL, NULL); + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Horizontal median"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +static void img_iface_median_vertical (void) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Horizontal lines */ + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEDIAN_VERTICAL, NULL); + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Vertical median"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +/* img_cv --------------------------------------------------------------------*/ +/* ----- Core: The core functionality */ +/* ----- ------- Pixel */ +static void img_iface_pixel_get (void *data) +{ + struct Img_Iface_Data_Pixel_Get data_tmp; + struct Img_Iface_Data_Pixel_Get *data_cast; + unsigned char val; + char title [80]; + + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Data */ + if (!data) { + data_tmp.val = &val; + + /* Ask user */ + 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; + } + + /* Get pixel value */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_PIXEL_GET, data); + + /* Write into log */ + data_cast = (struct Img_Iface_Data_Pixel_Get *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Pixel get: (%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)++; +} + +static void img_iface_pixel_set (void *data) +{ + struct Img_Iface_Data_Pixel_Set data_tmp; + struct Img_Iface_Data_Pixel_Set *data_cast; + char title [80]; + + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Data */ + if (!data) { + /* Ask user */ + 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); + + snprintf(title, 80, "val:"); + data_tmp.val = user_iface_getint(0, 0, 255, + title, NULL); + + data = (void *)&data_tmp; + } + + /* Set pixel value */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_PIXEL_SET, data); + + /* Write into log */ + data_cast = (struct Img_Iface_Data_Pixel_Set *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Pixel get: (%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)++; +} + +/* ----- ------- ROI */ +static void img_iface_set_ROI (void *data) +{ + struct Img_Iface_Data_SetROI data_tmp; + struct Img_Iface_Data_SetROI *data_cast; + char title [80]; + + /* Data */ + if (!data) { + /* Ask user */ + snprintf(title, 80, "Origin: x:"); + data_tmp.rect.x = user_iface_getint(0, 0, + image_copy_tmp.cols, + title, NULL); + + snprintf(title, 80, "Origin: y:"); + data_tmp.rect.y = user_iface_getint(0, 0, + image_copy_tmp.rows, + title, NULL); + + snprintf(title, 80, "Width:"); + data_tmp.rect.width = user_iface_getint(1, + image_copy_tmp.cols - data_tmp.rect.x, + image_copy_tmp.cols - data_tmp.rect.x, + title, NULL); + + snprintf(title, 80, "Height:"); + data_tmp.rect.height = user_iface_getint(1, + image_copy_tmp.rows - data_tmp.rect.y, + image_copy_tmp.rows - data_tmp.rect.y, + title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + data_cast = (struct Img_Iface_Data_SetROI *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "ROI: (%i,%i) w=%i,h=%i", + data_cast->rect.x, + data_cast->rect.y, + data_cast->rect.width, + data_cast->rect.height); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Set ROI */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_SET_ROI, data); +} + +static void img_iface_set_ROI_2rect (void *data) +{ + struct Img_Iface_Data_SetROI data_tmp; + struct Img_Iface_Data_SetROI *data_cast; + + /* Data */ + if (!data) { + data_tmp.rect.x = rectangle.x; + data_tmp.rect.y = rectangle.y; + data_tmp.rect.width = rectangle.width; + data_tmp.rect.height = rectangle.height; + + data = (void *)&data_tmp; + } + + /* Write into log */ + data_cast = (struct Img_Iface_Data_SetROI *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "ROI: (%i,%i) w=%i,h=%i", + data_cast->rect.x, + data_cast->rect.y, + data_cast->rect.width, + data_cast->rect.height); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Set ROI */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_SET_ROI, data); +} + +/* ----- ------- Operations on arrays */ +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_not (void) +{ + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Invert color"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* 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_component (void *data) +{ + /* Must have at least 3 channels */ + if (image_copy_tmp.channels() < 3) { + /* 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; + } + + /* Data */ + struct Img_Iface_Data_Component data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Component:"); + data_tmp.cmp = user_iface_getint(0, 0, + image_copy_tmp.channels() - 1, + title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Component *data_cast; + data_cast = (struct Img_Iface_Data_Component *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Component %i", + data_cast->cmp); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Filter: extract component */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_COMPONENT, data); +} + +/* ----- Imgproc: Image processing */ +/* ----- ------- Image filtering */ +static void img_iface_dilate (void *data) +{ + /* Data */ + struct Img_Iface_Data_Dilate_Erode data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Iterations:"); + data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Dilate_Erode *data_cast; + data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Dilate i=%i", + data_cast->i); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Dilate */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data); +} + +static void img_iface_erode (void *data) +{ + /* Data */ + struct Img_Iface_Data_Dilate_Erode data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Iterations:"); + data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Dilate_Erode *data_cast; + data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Erode i=%i", + data_cast->i); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Erode */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data); +} + +static void img_iface_dilate_erode (void *data) +{ + /* Data */ + struct Img_Iface_Data_Dilate_Erode data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Iterations:"); + data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Dilate_Erode *data_cast; + data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Dilate-erode i=%i", + data_cast->i); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Dilate */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data); + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data); +} + +static void img_iface_erode_dilate (void *data) +{ + /* Data */ + struct Img_Iface_Data_Dilate_Erode data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Iterations:"); + data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Dilate_Erode *data_cast; + data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Erode-dilate i=%i", + data_cast->i); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Dilate */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data); + img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data); +} + +static void img_iface_smooth (void *data) +{ + /* Data */ + struct Img_Iface_Data_Smooth data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Method: MEAN=1, GAUSS=2, MEDIAN=3"); + data_tmp.method = user_iface_getint(1, 3, 3, title, NULL); + + snprintf(title, 80, "Kernel size: 3, 5, 7, ..."); + data_tmp.ksize = user_iface_getint(3, 3, INFINITY, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Smooth *data_cast; + data_cast = (struct Img_Iface_Data_Smooth *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Smooth mth=%i [%ix%i]", + data_cast->method, + data_cast->ksize, + data_cast->ksize); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Filter: smooth */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_SMOOTH, data); +} + +static void img_iface_sobel (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Data */ + struct Img_Iface_Data_Sobel data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Order of the derivative x"); + data_tmp.dx = user_iface_getint(0, 1, 10, title, NULL); + + snprintf(title, 80, "Order of the derivative y"); + data_tmp.dy = user_iface_getint(0, 1, 10, title, NULL); + + snprintf(title, 80, "Size of the extended Sobel kernel (-1 -> Scharr"); + data_tmp.ksize = user_iface_getint(-1, 3, 7, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Sobel *data_cast; + data_cast = (struct Img_Iface_Data_Sobel *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Sobel dx=%i;dy=%i [ks=%i]", + data_cast->dx, + data_cast->dy, + data_cast->ksize); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Filter: sobel */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_SOBEL, data); +} + +static void img_iface_border (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Data */ + struct Img_Iface_Data_Border data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Size"); + data_tmp.size = user_iface_getint(1, 1, 0xF000, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Border *data_cast; + data_cast = (struct Img_Iface_Data_Border *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Border size=%i", + data_cast->size); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Add border */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_BORDER, data); +} + +/* ----- ------- Geometric image transformations */ +static void img_iface_mirror (void *data) +{ + /* Data */ + struct Img_Iface_Data_Mirror data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Axis: 0=x; 1=y"); + data_tmp.axis = user_iface_getint(0, 1, 1, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Mirror *data_cast; + data_cast = (struct Img_Iface_Data_Mirror *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Mirror axis: %i", + data_cast->axis); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Mirror */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_MIRROR, data); +} + +static void img_iface_rotate_orto (void *data) +{ + /* Data */ + struct Img_Iface_Data_Rotate_Orto data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Rotate (counterclockwise) n * pi/2 rad; n:"); + data_tmp.n = user_iface_getint(1, 1, 3, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Rotate_Orto *data_cast; + data_cast = (struct Img_Iface_Data_Rotate_Orto *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Rotate %i * pi/2 rad", + data_cast->n); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Rotate ortogonally */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE_ORTO, data); +} + +static void img_iface_rotate (void *data) +{ + /* Data */ + struct Img_Iface_Data_Rotate data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Center: x:"); + data_tmp.center.x = user_iface_getdbl(0, 0, INFINITY, title, NULL); + + snprintf(title, 80, "Center: y:"); + data_tmp.center.y = user_iface_getdbl(0, 0, INFINITY, title, NULL); + + snprintf(title, 80, "Angle: (deg)"); + data_tmp.angle = user_iface_getdbl(-INFINITY, 0, INFINITY, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Rotate *data_cast; + data_cast = (struct Img_Iface_Data_Rotate *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Rotate (%.2f,%.2f) %lfº", + data_cast->center.x, + data_cast->center.y, + data_cast->angle); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Rotate ortogonally */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE, data); +} + +static void img_iface_rotate_2rect (void *data) +{ + /* Data */ + struct Img_Iface_Data_Rotate data_tmp; + if (!data) { + data_tmp.center.x = rectangle_rot.center.x; + data_tmp.center.y = rectangle_rot.center.y; + data_tmp.angle = rectangle_rot.angle; + + /* If angle is < -45º, it is taking into acount the incorrect side */ + if (data_tmp.angle < -45.0) { + data_tmp.angle += 90.0; + } + + data = (void *)&data_tmp; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Rotate to rectangle"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Rotate ortogonally */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE, data); +} + +/* ----- ------- Miscellaneous image transformations */ +static void img_iface_adaptive_thr (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Data */ + struct Img_Iface_Data_Adaptive_Thr data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Method: MEAN=0, GAUSS=1"); + data_tmp.method = user_iface_getint(0, 1, 1, title, NULL); + + snprintf(title, 80, "Type: BIN=0, BIN_INV=1"); + data_tmp.thr_typ = user_iface_getint(0, 0, 1, title, NULL); + + snprintf(title, 80, "Kernel size: 3, 5, 7, ..."); + data_tmp.ksize = user_iface_getint(3, 3, INFINITY, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Adaptive_Thr *data_cast; + data_cast = (struct Img_Iface_Data_Adaptive_Thr *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Threshold mth=%i, typ=%i, ks=%i", + data_cast->method, + data_cast->thr_typ, + data_cast->ksize); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Filter: adaptive threshold */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ADAPTIVE_THRESHOLD, data); +} + +static void img_iface_cvt_color (void *data) +{ + /* Must have at least 3 channels */ + if (image_copy_tmp.channels() < 3) { + /* 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; + } + + /* Data */ + struct Img_Iface_Data_Cvt_Color data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Method: BGR2GRAY = 6, BGR2HSV = 40"); + data_tmp.method = user_iface_getint(0, 0, + cv::COLOR_COLORCVT_MAX, + title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Cvt_Color *data_cast; + data_cast = (struct Img_Iface_Data_Cvt_Color *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Convert color %i", + data_cast->method); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Filter: BGR to gray */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_CVT_COLOR, data); +} + +static void img_iface_distance_transform (void) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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, + "Distance transform"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Distance transform */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_DISTANCE_TRANSFORM, NULL); +} + +static void img_iface_threshold (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Data */ + struct Img_Iface_Data_Threshold data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Type: BIN=0, BIN_INV=1, TRUNC=2, TOZ=3, TOZ_INV=4"); + data_tmp.thr_typ = user_iface_getint(0, 0, 4, title, NULL); + + snprintf(title, 80, "Value: 0 to 255 (or -1 for Otsu's algorithm)"); + data_tmp.thr_val = user_iface_getint(-1, 0, 255, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Threshold *data_cast; + data_cast = (struct Img_Iface_Data_Threshold *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Threshold typ=%i, val=%i", + data_cast->thr_typ, + data_cast->thr_val); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Filter: threshold */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_THRESHOLD, data); +} + +/* ----- ------- Histograms */ +static void img_iface_histogram (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Data */ + struct Img_Iface_Data_Histogram data_tmp; + if (!data) { + data_tmp.hist_c0 = &histogram_c0; + data_tmp.hist_img = &hist_img_c1; + + data = (void *)&data_tmp; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Histogram"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Histogram */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_HISTOGRAM, data); +} + +static void img_iface_histogram_c3 (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 3) { + /* 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; + } + + /* Data */ + struct Img_Iface_Data_Histogram data_tmp; + if (!data) { + data_tmp.hist_c0 = &histogram_c0; + data_tmp.hist_c1 = &histogram_c1; + data_tmp.hist_c2 = &histogram_c2; + data_tmp.hist_img = &hist_img_c3; + + data = (void *)&data_tmp; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Histogram (3 channels)"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Histogram */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_HISTOGRAM_C3, data); +} + +/* ----- ------- Structural analysis and shape descriptors */ +static void img_iface_contours (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Data */ + struct Img_Iface_Data_Contours data_tmp; + if (!data) { + data_tmp.contours = &contours; + data_tmp.hierarchy = &hierarchy; + + data = (void *)&data_tmp; + } + + /* Contours */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_CONTOURS, data); + + /* Write into log */ + struct Img_Iface_Data_Contours *data_cast; + data_cast = (struct Img_Iface_Data_Contours *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Contours n=%i", + (int)data_cast->contours->size()); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +static void img_iface_contours_size (void *data) +{ + /* 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; + } + + /* Contours size */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_CONTOURS_SIZE, data); + + /* Write into log */ + struct Img_Iface_Data_Contours_Size *data_cast; + data_cast = (struct Img_Iface_Data_Contours_Size *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Contours size:"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + int i; + for (i = 0; i < (int)data_cast->contours->size(); i++) { + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "cnt[%i]: A=%lf; P=%lf;", + i, + data_cast->area[i], + data_cast->perimeter[i]); + user_iface_log.lvl[user_iface_log.len] = 2; + (user_iface_log.len)++; + } +} + +static void img_iface_bounding_rect (void *data) +{ + /* Data */ + struct Img_Iface_Data_Bounding_Rect data_tmp; + if (!data) { + if(!contours.size()) { + /* 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; + } + data_tmp.contour = &(contours[0]); + data_tmp.rect = &rectangle; + data_tmp.show = true; + + data = (void *)&data_tmp; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Bounding rectangle"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Enclosing rectangle */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_BOUNDING_RECT, data); +} + +static void img_iface_fit_ellipse (void *data) +{ + /* Data */ + struct Img_Iface_Data_MinARect data_tmp; + if (!data) { + if(!contours.size()) { + /* 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; + } + data_tmp.contour = &(contours[0]); + + data_tmp.rect = &rectangle_rot; + + data = (void *)&data_tmp; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Fit ellipse"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Enclosing rectangle */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_FIT_ELLIPSE, data); +} + +static void img_iface_min_area_rect (void *data) +{ + /* Data */ + struct Img_Iface_Data_MinARect data_tmp; + if (!data) { + if(!contours.size()) { + /* 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; + } + data_tmp.contour = &(contours[0]); + data_tmp.rect = &rectangle_rot; + data_tmp.show = true; + + data = (void *)&data_tmp; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Min area rectangle"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Enclosing rectangle */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_MIN_AREA_RECT, data); +} + +/* ----- ------- Feature detection */ +static void img_iface_hough_circles (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Data */ + struct Img_Iface_Data_Hough_Circles data_tmp; + if (!data) { + data_tmp.circles = &circles; + + /* Ask user */ + char title [80]; + snprintf(title, 80, "Minimum distance:"); + data_tmp.dist_min = user_iface_getdbl(0, 5, INFINITY, title, NULL); + + snprintf(title, 80, "param 1:"); + data_tmp.param_1 = user_iface_getdbl(0, 200, INFINITY, title, NULL); + + snprintf(title, 80, "param 2:"); + data_tmp.param_2 = user_iface_getdbl(0, 100, INFINITY, title, NULL); + + snprintf(title, 80, "Minimum radius"); + data_tmp.radius_min = user_iface_getint(0, 10, INFINITY, title, NULL); + + snprintf(title, 80, "Maximum radius"); + data_tmp.radius_max = user_iface_getint(0, 0, INFINITY, title, NULL); + + data = (void *)&data_tmp; + } + + /* Circles */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_HOUGH_CIRCLES, data); + + /* Write into log */ + struct Img_Iface_Data_Hough_Circles *data_cast; + data_cast = (struct Img_Iface_Data_Hough_Circles *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Circles n=%i", + (int)data_cast->circles->size()); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +/* img_orb -------------------------------------------------------------------*/ +static void img_iface_align (void) +{ + /* Must have defined a reference */ + if (image_ref.empty()) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! Reference is NULL"); + 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, + "Align to reference"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Align to reference image_ref */ + img_orb_act(&image_ref, &image_copy_tmp, IMG_ORB_ACT_ALIGN); +} + +/* img_calib3d ---------------------------------------------------------------*/ +static void img_iface_calibrate (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Data */ + struct Img_Iface_Data_Calibrate data_tmp; + if (!data) { + data_tmp.intrinsic_mat = &intrinsic_mat; + data_tmp.dist_coefs = &dist_coefs; + data_tmp.rvecs = &rvecs; + data_tmp.tvecs = &tvecs; + + data = (void *)&data_tmp; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Calibrate"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Contours */ + img_calib3d_act(&image_copy_tmp, IMG_CALIB3D_ACT_CALIBRATE, data); +} + +static void img_iface_undistort (void *data) +{ + /* Data */ + struct Img_Iface_Data_Undistort data_tmp; + if (!data) { + data_tmp.intrinsic_mat = &intrinsic_mat; + data_tmp.dist_coefs = &dist_coefs; + + data = (void *)&data_tmp; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Undistort"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Contours */ + img_calib3d_act(&image_copy_tmp, IMG_CALIB3D_ACT_UNDISTORT, data); +} + +/* img_zbar ------------------------------------------------------------------*/ +static void img_iface_decode (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Data */ + struct Img_Iface_Data_Decode data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Type of code: (0 for all)"); + data_tmp.code_type = (enum zbar::zbar_symbol_type_e) + user_iface_getint(0, 0, INT_MAX, + title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Decode *data_cast; + data_cast = (struct Img_Iface_Data_Decode *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Detect codes c=%i", + data_cast->code_type); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Decode */ + img_zb_act(&image_copy_tmp, IMG_ZB_ACT_DECODE, data); + + /* Results */ + if (!zb_codes.n) { + /* No text found */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! No code detected"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + } else { + /* Write results into log */ + int i; + for (i = 0; i < zb_codes.n; i++) { + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "%s -- '%s'", + zb_codes.arr[i].sym_name, + zb_codes.arr[i].data); + user_iface_log.lvl[user_iface_log.len] = 2; + (user_iface_log.len)++; + } + } +} + +/* img_ocr -------------------------------------------------------------------*/ +static void img_iface_read (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* 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; + } + + /* Data */ + struct Img_Iface_Data_Read data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Language: ENG = 0, SPA = 1, CAT = 2"); + data_tmp.lang = user_iface_getint(0, 1, 2, title, NULL); + + snprintf(title, 80, "Config: none = 0, Price = 1"); + data_tmp.conf = user_iface_getint(0, 1, 2, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Read *data_cast; + data_cast = (struct Img_Iface_Data_Read *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "OCR (lang=%i) [c=%i]", + data_cast->lang, + data_cast->conf); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Adapt image data */ + data_cast->img.data = image_copy_tmp.data; + data_cast->img.width = image_copy_tmp.size().width; + data_cast->img.height = image_copy_tmp.size().height; + data_cast->img.B_per_pix = image_copy_tmp.channels(); + data_cast->img.B_per_line = image_copy_tmp.step1(); + + /* OCR */ + img_ocr_act(IMG_OCR_ACT_READ, data); + + /* Results */ + if (img_ocr_text[0] == '\0') { + /* No text found */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! No text detected"); + user_iface_log.lvl[user_iface_log.len] = 2; + (user_iface_log.len)++; + } +} + +/* img_iface -----------------------------------------------------------------*/ +static void img_iface_apply (void) +{ + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Apply changes"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Write tmp into old */ + image_copy_old.release(); + image_copy_tmp.copyTo(image_copy_old); +} + +static void img_iface_discard (void) +{ + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Discard changes"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Discard tmp image copy */ + image_copy_tmp.release(); + image_copy_old.copyTo(image_copy_tmp); +} + +static void img_iface_save_mem (void *data) +{ + /* Which memory to use */ + int x; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "mem_X; X:"); + x = user_iface_getint(0, 0, IMG_MEM_SIZE - 1, title, NULL); + } else { + x = *(int *)data; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Save to mem_%i", x); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Write into mem */ + image_mem[x].release(); + image_copy_tmp.copyTo(image_mem[x]); +} + +static void img_iface_load_mem (void *data) +{ + /* Which memory to use */ + int x; + if (!data) { + /* Ask user which memory to use */ + char title [80]; + snprintf(title, 80, "mem_X; X:"); + x = user_iface_getint(0, 0, IMG_MEM_SIZE - 1, title, NULL); + } else { + x = *(int *)data; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Load from mem_%i", x); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + if (!image_mem[x].empty()) { + /* Discard tmp image copy */ + image_copy_tmp.release(); + + /* Load from mem */ + image_mem[x].copyTo(image_copy_tmp); + } +} + +static void img_iface_save_ref (void) +{ + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Save to reference"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Write into ref */ + image_ref.release(); + image_copy_tmp.copyTo(image_ref); + image_ref = image_copy_tmp; +} + +/* save ----------------------------------------------------------------------*/ +static void img_iface_save_file (void) +{ + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Save as..."); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Write into image struct (save.c) */ + image.release(); + image_copy_tmp.copyTo(image); + + /* Save into file */ + save_image_file(NULL, NULL); +} + +static void img_iface_save_update (void) +{ + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Save: update img"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Write into image struct (save.c) */ + image.release(); + image_copy_tmp.copyTo(image); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/src/img_ocr.c b/modules/image/src/img_ocr.c index 5aba51e..c406abf 100644 --- a/modules/image/src/img_ocr.c +++ b/modules/image/src/img_ocr.c @@ -1,128 +1,128 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* INT_MAX */ - #include - #include - /* snprintf() & FILENAME_MAX */ - #include - -/* Packages ------------------------------------------------------------------*/ - /* OCR Tesseract */ - #include - -/* Project -------------------------------------------------------------------*/ - /* share_path */ - #include "about.h" - -/* Module --------------------------------------------------------------------*/ - /* data & img_ocr_text & OCR_TEXT_MAX */ - #include "img_iface.h" - - #include "img_ocr.h" - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void img_ocr_read (void *data); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void img_ocr_act (int action, void *data) -{ - switch (action) { - case IMG_OCR_ACT_READ: - img_ocr_read(data); - break; - } -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void img_ocr_read (void *data) -{ - struct TessBaseAPI *handle_ocr; - - /* Data */ - struct Img_Iface_Data_Read *data_cast; - data_cast = (struct Img_Iface_Data_Read *)data; - - /* Language */ - int lang; - char lang_str [20 + 1]; - lang = data_cast->lang; - switch (lang) { - case IMG_IFACE_OCR_LANG_ENG: - sprintf(lang_str, "eng"); - break; - case IMG_IFACE_OCR_LANG_SPA: - sprintf(lang_str, "spa"); - break; - case IMG_IFACE_OCR_LANG_CAT: - sprintf(lang_str, "cat"); - break; - case IMG_IFACE_OCR_LANG_DIGITS: - sprintf(lang_str, "digits"); - break; - case IMG_IFACE_OCR_LANG_DIGITS_COMMA: - sprintf(lang_str, "digits_comma"); - break; - } - - /* Config file */ - int conf; - char conf_str [FILENAME_MAX]; - conf = data_cast->conf; - switch (conf) { - case IMG_IFACE_OCR_CONF_PRICE: - snprintf(conf_str, 6, "%s/%s", share_path, "price"); - break; - } - - /* init OCR */ - handle_ocr = TessBaseAPICreate(); - TessBaseAPIInit2(handle_ocr, NULL, lang_str, -#ifdef OEM_LSTM_ONLY - OEM_LSTM_ONLY); -#else - OEM_DEFAULT); -#endif -// OEM_TESSERACT_LSTM_COMBINED); - if (conf) { - /* Configure OCR (whitelist chars) */ - TessBaseAPIReadConfigFile(handle_ocr, conf_str); - } - - /* scan image for text */ - TessBaseAPISetImage(handle_ocr, data_cast->img.data, - data_cast->img.width, data_cast->img.height, - data_cast->img.B_per_pix, - data_cast->img.B_per_line); - TessBaseAPIRecognize(handle_ocr, NULL); - char *txt; - txt = TessBaseAPIGetUTF8Text(handle_ocr); - - /* Copy text to global variable */ - snprintf(img_ocr_text, OCR_TEXT_MAX, "%s", txt); - - /* cleanup */ - TessDeleteText(txt); - TessBaseAPIEnd(handle_ocr); - TessBaseAPIDelete(handle_ocr); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* INT_MAX */ + #include + #include + /* snprintf() & FILENAME_MAX */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* OCR Tesseract */ + #include + +/* Project -------------------------------------------------------------------*/ + /* share_path */ + #include "about.h" + +/* Module --------------------------------------------------------------------*/ + /* data & img_ocr_text & OCR_TEXT_MAX */ + #include "img_iface.h" + + #include "img_ocr.h" + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void img_ocr_read (void *data); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void img_ocr_act (int action, void *data) +{ + switch (action) { + case IMG_OCR_ACT_READ: + img_ocr_read(data); + break; + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void img_ocr_read (void *data) +{ + struct TessBaseAPI *handle_ocr; + + /* Data */ + struct Img_Iface_Data_Read *data_cast; + data_cast = (struct Img_Iface_Data_Read *)data; + + /* Language */ + int lang; + char lang_str [20 + 1]; + lang = data_cast->lang; + switch (lang) { + case IMG_IFACE_OCR_LANG_ENG: + sprintf(lang_str, "eng"); + break; + case IMG_IFACE_OCR_LANG_SPA: + sprintf(lang_str, "spa"); + break; + case IMG_IFACE_OCR_LANG_CAT: + sprintf(lang_str, "cat"); + break; + case IMG_IFACE_OCR_LANG_DIGITS: + sprintf(lang_str, "digits"); + break; + case IMG_IFACE_OCR_LANG_DIGITS_COMMA: + sprintf(lang_str, "digits_comma"); + break; + } + + /* Config file */ + int conf; + char conf_str [FILENAME_MAX]; + conf = data_cast->conf; + switch (conf) { + case IMG_IFACE_OCR_CONF_PRICE: + snprintf(conf_str, 6, "%s/%s", share_path, "price"); + break; + } + + /* init OCR */ + handle_ocr = TessBaseAPICreate(); + TessBaseAPIInit2(handle_ocr, NULL, lang_str, +#ifdef OEM_LSTM_ONLY + OEM_LSTM_ONLY); +#else + OEM_DEFAULT); +#endif +// OEM_TESSERACT_LSTM_COMBINED); + if (conf) { + /* Configure OCR (whitelist chars) */ + TessBaseAPIReadConfigFile(handle_ocr, conf_str); + } + + /* scan image for text */ + TessBaseAPISetImage(handle_ocr, data_cast->img.data, + data_cast->img.width, data_cast->img.height, + data_cast->img.B_per_pix, + data_cast->img.B_per_line); + TessBaseAPIRecognize(handle_ocr, NULL); + char *txt; + txt = TessBaseAPIGetUTF8Text(handle_ocr); + + /* Copy text to global variable */ + snprintf(img_ocr_text, OCR_TEXT_MAX, "%s", txt); + + /* cleanup */ + TessDeleteText(txt); + TessBaseAPIEnd(handle_ocr); + TessBaseAPIDelete(handle_ocr); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/src/img_orb.cpp b/modules/image/src/img_orb.cpp index f62203c..6d91085 100644 --- a/modules/image/src/img_orb.cpp +++ b/modules/image/src/img_orb.cpp @@ -1,126 +1,126 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C++ --------------------------------------------------------------*/ - /* class std::vector */ - #include - -/* Standard C ----------------------------------------------------------------*/ - /* snprintf() */ - #include - -/* Packages ------------------------------------------------------------------*/ - /* opencv */ - #include - #include - -/* Module -------------------------------------------------------------------*/ - #include "img_orb.hpp" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define MAX_FEATURES (50000) - # define GOOD_MATCH_P (0.25) - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void img_orb_align (class cv::Mat *img_0, - class cv::Mat *img_1); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void img_orb_act (class cv::Mat *img_ref, - class cv::Mat *imgptr, int action) -{ - switch (action) { - case IMG_ORB_ACT_ALIGN: - img_orb_align(img_ref, imgptr); - break; - } -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void img_orb_align (class cv::Mat *img_0, - class cv::Mat *img_1) -{ - /* Variables to store keypoints & descriptors */ - class std::vector keypoints_0; - class std::vector keypoints_1; - class cv::Mat descriptors_0; - class cv::Mat descriptors_1; - - /* Detect ORB features & compute descriptors */ -#if 1 - /* OpenCV 2.x */ - class cv::ORB orb; - orb(*img_0, cv::Mat(), keypoints_0, descriptors_0); - orb(*img_1, cv::Mat(), keypoints_1, descriptors_1); -#else - /* OpenCV 3.x */ - class cv::Ptr orb; - orb = cv::ORB::create(MAX_FEATURES); - orb->detectAndCompute(*img_0, cv::Mat(), keypoints_0, descriptors_0); - orb->detectAndCompute(*img_1, cv::Mat(), keypoints_1, descriptors_1); -#endif - - - /* Match structures */ - class std::vector matches; - cv::Ptr matcher; - matcher = cv::DescriptorMatcher::create("BruteForce-Hamming"); - matcher->match(descriptors_1, descriptors_0, matches, cv::Mat()); - - /* Sort matches by score */ - std::sort(matches.begin(), matches.end()); - - /* Remove not so good matches */ - int good_matches; - good_matches = GOOD_MATCH_P * matches.size(); - matches.erase(matches.begin() + good_matches, matches.end()); - - /* Draw top matches */ - class cv::Mat img_matches; - cv::drawMatches(*img_1, keypoints_1, *img_0, keypoints_0, matches, - img_matches); - cv::imwrite("matches.jpg", img_matches); - - /* Extract location of good matches */ - class std::vector > points_0; - class std::vector > points_1; - int i; - for (i = 0; i < (int)matches.size(); i++) { - points_1.push_back(keypoints_1[matches[i].queryIdx].pt); - points_0.push_back(keypoints_0[matches[i].trainIdx].pt); - } - - /* Find homography */ - class cv::Mat img_hg; - img_hg = cv::findHomography(points_1, points_0, CV_RANSAC); - - /* Use homography to warp image */ - class cv::Mat img_align; - cv::warpPerspective(*img_1, img_align, img_hg, img_0->size()); - - /* Write img_align into img_1 */ - *img_1 = img_align; - img_align.release(); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C++ --------------------------------------------------------------*/ + /* class std::vector */ + #include + +/* Standard C ----------------------------------------------------------------*/ + /* snprintf() */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* opencv */ + #include + #include + +/* Module -------------------------------------------------------------------*/ + #include "img_orb.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define MAX_FEATURES (50000) + # define GOOD_MATCH_P (0.25) + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void img_orb_align (class cv::Mat *img_0, + class cv::Mat *img_1); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void img_orb_act (class cv::Mat *img_ref, + class cv::Mat *imgptr, int action) +{ + switch (action) { + case IMG_ORB_ACT_ALIGN: + img_orb_align(img_ref, imgptr); + break; + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void img_orb_align (class cv::Mat *img_0, + class cv::Mat *img_1) +{ + /* Variables to store keypoints & descriptors */ + class std::vector keypoints_0; + class std::vector keypoints_1; + class cv::Mat descriptors_0; + class cv::Mat descriptors_1; + + /* Detect ORB features & compute descriptors */ +#if 1 + /* OpenCV 2.x */ + class cv::ORB orb; + orb(*img_0, cv::Mat(), keypoints_0, descriptors_0); + orb(*img_1, cv::Mat(), keypoints_1, descriptors_1); +#else + /* OpenCV 3.x */ + class cv::Ptr orb; + orb = cv::ORB::create(MAX_FEATURES); + orb->detectAndCompute(*img_0, cv::Mat(), keypoints_0, descriptors_0); + orb->detectAndCompute(*img_1, cv::Mat(), keypoints_1, descriptors_1); +#endif + + + /* Match structures */ + class std::vector matches; + cv::Ptr matcher; + matcher = cv::DescriptorMatcher::create("BruteForce-Hamming"); + matcher->match(descriptors_1, descriptors_0, matches, cv::Mat()); + + /* Sort matches by score */ + std::sort(matches.begin(), matches.end()); + + /* Remove not so good matches */ + int good_matches; + good_matches = GOOD_MATCH_P * matches.size(); + matches.erase(matches.begin() + good_matches, matches.end()); + + /* Draw top matches */ + class cv::Mat img_matches; + cv::drawMatches(*img_1, keypoints_1, *img_0, keypoints_0, matches, + img_matches); + cv::imwrite("matches.jpg", img_matches); + + /* Extract location of good matches */ + class std::vector > points_0; + class std::vector > points_1; + int i; + for (i = 0; i < (int)matches.size(); i++) { + points_1.push_back(keypoints_1[matches[i].queryIdx].pt); + points_0.push_back(keypoints_0[matches[i].trainIdx].pt); + } + + /* Find homography */ + class cv::Mat img_hg; + img_hg = cv::findHomography(points_1, points_0, CV_RANSAC); + + /* Use homography to warp image */ + class cv::Mat img_align; + cv::warpPerspective(*img_1, img_align, img_hg, img_0->size()); + + /* Write img_align into img_1 */ + *img_1 = img_align; + img_align.release(); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/src/img_zbar.cpp b/modules/image/src/img_zbar.cpp index 083093b..5a976a6 100644 --- a/modules/image/src/img_zbar.cpp +++ b/modules/image/src/img_zbar.cpp @@ -1,102 +1,102 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* INT_MAX */ - #include - #include - /* snprintf() */ - #include - -/* Packages ------------------------------------------------------------------*/ - /* opencv */ - #include - /* zbar */ - #include - -/* Module --------------------------------------------------------------------*/ - /* data & zb_codes */ - #include "img_iface.hpp" - - #include "img_zbar.hpp" - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void img_zb_decode (class cv::Mat *imgptr, void *data); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void img_zb_act (class cv::Mat *imgptr, int action, void *data) -{ - switch (action) { - case IMG_ZB_ACT_DECODE: - img_zb_decode(imgptr, data); - break; - } -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void img_zb_decode (class cv::Mat *imgptr, void *data) -{ - struct zbar::zbar_image_scanner_s *scanner; - struct zbar::zbar_image_s *image_zb; - const struct zbar::zbar_symbol_s *symbol; - - /* Type of code to scan */ - enum zbar::zbar_symbol_type_e code_type; - code_type = ((struct Img_Iface_Data_Decode *)data)->code_type; - - /* create & configure a reader */ - scanner = zbar::zbar_image_scanner_create(); - zbar::zbar_image_scanner_set_config(scanner, code_type, - zbar::ZBAR_CFG_ENABLE, 1); - - /* wrap image data */ - image_zb = zbar::zbar_image_create(); - zbar::zbar_image_set_format(image_zb, *(int*)"GREY"); - zbar::zbar_image_set_size(image_zb, imgptr->cols, imgptr->rows); - zbar::zbar_image_set_data(image_zb, (void *)(imgptr->data), - (imgptr->cols * imgptr->rows), - NULL); - - /* scan the image for barcodes */ - int i; - zb_codes.n = zbar::zbar_scan_image(scanner, image_zb); - if (zb_codes.n) { - /* extract results */ - symbol = zbar::zbar_image_first_symbol(image_zb); - for (i = 0; i < ZB_CODES_MAX && symbol; i++) { - /* Write results into array */ - zb_codes.arr[i].type = zbar::zbar_symbol_get_type(symbol); - snprintf(zb_codes.arr[i].sym_name, 80, "%s", - zbar::zbar_get_symbol_name( - zb_codes.arr[i].type)); - snprintf(zb_codes.arr[i].data, ZBAR_LEN_MAX, "%s", - zbar::zbar_symbol_get_data(symbol)); - - /* Load next symbol */ - symbol = zbar::zbar_symbol_next(symbol); - } - } - - /* clean up */ - zbar::zbar_image_destroy(image_zb); - zbar::zbar_image_scanner_destroy(scanner); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* INT_MAX */ + #include + #include + /* snprintf() */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* opencv */ + #include + /* zbar */ + #include + +/* Module --------------------------------------------------------------------*/ + /* data & zb_codes */ + #include "img_iface.hpp" + + #include "img_zbar.hpp" + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void img_zb_decode (class cv::Mat *imgptr, void *data); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void img_zb_act (class cv::Mat *imgptr, int action, void *data) +{ + switch (action) { + case IMG_ZB_ACT_DECODE: + img_zb_decode(imgptr, data); + break; + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void img_zb_decode (class cv::Mat *imgptr, void *data) +{ + struct zbar::zbar_image_scanner_s *scanner; + struct zbar::zbar_image_s *image_zb; + const struct zbar::zbar_symbol_s *symbol; + + /* Type of code to scan */ + enum zbar::zbar_symbol_type_e code_type; + code_type = ((struct Img_Iface_Data_Decode *)data)->code_type; + + /* create & configure a reader */ + scanner = zbar::zbar_image_scanner_create(); + zbar::zbar_image_scanner_set_config(scanner, code_type, + zbar::ZBAR_CFG_ENABLE, 1); + + /* wrap image data */ + image_zb = zbar::zbar_image_create(); + zbar::zbar_image_set_format(image_zb, *(int*)"GREY"); + zbar::zbar_image_set_size(image_zb, imgptr->cols, imgptr->rows); + zbar::zbar_image_set_data(image_zb, (void *)(imgptr->data), + (imgptr->cols * imgptr->rows), + NULL); + + /* scan the image for barcodes */ + int i; + zb_codes.n = zbar::zbar_scan_image(scanner, image_zb); + if (zb_codes.n) { + /* extract results */ + symbol = zbar::zbar_image_first_symbol(image_zb); + for (i = 0; i < ZB_CODES_MAX && symbol; i++) { + /* Write results into array */ + zb_codes.arr[i].type = zbar::zbar_symbol_get_type(symbol); + snprintf(zb_codes.arr[i].sym_name, 80, "%s", + zbar::zbar_get_symbol_name( + zb_codes.arr[i].type)); + snprintf(zb_codes.arr[i].data, ZBAR_LEN_MAX, "%s", + zbar::zbar_symbol_get_data(symbol)); + + /* Load next symbol */ + symbol = zbar::zbar_symbol_next(symbol); + } + } + + /* clean up */ + zbar::zbar_image_destroy(image_zb); + zbar::zbar_image_scanner_destroy(scanner); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/menu/inc/menu_clui.h b/modules/menu/inc/menu_clui.h index ae982a8..49de943 100644 --- a/modules/menu/inc/menu_clui.h +++ b/modules/menu/inc/menu_clui.h @@ -1,27 +1,27 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_MENU_CLUI_H - # define VA_MENU_CLUI_H - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void menu_clui (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* menu_clui.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_MENU_CLUI_H + # define VA_MENU_CLUI_H + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void menu_clui (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* menu_clui.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/menu/inc/menu_iface.h b/modules/menu/inc/menu_iface.h index 320cbd4..09a1164 100644 --- a/modules/menu/inc/menu_iface.h +++ b/modules/menu/inc/menu_iface.h @@ -1,43 +1,43 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_MENU_IFACE_H - # define VA_MENU_IFACE_H - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Menu_Iface_Mode { - MENU_IFACE_FOO = 0, - MENU_IFACE_CLUI, - MENU_IFACE_TUI - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern int menu_iface_mode; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void menu_iface (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* menu_iface.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_MENU_IFACE_H + # define VA_MENU_IFACE_H + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Menu_Iface_Mode { + MENU_IFACE_FOO = 0, + MENU_IFACE_CLUI, + MENU_IFACE_TUI + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +extern int menu_iface_mode; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void menu_iface (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* menu_iface.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/menu/inc/menu_iface.hpp b/modules/menu/inc/menu_iface.hpp index a1fbb25..1b5b60c 100644 --- a/modules/menu/inc/menu_iface.hpp +++ b/modules/menu/inc/menu_iface.hpp @@ -1,55 +1,55 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_MENU_IFACE_HPP - # define VA_MENU_IFACE_HPP - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Menu_Iface_Mode { - MENU_IFACE_FOO = 0, - MENU_IFACE_CLUI, - MENU_IFACE_TUI - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - extern int menu_iface_mode; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void menu_iface (void); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* menu_iface.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_MENU_IFACE_HPP + # define VA_MENU_IFACE_HPP + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Menu_Iface_Mode { + MENU_IFACE_FOO = 0, + MENU_IFACE_CLUI, + MENU_IFACE_TUI + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern int menu_iface_mode; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void menu_iface (void); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* menu_iface.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/menu/inc/menu_tui.h b/modules/menu/inc/menu_tui.h index 5ccaebd..74cfd5f 100644 --- a/modules/menu/inc/menu_tui.h +++ b/modules/menu/inc/menu_tui.h @@ -1,27 +1,27 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_MENU_TUI_H - # define VA_MENU_TUI_H - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void menu_tui (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* menu_tui.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_MENU_TUI_H + # define VA_MENU_TUI_H + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void menu_tui (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* menu_tui.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/menu/inc/parser.h b/modules/menu/inc/parser.h index 836385c..a29afcd 100644 --- a/modules/menu/inc/parser.h +++ b/modules/menu/inc/parser.h @@ -1,27 +1,27 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PARSER_H - # define VA_PARSER_H - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void parser (int argc, char *argv[]); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* parser.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PARSER_H + # define VA_PARSER_H + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void parser (int argc, char *argv[]); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* parser.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/menu/inc/parser.hpp b/modules/menu/inc/parser.hpp index ff40d1f..700a0aa 100644 --- a/modules/menu/inc/parser.hpp +++ b/modules/menu/inc/parser.hpp @@ -1,39 +1,39 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PARSER_HPP - # define VA_PARSER_HPP - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void parser (int argc, char *argv[]); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* parser.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PARSER_HPP + # define VA_PARSER_HPP + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void parser (int argc, char *argv[]); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* parser.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/menu/src/menu_clui.c b/modules/menu/src/menu_clui.c index 49c58e2..db2a11e 100644 --- a/modules/menu/src/menu_clui.c +++ b/modules/menu/src/menu_clui.c @@ -1,116 +1,116 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - #include "alx_input.h" - - #include "about.h" -// #include "save.h" - /* start_switch() */ - #include "start.h" - - #include "menu_clui.h" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define BUFF_SIZE (1024) - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -//static void menu_clui_rand (void); -//static void menu_clui_custom (void); -static void menu_clui_load (void); -static void menu_clui_start (void); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void menu_clui (void) -{ - char buff [BUFF_SIZE]; - char ch; - - ch = 'n'; - printf("Read 'Disclaimer of warranty'? (yes/NO): "); - fgets(buff, BUFF_SIZE, stdin); - sscanf(buff, " %c", &ch); - if (ch == 'y' || ch == 'Y') { - puts (" >yes"); - print_share_file(SHARE_DISCLAIMER); - } else { - puts (" >NO"); - } - - ch = 'n'; - printf("Read 'License'? (yes/NO): "); - fgets(buff, BUFF_SIZE, stdin); - sscanf(buff, " %c", &ch); - if (ch == 'y' || ch == 'Y') { - puts (" >yes"); - print_share_file(SHARE_LICENSE); - } else { - puts (" >NO"); - } -#if 0 - printf("Game interface? (NCURSES/text): "); - scanf(" %c%*s ", &ch); - if (ch == 't' || ch == 'T') { - puts (" >text"); - // FIXME - } else { - puts (" >NCURSES"); - // FIXME - } -#endif - menu_clui_load(); -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void menu_clui_load (void) -{ -#if 0 - /* File name */ // FIXME - alx_w_getfname(USER_SAVED_DIR, saved_name, "File name:", saved_name, NULL); -#endif - menu_clui_start(); -} - -static void menu_clui_start (void) -{ - puts(" >>START:"); - start_switch(); - - char buff [BUFF_SIZE]; - char ch; - - ch = 'm'; - printf("Load again? (MENU/load/exit): "); - fgets(buff, BUFF_SIZE, stdin); - sscanf(buff, " %c", &ch); - if (ch == 'p' || ch == 'P') { - puts (" >load"); - menu_clui_start(); - } else if (ch == 'e' || ch == 'E') { - puts (" >exit!"); - } else { - puts (" >MENU"); - menu_clui(); - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + #include "alx_input.h" + + #include "about.h" +// #include "save.h" + /* start_switch() */ + #include "start.h" + + #include "menu_clui.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define BUFF_SIZE (1024) + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +//static void menu_clui_rand (void); +//static void menu_clui_custom (void); +static void menu_clui_load (void); +static void menu_clui_start (void); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void menu_clui (void) +{ + char buff [BUFF_SIZE]; + char ch; + + ch = 'n'; + printf("Read 'Disclaimer of warranty'? (yes/NO): "); + fgets(buff, BUFF_SIZE, stdin); + sscanf(buff, " %c", &ch); + if (ch == 'y' || ch == 'Y') { + puts (" >yes"); + print_share_file(SHARE_DISCLAIMER); + } else { + puts (" >NO"); + } + + ch = 'n'; + printf("Read 'License'? (yes/NO): "); + fgets(buff, BUFF_SIZE, stdin); + sscanf(buff, " %c", &ch); + if (ch == 'y' || ch == 'Y') { + puts (" >yes"); + print_share_file(SHARE_LICENSE); + } else { + puts (" >NO"); + } +#if 0 + printf("Game interface? (NCURSES/text): "); + scanf(" %c%*s ", &ch); + if (ch == 't' || ch == 'T') { + puts (" >text"); + // FIXME + } else { + puts (" >NCURSES"); + // FIXME + } +#endif + menu_clui_load(); +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void menu_clui_load (void) +{ +#if 0 + /* File name */ // FIXME + alx_w_getfname(USER_SAVED_DIR, saved_name, "File name:", saved_name, NULL); +#endif + menu_clui_start(); +} + +static void menu_clui_start (void) +{ + puts(" >>START:"); + start_switch(); + + char buff [BUFF_SIZE]; + char ch; + + ch = 'm'; + printf("Load again? (MENU/load/exit): "); + fgets(buff, BUFF_SIZE, stdin); + sscanf(buff, " %c", &ch); + if (ch == 'p' || ch == 'P') { + puts (" >load"); + menu_clui_start(); + } else if (ch == 'e' || ch == 'E') { + puts (" >exit!"); + } else { + puts (" >MENU"); + menu_clui(); + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/menu/src/menu_iface.c b/modules/menu/src/menu_iface.c index 1a00c29..03b1413 100644 --- a/modules/menu/src/menu_iface.c +++ b/modules/menu/src/menu_iface.c @@ -1,45 +1,45 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - /* menu_clui() */ - #include "menu_clui.h" - /* menu_tui() */ - #include "menu_tui.h" - - #include "menu_iface.h" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -int menu_iface_mode; - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void menu_iface (void) -{ - switch (menu_iface_mode) { - case MENU_IFACE_FOO: - break; - - case MENU_IFACE_CLUI: - menu_clui(); - break; - - case MENU_IFACE_TUI: - menu_tui(); - break; - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + /* menu_clui() */ + #include "menu_clui.h" + /* menu_tui() */ + #include "menu_tui.h" + + #include "menu_iface.h" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +int menu_iface_mode; + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void menu_iface (void) +{ + switch (menu_iface_mode) { + case MENU_IFACE_FOO: + break; + + case MENU_IFACE_CLUI: + menu_clui(); + break; + + case MENU_IFACE_TUI: + menu_tui(); + break; + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/menu/src/menu_tui.c b/modules/menu/src/menu_tui.c index 0d38918..b81c729 100644 --- a/modules/menu/src/menu_tui.c +++ b/modules/menu/src/menu_tui.c @@ -1,334 +1,334 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include - #include - #include - -/* libalx --------------------------------------------------------------------*/ - #include "alx_ncur.h" - -/* Project -------------------------------------------------------------------*/ - /* printf_share_file() */ - #include "about.h" - /* proc_debug */ - #include "proc_iface.h" - /* saved_name */ - #include "save.h" - /* start_switch() */ - #include "start.h" - /* user_iface_log */ - #include "user_iface.h" - -/* Module --------------------------------------------------------------------*/ - #include "menu_tui.h" - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void menu_tui_continue (void); -static void menu_tui_select (void); -static void menu_tui_series (void); -static void menu_tui_devel (void); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void menu_tui (void) -{ - alx_resume_curses(); - - /* Menu dimensions & options */ - int h; - int w; - h = 23; - w = 80; - int N; - N = 4; - struct Alx_Menu mnu[4] = { - {7, 4, "[0] Exit program"}, - {2, 4, "[1] Continue"}, - {4, 4, "[2] Disclaimer of warranty"}, - {5, 4, "[3] Terms and conditions"} - }; - - /* Menu */ - bool wh; - int sw; - wh = true; - while (wh) { - /* Menu loop */ - sw = alx_menu(h, w, N, mnu, "MENU:"); - - /* Selection */ - switch (sw) { - case 0: - wh = false; - break; - - case 1: - menu_tui_continue(); - break; - - case 2: - alx_pause_curses(); - print_share_file(SHARE_DISCLAIMER); - getchar(); - alx_resume_curses(); - break; - - case 3: - alx_pause_curses(); - print_share_file(SHARE_LICENSE); - getchar(); - alx_resume_curses(); - break; - } - } - - alx_pause_curses(); -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void menu_tui_continue (void) -{ - /* Menu dimensions & options */ - WINDOW *win; - int h; - int w; - int r; - int c; - h = 23; - w = 80; - r = 1; - c = (80 - w) / 2; - int N; - N = 6; - struct Alx_Menu mnu[6] = { - {8, 4, "[0] Back"}, - {2, 4, "[1] Start"}, - {3, 4, "[2] Select"}, - {4, 4, "[3] Series"}, - {5, 4, "[4] Change file name"}, - {6, 4, "[5] DEVEL"} - }; - - /* Input box */ - int w2; - int r2; - w2 = w - 8; - r2 = r + h - 5; - char *txt[] = {"File name:"}; - - /* Menu */ - bool wh; - int sw; - wh = true; - while (wh) { - /* Menu loop */ - win = newwin(h, w, r, c); - mvwprintw(win, mnu[1].r, mnu[1].c, "%s (File: \"%s\")", - mnu[1].t, saved_name); - wrefresh(win); - sw = alx_menu_2(win, N, mnu, "CONTINUE:"); - - /* Selection */ - switch (sw) { - case 0: - wh = false; - break; - - case 1: - alx_win_del(win); - alx_pause_curses(); - start_switch(); - alx_resume_curses(); - break; - - case 2: - alx_win_del(win); - menu_tui_select(); - break; - - case 3: - alx_win_del(win); - menu_tui_series(); - break; - - case 4: - save_clr(); - alx_w_getfname(saved_path, saved_name, true, w2, r2, - txt[0], NULL); - alx_win_del(win); - break; - - case 5: - alx_win_del(win); - menu_tui_devel(); - break; - } - } - - /* Cleanup */ - alx_win_del(win); -} - -static void menu_tui_select (void) -{ - /* Menu dimensions & options */ - int h; - int w; - h = 23; - w = 80; - int N; - N = 3; - struct Alx_Menu mnu[3] = { - {6, 4, "[0] Back"}, - {2, 4, "[1] Single image"}, - {4, 4, "[2] Series"} - }; - - /* Menu loop */ - int sw; - sw = alx_menu(h, w, N, mnu, "SELECT MODE:"); - - /* Selection */ - switch (sw) { - case 1: - start_mode = START_SINGLE; - break; - - case 2: - start_mode = START_SERIES; - break; - } - -} - -static void menu_tui_series (void) -{ - /* Menu dimensions & options */ - int h; - int w; - h = 23; - w = 80; - int N; - N = 6; - struct Alx_Menu mnu[6] = { - {8, 4, "[0] Back"}, - {2, 4, "[1] Label"}, - {3, 4, "[2] Objects"}, - {4, 4, "[3] Coins"}, - {5, 4, "[4] Resistor"}, - {6, 4, "[5] Lighters"} - }; - - /* Menu loop */ - int sw; - sw = alx_menu(h, w, N, mnu, "SELECT LEVEL:"); - - /* Selection */ - switch (sw) { - case 1: - proc_mode = PROC_MODE_LABEL_SERIES; - break; - case 2: - proc_mode = PROC_MODE_OBJECTS_SERIES; - break; - case 3: - proc_mode = PROC_MODE_COINS_SERIES; - break; - case 4: - proc_mode = PROC_MODE_RESISTOR_SERIES; - break; - case 5: - proc_mode = PROC_MODE_LIGHTER_SERIES; - break; - } - -} - -static void menu_tui_devel (void) -{ - WINDOW *win; - int h; - int w; - int r; - int c; - h = 23; - w = 80; - r = 1; - c = (80 - w) / 2; - int N; - N = 4; - struct Alx_Menu mnu[4] = { - {6, 4, "[0] Back"}, - {2, 4, "[1] Change process mode"}, - {3, 4, "[2] Change log mode"}, - {4, 4, "[3] Change user iface mode"} - }; - - /* Input box */ - int w2; - int r2; - w2 = w - 8; - r2 = r + h - 5; - char *txt[] = { - "Modes: 0=Auto; 1=Stop@prod; 2=Delay@step; 3=Stop@step", - "Modes: 0=Results; 1=Operations; 2=All", - "Modes: 1=CLUI; 2=TUI" - }; - - /* Menu */ - win = newwin(h, w, r, c); - - /* Menu loop */ - bool wh; - int sw; - wh = true; - while (wh) { - /* Selection */ - sw = alx_menu_2(win, N, mnu, "DEVELOPER OPTIONS:"); - - switch (sw) { - case 0: - wh = false; - break; - - case 1: - proc_debug = alx_w_getint(w2, r2, txt[0], - PROC_DBG_NO, 0, PROC_DBG_STOP_STEP, - NULL); - break; - - case 2: - user_iface_log.visible = alx_w_getint(w2, r2, txt[1], - 0, 2, 2, NULL); - break; - - case 3: - user_iface_mode = alx_w_getint(w2, r2, txt[2], - 1, 2, 2, NULL); - break; - } - } - - /* Cleanup */ - alx_win_del(win); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + #include + #include + #include + +/* libalx --------------------------------------------------------------------*/ + #include "alx_ncur.h" + +/* Project -------------------------------------------------------------------*/ + /* printf_share_file() */ + #include "about.h" + /* proc_debug */ + #include "proc_iface.h" + /* saved_name */ + #include "save.h" + /* start_switch() */ + #include "start.h" + /* user_iface_log */ + #include "user_iface.h" + +/* Module --------------------------------------------------------------------*/ + #include "menu_tui.h" + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void menu_tui_continue (void); +static void menu_tui_select (void); +static void menu_tui_series (void); +static void menu_tui_devel (void); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void menu_tui (void) +{ + alx_resume_curses(); + + /* Menu dimensions & options */ + int h; + int w; + h = 23; + w = 80; + int N; + N = 4; + struct Alx_Menu mnu[4] = { + {7, 4, "[0] Exit program"}, + {2, 4, "[1] Continue"}, + {4, 4, "[2] Disclaimer of warranty"}, + {5, 4, "[3] Terms and conditions"} + }; + + /* Menu */ + bool wh; + int sw; + wh = true; + while (wh) { + /* Menu loop */ + sw = alx_menu(h, w, N, mnu, "MENU:"); + + /* Selection */ + switch (sw) { + case 0: + wh = false; + break; + + case 1: + menu_tui_continue(); + break; + + case 2: + alx_pause_curses(); + print_share_file(SHARE_DISCLAIMER); + getchar(); + alx_resume_curses(); + break; + + case 3: + alx_pause_curses(); + print_share_file(SHARE_LICENSE); + getchar(); + alx_resume_curses(); + break; + } + } + + alx_pause_curses(); +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void menu_tui_continue (void) +{ + /* Menu dimensions & options */ + WINDOW *win; + int h; + int w; + int r; + int c; + h = 23; + w = 80; + r = 1; + c = (80 - w) / 2; + int N; + N = 6; + struct Alx_Menu mnu[6] = { + {8, 4, "[0] Back"}, + {2, 4, "[1] Start"}, + {3, 4, "[2] Select"}, + {4, 4, "[3] Series"}, + {5, 4, "[4] Change file name"}, + {6, 4, "[5] DEVEL"} + }; + + /* Input box */ + int w2; + int r2; + w2 = w - 8; + r2 = r + h - 5; + char *txt[] = {"File name:"}; + + /* Menu */ + bool wh; + int sw; + wh = true; + while (wh) { + /* Menu loop */ + win = newwin(h, w, r, c); + mvwprintw(win, mnu[1].r, mnu[1].c, "%s (File: \"%s\")", + mnu[1].t, saved_name); + wrefresh(win); + sw = alx_menu_2(win, N, mnu, "CONTINUE:"); + + /* Selection */ + switch (sw) { + case 0: + wh = false; + break; + + case 1: + alx_win_del(win); + alx_pause_curses(); + start_switch(); + alx_resume_curses(); + break; + + case 2: + alx_win_del(win); + menu_tui_select(); + break; + + case 3: + alx_win_del(win); + menu_tui_series(); + break; + + case 4: + save_clr(); + alx_w_getfname(saved_path, saved_name, true, w2, r2, + txt[0], NULL); + alx_win_del(win); + break; + + case 5: + alx_win_del(win); + menu_tui_devel(); + break; + } + } + + /* Cleanup */ + alx_win_del(win); +} + +static void menu_tui_select (void) +{ + /* Menu dimensions & options */ + int h; + int w; + h = 23; + w = 80; + int N; + N = 3; + struct Alx_Menu mnu[3] = { + {6, 4, "[0] Back"}, + {2, 4, "[1] Single image"}, + {4, 4, "[2] Series"} + }; + + /* Menu loop */ + int sw; + sw = alx_menu(h, w, N, mnu, "SELECT MODE:"); + + /* Selection */ + switch (sw) { + case 1: + start_mode = START_SINGLE; + break; + + case 2: + start_mode = START_SERIES; + break; + } + +} + +static void menu_tui_series (void) +{ + /* Menu dimensions & options */ + int h; + int w; + h = 23; + w = 80; + int N; + N = 6; + struct Alx_Menu mnu[6] = { + {8, 4, "[0] Back"}, + {2, 4, "[1] Label"}, + {3, 4, "[2] Objects"}, + {4, 4, "[3] Coins"}, + {5, 4, "[4] Resistor"}, + {6, 4, "[5] Lighters"} + }; + + /* Menu loop */ + int sw; + sw = alx_menu(h, w, N, mnu, "SELECT LEVEL:"); + + /* Selection */ + switch (sw) { + case 1: + proc_mode = PROC_MODE_LABEL_SERIES; + break; + case 2: + proc_mode = PROC_MODE_OBJECTS_SERIES; + break; + case 3: + proc_mode = PROC_MODE_COINS_SERIES; + break; + case 4: + proc_mode = PROC_MODE_RESISTOR_SERIES; + break; + case 5: + proc_mode = PROC_MODE_LIGHTER_SERIES; + break; + } + +} + +static void menu_tui_devel (void) +{ + WINDOW *win; + int h; + int w; + int r; + int c; + h = 23; + w = 80; + r = 1; + c = (80 - w) / 2; + int N; + N = 4; + struct Alx_Menu mnu[4] = { + {6, 4, "[0] Back"}, + {2, 4, "[1] Change process mode"}, + {3, 4, "[2] Change log mode"}, + {4, 4, "[3] Change user iface mode"} + }; + + /* Input box */ + int w2; + int r2; + w2 = w - 8; + r2 = r + h - 5; + char *txt[] = { + "Modes: 0=Auto; 1=Stop@prod; 2=Delay@step; 3=Stop@step", + "Modes: 0=Results; 1=Operations; 2=All", + "Modes: 1=CLUI; 2=TUI" + }; + + /* Menu */ + win = newwin(h, w, r, c); + + /* Menu loop */ + bool wh; + int sw; + wh = true; + while (wh) { + /* Selection */ + sw = alx_menu_2(win, N, mnu, "DEVELOPER OPTIONS:"); + + switch (sw) { + case 0: + wh = false; + break; + + case 1: + proc_debug = alx_w_getint(w2, r2, txt[0], + PROC_DBG_NO, 0, PROC_DBG_STOP_STEP, + NULL); + break; + + case 2: + user_iface_log.visible = alx_w_getint(w2, r2, txt[1], + 0, 2, 2, NULL); + break; + + case 3: + user_iface_mode = alx_w_getint(w2, r2, txt[2], + 1, 2, 2, NULL); + break; + } + } + + /* Cleanup */ + alx_win_del(win); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/menu/src/parser.c b/modules/menu/src/parser.c index 6b03264..ef8cec9 100644 --- a/modules/menu/src/parser.c +++ b/modules/menu/src/parser.c @@ -1,140 +1,140 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include - /* FILE & fopen() & snprintf() & FILENAME_MAX */ - #include - /* exit() */ - #include - -/* Project -------------------------------------------------------------------*/ - /* print_share_...() */ - #include "about.h" - /* user_iface_mode */ - #include "user_iface.h" - /* saved_name */ - #include "save.h" - -/* Module --------------------------------------------------------------------*/ - /* menu_iface_mode */ - #include "menu_iface.h" - - #include "parser.h" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define OPT_LIST "hLuv""f:i:" - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void parse_file (char* argument); -static void parse_iface (char* argument); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void parser (int argc, char *argv[]) -{ - int opt = 0; - int opt_index = 0; - - struct option long_options[] = { - /* Standard */ - {"help", no_argument, 0, 'h'}, - {"license", no_argument, 0, 'L'}, - {"usage", no_argument, 0, 'u'}, - {"version", no_argument, 0, 'v'}, - /* Non-standard */ - {"file", required_argument, 0, 'f'}, - {"iface", required_argument, 0, 'i'}, - /* Null */ - {0, 0, 0, 0} - }; - - while ((opt = getopt_long(argc, argv, OPT_LIST, long_options, - &opt_index)) != -1) { - - switch (opt) { - /* Standard */ - case 'h': - print_share_file(SHARE_HELP); - exit(EXIT_SUCCESS); - - case 'L': - print_share_file(SHARE_LICENSE); - exit(EXIT_SUCCESS); - - case 'u': - print_share_file(SHARE_USAGE); - exit(EXIT_SUCCESS); - - case 'v': - print_version(); - exit(EXIT_SUCCESS); - - /* Non-standard */ - case 'f': - parse_file(optarg); - break; - - case 'i': - parse_iface(optarg); - break; - - case '?': - /* getopt_long already printed an error message. */ - - default: - print_share_file(SHARE_USAGE); - exit(EXIT_FAILURE); - } - } -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void parse_file (char* argument) -{ - // FIXME - FILE *fp; - fp = fopen(argument, "r"); - if (!fp) { - printf("--file argument not valid\n"); - printf("It must be a valid file name (relative to saved dir)\n"); - exit(EXIT_FAILURE); - } else { - fclose(fp); - - sprintf(saved_path, ""); - snprintf(saved_name, FILENAME_MAX, "%s", argument); - } -} - -static void parse_iface (char* argument) -{ - menu_iface_mode = atoi(argument); - user_iface_mode = menu_iface_mode; - if (menu_iface_mode < MENU_IFACE_CLUI || menu_iface_mode > MENU_IFACE_TUI) { - printf("--iface argument not valid\n"); - printf("It must be an integer [%i U %i]\n", MENU_IFACE_CLUI, MENU_IFACE_TUI); - exit(EXIT_FAILURE); - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + #include + /* FILE & fopen() & snprintf() & FILENAME_MAX */ + #include + /* exit() */ + #include + +/* Project -------------------------------------------------------------------*/ + /* print_share_...() */ + #include "about.h" + /* user_iface_mode */ + #include "user_iface.h" + /* saved_name */ + #include "save.h" + +/* Module --------------------------------------------------------------------*/ + /* menu_iface_mode */ + #include "menu_iface.h" + + #include "parser.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define OPT_LIST "hLuv""f:i:" + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void parse_file (char* argument); +static void parse_iface (char* argument); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void parser (int argc, char *argv[]) +{ + int opt = 0; + int opt_index = 0; + + struct option long_options[] = { + /* Standard */ + {"help", no_argument, 0, 'h'}, + {"license", no_argument, 0, 'L'}, + {"usage", no_argument, 0, 'u'}, + {"version", no_argument, 0, 'v'}, + /* Non-standard */ + {"file", required_argument, 0, 'f'}, + {"iface", required_argument, 0, 'i'}, + /* Null */ + {0, 0, 0, 0} + }; + + while ((opt = getopt_long(argc, argv, OPT_LIST, long_options, + &opt_index)) != -1) { + + switch (opt) { + /* Standard */ + case 'h': + print_share_file(SHARE_HELP); + exit(EXIT_SUCCESS); + + case 'L': + print_share_file(SHARE_LICENSE); + exit(EXIT_SUCCESS); + + case 'u': + print_share_file(SHARE_USAGE); + exit(EXIT_SUCCESS); + + case 'v': + print_version(); + exit(EXIT_SUCCESS); + + /* Non-standard */ + case 'f': + parse_file(optarg); + break; + + case 'i': + parse_iface(optarg); + break; + + case '?': + /* getopt_long already printed an error message. */ + + default: + print_share_file(SHARE_USAGE); + exit(EXIT_FAILURE); + } + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void parse_file (char* argument) +{ + // FIXME + FILE *fp; + fp = fopen(argument, "r"); + if (!fp) { + printf("--file argument not valid\n"); + printf("It must be a valid file name (relative to saved dir)\n"); + exit(EXIT_FAILURE); + } else { + fclose(fp); + + sprintf(saved_path, ""); + snprintf(saved_name, FILENAME_MAX, "%s", argument); + } +} + +static void parse_iface (char* argument) +{ + menu_iface_mode = atoi(argument); + user_iface_mode = menu_iface_mode; + if (menu_iface_mode < MENU_IFACE_CLUI || menu_iface_mode > MENU_IFACE_TUI) { + printf("--iface argument not valid\n"); + printf("It must be an integer [%i U %i]\n", MENU_IFACE_CLUI, MENU_IFACE_TUI); + exit(EXIT_FAILURE); + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_coins.h b/modules/proc/inc/proc_coins.h index 211971c..7e29d7d 100644 --- a/modules/proc/inc/proc_coins.h +++ b/modules/proc/inc/proc_coins.h @@ -1,48 +1,48 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_COINS_H - # define VA_PROC_COINS_H - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Coins { - COINS_OK, - COINS_NOK_COINS, - COINS_NOK_OVERLAP, - COINS_NOK_SIZE - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - int proc_coins (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_coins.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_COINS_H + # define VA_PROC_COINS_H + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Coins { + COINS_OK, + COINS_NOK_COINS, + COINS_NOK_OVERLAP, + COINS_NOK_SIZE + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_coins (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_coins.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_coins.hpp b/modules/proc/inc/proc_coins.hpp index 5b64870..9315324 100644 --- a/modules/proc/inc/proc_coins.hpp +++ b/modules/proc/inc/proc_coins.hpp @@ -1,60 +1,60 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_COINS_HPP - # define VA_PROC_COINS_HPP - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Coins { - COINS_OK, - COINS_NOK_COINS, - COINS_NOK_OVERLAP, - COINS_NOK_SIZE - }; - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - int proc_coins (void); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_coins.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_COINS_HPP + # define VA_PROC_COINS_HPP + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Coins { + COINS_OK, + COINS_NOK_COINS, + COINS_NOK_OVERLAP, + COINS_NOK_SIZE + }; + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_coins (void); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_coins.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_common.h b/modules/proc/inc/proc_common.h index e0a6e36..1d4077e 100644 --- a/modules/proc/inc/proc_common.h +++ b/modules/proc/inc/proc_common.h @@ -1,45 +1,45 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_COMMON_H - # define VA_PROC_COMMON_H - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void proc_show_img (void); - - void clock_start (void); - void clock_stop (const char *txt); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_common.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_COMMON_H + # define VA_PROC_COMMON_H + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void proc_show_img (void); + + void clock_start (void); + void clock_stop (const char *txt); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_common.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_common.hpp b/modules/proc/inc/proc_common.hpp index 85d5eb3..7332b84 100644 --- a/modules/proc/inc/proc_common.hpp +++ b/modules/proc/inc/proc_common.hpp @@ -1,111 +1,111 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_COMMON_HPP - # define VA_PROC_COMMON_HPP - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void proc_apply (void); -void proc_save_mem (int n); -void proc_load_mem (int n); -void proc_save_ref (void); -void proc_save_file (void); -void proc_save_update (void); - -void proc_local_max (void); -void proc_skeleton (void); -void proc_lines_vertical (void); -void proc_median_horizontal (void); -void proc_median_vertical (void); - -void proc_pixel_get (int x, int y, unsigned char *val); -void proc_pixel_set (int x, int y, unsigned char val); -void proc_ROI (int x, int y, int w, int h); -void proc_and_2ref (void); -void proc_not (void); -void proc_or_2ref (void); -void proc_cmp (int cmp); -void proc_dilate (int size); -void proc_erode (int size); -void proc_dilate_erode (int size); -void proc_erode_dilate (int size); -void proc_smooth (int method, int ksize); -void proc_border (int size); -void proc_rotate (double center_x, double center_y, double angle); -void proc_adaptive_threshold (int method, int type, int ksize); -void proc_cvt_color (int method); -void proc_distance_transform (void); -void proc_threshold (int type, int ksize); -void proc_contours ( - std::vector >> *contours, - class cv::Mat *hierarchy); -void proc_contours_size ( - std::vector >> *contours, - double *area, - double *perimeter); -void proc_bounding_rect ( - std::vector > *contour, - class cv::Rect_ *rect, - bool show); -void proc_fit_ellipse ( - std::vector > *contour, - class cv::RotatedRect *rect, - bool show); -void proc_min_area_rect ( - std::vector > *contour, - class cv::RotatedRect *rect, - bool show); - -void proc_OCR (int lang, int conf); -void proc_zbar (int type); - -void proc_show_img (void); - -void clock_start (void); -void clock_stop (const char *txt); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_common.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_COMMON_HPP + # define VA_PROC_COMMON_HPP + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void proc_apply (void); +void proc_save_mem (int n); +void proc_load_mem (int n); +void proc_save_ref (void); +void proc_save_file (void); +void proc_save_update (void); + +void proc_local_max (void); +void proc_skeleton (void); +void proc_lines_vertical (void); +void proc_median_horizontal (void); +void proc_median_vertical (void); + +void proc_pixel_get (int x, int y, unsigned char *val); +void proc_pixel_set (int x, int y, unsigned char val); +void proc_ROI (int x, int y, int w, int h); +void proc_and_2ref (void); +void proc_not (void); +void proc_or_2ref (void); +void proc_cmp (int cmp); +void proc_dilate (int size); +void proc_erode (int size); +void proc_dilate_erode (int size); +void proc_erode_dilate (int size); +void proc_smooth (int method, int ksize); +void proc_border (int size); +void proc_rotate (double center_x, double center_y, double angle); +void proc_adaptive_threshold (int method, int type, int ksize); +void proc_cvt_color (int method); +void proc_distance_transform (void); +void proc_threshold (int type, int ksize); +void proc_contours ( + std::vector >> *contours, + class cv::Mat *hierarchy); +void proc_contours_size ( + std::vector >> *contours, + double *area, + double *perimeter); +void proc_bounding_rect ( + std::vector > *contour, + class cv::Rect_ *rect, + bool show); +void proc_fit_ellipse ( + std::vector > *contour, + class cv::RotatedRect *rect, + bool show); +void proc_min_area_rect ( + std::vector > *contour, + class cv::RotatedRect *rect, + bool show); + +void proc_OCR (int lang, int conf); +void proc_zbar (int type); + +void proc_show_img (void); + +void clock_start (void); +void clock_stop (const char *txt); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_common.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_iface.h b/modules/proc/inc/proc_iface.h index eefe9c7..57f23a9 100644 --- a/modules/proc/inc/proc_iface.h +++ b/modules/proc/inc/proc_iface.h @@ -1,71 +1,71 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_IFACE_H - # define VA_PROC_IFACE_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Mode { - PROC_MODE_FOO, - - PROC_MODE = 0x008000u, - PROC_MODE_LABEL_SERIES, - PROC_MODE_LABEL_CALIB, - PROC_MODE_OBJECTS_SERIES, - PROC_MODE_OBJECTS_CALIB, - PROC_MODE_COINS_SERIES, - PROC_MODE_COINS_CALIB, - PROC_MODE_RESISTOR_SERIES, - PROC_MODE_RESISTOR_CALIB, - PROC_MODE_LIGHTER_SERIES - }; - - enum Proc_DBG { - PROC_DBG_NO, - PROC_DBG_STOP_ITEM, - PROC_DBG_DELAY_STEP, - PROC_DBG_STOP_STEP - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - extern int proc_debug; - extern int proc_mode; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - int proc_iface_single (int action); - void proc_iface_series (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_iface.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_IFACE_H + # define VA_PROC_IFACE_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Mode { + PROC_MODE_FOO, + + PROC_MODE = 0x008000u, + PROC_MODE_LABEL_SERIES, + PROC_MODE_LABEL_CALIB, + PROC_MODE_OBJECTS_SERIES, + PROC_MODE_OBJECTS_CALIB, + PROC_MODE_COINS_SERIES, + PROC_MODE_COINS_CALIB, + PROC_MODE_RESISTOR_SERIES, + PROC_MODE_RESISTOR_CALIB, + PROC_MODE_LIGHTER_SERIES + }; + + enum Proc_DBG { + PROC_DBG_NO, + PROC_DBG_STOP_ITEM, + PROC_DBG_DELAY_STEP, + PROC_DBG_STOP_STEP + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern int proc_debug; + extern int proc_mode; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_iface_single (int action); + void proc_iface_series (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_iface.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_iface.hpp b/modules/proc/inc/proc_iface.hpp index cabf958..d1e03de 100644 --- a/modules/proc/inc/proc_iface.hpp +++ b/modules/proc/inc/proc_iface.hpp @@ -1,83 +1,83 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_IFACE_H - # define VA_PROC_IFACE_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Mode { - PROC_MODE_FOO, - - PROC_MODE = 0x008000u, - PROC_MODE_LABEL_SERIES, - PROC_MODE_LABEL_CALIB, - PROC_MODE_OBJECTS_SERIES, - PROC_MODE_OBJECTS_CALIB, - PROC_MODE_COINS_SERIES, - PROC_MODE_COINS_CALIB, - PROC_MODE_RESISTOR_SERIES, - PROC_MODE_RESISTOR_CALIB, - PROC_MODE_LIGHTER_SERIES - }; - - enum Proc_DBG { - PROC_DBG_NO, - PROC_DBG_STOP_ITEM, - PROC_DBG_DELAY_STEP, - PROC_DBG_STOP_STEP - }; - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - extern int proc_debug; - extern int proc_mode; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - int proc_iface_single (int action); - void proc_iface_series (void); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_iface.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_IFACE_H + # define VA_PROC_IFACE_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Mode { + PROC_MODE_FOO, + + PROC_MODE = 0x008000u, + PROC_MODE_LABEL_SERIES, + PROC_MODE_LABEL_CALIB, + PROC_MODE_OBJECTS_SERIES, + PROC_MODE_OBJECTS_CALIB, + PROC_MODE_COINS_SERIES, + PROC_MODE_COINS_CALIB, + PROC_MODE_RESISTOR_SERIES, + PROC_MODE_RESISTOR_CALIB, + PROC_MODE_LIGHTER_SERIES + }; + + enum Proc_DBG { + PROC_DBG_NO, + PROC_DBG_STOP_ITEM, + PROC_DBG_DELAY_STEP, + PROC_DBG_STOP_STEP + }; + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern int proc_debug; + extern int proc_mode; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_iface_single (int action); + void proc_iface_series (void); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_iface.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_label.h b/modules/proc/inc/proc_label.h index 1792e43..a1091b8 100644 --- a/modules/proc/inc/proc_label.h +++ b/modules/proc/inc/proc_label.h @@ -1,50 +1,50 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_LABEL_H - # define VA_PROC_LABEL_H - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Label { - LABEL_OK, - LABEL_NOK_LABEL, - LABEL_NOK_CERDO, - LABEL_NOK_BCODE, - LABEL_NOK_PRODUCT, - LABEL_NOK_PRICE - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - int proc_label (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_label.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_LABEL_H + # define VA_PROC_LABEL_H + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Label { + LABEL_OK, + LABEL_NOK_LABEL, + LABEL_NOK_CERDO, + LABEL_NOK_BCODE, + LABEL_NOK_PRODUCT, + LABEL_NOK_PRICE + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_label (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_label.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_label.hpp b/modules/proc/inc/proc_label.hpp index eb5dd66..b456a55 100644 --- a/modules/proc/inc/proc_label.hpp +++ b/modules/proc/inc/proc_label.hpp @@ -1,62 +1,62 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_LABEL_HPP - # define VA_PROC_LABEL_HPP - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Label { - LABEL_OK, - LABEL_NOK_LABEL, - LABEL_NOK_CERDO, - LABEL_NOK_BCODE, - LABEL_NOK_PRODUCT, - LABEL_NOK_PRICE - }; - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - int proc_label (void); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_label.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_LABEL_HPP + # define VA_PROC_LABEL_HPP + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Label { + LABEL_OK, + LABEL_NOK_LABEL, + LABEL_NOK_CERDO, + LABEL_NOK_BCODE, + LABEL_NOK_PRODUCT, + LABEL_NOK_PRICE + }; + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_label (void); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_label.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_lighters.h b/modules/proc/inc/proc_lighters.h index 115d98b..f10c533 100644 --- a/modules/proc/inc/proc_lighters.h +++ b/modules/proc/inc/proc_lighters.h @@ -1,47 +1,47 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_LIGHTERS_H - # define VA_PROC_LIGHTERS_H - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Lighter { - LIGHTER_OK, - LIGHTER_NOK_LIGHTER, - LIGHTER_NOK_SIZE - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - int proc_lighter (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_lighters.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_LIGHTERS_H + # define VA_PROC_LIGHTERS_H + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Lighter { + LIGHTER_OK, + LIGHTER_NOK_LIGHTER, + LIGHTER_NOK_SIZE + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_lighter (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_lighters.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_lighters.hpp b/modules/proc/inc/proc_lighters.hpp index 06c4080..cc16a79 100644 --- a/modules/proc/inc/proc_lighters.hpp +++ b/modules/proc/inc/proc_lighters.hpp @@ -1,59 +1,59 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_LIGHTERS_H - # define VA_PROC_LIGHTERS_H - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Lighter { - LIGHTER_OK, - LIGHTER_NOK_LIGHTER, - LIGHTER_NOK_SIZE - }; - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - int proc_lighter (void); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_lighters.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_LIGHTERS_H + # define VA_PROC_LIGHTERS_H + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Lighter { + LIGHTER_OK, + LIGHTER_NOK_LIGHTER, + LIGHTER_NOK_SIZE + }; + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_lighter (void); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_lighters.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_objects.h b/modules/proc/inc/proc_objects.h index fb53ac4..be841ba 100644 --- a/modules/proc/inc/proc_objects.h +++ b/modules/proc/inc/proc_objects.h @@ -1,49 +1,49 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_OBJECTS_H - # define VA_PROC_OBJECTS_H - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Objects { - OBJECTS_OK, - OBJECTS_NOK_PATTERN, - OBJECTS_NOK_OBJECTS, - OBJECTS_NOK_SIZE - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - int proc_objects_calibrate (void); - int proc_objects (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_objects.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_OBJECTS_H + # define VA_PROC_OBJECTS_H + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Objects { + OBJECTS_OK, + OBJECTS_NOK_PATTERN, + OBJECTS_NOK_OBJECTS, + OBJECTS_NOK_SIZE + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_objects_calibrate (void); + int proc_objects (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_objects.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_objects.hpp b/modules/proc/inc/proc_objects.hpp index 300e625..1a3084f 100644 --- a/modules/proc/inc/proc_objects.hpp +++ b/modules/proc/inc/proc_objects.hpp @@ -1,61 +1,61 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_OBJECTS_HPP - # define VA_PROC_OBJECTS_HPP - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Objects { - OBJECTS_OK, - OBJECTS_NOK_PATTERN, - OBJECTS_NOK_OBJECTS, - OBJECTS_NOK_SIZE - }; - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - int proc_objects_calibrate (void); - int proc_objects (void); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_objects.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_OBJECTS_HPP + # define VA_PROC_OBJECTS_HPP + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Objects { + OBJECTS_OK, + OBJECTS_NOK_PATTERN, + OBJECTS_NOK_OBJECTS, + OBJECTS_NOK_SIZE + }; + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_objects_calibrate (void); + int proc_objects (void); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_objects.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_resistor.h b/modules/proc/inc/proc_resistor.h index 7784ebb..ca60a8a 100644 --- a/modules/proc/inc/proc_resistor.h +++ b/modules/proc/inc/proc_resistor.h @@ -1,50 +1,50 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_RESISTOR_H - # define VA_PROC_RESISTOR_H - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Resistor { - RESISTOR_OK, - RESISTOR_NOK_RESISTOR, - RESISTOR_NOK_BANDS, - RESISTOR_NOK_COLOR, - RESISTOR_NOK_STD_VALUE, - RESISTOR_NOK_TOLERANCE - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - int proc_resistor (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_resistor.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_RESISTOR_H + # define VA_PROC_RESISTOR_H + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Resistor { + RESISTOR_OK, + RESISTOR_NOK_RESISTOR, + RESISTOR_NOK_BANDS, + RESISTOR_NOK_COLOR, + RESISTOR_NOK_STD_VALUE, + RESISTOR_NOK_TOLERANCE + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_resistor (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_resistor.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_resistor.hpp b/modules/proc/inc/proc_resistor.hpp index 9982e6f..fce85d8 100644 --- a/modules/proc/inc/proc_resistor.hpp +++ b/modules/proc/inc/proc_resistor.hpp @@ -1,62 +1,62 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_RESISTOR_HPP - # define VA_PROC_RESISTOR_HPP - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Resistor { - RESISTOR_OK, - RESISTOR_NOK_RESISTOR, - RESISTOR_NOK_BANDS, - RESISTOR_NOK_COLOR, - RESISTOR_NOK_STD_VALUE, - RESISTOR_NOK_TOLERANCE - }; - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - int proc_resistor (void); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_resistor.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_RESISTOR_HPP + # define VA_PROC_RESISTOR_HPP + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Resistor { + RESISTOR_OK, + RESISTOR_NOK_RESISTOR, + RESISTOR_NOK_BANDS, + RESISTOR_NOK_COLOR, + RESISTOR_NOK_STD_VALUE, + RESISTOR_NOK_TOLERANCE + }; + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_resistor (void); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_resistor.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/src/proc_coins.cpp b/modules/proc/src/proc_coins.cpp index 71bbac2..8f26e71 100644 --- a/modules/proc/src/proc_coins.cpp +++ b/modules/proc/src/proc_coins.cpp @@ -1,378 +1,378 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* snprintf() & fflush() */ - #include - -/* Packages ------------------------------------------------------------------*/ - /* openCV */ - #include - -/* libalx ------------------------------------------------------------------*/ - /* alx_maximum_u8() */ - #include "alx_math.hpp" - -/* Project -------------------------------------------------------------------*/ - /* constants */ - #include "img_iface.hpp" - /* user_iface_log */ - #include "user_iface.hpp" - -/* Module --------------------------------------------------------------------*/ - #include "proc_common.hpp" - - #include "proc_coins.hpp" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define COINS_MAX 1024 - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ -struct Coins_Properties { - /* position */ - int x; - int y; - - /* value */ - uint8_t diameter_pix; - double diameter_mm; - double value; -}; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ - -/* Static --------------------------------------------------------------------*/ -static class std::vector >> contours; -static class cv::Mat hierarchy; -static class cv::Rect_ rectangle [COINS_MAX]; -static int coins_n; -static struct Coins_Properties coins [COINS_MAX]; -static double ratio_mm_per_pix; -static double value_total; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_coins (int status); - -static void coins_segmentate (void); -static int coins_positions (void); -static void coins_diameters_pix (void); -static void calibrate_mm_per_pix (void); -static void coins_diameters_mm (void); -static int coins_values (void); -static double coin_value (double diameter_mm); -static void coins_total_value (void); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -int proc_coins (void) -{ - int status; - - proc_save_mem(0); - /* Segmentate coins */ - { - /* Measure time */ - clock_start(); - - coins_segmentate(); - - /* Measure time */ - clock_stop("Segmentate coins"); - } - /* Find coins positions */ - { - /* Measure time */ - clock_start(); - - status = coins_positions(); - if (status) { - result_coins(status); - return status; - } - - /* Measure time */ - clock_stop("Find coins positions"); - } - /* Get coin diameters in pixels */ - { - /* Measure time */ - clock_start(); - - coins_diameters_pix(); - - /* Measure time */ - clock_stop("Coins diameters in pixels"); - } - /* Calibrate with the biggest coin; every img should have a 2 € coin */ - { - /* Measure time */ - clock_start(); - - calibrate_mm_per_pix(); - - /* Measure time */ - clock_stop("Calibrate (mm per pix)"); - } - /* Get coins diameters in mm */ - { - /* Measure time */ - clock_start(); - - coins_diameters_mm(); - - /* Measure time */ - clock_stop("Coins diameters in mm"); - } - /* Get coins values (by their sizes) */ - { - /* Measure time */ - clock_start(); - - status = coins_values(); - if (status) { - result_coins(status); - return status; - } - - /* Measure time */ - clock_stop("Coins values"); - } - /* Add total value */ - { - /* Measure time */ - clock_start(); - - coins_total_value(); - - /* Measure time */ - clock_stop("Total value"); - } - - status = COINS_OK; - result_coins(status); - return status; -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_coins (int status) -{ - /* Cleanup */ - - /* Write result into log */ - switch (status) { - case COINS_OK: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: OK"); - break; - case COINS_NOK_COINS: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK_COINS"); - break; -#if 0 - case COINS_NOK_OVERLAP: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK_OVERLAP"); - break; -#endif - case COINS_NOK_SIZE: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK_SIZE"); - break; - default: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK"); - break; - } - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - -static void coins_segmentate (void) -{ - proc_load_mem(0); - - proc_cmp(IMG_IFACE_CMP_BLUE); - proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU); - proc_distance_transform(); - proc_local_max(); - proc_dilate(6); - proc_save_mem(1); -} - -static int coins_positions (void) -{ - int status; - int i; - - proc_load_mem(1); - - proc_contours(&contours, &hierarchy); - coins_n = contours.size(); - - /* If no contour is found, error: NOK_COINS */ - if (!coins_n) { - status = COINS_NOK_COINS; - return status; - } - - /* Get position of each contour */ - for (i = 0; i < coins_n; i++) { - proc_bounding_rect(&(contours[i]), &(rectangle[i]), true); - coins[i].x = rectangle[i].x + rectangle[i].width / 2.0; - coins[i].y = rectangle[i].y + rectangle[i].height / 2.0; - } - - status = COINS_OK; - return status; -} - -static void coins_diameters_pix (void) -{ - int i; - - proc_load_mem(1); - - /* Get coins diameters in pixels */ - for (i = 0; i < coins_n; i++) { - proc_pixel_get(coins[i].x, coins[i].y, - &(coins[i].diameter_pix)); - coins[i].diameter_pix *= 2; - } -} - -static void calibrate_mm_per_pix (void) -{ - uint8_t coins_size_pix [coins_n]; - int i; - int max_pos; - int max_size; - - for (i = 0; i < coins_n; i++) { - coins_size_pix[i] = coins[i].diameter_pix; - } - - max_pos = alx_maximum_u8(coins_n, coins_size_pix); - max_size = coins_size_pix[max_pos]; - ratio_mm_per_pix = 25.75 / max_size; -} - -static void coins_diameters_mm (void) -{ - int i; - - for (i = 0; i < coins_n; i++) { - coins[i].diameter_mm = ratio_mm_per_pix * - coins[i].diameter_pix; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin[%i]: %.2lf mm", - i, - coins[i].diameter_mm); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - } -} - -static int coins_values (void) -{ - int status; - int i; - - for (i = 0; i < coins_n; i++) { - coins[i].value = coin_value(coins[i].diameter_mm); - - /* If a coin is of invalid size, error: NOK_SIZE */ - if (coins[i].value < 0) { - status = COINS_NOK_SIZE; - return status; - } - - /* Write values into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin[%i]: %.2lf EUR", - i, - coins[i].value); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - } - - status = COINS_OK; - return status; -} - -static double coin_value (double diameter_mm) -{ - double value; - - /* Get coin value by its diameter in mm */ - if (diameter_mm > 27.00) { - value = -1; - } else if (diameter_mm > 25.00) { - value = 2.00; - } else if (diameter_mm > 23.75) { - value = 0.50; - } else if (diameter_mm > 22.75) { - value = 1.00; - } else if (diameter_mm > 21.75) { - value = 0.20; - } else if (diameter_mm > 20.50) { - value = 0.05; - } else if (diameter_mm > 19.25) { - value = 0.10; - } else if (diameter_mm > 17.50) { - value = 0.02; - } else if (diameter_mm > 15.00) { - value = 0.01; - } else { - value = -1; - } - - return value; -} - -static void coins_total_value (void) -{ - int i; - - value_total = 0.00; - - for (i = 0; i < coins_n; i++) { - value_total += coins[i].value; - } - - /* Write total value into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Total value: %.2lf EUR", - value_total); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* snprintf() & fflush() */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* openCV */ + #include + +/* libalx ------------------------------------------------------------------*/ + /* alx_maximum_u8() */ + #include "alx_math.hpp" + +/* Project -------------------------------------------------------------------*/ + /* constants */ + #include "img_iface.hpp" + /* user_iface_log */ + #include "user_iface.hpp" + +/* Module --------------------------------------------------------------------*/ + #include "proc_common.hpp" + + #include "proc_coins.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define COINS_MAX 1024 + + +/****************************************************************************** + ******* structs ************************************************************** + ******************************************************************************/ +struct Coins_Properties { + /* position */ + int x; + int y; + + /* value */ + uint8_t diameter_pix; + double diameter_mm; + double value; +}; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ + +/* Static --------------------------------------------------------------------*/ +static class std::vector >> contours; +static class cv::Mat hierarchy; +static class cv::Rect_ rectangle [COINS_MAX]; +static int coins_n; +static struct Coins_Properties coins [COINS_MAX]; +static double ratio_mm_per_pix; +static double value_total; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_coins (int status); + +static void coins_segmentate (void); +static int coins_positions (void); +static void coins_diameters_pix (void); +static void calibrate_mm_per_pix (void); +static void coins_diameters_mm (void); +static int coins_values (void); +static double coin_value (double diameter_mm); +static void coins_total_value (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +int proc_coins (void) +{ + int status; + + proc_save_mem(0); + /* Segmentate coins */ + { + /* Measure time */ + clock_start(); + + coins_segmentate(); + + /* Measure time */ + clock_stop("Segmentate coins"); + } + /* Find coins positions */ + { + /* Measure time */ + clock_start(); + + status = coins_positions(); + if (status) { + result_coins(status); + return status; + } + + /* Measure time */ + clock_stop("Find coins positions"); + } + /* Get coin diameters in pixels */ + { + /* Measure time */ + clock_start(); + + coins_diameters_pix(); + + /* Measure time */ + clock_stop("Coins diameters in pixels"); + } + /* Calibrate with the biggest coin; every img should have a 2 € coin */ + { + /* Measure time */ + clock_start(); + + calibrate_mm_per_pix(); + + /* Measure time */ + clock_stop("Calibrate (mm per pix)"); + } + /* Get coins diameters in mm */ + { + /* Measure time */ + clock_start(); + + coins_diameters_mm(); + + /* Measure time */ + clock_stop("Coins diameters in mm"); + } + /* Get coins values (by their sizes) */ + { + /* Measure time */ + clock_start(); + + status = coins_values(); + if (status) { + result_coins(status); + return status; + } + + /* Measure time */ + clock_stop("Coins values"); + } + /* Add total value */ + { + /* Measure time */ + clock_start(); + + coins_total_value(); + + /* Measure time */ + clock_stop("Total value"); + } + + status = COINS_OK; + result_coins(status); + return status; +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_coins (int status) +{ + /* Cleanup */ + + /* Write result into log */ + switch (status) { + case COINS_OK: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: OK"); + break; + case COINS_NOK_COINS: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK_COINS"); + break; +#if 0 + case COINS_NOK_OVERLAP: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK_OVERLAP"); + break; +#endif + case COINS_NOK_SIZE: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK_SIZE"); + break; + default: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK"); + break; + } + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + +static void coins_segmentate (void) +{ + proc_load_mem(0); + + proc_cmp(IMG_IFACE_CMP_BLUE); + proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU); + proc_distance_transform(); + proc_local_max(); + proc_dilate(6); + proc_save_mem(1); +} + +static int coins_positions (void) +{ + int status; + int i; + + proc_load_mem(1); + + proc_contours(&contours, &hierarchy); + coins_n = contours.size(); + + /* If no contour is found, error: NOK_COINS */ + if (!coins_n) { + status = COINS_NOK_COINS; + return status; + } + + /* Get position of each contour */ + for (i = 0; i < coins_n; i++) { + proc_bounding_rect(&(contours[i]), &(rectangle[i]), true); + coins[i].x = rectangle[i].x + rectangle[i].width / 2.0; + coins[i].y = rectangle[i].y + rectangle[i].height / 2.0; + } + + status = COINS_OK; + return status; +} + +static void coins_diameters_pix (void) +{ + int i; + + proc_load_mem(1); + + /* Get coins diameters in pixels */ + for (i = 0; i < coins_n; i++) { + proc_pixel_get(coins[i].x, coins[i].y, + &(coins[i].diameter_pix)); + coins[i].diameter_pix *= 2; + } +} + +static void calibrate_mm_per_pix (void) +{ + uint8_t coins_size_pix [coins_n]; + int i; + int max_pos; + int max_size; + + for (i = 0; i < coins_n; i++) { + coins_size_pix[i] = coins[i].diameter_pix; + } + + max_pos = alx_maximum_u8(coins_n, coins_size_pix); + max_size = coins_size_pix[max_pos]; + ratio_mm_per_pix = 25.75 / max_size; +} + +static void coins_diameters_mm (void) +{ + int i; + + for (i = 0; i < coins_n; i++) { + coins[i].diameter_mm = ratio_mm_per_pix * + coins[i].diameter_pix; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin[%i]: %.2lf mm", + i, + coins[i].diameter_mm); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + } +} + +static int coins_values (void) +{ + int status; + int i; + + for (i = 0; i < coins_n; i++) { + coins[i].value = coin_value(coins[i].diameter_mm); + + /* If a coin is of invalid size, error: NOK_SIZE */ + if (coins[i].value < 0) { + status = COINS_NOK_SIZE; + return status; + } + + /* Write values into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin[%i]: %.2lf EUR", + i, + coins[i].value); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + } + + status = COINS_OK; + return status; +} + +static double coin_value (double diameter_mm) +{ + double value; + + /* Get coin value by its diameter in mm */ + if (diameter_mm > 27.00) { + value = -1; + } else if (diameter_mm > 25.00) { + value = 2.00; + } else if (diameter_mm > 23.75) { + value = 0.50; + } else if (diameter_mm > 22.75) { + value = 1.00; + } else if (diameter_mm > 21.75) { + value = 0.20; + } else if (diameter_mm > 20.50) { + value = 0.05; + } else if (diameter_mm > 19.25) { + value = 0.10; + } else if (diameter_mm > 17.50) { + value = 0.02; + } else if (diameter_mm > 15.00) { + value = 0.01; + } else { + value = -1; + } + + return value; +} + +static void coins_total_value (void) +{ + int i; + + value_total = 0.00; + + for (i = 0; i < coins_n; i++) { + value_total += coins[i].value; + } + + /* Write total value into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Total value: %.2lf EUR", + value_total); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/src/proc_common.cpp b/modules/proc/src/proc_common.cpp index 86c137a..96b66f1 100644 --- a/modules/proc/src/proc_common.cpp +++ b/modules/proc/src/proc_common.cpp @@ -1,432 +1,432 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include - /* snprintf() & fflush() */ - #include - /* clock_t & clock() & CLOCKS_PER_SEC */ - #include - -/* Packages ------------------------------------------------------------------*/ - /* openCV */ - #include - /* enum zbar::zbar_symbol_type_e */ - #include - -/* 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_skeleton (void) -{ - img_iface_act(IMG_IFACE_ACT_SKELETON, 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_get (int x, int y, unsigned char *val) -{ - struct Img_Iface_Data_Pixel_Get data; - data.x = x; - data.y = y; - data.val = val; - img_iface_act(IMG_IFACE_ACT_PIXEL_GET, (void *)&data); -} - -void proc_pixel_set (int x, int y, unsigned char val) -{ - struct Img_Iface_Data_Pixel_Set data; - data.x = x; - data.y = y; - data.val = val; - img_iface_act(IMG_IFACE_ACT_PIXEL_SET, (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_border (int size) -{ - struct Img_Iface_Data_Border data; - - data.size = size; - img_iface_act(IMG_IFACE_ACT_BORDER, (void *)&data); - - proc_show_img(); -} - -void proc_rotate (double center_x, double center_y, double angle) -{ - struct Img_Iface_Data_Rotate data; - - data.center.x = center_x; - data.center.y = center_y; - data.angle = 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 ( - class std::vector >> *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 ( - class std::vector >> *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 ( - class std::vector > *contour, - class cv::Rect_ *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 ( - class std::vector > *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 ( - class std::vector > *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)", - time_diff, txt); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + #include + /* snprintf() & fflush() */ + #include + /* clock_t & clock() & CLOCKS_PER_SEC */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* openCV */ + #include + /* enum zbar::zbar_symbol_type_e */ + #include + +/* 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_skeleton (void) +{ + img_iface_act(IMG_IFACE_ACT_SKELETON, 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_get (int x, int y, unsigned char *val) +{ + struct Img_Iface_Data_Pixel_Get data; + data.x = x; + data.y = y; + data.val = val; + img_iface_act(IMG_IFACE_ACT_PIXEL_GET, (void *)&data); +} + +void proc_pixel_set (int x, int y, unsigned char val) +{ + struct Img_Iface_Data_Pixel_Set data; + data.x = x; + data.y = y; + data.val = val; + img_iface_act(IMG_IFACE_ACT_PIXEL_SET, (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_border (int size) +{ + struct Img_Iface_Data_Border data; + + data.size = size; + img_iface_act(IMG_IFACE_ACT_BORDER, (void *)&data); + + proc_show_img(); +} + +void proc_rotate (double center_x, double center_y, double angle) +{ + struct Img_Iface_Data_Rotate data; + + data.center.x = center_x; + data.center.y = center_y; + data.angle = 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 ( + class std::vector >> *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 ( + class std::vector >> *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 ( + class std::vector > *contour, + class cv::Rect_ *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 ( + class std::vector > *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 ( + class std::vector > *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)", + time_diff, txt); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/src/proc_iface.c b/modules/proc/src/proc_iface.c index efb2e52..b150bc6 100644 --- a/modules/proc/src/proc_iface.c +++ b/modules/proc/src/proc_iface.c @@ -1,227 +1,227 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* errno */ - #include - #include - /* snprintf() & fflush() */ - #include - /* clock_t & clock() & CLOCKS_PER_SEC */ - #include - -/* libalx -------------------------------------------------------------------*/ - /* alx_sscan_fname() */ - #include "alx_input.h" - -/* Project -------------------------------------------------------------------*/ - /* img_iface_load() */ - #include "img_iface.h" - /* user_iface_log */ - #include "user_iface.h" - /* saved_path */ - #include "save.h" - -/* Module --------------------------------------------------------------------*/ - #include "proc_label.h" - #include "proc_lighters.h" - #include "proc_objects.h" - #include "proc_coins.h" - #include "proc_resistor.h" - #include "proc_common.h" - - #include "proc_iface.h" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ - int proc_debug; - int proc_mode; - -/* Static --------------------------------------------------------------------*/ -static char proc_path [FILENAME_MAX]; -static char proc_fail_path [FILENAME_MAX]; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -int proc_iface_single (int action) -{ - int error; - clock_t time_0; - clock_t time_1; - double time_tot; - - /* Init timer */ - time_0 = clock(); - - /* Process */ - switch (action) { - case PROC_MODE_LABEL_SERIES: - error = proc_label(); - break; - case PROC_MODE_OBJECTS_CALIB: - error = proc_objects_calibrate(); - break; - case PROC_MODE_OBJECTS_SERIES: - error = proc_objects(); - break; - case PROC_MODE_COINS_SERIES: - error = proc_coins(); - break; - case PROC_MODE_RESISTOR_SERIES: - error = proc_resistor(); - break; - case PROC_MODE_LIGHTER_SERIES: - error = proc_lighter(); - break; - default: - error = -1; - } - - /* End timer */ - time_1 = clock(); - - /* Calculate time in seconds */ - time_tot = ((double) time_1 - time_0) / CLOCKS_PER_SEC; - - /* Write time into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Item total time: %.3lf", - time_tot); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - return error; -} - -void proc_iface_series (void) -{ - bool file_error; - int num_len; - char file_basename [FILENAME_MAX]; - char file_ext [FILENAME_MAX]; - char file_name [FILENAME_MAX]; - bool proc_error; - char save_error_as [FILENAME_MAX]; - bool wh; - /* if i starts being 0, the camera needs calibration */ - int i; - char txt_tmp [80]; - - switch (proc_mode) { - case PROC_MODE_LABEL_SERIES: - snprintf(proc_path, FILENAME_MAX, "%s", labels_path); - snprintf(proc_fail_path, FILENAME_MAX, "%s", labels_fail_path); - snprintf(file_basename, FILENAME_MAX, "b"); - num_len = 4; - snprintf(file_ext, FILENAME_MAX, ".BMP"); - i = 1; - break; - case PROC_MODE_OBJECTS_SERIES: - snprintf(proc_path, FILENAME_MAX, "%s", objects_path); - snprintf(proc_fail_path, FILENAME_MAX, "%s", objects_fail_path); - snprintf(file_basename, FILENAME_MAX, "o"); - num_len = 4; - snprintf(file_ext, FILENAME_MAX, ".jpeg"); - i = 0; - proc_mode++; - break; - case PROC_MODE_COINS_SERIES: - snprintf(proc_path, FILENAME_MAX, "%s", coins_path); - snprintf(proc_fail_path, FILENAME_MAX, "%s", coins_fail_path); - snprintf(file_basename, FILENAME_MAX, "c"); - num_len = 4; - snprintf(file_ext, FILENAME_MAX, ".jpeg"); - i = 1; - break; - case PROC_MODE_RESISTOR_SERIES: - snprintf(proc_path, FILENAME_MAX, "%s", resistors_path); - snprintf(proc_fail_path, FILENAME_MAX, "%s", resistors_fail_path); - snprintf(file_basename, FILENAME_MAX, "r"); - num_len = 4; - snprintf(file_ext, FILENAME_MAX, ".png"); - i = 1; - break; - case PROC_MODE_LIGHTER_SERIES: - snprintf(proc_path, FILENAME_MAX, "%s", lighters_path); - snprintf(proc_fail_path, FILENAME_MAX, "%s", lighters_fail_path); - snprintf(file_basename, FILENAME_MAX, "lighters"); - num_len = 4; - snprintf(file_ext, FILENAME_MAX, ".jpeg"); - i = 1; - break; - default: - return; - } - - wh = true; - for (; wh; i++) { - snprintf(file_name, FILENAME_MAX, "%s%04i%s", - file_basename, i, file_ext); - - file_error = alx_sscan_fname(proc_path, file_name, - true, file_name); - - if (file_error) { - wh = false; - } else { - errno = 0; - img_iface_load(proc_path, file_name); - - if (!errno) { - /* Process */ - proc_error = proc_iface_single(proc_mode); - - if (proc_error) { - /* Save failed image into file */ - proc_show_img(); - snprintf(save_error_as, FILENAME_MAX, - "%s%0*i_err%s", - file_basename, - num_len, i, - file_ext); - save_image_file(proc_fail_path, - save_error_as); - } - - /* Show log */ - snprintf(txt_tmp, FILENAME_MAX, "%04i", i); - user_iface_show_log(txt_tmp, "Item"); - - if (proc_debug >= PROC_DBG_STOP_ITEM) { - getchar(); - } - } else { - printf("errno:%i\n", errno); - } - } - - if (!i) { - proc_mode--; - } - } -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* errno */ + #include + #include + /* snprintf() & fflush() */ + #include + /* clock_t & clock() & CLOCKS_PER_SEC */ + #include + +/* libalx -------------------------------------------------------------------*/ + /* alx_sscan_fname() */ + #include "alx_input.h" + +/* Project -------------------------------------------------------------------*/ + /* img_iface_load() */ + #include "img_iface.h" + /* user_iface_log */ + #include "user_iface.h" + /* saved_path */ + #include "save.h" + +/* Module --------------------------------------------------------------------*/ + #include "proc_label.h" + #include "proc_lighters.h" + #include "proc_objects.h" + #include "proc_coins.h" + #include "proc_resistor.h" + #include "proc_common.h" + + #include "proc_iface.h" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ + int proc_debug; + int proc_mode; + +/* Static --------------------------------------------------------------------*/ +static char proc_path [FILENAME_MAX]; +static char proc_fail_path [FILENAME_MAX]; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +int proc_iface_single (int action) +{ + int error; + clock_t time_0; + clock_t time_1; + double time_tot; + + /* Init timer */ + time_0 = clock(); + + /* Process */ + switch (action) { + case PROC_MODE_LABEL_SERIES: + error = proc_label(); + break; + case PROC_MODE_OBJECTS_CALIB: + error = proc_objects_calibrate(); + break; + case PROC_MODE_OBJECTS_SERIES: + error = proc_objects(); + break; + case PROC_MODE_COINS_SERIES: + error = proc_coins(); + break; + case PROC_MODE_RESISTOR_SERIES: + error = proc_resistor(); + break; + case PROC_MODE_LIGHTER_SERIES: + error = proc_lighter(); + break; + default: + error = -1; + } + + /* End timer */ + time_1 = clock(); + + /* Calculate time in seconds */ + time_tot = ((double) time_1 - time_0) / CLOCKS_PER_SEC; + + /* Write time into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Item total time: %.3lf", + time_tot); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + return error; +} + +void proc_iface_series (void) +{ + bool file_error; + int num_len; + char file_basename [FILENAME_MAX]; + char file_ext [FILENAME_MAX]; + char file_name [FILENAME_MAX]; + bool proc_error; + char save_error_as [FILENAME_MAX]; + bool wh; + /* if i starts being 0, the camera needs calibration */ + int i; + char txt_tmp [80]; + + switch (proc_mode) { + case PROC_MODE_LABEL_SERIES: + snprintf(proc_path, FILENAME_MAX, "%s", labels_path); + snprintf(proc_fail_path, FILENAME_MAX, "%s", labels_fail_path); + snprintf(file_basename, FILENAME_MAX, "b"); + num_len = 4; + snprintf(file_ext, FILENAME_MAX, ".BMP"); + i = 1; + break; + case PROC_MODE_OBJECTS_SERIES: + snprintf(proc_path, FILENAME_MAX, "%s", objects_path); + snprintf(proc_fail_path, FILENAME_MAX, "%s", objects_fail_path); + snprintf(file_basename, FILENAME_MAX, "o"); + num_len = 4; + snprintf(file_ext, FILENAME_MAX, ".jpeg"); + i = 0; + proc_mode++; + break; + case PROC_MODE_COINS_SERIES: + snprintf(proc_path, FILENAME_MAX, "%s", coins_path); + snprintf(proc_fail_path, FILENAME_MAX, "%s", coins_fail_path); + snprintf(file_basename, FILENAME_MAX, "c"); + num_len = 4; + snprintf(file_ext, FILENAME_MAX, ".jpeg"); + i = 1; + break; + case PROC_MODE_RESISTOR_SERIES: + snprintf(proc_path, FILENAME_MAX, "%s", resistors_path); + snprintf(proc_fail_path, FILENAME_MAX, "%s", resistors_fail_path); + snprintf(file_basename, FILENAME_MAX, "r"); + num_len = 4; + snprintf(file_ext, FILENAME_MAX, ".png"); + i = 1; + break; + case PROC_MODE_LIGHTER_SERIES: + snprintf(proc_path, FILENAME_MAX, "%s", lighters_path); + snprintf(proc_fail_path, FILENAME_MAX, "%s", lighters_fail_path); + snprintf(file_basename, FILENAME_MAX, "lighters"); + num_len = 4; + snprintf(file_ext, FILENAME_MAX, ".jpeg"); + i = 1; + break; + default: + return; + } + + wh = true; + for (; wh; i++) { + snprintf(file_name, FILENAME_MAX, "%s%04i%s", + file_basename, i, file_ext); + + file_error = alx_sscan_fname(proc_path, file_name, + true, file_name); + + if (file_error) { + wh = false; + } else { + errno = 0; + img_iface_load(proc_path, file_name); + + if (!errno) { + /* Process */ + proc_error = proc_iface_single(proc_mode); + + if (proc_error) { + /* Save failed image into file */ + proc_show_img(); + snprintf(save_error_as, FILENAME_MAX, + "%s%0*i_err%s", + file_basename, + num_len, i, + file_ext); + save_image_file(proc_fail_path, + save_error_as); + } + + /* Show log */ + snprintf(txt_tmp, FILENAME_MAX, "%04i", i); + user_iface_show_log(txt_tmp, "Item"); + + if (proc_debug >= PROC_DBG_STOP_ITEM) { + getchar(); + } + } else { + printf("errno:%i\n", errno); + } + } + + if (!i) { + proc_mode--; + } + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/src/proc_label.cpp b/modules/proc/src/proc_label.cpp index 8615d98..57acf09 100644 --- a/modules/proc/src/proc_label.cpp +++ b/modules/proc/src/proc_label.cpp @@ -1,385 +1,385 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* snprintf() */ - #include - /* strcmp() */ - #include - -/* Packages ------------------------------------------------------------------*/ - /* openCV */ - #include - /* zbar::ZBAR_EAN13 */ - #include - -/* Project -------------------------------------------------------------------*/ - /* zb_codes */ - #include "img_iface.hpp" - /* user_iface_log */ - #include "user_iface.hpp" - -/* Module --------------------------------------------------------------------*/ - #include "proc_common.hpp" - - #include "proc_label.hpp" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ - -/* Static --------------------------------------------------------------------*/ -static class std::vector >> contours; -static class cv::Mat hierarchy; -static class cv::RotatedRect rect; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_label (int status); - -static int label_find (void); -static void label_align (void); -static int find_cerdo (void); -static int barcode_read (void); -static int barcode_chk_prod (void); -static void price_read (void); -static int price_chk (void); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -int proc_label (void) -{ - int status; - - proc_save_mem(0); - /* Find label (position and angle) */ - { - /* Measure time */ - clock_start(); - - status = label_find(); - if (status) { - result_label(status); - return status; - } - - /* Measure time */ - clock_stop("Find label"); - } - /* Align label and extract green component */ - { - /* Measure time */ - clock_start(); - - label_align(); - - /* Measure time */ - clock_stop("Align label"); - } - /* Find "Cerdo" in aligned image */ - { - /* Measure time */ - clock_start(); - - status = find_cerdo(); - if (status) { - result_label(status); - return status; - } - - /* Measure time */ - clock_stop("Find cerdo (OCR)"); - } - /* Read barcode in original image */ - { - /* Measure time */ - clock_start(); - - status = barcode_read(); - if (status) { - result_label(status); - return status; - } - - /* Measure time */ - clock_stop("Read barcode (zbar)"); - } - /* Check product code in barcode */ - { - /* Measure time */ - clock_start(); - - status = barcode_chk_prod(); - if (status) { - result_label(status); - return status; - } - - /* Measure time */ - clock_stop("Chk product code"); - } - /* Read price in aligned image (green component) */ - { - /* Measure time */ - clock_start(); - - price_read(); - - /* Measure time */ - clock_stop("Read price (OCR)"); - } - /* Check label price with barcode price */ - { - /* Measure time */ - clock_start(); - - status = price_chk(); - if (status) { - result_label(status); - return status; - } - - /* Measure time */ - clock_stop("Check price"); - } - - status = LABEL_OK; - result_label(status); - return status; -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_label (int status) -{ - /* Cleanup */ - - /* Write result into log */ - switch (status) { - case LABEL_OK: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Label: OK"); - break; - case LABEL_NOK_LABEL: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Label: NOK_LABEL"); - break; - case LABEL_NOK_CERDO: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Label: NOK_CERDO"); - break; - case LABEL_NOK_BCODE: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Label: NOK_BCODE"); - break; - case LABEL_NOK_PRODUCT: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Label: NOK_PRODUCT"); - break; - case LABEL_NOK_PRICE: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Label: NOK_PRICE"); - break; - default: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Label: NOK"); - break; - } - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - -static int label_find (void) -{ - int status; - int tmp; - - proc_load_mem(0); - - 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_not(); -#endif - proc_smooth(IMGI_SMOOTH_MEAN, 21); - proc_threshold(cv::THRESH_BINARY_INV, 2); - proc_dilate_erode(100); - proc_contours(&contours, &hierarchy); - - /* If no contour is found, error: NOK_LABEL */ - if (!contours.size()) { - status = LABEL_NOK_LABEL; - return status; - } - - 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) { - rect.angle += 90.0; - tmp = rect.size.width; - rect.size.width = rect.size.height; - rect.size.height = tmp; - } - - status = LABEL_OK; - return status; -} - -static void label_align (void) -{ - proc_load_mem(0); - - proc_rotate(rect.center.x, rect.center.y, rect.angle); - proc_cmp(IMG_IFACE_CMP_GREEN); - proc_save_mem(1); -} - -static int find_cerdo (void) -{ - int status; - int x; - int y; - int w; - int h; - bool cerdo_nok; - - proc_load_mem(1); - - x = rect.center.x - (1.05 * rect.size.width / 2); - if (x < 0) { - x = 0; - } - y = rect.center.y - (1.47 * rect.size.height / 2); - if (y < 0) { - y = 0; - } - w = rect.size.width / 2; - h = rect.size.height * 0.20; - proc_ROI(x, y, w, h); - proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); - proc_erode(1); - proc_OCR(IMG_IFACE_OCR_LANG_ENG, IMG_IFACE_OCR_CONF_NONE); - - /* Compare Label text to "Cerdo". */ - cerdo_nok = strncmp(img_ocr_text, "Cerdo", - strlen("Cerdo")); - - /* If string doesn't match, error: NOK_CERDO */ - if (cerdo_nok) { - status = LABEL_NOK_CERDO; - return status; - } - - status = LABEL_OK; - return status; -} - -static int barcode_read (void) -{ - int status; - - proc_load_mem(0); - - proc_cmp(IMG_IFACE_CMP_GREEN); - proc_zbar(zbar::ZBAR_EAN13); - - /* Check that 1 and only 1 bcode is read. */ - if (zb_codes.n != 1) { - status = LABEL_NOK_BCODE; - return status; - } - - status = LABEL_OK; - return status; -} - -static int barcode_chk_prod (void) -{ - int status; - bool prod_nok; - - prod_nok = strncmp(zb_codes.arr[0].data, "2301703", - strlen("2301703")); - if (prod_nok) { - status = LABEL_NOK_PRODUCT; - return status; - } - - status = LABEL_OK; - return status; -} - -static void price_read (void) -{ - int x; - int y; - int w; - int h; - - proc_load_mem(1); - - x = rect.center.x + (0.33 * rect.size.width / 2); - y = rect.center.y + (0.64 * rect.size.height / 2); - w = rect.size.width * 0.225; - h = rect.size.height * 0.15; - proc_ROI(x, y, w, h); - proc_smooth(IMGI_SMOOTH_MEAN, 3); - proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); - proc_dilate_erode(1); - proc_threshold(cv::THRESH_BINARY, 1); - proc_OCR(IMG_IFACE_OCR_LANG_DIGITS, IMG_IFACE_OCR_CONF_PRICE); -} - -static int price_chk (void) -{ - int status; - char price [80]; - bool price_nok; - - /* Extract price from barcode */ - if (zb_codes.arr[0].data[8] != '0') { - snprintf(price, 80, "%c%c.%c%c", - zb_codes.arr[0].data[8], - zb_codes.arr[0].data[9], - zb_codes.arr[0].data[10], - zb_codes.arr[0].data[11]); - } else { - snprintf(price, 80, "%c.%c%c", - zb_codes.arr[0].data[9], - zb_codes.arr[0].data[10], - zb_codes.arr[0].data[11]); - } - - /* Compare price from barcode and from text */ - price_nok = strncmp(img_ocr_text, price, strlen(price)); - - if (price_nok) { - status = LABEL_NOK_PRICE; - return status; - } - - status = LABEL_OK; - return status; -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* snprintf() */ + #include + /* strcmp() */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* openCV */ + #include + /* zbar::ZBAR_EAN13 */ + #include + +/* Project -------------------------------------------------------------------*/ + /* zb_codes */ + #include "img_iface.hpp" + /* user_iface_log */ + #include "user_iface.hpp" + +/* Module --------------------------------------------------------------------*/ + #include "proc_common.hpp" + + #include "proc_label.hpp" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ + +/* Static --------------------------------------------------------------------*/ +static class std::vector >> contours; +static class cv::Mat hierarchy; +static class cv::RotatedRect rect; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_label (int status); + +static int label_find (void); +static void label_align (void); +static int find_cerdo (void); +static int barcode_read (void); +static int barcode_chk_prod (void); +static void price_read (void); +static int price_chk (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +int proc_label (void) +{ + int status; + + proc_save_mem(0); + /* Find label (position and angle) */ + { + /* Measure time */ + clock_start(); + + status = label_find(); + if (status) { + result_label(status); + return status; + } + + /* Measure time */ + clock_stop("Find label"); + } + /* Align label and extract green component */ + { + /* Measure time */ + clock_start(); + + label_align(); + + /* Measure time */ + clock_stop("Align label"); + } + /* Find "Cerdo" in aligned image */ + { + /* Measure time */ + clock_start(); + + status = find_cerdo(); + if (status) { + result_label(status); + return status; + } + + /* Measure time */ + clock_stop("Find cerdo (OCR)"); + } + /* Read barcode in original image */ + { + /* Measure time */ + clock_start(); + + status = barcode_read(); + if (status) { + result_label(status); + return status; + } + + /* Measure time */ + clock_stop("Read barcode (zbar)"); + } + /* Check product code in barcode */ + { + /* Measure time */ + clock_start(); + + status = barcode_chk_prod(); + if (status) { + result_label(status); + return status; + } + + /* Measure time */ + clock_stop("Chk product code"); + } + /* Read price in aligned image (green component) */ + { + /* Measure time */ + clock_start(); + + price_read(); + + /* Measure time */ + clock_stop("Read price (OCR)"); + } + /* Check label price with barcode price */ + { + /* Measure time */ + clock_start(); + + status = price_chk(); + if (status) { + result_label(status); + return status; + } + + /* Measure time */ + clock_stop("Check price"); + } + + status = LABEL_OK; + result_label(status); + return status; +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_label (int status) +{ + /* Cleanup */ + + /* Write result into log */ + switch (status) { + case LABEL_OK: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Label: OK"); + break; + case LABEL_NOK_LABEL: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Label: NOK_LABEL"); + break; + case LABEL_NOK_CERDO: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Label: NOK_CERDO"); + break; + case LABEL_NOK_BCODE: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Label: NOK_BCODE"); + break; + case LABEL_NOK_PRODUCT: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Label: NOK_PRODUCT"); + break; + case LABEL_NOK_PRICE: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Label: NOK_PRICE"); + break; + default: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Label: NOK"); + break; + } + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + +static int label_find (void) +{ + int status; + int tmp; + + proc_load_mem(0); + + 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_not(); +#endif + proc_smooth(IMGI_SMOOTH_MEAN, 21); + proc_threshold(cv::THRESH_BINARY_INV, 2); + proc_dilate_erode(100); + proc_contours(&contours, &hierarchy); + + /* If no contour is found, error: NOK_LABEL */ + if (!contours.size()) { + status = LABEL_NOK_LABEL; + return status; + } + + 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) { + rect.angle += 90.0; + tmp = rect.size.width; + rect.size.width = rect.size.height; + rect.size.height = tmp; + } + + status = LABEL_OK; + return status; +} + +static void label_align (void) +{ + proc_load_mem(0); + + proc_rotate(rect.center.x, rect.center.y, rect.angle); + proc_cmp(IMG_IFACE_CMP_GREEN); + proc_save_mem(1); +} + +static int find_cerdo (void) +{ + int status; + int x; + int y; + int w; + int h; + bool cerdo_nok; + + proc_load_mem(1); + + x = rect.center.x - (1.05 * rect.size.width / 2); + if (x < 0) { + x = 0; + } + y = rect.center.y - (1.47 * rect.size.height / 2); + if (y < 0) { + y = 0; + } + w = rect.size.width / 2; + h = rect.size.height * 0.20; + proc_ROI(x, y, w, h); + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_erode(1); + proc_OCR(IMG_IFACE_OCR_LANG_ENG, IMG_IFACE_OCR_CONF_NONE); + + /* Compare Label text to "Cerdo". */ + cerdo_nok = strncmp(img_ocr_text, "Cerdo", + strlen("Cerdo")); + + /* If string doesn't match, error: NOK_CERDO */ + if (cerdo_nok) { + status = LABEL_NOK_CERDO; + return status; + } + + status = LABEL_OK; + return status; +} + +static int barcode_read (void) +{ + int status; + + proc_load_mem(0); + + proc_cmp(IMG_IFACE_CMP_GREEN); + proc_zbar(zbar::ZBAR_EAN13); + + /* Check that 1 and only 1 bcode is read. */ + if (zb_codes.n != 1) { + status = LABEL_NOK_BCODE; + return status; + } + + status = LABEL_OK; + return status; +} + +static int barcode_chk_prod (void) +{ + int status; + bool prod_nok; + + prod_nok = strncmp(zb_codes.arr[0].data, "2301703", + strlen("2301703")); + if (prod_nok) { + status = LABEL_NOK_PRODUCT; + return status; + } + + status = LABEL_OK; + return status; +} + +static void price_read (void) +{ + int x; + int y; + int w; + int h; + + proc_load_mem(1); + + x = rect.center.x + (0.33 * rect.size.width / 2); + y = rect.center.y + (0.64 * rect.size.height / 2); + w = rect.size.width * 0.225; + h = rect.size.height * 0.15; + proc_ROI(x, y, w, h); + proc_smooth(IMGI_SMOOTH_MEAN, 3); + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_dilate_erode(1); + proc_threshold(cv::THRESH_BINARY, 1); + proc_OCR(IMG_IFACE_OCR_LANG_DIGITS, IMG_IFACE_OCR_CONF_PRICE); +} + +static int price_chk (void) +{ + int status; + char price [80]; + bool price_nok; + + /* Extract price from barcode */ + if (zb_codes.arr[0].data[8] != '0') { + snprintf(price, 80, "%c%c.%c%c", + zb_codes.arr[0].data[8], + zb_codes.arr[0].data[9], + zb_codes.arr[0].data[10], + zb_codes.arr[0].data[11]); + } else { + snprintf(price, 80, "%c.%c%c", + zb_codes.arr[0].data[9], + zb_codes.arr[0].data[10], + zb_codes.arr[0].data[11]); + } + + /* Compare price from barcode and from text */ + price_nok = strncmp(img_ocr_text, price, strlen(price)); + + if (price_nok) { + status = LABEL_NOK_PRICE; + return status; + } + + status = LABEL_OK; + return status; +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/src/proc_lighters.cpp b/modules/proc/src/proc_lighters.cpp index 0f7c848..7b5cfdf 100644 --- a/modules/proc/src/proc_lighters.cpp +++ b/modules/proc/src/proc_lighters.cpp @@ -1,315 +1,368 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include - #include - -/* Packages ------------------------------------------------------------------*/ - /* openCV */ - #include - -/* libalx ------------------------------------------------------------------*/ - /* alx_maximum_u8() */ - #include "alx_math.hpp" - -/* Project -------------------------------------------------------------------*/ - /* constants */ - #include "img_iface.hpp" - /* user_iface_log */ - #include "user_iface.hpp" - -/* Module --------------------------------------------------------------------*/ - #include "proc_common.hpp" - - #include "proc_lighters.hpp" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ -struct Point { - uint16_t x; - uint16_t y; -}; - -struct Size { - uint16_t h; - uint16_t w; -}; - -struct Lighter_Properties { - /* position */ - struct Point pos; - struct Size size; - double angle; - - bool fork; - bool valve; - bool hood; - bool wheel; -}; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ - -/* Static --------------------------------------------------------------------*/ -static class std::vector >> contours_all; -static class std::vector >> contours_one; -static class cv::Mat hierarchy; -static class cv::RotatedRect rect_rot [CONTOURS_MAX]; -static class cv::Rect_ rect; -static struct Lighter_Properties lighter [CONTOURS_MAX]; -static unsigned lighters_n; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_lighter (int status); - -static void lighters_bgr2gray (void); -static void lighters_segment_full (void); -static int lighters_find (void); -static void lighter_segment_body (int i); -static void lighter_crop_head (int i); -static void lighter_segment_head (int i); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -int proc_lighter (void) -{ - int status; - int i; - - proc_save_mem(0); - /* Segment lighters */ - { - /* Measure time */ - clock_start(); - - lighters_bgr2gray(); - lighters_segment_full(); - lighters_find(); - - /* Measure time */ - clock_stop("Segment lighten"); - } - for (i = 0; (unsigned)i < lighters_n; i++) { - /* Segment lighter */ - { - /* Measure time */ - clock_start(); - - lighter_segment_body(i); - - /* Measure time */ - clock_stop("Segment lighten"); - } - /* Segment interest zone */ - { - /* Measure time */ - clock_start(); - - lighter_crop_head(i); - lighter_segment_head(i); - - /* Measure time */ - clock_stop("Segment interest zone"); - } - } - - status = LIGHTER_OK; - result_lighter(status); - return status; -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_lighter (int status) -{ - /* Cleanup */ - - /* Write result into log */ - switch (status) { - case LIGHTER_OK: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: OK"); - break; - case LIGHTER_NOK_LIGHTER: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK_LIGHTER"); - break; - - case LIGHTER_NOK_SIZE: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK_SIZE"); - break; - default: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK"); - break; - } - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - -/* process -------------------------------------------------------------------*/ -static void lighters_bgr2gray (void) -{ - proc_load_mem(0); - - proc_cvt_color(cv::COLOR_BGR2GRAY); - proc_not(); - proc_border(100); - proc_save_mem(1); -} - -static void lighters_segment_full (void) -{ - proc_load_mem(1); - - proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); - proc_erode_dilate(1); - proc_dilate_erode(1); - proc_save_mem(2); -} - -static int lighters_find (void) -{ - int status; - int i; - int tmp; - - proc_load_mem(2); - - proc_contours(&contours_all, &hierarchy); - lighters_n = contours_all.size(); - - /* If no contour is found, error: NOK_RESISTOR */ - if (!lighters_n) { - status = LIGHTER_NOK_LIGHTER; - return status; - } - - for (i = 0; (unsigned)i < lighters_n; i++) { - proc_min_area_rect(&(contours_all[i]), &rect_rot[i], true); - - /* If width > height, it is taking into acount the incorrect side */ - if (rect_rot[i].size.width > rect_rot[i].size.height) { - rect_rot[i].angle += 90.0; - tmp = rect_rot[i].size.width; - rect_rot[i].size.width = rect_rot[i].size.height; - rect_rot[i].size.height = tmp; - } - - lighter[i].pos.x = rect_rot[i].center.x; - lighter[i].pos.y = rect_rot[i].center.y; - lighter[i].angle = rect_rot[i].angle; - lighter[i].size.h = rect_rot[i].size.height; - lighter[i].size.w = rect_rot[i].size.width; - } - - status = LIGHTER_OK; - return status; -} - -static void lighter_segment_body (int i) -{ - int x; - int y; - int w; - int h; - - proc_load_mem(1); - - proc_rotate(lighter[i].pos.x, lighter[i].pos.y, lighter[i].angle); - w = lighter[i].size.w * 1.25; - h = lighter[i].size.h * 1.25; - x = lighter[i].pos.x - (w / 2.0); - y = lighter[i].pos.y - (h / 2.0); - proc_ROI(x, y, w, h); - proc_threshold(cv::THRESH_BINARY, 255 - 165); - - proc_erode_dilate(1); - proc_dilate_erode(1); - proc_erode_dilate(lighter[i].size.w * 0.43); - proc_save_mem(3); - - proc_contours(&contours_one, &hierarchy); - proc_bounding_rect(&(contours_one[0]), &rect, true); -} - -static void lighter_crop_head (int i) -{ - int x; - int y; - int w; - int h; - - proc_load_mem(3); - proc_not(); - proc_erode(1); - proc_save_ref(); - - proc_load_mem(1); - proc_rotate(lighter[i].pos.x, lighter[i].pos.y, lighter[i].angle); - w = lighter[i].size.w * 1.25; - h = lighter[i].size.h * 1.25; - x = lighter[i].pos.x - (w / 2.0); - y = lighter[i].pos.y - (h / 2.0); - proc_ROI(x, y, w, h); - proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); - proc_and_2ref(); -// - w = rect.width * 1.15; - h = rect.width * 0.65; - x = rect.x - rect.width * 0.075; - y = rect.y - rect.width * 0.65; - proc_ROI(x, y, w, h); - rect.x = x; - rect.y = y; - rect.width = w; - rect.height = h; - proc_save_mem(8); - -proc_apply(); -proc_save_file(); -} - -static void lighter_segment_head (int i) -{ - proc_load_mem(8); -/* - proc_smooth(IMGI_SMOOTH_MEDIAN, 5); - proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); - proc_dilate_erode(5); - proc_erode_dilate(rect[0].height * 0.25); - - proc_contours(&contours, &hierarchy); - proc_bounding_rect(&(contours[0]), &(rect[0]), true); -*/ - proc_save_mem(9); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + #include + #include + +/* Packages ------------------------------------------------------------------*/ + /* openCV */ + #include + +/* libalx ------------------------------------------------------------------*/ + /* alx_maximum_u8() */ + #include "alx_math.hpp" + +/* Project -------------------------------------------------------------------*/ + /* constants */ + #include "img_iface.hpp" + /* user_iface_log */ + #include "user_iface.hpp" + +/* Module --------------------------------------------------------------------*/ + #include "proc_common.hpp" + + #include "proc_lighters.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Lighter_Hood { + HOOD_OK, + HOOD_NOT_PRESENT, + HOOD_NOT_OK +}; + + +/****************************************************************************** + ******* structs ************************************************************** + ******************************************************************************/ +struct Point { + uint16_t x; + uint16_t y; +}; + +struct Size { + uint16_t h; + uint16_t w; +}; + +struct Lighter_Properties { + /* position */ + struct Point pos; + struct Size size; + double angle; + + bool fork; + bool valve; + int hood; + bool wheel; +}; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ + +/* Static --------------------------------------------------------------------*/ +static class std::vector >> contours_all; +static class std::vector >> contours_one; +static class cv::Mat hierarchy; +static class cv::RotatedRect rect_rot [CONTOURS_MAX]; +static class cv::Rect_ rect; +static struct Lighter_Properties lighter [CONTOURS_MAX]; +static unsigned lighters_n; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_lighter (int status); + +static void lighters_bgr2gray (void); +static void lighters_segment_full (void); +static int lighters_find (void); +static void lighter_segment_body (int i); +static void lighter_crop_head (int i); +static void lighter_chk_wheel (int i); +static void lighter_chk_hood (int i); +static void lighter_segment_head (int i); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +int proc_lighter (void) +{ + int status; + int i; + + proc_save_mem(0); + /* Segment lighters */ + { + /* Measure time */ + clock_start(); + + lighters_bgr2gray(); + lighters_segment_full(); + lighters_find(); + + /* Measure time */ + clock_stop("Segment lighten"); + } + for (i = 0; (unsigned)i < lighters_n; i++) { + /* Segment lighter */ + { + /* Measure time */ + clock_start(); + + lighter_segment_body(i); + + /* Measure time */ + clock_stop("Segment lighten"); + } + /* Segment interest zone */ + { + /* Measure time */ + clock_start(); + + lighter_crop_head(i); + lighter_chk_wheel(i); + lighter_chk_hood(i); + (void)lighter_segment_head; + + /* Measure time */ + clock_stop("Segment interest zone"); + } + } + + status = LIGHTER_OK; + result_lighter(status); + return status; +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_lighter (int status) +{ + + /* Write result into log */ + switch (status) { + case LIGHTER_OK: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: OK"); + break; + case LIGHTER_NOK_LIGHTER: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK_LIGHTER"); + break; + + case LIGHTER_NOK_SIZE: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK_SIZE"); + break; + default: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK"); + break; + } + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + +/* process -------------------------------------------------------------------*/ +static void lighters_bgr2gray (void) +{ + + proc_load_mem(0); + + proc_cvt_color(cv::COLOR_BGR2GRAY); + proc_not(); + proc_border(100); + proc_save_mem(1); +} + +static void lighters_segment_full (void) +{ + + proc_load_mem(1); + + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_erode_dilate(1); + proc_dilate_erode(1); + proc_save_mem(2); +} + +static int lighters_find (void) +{ + int status; + int i; + int tmp; + + proc_load_mem(2); + + proc_contours(&contours_all, &hierarchy); + lighters_n = contours_all.size(); + + /* If no contour is found, error: NOK_RESISTOR */ + if (!lighters_n) { + status = LIGHTER_NOK_LIGHTER; + return status; + } + + for (i = 0; (unsigned)i < lighters_n; i++) { + proc_min_area_rect(&(contours_all[i]), &rect_rot[i], true); + + /* If width > height, it is taking into acount the incorrect side */ + if (rect_rot[i].size.width > rect_rot[i].size.height) { + rect_rot[i].angle += 90.0; + tmp = rect_rot[i].size.width; + rect_rot[i].size.width = rect_rot[i].size.height; + rect_rot[i].size.height = tmp; + } + + lighter[i].pos.x = rect_rot[i].center.x; + lighter[i].pos.y = rect_rot[i].center.y; + lighter[i].angle = rect_rot[i].angle; + lighter[i].size.h = rect_rot[i].size.height; + lighter[i].size.w = rect_rot[i].size.width; + } + + status = LIGHTER_OK; + return status; +} + +static void lighter_segment_body (int i) +{ + int x; + int y; + int w; + int h; + + proc_load_mem(1); + + proc_rotate(lighter[i].pos.x, lighter[i].pos.y, lighter[i].angle); + w = lighter[i].size.w * 1.25; + h = lighter[i].size.h * 1.25; + x = lighter[i].pos.x - (w / 2.0); + y = lighter[i].pos.y - (h / 2.0); + proc_ROI(x, y, w, h); + proc_threshold(cv::THRESH_BINARY, 255 - 165); + + proc_erode_dilate(1); + proc_dilate_erode(1); + proc_erode_dilate(lighter[i].size.w * 0.43); + proc_save_mem(3); + + proc_contours(&contours_one, &hierarchy); + proc_bounding_rect(&(contours_one[0]), &rect, true); +} + +static void lighter_crop_head (int i) +{ + int x; + int y; + int w; + int h; + + proc_load_mem(3); + proc_not(); + proc_erode(1); + proc_save_ref(); + + proc_load_mem(1); + proc_rotate(lighter[i].pos.x, lighter[i].pos.y, lighter[i].angle); + w = lighter[i].size.w * 1.25; + h = lighter[i].size.h * 1.25; + x = lighter[i].pos.x - (w / 2.0); + y = lighter[i].pos.y - (h / 2.0); + proc_ROI(x, y, w, h); + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_and_2ref(); +// + w = rect.width * 1.15; + h = rect.width * 0.65; + x = rect.x - rect.width * 0.075; + y = rect.y - rect.width * 0.65; + proc_ROI(x, y, w, h); + rect.x = x; + rect.y = y; + rect.width = w; + rect.height = h; + lighter[i].size.w = w; + lighter[i].size.h = h; + proc_save_mem(4); +} + +static void lighter_chk_hood (int i) +{ + uint8_t val1; + uint8_t val2; + proc_load_mem(4); + + proc_pixel_get(lighter[i].size.w * 0.2, lighter[i].size.h * 0.3, &val1); + proc_pixel_set(lighter[i].size.w * 0.2, lighter[i].size.h * 0.3, 0); + if (val1) { + proc_pixel_get(lighter[i].size.w * 0.2, lighter[i].size.h * 0.8, + &val2); + proc_pixel_set(lighter[i].size.w * 0.2, lighter[i].size.h * 0.8, + 0); + if (val2) { + lighter[i].hood = HOOD_OK; + } else { + lighter[i].hood = HOOD_NOT_OK; + } + } else { + lighter[i].hood = HOOD_NOT_PRESENT; + } + +proc_apply(); +proc_save_file(); + proc_save_mem(7); +} + +static void lighter_chk_wheel (int i) +{ + uint8_t val; + + proc_load_mem(4); + + proc_pixel_get(lighter[i].size.w * 0.58, lighter[i].size.h * 0.19, &val); + proc_pixel_set(lighter[i].size.w * 0.58, lighter[i].size.h * 0.19, 0); + lighter[i].wheel = (bool)val; + proc_save_mem(6); +} + +static void lighter_segment_head (int i) +{ + proc_load_mem(8); +/* + proc_smooth(IMGI_SMOOTH_MEDIAN, 5); + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_dilate_erode(5); + proc_erode_dilate(rect[0].height * 0.25); + + proc_contours(&contours, &hierarchy); + proc_bounding_rect(&(contours[0]), &(rect[0]), true); +*/ + proc_save_mem(9); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/src/proc_objects.cpp b/modules/proc/src/proc_objects.cpp index 5c30a52..026cb25 100644 --- a/modules/proc/src/proc_objects.cpp +++ b/modules/proc/src/proc_objects.cpp @@ -1,697 +1,697 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* snprintf() */ - #include - -/* Packages ------------------------------------------------------------------*/ - /* openCV */ - #include - -/* libalx ------------------------------------------------------------------*/ - /* alx_maximum_u8() */ - #include "alx_math.hpp" - -/* Project -------------------------------------------------------------------*/ - /* constants */ - #include "img_iface.hpp" - /* user_iface_log */ - #include "user_iface.hpp" - -/* Module --------------------------------------------------------------------*/ - #include "proc_common.hpp" - - #include "proc_objects.hpp" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define OBJECTS_MAX (1024) - # define PATTERN_SQUARE_LEN_MM (10.0) - - # define PATTERN_DILATE (2) - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ -struct Point { - uint16_t x_pix; - uint16_t y_pix; - - double x_mm; - double y_mm; -}; - -struct Pattern_Square { - struct Point pos; - - uint8_t len; -}; - -struct Pattern_Properties { - /* center */ - struct Point center; - struct Point origin; - - /* Angle */ - double angle; - - /* Size */ - uint16_t height; - uint16_t width; - - /* Squares (distance calibration) */ - struct Pattern_Square square [OBJECTS_MAX]; -}; - -struct Objects_Properties { - /* position */ - struct Point pos; - - /* Angle */ - double angle; - - /* Area */ - double area_pix2; - double area_mm2; - - /* Perimeter */ - double perimeter_pix; - double perimeter_mm; - - /* type */ - double ratio_p2_a; - double area_rect; - double ratio_a_arect; - double perimeter_rect; - double ratio_p_prect; -}; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ - -/* Static --------------------------------------------------------------------*/ -static class std::vector >> contours; -static class cv::Mat hierarchy; -static class cv::RotatedRect rect_rot [OBJECTS_MAX]; -static class cv::Rect_ rect [OBJECTS_MAX]; -static struct Pattern_Properties pattern; -static int squares_n; -static double ratio_mm_pix; -static int objects_n; -static struct Objects_Properties objects [OBJECTS_MAX]; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_objects (int status); - -static void pattern_bgr2gray (void); -static int pattern_find (void); -static void pattern_rotation_get (void); -static void pattern_rotation_fix (void); -static void pattern_dimensions_get (void); -static void pattern_dimensions_fix (void); -static void pattern_squares_find (void); -static void pattern_squares_pos_get (void); -static void pattern_squares_len_get (void); -static void pattern_calib_mm_pix (void); - -static void objects_bgr2gray (void); -static void objects_rotation_fix (void); -static void objects_dimensions_fix (void); -static void objects_segment (void); -static int objects_contours (void); -static void objects_position_pix (void); -static void objects_size_pix (void); -static void objects_shape (void); -static void objects_position_mm (void); -static void objects_size_mm (void); -static void objects_log (void); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -int proc_objects_calibrate (void) -{ - int status; - - proc_save_mem(0); - /* Calibrate angle with the whole pattern */ - { - /* Measure time */ - clock_start(); - - pattern_bgr2gray(); - status = pattern_find(); - if (status) { - result_objects(status); - return status; - } - pattern_rotation_get(); - pattern_rotation_fix(); - - /* Measure time */ - clock_stop("Calibrate: rotation"); - } - /* Segmentate pattern squares */ - { - /* Measure time */ - clock_start(); - - pattern_dimensions_get(); - pattern_dimensions_fix(); - - /* Measure time */ - clock_stop("Calibrate: dimensions"); - } - /* Find squares */ - { - /* Measure time */ - clock_start(); - - pattern_squares_find(); - pattern_squares_pos_get(); - pattern_squares_len_get(); - pattern_calib_mm_pix(); - - /* Measure time */ - clock_stop("Calibrate (mm per pix)"); - } - - status = OBJECTS_OK; - result_objects(status); - return status; -} - -int proc_objects (void) -{ - int status; - - proc_save_mem(0); - /* Align image */ - { - /* Measure time */ - clock_start(); - - objects_bgr2gray(); - objects_rotation_fix(); - objects_dimensions_fix(); - - /* Measure time */ - clock_stop("Align image to pattern"); - } - /* Segment objects */ - { - /* Measure time */ - clock_start(); - - objects_segment(); - - /* Measure time */ - clock_stop("Segment objects"); - } - /* Find objects positions */ - { - /* Measure time */ - clock_start(); - - status = objects_contours(); - if (status) { - result_objects(status); - return status; - } - - /* Measure time */ - clock_stop("Find objects"); - } - /* Get objects properties in pixels */ - { - /* Measure time */ - clock_start(); - - objects_position_pix(); - objects_position_mm(); - - /* Measure time */ - clock_stop("Objects positions"); - } - /* Get objects properties in mm */ - { - /* Measure time */ - clock_start(); - - objects_size_pix(); - objects_size_mm(); - - /* Measure time */ - clock_stop("Objects sizes"); - } - /* Get objects properties in mm */ - { - /* Measure time */ - clock_start(); - - objects_shape(); - - /* Measure time */ - clock_stop("Objects shapes"); - } - /* Print properties of objects into log */ - { - /* Measure time */ - clock_start(); - - objects_log(); - - /* Measure time */ - clock_stop("Objects properties (log)"); - } - - status = OBJECTS_OK; - result_objects(status); - return status; -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_objects (int status) -{ - /* Write result into log */ - switch (status) { - case OBJECTS_OK: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: OK"); - break; - case OBJECTS_NOK_OBJECTS: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK_OBJECTS"); - break; - - case OBJECTS_NOK_SIZE: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK_SIZE"); - break; - default: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK"); - break; - } - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - -/* calibration ---------------------------------------------------------------*/ -static void pattern_bgr2gray (void) -{ - proc_load_mem(0); - - proc_cvt_color(cv::COLOR_BGR2GRAY); - proc_save_mem(1); -} - -static int pattern_find (void) -{ - int status; - - proc_load_mem(1); - - proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU); - proc_erode_dilate(16); - proc_dilate(2); - proc_contours(&contours, &hierarchy); - - /* If no contour is found, error: NOK_PATTERN */ - if (contours.size() != 1) { - status = OBJECTS_NOK_PATTERN; - return status; - } - - status = OBJECTS_OK; - return status; -} - -static void pattern_rotation_get (void) -{ - proc_min_area_rect(&(contours[0]), &(rect_rot[0]), true); - - /* If angle is < -45º, it is taking into account the incorrect side */ - if (rect_rot[0].angle < -45.0) { - rect_rot[0].angle += 90.0; - } - pattern.angle = rect_rot[0].angle; - pattern.center.x_pix = rect_rot[0].center.x; - pattern.center.y_pix = rect_rot[0].center.y; - - /* Write pattern properties into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "pattern angle = %lf DEG", - -pattern.angle); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "pattern center (x) = %i pix", - pattern.center.x_pix); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "pattern center (y) = %i pix", - pattern.center.y_pix); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - -static void pattern_rotation_fix (void) -{ - proc_load_mem(1); - - /* invert image before rotation to avoid black bands */ - proc_not(); - proc_rotate(pattern.center.x_pix, pattern.center.y_pix, pattern.angle); - proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); - proc_save_mem(2); -} - -static void pattern_dimensions_get (void) -{ - proc_load_mem(2); - - proc_erode_dilate(16); - proc_dilate(PATTERN_DILATE); - proc_contours(&contours, &hierarchy); - proc_bounding_rect(&(contours[0]), &(rect[0]), true); -} - -static void pattern_dimensions_fix (void) -{ - /* Need to correct also pattern dilatation (pattern_dimensions_get()) */ - pattern.origin.x_pix = rect[0].x; - pattern.origin.y_pix = rect[0].y; - pattern.width = rect[0].width; - pattern.height = rect[0].height; - - proc_load_mem(2); - - proc_ROI(pattern.origin.x_pix, pattern.origin.y_pix, - pattern.width, pattern.height); - proc_save_mem(3); -} - -static void pattern_squares_find (void) -{ - proc_load_mem(3); - - proc_distance_transform(); - proc_local_max(); - proc_dilate(6); - proc_save_mem(4); - - proc_contours(&contours, &hierarchy); - squares_n = contours.size(); -} - -static void pattern_squares_pos_get (void) -{ - int i; - - /* Get position of each contour */ - for (i = 0; i < squares_n; i++) { - proc_bounding_rect(&(contours[i]), &(rect[i]), true); - - pattern.square[i].pos.x_pix = rect[i].x + rect[i].width/2.0; - pattern.square[i].pos.y_pix = rect[i].y + rect[i].height/2.0; - } -} - -static void pattern_squares_len_get (void) -{ - int i; - - proc_load_mem(4); - - /* Get pattern square side lenght in pixels */ - for (i = 0; i < squares_n; i++) { - proc_pixel_get(pattern.square[i].pos.x_pix, - pattern.square[i].pos.y_pix, - &(pattern.square[i].len)); - pattern.square[i].len *= 2; - } -} - -static void pattern_calib_mm_pix (void) -{ - int i; - uint8_t pattern_len [OBJECTS_MAX]; - uint8_t median_size; - - for (i = 0; i < squares_n; i++) { - pattern_len[i] = pattern.square[i].len; - } - - median_size = alx_median_u8(squares_n, pattern_len); - ratio_mm_pix = PATTERN_SQUARE_LEN_MM / median_size; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "mm/pix = %lf", - ratio_mm_pix); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - -/* process -------------------------------------------------------------------*/ -static void objects_bgr2gray (void) -{ - proc_load_mem(0); - - proc_cvt_color(cv::COLOR_BGR2GRAY); - proc_save_mem(1); -} - -static void objects_rotation_fix (void) -{ - proc_load_mem(1); - - /* invert image before rotation to avoid black bands */ - proc_not(); - proc_rotate(pattern.center.x_pix, pattern.center.y_pix, pattern.angle); - proc_save_mem(2); -} - -static void objects_dimensions_fix (void) -{ - /* Need to correct also pattern dilatation (pattern_dimensions_get()) */ - proc_load_mem(2); - - proc_ROI(pattern.origin.x_pix, pattern.origin.y_pix, - pattern.width, pattern.height); - proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); - proc_save_mem(3); -} - -static void objects_segment (void) -{ - proc_load_mem(3); - - proc_dilate_erode(3); - proc_erode_dilate(3); - proc_save_mem(4); - - proc_distance_transform(); - proc_threshold(cv::THRESH_BINARY_INV, 30); - proc_distance_transform(); - proc_skeleton(); - proc_threshold(cv::THRESH_BINARY_INV, 10); - proc_save_ref(); - proc_save_mem(5); - - proc_load_mem(3); - proc_and_2ref(); - proc_distance_transform(); - proc_threshold(cv::THRESH_BINARY, 10); - proc_save_mem(6); -} - -static int objects_contours (void) -{ - int status; - - proc_load_mem(6); - - proc_contours(&contours, &hierarchy); - objects_n = contours.size(); - - /* If no contour is found, error: NOK_OBJECTS */ - if (!objects_n) { - status = OBJECTS_NOK_OBJECTS; - return status; - } - - status = OBJECTS_OK; - return status; -} - -static void objects_position_pix (void) -{ - int i; - - /* Get position of each contour */ - for (i = 0; i < objects_n; i++) { - proc_fit_ellipse(&(contours[i]), &(rect_rot[i]), true); - - objects[i].pos.x_pix = rect_rot[i].center.x; - objects[i].pos.y_pix = rect_rot[i].center.y; - - objects[i].angle = -rect_rot[i].angle + 90.0; - if (objects[i].angle < 0) { - objects[i].angle += 180.0; - } - } -} - -static void objects_position_mm (void) -{ - int i; - - /* Get position of each contour */ - for (i = 0; i < objects_n; i++) { - objects[i].pos.x_mm = ratio_mm_pix * objects[i].pos.x_pix; - objects[i].pos.y_mm = ratio_mm_pix * objects[i].pos.y_pix; - } -} - -static void objects_size_pix (void) -{ - double area [OBJECTS_MAX]; - double perimeter [OBJECTS_MAX]; - int i; - - /* Get size of each contour */ - proc_contours_size(&contours, area, perimeter); - for (i = 0; i < objects_n; i++) { - objects[i].area_pix2 = area[i]; - objects[i].perimeter_pix = perimeter[i]; - } -} - -static void objects_size_mm (void) -{ - int i; - - /* Get position of each contour */ - for (i = 0; i < objects_n; i++) { - objects[i].area_mm2 = pow(ratio_mm_pix, 2) * - objects[i].area_pix2; - objects[i].perimeter_mm = ratio_mm_pix * - objects[i].perimeter_pix; - } -} - -static void objects_shape (void) -{ - int i; - - /* Get shape of each contour */ - for (i = 0; i < objects_n; i++) { - proc_min_area_rect(&(contours[i]), &(rect_rot[i]), true); - - objects[i].ratio_p2_a = pow(objects[i].perimeter_pix, 2) / - objects[i].area_pix2; - - objects[i].area_rect = rect_rot[i].size.width * - rect_rot[i].size.height; - objects[i].perimeter_rect = 2.0 * - (rect_rot[i].size.width + - rect_rot[i].size.height); - - objects[i].ratio_p_prect = objects[i].perimeter_pix / - objects[i].perimeter_rect; - objects[i].ratio_a_arect = objects[i].area_pix2 / - objects[i].area_rect; - } -} - -static void objects_log (void) -{ - int i; - - /* Get coins diameters in mm */ - for (i = 0; i < objects_n; i++) { - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Object[%i]:", - i); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " pos: (%.1lf, %.1lf) mm", - objects[i].pos.x_mm, - objects[i].pos.y_mm); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " ang = %.1lf DEG", - objects[i].angle); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " A = %.1lf mm2", - objects[i].area_mm2); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " P = %.1lf mm", - objects[i].perimeter_mm); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " p2/A = %.2lf", - objects[i].ratio_p2_a); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " p/p_r = %.2lf", - objects[i].ratio_p_prect); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " A/A_r = %.2lf", - objects[i].ratio_a_arect); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* snprintf() */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* openCV */ + #include + +/* libalx ------------------------------------------------------------------*/ + /* alx_maximum_u8() */ + #include "alx_math.hpp" + +/* Project -------------------------------------------------------------------*/ + /* constants */ + #include "img_iface.hpp" + /* user_iface_log */ + #include "user_iface.hpp" + +/* Module --------------------------------------------------------------------*/ + #include "proc_common.hpp" + + #include "proc_objects.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define OBJECTS_MAX (1024) + # define PATTERN_SQUARE_LEN_MM (10.0) + + # define PATTERN_DILATE (2) + + +/****************************************************************************** + ******* structs ************************************************************** + ******************************************************************************/ +struct Point { + uint16_t x_pix; + uint16_t y_pix; + + double x_mm; + double y_mm; +}; + +struct Pattern_Square { + struct Point pos; + + uint8_t len; +}; + +struct Pattern_Properties { + /* center */ + struct Point center; + struct Point origin; + + /* Angle */ + double angle; + + /* Size */ + uint16_t height; + uint16_t width; + + /* Squares (distance calibration) */ + struct Pattern_Square square [OBJECTS_MAX]; +}; + +struct Objects_Properties { + /* position */ + struct Point pos; + + /* Angle */ + double angle; + + /* Area */ + double area_pix2; + double area_mm2; + + /* Perimeter */ + double perimeter_pix; + double perimeter_mm; + + /* type */ + double ratio_p2_a; + double area_rect; + double ratio_a_arect; + double perimeter_rect; + double ratio_p_prect; +}; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ + +/* Static --------------------------------------------------------------------*/ +static class std::vector >> contours; +static class cv::Mat hierarchy; +static class cv::RotatedRect rect_rot [OBJECTS_MAX]; +static class cv::Rect_ rect [OBJECTS_MAX]; +static struct Pattern_Properties pattern; +static int squares_n; +static double ratio_mm_pix; +static int objects_n; +static struct Objects_Properties objects [OBJECTS_MAX]; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_objects (int status); + +static void pattern_bgr2gray (void); +static int pattern_find (void); +static void pattern_rotation_get (void); +static void pattern_rotation_fix (void); +static void pattern_dimensions_get (void); +static void pattern_dimensions_fix (void); +static void pattern_squares_find (void); +static void pattern_squares_pos_get (void); +static void pattern_squares_len_get (void); +static void pattern_calib_mm_pix (void); + +static void objects_bgr2gray (void); +static void objects_rotation_fix (void); +static void objects_dimensions_fix (void); +static void objects_segment (void); +static int objects_contours (void); +static void objects_position_pix (void); +static void objects_size_pix (void); +static void objects_shape (void); +static void objects_position_mm (void); +static void objects_size_mm (void); +static void objects_log (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +int proc_objects_calibrate (void) +{ + int status; + + proc_save_mem(0); + /* Calibrate angle with the whole pattern */ + { + /* Measure time */ + clock_start(); + + pattern_bgr2gray(); + status = pattern_find(); + if (status) { + result_objects(status); + return status; + } + pattern_rotation_get(); + pattern_rotation_fix(); + + /* Measure time */ + clock_stop("Calibrate: rotation"); + } + /* Segmentate pattern squares */ + { + /* Measure time */ + clock_start(); + + pattern_dimensions_get(); + pattern_dimensions_fix(); + + /* Measure time */ + clock_stop("Calibrate: dimensions"); + } + /* Find squares */ + { + /* Measure time */ + clock_start(); + + pattern_squares_find(); + pattern_squares_pos_get(); + pattern_squares_len_get(); + pattern_calib_mm_pix(); + + /* Measure time */ + clock_stop("Calibrate (mm per pix)"); + } + + status = OBJECTS_OK; + result_objects(status); + return status; +} + +int proc_objects (void) +{ + int status; + + proc_save_mem(0); + /* Align image */ + { + /* Measure time */ + clock_start(); + + objects_bgr2gray(); + objects_rotation_fix(); + objects_dimensions_fix(); + + /* Measure time */ + clock_stop("Align image to pattern"); + } + /* Segment objects */ + { + /* Measure time */ + clock_start(); + + objects_segment(); + + /* Measure time */ + clock_stop("Segment objects"); + } + /* Find objects positions */ + { + /* Measure time */ + clock_start(); + + status = objects_contours(); + if (status) { + result_objects(status); + return status; + } + + /* Measure time */ + clock_stop("Find objects"); + } + /* Get objects properties in pixels */ + { + /* Measure time */ + clock_start(); + + objects_position_pix(); + objects_position_mm(); + + /* Measure time */ + clock_stop("Objects positions"); + } + /* Get objects properties in mm */ + { + /* Measure time */ + clock_start(); + + objects_size_pix(); + objects_size_mm(); + + /* Measure time */ + clock_stop("Objects sizes"); + } + /* Get objects properties in mm */ + { + /* Measure time */ + clock_start(); + + objects_shape(); + + /* Measure time */ + clock_stop("Objects shapes"); + } + /* Print properties of objects into log */ + { + /* Measure time */ + clock_start(); + + objects_log(); + + /* Measure time */ + clock_stop("Objects properties (log)"); + } + + status = OBJECTS_OK; + result_objects(status); + return status; +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_objects (int status) +{ + /* Write result into log */ + switch (status) { + case OBJECTS_OK: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: OK"); + break; + case OBJECTS_NOK_OBJECTS: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK_OBJECTS"); + break; + + case OBJECTS_NOK_SIZE: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK_SIZE"); + break; + default: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK"); + break; + } + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + +/* calibration ---------------------------------------------------------------*/ +static void pattern_bgr2gray (void) +{ + proc_load_mem(0); + + proc_cvt_color(cv::COLOR_BGR2GRAY); + proc_save_mem(1); +} + +static int pattern_find (void) +{ + int status; + + proc_load_mem(1); + + proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU); + proc_erode_dilate(16); + proc_dilate(2); + proc_contours(&contours, &hierarchy); + + /* If no contour is found, error: NOK_PATTERN */ + if (contours.size() != 1) { + status = OBJECTS_NOK_PATTERN; + return status; + } + + status = OBJECTS_OK; + return status; +} + +static void pattern_rotation_get (void) +{ + proc_min_area_rect(&(contours[0]), &(rect_rot[0]), true); + + /* If angle is < -45º, it is taking into account the incorrect side */ + if (rect_rot[0].angle < -45.0) { + rect_rot[0].angle += 90.0; + } + pattern.angle = rect_rot[0].angle; + pattern.center.x_pix = rect_rot[0].center.x; + pattern.center.y_pix = rect_rot[0].center.y; + + /* Write pattern properties into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "pattern angle = %lf DEG", + -pattern.angle); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "pattern center (x) = %i pix", + pattern.center.x_pix); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "pattern center (y) = %i pix", + pattern.center.y_pix); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + +static void pattern_rotation_fix (void) +{ + proc_load_mem(1); + + /* invert image before rotation to avoid black bands */ + proc_not(); + proc_rotate(pattern.center.x_pix, pattern.center.y_pix, pattern.angle); + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_save_mem(2); +} + +static void pattern_dimensions_get (void) +{ + proc_load_mem(2); + + proc_erode_dilate(16); + proc_dilate(PATTERN_DILATE); + proc_contours(&contours, &hierarchy); + proc_bounding_rect(&(contours[0]), &(rect[0]), true); +} + +static void pattern_dimensions_fix (void) +{ + /* Need to correct also pattern dilatation (pattern_dimensions_get()) */ + pattern.origin.x_pix = rect[0].x; + pattern.origin.y_pix = rect[0].y; + pattern.width = rect[0].width; + pattern.height = rect[0].height; + + proc_load_mem(2); + + proc_ROI(pattern.origin.x_pix, pattern.origin.y_pix, + pattern.width, pattern.height); + proc_save_mem(3); +} + +static void pattern_squares_find (void) +{ + proc_load_mem(3); + + proc_distance_transform(); + proc_local_max(); + proc_dilate(6); + proc_save_mem(4); + + proc_contours(&contours, &hierarchy); + squares_n = contours.size(); +} + +static void pattern_squares_pos_get (void) +{ + int i; + + /* Get position of each contour */ + for (i = 0; i < squares_n; i++) { + proc_bounding_rect(&(contours[i]), &(rect[i]), true); + + pattern.square[i].pos.x_pix = rect[i].x + rect[i].width/2.0; + pattern.square[i].pos.y_pix = rect[i].y + rect[i].height/2.0; + } +} + +static void pattern_squares_len_get (void) +{ + int i; + + proc_load_mem(4); + + /* Get pattern square side lenght in pixels */ + for (i = 0; i < squares_n; i++) { + proc_pixel_get(pattern.square[i].pos.x_pix, + pattern.square[i].pos.y_pix, + &(pattern.square[i].len)); + pattern.square[i].len *= 2; + } +} + +static void pattern_calib_mm_pix (void) +{ + int i; + uint8_t pattern_len [OBJECTS_MAX]; + uint8_t median_size; + + for (i = 0; i < squares_n; i++) { + pattern_len[i] = pattern.square[i].len; + } + + median_size = alx_median_u8(squares_n, pattern_len); + ratio_mm_pix = PATTERN_SQUARE_LEN_MM / median_size; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "mm/pix = %lf", + ratio_mm_pix); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + +/* process -------------------------------------------------------------------*/ +static void objects_bgr2gray (void) +{ + proc_load_mem(0); + + proc_cvt_color(cv::COLOR_BGR2GRAY); + proc_save_mem(1); +} + +static void objects_rotation_fix (void) +{ + proc_load_mem(1); + + /* invert image before rotation to avoid black bands */ + proc_not(); + proc_rotate(pattern.center.x_pix, pattern.center.y_pix, pattern.angle); + proc_save_mem(2); +} + +static void objects_dimensions_fix (void) +{ + /* Need to correct also pattern dilatation (pattern_dimensions_get()) */ + proc_load_mem(2); + + proc_ROI(pattern.origin.x_pix, pattern.origin.y_pix, + pattern.width, pattern.height); + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_save_mem(3); +} + +static void objects_segment (void) +{ + proc_load_mem(3); + + proc_dilate_erode(3); + proc_erode_dilate(3); + proc_save_mem(4); + + proc_distance_transform(); + proc_threshold(cv::THRESH_BINARY_INV, 30); + proc_distance_transform(); + proc_skeleton(); + proc_threshold(cv::THRESH_BINARY_INV, 10); + proc_save_ref(); + proc_save_mem(5); + + proc_load_mem(3); + proc_and_2ref(); + proc_distance_transform(); + proc_threshold(cv::THRESH_BINARY, 10); + proc_save_mem(6); +} + +static int objects_contours (void) +{ + int status; + + proc_load_mem(6); + + proc_contours(&contours, &hierarchy); + objects_n = contours.size(); + + /* If no contour is found, error: NOK_OBJECTS */ + if (!objects_n) { + status = OBJECTS_NOK_OBJECTS; + return status; + } + + status = OBJECTS_OK; + return status; +} + +static void objects_position_pix (void) +{ + int i; + + /* Get position of each contour */ + for (i = 0; i < objects_n; i++) { + proc_fit_ellipse(&(contours[i]), &(rect_rot[i]), true); + + objects[i].pos.x_pix = rect_rot[i].center.x; + objects[i].pos.y_pix = rect_rot[i].center.y; + + objects[i].angle = -rect_rot[i].angle + 90.0; + if (objects[i].angle < 0) { + objects[i].angle += 180.0; + } + } +} + +static void objects_position_mm (void) +{ + int i; + + /* Get position of each contour */ + for (i = 0; i < objects_n; i++) { + objects[i].pos.x_mm = ratio_mm_pix * objects[i].pos.x_pix; + objects[i].pos.y_mm = ratio_mm_pix * objects[i].pos.y_pix; + } +} + +static void objects_size_pix (void) +{ + double area [OBJECTS_MAX]; + double perimeter [OBJECTS_MAX]; + int i; + + /* Get size of each contour */ + proc_contours_size(&contours, area, perimeter); + for (i = 0; i < objects_n; i++) { + objects[i].area_pix2 = area[i]; + objects[i].perimeter_pix = perimeter[i]; + } +} + +static void objects_size_mm (void) +{ + int i; + + /* Get position of each contour */ + for (i = 0; i < objects_n; i++) { + objects[i].area_mm2 = pow(ratio_mm_pix, 2) * + objects[i].area_pix2; + objects[i].perimeter_mm = ratio_mm_pix * + objects[i].perimeter_pix; + } +} + +static void objects_shape (void) +{ + int i; + + /* Get shape of each contour */ + for (i = 0; i < objects_n; i++) { + proc_min_area_rect(&(contours[i]), &(rect_rot[i]), true); + + objects[i].ratio_p2_a = pow(objects[i].perimeter_pix, 2) / + objects[i].area_pix2; + + objects[i].area_rect = rect_rot[i].size.width * + rect_rot[i].size.height; + objects[i].perimeter_rect = 2.0 * + (rect_rot[i].size.width + + rect_rot[i].size.height); + + objects[i].ratio_p_prect = objects[i].perimeter_pix / + objects[i].perimeter_rect; + objects[i].ratio_a_arect = objects[i].area_pix2 / + objects[i].area_rect; + } +} + +static void objects_log (void) +{ + int i; + + /* Get coins diameters in mm */ + for (i = 0; i < objects_n; i++) { + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Object[%i]:", + i); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " pos: (%.1lf, %.1lf) mm", + objects[i].pos.x_mm, + objects[i].pos.y_mm); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " ang = %.1lf DEG", + objects[i].angle); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " A = %.1lf mm2", + objects[i].area_mm2); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " P = %.1lf mm", + objects[i].perimeter_mm); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " p2/A = %.2lf", + objects[i].ratio_p2_a); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " p/p_r = %.2lf", + objects[i].ratio_p_prect); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " A/A_r = %.2lf", + objects[i].ratio_a_arect); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/src/proc_resistor.cpp b/modules/proc/src/proc_resistor.cpp index cdac617..58f1fe4 100644 --- a/modules/proc/src/proc_resistor.cpp +++ b/modules/proc/src/proc_resistor.cpp @@ -1,1459 +1,1459 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* pow() */ - #include - /* snprintf() & fflush() */ - #include - -/* Packages ------------------------------------------------------------------*/ - /* openCV */ - #include - -/* Project -------------------------------------------------------------------*/ - /* CONSTANTS */ - #include "img_iface.hpp" - /* user_iface_log */ - #include "user_iface.hpp" - -/* Module --------------------------------------------------------------------*/ - #include "proc_common.hpp" - - #include "proc_resistor.hpp" - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ -struct Resistor_Bands { - /* position */ - int x; - int y; - - /* value */ - unsigned char h; - unsigned char s; - unsigned char v; -}; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ - -/* Static --------------------------------------------------------------------*/ -static class std::vector >> contours; -static class cv::Mat hierarchy; -static class cv::RotatedRect rect_rot; -static class cv::Rect_ rect; -static int bkgd; -static int bands_n; -static struct Resistor_Bands bands [5]; -static char code [6]; -static int base; -static float resistance; -static int tolerance; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_resistor (int status); - -static int resistor_find (void); -static void resistor_align (void); -static void resistor_dimensions_0 (void); -static void resistor_crop_0 (void); -static void resistor_bkgd (void); -static void resistor_dimensions_1 (void); -static void resistor_crop_1 (void); -static void separate_bkgd_bands_h (void); -static void separate_bkgd_bands_s (void); -static void separate_bkgd_bands_v (void); -static void bkgd_find (void); -static int bands_find (void); -static void bands_colors (void); -static void bands_code (void); -static char band_hsv2code (struct Resistor_Bands *band); -static void bands_code_deduce_0 (void); -static void bands_code_deduce_1 (void); -static int bands_code_deduce_no (void); -static void resistor_value (void); -static int resistor_tolerance (void); -static int chk_std_value (void); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -int proc_resistor (void) -{ - int status; - - proc_save_mem(0); - /* Find resistor (position and angle) */ - { - /* Measure time */ - clock_start(); - - status = resistor_find(); - if (status) { - result_resistor(status); - return status; - } - - /* Measure time */ - clock_stop("Find resistor"); - } - /* Align resistor, find its dimensions, and crop */ - { - /* Measure time */ - clock_start(); - - resistor_align(); - resistor_dimensions_0(); - resistor_crop_0(); - - /* Measure time */ - clock_stop("Align, dimensions, & crop"); - } - /* Find backgroung color */ - { - /* Measure time */ - clock_start(); - - resistor_bkgd(); - - /* Measure time */ - clock_stop("Background color"); - } - /* Crop more */ - { - /* Measure time */ - clock_start(); - - resistor_dimensions_1(); - resistor_crop_1(); - - /* Measure time */ - clock_stop("Crop more"); - } - /* Separate background (BK) and lines (WH) */ - { - /* Measure time */ - clock_start(); - - separate_bkgd_bands_h(); - separate_bkgd_bands_s(); - separate_bkgd_bands_v(); - bkgd_find(); - - /* Measure time */ - clock_stop("Separate bkgd from bands"); - } - /* Find bands: contours -> rectangles */ - { - /* Measure time */ - clock_start(); - - status = bands_find(); - if (status) { - result_resistor(status); - return status; - } - - /* Measure time */ - clock_stop("Find bands"); - } - /* Read values on the center of each band */ - { - /* Measure time */ - clock_start(); - - bands_colors(); - - /* Measure time */ - clock_stop("Bands' colors"); - } - /* Interpret colors */ - { - /* Measure time */ - clock_start(); - - bands_code(); - bands_code_deduce_0(); - bands_code_deduce_1(); - status = bands_code_deduce_no(); - if (status) { - result_resistor(status); - return status; - } - - /* Measure time */ - clock_stop("Interpret colors"); - } - /* Calculate resistor value & tolerance */ - { - /* Measure time */ - clock_start(); - - resistor_value(); - status = resistor_tolerance(); - if (status) { - result_resistor(status); - return status; - } - - /* Write resistor value into log */ - if (bands_n != 1) { - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistance: %.2E ± %i%% Ohm", - resistance, tolerance); - } else { - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistance: 0 Ohm"); - } - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Measure time */ - clock_stop("Calculate resistance & tolerance"); - } - /* Check STD value */ - { - /* Measure time */ - clock_start(); - - status = chk_std_value(); - if (status) { - result_resistor(status); - return status; - } - - /* Measure time */ - clock_stop("Chk STD values"); - } - - status = RESISTOR_OK; - result_resistor(status); - return status; -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_resistor (int status) -{ - /* Write result into log */ - switch (status) { - case RESISTOR_OK: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistor: OK"); - break; - case RESISTOR_NOK_RESISTOR: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistor: NOK_RESISTOR"); - break; - case RESISTOR_NOK_BANDS: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistor: NOK_BANDS"); - break; - case RESISTOR_NOK_COLOR: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistor: NOK_COLOR"); - break; - case RESISTOR_NOK_STD_VALUE: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistor: NOK_STD_VALUE"); - break; - case RESISTOR_NOK_TOLERANCE: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistor: NOK_TOLERANCE"); - break; - default: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistor: NOK"); - break; - } - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - -static int resistor_find (void) -{ - int status; - - proc_load_mem(0); - - /* BGR -> HSV */ - proc_cvt_color(cv::COLOR_BGR2HSV); - proc_save_mem(19); - - proc_cmp(IMG_IFACE_CMP_SATURATION); - proc_smooth(IMGI_SMOOTH_MEDIAN, 7); - proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); - proc_save_mem(1); - proc_dilate_erode(10); - proc_contours(&contours, &hierarchy); - - /* If no contour is found, error: NOK_RESISTOR */ - if (!contours.size()) { - status = RESISTOR_NOK_RESISTOR; - return status; - } - - proc_min_area_rect(&(contours[0]), &rect_rot, true); - - /* If angle is < -45º, it is taking into acount the incorrect side */ - if (rect_rot.angle < -45.0) { - rect_rot.angle += 90.0; - } - - status = RESISTOR_OK; - return status; -} - -static void resistor_align (void) -{ - proc_load_mem(19); - proc_rotate(rect_rot.center.x, rect_rot.center.y, rect_rot.angle); - proc_save_mem(2); - proc_load_mem(1); - proc_rotate(rect_rot.center.x, rect_rot.center.y, rect_rot.angle); - proc_save_mem(3); -} - -static void resistor_dimensions_0 (void) -{ - proc_load_mem(3); - - proc_dilate_erode(10); - proc_contours(&contours, &hierarchy); - proc_bounding_rect(&(contours[0]), &rect, true); -} - -static void resistor_crop_0 (void) -{ - int x; - int y; - int w; - int h; - - proc_load_mem(2); - - w = rect.width; - h = rect.height; - x = rect.x; - y = rect.y; - proc_ROI(x, y, w, h); - proc_save_mem(4); -} - -static void resistor_bkgd (void) -{ - uint8_t bkgd_hue; - uint8_t bkgd_sat; - - /* hue */ - proc_load_mem(4); - proc_cmp(IMG_IFACE_CMP_HUE); - proc_median_vertical(); - proc_median_horizontal(); - proc_pixel_get(0, 0, &bkgd_hue); - - /* saturation */ - proc_load_mem(4); - proc_cmp(IMG_IFACE_CMP_SATURATION); - proc_median_vertical(); - proc_median_horizontal(); - proc_pixel_get(0, 0, &bkgd_sat); - - if (bkgd_hue < 50) { - /* Beige */ - bkgd = 0; - } else { - /* Blue */ - if ((bkgd_hue < 90) || (bkgd_sat < 100)) { - /* Teal blue */ - bkgd = 1; - } else if (bkgd_hue >= 105) { - /* Dark blue */ - bkgd = 2; - } else { - /* Normal blue */ - bkgd = 3; - } - } -} - -static void resistor_dimensions_1 (void) -{ - proc_load_mem(3); - - proc_dilate_erode(10); - proc_erode_dilate((rect.height * 0.67) / 2); - proc_contours(&contours, &hierarchy); - proc_bounding_rect(&(contours[0]), &rect, true); -} - -static void resistor_crop_1 (void) -{ - int x; - int y; - int w; - int h; - - proc_load_mem(2); - - w = rect.width * 0.95; - h = rect.height * 0.8; - x = rect.x + w * (1.0 - 0.95) / 2.0; - y = rect.y + h * (1.0 - 0.8) / 2.0; - proc_ROI(x, y, w, h); - proc_save_mem(4); -} - -static void separate_bkgd_bands_h (void) -{ - proc_load_mem(4); - - proc_cmp(IMG_IFACE_CMP_HUE); - proc_median_vertical(); - proc_save_mem(9); - - switch (bkgd) { - case 0: - proc_threshold(cv::THRESH_TOZERO_INV, 20); - proc_threshold(cv::THRESH_TOZERO, 5); - break; - case 1: - proc_threshold(cv::THRESH_TOZERO_INV, 100); - proc_threshold(cv::THRESH_TOZERO, 70); - break; - case 2: - proc_threshold(cv::THRESH_TOZERO_INV, 115); - proc_threshold(cv::THRESH_TOZERO, 100); - break; - case 3: - proc_threshold(cv::THRESH_TOZERO_INV, 110); - proc_threshold(cv::THRESH_TOZERO, 90); - break; - } - proc_threshold(cv::THRESH_BINARY_INV, 1); - proc_save_mem(5); -} - -static void separate_bkgd_bands_s (void) -{ - proc_load_mem(4); - - proc_cmp(IMG_IFACE_CMP_SATURATION); - proc_median_vertical(); - proc_save_mem(10); - - switch (bkgd) { - - case 0: - proc_threshold(cv::THRESH_TOZERO_INV, 160); - proc_threshold(cv::THRESH_TOZERO, 110); - break; - case 1: - proc_threshold(cv::THRESH_TOZERO_INV, 180); - proc_threshold(cv::THRESH_TOZERO, 30); - break; - case 2: - proc_threshold(cv::THRESH_TOZERO_INV, 190); - proc_threshold(cv::THRESH_TOZERO, 170); - break; - case 3: - proc_threshold(cv::THRESH_TOZERO_INV, 210); - proc_threshold(cv::THRESH_TOZERO, 120); - break; - } - proc_threshold(cv::THRESH_BINARY_INV, 1); - proc_save_mem(6); -} - -static void separate_bkgd_bands_v (void) -{ - proc_load_mem(4); - - proc_cmp(IMG_IFACE_CMP_VALUE); - proc_median_vertical(); - proc_save_mem(11); - - switch (bkgd) { - case 0: - proc_threshold(cv::THRESH_TOZERO_INV, 170); - proc_threshold(cv::THRESH_TOZERO, 100); - break; - - case 1: - proc_threshold(cv::THRESH_TOZERO_INV, 180); - proc_threshold(cv::THRESH_TOZERO, 100); - break; - case 2: - proc_threshold(cv::THRESH_TOZERO_INV, 180); - proc_threshold(cv::THRESH_TOZERO, 150); - break; - case 3: - proc_threshold(cv::THRESH_TOZERO_INV, 190); - proc_threshold(cv::THRESH_TOZERO, 90); - break; - } - proc_threshold(cv::THRESH_BINARY_INV, 1); - proc_save_mem(7); -} - -static void bkgd_find (void) -{ - /* Merge the components: H | S | V */ - proc_load_mem(7); - proc_save_ref(); - proc_load_mem(6); - proc_or_2ref(); - proc_save_ref(); - proc_load_mem(5); - proc_or_2ref(); - if (rect.width * 0.95 > 80) { - proc_dilate_erode(1); - } - proc_save_mem(8); -} - -static int bands_find (void) -{ - int status; - - proc_load_mem(8); - - /* Contours */ - proc_contours(&contours, &hierarchy); - if (contours.size() > 5) { - proc_load_mem(8); - proc_dilate_erode(1); - proc_contours(&contours, &hierarchy); - } - - bands_n = contours.size(); - if ((bands_n == 0) || (bands_n == 2) || (bands_n > 5)) { - status = RESISTOR_NOK_BANDS; - return status; - } - - /* Band 0 (hundreds) */ - if (bands_n == 5) { - proc_bounding_rect(&(contours[4]), &rect, true); - bands[0].x = rect.x + rect.width / 2.0; - bands[0].y = rect.y + rect.height / 2.0; - } - - /* Band 1 (tens) */ - if (bands_n >= 3) { - if (bands_n > 3) { - proc_bounding_rect(&(contours[3]), &rect, true); - } else { - proc_bounding_rect(&(contours[2]), &rect, true); - } - bands[1].x = rect.x + rect.width / 2.0; - bands[1].y = rect.y + rect.height / 2.0; - } - - /* Band 2 (units) */ - if (bands_n > 3) { - proc_bounding_rect(&(contours[2]), &rect, true); - } else if (bands_n == 3) { - proc_bounding_rect(&(contours[1]), &rect, true); - } else { /* bands_n == 1 */ - proc_bounding_rect(&(contours[0]), &rect, true); - } - bands[2].x = rect.x + rect.width / 2.0; - bands[2].y = rect.y + rect.height / 2.0; - - /* Band 3 (multiplier) */ - if (bands_n >= 3) { - if (bands_n > 3) { - proc_bounding_rect(&(contours[1]), &rect, true); - } else { - proc_bounding_rect(&(contours[0]), &rect, true); - } - bands[3].x = rect.x + rect.width / 2.0; - bands[3].y = rect.y + rect.height / 2.0; - } - - /* Band 4 (tolerance) */ - if (bands_n > 3) { - proc_bounding_rect(&(contours[0]), &rect, true); - bands[4].x = rect.x + rect.width / 2.0; - bands[4].y = rect.y + rect.height / 2.0; - } - - status = RESISTOR_OK; - return status; -} - -static void bands_colors (void) -{ - /* Hue */ - proc_load_mem(9); - if (bands_n == 5) { - proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].h)); - } - if (bands_n >= 3) { - proc_pixel_get(bands[1].x, bands[1].y, &(bands[1].h)); - } - proc_pixel_get(bands[2].x, bands[2].y, &(bands[2].h)); - if (bands_n >= 3) { - proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].h)); - } - if (bands_n > 3) { - proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].h)); - } - - /* Saturation */ - proc_load_mem(10); - if (bands_n == 5) { - proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].s)); - } - if (bands_n >= 3) { - proc_pixel_get(bands[1].x, bands[1].y, &(bands[1].s)); - } - proc_pixel_get(bands[2].x, bands[2].y, &(bands[2].s)); - if (bands_n >= 3) { - proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].s)); - } - if (bands_n > 3) { - proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].s)); - } - - /* Value */ - proc_load_mem(11); - if (bands_n == 5) { - proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].v)); - } - if (bands_n >= 3) { - proc_pixel_get(bands[1].x, bands[1].y, &(bands[1].v)); - } - proc_pixel_get(bands[2].x, bands[2].y, &(bands[2].v)); - if (bands_n >= 3) { - proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].v)); - } - if (bands_n > 3) { - proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].v)); - } -} - -static void bands_code (void) -{ - int i; - - /* Init to 0 */ - for (i = 0; i < 6; i++) { - code[i] = '\0'; - } - - /* Band 0 (hundreds) */ - if (bands_n == 5) { - code[0] = band_hsv2code(&bands[0]); - } else { - code[0] = 'n'; - } - - - /* Band 1 (tens) */ - if (bands_n != 1) { - code[1] = band_hsv2code(&bands[1]); - } else { - code[1] = 'n'; - } - - /* Band 2 (units) */ - code[2] = band_hsv2code(&bands[2]); - - /* Band 3 (multiplier) */ - if (bands_n != 1) { - code[3] = band_hsv2code(&bands[3]); - } else { - code[3] = 'n'; - } - - /* Band 4 (tolerance) */ - if (bands_n > 3) { - code[4] = band_hsv2code(&bands[4]); - } else { - code[4] = 'n'; - } - - /* 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)++; -} - -static char band_hsv2code (struct Resistor_Bands *band) -{ - char ch; - - /* - * Not able to segmentate: - * q = 1 2 - * w = 2 3 - * e = 3 g - * r = 3 4 - * t = 1 8 - * y = 0 1 - * u = 0 1 8 - */ - - if (band->h < 10) { - // 1 2 3 - if (band->s < 90) { - // 1 3 - if (band->v < 85) { - ch = '1'; - } else { - ch = '3'; - } - } else if (band->s < 140) { - // 1 2 3 - if (band->v < 60) { - ch = '1'; - } else if (band->v < 85) { - // 1 2 - ch = 'q'; - } else if (band->v < 90) { - ch = '2'; - } else if (band->v < 150) { - // 2 3 - ch = 'w'; - } else { - ch = '3'; - } - } else if (band->s < 210) { - // 2 3 - if (band->v < 90) { - ch = '2'; - } else if (band->v < 150) { - // 2 3 - ch = 'w'; - } else { - ch = '3'; - } - } else { - ch = '3'; - } - } else if (band->h < 35) { - // 1 3 g - if (band->s < 130) { - // 1 3 - if (band->v < 85) { - ch = '1'; - } else { - ch = '3'; - } - } else if (band->s < 140) { - // 1 3 g - if (band->v < 85) { - ch = '1'; - } else if (band->v < 120) { - ch = '3'; - } else { - // 3 g - ch = 'e'; - } - } else if (band->s < 180) { - // 3 g - if (band->v < 120) { - ch = '3'; - } else { - // 3 g - ch = 'e'; - } - } else { - ch = '3'; - } - } else if (band->h < 50) { - // 1 3 - if (band->s < 140) { - // 1 3 - if (band->v < 85) { - ch = '1'; - } else { - ch = '3'; - } - } else { - ch = '3'; - } - } else if (band->h < 60) { - // 1 3 4 - if (band->s < 140) { - // 1 3 - if (band->v < 85) { - ch = '1'; - } else { - ch = '3'; - } - } else if (band->s < 160) { - ch = '3'; - } else if (band->s < 180) { - // 3 4 - if (band->v < 110) { - // 3 4 - ch = 'r'; - } else { - ch = '3'; - } - } else { - ch = '3'; - } - } else if (band->h < 80) { - // 1 5 - if (band->s < 165) { - ch = '1'; - } else { - ch = '5'; - } - } else if (band->h < 90) { - ch = '1'; - } else if (band->h < 100) { - // 0 1 8 9 - if (band->s < 40) { - // 1 8 9 - if (band->v < 55) { - ch = '1'; - } else if (band->v < 80) { - // 1 8 - ch = 't'; - } else if (band->v < 125) { - ch = '1'; - } else { - ch = '9'; - } - } else if (band->s < 70) { - // 0 1 8 9 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 55) { - // 0 1 - ch = 'y'; - } else if (band->v < 75) { - // 0 1 8 - ch = 'u'; - } else if (band->v < 80) { - // 1 8 - ch = 't'; - } else if (band->v < 125) { - ch = '1'; - } else { - ch = '9'; - } - } else if (band->s < 100) { - // 0 1 8 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 55) { - // 0 1 - ch = 'y'; - } else if (band->v < 75) { - // 0 1 8 - ch = 'u'; - } else if (band->v < 80) { - // 1 8 - ch = 't'; - } else { - ch = '1'; - } - } else if (band->s < 140) { - // 0 1 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else { - ch = '1'; - } - } else { - ch = '0'; - } - } else if (band->h < 110) { - // 0 1 6 8 - if (band->s < 40) { - // 1 8 - if (band->v < 55) { - ch = '1'; - } else if (band->v < 80) { - // 1 8 - ch = 't'; - } else { - ch = '1'; - } - } else if (band->s < 100) { - // 0 1 8 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 55) { - // 0 1 - ch = 'y'; - } else if (band->v < 75) { - // 0 1 8 - ch = 'u'; - } else if (band->v < 80) { - // 1 8 - ch = 't'; - } else { - ch = '1'; - } - } else if (band->s < 140) { - // 0 1 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else { - ch = '1'; - } - } else if (band->s < 200) { - ch = '0'; - } else { - ch = '6'; - } - } else if (band->h < 120) { - // 0 1 6 7 - if (band->s < 40) { - ch = '1'; - } else if (band->s < 90) { - // 0 1 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else { - ch = '1'; - } - } else if (band->s < 110) { - // 0 1 7 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else if (band->v < 120) { - ch = '1'; - } else { - ch = '7'; - } - } else if (band->s < 140) { - // 0 1 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else { - ch = '1'; - } - } else if (band->s < 200) { - ch = '0'; - } else { - ch = '6'; - } - } else if (band->h < 130) { - // 0 1 7 - if (band->s < 40) { - ch = '1'; - } else if (band->s < 90) { - // 0 1 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else { - ch = '1'; - } - } else if (band->s < 110) { - // 0 1 7 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else if (band->v < 120) { - ch = '1'; - } else { - ch = '7'; - } - } else if (band->s < 140) { - // 0 1 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else { - ch = '1'; - } - } else { - ch = '0'; - } - } else if (band->h < 140) { - // 0 1 - if (band->s < 40) { - ch = '1'; - } else if (band->s < 140) { - // 0 1 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else { - ch = '1'; - } - } else { - ch = '0'; - } - } else if (band->h < 150) { - ch = '0'; - } else { - ch = '2'; - } - - return ch; -} - -static void bands_code_deduce_0 (void) -{ - /* - * Not able to segmentate: - * q = 1 2 - * w = 2 3 - * e = 3 g - * r = 3 4 - * t = 1 8 - * y = 0 1 - * u = 0 1 8 - */ - - /* Band 0 (hundreds) */ - switch (code[0]) { - case 'e': - code[0] = '3'; - break; - case 'y': - code[0] = '1'; - break; - case 'u': - code[0] = 't'; - break; - } - - /* Band 2 (units) */ - switch (code[2]) { - case 'e': - code[2] = '3'; - break; - } - - /* Band 3 (multiplier) */ - switch (code[3]) { - case 't': - code[3] = '1'; - break; - case 'u': - code[3] = 'y'; - break; - } - - /* Band 4 (tolerance) */ - switch (code[4]) { - case 'w': - code[4] = '2'; - break; - case 'e': - code[4] = 'g'; - break; - case 't': - code[4] = '1'; - break; - case 'y': - code[4] = '1'; - break; - case 'u': - code[4] = '1'; - break; - } - - /* 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)++; -} - -static void bands_code_deduce_1 (void) -{ - /* - * Not able to segmentate: - - * q = 1 2 - * w = 2 3 - * e = 3 g - * r = 3 4 - * t = 1 8 - * y = 0 1 - - * u = 0 1 8 - */ - - /* Band 0 (hundreds) */ - switch (code[0]) { - case 'q': - switch (code[1]) { - case '1': - case '3': - case '5': - case '6': - case '8': - code[0] = '1'; - break; - case '2': - case '4': - case '7': - code[0] = '2'; - break; - case '0': - // q - break; - } - break; - case 'w': - switch (code[1]) { - case '2': - case '4': - case '7': - code[0] = '2'; - break; - case '3': - case '6': - case '9': - code[0] = '3'; - break; - case '0': - // w - break; - } - break; - case 'r': - switch (code[1]) { - case '0': - case '6': - case '9': - code[0] = '3'; - break; - case '7': - code[0] = '4'; - break; - case '3': - // r - break; - } - break; - case 't': - switch (code[1]) { - case '0': - case '1': - case '3': - case '5': - case '6': - case '8': - code[0] = '1'; - break; - case '2': - // t - break; - } - break; - } - - /* Band 1 (tens) */ - switch (code[1]) { - case 'q': - switch (code[0]) { - case '5': - case '9': - code[1] = '1'; - break; - case '2': - case '6': - case '8': - code[1] = '2'; - break; - case '1': - // q - break; - } - break; - case 'w': - switch (code[0]) { - case '2': - case '6': - case '8': - code[1] = '2'; - break; - case '3': - case '4': - code[1] = '3'; - break; - case '1': - // w - break; - } - break; - case 't': - switch (code[0]) { - case '5': - case '9': - code[1] = '1'; - break; - case '6': - code[1] = '8'; - break; - case '1': - // t - break; - } - break; - case 'y': - switch (code[0]) { - case '2': - case '3': - code[1] = '0'; - break; - case '5': - case '9': - code[1] = '1'; - break; - case '1': - // y - break; - } - break; - case 'u': - switch (code[0]) { - case '2': - case '3': - code[1] = '0'; - break; - case '5': - case '9': - code[1] = '1'; - break; - case '6': - code[1] = '8'; - break; - case '1': - // u - break; - } - break; - } - - /* Band 2 (units) */ - switch (code[2]) { - case 'y': - code[2] = '0'; - break; - case 'u': - code[2] = '0'; - break; - } - - /* Band 3 (multiplier) */ - switch (code[3]) { - case 'y': - code[3] = '0'; - break; - } - - /* Band 4 (tolerance) */ - switch (code[4]) { - case 'q': - code[4] = '2'; - break; - } - - /* 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)++; -} - -static int bands_code_deduce_no (void) -{ - int status; - int i; - - /* - * Not able to segmentate: - * q = 1 2 - * w = 2 3 - * e = 3 g - * r = 3 4 - * t = 1 8 - * y = 0 1 - * u = 0 1 8 - */ - - for (i = 0; i < 5; i++) { - switch (code[i]) { - case 'q': - case 'w': - case 'e': - case 'r': - case 't': - case 'y': - case 'u': - code[i] = '?'; - break; - } - } - - for (i = 0; i < 5; i++) { - if (code[i] == '?') { - status = RESISTOR_NOK_COLOR; - return status; - } - } - - /* 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)++; - - status = RESISTOR_OK; - return status; -} - -static void resistor_value (void) -{ - int power; - - /* Base value */ - base = code[2] - '0'; - if (code[1] != 'n') { - base += (code[1] - '0') * 10; - } - if (code[0] != 'n') { - base += (code[0] - '0') * 100; - } - - /* Calculate resistance */ - if ((code[3] > '0') && (code[3] < '9')) { - power = code[3] - '0'; - } else if (code[3] == 'g') { - power = -1; - } else if (code[3] == 's') { - power = -2; - } else { - // error - return; - } - resistance = base * pow(10, power); -} - -static int resistor_tolerance (void) -{ - int status; - - if (bands_n != 1) { - switch (code[4]) { - case '1': - tolerance = 1; - break; - case '2': - tolerance = 2; - break; - case '4': - case 'g': - case 'n': - tolerance = 5; - break; - case '8': - tolerance = 10; - break; - default: - status = RESISTOR_NOK_TOLERANCE; - return status; - } - } - - status = RESISTOR_OK; - return status; -} - -static int chk_std_value (void) -{ - int status; - /* Check that base value is a standard value */ - int std_values_10 [12] = {10,12,15,18,22,27,33,39,47,56,68,82}; - int std_values_5 [12] = {11,13,16,20,24,30,36,43,51,62,75,91}; - bool std_value_nok = true; - int i; - - if (bands_n != 1) { - for (i = 0; i < 12; i++) { - if (base == std_values_10[i]) { - std_value_nok = false; - } - if (base == (std_values_10[i] * 10)) { - std_value_nok = false; - } - } - if (tolerance <= 5) { - for (i = 0; i < 12; i++) { - if (base == std_values_5[i]) { - std_value_nok = false; - } - if (base == (std_values_5[i] * 10)) { - std_value_nok = false; - } - } - } - } else { - if (base == 0) { - std_value_nok = false; - } - } - - if (std_value_nok) { - status = RESISTOR_NOK_STD_VALUE; - return status; - } - - status = RESISTOR_OK; - return status; -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* pow() */ + #include + /* snprintf() & fflush() */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* openCV */ + #include + +/* Project -------------------------------------------------------------------*/ + /* CONSTANTS */ + #include "img_iface.hpp" + /* user_iface_log */ + #include "user_iface.hpp" + +/* Module --------------------------------------------------------------------*/ + #include "proc_common.hpp" + + #include "proc_resistor.hpp" + + +/****************************************************************************** + ******* structs ************************************************************** + ******************************************************************************/ +struct Resistor_Bands { + /* position */ + int x; + int y; + + /* value */ + unsigned char h; + unsigned char s; + unsigned char v; +}; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ + +/* Static --------------------------------------------------------------------*/ +static class std::vector >> contours; +static class cv::Mat hierarchy; +static class cv::RotatedRect rect_rot; +static class cv::Rect_ rect; +static int bkgd; +static int bands_n; +static struct Resistor_Bands bands [5]; +static char code [6]; +static int base; +static float resistance; +static int tolerance; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_resistor (int status); + +static int resistor_find (void); +static void resistor_align (void); +static void resistor_dimensions_0 (void); +static void resistor_crop_0 (void); +static void resistor_bkgd (void); +static void resistor_dimensions_1 (void); +static void resistor_crop_1 (void); +static void separate_bkgd_bands_h (void); +static void separate_bkgd_bands_s (void); +static void separate_bkgd_bands_v (void); +static void bkgd_find (void); +static int bands_find (void); +static void bands_colors (void); +static void bands_code (void); +static char band_hsv2code (struct Resistor_Bands *band); +static void bands_code_deduce_0 (void); +static void bands_code_deduce_1 (void); +static int bands_code_deduce_no (void); +static void resistor_value (void); +static int resistor_tolerance (void); +static int chk_std_value (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +int proc_resistor (void) +{ + int status; + + proc_save_mem(0); + /* Find resistor (position and angle) */ + { + /* Measure time */ + clock_start(); + + status = resistor_find(); + if (status) { + result_resistor(status); + return status; + } + + /* Measure time */ + clock_stop("Find resistor"); + } + /* Align resistor, find its dimensions, and crop */ + { + /* Measure time */ + clock_start(); + + resistor_align(); + resistor_dimensions_0(); + resistor_crop_0(); + + /* Measure time */ + clock_stop("Align, dimensions, & crop"); + } + /* Find backgroung color */ + { + /* Measure time */ + clock_start(); + + resistor_bkgd(); + + /* Measure time */ + clock_stop("Background color"); + } + /* Crop more */ + { + /* Measure time */ + clock_start(); + + resistor_dimensions_1(); + resistor_crop_1(); + + /* Measure time */ + clock_stop("Crop more"); + } + /* Separate background (BK) and lines (WH) */ + { + /* Measure time */ + clock_start(); + + separate_bkgd_bands_h(); + separate_bkgd_bands_s(); + separate_bkgd_bands_v(); + bkgd_find(); + + /* Measure time */ + clock_stop("Separate bkgd from bands"); + } + /* Find bands: contours -> rectangles */ + { + /* Measure time */ + clock_start(); + + status = bands_find(); + if (status) { + result_resistor(status); + return status; + } + + /* Measure time */ + clock_stop("Find bands"); + } + /* Read values on the center of each band */ + { + /* Measure time */ + clock_start(); + + bands_colors(); + + /* Measure time */ + clock_stop("Bands' colors"); + } + /* Interpret colors */ + { + /* Measure time */ + clock_start(); + + bands_code(); + bands_code_deduce_0(); + bands_code_deduce_1(); + status = bands_code_deduce_no(); + if (status) { + result_resistor(status); + return status; + } + + /* Measure time */ + clock_stop("Interpret colors"); + } + /* Calculate resistor value & tolerance */ + { + /* Measure time */ + clock_start(); + + resistor_value(); + status = resistor_tolerance(); + if (status) { + result_resistor(status); + return status; + } + + /* Write resistor value into log */ + if (bands_n != 1) { + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Resistance: %.2E ± %i%% Ohm", + resistance, tolerance); + } else { + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Resistance: 0 Ohm"); + } + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Measure time */ + clock_stop("Calculate resistance & tolerance"); + } + /* Check STD value */ + { + /* Measure time */ + clock_start(); + + status = chk_std_value(); + if (status) { + result_resistor(status); + return status; + } + + /* Measure time */ + clock_stop("Chk STD values"); + } + + status = RESISTOR_OK; + result_resistor(status); + return status; +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_resistor (int status) +{ + /* Write result into log */ + switch (status) { + case RESISTOR_OK: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Resistor: OK"); + break; + case RESISTOR_NOK_RESISTOR: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Resistor: NOK_RESISTOR"); + break; + case RESISTOR_NOK_BANDS: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Resistor: NOK_BANDS"); + break; + case RESISTOR_NOK_COLOR: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Resistor: NOK_COLOR"); + break; + case RESISTOR_NOK_STD_VALUE: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Resistor: NOK_STD_VALUE"); + break; + case RESISTOR_NOK_TOLERANCE: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Resistor: NOK_TOLERANCE"); + break; + default: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Resistor: NOK"); + break; + } + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + +static int resistor_find (void) +{ + int status; + + proc_load_mem(0); + + /* BGR -> HSV */ + proc_cvt_color(cv::COLOR_BGR2HSV); + proc_save_mem(19); + + proc_cmp(IMG_IFACE_CMP_SATURATION); + proc_smooth(IMGI_SMOOTH_MEDIAN, 7); + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_save_mem(1); + proc_dilate_erode(10); + proc_contours(&contours, &hierarchy); + + /* If no contour is found, error: NOK_RESISTOR */ + if (!contours.size()) { + status = RESISTOR_NOK_RESISTOR; + return status; + } + + proc_min_area_rect(&(contours[0]), &rect_rot, true); + + /* If angle is < -45º, it is taking into acount the incorrect side */ + if (rect_rot.angle < -45.0) { + rect_rot.angle += 90.0; + } + + status = RESISTOR_OK; + return status; +} + +static void resistor_align (void) +{ + proc_load_mem(19); + proc_rotate(rect_rot.center.x, rect_rot.center.y, rect_rot.angle); + proc_save_mem(2); + proc_load_mem(1); + proc_rotate(rect_rot.center.x, rect_rot.center.y, rect_rot.angle); + proc_save_mem(3); +} + +static void resistor_dimensions_0 (void) +{ + proc_load_mem(3); + + proc_dilate_erode(10); + proc_contours(&contours, &hierarchy); + proc_bounding_rect(&(contours[0]), &rect, true); +} + +static void resistor_crop_0 (void) +{ + int x; + int y; + int w; + int h; + + proc_load_mem(2); + + w = rect.width; + h = rect.height; + x = rect.x; + y = rect.y; + proc_ROI(x, y, w, h); + proc_save_mem(4); +} + +static void resistor_bkgd (void) +{ + uint8_t bkgd_hue; + uint8_t bkgd_sat; + + /* hue */ + proc_load_mem(4); + proc_cmp(IMG_IFACE_CMP_HUE); + proc_median_vertical(); + proc_median_horizontal(); + proc_pixel_get(0, 0, &bkgd_hue); + + /* saturation */ + proc_load_mem(4); + proc_cmp(IMG_IFACE_CMP_SATURATION); + proc_median_vertical(); + proc_median_horizontal(); + proc_pixel_get(0, 0, &bkgd_sat); + + if (bkgd_hue < 50) { + /* Beige */ + bkgd = 0; + } else { + /* Blue */ + if ((bkgd_hue < 90) || (bkgd_sat < 100)) { + /* Teal blue */ + bkgd = 1; + } else if (bkgd_hue >= 105) { + /* Dark blue */ + bkgd = 2; + } else { + /* Normal blue */ + bkgd = 3; + } + } +} + +static void resistor_dimensions_1 (void) +{ + proc_load_mem(3); + + proc_dilate_erode(10); + proc_erode_dilate((rect.height * 0.67) / 2); + proc_contours(&contours, &hierarchy); + proc_bounding_rect(&(contours[0]), &rect, true); +} + +static void resistor_crop_1 (void) +{ + int x; + int y; + int w; + int h; + + proc_load_mem(2); + + w = rect.width * 0.95; + h = rect.height * 0.8; + x = rect.x + w * (1.0 - 0.95) / 2.0; + y = rect.y + h * (1.0 - 0.8) / 2.0; + proc_ROI(x, y, w, h); + proc_save_mem(4); +} + +static void separate_bkgd_bands_h (void) +{ + proc_load_mem(4); + + proc_cmp(IMG_IFACE_CMP_HUE); + proc_median_vertical(); + proc_save_mem(9); + + switch (bkgd) { + case 0: + proc_threshold(cv::THRESH_TOZERO_INV, 20); + proc_threshold(cv::THRESH_TOZERO, 5); + break; + case 1: + proc_threshold(cv::THRESH_TOZERO_INV, 100); + proc_threshold(cv::THRESH_TOZERO, 70); + break; + case 2: + proc_threshold(cv::THRESH_TOZERO_INV, 115); + proc_threshold(cv::THRESH_TOZERO, 100); + break; + case 3: + proc_threshold(cv::THRESH_TOZERO_INV, 110); + proc_threshold(cv::THRESH_TOZERO, 90); + break; + } + proc_threshold(cv::THRESH_BINARY_INV, 1); + proc_save_mem(5); +} + +static void separate_bkgd_bands_s (void) +{ + proc_load_mem(4); + + proc_cmp(IMG_IFACE_CMP_SATURATION); + proc_median_vertical(); + proc_save_mem(10); + + switch (bkgd) { + + case 0: + proc_threshold(cv::THRESH_TOZERO_INV, 160); + proc_threshold(cv::THRESH_TOZERO, 110); + break; + case 1: + proc_threshold(cv::THRESH_TOZERO_INV, 180); + proc_threshold(cv::THRESH_TOZERO, 30); + break; + case 2: + proc_threshold(cv::THRESH_TOZERO_INV, 190); + proc_threshold(cv::THRESH_TOZERO, 170); + break; + case 3: + proc_threshold(cv::THRESH_TOZERO_INV, 210); + proc_threshold(cv::THRESH_TOZERO, 120); + break; + } + proc_threshold(cv::THRESH_BINARY_INV, 1); + proc_save_mem(6); +} + +static void separate_bkgd_bands_v (void) +{ + proc_load_mem(4); + + proc_cmp(IMG_IFACE_CMP_VALUE); + proc_median_vertical(); + proc_save_mem(11); + + switch (bkgd) { + case 0: + proc_threshold(cv::THRESH_TOZERO_INV, 170); + proc_threshold(cv::THRESH_TOZERO, 100); + break; + + case 1: + proc_threshold(cv::THRESH_TOZERO_INV, 180); + proc_threshold(cv::THRESH_TOZERO, 100); + break; + case 2: + proc_threshold(cv::THRESH_TOZERO_INV, 180); + proc_threshold(cv::THRESH_TOZERO, 150); + break; + case 3: + proc_threshold(cv::THRESH_TOZERO_INV, 190); + proc_threshold(cv::THRESH_TOZERO, 90); + break; + } + proc_threshold(cv::THRESH_BINARY_INV, 1); + proc_save_mem(7); +} + +static void bkgd_find (void) +{ + /* Merge the components: H | S | V */ + proc_load_mem(7); + proc_save_ref(); + proc_load_mem(6); + proc_or_2ref(); + proc_save_ref(); + proc_load_mem(5); + proc_or_2ref(); + if (rect.width * 0.95 > 80) { + proc_dilate_erode(1); + } + proc_save_mem(8); +} + +static int bands_find (void) +{ + int status; + + proc_load_mem(8); + + /* Contours */ + proc_contours(&contours, &hierarchy); + if (contours.size() > 5) { + proc_load_mem(8); + proc_dilate_erode(1); + proc_contours(&contours, &hierarchy); + } + + bands_n = contours.size(); + if ((bands_n == 0) || (bands_n == 2) || (bands_n > 5)) { + status = RESISTOR_NOK_BANDS; + return status; + } + + /* Band 0 (hundreds) */ + if (bands_n == 5) { + proc_bounding_rect(&(contours[4]), &rect, true); + bands[0].x = rect.x + rect.width / 2.0; + bands[0].y = rect.y + rect.height / 2.0; + } + + /* Band 1 (tens) */ + if (bands_n >= 3) { + if (bands_n > 3) { + proc_bounding_rect(&(contours[3]), &rect, true); + } else { + proc_bounding_rect(&(contours[2]), &rect, true); + } + bands[1].x = rect.x + rect.width / 2.0; + bands[1].y = rect.y + rect.height / 2.0; + } + + /* Band 2 (units) */ + if (bands_n > 3) { + proc_bounding_rect(&(contours[2]), &rect, true); + } else if (bands_n == 3) { + proc_bounding_rect(&(contours[1]), &rect, true); + } else { /* bands_n == 1 */ + proc_bounding_rect(&(contours[0]), &rect, true); + } + bands[2].x = rect.x + rect.width / 2.0; + bands[2].y = rect.y + rect.height / 2.0; + + /* Band 3 (multiplier) */ + if (bands_n >= 3) { + if (bands_n > 3) { + proc_bounding_rect(&(contours[1]), &rect, true); + } else { + proc_bounding_rect(&(contours[0]), &rect, true); + } + bands[3].x = rect.x + rect.width / 2.0; + bands[3].y = rect.y + rect.height / 2.0; + } + + /* Band 4 (tolerance) */ + if (bands_n > 3) { + proc_bounding_rect(&(contours[0]), &rect, true); + bands[4].x = rect.x + rect.width / 2.0; + bands[4].y = rect.y + rect.height / 2.0; + } + + status = RESISTOR_OK; + return status; +} + +static void bands_colors (void) +{ + /* Hue */ + proc_load_mem(9); + if (bands_n == 5) { + proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].h)); + } + if (bands_n >= 3) { + proc_pixel_get(bands[1].x, bands[1].y, &(bands[1].h)); + } + proc_pixel_get(bands[2].x, bands[2].y, &(bands[2].h)); + if (bands_n >= 3) { + proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].h)); + } + if (bands_n > 3) { + proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].h)); + } + + /* Saturation */ + proc_load_mem(10); + if (bands_n == 5) { + proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].s)); + } + if (bands_n >= 3) { + proc_pixel_get(bands[1].x, bands[1].y, &(bands[1].s)); + } + proc_pixel_get(bands[2].x, bands[2].y, &(bands[2].s)); + if (bands_n >= 3) { + proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].s)); + } + if (bands_n > 3) { + proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].s)); + } + + /* Value */ + proc_load_mem(11); + if (bands_n == 5) { + proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].v)); + } + if (bands_n >= 3) { + proc_pixel_get(bands[1].x, bands[1].y, &(bands[1].v)); + } + proc_pixel_get(bands[2].x, bands[2].y, &(bands[2].v)); + if (bands_n >= 3) { + proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].v)); + } + if (bands_n > 3) { + proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].v)); + } +} + +static void bands_code (void) +{ + int i; + + /* Init to 0 */ + for (i = 0; i < 6; i++) { + code[i] = '\0'; + } + + /* Band 0 (hundreds) */ + if (bands_n == 5) { + code[0] = band_hsv2code(&bands[0]); + } else { + code[0] = 'n'; + } + + + /* Band 1 (tens) */ + if (bands_n != 1) { + code[1] = band_hsv2code(&bands[1]); + } else { + code[1] = 'n'; + } + + /* Band 2 (units) */ + code[2] = band_hsv2code(&bands[2]); + + /* Band 3 (multiplier) */ + if (bands_n != 1) { + code[3] = band_hsv2code(&bands[3]); + } else { + code[3] = 'n'; + } + + /* Band 4 (tolerance) */ + if (bands_n > 3) { + code[4] = band_hsv2code(&bands[4]); + } else { + code[4] = 'n'; + } + + /* 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)++; +} + +static char band_hsv2code (struct Resistor_Bands *band) +{ + char ch; + + /* + * Not able to segmentate: + * q = 1 2 + * w = 2 3 + * e = 3 g + * r = 3 4 + * t = 1 8 + * y = 0 1 + * u = 0 1 8 + */ + + if (band->h < 10) { + // 1 2 3 + if (band->s < 90) { + // 1 3 + if (band->v < 85) { + ch = '1'; + } else { + ch = '3'; + } + } else if (band->s < 140) { + // 1 2 3 + if (band->v < 60) { + ch = '1'; + } else if (band->v < 85) { + // 1 2 + ch = 'q'; + } else if (band->v < 90) { + ch = '2'; + } else if (band->v < 150) { + // 2 3 + ch = 'w'; + } else { + ch = '3'; + } + } else if (band->s < 210) { + // 2 3 + if (band->v < 90) { + ch = '2'; + } else if (band->v < 150) { + // 2 3 + ch = 'w'; + } else { + ch = '3'; + } + } else { + ch = '3'; + } + } else if (band->h < 35) { + // 1 3 g + if (band->s < 130) { + // 1 3 + if (band->v < 85) { + ch = '1'; + } else { + ch = '3'; + } + } else if (band->s < 140) { + // 1 3 g + if (band->v < 85) { + ch = '1'; + } else if (band->v < 120) { + ch = '3'; + } else { + // 3 g + ch = 'e'; + } + } else if (band->s < 180) { + // 3 g + if (band->v < 120) { + ch = '3'; + } else { + // 3 g + ch = 'e'; + } + } else { + ch = '3'; + } + } else if (band->h < 50) { + // 1 3 + if (band->s < 140) { + // 1 3 + if (band->v < 85) { + ch = '1'; + } else { + ch = '3'; + } + } else { + ch = '3'; + } + } else if (band->h < 60) { + // 1 3 4 + if (band->s < 140) { + // 1 3 + if (band->v < 85) { + ch = '1'; + } else { + ch = '3'; + } + } else if (band->s < 160) { + ch = '3'; + } else if (band->s < 180) { + // 3 4 + if (band->v < 110) { + // 3 4 + ch = 'r'; + } else { + ch = '3'; + } + } else { + ch = '3'; + } + } else if (band->h < 80) { + // 1 5 + if (band->s < 165) { + ch = '1'; + } else { + ch = '5'; + } + } else if (band->h < 90) { + ch = '1'; + } else if (band->h < 100) { + // 0 1 8 9 + if (band->s < 40) { + // 1 8 9 + if (band->v < 55) { + ch = '1'; + } else if (band->v < 80) { + // 1 8 + ch = 't'; + } else if (band->v < 125) { + ch = '1'; + } else { + ch = '9'; + } + } else if (band->s < 70) { + // 0 1 8 9 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 55) { + // 0 1 + ch = 'y'; + } else if (band->v < 75) { + // 0 1 8 + ch = 'u'; + } else if (band->v < 80) { + // 1 8 + ch = 't'; + } else if (band->v < 125) { + ch = '1'; + } else { + ch = '9'; + } + } else if (band->s < 100) { + // 0 1 8 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 55) { + // 0 1 + ch = 'y'; + } else if (band->v < 75) { + // 0 1 8 + ch = 'u'; + } else if (band->v < 80) { + // 1 8 + ch = 't'; + } else { + ch = '1'; + } + } else if (band->s < 140) { + // 0 1 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 75) { + // 0 1 + ch = 'y'; + } else { + ch = '1'; + } + } else { + ch = '0'; + } + } else if (band->h < 110) { + // 0 1 6 8 + if (band->s < 40) { + // 1 8 + if (band->v < 55) { + ch = '1'; + } else if (band->v < 80) { + // 1 8 + ch = 't'; + } else { + ch = '1'; + } + } else if (band->s < 100) { + // 0 1 8 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 55) { + // 0 1 + ch = 'y'; + } else if (band->v < 75) { + // 0 1 8 + ch = 'u'; + } else if (band->v < 80) { + // 1 8 + ch = 't'; + } else { + ch = '1'; + } + } else if (band->s < 140) { + // 0 1 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 75) { + // 0 1 + ch = 'y'; + } else { + ch = '1'; + } + } else if (band->s < 200) { + ch = '0'; + } else { + ch = '6'; + } + } else if (band->h < 120) { + // 0 1 6 7 + if (band->s < 40) { + ch = '1'; + } else if (band->s < 90) { + // 0 1 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 75) { + // 0 1 + ch = 'y'; + } else { + ch = '1'; + } + } else if (band->s < 110) { + // 0 1 7 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 75) { + // 0 1 + ch = 'y'; + } else if (band->v < 120) { + ch = '1'; + } else { + ch = '7'; + } + } else if (band->s < 140) { + // 0 1 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 75) { + // 0 1 + ch = 'y'; + } else { + ch = '1'; + } + } else if (band->s < 200) { + ch = '0'; + } else { + ch = '6'; + } + } else if (band->h < 130) { + // 0 1 7 + if (band->s < 40) { + ch = '1'; + } else if (band->s < 90) { + // 0 1 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 75) { + // 0 1 + ch = 'y'; + } else { + ch = '1'; + } + } else if (band->s < 110) { + // 0 1 7 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 75) { + // 0 1 + ch = 'y'; + } else if (band->v < 120) { + ch = '1'; + } else { + ch = '7'; + } + } else if (band->s < 140) { + // 0 1 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 75) { + // 0 1 + ch = 'y'; + } else { + ch = '1'; + } + } else { + ch = '0'; + } + } else if (band->h < 140) { + // 0 1 + if (band->s < 40) { + ch = '1'; + } else if (band->s < 140) { + // 0 1 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 75) { + // 0 1 + ch = 'y'; + } else { + ch = '1'; + } + } else { + ch = '0'; + } + } else if (band->h < 150) { + ch = '0'; + } else { + ch = '2'; + } + + return ch; +} + +static void bands_code_deduce_0 (void) +{ + /* + * Not able to segmentate: + * q = 1 2 + * w = 2 3 + * e = 3 g + * r = 3 4 + * t = 1 8 + * y = 0 1 + * u = 0 1 8 + */ + + /* Band 0 (hundreds) */ + switch (code[0]) { + case 'e': + code[0] = '3'; + break; + case 'y': + code[0] = '1'; + break; + case 'u': + code[0] = 't'; + break; + } + + /* Band 2 (units) */ + switch (code[2]) { + case 'e': + code[2] = '3'; + break; + } + + /* Band 3 (multiplier) */ + switch (code[3]) { + case 't': + code[3] = '1'; + break; + case 'u': + code[3] = 'y'; + break; + } + + /* Band 4 (tolerance) */ + switch (code[4]) { + case 'w': + code[4] = '2'; + break; + case 'e': + code[4] = 'g'; + break; + case 't': + code[4] = '1'; + break; + case 'y': + code[4] = '1'; + break; + case 'u': + code[4] = '1'; + break; + } + + /* 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)++; +} + +static void bands_code_deduce_1 (void) +{ + /* + * Not able to segmentate: + + * q = 1 2 + * w = 2 3 + * e = 3 g + * r = 3 4 + * t = 1 8 + * y = 0 1 + + * u = 0 1 8 + */ + + /* Band 0 (hundreds) */ + switch (code[0]) { + case 'q': + switch (code[1]) { + case '1': + case '3': + case '5': + case '6': + case '8': + code[0] = '1'; + break; + case '2': + case '4': + case '7': + code[0] = '2'; + break; + case '0': + // q + break; + } + break; + case 'w': + switch (code[1]) { + case '2': + case '4': + case '7': + code[0] = '2'; + break; + case '3': + case '6': + case '9': + code[0] = '3'; + break; + case '0': + // w + break; + } + break; + case 'r': + switch (code[1]) { + case '0': + case '6': + case '9': + code[0] = '3'; + break; + case '7': + code[0] = '4'; + break; + case '3': + // r + break; + } + break; + case 't': + switch (code[1]) { + case '0': + case '1': + case '3': + case '5': + case '6': + case '8': + code[0] = '1'; + break; + case '2': + // t + break; + } + break; + } + + /* Band 1 (tens) */ + switch (code[1]) { + case 'q': + switch (code[0]) { + case '5': + case '9': + code[1] = '1'; + break; + case '2': + case '6': + case '8': + code[1] = '2'; + break; + case '1': + // q + break; + } + break; + case 'w': + switch (code[0]) { + case '2': + case '6': + case '8': + code[1] = '2'; + break; + case '3': + case '4': + code[1] = '3'; + break; + case '1': + // w + break; + } + break; + case 't': + switch (code[0]) { + case '5': + case '9': + code[1] = '1'; + break; + case '6': + code[1] = '8'; + break; + case '1': + // t + break; + } + break; + case 'y': + switch (code[0]) { + case '2': + case '3': + code[1] = '0'; + break; + case '5': + case '9': + code[1] = '1'; + break; + case '1': + // y + break; + } + break; + case 'u': + switch (code[0]) { + case '2': + case '3': + code[1] = '0'; + break; + case '5': + case '9': + code[1] = '1'; + break; + case '6': + code[1] = '8'; + break; + case '1': + // u + break; + } + break; + } + + /* Band 2 (units) */ + switch (code[2]) { + case 'y': + code[2] = '0'; + break; + case 'u': + code[2] = '0'; + break; + } + + /* Band 3 (multiplier) */ + switch (code[3]) { + case 'y': + code[3] = '0'; + break; + } + + /* Band 4 (tolerance) */ + switch (code[4]) { + case 'q': + code[4] = '2'; + break; + } + + /* 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)++; +} + +static int bands_code_deduce_no (void) +{ + int status; + int i; + + /* + * Not able to segmentate: + * q = 1 2 + * w = 2 3 + * e = 3 g + * r = 3 4 + * t = 1 8 + * y = 0 1 + * u = 0 1 8 + */ + + for (i = 0; i < 5; i++) { + switch (code[i]) { + case 'q': + case 'w': + case 'e': + case 'r': + case 't': + case 'y': + case 'u': + code[i] = '?'; + break; + } + } + + for (i = 0; i < 5; i++) { + if (code[i] == '?') { + status = RESISTOR_NOK_COLOR; + return status; + } + } + + /* 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)++; + + status = RESISTOR_OK; + return status; +} + +static void resistor_value (void) +{ + int power; + + /* Base value */ + base = code[2] - '0'; + if (code[1] != 'n') { + base += (code[1] - '0') * 10; + } + if (code[0] != 'n') { + base += (code[0] - '0') * 100; + } + + /* Calculate resistance */ + if ((code[3] > '0') && (code[3] < '9')) { + power = code[3] - '0'; + } else if (code[3] == 'g') { + power = -1; + } else if (code[3] == 's') { + power = -2; + } else { + // error + return; + } + resistance = base * pow(10, power); +} + +static int resistor_tolerance (void) +{ + int status; + + if (bands_n != 1) { + switch (code[4]) { + case '1': + tolerance = 1; + break; + case '2': + tolerance = 2; + break; + case '4': + case 'g': + case 'n': + tolerance = 5; + break; + case '8': + tolerance = 10; + break; + default: + status = RESISTOR_NOK_TOLERANCE; + return status; + } + } + + status = RESISTOR_OK; + return status; +} + +static int chk_std_value (void) +{ + int status; + /* Check that base value is a standard value */ + int std_values_10 [12] = {10,12,15,18,22,27,33,39,47,56,68,82}; + int std_values_5 [12] = {11,13,16,20,24,30,36,43,51,62,75,91}; + bool std_value_nok = true; + int i; + + if (bands_n != 1) { + for (i = 0; i < 12; i++) { + if (base == std_values_10[i]) { + std_value_nok = false; + } + if (base == (std_values_10[i] * 10)) { + std_value_nok = false; + } + } + if (tolerance <= 5) { + for (i = 0; i < 12; i++) { + if (base == std_values_5[i]) { + std_value_nok = false; + } + if (base == (std_values_5[i] * 10)) { + std_value_nok = false; + } + } + } + } else { + if (base == 0) { + std_value_nok = false; + } + } + + if (std_value_nok) { + status = RESISTOR_NOK_STD_VALUE; + return status; + } + + status = RESISTOR_OK; + return status; +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/save/inc/save.h b/modules/save/inc/save.h index 46cab58..a3388d7 100644 --- a/modules/save/inc/save.h +++ b/modules/save/inc/save.h @@ -1,78 +1,78 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_SAVE_H - # define VA_SAVE_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* FILENAME_MAX */ - #include - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define ENV_HOME "HOME" - - # define USER_PROG_DIR "vision-artificial/" - # define USER_SAVED_DIR "vision-artificial/saved/" - # define USER_LABELS_DIR "vision-artificial/labels/" - # define USER_LABELS_FAIL_DIR "vision-artificial/labels/fail" - # define USER_LIGHTERS_DIR "vision-artificial/lighters/" - # define USER_LIGHTERS_FAIL_DIR "vision-artificial/lighters/fail" - # define USER_OBJECTS_DIR "vision-artificial/objects/" - # define USER_OBJECTS_FAIL_DIR "vision-artificial/objects/fail" - # define USER_COINS_DIR "vision-artificial/coins/" - # define USER_COINS_FAIL_DIR "vision-artificial/coins/fail" - # define USER_RESISTORS_DIR "vision-artificial/resistors/" - # define USER_RESISTORS_FAIL_DIR "vision-artificial/resistors/fail" - # define SAVED_NAME_DEFAULT "saved" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - extern char home_path [FILENAME_MAX]; - extern char user_prog_path [FILENAME_MAX]; - extern char saved_path [FILENAME_MAX]; - extern char labels_path [FILENAME_MAX]; - extern char labels_fail_path [FILENAME_MAX]; - extern char lighters_path [FILENAME_MAX]; - extern char lighters_fail_path [FILENAME_MAX]; - extern char objects_path [FILENAME_MAX]; - extern char objects_fail_path [FILENAME_MAX]; - extern char coins_path [FILENAME_MAX]; - extern char coins_fail_path [FILENAME_MAX]; - extern char resistors_path [FILENAME_MAX]; - extern char resistors_fail_path [FILENAME_MAX]; - extern char saved_name [FILENAME_MAX]; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void save_init (void); - void save_cleanup (void); - void save_clr (void); - void load_image_file (const char *fpath, const char *fname); - void save_image_file (const char *fpath, const char *save_as); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* save.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_SAVE_H + # define VA_SAVE_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* FILENAME_MAX */ + #include + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define ENV_HOME "HOME" + + # define USER_PROG_DIR "vision-artificial/" + # define USER_SAVED_DIR "vision-artificial/saved/" + # define USER_LABELS_DIR "vision-artificial/labels/" + # define USER_LABELS_FAIL_DIR "vision-artificial/labels/fail" + # define USER_LIGHTERS_DIR "vision-artificial/lighters/" + # define USER_LIGHTERS_FAIL_DIR "vision-artificial/lighters/fail" + # define USER_OBJECTS_DIR "vision-artificial/objects/" + # define USER_OBJECTS_FAIL_DIR "vision-artificial/objects/fail" + # define USER_COINS_DIR "vision-artificial/coins/" + # define USER_COINS_FAIL_DIR "vision-artificial/coins/fail" + # define USER_RESISTORS_DIR "vision-artificial/resistors/" + # define USER_RESISTORS_FAIL_DIR "vision-artificial/resistors/fail" + # define SAVED_NAME_DEFAULT "saved" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern char home_path [FILENAME_MAX]; + extern char user_prog_path [FILENAME_MAX]; + extern char saved_path [FILENAME_MAX]; + extern char labels_path [FILENAME_MAX]; + extern char labels_fail_path [FILENAME_MAX]; + extern char lighters_path [FILENAME_MAX]; + extern char lighters_fail_path [FILENAME_MAX]; + extern char objects_path [FILENAME_MAX]; + extern char objects_fail_path [FILENAME_MAX]; + extern char coins_path [FILENAME_MAX]; + extern char coins_fail_path [FILENAME_MAX]; + extern char resistors_path [FILENAME_MAX]; + extern char resistors_fail_path [FILENAME_MAX]; + extern char saved_name [FILENAME_MAX]; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void save_init (void); + void save_cleanup (void); + void save_clr (void); + void load_image_file (const char *fpath, const char *fname); + void save_image_file (const char *fpath, const char *save_as); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* save.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/save/inc/save.hpp b/modules/save/inc/save.hpp index 5dcf6e5..d7640a1 100644 --- a/modules/save/inc/save.hpp +++ b/modules/save/inc/save.hpp @@ -1,95 +1,95 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_SAVE_HPP - # define VA_SAVE_HPP - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* FILENAME_MAX */ - #include - -/* Project -------------------------------------------------------------------*/ - /* opencv */ - #include - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define ENV_HOME "HOME" - - # define USER_PROG_DIR "vision-artificial/" - # define USER_SAVED_DIR "vision-artificial/saved/" - # define USER_LABELS_DIR "vision-artificial/labels/" - # define USER_LABELS_FAIL_DIR "vision-artificial/labels/fail" - # define USER_LIGHTERS_DIR "vision-artificial/lighters/" - # define USER_LIGHTERS_FAIL_DIR "vision-artificial/lighters/fail" - # define USER_OBJECTS_DIR "vision-artificial/objects/" - # define USER_OBJECTS_FAIL_DIR "vision-artificial/objects/fail" - # define USER_COINS_DIR "vision-artificial/coins/" - # define USER_COINS_FAIL_DIR "vision-artificial/coins/fail" - # define USER_RESISTORS_DIR "vision-artificial/resistors/" - # define USER_RESISTORS_FAIL_DIR "vision-artificial/resistors/fail" - # define SAVED_NAME_DEFAULT "saved" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - extern class cv::Mat image; - extern char home_path [FILENAME_MAX]; - extern char user_prog_path [FILENAME_MAX]; - extern char saved_path [FILENAME_MAX]; - extern char labels_path [FILENAME_MAX]; - extern char labels_fail_path [FILENAME_MAX]; - extern char lighters_path [FILENAME_MAX]; - extern char lighters_fail_path [FILENAME_MAX]; - extern char objects_path [FILENAME_MAX]; - extern char objects_fail_path [FILENAME_MAX]; - extern char coins_path [FILENAME_MAX]; - extern char coins_fail_path [FILENAME_MAX]; - extern char resistors_path [FILENAME_MAX]; - extern char resistors_fail_path [FILENAME_MAX]; - extern char saved_name [FILENAME_MAX]; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void save_init (void); - void save_cleanup (void); - void save_clr (void); - void load_image_file (const char *fpath, const char *fname); - void save_image_file (const char *fpath, const char *save_as); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* save.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_SAVE_HPP + # define VA_SAVE_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* FILENAME_MAX */ + #include + +/* Project -------------------------------------------------------------------*/ + /* opencv */ + #include + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define ENV_HOME "HOME" + + # define USER_PROG_DIR "vision-artificial/" + # define USER_SAVED_DIR "vision-artificial/saved/" + # define USER_LABELS_DIR "vision-artificial/labels/" + # define USER_LABELS_FAIL_DIR "vision-artificial/labels/fail" + # define USER_LIGHTERS_DIR "vision-artificial/lighters/" + # define USER_LIGHTERS_FAIL_DIR "vision-artificial/lighters/fail" + # define USER_OBJECTS_DIR "vision-artificial/objects/" + # define USER_OBJECTS_FAIL_DIR "vision-artificial/objects/fail" + # define USER_COINS_DIR "vision-artificial/coins/" + # define USER_COINS_FAIL_DIR "vision-artificial/coins/fail" + # define USER_RESISTORS_DIR "vision-artificial/resistors/" + # define USER_RESISTORS_FAIL_DIR "vision-artificial/resistors/fail" + # define SAVED_NAME_DEFAULT "saved" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern class cv::Mat image; + extern char home_path [FILENAME_MAX]; + extern char user_prog_path [FILENAME_MAX]; + extern char saved_path [FILENAME_MAX]; + extern char labels_path [FILENAME_MAX]; + extern char labels_fail_path [FILENAME_MAX]; + extern char lighters_path [FILENAME_MAX]; + extern char lighters_fail_path [FILENAME_MAX]; + extern char objects_path [FILENAME_MAX]; + extern char objects_fail_path [FILENAME_MAX]; + extern char coins_path [FILENAME_MAX]; + extern char coins_fail_path [FILENAME_MAX]; + extern char resistors_path [FILENAME_MAX]; + extern char resistors_fail_path [FILENAME_MAX]; + extern char saved_name [FILENAME_MAX]; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void save_init (void); + void save_cleanup (void); + void save_clr (void); + void load_image_file (const char *fpath, const char *fname); + void save_image_file (const char *fpath, const char *save_as); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* save.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/save/src/save.cpp b/modules/save/src/save.cpp index e174f8b..6e948a8 100644 --- a/modules/save/src/save.cpp +++ b/modules/save/src/save.cpp @@ -1,198 +1,198 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* errno */ - #include - /* fscanf() & fprintf() & FILE & FILENAME_MAX & snprintf() */ - #include - /* getenv() */ - #include - -/* Linux ---------------------------------------------------------------------*/ - /* mkdir */ - #include - -/* Packages ------------------------------------------------------------------*/ - /* opencv */ - #include - -/* Project -------------------------------------------------------------------*/ - /* user_iface_save_name() */ - #include "user_iface.hpp" - -/* Module --------------------------------------------------------------------*/ - #include "save.hpp" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -class cv::Mat image; -char home_path [FILENAME_MAX]; -char user_prog_path [FILENAME_MAX]; -char saved_path [FILENAME_MAX]; -char labels_path [FILENAME_MAX]; -char labels_fail_path [FILENAME_MAX]; -char lighters_path [FILENAME_MAX]; -char lighters_fail_path [FILENAME_MAX]; -char objects_path [FILENAME_MAX]; -char objects_fail_path [FILENAME_MAX]; -char coins_path [FILENAME_MAX]; -char coins_fail_path [FILENAME_MAX]; -char resistors_path [FILENAME_MAX]; -char resistors_fail_path [FILENAME_MAX]; -char saved_name [FILENAME_MAX]; - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void save_init (void) -{ - snprintf(home_path, FILENAME_MAX, "%s/", getenv(ENV_HOME)); - snprintf(user_prog_path, FILENAME_MAX, "%s/%s/", home_path, USER_PROG_DIR); - snprintf(saved_path, FILENAME_MAX, "%s/%s/", home_path, USER_SAVED_DIR); - snprintf(labels_path, FILENAME_MAX, "%s/%s/", home_path, USER_LABELS_DIR); - snprintf(labels_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_LABELS_FAIL_DIR); - snprintf(lighters_path, FILENAME_MAX, "%s/%s/", home_path, USER_LIGHTERS_DIR); - snprintf(lighters_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_LIGHTERS_FAIL_DIR); - snprintf(objects_path, FILENAME_MAX, "%s/%s/", home_path, USER_OBJECTS_DIR); - snprintf(objects_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_OBJECTS_FAIL_DIR); - snprintf(coins_path, FILENAME_MAX, "%s/%s/", home_path, USER_COINS_DIR); - snprintf(coins_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_COINS_FAIL_DIR); - snprintf(resistors_path, FILENAME_MAX, "%s/%s/", home_path, USER_RESISTORS_DIR); - snprintf(resistors_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_RESISTORS_FAIL_DIR); - sprintf(saved_name, ""); - - int err; - err = mkdir(user_prog_path, 0700); - - if (!err) { - } else { - - switch (errno) { - case EACCES: - printf("err = EACCES"); -// exit(EXIT_FAILURE); - break; - - case EEXIST: - /* OK */ - break; - - default: - printf("WTF?!"); -// exit(EXIT_FAILURE); - } - } - - mkdir(saved_path, 0700); - mkdir(labels_path, 0700); - mkdir(labels_fail_path, 0700); -} - -void save_clr (void) -{ - snprintf(saved_path, FILENAME_MAX, "%s/%s/", home_path, USER_SAVED_DIR); -} - -void load_image_file (const char *fpath, const char *fname) -{ - char file_path [FILENAME_MAX]; - char file_name [FILENAME_MAX]; - - /* Free old image */ - image.release(); - - /* Set file_path */ - if (!fpath) { - /* Default path */ - save_clr(); - snprintf(file_path, FILENAME_MAX, "%s", saved_path); - } else { - snprintf(file_path, FILENAME_MAX, "%s", fpath); - } - - /* Set file_name */ - if (!fname) { - /* Request file name */ - user_iface_fname(file_path, saved_name); - } else { - snprintf(saved_name, FILENAME_MAX, "%s", fname); - } - - /* File name */ - snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name); - - /* Load image */ - image = cv::imread(file_name, CV_LOAD_IMAGE_COLOR); - - /* Manage load error */ - if (image.empty()) { - printf("Could not load file: %s\n", file_name); -// exit(0); - } -} - -void save_cleanup (void) -{ - /* Free old image */ - image.release(); -} - -void save_image_file (const char *fpath, const char *save_as) -{ - char file_path [FILENAME_MAX]; - char file_name [FILENAME_MAX]; - FILE *fp; - - /* Set file_path */ - if (!fpath) { - /* Default path */ - save_clr(); - snprintf(file_path, FILENAME_MAX, "%s", saved_path); - } else { - snprintf(file_path, FILENAME_MAX, "%s", fpath); - } - - /* Set file_name */ - if (!save_as) { - /* Default name */ - snprintf(saved_name, FILENAME_MAX, "%s", SAVED_NAME_DEFAULT); - /* Request file name */ - user_iface_fname(saved_path, saved_name); - } else { - snprintf(saved_name, FILENAME_MAX, "%s", save_as); - } - - /* Prepend the path */ - snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name); - - fp = fopen(file_name, "r"); - if (fp) { - /* Name in use; ask once more */ - fclose(fp); - user_iface_fname(saved_path, saved_name); - snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name); - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "%s", saved_name); - user_iface_log.lvl[user_iface_log.len] = 2; - (user_iface_log.len)++; - - - /* Write to a new file */ - cv::imwrite(file_name, image); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* errno */ + #include + /* fscanf() & fprintf() & FILE & FILENAME_MAX & snprintf() */ + #include + /* getenv() */ + #include + +/* Linux ---------------------------------------------------------------------*/ + /* mkdir */ + #include + +/* Packages ------------------------------------------------------------------*/ + /* opencv */ + #include + +/* Project -------------------------------------------------------------------*/ + /* user_iface_save_name() */ + #include "user_iface.hpp" + +/* Module --------------------------------------------------------------------*/ + #include "save.hpp" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +class cv::Mat image; +char home_path [FILENAME_MAX]; +char user_prog_path [FILENAME_MAX]; +char saved_path [FILENAME_MAX]; +char labels_path [FILENAME_MAX]; +char labels_fail_path [FILENAME_MAX]; +char lighters_path [FILENAME_MAX]; +char lighters_fail_path [FILENAME_MAX]; +char objects_path [FILENAME_MAX]; +char objects_fail_path [FILENAME_MAX]; +char coins_path [FILENAME_MAX]; +char coins_fail_path [FILENAME_MAX]; +char resistors_path [FILENAME_MAX]; +char resistors_fail_path [FILENAME_MAX]; +char saved_name [FILENAME_MAX]; + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void save_init (void) +{ + snprintf(home_path, FILENAME_MAX, "%s/", getenv(ENV_HOME)); + snprintf(user_prog_path, FILENAME_MAX, "%s/%s/", home_path, USER_PROG_DIR); + snprintf(saved_path, FILENAME_MAX, "%s/%s/", home_path, USER_SAVED_DIR); + snprintf(labels_path, FILENAME_MAX, "%s/%s/", home_path, USER_LABELS_DIR); + snprintf(labels_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_LABELS_FAIL_DIR); + snprintf(lighters_path, FILENAME_MAX, "%s/%s/", home_path, USER_LIGHTERS_DIR); + snprintf(lighters_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_LIGHTERS_FAIL_DIR); + snprintf(objects_path, FILENAME_MAX, "%s/%s/", home_path, USER_OBJECTS_DIR); + snprintf(objects_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_OBJECTS_FAIL_DIR); + snprintf(coins_path, FILENAME_MAX, "%s/%s/", home_path, USER_COINS_DIR); + snprintf(coins_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_COINS_FAIL_DIR); + snprintf(resistors_path, FILENAME_MAX, "%s/%s/", home_path, USER_RESISTORS_DIR); + snprintf(resistors_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_RESISTORS_FAIL_DIR); + sprintf(saved_name, ""); + + int err; + err = mkdir(user_prog_path, 0700); + + if (!err) { + } else { + + switch (errno) { + case EACCES: + printf("err = EACCES"); +// exit(EXIT_FAILURE); + break; + + case EEXIST: + /* OK */ + break; + + default: + printf("WTF?!"); +// exit(EXIT_FAILURE); + } + } + + mkdir(saved_path, 0700); + mkdir(labels_path, 0700); + mkdir(labels_fail_path, 0700); +} + +void save_clr (void) +{ + snprintf(saved_path, FILENAME_MAX, "%s/%s/", home_path, USER_SAVED_DIR); +} + +void load_image_file (const char *fpath, const char *fname) +{ + char file_path [FILENAME_MAX]; + char file_name [FILENAME_MAX]; + + /* Free old image */ + image.release(); + + /* Set file_path */ + if (!fpath) { + /* Default path */ + save_clr(); + snprintf(file_path, FILENAME_MAX, "%s", saved_path); + } else { + snprintf(file_path, FILENAME_MAX, "%s", fpath); + } + + /* Set file_name */ + if (!fname) { + /* Request file name */ + user_iface_fname(file_path, saved_name); + } else { + snprintf(saved_name, FILENAME_MAX, "%s", fname); + } + + /* File name */ + snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name); + + /* Load image */ + image = cv::imread(file_name, CV_LOAD_IMAGE_COLOR); + + /* Manage load error */ + if (image.empty()) { + printf("Could not load file: %s\n", file_name); +// exit(0); + } +} + +void save_cleanup (void) +{ + /* Free old image */ + image.release(); +} + +void save_image_file (const char *fpath, const char *save_as) +{ + char file_path [FILENAME_MAX]; + char file_name [FILENAME_MAX]; + FILE *fp; + + /* Set file_path */ + if (!fpath) { + /* Default path */ + save_clr(); + snprintf(file_path, FILENAME_MAX, "%s", saved_path); + } else { + snprintf(file_path, FILENAME_MAX, "%s", fpath); + } + + /* Set file_name */ + if (!save_as) { + /* Default name */ + snprintf(saved_name, FILENAME_MAX, "%s", SAVED_NAME_DEFAULT); + /* Request file name */ + user_iface_fname(saved_path, saved_name); + } else { + snprintf(saved_name, FILENAME_MAX, "%s", save_as); + } + + /* Prepend the path */ + snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name); + + fp = fopen(file_name, "r"); + if (fp) { + /* Name in use; ask once more */ + fclose(fp); + user_iface_fname(saved_path, saved_name); + snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name); + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "%s", saved_name); + user_iface_log.lvl[user_iface_log.len] = 2; + (user_iface_log.len)++; + + + /* Write to a new file */ + cv::imwrite(file_name, image); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/user/inc/user_clui.h b/modules/user/inc/user_clui.h index dffc625..916fe00 100644 --- a/modules/user/inc/user_clui.h +++ b/modules/user/inc/user_clui.h @@ -1,30 +1,30 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_USER_CLUI_H - # define VA_USER_CLUI_H - - -/****************************************************************************** - ******* 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); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* user_clui.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_USER_CLUI_H + # define VA_USER_CLUI_H + + +/****************************************************************************** + ******* 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); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* user_clui.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/user/inc/user_iface.h b/modules/user/inc/user_iface.h index f4511be..f65d708 100644 --- a/modules/user/inc/user_iface.h +++ b/modules/user/inc/user_iface.h @@ -1,163 +1,163 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_USER_IFACE_H - # define VA_USER_IFACE_H - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define LOG_LEN (1048576) - # define LOG_LINE_LEN (80) - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* intX_t */ - #include - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Player_Iface_Mode { - USER_IFACE_FOO, - USER_IFACE_CLUI, - USER_IFACE_TUI - }; - - enum Player_Iface_Action { - USER_IFACE_ACT_FOO = 0x000000u, - - USER_IFACE_ACT_ALX = 0x000010u, - USER_IFACE_ACT_LOCAL_MAX, - USER_IFACE_ACT_SKELETON, - USER_IFACE_ACT_LINES_HORIZONTAL, - USER_IFACE_ACT_LINES_VERTICAL, - USER_IFACE_ACT_MEAN_HORIZONTAL, - USER_IFACE_ACT_MEAN_VERTICAL, - USER_IFACE_ACT_MEDIAN_HORIZONTAL, - USER_IFACE_ACT_MEDIAN_VERTICAL, - - USER_IFACE_ACT_CV = 0x000100u, - USER_IFACE_ACT_PIXEL_GET, - USER_IFACE_ACT_PIXEL_SET, - USER_IFACE_ACT_SET_ROI, - USER_IFACE_ACT_SET_ROI_2RECT, - USER_IFACE_ACT_AND_2REF, - USER_IFACE_ACT_NOT, - USER_IFACE_ACT_OR_2REF, - USER_IFACE_ACT_COMPONENT, - USER_IFACE_ACT_DILATE, - USER_IFACE_ACT_ERODE, - USER_IFACE_ACT_DILATE_ERODE, - USER_IFACE_ACT_ERODE_DILATE, - USER_IFACE_ACT_SMOOTH, - USER_IFACE_ACT_SOBEL, - USER_IFACE_ACT_BORDER, - USER_IFACE_ACT_MIRROR, - USER_IFACE_ACT_ROTATE_ORTO, - USER_IFACE_ACT_ROTATE, - USER_IFACE_ACT_ROTATE_2RECT, - USER_IFACE_ACT_ADAPTIVE_THRESHOLD, - USER_IFACE_ACT_CVT_COLOR, - USER_IFACE_ACT_DISTANCE_TRANSFORM, - USER_IFACE_ACT_THRESHOLD, - USER_IFACE_ACT_HISTOGRAM, - USER_IFACE_ACT_HISTOGRAM_C3, - USER_IFACE_ACT_CONTOURS, - USER_IFACE_ACT_CONTOURS_SIZE, - USER_IFACE_ACT_BOUNDING_RECT, - USER_IFACE_ACT_FIT_ELLIPSE, - USER_IFACE_ACT_MIN_AREA_RECT, - USER_IFACE_ACT_HOUGH_CIRCLES, - - USER_IFACE_ACT_ORB = 0x000200u, - USER_IFACE_ACT_ALIGN, - - USER_IFACE_ACT_CALIB3D = 0x000400u, - USER_IFACE_ACT_CALIBRATE, - USER_IFACE_ACT_UNDISTORT, - - USER_IFACE_ACT_ZB = 0x000800u, - USER_IFACE_ACT_DECODE, - - USER_IFACE_ACT_OCR = 0x001000u, - USER_IFACE_ACT_READ, - - USER_IFACE_ACT_IMGI = 0x002000u, - USER_IFACE_ACT_APPLY, - USER_IFACE_ACT_DISCARD, - USER_IFACE_ACT_SAVE_MEM, - USER_IFACE_ACT_LOAD_MEM, - USER_IFACE_ACT_SAVE_REF, - - USER_IFACE_ACT_SAVE = 0x004000u, - USER_IFACE_ACT_SAVE_FILE, - USER_IFACE_ACT_SAVE_UPDT, - - USER_IFACE_ACT_PROC = 0x008000u, - USER_IFACE_ACT_PROC_LABEL_SERIES, - USER_IFACE_ACT_PROC_LABEL_CALIB, - USER_IFACE_ACT_PROC_OBJECTS_SERIES, - USER_IFACE_ACT_PROC_OBJECTS_CALIB, - USER_IFACE_ACT_PROC_COINS_SERIES, - USER_IFACE_ACT_PROC_COINS_CALIB, - USER_IFACE_ACT_PROC_RESISTOR_SERIES, - USER_IFACE_ACT_PROC_RESISTOR_CALIB, - - USER_IFACE_ACT_USRI = 0x010000u, - USER_IFACE_ACT_SHOW_OCR, - USER_IFACE_ACT_QUIT - }; - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ - struct User_Iface_Log { - int len; - char line [LOG_LEN] [LOG_LINE_LEN]; - int lvl [LOG_LEN]; - int visible; - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - extern int user_iface_mode; - extern struct User_Iface_Log user_iface_log; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void user_iface_init (void); - void user_iface_cleanup (void); - void user_iface (void); - void user_iface_show_log (const char *title, const char *subtitle); - void user_iface_fname (const char *filepath, char *filename); - double user_iface_getdbl (double m, double def, double M, - const char *title, const char *help); - int64_t user_iface_getint (double m, int64_t def, double M, - const char *title, const char *help); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* user_iface.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_USER_IFACE_H + # define VA_USER_IFACE_H + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define LOG_LEN (1048576) + # define LOG_LINE_LEN (80) + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* intX_t */ + #include + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Player_Iface_Mode { + USER_IFACE_FOO, + USER_IFACE_CLUI, + USER_IFACE_TUI + }; + + enum Player_Iface_Action { + USER_IFACE_ACT_FOO = 0x000000u, + + USER_IFACE_ACT_ALX = 0x000010u, + USER_IFACE_ACT_LOCAL_MAX, + USER_IFACE_ACT_SKELETON, + USER_IFACE_ACT_LINES_HORIZONTAL, + USER_IFACE_ACT_LINES_VERTICAL, + USER_IFACE_ACT_MEAN_HORIZONTAL, + USER_IFACE_ACT_MEAN_VERTICAL, + USER_IFACE_ACT_MEDIAN_HORIZONTAL, + USER_IFACE_ACT_MEDIAN_VERTICAL, + + USER_IFACE_ACT_CV = 0x000100u, + USER_IFACE_ACT_PIXEL_GET, + USER_IFACE_ACT_PIXEL_SET, + USER_IFACE_ACT_SET_ROI, + USER_IFACE_ACT_SET_ROI_2RECT, + USER_IFACE_ACT_AND_2REF, + USER_IFACE_ACT_NOT, + USER_IFACE_ACT_OR_2REF, + USER_IFACE_ACT_COMPONENT, + USER_IFACE_ACT_DILATE, + USER_IFACE_ACT_ERODE, + USER_IFACE_ACT_DILATE_ERODE, + USER_IFACE_ACT_ERODE_DILATE, + USER_IFACE_ACT_SMOOTH, + USER_IFACE_ACT_SOBEL, + USER_IFACE_ACT_BORDER, + USER_IFACE_ACT_MIRROR, + USER_IFACE_ACT_ROTATE_ORTO, + USER_IFACE_ACT_ROTATE, + USER_IFACE_ACT_ROTATE_2RECT, + USER_IFACE_ACT_ADAPTIVE_THRESHOLD, + USER_IFACE_ACT_CVT_COLOR, + USER_IFACE_ACT_DISTANCE_TRANSFORM, + USER_IFACE_ACT_THRESHOLD, + USER_IFACE_ACT_HISTOGRAM, + USER_IFACE_ACT_HISTOGRAM_C3, + USER_IFACE_ACT_CONTOURS, + USER_IFACE_ACT_CONTOURS_SIZE, + USER_IFACE_ACT_BOUNDING_RECT, + USER_IFACE_ACT_FIT_ELLIPSE, + USER_IFACE_ACT_MIN_AREA_RECT, + USER_IFACE_ACT_HOUGH_CIRCLES, + + USER_IFACE_ACT_ORB = 0x000200u, + USER_IFACE_ACT_ALIGN, + + USER_IFACE_ACT_CALIB3D = 0x000400u, + USER_IFACE_ACT_CALIBRATE, + USER_IFACE_ACT_UNDISTORT, + + USER_IFACE_ACT_ZB = 0x000800u, + USER_IFACE_ACT_DECODE, + + USER_IFACE_ACT_OCR = 0x001000u, + USER_IFACE_ACT_READ, + + USER_IFACE_ACT_IMGI = 0x002000u, + USER_IFACE_ACT_APPLY, + USER_IFACE_ACT_DISCARD, + USER_IFACE_ACT_SAVE_MEM, + USER_IFACE_ACT_LOAD_MEM, + USER_IFACE_ACT_SAVE_REF, + + USER_IFACE_ACT_SAVE = 0x004000u, + USER_IFACE_ACT_SAVE_FILE, + USER_IFACE_ACT_SAVE_UPDT, + + USER_IFACE_ACT_PROC = 0x008000u, + USER_IFACE_ACT_PROC_LABEL_SERIES, + USER_IFACE_ACT_PROC_LABEL_CALIB, + USER_IFACE_ACT_PROC_OBJECTS_SERIES, + USER_IFACE_ACT_PROC_OBJECTS_CALIB, + USER_IFACE_ACT_PROC_COINS_SERIES, + USER_IFACE_ACT_PROC_COINS_CALIB, + USER_IFACE_ACT_PROC_RESISTOR_SERIES, + USER_IFACE_ACT_PROC_RESISTOR_CALIB, + + USER_IFACE_ACT_USRI = 0x010000u, + USER_IFACE_ACT_SHOW_OCR, + USER_IFACE_ACT_QUIT + }; + + +/****************************************************************************** + ******* structs ************************************************************** + ******************************************************************************/ + struct User_Iface_Log { + int len; + char line [LOG_LEN] [LOG_LINE_LEN]; + int lvl [LOG_LEN]; + int visible; + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern int user_iface_mode; + extern struct User_Iface_Log user_iface_log; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void user_iface_init (void); + void user_iface_cleanup (void); + void user_iface (void); + void user_iface_show_log (const char *title, const char *subtitle); + void user_iface_fname (const char *filepath, char *filename); + double user_iface_getdbl (double m, double def, double M, + const char *title, const char *help); + int64_t user_iface_getint (double m, int64_t def, double M, + const char *title, const char *help); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* user_iface.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/user/inc/user_iface.hpp b/modules/user/inc/user_iface.hpp index c127d93..134f5dd 100644 --- a/modules/user/inc/user_iface.hpp +++ b/modules/user/inc/user_iface.hpp @@ -1,175 +1,175 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_USER_IFACE_HPP - # define VA_USER_IFACE_HPP - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define LOG_LEN (1048576) - # define LOG_LINE_LEN (80) - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* intX_t */ - #include - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Player_Iface_Mode { - USER_IFACE_FOO, - USER_IFACE_CLUI, - USER_IFACE_TUI - }; - - enum Player_Iface_Action { - USER_IFACE_ACT_FOO = 0x000000u, - - USER_IFACE_ACT_ALX = 0x000010u, - USER_IFACE_ACT_LOCAL_MAX, - USER_IFACE_ACT_SKELETON, - USER_IFACE_ACT_LINES_HORIZONTAL, - USER_IFACE_ACT_LINES_VERTICAL, - USER_IFACE_ACT_MEAN_HORIZONTAL, - USER_IFACE_ACT_MEAN_VERTICAL, - USER_IFACE_ACT_MEDIAN_HORIZONTAL, - USER_IFACE_ACT_MEDIAN_VERTICAL, - - USER_IFACE_ACT_CV = 0x000100u, - USER_IFACE_ACT_PIXEL_GET, - USER_IFACE_ACT_PIXEL_SET, - USER_IFACE_ACT_SET_ROI, - USER_IFACE_ACT_SET_ROI_2RECT, - USER_IFACE_ACT_AND_2REF, - USER_IFACE_ACT_NOT, - USER_IFACE_ACT_OR_2REF, - USER_IFACE_ACT_COMPONENT, - USER_IFACE_ACT_DILATE, - USER_IFACE_ACT_ERODE, - USER_IFACE_ACT_DILATE_ERODE, - USER_IFACE_ACT_ERODE_DILATE, - USER_IFACE_ACT_SMOOTH, - USER_IFACE_ACT_SOBEL, - USER_IFACE_ACT_BORDER, - USER_IFACE_ACT_MIRROR, - USER_IFACE_ACT_ROTATE_ORTO, - USER_IFACE_ACT_ROTATE, - USER_IFACE_ACT_ROTATE_2RECT, - USER_IFACE_ACT_ADAPTIVE_THRESHOLD, - USER_IFACE_ACT_CVT_COLOR, - USER_IFACE_ACT_DISTANCE_TRANSFORM, - USER_IFACE_ACT_THRESHOLD, - USER_IFACE_ACT_HISTOGRAM, - USER_IFACE_ACT_HISTOGRAM_C3, - USER_IFACE_ACT_CONTOURS, - USER_IFACE_ACT_CONTOURS_SIZE, - USER_IFACE_ACT_BOUNDING_RECT, - USER_IFACE_ACT_FIT_ELLIPSE, - USER_IFACE_ACT_MIN_AREA_RECT, - USER_IFACE_ACT_HOUGH_CIRCLES, - - USER_IFACE_ACT_ORB = 0x000200u, - USER_IFACE_ACT_ALIGN, - - USER_IFACE_ACT_CALIB3D = 0x000400u, - USER_IFACE_ACT_CALIBRATE, - USER_IFACE_ACT_UNDISTORT, - - USER_IFACE_ACT_ZB = 0x000800u, - USER_IFACE_ACT_DECODE, - - USER_IFACE_ACT_OCR = 0x001000u, - USER_IFACE_ACT_READ, - - USER_IFACE_ACT_IMGI = 0x002000u, - USER_IFACE_ACT_APPLY, - USER_IFACE_ACT_DISCARD, - USER_IFACE_ACT_SAVE_MEM, - USER_IFACE_ACT_LOAD_MEM, - USER_IFACE_ACT_SAVE_REF, - - USER_IFACE_ACT_SAVE = 0x004000u, - USER_IFACE_ACT_SAVE_FILE, - USER_IFACE_ACT_SAVE_UPDT, - - USER_IFACE_ACT_PROC = 0x008000u, - USER_IFACE_ACT_PROC_LABEL_SERIES, - USER_IFACE_ACT_PROC_LABEL_CALIB, - USER_IFACE_ACT_PROC_OBJECTS_SERIES, - USER_IFACE_ACT_PROC_OBJECTS_CALIB, - USER_IFACE_ACT_PROC_COINS_SERIES, - USER_IFACE_ACT_PROC_COINS_CALIB, - USER_IFACE_ACT_PROC_RESISTOR_SERIES, - USER_IFACE_ACT_PROC_RESISTOR_CALIB, - - USER_IFACE_ACT_USRI = 0x010000u, - USER_IFACE_ACT_SHOW_OCR, - USER_IFACE_ACT_QUIT - }; - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ - struct User_Iface_Log { - int len; - char line [LOG_LEN] [LOG_LINE_LEN]; - int lvl [LOG_LEN]; - int visible; - }; - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - extern int user_iface_mode; - extern struct User_Iface_Log user_iface_log; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void user_iface_init (void); - void user_iface_cleanup (void); - void user_iface (void); - void user_iface_show_log (const char *title, const char *subtitle); - void user_iface_fname (const char *filepath, char *filename); - double user_iface_getdbl (double m, double def, double M, - const char *title, const char *help); - int64_t user_iface_getint (double m, int64_t def, double M, - const char *title, const char *help); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* user_iface.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_USER_IFACE_HPP + # define VA_USER_IFACE_HPP + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define LOG_LEN (1048576) + # define LOG_LINE_LEN (80) + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* intX_t */ + #include + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Player_Iface_Mode { + USER_IFACE_FOO, + USER_IFACE_CLUI, + USER_IFACE_TUI + }; + + enum Player_Iface_Action { + USER_IFACE_ACT_FOO = 0x000000u, + + USER_IFACE_ACT_ALX = 0x000010u, + USER_IFACE_ACT_LOCAL_MAX, + USER_IFACE_ACT_SKELETON, + USER_IFACE_ACT_LINES_HORIZONTAL, + USER_IFACE_ACT_LINES_VERTICAL, + USER_IFACE_ACT_MEAN_HORIZONTAL, + USER_IFACE_ACT_MEAN_VERTICAL, + USER_IFACE_ACT_MEDIAN_HORIZONTAL, + USER_IFACE_ACT_MEDIAN_VERTICAL, + + USER_IFACE_ACT_CV = 0x000100u, + USER_IFACE_ACT_PIXEL_GET, + USER_IFACE_ACT_PIXEL_SET, + USER_IFACE_ACT_SET_ROI, + USER_IFACE_ACT_SET_ROI_2RECT, + USER_IFACE_ACT_AND_2REF, + USER_IFACE_ACT_NOT, + USER_IFACE_ACT_OR_2REF, + USER_IFACE_ACT_COMPONENT, + USER_IFACE_ACT_DILATE, + USER_IFACE_ACT_ERODE, + USER_IFACE_ACT_DILATE_ERODE, + USER_IFACE_ACT_ERODE_DILATE, + USER_IFACE_ACT_SMOOTH, + USER_IFACE_ACT_SOBEL, + USER_IFACE_ACT_BORDER, + USER_IFACE_ACT_MIRROR, + USER_IFACE_ACT_ROTATE_ORTO, + USER_IFACE_ACT_ROTATE, + USER_IFACE_ACT_ROTATE_2RECT, + USER_IFACE_ACT_ADAPTIVE_THRESHOLD, + USER_IFACE_ACT_CVT_COLOR, + USER_IFACE_ACT_DISTANCE_TRANSFORM, + USER_IFACE_ACT_THRESHOLD, + USER_IFACE_ACT_HISTOGRAM, + USER_IFACE_ACT_HISTOGRAM_C3, + USER_IFACE_ACT_CONTOURS, + USER_IFACE_ACT_CONTOURS_SIZE, + USER_IFACE_ACT_BOUNDING_RECT, + USER_IFACE_ACT_FIT_ELLIPSE, + USER_IFACE_ACT_MIN_AREA_RECT, + USER_IFACE_ACT_HOUGH_CIRCLES, + + USER_IFACE_ACT_ORB = 0x000200u, + USER_IFACE_ACT_ALIGN, + + USER_IFACE_ACT_CALIB3D = 0x000400u, + USER_IFACE_ACT_CALIBRATE, + USER_IFACE_ACT_UNDISTORT, + + USER_IFACE_ACT_ZB = 0x000800u, + USER_IFACE_ACT_DECODE, + + USER_IFACE_ACT_OCR = 0x001000u, + USER_IFACE_ACT_READ, + + USER_IFACE_ACT_IMGI = 0x002000u, + USER_IFACE_ACT_APPLY, + USER_IFACE_ACT_DISCARD, + USER_IFACE_ACT_SAVE_MEM, + USER_IFACE_ACT_LOAD_MEM, + USER_IFACE_ACT_SAVE_REF, + + USER_IFACE_ACT_SAVE = 0x004000u, + USER_IFACE_ACT_SAVE_FILE, + USER_IFACE_ACT_SAVE_UPDT, + + USER_IFACE_ACT_PROC = 0x008000u, + USER_IFACE_ACT_PROC_LABEL_SERIES, + USER_IFACE_ACT_PROC_LABEL_CALIB, + USER_IFACE_ACT_PROC_OBJECTS_SERIES, + USER_IFACE_ACT_PROC_OBJECTS_CALIB, + USER_IFACE_ACT_PROC_COINS_SERIES, + USER_IFACE_ACT_PROC_COINS_CALIB, + USER_IFACE_ACT_PROC_RESISTOR_SERIES, + USER_IFACE_ACT_PROC_RESISTOR_CALIB, + + USER_IFACE_ACT_USRI = 0x010000u, + USER_IFACE_ACT_SHOW_OCR, + USER_IFACE_ACT_QUIT + }; + + +/****************************************************************************** + ******* structs ************************************************************** + ******************************************************************************/ + struct User_Iface_Log { + int len; + char line [LOG_LEN] [LOG_LINE_LEN]; + int lvl [LOG_LEN]; + int visible; + }; + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern int user_iface_mode; + extern struct User_Iface_Log user_iface_log; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void user_iface_init (void); + void user_iface_cleanup (void); + void user_iface (void); + void user_iface_show_log (const char *title, const char *subtitle); + void user_iface_fname (const char *filepath, char *filename); + double user_iface_getdbl (double m, double def, double M, + const char *title, const char *help); + int64_t user_iface_getint (double m, int64_t def, double M, + const char *title, const char *help); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* user_iface.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/user/inc/user_tui.h b/modules/user/inc/user_tui.h index d8f9a3c..c9c027c 100644 --- a/modules/user/inc/user_tui.h +++ b/modules/user/inc/user_tui.h @@ -1,36 +1,36 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_USER_TUI_H - # define VA_USER_TUI_H - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void user_tui_init (void); -void user_tui_cleanup (void); -int user_tui (const char *title, const char *subtitle); -void user_tui_show_log (const char *title, const char *subtitle); -void user_tui_fname (const char *filepath, char *filename); -double user_tui_getdbl (double m, double def, double M, - const char *title, const char *help); -int64_t user_tui_getint (double m, int64_t def, double M, - const char *title, const char *help); -void user_tui_show_ocr (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* user_tui.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_USER_TUI_H + # define VA_USER_TUI_H + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void user_tui_init (void); +void user_tui_cleanup (void); +int user_tui (const char *title, const char *subtitle); +void user_tui_show_log (const char *title, const char *subtitle); +void user_tui_fname (const char *filepath, char *filename); +double user_tui_getdbl (double m, double def, double M, + const char *title, const char *help); +int64_t user_tui_getint (double m, int64_t def, double M, + const char *title, const char *help); +void user_tui_show_ocr (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* user_tui.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/user/src/user_clui.c b/modules/user/src/user_clui.c index 9a4405a..0799df3 100644 --- a/modules/user/src/user_clui.c +++ b/modules/user/src/user_clui.c @@ -1,622 +1,622 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* printf() & fgets() & sscanf() */ - #include - -/* Project -------------------------------------------------------------------*/ - /*img_ocr_text */ - #include "img_iface.h" - -/* libalx --------------------------------------------------------------------*/ - /* alx_sscan_fname() */ - #include "alx_input.h" - -/* Module --------------------------------------------------------------------*/ - /* user_iface_log */ - #include "user_iface.h" - - #include "user_clui.h" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define BUFF_SIZE (1024) - - -/****************************************************************************** - ******* static variables ***************************************************** - ******************************************************************************/ -static int log_pos; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ - /* Log */ -static void log_loop (void); - /* Input */ -static int usr_input (void); - /* Help */ -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; - - /* User action */ - show_help(); - user_clui_show_log(title, subtitle); - action = usr_input(); - - return action; -} - -void user_clui_fname (const char *filepath, char *filename) -{ - puts("File name:"); - puts("Valid extensions: .bmp .dib .jpeg .png .pbm .pgm .ppm .tiff"); - fgets(filename, FILENAME_MAX, stdin); - alx_sscan_fname(filepath, filename, false, filename); -} - -void user_clui_show_log (const char *title, const char *subtitle) -{ - puts("________________________________________________________________________________"); - - /* Board */ - log_loop(); - - /* Subtitle & title */ - printf("%s - %s\n", subtitle, title); - puts("--------------------------------------------------------------------------------"); - -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -/* Log -----------------------------------------------------------------------*/ -static void log_loop (void) -{ - int lvl; - - putchar('\n'); - 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[log_pos]); - } - } - putchar('\n'); -} - -/* Input ---------------------------------------------------------------------*/ -static int usr_input (void) -{ - int action; - - char buff [BUFF_SIZE]; - char ch [10]; - - int i; - for (i = 0; i < 10; i++) { - ch[i] = '\0'; - } - buff[0] = '\0'; - - /* Wait for input */ - fgets(buff, BUFF_SIZE, stdin); - - /* Interpret input */ - sscanf(buff, " %c%c%c%c%c", &ch[0], &ch[1], &ch[2], &ch[3], &ch[4]); - switch (ch[0]) { - case '+': - action = USER_IFACE_ACT_APPLY; - break; - - case '-': - action = USER_IFACE_ACT_DISCARD; - break; - - case 'e': - /* Exercises from class */ - switch (ch[1]) { - case '1': - /* Label */ - switch (ch[2]) { - case '1': - action = USER_IFACE_ACT_PROC_LABEL_SERIES; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '2': - /* Objects */ - switch (ch[2]) { - case '0': - action = USER_IFACE_ACT_PROC_OBJECTS_CALIB; - break; - case '1': - action = USER_IFACE_ACT_PROC_OBJECTS_SERIES; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '3': - /* Coins */ - switch (ch[2]) { - case '1': - action = USER_IFACE_ACT_PROC_COINS_SERIES; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '4': - /* Resistor */ - switch (ch[2]) { - case '1': - action = USER_IFACE_ACT_PROC_RESISTOR_SERIES; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - - case 'f': - /* Use simple funtions */ - switch (ch[1]) { - case '0': - /* img_alx */ - switch (ch[2]) { - case '0': - /* Distance transform postprocessing */ - switch (ch[3]) { - case '0': - action = USER_IFACE_ACT_LOCAL_MAX; - break; - case '1': - action = USER_IFACE_ACT_SKELETON; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '1': - /* Lines */ - switch (ch[3]) { - case '0': - action = USER_IFACE_ACT_LINES_HORIZONTAL; - break; - case '1': - action = USER_IFACE_ACT_LINES_VERTICAL; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '2': - /* Smooth */ - switch (ch[3]) { - case '0': - action = USER_IFACE_ACT_MEAN_HORIZONTAL; - break; - case '1': - action = USER_IFACE_ACT_MEAN_VERTICAL; - break; - case '2': - action = USER_IFACE_ACT_MEDIAN_HORIZONTAL; - break; - case '3': - action = USER_IFACE_ACT_MEDIAN_VERTICAL; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '1': - /* img_cv */ - switch (ch[2]) { - case '0': - /* Core: The core functionality */ - switch (ch[3]) { - case '0': - /* Pixel */ - switch (ch[4]) { - case '0': - action = USER_IFACE_ACT_PIXEL_GET; - break; - case '1': - action = USER_IFACE_ACT_PIXEL_SET; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '1': - /* ROI */ - switch (ch[4]) { - case '0': - action = USER_IFACE_ACT_SET_ROI; - break; - case '1': - action = USER_IFACE_ACT_SET_ROI_2RECT; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '2': - /* Operations on Arrays */ - switch (ch[4]) { - case '0': - action = USER_IFACE_ACT_AND_2REF; - break; - case '1': - action = USER_IFACE_ACT_NOT; - break; - case '2': - action = USER_IFACE_ACT_OR_2REF; - break; - case '3': - action = USER_IFACE_ACT_COMPONENT; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '1': - /* Imgproc: Image processing */ - switch (ch[3]) { - case '0': - /* Image filtering */ - switch (ch[4]) { - case '0': - action = USER_IFACE_ACT_DILATE; - break; - case '1': - action = USER_IFACE_ACT_ERODE; - break; - case '2': - action = USER_IFACE_ACT_DILATE_ERODE; - break; - case '3': - action = USER_IFACE_ACT_ERODE_DILATE; - break; - case '4': - action = USER_IFACE_ACT_SMOOTH; - break; - case '5': - action = USER_IFACE_ACT_SOBEL; - break; - case '6': - action = USER_IFACE_ACT_BORDER; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '1': - /* Geometric image transformations */ - switch (ch[4]) { - case '0': - action = USER_IFACE_ACT_MIRROR; - break; - case '1': - action = USER_IFACE_ACT_ROTATE_ORTO; - break; - case '2': - action = USER_IFACE_ACT_ROTATE; - break; - case '3': - action = USER_IFACE_ACT_ROTATE_2RECT; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '2': - /* Miscellaneous image transformations */ - switch (ch[4]) { - case '0': - action = USER_IFACE_ACT_ADAPTIVE_THRESHOLD; - break; - case '1': - action = USER_IFACE_ACT_CVT_COLOR; - break; - case '2': - action = USER_IFACE_ACT_DISTANCE_TRANSFORM; - break; - case '3': - action = USER_IFACE_ACT_THRESHOLD; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '3': - /* Histograms */ - switch (ch[4]) { - case '0': - action = USER_IFACE_ACT_HISTOGRAM; - break; - case '1': - action = USER_IFACE_ACT_HISTOGRAM_C3; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '4': - /* Structural analysis and shape descriptors */ - switch (ch[4]) { - case '0': - action = USER_IFACE_ACT_CONTOURS; - break; - case '1': - action = USER_IFACE_ACT_CONTOURS_SIZE; - break; - case '2': - action = USER_IFACE_ACT_BOUNDING_RECT; - break; - case '3': - action = USER_IFACE_ACT_FIT_ELLIPSE; - break; - case '4': - action = USER_IFACE_ACT_MIN_AREA_RECT; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '5': - /* Feature detection */ - switch (ch[4]) { - case '0': - action = USER_IFACE_ACT_HOUGH_CIRCLES; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '2': - /* img_orb */ - switch (ch[2]) { - case '0': - action = USER_IFACE_ACT_ALIGN; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '3': - /* img_calib3d */ - switch (ch[2]) { - case '0': - action = USER_IFACE_ACT_CALIBRATE; - break; - case '1': - action = USER_IFACE_ACT_UNDISTORT; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '4': - /* img_zbar */ - switch (ch[2]) { - case '0': - action = USER_IFACE_ACT_DECODE; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '5': - /* img_ocr */ - switch (ch[2]) { - case '0': - action = USER_IFACE_ACT_READ; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - - case 'l': - action = USER_IFACE_ACT_LOAD_MEM; - break; - - case 'm': - action = USER_IFACE_ACT_SAVE_MEM; - break; - - case 'q': - action = USER_IFACE_ACT_QUIT; - break; - - case 'r': - action = USER_IFACE_ACT_SAVE_REF; - break; - - case 's': - action = USER_IFACE_ACT_SAVE_FILE; - break; - - case 'u': - /* User iface actions */ - switch (ch[1]) { - case '1': - action = USER_IFACE_ACT_SHOW_OCR; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - - case 'x': - /* Special sequence "xyzzy" */ - if (ch[1] == 'y') { - if (ch[2] == 'z') { - if (ch[3] == 'z') { - if (ch[4] == 'y') { - action = USER_IFACE_ACT_FOO; - } - } - } - } - break; - - default: - action = USER_IFACE_ACT_FOO; - break; - } - - return action; -} - -/* * * * * * * * * * - * * * Help * * * * * * * - * * * * * * * * * */ -static void show_help (void) -{ - // FIXME - printf("Apply: %s\n", "Space"); - printf("Discard: %s\n", "Backspace"); - printf("Save to mem: %c\n", 'm'); - printf("Load from mem: %c\n", 'l'); - printf("Save to ref: %c\n", 'r'); - printf("Save to file: %c\n", 's'); - printf("Functions:\n"); - printf(" - Local maxima: %s\n", "f000"); - printf(" - Skeleton: %s\n", "f001"); - printf(" - Horizontal lines: %s\n", "f010"); - printf(" - Vertical lines: %s\n", "f011"); - printf(" - Horizontal mean: %s\n", "f020"); - printf(" - Vertical mean: %s\n", "f021"); - printf(" - Horizontal median: %s\n", "f022"); - printf(" - Vertical median: %s\n", "f023"); - printf(" - Pixel get: %s\n", "f1000"); - printf(" - Pixel set: %s\n", "f1001"); - printf(" - Set ROI: %s\n", "f1010"); - printf(" - Set ROI 2rect: %s\n", "f1011"); - printf(" - Bitwise AND 2ref: %s\n", "f1020"); - printf(" - Bitwise NOT: %s\n", "f1021"); - printf(" - Bitwise OR 2ref: %s\n", "f1022"); - printf(" - Component: %s\n", "f1023"); - printf(" - Dilate: %s\n", "f1100"); - printf(" - Erode: %s\n", "f1101"); - printf(" - D-E: %s\n", "f1102"); - printf(" - E-D: %s\n", "f1103"); - printf(" - Smooth: %s\n", "f1104"); - printf(" - Sobel: %s\n", "f1105"); - printf(" - Border: %s\n", "f1106"); - printf(" - Mirror: %s\n", "f1110"); - printf(" - Rotate ortogonally: %s\n", "f1111"); - printf(" - Rotate: %s\n", "f1112"); - printf(" - Rotate 2rect_rot: %s\n", "f1113"); - printf(" - Adaptive threshold: %s\n", "f1120"); - printf(" - Cvt color: %s\n", "f1121"); - printf(" - Distance transform: %s\n", "f1122"); - printf(" - Threshold: %s\n", "f1123"); - printf(" - Histogram: %s\n", "f1130"); - printf(" - Histogram (3 chan): %s\n", "f1131"); - printf(" - Contours: %s\n", "f1140"); - printf(" - Contours size: %s\n", "f1141"); - printf(" - Bounding rectangle: %s\n", "f1142"); - printf(" - Fit ellipse: %s\n", "f1143"); - printf(" - Min. area rectangle: %s\n", "f1144"); - printf(" - Hough circles: %s\n", "f1150"); - printf(" - Align 2ref (ORB): %s\n", "f20"); - printf(" - Calibrate (Calib3d): %s\n", "f30"); - printf(" - Undistort (Calib3d): %s\n", "f31"); - printf(" - Scan codes (ZBAR): %s\n", "f40"); - printf(" - Scan text (OCR): %s\n", "f50"); - printf("Exercises:\n"); - printf(" - Label: %s\n", "e11"); - printf(" - Objects (calib): %s\n", "e20"); - printf(" - Objects: %s\n", "e21"); - printf(" - Coins: %s\n", "e31"); - printf(" - Resistor: %s\n", "e41"); - printf("Other:\n"); - printf(" - Show OCR text: %s\n", "u1"); - printf("Quit: %c\n", 'q'); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* printf() & fgets() & sscanf() */ + #include + +/* Project -------------------------------------------------------------------*/ + /*img_ocr_text */ + #include "img_iface.h" + +/* libalx --------------------------------------------------------------------*/ + /* alx_sscan_fname() */ + #include "alx_input.h" + +/* Module --------------------------------------------------------------------*/ + /* user_iface_log */ + #include "user_iface.h" + + #include "user_clui.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define BUFF_SIZE (1024) + + +/****************************************************************************** + ******* static variables ***************************************************** + ******************************************************************************/ +static int log_pos; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ + /* Log */ +static void log_loop (void); + /* Input */ +static int usr_input (void); + /* Help */ +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; + + /* User action */ + show_help(); + user_clui_show_log(title, subtitle); + action = usr_input(); + + return action; +} + +void user_clui_fname (const char *filepath, char *filename) +{ + puts("File name:"); + puts("Valid extensions: .bmp .dib .jpeg .png .pbm .pgm .ppm .tiff"); + fgets(filename, FILENAME_MAX, stdin); + alx_sscan_fname(filepath, filename, false, filename); +} + +void user_clui_show_log (const char *title, const char *subtitle) +{ + puts("________________________________________________________________________________"); + + /* Board */ + log_loop(); + + /* Subtitle & title */ + printf("%s - %s\n", subtitle, title); + puts("--------------------------------------------------------------------------------"); + +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +/* Log -----------------------------------------------------------------------*/ +static void log_loop (void) +{ + int lvl; + + putchar('\n'); + 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[log_pos]); + } + } + putchar('\n'); +} + +/* Input ---------------------------------------------------------------------*/ +static int usr_input (void) +{ + int action; + + char buff [BUFF_SIZE]; + char ch [10]; + + int i; + for (i = 0; i < 10; i++) { + ch[i] = '\0'; + } + buff[0] = '\0'; + + /* Wait for input */ + fgets(buff, BUFF_SIZE, stdin); + + /* Interpret input */ + sscanf(buff, " %c%c%c%c%c", &ch[0], &ch[1], &ch[2], &ch[3], &ch[4]); + switch (ch[0]) { + case '+': + action = USER_IFACE_ACT_APPLY; + break; + + case '-': + action = USER_IFACE_ACT_DISCARD; + break; + + case 'e': + /* Exercises from class */ + switch (ch[1]) { + case '1': + /* Label */ + switch (ch[2]) { + case '1': + action = USER_IFACE_ACT_PROC_LABEL_SERIES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* Objects */ + switch (ch[2]) { + case '0': + action = USER_IFACE_ACT_PROC_OBJECTS_CALIB; + break; + case '1': + action = USER_IFACE_ACT_PROC_OBJECTS_SERIES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '3': + /* Coins */ + switch (ch[2]) { + case '1': + action = USER_IFACE_ACT_PROC_COINS_SERIES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '4': + /* Resistor */ + switch (ch[2]) { + case '1': + action = USER_IFACE_ACT_PROC_RESISTOR_SERIES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + + case 'f': + /* Use simple funtions */ + switch (ch[1]) { + case '0': + /* img_alx */ + switch (ch[2]) { + case '0': + /* Distance transform postprocessing */ + switch (ch[3]) { + case '0': + action = USER_IFACE_ACT_LOCAL_MAX; + break; + case '1': + action = USER_IFACE_ACT_SKELETON; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '1': + /* Lines */ + switch (ch[3]) { + case '0': + action = USER_IFACE_ACT_LINES_HORIZONTAL; + break; + case '1': + action = USER_IFACE_ACT_LINES_VERTICAL; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* Smooth */ + switch (ch[3]) { + case '0': + action = USER_IFACE_ACT_MEAN_HORIZONTAL; + break; + case '1': + action = USER_IFACE_ACT_MEAN_VERTICAL; + break; + case '2': + action = USER_IFACE_ACT_MEDIAN_HORIZONTAL; + break; + case '3': + action = USER_IFACE_ACT_MEDIAN_VERTICAL; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '1': + /* img_cv */ + switch (ch[2]) { + case '0': + /* Core: The core functionality */ + switch (ch[3]) { + case '0': + /* Pixel */ + switch (ch[4]) { + case '0': + action = USER_IFACE_ACT_PIXEL_GET; + break; + case '1': + action = USER_IFACE_ACT_PIXEL_SET; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '1': + /* ROI */ + switch (ch[4]) { + case '0': + action = USER_IFACE_ACT_SET_ROI; + break; + case '1': + action = USER_IFACE_ACT_SET_ROI_2RECT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* Operations on Arrays */ + switch (ch[4]) { + case '0': + action = USER_IFACE_ACT_AND_2REF; + break; + case '1': + action = USER_IFACE_ACT_NOT; + break; + case '2': + action = USER_IFACE_ACT_OR_2REF; + break; + case '3': + action = USER_IFACE_ACT_COMPONENT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '1': + /* Imgproc: Image processing */ + switch (ch[3]) { + case '0': + /* Image filtering */ + switch (ch[4]) { + case '0': + action = USER_IFACE_ACT_DILATE; + break; + case '1': + action = USER_IFACE_ACT_ERODE; + break; + case '2': + action = USER_IFACE_ACT_DILATE_ERODE; + break; + case '3': + action = USER_IFACE_ACT_ERODE_DILATE; + break; + case '4': + action = USER_IFACE_ACT_SMOOTH; + break; + case '5': + action = USER_IFACE_ACT_SOBEL; + break; + case '6': + action = USER_IFACE_ACT_BORDER; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '1': + /* Geometric image transformations */ + switch (ch[4]) { + case '0': + action = USER_IFACE_ACT_MIRROR; + break; + case '1': + action = USER_IFACE_ACT_ROTATE_ORTO; + break; + case '2': + action = USER_IFACE_ACT_ROTATE; + break; + case '3': + action = USER_IFACE_ACT_ROTATE_2RECT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* Miscellaneous image transformations */ + switch (ch[4]) { + case '0': + action = USER_IFACE_ACT_ADAPTIVE_THRESHOLD; + break; + case '1': + action = USER_IFACE_ACT_CVT_COLOR; + break; + case '2': + action = USER_IFACE_ACT_DISTANCE_TRANSFORM; + break; + case '3': + action = USER_IFACE_ACT_THRESHOLD; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '3': + /* Histograms */ + switch (ch[4]) { + case '0': + action = USER_IFACE_ACT_HISTOGRAM; + break; + case '1': + action = USER_IFACE_ACT_HISTOGRAM_C3; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '4': + /* Structural analysis and shape descriptors */ + switch (ch[4]) { + case '0': + action = USER_IFACE_ACT_CONTOURS; + break; + case '1': + action = USER_IFACE_ACT_CONTOURS_SIZE; + break; + case '2': + action = USER_IFACE_ACT_BOUNDING_RECT; + break; + case '3': + action = USER_IFACE_ACT_FIT_ELLIPSE; + break; + case '4': + action = USER_IFACE_ACT_MIN_AREA_RECT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '5': + /* Feature detection */ + switch (ch[4]) { + case '0': + action = USER_IFACE_ACT_HOUGH_CIRCLES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* img_orb */ + switch (ch[2]) { + case '0': + action = USER_IFACE_ACT_ALIGN; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '3': + /* img_calib3d */ + switch (ch[2]) { + case '0': + action = USER_IFACE_ACT_CALIBRATE; + break; + case '1': + action = USER_IFACE_ACT_UNDISTORT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '4': + /* img_zbar */ + switch (ch[2]) { + case '0': + action = USER_IFACE_ACT_DECODE; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '5': + /* img_ocr */ + switch (ch[2]) { + case '0': + action = USER_IFACE_ACT_READ; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + + case 'l': + action = USER_IFACE_ACT_LOAD_MEM; + break; + + case 'm': + action = USER_IFACE_ACT_SAVE_MEM; + break; + + case 'q': + action = USER_IFACE_ACT_QUIT; + break; + + case 'r': + action = USER_IFACE_ACT_SAVE_REF; + break; + + case 's': + action = USER_IFACE_ACT_SAVE_FILE; + break; + + case 'u': + /* User iface actions */ + switch (ch[1]) { + case '1': + action = USER_IFACE_ACT_SHOW_OCR; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + + case 'x': + /* Special sequence "xyzzy" */ + if (ch[1] == 'y') { + if (ch[2] == 'z') { + if (ch[3] == 'z') { + if (ch[4] == 'y') { + action = USER_IFACE_ACT_FOO; + } + } + } + } + break; + + default: + action = USER_IFACE_ACT_FOO; + break; + } + + return action; +} + +/* * * * * * * * * * + * * * Help * * * * * * * + * * * * * * * * * */ +static void show_help (void) +{ + // FIXME + printf("Apply: %s\n", "Space"); + printf("Discard: %s\n", "Backspace"); + printf("Save to mem: %c\n", 'm'); + printf("Load from mem: %c\n", 'l'); + printf("Save to ref: %c\n", 'r'); + printf("Save to file: %c\n", 's'); + printf("Functions:\n"); + printf(" - Local maxima: %s\n", "f000"); + printf(" - Skeleton: %s\n", "f001"); + printf(" - Horizontal lines: %s\n", "f010"); + printf(" - Vertical lines: %s\n", "f011"); + printf(" - Horizontal mean: %s\n", "f020"); + printf(" - Vertical mean: %s\n", "f021"); + printf(" - Horizontal median: %s\n", "f022"); + printf(" - Vertical median: %s\n", "f023"); + printf(" - Pixel get: %s\n", "f1000"); + printf(" - Pixel set: %s\n", "f1001"); + printf(" - Set ROI: %s\n", "f1010"); + printf(" - Set ROI 2rect: %s\n", "f1011"); + printf(" - Bitwise AND 2ref: %s\n", "f1020"); + printf(" - Bitwise NOT: %s\n", "f1021"); + printf(" - Bitwise OR 2ref: %s\n", "f1022"); + printf(" - Component: %s\n", "f1023"); + printf(" - Dilate: %s\n", "f1100"); + printf(" - Erode: %s\n", "f1101"); + printf(" - D-E: %s\n", "f1102"); + printf(" - E-D: %s\n", "f1103"); + printf(" - Smooth: %s\n", "f1104"); + printf(" - Sobel: %s\n", "f1105"); + printf(" - Border: %s\n", "f1106"); + printf(" - Mirror: %s\n", "f1110"); + printf(" - Rotate ortogonally: %s\n", "f1111"); + printf(" - Rotate: %s\n", "f1112"); + printf(" - Rotate 2rect_rot: %s\n", "f1113"); + printf(" - Adaptive threshold: %s\n", "f1120"); + printf(" - Cvt color: %s\n", "f1121"); + printf(" - Distance transform: %s\n", "f1122"); + printf(" - Threshold: %s\n", "f1123"); + printf(" - Histogram: %s\n", "f1130"); + printf(" - Histogram (3 chan): %s\n", "f1131"); + printf(" - Contours: %s\n", "f1140"); + printf(" - Contours size: %s\n", "f1141"); + printf(" - Bounding rectangle: %s\n", "f1142"); + printf(" - Fit ellipse: %s\n", "f1143"); + printf(" - Min. area rectangle: %s\n", "f1144"); + printf(" - Hough circles: %s\n", "f1150"); + printf(" - Align 2ref (ORB): %s\n", "f20"); + printf(" - Calibrate (Calib3d): %s\n", "f30"); + printf(" - Undistort (Calib3d): %s\n", "f31"); + printf(" - Scan codes (ZBAR): %s\n", "f40"); + printf(" - Scan text (OCR): %s\n", "f50"); + printf("Exercises:\n"); + printf(" - Label: %s\n", "e11"); + printf(" - Objects (calib): %s\n", "e20"); + printf(" - Objects: %s\n", "e21"); + printf(" - Coins: %s\n", "e31"); + printf(" - Resistor: %s\n", "e41"); + printf("Other:\n"); + printf(" - Show OCR text: %s\n", "u1"); + printf("Quit: %c\n", 'q'); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/user/src/user_iface.c b/modules/user/src/user_iface.c index 629dfd8..f465944 100644 --- a/modules/user/src/user_iface.c +++ b/modules/user/src/user_iface.c @@ -1,227 +1,227 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* intX_t */ - #include - /* snprintf() & fflush() */ - #include - -/* Project -------------------------------------------------------------------*/ - /* img_iface_act_nodata() */ - #include "img_iface.h" - /* proc_iface() */ - #include "proc_iface.h" - -/* Module --------------------------------------------------------------------*/ - /* user_clui() & ...save_name() */ - #include "user_clui.h" - /* user_tui() & ...init() & ...cleanup() & ...save_name() */ - #include "user_tui.h" - - #include "user_iface.h" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define TITLE_SIZE (20) - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -int user_iface_mode; -struct User_Iface_Log user_iface_log; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -void user_iface_act (int action); -void user_iface_show_ocr (void); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void user_iface_init (void) -{ - user_iface_log.len = 0; - - switch (user_iface_mode) { - case USER_IFACE_CLUI: - user_clui_init(); - break; - - case USER_IFACE_TUI: - user_tui_init(); - break; - } -} - -void user_iface_cleanup (void) -{ - switch (user_iface_mode) { - case USER_IFACE_CLUI: - break; - - case USER_IFACE_TUI: - user_tui_cleanup(); - break; - } - - fflush(stdout); -} - -void user_iface (void) -{ - char title[TITLE_SIZE]; - char subtitle[TITLE_SIZE]; - int user_action; - - snprintf(title, TITLE_SIZE, "Title"); - snprintf(subtitle, TITLE_SIZE, "Subtitle"); - - do { - /* Display image */ - img_iface_show_img(); - - /* Request user action */ - switch (user_iface_mode) { - case USER_IFACE_CLUI: - user_action = user_clui(title, subtitle); - break; - - case USER_IFACE_TUI: - user_action = user_tui(title, subtitle); - break; - - default: - user_action = USER_IFACE_ACT_FOO; - break; - } - - /* Do action */ - user_iface_act(user_action); - } while (user_action != USER_IFACE_ACT_QUIT); -} - -void user_iface_show_log (const char *title, const char *subtitle) -{ - switch (user_iface_mode) { - case USER_IFACE_CLUI: - user_clui_show_log(title, subtitle); - break; - - case USER_IFACE_TUI: - user_tui_show_log(title, subtitle); - break; - } -} - -void user_iface_fname (const char *filepath, char *filename) -{ - switch (user_iface_mode) { - case USER_IFACE_CLUI: - user_clui_fname(filepath, filename); - break; - - case USER_IFACE_TUI: - user_tui_fname(filepath, filename); - break; - } -} - -int64_t user_iface_getint (double m, int64_t def, double M, - const char *title, const char *help) -{ - int64_t i; - - switch (user_iface_mode) { - case USER_IFACE_CLUI: - // FIXME - i = 1; - break; - - case USER_IFACE_TUI: - i = user_tui_getint(m, def, M, title, help); - break; - - default: - i = 1; - break; - } - - return i; -} - -double user_iface_getdbl (double m, double def, double M, - const char *title, const char *help) -{ - int64_t i; - - switch (user_iface_mode) { - case USER_IFACE_CLUI: - // FIXME - i = 1; - break; - - case USER_IFACE_TUI: - i = user_tui_getdbl(m, def, M, title, help); - break; - - default: - i = 1; - break; - } - - return i; -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -void user_iface_act (int action) -{ - if (action & USER_IFACE_ACT_USRI) { - switch (action) { - case USER_IFACE_ACT_SHOW_OCR: - user_iface_show_ocr(); - break; - case USER_IFACE_ACT_QUIT: - /* do nothing */ - break; - } - - } else if (action & USER_IFACE_ACT_PROC) { - proc_iface_single(action); - - } else { - img_iface_act_nodata(action); - } -} - -void user_iface_show_ocr (void) -{ - switch (user_iface_mode) { - case USER_IFACE_CLUI: - // FIXME - break; - - case USER_IFACE_TUI: - user_tui_show_ocr(); - break; - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* intX_t */ + #include + /* snprintf() & fflush() */ + #include + +/* Project -------------------------------------------------------------------*/ + /* img_iface_act_nodata() */ + #include "img_iface.h" + /* proc_iface() */ + #include "proc_iface.h" + +/* Module --------------------------------------------------------------------*/ + /* user_clui() & ...save_name() */ + #include "user_clui.h" + /* user_tui() & ...init() & ...cleanup() & ...save_name() */ + #include "user_tui.h" + + #include "user_iface.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define TITLE_SIZE (20) + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +int user_iface_mode; +struct User_Iface_Log user_iface_log; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +void user_iface_act (int action); +void user_iface_show_ocr (void); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void user_iface_init (void) +{ + user_iface_log.len = 0; + + switch (user_iface_mode) { + case USER_IFACE_CLUI: + user_clui_init(); + break; + + case USER_IFACE_TUI: + user_tui_init(); + break; + } +} + +void user_iface_cleanup (void) +{ + switch (user_iface_mode) { + case USER_IFACE_CLUI: + break; + + case USER_IFACE_TUI: + user_tui_cleanup(); + break; + } + + fflush(stdout); +} + +void user_iface (void) +{ + char title[TITLE_SIZE]; + char subtitle[TITLE_SIZE]; + int user_action; + + snprintf(title, TITLE_SIZE, "Title"); + snprintf(subtitle, TITLE_SIZE, "Subtitle"); + + do { + /* Display image */ + img_iface_show_img(); + + /* Request user action */ + switch (user_iface_mode) { + case USER_IFACE_CLUI: + user_action = user_clui(title, subtitle); + break; + + case USER_IFACE_TUI: + user_action = user_tui(title, subtitle); + break; + + default: + user_action = USER_IFACE_ACT_FOO; + break; + } + + /* Do action */ + user_iface_act(user_action); + } while (user_action != USER_IFACE_ACT_QUIT); +} + +void user_iface_show_log (const char *title, const char *subtitle) +{ + switch (user_iface_mode) { + case USER_IFACE_CLUI: + user_clui_show_log(title, subtitle); + break; + + case USER_IFACE_TUI: + user_tui_show_log(title, subtitle); + break; + } +} + +void user_iface_fname (const char *filepath, char *filename) +{ + switch (user_iface_mode) { + case USER_IFACE_CLUI: + user_clui_fname(filepath, filename); + break; + + case USER_IFACE_TUI: + user_tui_fname(filepath, filename); + break; + } +} + +int64_t user_iface_getint (double m, int64_t def, double M, + const char *title, const char *help) +{ + int64_t i; + + switch (user_iface_mode) { + case USER_IFACE_CLUI: + // FIXME + i = 1; + break; + + case USER_IFACE_TUI: + i = user_tui_getint(m, def, M, title, help); + break; + + default: + i = 1; + break; + } + + return i; +} + +double user_iface_getdbl (double m, double def, double M, + const char *title, const char *help) +{ + int64_t i; + + switch (user_iface_mode) { + case USER_IFACE_CLUI: + // FIXME + i = 1; + break; + + case USER_IFACE_TUI: + i = user_tui_getdbl(m, def, M, title, help); + break; + + default: + i = 1; + break; + } + + return i; +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +void user_iface_act (int action) +{ + if (action & USER_IFACE_ACT_USRI) { + switch (action) { + case USER_IFACE_ACT_SHOW_OCR: + user_iface_show_ocr(); + break; + case USER_IFACE_ACT_QUIT: + /* do nothing */ + break; + } + + } else if (action & USER_IFACE_ACT_PROC) { + proc_iface_single(action); + + } else { + img_iface_act_nodata(action); + } +} + +void user_iface_show_ocr (void) +{ + switch (user_iface_mode) { + case USER_IFACE_CLUI: + // FIXME + break; + + case USER_IFACE_TUI: + user_tui_show_ocr(); + break; + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/user/src/user_tui.c b/modules/user/src/user_tui.c index 305e1d2..4c10dc6 100644 --- a/modules/user/src/user_tui.c +++ b/modules/user/src/user_tui.c @@ -1,771 +1,771 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include - /* WINDOW & wgetch() & KEY_... & ... */ - #include - -/* libalx --------------------------------------------------------------------*/ - /* alx_..._curses() & alx_ncur_prn_...() */ - #include "alx_ncur.h" - -/* Project -------------------------------------------------------------------*/ - /*img_ocr_text */ - #include "img_iface.h" - -/* Module --------------------------------------------------------------------*/ - /* user_iface_log */ - #include "user_iface.h" - - #include "user_tui.h" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -static WINDOW *win_log; -static WINDOW *win_help; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ - /* Log */ -static void log_loop (void); - /* Input */ -static int usr_input (void); - /* Help */ -static void show_help (void); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void user_tui_init (void) -{ - /* Use curses mode */ - alx_resume_curses(); - - /* Dimensions: log */ - const int h1 = 54; - const int w1 = 40; - const int r1 = 0; - const int c1 = 30; - win_log = newwin(h1, w1, r1, c1); - - /* Dimensions: help */ - const int h2 = 54; - const int w2 = 40; - const int r2 = 0; - const int c2 = 0; - win_help = newwin(h2, w2, r2, c2); - - /* Activate keypad, don't echo input */ - keypad(win_log, true); - noecho(); -} - -void user_tui_cleanup (void) -{ - /* Del wins & return to terminal mode */ - alx_win_del(win_log); - alx_win_del(win_help); - alx_pause_curses(); -} - -int user_tui (const char *title, const char *subtitle) -{ - int action; -// action = USER_IFACE_ACT_FOO; - - show_help(); - user_tui_show_log(title, subtitle); - action = usr_input(); - - return action; -} - -void user_tui_fname (const char *filepath, char *filename) -{ - /* Input box */ - int w; - int r; - w = 75; - r = 10; - - /* Request name */ - alx_w_getfname(filepath, filename, false, w, r, "File name:", - "Valid extensions: .bmp .dib .jpeg .png .pbm .pgm .ppm .tiff"); -} - -void user_tui_show_log (const char *title, const char *subtitle) -{ - /* Clear & box */ - werase(win_log); - box(win_log, 0, 0); - - /* Title */ - alx_ncur_prn_title(win_log, title); - /* Subtitle */ - alx_ncur_prn_subtitle(win_log, subtitle); - - /* Log */ - log_loop(); - - /* Refresh */ - wrefresh(win_log); -} - -double user_tui_getdbl (double m, double def, double M, - const char *title, const char *help) -{ - /* Input box */ - int w; - int r; - w = 75; - r = 10; - - /* Request int */ - double R; - R = alx_w_getdbl(w, r, title, m, def, M, help); - return R; -} - -int64_t user_tui_getint (double m, int64_t def, double M, - const char *title, const char *help) -{ - /* Input box */ - int w; - int r; - w = 75; - r = 10; - - /* Request int */ - int64_t i; - i = alx_w_getint(w, r, title, m, def, M, help); - return i; -} - -void user_tui_show_ocr (void) -{ - alx_pause_curses(); - - printf("%s", img_ocr_text); - getchar(); - - alx_resume_curses(); -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -/* Log -----------------------------------------------------------------------*/ -static void log_loop (void) -{ - int i; - int i_0; - int l; - int l_0; - - if (user_iface_log.len > 51) { - i_0 = user_iface_log.len - 51; - l_0 = 1; - mvwprintw(win_log, 1, 10, "..."); - } else { - i_0 = 0; - l_0 = 0; - } - - l = l_0; - for (i = i_0; i < user_iface_log.len; i++) { - if (user_iface_log.lvl[i] <= user_iface_log.visible) { - mvwprintw(win_log, (1 + l), - (1 + 4 * user_iface_log.lvl[i]), - "%.*s", - 40 - 2 - 4 * user_iface_log.lvl[i], - user_iface_log.line[i]); - l++; - } - } -} - -/* Input ---------------------------------------------------------------------*/ -static int usr_input (void) -{ - int action; - wchar_t ch; - - /* Interpret input */ - ch = wgetch(win_log); - switch (ch) { - case ' ': - action = USER_IFACE_ACT_APPLY; - break; - - /* ASCII 0x08 is BS */ - case KEY_BACKSPACE: - case 0x08: - action = USER_IFACE_ACT_DISCARD; - break; - - case 'e': - /* Exercises from class */ - ch = wgetch(win_log); - - switch (ch) { - case '1': - /* Label */ - ch = wgetch(win_log); - - switch (ch) { - case '1': - action = USER_IFACE_ACT_PROC_LABEL_SERIES; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '2': - /* Objects */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_PROC_OBJECTS_CALIB; - break; - case '1': - action = USER_IFACE_ACT_PROC_OBJECTS_SERIES; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '3': - /* Coins */ - ch = wgetch(win_log); - - switch (ch) { - case '1': - action = USER_IFACE_ACT_PROC_COINS_SERIES; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '4': - /* Resistor */ - ch = wgetch(win_log); - - switch (ch) { - case '1': - action = USER_IFACE_ACT_PROC_RESISTOR_SERIES; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - - case 'f': - /* Use simple funtions */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - /* img_alx */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - /* Distance transform postprocessing */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_LOCAL_MAX; - break; - case '1': - action = USER_IFACE_ACT_SKELETON; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '1': - /* Lines */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_LINES_HORIZONTAL; - break; - case '1': - action = USER_IFACE_ACT_LINES_VERTICAL; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '2': - /* Smooth */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_MEAN_HORIZONTAL; - break; - case '1': - action = USER_IFACE_ACT_MEAN_VERTICAL; - break; - case '2': - action = USER_IFACE_ACT_MEDIAN_HORIZONTAL; - break; - case '3': - action = USER_IFACE_ACT_MEDIAN_VERTICAL; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '1': - /* img_cv */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - /* Core: The core functionality */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - /* Pixel */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_PIXEL_GET; - break; - case '1': - action = USER_IFACE_ACT_PIXEL_SET; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '1': - /* ROI */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_SET_ROI; - break; - case '1': - action = USER_IFACE_ACT_SET_ROI_2RECT; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '2': - /* Operations on Arrays */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_AND_2REF; - break; - case '1': - action = USER_IFACE_ACT_NOT; - break; - case '2': - action = USER_IFACE_ACT_OR_2REF; - break; - case '3': - action = USER_IFACE_ACT_COMPONENT; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '1': - /* Imgproc: Image processing */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - /* Image filtering */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_DILATE; - break; - case '1': - action = USER_IFACE_ACT_ERODE; - break; - case '2': - action = USER_IFACE_ACT_DILATE_ERODE; - break; - case '3': - action = USER_IFACE_ACT_ERODE_DILATE; - break; - case '4': - action = USER_IFACE_ACT_SMOOTH; - break; - case '5': - action = USER_IFACE_ACT_SOBEL; - break; - case '6': - action = USER_IFACE_ACT_BORDER; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '1': - /* Geometric image transformations */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_MIRROR; - break; - case '1': - action = USER_IFACE_ACT_ROTATE_ORTO; - break; - case '2': - action = USER_IFACE_ACT_ROTATE; - break; - case '3': - action = USER_IFACE_ACT_ROTATE_2RECT; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '2': - /* Miscellaneous image transformations */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_ADAPTIVE_THRESHOLD; - break; - case '1': - action = USER_IFACE_ACT_CVT_COLOR; - break; - case '2': - action = USER_IFACE_ACT_DISTANCE_TRANSFORM; - break; - case '3': - action = USER_IFACE_ACT_THRESHOLD; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '3': - /* Histograms */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_HISTOGRAM; - break; - case '1': - action = USER_IFACE_ACT_HISTOGRAM_C3; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '4': - /* Structural analysis and shape descriptors */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_CONTOURS; - break; - case '1': - action = USER_IFACE_ACT_CONTOURS_SIZE; - break; - case '2': - action = USER_IFACE_ACT_BOUNDING_RECT; - break; - case '3': - action = USER_IFACE_ACT_FIT_ELLIPSE; - break; - case '4': - action = USER_IFACE_ACT_MIN_AREA_RECT; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '5': - /* Feature detection */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_HOUGH_CIRCLES; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '2': - /* img_orb */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_ALIGN; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '3': - /* img_calib3d */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_CALIBRATE; - break; - case '1': - action = USER_IFACE_ACT_UNDISTORT; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '4': - /* img_zbar */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_DECODE; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - case '5': - /* img_ocr */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_READ; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - - case 'l': - action = USER_IFACE_ACT_LOAD_MEM; - break; - - case 'm': - action = USER_IFACE_ACT_SAVE_MEM; - break; - - case 'q': - action = USER_IFACE_ACT_QUIT; - break; - - case 'r': - action = USER_IFACE_ACT_SAVE_REF; - break; - - case 's': - action = USER_IFACE_ACT_SAVE_FILE; - break; - - case 'u': - /* User iface actions */ - ch = wgetch(win_log); - - switch (ch) { - case '1': - action = USER_IFACE_ACT_SHOW_OCR; - break; - default: - action = USER_IFACE_ACT_FOO; - break; - } - break; - - case 'x': - action = USER_IFACE_ACT_FOO; - - /* Special sequence "xyzzy" */ - ch = wgetch(win_log); - if (ch == 'y') { - ch = wgetch(win_log); - if (ch == 'z') { - - ch = wgetch(win_log); - if (ch == 'z') { - - ch = wgetch(win_log); - if (ch == 'y') { - action = USER_IFACE_ACT_FOO; - } - } - } - } - break; - - default: - action = USER_IFACE_ACT_FOO; - break; - } - - return action; -} - -/* * * * * * * * * * - * * * Help * * * * * * * - * * * * * * * * * */ -static void show_help (void) -{ - /* Clear */ - werase(win_help); - - int r; - int c; - - r = 0; - c = 0; - mvwprintw(win_help, r++, c, "Apply: %s", "Space"); - mvwprintw(win_help, r++, c, "Discard: %s", "BS"); - mvwprintw(win_help, r++, c, "Save to mem: %c", 'm'); - mvwprintw(win_help, r++, c, "Load from mem: %c", 'l'); - 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, " - Local maxima: %s", "f000"); - mvwprintw(win_help, r++, c, " - Skeleton: %s", "f001"); - mvwprintw(win_help, r++, c, " - Horizontal lines: %s", "f010"); - mvwprintw(win_help, r++, c, " - Vertical lines: %s", "f011"); - mvwprintw(win_help, r++, c, " - Horizontal mean: %s", "f020"); - mvwprintw(win_help, r++, c, " - Vertical mean: %s", "f021"); - mvwprintw(win_help, r++, c, " - Horizontal median: %s", "f022"); - mvwprintw(win_help, r++, c, " - Vertical median: %s", "f023"); - mvwprintw(win_help, r++, c, " - Pixel get: %s", "f1000"); - mvwprintw(win_help, r++, c, " - Pixel set: %s", "f1001"); - mvwprintw(win_help, r++, c, " - Set ROI: %s", "f1010"); - mvwprintw(win_help, r++, c, " - Set ROI 2rect: %s", "f1011"); - mvwprintw(win_help, r++, c, " - Bitwise AND 2ref: %s", "f1020"); - mvwprintw(win_help, r++, c, " - Bitwise NOT: %s", "f1021"); - mvwprintw(win_help, r++, c, " - Bitwise OR 2ref: %s", "f1022"); - mvwprintw(win_help, r++, c, " - Component: %s", "f1023"); - mvwprintw(win_help, r++, c, " - Dilate: %s", "f1100"); - mvwprintw(win_help, r++, c, " - Erode: %s", "f1101"); - mvwprintw(win_help, r++, c, " - D-E: %s", "f1102"); - mvwprintw(win_help, r++, c, " - E-D: %s", "f1103"); - mvwprintw(win_help, r++, c, " - Smooth: %s", "f1104"); - mvwprintw(win_help, r++, c, " - Sobel: %s", "f1105"); - mvwprintw(win_help, r++, c, " - Border: %s", "f1106"); - mvwprintw(win_help, r++, c, " - Mirror: %s", "f1110"); - mvwprintw(win_help, r++, c, " - Rotate ortogonally: %s", "f1111"); - mvwprintw(win_help, r++, c, " - Rotate: %s", "f1112"); - mvwprintw(win_help, r++, c, " - Rotate 2rect_rot: %s", "f1113"); - mvwprintw(win_help, r++, c, " - Adaptive threshold: %s", "f1120"); - mvwprintw(win_help, r++, c, " - Cvt color: %s", "f1121"); - mvwprintw(win_help, r++, c, " - Distance transform: %s", "f1122"); - mvwprintw(win_help, r++, c, " - Threshold: %s", "f1123"); - mvwprintw(win_help, r++, c, " - Histogram: %s", "f1130"); - mvwprintw(win_help, r++, c, " - Histogram (3 chan): %s", "f1131"); - mvwprintw(win_help, r++, c, " - Contours: %s", "f1140"); - mvwprintw(win_help, r++, c, " - Contours size: %s", "f1141"); - mvwprintw(win_help, r++, c, " - Bounding rectangle: %s", "f1142"); - mvwprintw(win_help, r++, c, " - Fit ellipse: %s", "f1143"); - mvwprintw(win_help, r++, c, " - Min. area rectangle: %s", "f1144"); - mvwprintw(win_help, r++, c, " - Hough circles: %s", "f1150"); - mvwprintw(win_help, r++, c, " - Align 2ref (ORB): %s", "f20"); - mvwprintw(win_help, r++, c, " - Calibrate (Calib3d): %s", "f30"); - mvwprintw(win_help, r++, c, " - Undistort (Calib3d): %s", "f31"); - mvwprintw(win_help, r++, c, " - Scan codes (ZBAR): %s", "f40"); - mvwprintw(win_help, r++, c, " - Scan text (OCR): %s", "f50"); - mvwprintw(win_help, r++, c, "Exercises:"); - mvwprintw(win_help, r++, c, " - Label: %s", "e11"); - mvwprintw(win_help, r++, c, " - Objects (calib): %s", "e20"); - mvwprintw(win_help, r++, c, " - Objects: %s", "e21"); - mvwprintw(win_help, r++, c, " - Coins: %s", "e31"); - mvwprintw(win_help, r++, c, " - Resistor: %s", "e41"); - mvwprintw(win_help, r++, c, "Other:"); - mvwprintw(win_help, r++, c, " - Show OCR: %s", "u1"); - mvwprintw(win_help, r++, c, "Quit: %c", 'q'); - - /* Refresh */ - wrefresh(win_help); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + #include + /* WINDOW & wgetch() & KEY_... & ... */ + #include + +/* libalx --------------------------------------------------------------------*/ + /* alx_..._curses() & alx_ncur_prn_...() */ + #include "alx_ncur.h" + +/* Project -------------------------------------------------------------------*/ + /*img_ocr_text */ + #include "img_iface.h" + +/* Module --------------------------------------------------------------------*/ + /* user_iface_log */ + #include "user_iface.h" + + #include "user_tui.h" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +static WINDOW *win_log; +static WINDOW *win_help; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ + /* Log */ +static void log_loop (void); + /* Input */ +static int usr_input (void); + /* Help */ +static void show_help (void); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void user_tui_init (void) +{ + /* Use curses mode */ + alx_resume_curses(); + + /* Dimensions: log */ + const int h1 = 54; + const int w1 = 40; + const int r1 = 0; + const int c1 = 30; + win_log = newwin(h1, w1, r1, c1); + + /* Dimensions: help */ + const int h2 = 54; + const int w2 = 40; + const int r2 = 0; + const int c2 = 0; + win_help = newwin(h2, w2, r2, c2); + + /* Activate keypad, don't echo input */ + keypad(win_log, true); + noecho(); +} + +void user_tui_cleanup (void) +{ + /* Del wins & return to terminal mode */ + alx_win_del(win_log); + alx_win_del(win_help); + alx_pause_curses(); +} + +int user_tui (const char *title, const char *subtitle) +{ + int action; +// action = USER_IFACE_ACT_FOO; + + show_help(); + user_tui_show_log(title, subtitle); + action = usr_input(); + + return action; +} + +void user_tui_fname (const char *filepath, char *filename) +{ + /* Input box */ + int w; + int r; + w = 75; + r = 10; + + /* Request name */ + alx_w_getfname(filepath, filename, false, w, r, "File name:", + "Valid extensions: .bmp .dib .jpeg .png .pbm .pgm .ppm .tiff"); +} + +void user_tui_show_log (const char *title, const char *subtitle) +{ + /* Clear & box */ + werase(win_log); + box(win_log, 0, 0); + + /* Title */ + alx_ncur_prn_title(win_log, title); + /* Subtitle */ + alx_ncur_prn_subtitle(win_log, subtitle); + + /* Log */ + log_loop(); + + /* Refresh */ + wrefresh(win_log); +} + +double user_tui_getdbl (double m, double def, double M, + const char *title, const char *help) +{ + /* Input box */ + int w; + int r; + w = 75; + r = 10; + + /* Request int */ + double R; + R = alx_w_getdbl(w, r, title, m, def, M, help); + return R; +} + +int64_t user_tui_getint (double m, int64_t def, double M, + const char *title, const char *help) +{ + /* Input box */ + int w; + int r; + w = 75; + r = 10; + + /* Request int */ + int64_t i; + i = alx_w_getint(w, r, title, m, def, M, help); + return i; +} + +void user_tui_show_ocr (void) +{ + alx_pause_curses(); + + printf("%s", img_ocr_text); + getchar(); + + alx_resume_curses(); +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +/* Log -----------------------------------------------------------------------*/ +static void log_loop (void) +{ + int i; + int i_0; + int l; + int l_0; + + if (user_iface_log.len > 51) { + i_0 = user_iface_log.len - 51; + l_0 = 1; + mvwprintw(win_log, 1, 10, "..."); + } else { + i_0 = 0; + l_0 = 0; + } + + l = l_0; + for (i = i_0; i < user_iface_log.len; i++) { + if (user_iface_log.lvl[i] <= user_iface_log.visible) { + mvwprintw(win_log, (1 + l), + (1 + 4 * user_iface_log.lvl[i]), + "%.*s", + 40 - 2 - 4 * user_iface_log.lvl[i], + user_iface_log.line[i]); + l++; + } + } +} + +/* Input ---------------------------------------------------------------------*/ +static int usr_input (void) +{ + int action; + wchar_t ch; + + /* Interpret input */ + ch = wgetch(win_log); + switch (ch) { + case ' ': + action = USER_IFACE_ACT_APPLY; + break; + + /* ASCII 0x08 is BS */ + case KEY_BACKSPACE: + case 0x08: + action = USER_IFACE_ACT_DISCARD; + break; + + case 'e': + /* Exercises from class */ + ch = wgetch(win_log); + + switch (ch) { + case '1': + /* Label */ + ch = wgetch(win_log); + + switch (ch) { + case '1': + action = USER_IFACE_ACT_PROC_LABEL_SERIES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* Objects */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_PROC_OBJECTS_CALIB; + break; + case '1': + action = USER_IFACE_ACT_PROC_OBJECTS_SERIES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '3': + /* Coins */ + ch = wgetch(win_log); + + switch (ch) { + case '1': + action = USER_IFACE_ACT_PROC_COINS_SERIES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '4': + /* Resistor */ + ch = wgetch(win_log); + + switch (ch) { + case '1': + action = USER_IFACE_ACT_PROC_RESISTOR_SERIES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + + case 'f': + /* Use simple funtions */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + /* img_alx */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + /* Distance transform postprocessing */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_LOCAL_MAX; + break; + case '1': + action = USER_IFACE_ACT_SKELETON; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '1': + /* Lines */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_LINES_HORIZONTAL; + break; + case '1': + action = USER_IFACE_ACT_LINES_VERTICAL; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* Smooth */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_MEAN_HORIZONTAL; + break; + case '1': + action = USER_IFACE_ACT_MEAN_VERTICAL; + break; + case '2': + action = USER_IFACE_ACT_MEDIAN_HORIZONTAL; + break; + case '3': + action = USER_IFACE_ACT_MEDIAN_VERTICAL; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '1': + /* img_cv */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + /* Core: The core functionality */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + /* Pixel */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_PIXEL_GET; + break; + case '1': + action = USER_IFACE_ACT_PIXEL_SET; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '1': + /* ROI */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_SET_ROI; + break; + case '1': + action = USER_IFACE_ACT_SET_ROI_2RECT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* Operations on Arrays */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_AND_2REF; + break; + case '1': + action = USER_IFACE_ACT_NOT; + break; + case '2': + action = USER_IFACE_ACT_OR_2REF; + break; + case '3': + action = USER_IFACE_ACT_COMPONENT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '1': + /* Imgproc: Image processing */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + /* Image filtering */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_DILATE; + break; + case '1': + action = USER_IFACE_ACT_ERODE; + break; + case '2': + action = USER_IFACE_ACT_DILATE_ERODE; + break; + case '3': + action = USER_IFACE_ACT_ERODE_DILATE; + break; + case '4': + action = USER_IFACE_ACT_SMOOTH; + break; + case '5': + action = USER_IFACE_ACT_SOBEL; + break; + case '6': + action = USER_IFACE_ACT_BORDER; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '1': + /* Geometric image transformations */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_MIRROR; + break; + case '1': + action = USER_IFACE_ACT_ROTATE_ORTO; + break; + case '2': + action = USER_IFACE_ACT_ROTATE; + break; + case '3': + action = USER_IFACE_ACT_ROTATE_2RECT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* Miscellaneous image transformations */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_ADAPTIVE_THRESHOLD; + break; + case '1': + action = USER_IFACE_ACT_CVT_COLOR; + break; + case '2': + action = USER_IFACE_ACT_DISTANCE_TRANSFORM; + break; + case '3': + action = USER_IFACE_ACT_THRESHOLD; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '3': + /* Histograms */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_HISTOGRAM; + break; + case '1': + action = USER_IFACE_ACT_HISTOGRAM_C3; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '4': + /* Structural analysis and shape descriptors */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_CONTOURS; + break; + case '1': + action = USER_IFACE_ACT_CONTOURS_SIZE; + break; + case '2': + action = USER_IFACE_ACT_BOUNDING_RECT; + break; + case '3': + action = USER_IFACE_ACT_FIT_ELLIPSE; + break; + case '4': + action = USER_IFACE_ACT_MIN_AREA_RECT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '5': + /* Feature detection */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_HOUGH_CIRCLES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* img_orb */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_ALIGN; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '3': + /* img_calib3d */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_CALIBRATE; + break; + case '1': + action = USER_IFACE_ACT_UNDISTORT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '4': + /* img_zbar */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_DECODE; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '5': + /* img_ocr */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_READ; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + + case 'l': + action = USER_IFACE_ACT_LOAD_MEM; + break; + + case 'm': + action = USER_IFACE_ACT_SAVE_MEM; + break; + + case 'q': + action = USER_IFACE_ACT_QUIT; + break; + + case 'r': + action = USER_IFACE_ACT_SAVE_REF; + break; + + case 's': + action = USER_IFACE_ACT_SAVE_FILE; + break; + + case 'u': + /* User iface actions */ + ch = wgetch(win_log); + + switch (ch) { + case '1': + action = USER_IFACE_ACT_SHOW_OCR; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + + case 'x': + action = USER_IFACE_ACT_FOO; + + /* Special sequence "xyzzy" */ + ch = wgetch(win_log); + if (ch == 'y') { + ch = wgetch(win_log); + if (ch == 'z') { + + ch = wgetch(win_log); + if (ch == 'z') { + + ch = wgetch(win_log); + if (ch == 'y') { + action = USER_IFACE_ACT_FOO; + } + } + } + } + break; + + default: + action = USER_IFACE_ACT_FOO; + break; + } + + return action; +} + +/* * * * * * * * * * + * * * Help * * * * * * * + * * * * * * * * * */ +static void show_help (void) +{ + /* Clear */ + werase(win_help); + + int r; + int c; + + r = 0; + c = 0; + mvwprintw(win_help, r++, c, "Apply: %s", "Space"); + mvwprintw(win_help, r++, c, "Discard: %s", "BS"); + mvwprintw(win_help, r++, c, "Save to mem: %c", 'm'); + mvwprintw(win_help, r++, c, "Load from mem: %c", 'l'); + 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, " - Local maxima: %s", "f000"); + mvwprintw(win_help, r++, c, " - Skeleton: %s", "f001"); + mvwprintw(win_help, r++, c, " - Horizontal lines: %s", "f010"); + mvwprintw(win_help, r++, c, " - Vertical lines: %s", "f011"); + mvwprintw(win_help, r++, c, " - Horizontal mean: %s", "f020"); + mvwprintw(win_help, r++, c, " - Vertical mean: %s", "f021"); + mvwprintw(win_help, r++, c, " - Horizontal median: %s", "f022"); + mvwprintw(win_help, r++, c, " - Vertical median: %s", "f023"); + mvwprintw(win_help, r++, c, " - Pixel get: %s", "f1000"); + mvwprintw(win_help, r++, c, " - Pixel set: %s", "f1001"); + mvwprintw(win_help, r++, c, " - Set ROI: %s", "f1010"); + mvwprintw(win_help, r++, c, " - Set ROI 2rect: %s", "f1011"); + mvwprintw(win_help, r++, c, " - Bitwise AND 2ref: %s", "f1020"); + mvwprintw(win_help, r++, c, " - Bitwise NOT: %s", "f1021"); + mvwprintw(win_help, r++, c, " - Bitwise OR 2ref: %s", "f1022"); + mvwprintw(win_help, r++, c, " - Component: %s", "f1023"); + mvwprintw(win_help, r++, c, " - Dilate: %s", "f1100"); + mvwprintw(win_help, r++, c, " - Erode: %s", "f1101"); + mvwprintw(win_help, r++, c, " - D-E: %s", "f1102"); + mvwprintw(win_help, r++, c, " - E-D: %s", "f1103"); + mvwprintw(win_help, r++, c, " - Smooth: %s", "f1104"); + mvwprintw(win_help, r++, c, " - Sobel: %s", "f1105"); + mvwprintw(win_help, r++, c, " - Border: %s", "f1106"); + mvwprintw(win_help, r++, c, " - Mirror: %s", "f1110"); + mvwprintw(win_help, r++, c, " - Rotate ortogonally: %s", "f1111"); + mvwprintw(win_help, r++, c, " - Rotate: %s", "f1112"); + mvwprintw(win_help, r++, c, " - Rotate 2rect_rot: %s", "f1113"); + mvwprintw(win_help, r++, c, " - Adaptive threshold: %s", "f1120"); + mvwprintw(win_help, r++, c, " - Cvt color: %s", "f1121"); + mvwprintw(win_help, r++, c, " - Distance transform: %s", "f1122"); + mvwprintw(win_help, r++, c, " - Threshold: %s", "f1123"); + mvwprintw(win_help, r++, c, " - Histogram: %s", "f1130"); + mvwprintw(win_help, r++, c, " - Histogram (3 chan): %s", "f1131"); + mvwprintw(win_help, r++, c, " - Contours: %s", "f1140"); + mvwprintw(win_help, r++, c, " - Contours size: %s", "f1141"); + mvwprintw(win_help, r++, c, " - Bounding rectangle: %s", "f1142"); + mvwprintw(win_help, r++, c, " - Fit ellipse: %s", "f1143"); + mvwprintw(win_help, r++, c, " - Min. area rectangle: %s", "f1144"); + mvwprintw(win_help, r++, c, " - Hough circles: %s", "f1150"); + mvwprintw(win_help, r++, c, " - Align 2ref (ORB): %s", "f20"); + mvwprintw(win_help, r++, c, " - Calibrate (Calib3d): %s", "f30"); + mvwprintw(win_help, r++, c, " - Undistort (Calib3d): %s", "f31"); + mvwprintw(win_help, r++, c, " - Scan codes (ZBAR): %s", "f40"); + mvwprintw(win_help, r++, c, " - Scan text (OCR): %s", "f50"); + mvwprintw(win_help, r++, c, "Exercises:"); + mvwprintw(win_help, r++, c, " - Label: %s", "e11"); + mvwprintw(win_help, r++, c, " - Objects (calib): %s", "e20"); + mvwprintw(win_help, r++, c, " - Objects: %s", "e21"); + mvwprintw(win_help, r++, c, " - Coins: %s", "e31"); + mvwprintw(win_help, r++, c, " - Resistor: %s", "e41"); + mvwprintw(win_help, r++, c, "Other:"); + mvwprintw(win_help, r++, c, " - Show OCR: %s", "u1"); + mvwprintw(win_help, r++, c, "Quit: %c", 'q'); + + /* Refresh */ + wrefresh(win_help); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/main.cpp b/src/main.cpp index 875cfbd..f672b68 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,88 +1,88 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* getchar() */ - #include - -/* libalx --------------------------------------------------------------------*/ - #include "alx_ncur.hpp" - -/* Project -------------------------------------------------------------------*/ - /* about_init() & print_cpright() */ - #include "about.hpp" - #include "img_iface.hpp" - #include "menu_iface.hpp" - #include "user_iface.hpp" - #include "parser.hpp" - #include "save.hpp" - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void init_all (int *argc, char *(*argv[])); -static void cleanup (void); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -int main (int argc, char *argv[]) -{ - init_all(&argc, &argv); - - /* Print copyright () and wait for any key to continue */ - print_share_file(SHARE_COPYRIGHT); - getchar(); - - /* Menu () */ - menu_iface(); - - cleanup(); - - return 0; -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void init_all (int *argc, char *(*argv[])) -{ - /* Init curses */ - alx_start_curses(); - alx_pause_curses(); - - /* Init modules */ - about_init(); - save_init(); - - /* Modes */ - menu_iface_mode = MENU_IFACE_TUI; - user_iface_mode = USER_IFACE_TUI; - user_iface_log.visible = 2; - - /* Parse command line options */ - parser(*argc, *argv); -} - -static void cleanup (void) -{ - /* Clean img buffers */ - img_iface_cleanup_main(); - - /* End curses */ - alx_resume_curses(); - alx_end_curses(); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* getchar() */ + #include + +/* libalx --------------------------------------------------------------------*/ + #include "alx_ncur.hpp" + +/* Project -------------------------------------------------------------------*/ + /* about_init() & print_cpright() */ + #include "about.hpp" + #include "img_iface.hpp" + #include "menu_iface.hpp" + #include "user_iface.hpp" + #include "parser.hpp" + #include "save.hpp" + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void init_all (int *argc, char *(*argv[])); +static void cleanup (void); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +int main (int argc, char *argv[]) +{ + init_all(&argc, &argv); + + /* Print copyright () and wait for any key to continue */ + print_share_file(SHARE_COPYRIGHT); + getchar(); + + /* Menu () */ + menu_iface(); + + cleanup(); + + return 0; +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void init_all (int *argc, char *(*argv[])) +{ + /* Init curses */ + alx_start_curses(); + alx_pause_curses(); + + /* Init modules */ + about_init(); + save_init(); + + /* Modes */ + menu_iface_mode = MENU_IFACE_TUI; + user_iface_mode = USER_IFACE_TUI; + user_iface_log.visible = 2; + + /* Parse command line options */ + parser(*argc, *argv); +} + +static void cleanup (void) +{ + /* Clean img buffers */ + img_iface_cleanup_main(); + + /* End curses */ + alx_resume_curses(); + alx_end_curses(); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ -- cgit v1.2.3 From 076c99bc0654067eb43430ad74284670212e557e Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Sat, 5 Jan 2019 00:00:28 +0100 Subject: Rename macro --- modules/menu/src/menu_tui.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/menu/src/menu_tui.c b/modules/menu/src/menu_tui.c index b81c729..fd760cf 100644 --- a/modules/menu/src/menu_tui.c +++ b/modules/menu/src/menu_tui.c @@ -253,7 +253,7 @@ static void menu_tui_series (void) proc_mode = PROC_MODE_RESISTOR_SERIES; break; case 5: - proc_mode = PROC_MODE_LIGHTER_SERIES; + proc_mode = PROC_MODE_LIGHTERS_SERIES; break; } -- cgit v1.2.3 From 6e4fd761178350d926ae511398a1b34defdcd578 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Sat, 5 Jan 2019 00:00:59 +0100 Subject: Rename macro --- modules/proc/inc/proc_iface.h | 3 ++- modules/proc/inc/proc_iface.hpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/proc/inc/proc_iface.h b/modules/proc/inc/proc_iface.h index 57f23a9..8ce304c 100644 --- a/modules/proc/inc/proc_iface.h +++ b/modules/proc/inc/proc_iface.h @@ -35,7 +35,8 @@ PROC_MODE_COINS_CALIB, PROC_MODE_RESISTOR_SERIES, PROC_MODE_RESISTOR_CALIB, - PROC_MODE_LIGHTER_SERIES + PROC_MODE_LIGHTERS_SERIES, + PROC_MODE_LIGHTERS_CALIB }; enum Proc_DBG { diff --git a/modules/proc/inc/proc_iface.hpp b/modules/proc/inc/proc_iface.hpp index d1e03de..ede95f7 100644 --- a/modules/proc/inc/proc_iface.hpp +++ b/modules/proc/inc/proc_iface.hpp @@ -35,7 +35,8 @@ PROC_MODE_COINS_CALIB, PROC_MODE_RESISTOR_SERIES, PROC_MODE_RESISTOR_CALIB, - PROC_MODE_LIGHTER_SERIES + PROC_MODE_LIGHTERS_SERIES, + PROC_MODE_LIGHTERS_CALIB }; enum Proc_DBG { -- cgit v1.2.3 From a675df3226a3e36445bdb4d05ec0b66d6a41e174 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Sat, 5 Jan 2019 00:01:38 +0100 Subject: Add lighters to UI --- modules/user/inc/user_iface.h | 2 ++ modules/user/inc/user_iface.hpp | 2 ++ modules/user/src/user_clui.c | 12 ++++++++++++ modules/user/src/user_tui.c | 14 ++++++++++++++ 4 files changed, 30 insertions(+) diff --git a/modules/user/inc/user_iface.h b/modules/user/inc/user_iface.h index f65d708..dde7b64 100644 --- a/modules/user/inc/user_iface.h +++ b/modules/user/inc/user_iface.h @@ -113,6 +113,8 @@ USER_IFACE_ACT_PROC_COINS_CALIB, USER_IFACE_ACT_PROC_RESISTOR_SERIES, USER_IFACE_ACT_PROC_RESISTOR_CALIB, + USER_IFACE_ACT_PROC_LIGHTERS_SERIES, + USER_IFACE_ACT_PROC_LIGHTERS_CALIB, USER_IFACE_ACT_USRI = 0x010000u, USER_IFACE_ACT_SHOW_OCR, diff --git a/modules/user/inc/user_iface.hpp b/modules/user/inc/user_iface.hpp index 134f5dd..d01f3a3 100644 --- a/modules/user/inc/user_iface.hpp +++ b/modules/user/inc/user_iface.hpp @@ -113,6 +113,8 @@ USER_IFACE_ACT_PROC_COINS_CALIB, USER_IFACE_ACT_PROC_RESISTOR_SERIES, USER_IFACE_ACT_PROC_RESISTOR_CALIB, + USER_IFACE_ACT_PROC_LIGHTERS_SERIES, + USER_IFACE_ACT_PROC_LIGHTERS_CALIB, USER_IFACE_ACT_USRI = 0x010000u, USER_IFACE_ACT_SHOW_OCR, diff --git a/modules/user/src/user_clui.c b/modules/user/src/user_clui.c index 0799df3..218c14b 100644 --- a/modules/user/src/user_clui.c +++ b/modules/user/src/user_clui.c @@ -188,6 +188,17 @@ static int usr_input (void) break; } break; + case '5': + /* Lighters */ + switch (ch[2]) { + case '1': + action = USER_IFACE_ACT_PROC_LIGHTERS_SERIES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; default: action = USER_IFACE_ACT_FOO; break; @@ -611,6 +622,7 @@ static void show_help (void) printf(" - Objects: %s\n", "e21"); printf(" - Coins: %s\n", "e31"); printf(" - Resistor: %s\n", "e41"); + printf(" - Lighters: %s\n", "e51"); printf("Other:\n"); printf(" - Show OCR text: %s\n", "u1"); printf("Quit: %c\n", 'q'); diff --git a/modules/user/src/user_tui.c b/modules/user/src/user_tui.c index 4c10dc6..83c729d 100644 --- a/modules/user/src/user_tui.c +++ b/modules/user/src/user_tui.c @@ -275,6 +275,19 @@ static int usr_input (void) break; } break; + case '5': + /* Lighters */ + ch = wgetch(win_log); + + switch (ch) { + case '1': + action = USER_IFACE_ACT_PROC_LIGHTERS_SERIES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; default: action = USER_IFACE_ACT_FOO; break; @@ -757,6 +770,7 @@ static void show_help (void) mvwprintw(win_help, r++, c, " - Objects: %s", "e21"); mvwprintw(win_help, r++, c, " - Coins: %s", "e31"); mvwprintw(win_help, r++, c, " - Resistor: %s", "e41"); + mvwprintw(win_help, r++, c, " - Lighters: %s", "e51"); mvwprintw(win_help, r++, c, "Other:"); mvwprintw(win_help, r++, c, " - Show OCR: %s", "u1"); mvwprintw(win_help, r++, c, "Quit: %c", 'q'); -- cgit v1.2.3 From f113eb8c0c699ef352d3405a3c32f3439c980cf4 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Sat, 5 Jan 2019 00:02:29 +0100 Subject: Lighters images jpeg->png --- modules/proc/src/proc_iface.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/proc/src/proc_iface.c b/modules/proc/src/proc_iface.c index 2c3e870..4372b3c 100644 --- a/modules/proc/src/proc_iface.c +++ b/modules/proc/src/proc_iface.c @@ -85,7 +85,7 @@ int proc_iface_single (int action) case PROC_MODE_RESISTOR_SERIES: error = proc_resistor(); break; - case PROC_MODE_LIGHTER_SERIES: + case PROC_MODE_LIGHTERS_SERIES: error = proc_lighter(); break; default: @@ -156,12 +156,12 @@ void proc_iface_series (void) snprintf(file_ext, FILENAME_MAX, ".png"); i = 1; break; - case PROC_MODE_LIGHTER_SERIES: + case PROC_MODE_LIGHTERS_SERIES: snprintf(proc_path, FILENAME_MAX, "%s", lighters_path); snprintf(proc_fail_path, FILENAME_MAX, "%s", lighters_fail_path); snprintf(file_basename, FILENAME_MAX, "lighters"); num_len = 4; - snprintf(file_ext, FILENAME_MAX, ".jpeg"); + snprintf(file_ext, FILENAME_MAX, ".png"); i = 1; break; default: -- cgit v1.2.3 From e077965e60b8cada755a0644033768522d7c9f5d Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Sat, 5 Jan 2019 00:03:33 +0100 Subject: Finish proc: lighters --- modules/proc/src/proc_lighters.cpp | 286 ++++++++++++++++++++++++++++--------- 1 file changed, 215 insertions(+), 71 deletions(-) diff --git a/modules/proc/src/proc_lighters.cpp b/modules/proc/src/proc_lighters.cpp index 7b5cfdf..f7519a3 100644 --- a/modules/proc/src/proc_lighters.cpp +++ b/modules/proc/src/proc_lighters.cpp @@ -66,8 +66,11 @@ struct Lighter_Properties { bool fork; bool valve; - int hood; + int hood_; + bool hood; bool wheel; + + bool ok; }; @@ -95,10 +98,14 @@ static void lighters_bgr2gray (void); static void lighters_segment_full (void); static int lighters_find (void); static void lighter_segment_body (int i); +static void lighter_rm_body (int i); static void lighter_crop_head (int i); -static void lighter_chk_wheel (int i); static void lighter_chk_hood (int i); -static void lighter_segment_head (int i); +static void lighter_rm_hood (int i); +static void lighter_chk_fork (int i); +static void lighter_chk_wheel (int i); +static void lighter_chk_valve (int i); +static void lighters_log (void); /****************************************************************************** @@ -120,32 +127,40 @@ int proc_lighter (void) lighters_find(); /* Measure time */ - clock_stop("Segment lighten"); + clock_stop("Segment lighters"); } + /* Check each lighter */ for (i = 0; (unsigned)i < lighters_n; i++) { - /* Segment lighter */ - { - /* Measure time */ - clock_start(); - - lighter_segment_body(i); + /* Measure time */ + clock_start(); - /* Measure time */ - clock_stop("Segment lighten"); - } - /* Segment interest zone */ - { - /* Measure time */ - clock_start(); - - lighter_crop_head(i); - lighter_chk_wheel(i); - lighter_chk_hood(i); - (void)lighter_segment_head; - - /* Measure time */ - clock_stop("Segment interest zone"); + lighter[i].ok = true; + lighter_segment_body(i); + lighter_rm_body(i); + lighter_crop_head(i); + lighter_chk_hood(i); + if (lighter[i].hood_ != HOOD_NOT_PRESENT) { + lighter_rm_hood(i); + } else { + proc_load_mem(7); + proc_save_mem(8); } + lighter_chk_fork(i); + lighter_chk_wheel(i); + lighter_chk_valve(i); + + /* Measure time */ + clock_stop("Check parts"); + } + /* Print results of lighters into log */ + { + /* Measure time */ + clock_start(); + + lighters_log(); + + /* Measure time */ + clock_stop("Lighters properties (log)"); } status = LIGHTER_OK; @@ -192,19 +207,24 @@ static void lighters_bgr2gray (void) proc_cvt_color(cv::COLOR_BGR2GRAY); proc_not(); - proc_border(100); proc_save_mem(1); + + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_border(100); + proc_save_mem(3); + + proc_load_mem(1); + proc_border(100); + proc_save_mem(2); } static void lighters_segment_full (void) { - proc_load_mem(1); - - proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_load_mem(3); proc_erode_dilate(1); - proc_dilate_erode(1); - proc_save_mem(2); + proc_dilate_erode(2); + proc_save_mem(4); } static int lighters_find (void) @@ -213,8 +233,7 @@ static int lighters_find (void) int i; int tmp; - proc_load_mem(2); - + proc_load_mem(4); proc_contours(&contours_all, &hierarchy); lighters_n = contours_all.size(); @@ -237,7 +256,7 @@ static int lighters_find (void) lighter[i].pos.x = rect_rot[i].center.x; lighter[i].pos.y = rect_rot[i].center.y; - lighter[i].angle = rect_rot[i].angle; + lighter[i].angle = -rect_rot[i].angle; lighter[i].size.h = rect_rot[i].size.height; lighter[i].size.w = rect_rot[i].size.width; } @@ -253,9 +272,9 @@ static void lighter_segment_body (int i) int w; int h; - proc_load_mem(1); + proc_load_mem(2); - proc_rotate(lighter[i].pos.x, lighter[i].pos.y, lighter[i].angle); + proc_rotate(lighter[i].pos.x, lighter[i].pos.y, -lighter[i].angle); w = lighter[i].size.w * 1.25; h = lighter[i].size.h * 1.25; x = lighter[i].pos.x - (w / 2.0); @@ -266,26 +285,26 @@ static void lighter_segment_body (int i) proc_erode_dilate(1); proc_dilate_erode(1); proc_erode_dilate(lighter[i].size.w * 0.43); - proc_save_mem(3); + proc_save_mem(5); proc_contours(&contours_one, &hierarchy); proc_bounding_rect(&(contours_one[0]), &rect, true); } -static void lighter_crop_head (int i) +static void lighter_rm_body (int i) { int x; int y; int w; int h; - proc_load_mem(3); + proc_load_mem(5); proc_not(); - proc_erode(1); + proc_erode(5); proc_save_ref(); - proc_load_mem(1); - proc_rotate(lighter[i].pos.x, lighter[i].pos.y, lighter[i].angle); + proc_load_mem(3); + proc_rotate(lighter[i].pos.x, lighter[i].pos.y, -lighter[i].angle); w = lighter[i].size.w * 1.25; h = lighter[i].size.h * 1.25; x = lighter[i].pos.x - (w / 2.0); @@ -293,6 +312,17 @@ static void lighter_crop_head (int i) proc_ROI(x, y, w, h); proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); proc_and_2ref(); + proc_save_mem(6); +} + +static void lighter_crop_head (int i) +{ + int x; + int y; + int w; + int h; + + proc_load_mem(6); // w = rect.width * 1.15; h = rect.width * 0.65; @@ -305,61 +335,175 @@ static void lighter_crop_head (int i) rect.height = h; lighter[i].size.w = w; lighter[i].size.h = h; - proc_save_mem(4); + proc_save_mem(7); } static void lighter_chk_hood (int i) { uint8_t val1; uint8_t val2; - proc_load_mem(4); + proc_load_mem(7); + + proc_pixel_get(rect.width * 0.2, rect.height * 0.3, &val1); + proc_pixel_set(rect.width * 0.2, rect.height * 0.3, UINT8_MAX / 2); + proc_save_mem(9); - proc_pixel_get(lighter[i].size.w * 0.2, lighter[i].size.h * 0.3, &val1); - proc_pixel_set(lighter[i].size.w * 0.2, lighter[i].size.h * 0.3, 0); if (val1) { - proc_pixel_get(lighter[i].size.w * 0.2, lighter[i].size.h * 0.8, - &val2); - proc_pixel_set(lighter[i].size.w * 0.2, lighter[i].size.h * 0.8, - 0); + proc_pixel_get(rect.width * 0.2, rect.height * 0.8, &val2); + proc_pixel_set(rect.width * 0.2, rect.height * 0.8, UINT8_MAX /2); if (val2) { - lighter[i].hood = HOOD_OK; + lighter[i].hood_ = HOOD_OK; + lighter[i].hood = true; } else { - lighter[i].hood = HOOD_NOT_OK; + lighter[i].hood_ = HOOD_NOT_OK; + lighter[i].hood = false; + lighter[i].ok = false; } } else { - lighter[i].hood = HOOD_NOT_PRESENT; + lighter[i].hood_ = HOOD_NOT_PRESENT; + lighter[i].hood = false; + lighter[i].ok = false; } +} -proc_apply(); -proc_save_file(); - proc_save_mem(7); +static void lighter_rm_hood (int i) +{ + + proc_load_mem(7); + proc_border(2); + proc_save_ref(); + + proc_dilate_erode(2); + proc_erode_dilate(rect.height * 0.25); + proc_dilate(2); + proc_not(); + proc_and_2ref(); + proc_save_mem(8); +} + +static void lighter_chk_fork (int i) +{ + uint8_t val; + + proc_load_mem(8); + + proc_dilate_erode(2); + proc_pixel_get(rect.width * 0.8, rect.height * 0.8, &val); + proc_pixel_set(rect.width * 0.8, rect.height * 0.8, UINT8_MAX / 2); + proc_save_mem(10); + + if (val) { + lighter[i].fork = true; + } else { + lighter[i].fork = false; + lighter[i].ok = false; + } } static void lighter_chk_wheel (int i) { uint8_t val; - proc_load_mem(4); + proc_load_mem(8); - proc_pixel_get(lighter[i].size.w * 0.58, lighter[i].size.h * 0.19, &val); - proc_pixel_set(lighter[i].size.w * 0.58, lighter[i].size.h * 0.19, 0); - lighter[i].wheel = (bool)val; - proc_save_mem(6); + proc_dilate(5); + proc_pixel_get(rect.width * 0.58, rect.height * 0.19, &val); + proc_pixel_set(rect.width * 0.58, rect.height * 0.19, UINT8_MAX / 2); + proc_save_mem(11); + + if (val) { + lighter[i].wheel = true; + } else { + lighter[i].wheel = false; + lighter[i].ok = false; + } } -static void lighter_segment_head (int i) +static void lighter_chk_valve (int i) { + uint8_t val; + proc_load_mem(8); -/* - proc_smooth(IMGI_SMOOTH_MEDIAN, 5); - proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); - proc_dilate_erode(5); - proc_erode_dilate(rect[0].height * 0.25); - proc_contours(&contours, &hierarchy); - proc_bounding_rect(&(contours[0]), &(rect[0]), true); -*/ - proc_save_mem(9); + if (lighter[i].hood_ == HOOD_NOT_PRESENT) { + proc_dilate(5); + } else { + proc_dilate(10); + } + proc_pixel_get(rect.width * 0.07, rect.height * 0.92, &val); + proc_pixel_set(rect.width * 0.07, rect.height * 0.92, UINT8_MAX / 2); + proc_save_mem(12); + + if (val) { + lighter[i].valve = true; + } else { + lighter[i].valve = false; + lighter[i].ok = false; + } +} + +static void lighters_log (void) +{ + int i; + + for (i = 0; (unsigned)i < lighters_n; i++) { + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Lighter[%i]:", + i); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " pos: (%i, %i) pix", + lighter[i].pos.x, + lighter[i].pos.y); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " ang = %.1lf DEG", + lighter[i].angle); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " hood = %s", + lighter[i].hood ? "ok" : "nok"); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " fork = %s", + lighter[i].fork ? "ok" : "nok"); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " wheel = %s", + lighter[i].wheel ? "ok" : "nok"); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " valve = %s", + lighter[i].valve ? "ok" : "nok"); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " RESULT = %s", + lighter[i].ok ? "OK" : "NOK"); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + } } -- cgit v1.2.3 From f525f7ab1d393405284e8640b43910a45a52a6ac Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Sat, 5 Jan 2019 00:04:17 +0100 Subject: Update libalx --- libalx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libalx b/libalx index 110d0dc..0e3f07b 160000 --- a/libalx +++ b/libalx @@ -1 +1 @@ -Subproject commit 110d0dc28f2ecdf6d371412d41e5c39de2828155 +Subproject commit 0e3f07b6d3894c494f39d63c1c617b6600d65216 -- cgit v1.2.3 From 9829091db30c48050df684d34a7795485c2c63d1 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Sat, 5 Jan 2019 00:05:08 +0100 Subject: Fix bug: img_ref --- modules/image/src/img_iface.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/image/src/img_iface.cpp b/modules/image/src/img_iface.cpp index c252916..0c896f6 100644 --- a/modules/image/src/img_iface.cpp +++ b/modules/image/src/img_iface.cpp @@ -1971,7 +1971,6 @@ static void img_iface_save_ref (void) /* Write into ref */ image_ref.release(); image_copy_tmp.copyTo(image_ref); - image_ref = image_copy_tmp; } /* save ----------------------------------------------------------------------*/ -- cgit v1.2.3 From 7b5866b2eb9392ddf31621eb342efb0900f9c370 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Sat, 5 Jan 2019 00:05:30 +0100 Subject: Show img after pixel_set --- modules/proc/src/proc_common.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/proc/src/proc_common.cpp b/modules/proc/src/proc_common.cpp index 96b66f1..10a8a93 100644 --- a/modules/proc/src/proc_common.cpp +++ b/modules/proc/src/proc_common.cpp @@ -133,6 +133,8 @@ void proc_pixel_set (int x, int y, unsigned char val) data.y = y; data.val = val; img_iface_act(IMG_IFACE_ACT_PIXEL_SET, (void *)&data); + + proc_show_img(); } void proc_ROI (int x, int y, int w, int h) -- cgit v1.2.3 From bf7153d5b03c62774191368d7369543465923b41 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Sat, 5 Jan 2019 02:19:38 +0100 Subject: Fix style (kernel checkstyle) --- libalx | 2 +- modules/about/inc/about.h | 11 +++--- modules/about/inc/about.hpp | 11 +++--- modules/about/src/about.c | 19 +++++++---- modules/ctrl/inc/start.h | 1 + modules/ctrl/src/start.c | 5 +++ modules/image/inc/img_alx.hpp | 1 + modules/image/inc/img_calib3d.hpp | 3 +- modules/image/inc/img_cv.hpp | 1 + modules/image/inc/img_iface.h | 28 ++++++++-------- modules/image/inc/img_iface.hpp | 19 ++++++----- modules/image/inc/img_ocr.h | 1 + modules/image/inc/img_ocr.hpp | 3 +- modules/image/inc/img_orb.hpp | 5 +-- modules/image/inc/img_zbar.hpp | 1 + modules/image/src/img_calib3d.cpp | 1 + modules/image/src/img_cv.cpp | 1 + modules/image/src/img_iface.cpp | 3 +- modules/image/src/img_ocr.c | 22 ++++++------ modules/image/src/img_orb.cpp | 1 + modules/image/src/img_zbar.cpp | 1 + modules/menu/inc/menu_clui.h | 3 +- modules/menu/inc/menu_iface.h | 1 + modules/menu/inc/menu_iface.hpp | 5 +-- modules/menu/inc/menu_tui.h | 3 +- modules/menu/inc/parser.h | 1 + modules/menu/inc/parser.hpp | 3 +- modules/menu/src/menu_clui.c | 39 +++++++++++++--------- modules/menu/src/menu_iface.c | 1 + modules/menu/src/menu_tui.c | 68 +++++++++++++++++++++----------------- modules/menu/src/parser.c | 19 +++++++---- modules/proc/inc/proc_coins.h | 3 +- modules/proc/inc/proc_coins.hpp | 3 +- modules/proc/inc/proc_common.h | 7 ++-- modules/proc/inc/proc_common.hpp | 1 + modules/proc/inc/proc_iface.h | 9 ++--- modules/proc/inc/proc_iface.hpp | 9 ++--- modules/proc/inc/proc_label.h | 3 +- modules/proc/inc/proc_label.hpp | 3 +- modules/proc/inc/proc_lighters.h | 3 +- modules/proc/inc/proc_lighters.hpp | 3 +- modules/proc/inc/proc_objects.h | 5 +-- modules/proc/inc/proc_objects.hpp | 5 +-- modules/proc/inc/proc_resistor.h | 3 +- modules/proc/inc/proc_resistor.hpp | 3 +- modules/proc/src/proc_coins.cpp | 1 + modules/proc/src/proc_common.cpp | 1 + modules/proc/src/proc_iface.c | 1 + modules/proc/src/proc_label.cpp | 1 + modules/proc/src/proc_lighters.cpp | 1 + modules/proc/src/proc_objects.cpp | 1 + modules/proc/src/proc_resistor.cpp | 1 + modules/save/inc/save.h | 39 +++++++++++----------- modules/save/inc/save.hpp | 41 ++++++++++++----------- modules/save/src/save.cpp | 1 + modules/user/inc/user_clui.h | 1 + modules/user/inc/user_iface.h | 23 +++++++------ modules/user/inc/user_iface.hpp | 23 +++++++------ modules/user/inc/user_tui.h | 1 + modules/user/src/user_clui.c | 14 +++++--- modules/user/src/user_iface.c | 9 ++--- modules/user/src/user_tui.c | 51 ++++++++++++++++++---------- src/main.cpp | 1 + 63 files changed, 329 insertions(+), 225 deletions(-) diff --git a/libalx b/libalx index 0e3f07b..e67da56 160000 --- a/libalx +++ b/libalx @@ -1 +1 @@ -Subproject commit 0e3f07b6d3894c494f39d63c1c617b6600d65216 +Subproject commit e67da562ef5e2dda524c86da3367d537caee4d4c diff --git a/modules/about/inc/about.h b/modules/about/inc/about.h index 62a0963..381f13d 100644 --- a/modules/about/inc/about.h +++ b/modules/about/inc/about.h @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -40,16 +41,16 @@ /****************************************************************************** ******* variables ************************************************************ ******************************************************************************/ - extern char share_path [FILENAME_MAX]; +extern char share_path [FILENAME_MAX]; /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ - void about_init (void); - void snprint_share_file (char *dest, int destsize, int share_file); - void print_share_file (int share_file); - void print_version (void); +void about_init (void); +void snprint_share_file (char *dest, int destsize, int share_file); +void print_share_file (int share_file); +void print_version (void); /****************************************************************************** diff --git a/modules/about/inc/about.hpp b/modules/about/inc/about.hpp index a1a9f2e..31d5977 100644 --- a/modules/about/inc/about.hpp +++ b/modules/about/inc/about.hpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -46,16 +47,16 @@ extern "C" { /****************************************************************************** ******* variables ************************************************************ ******************************************************************************/ - extern char share_path [FILENAME_MAX]; +extern char share_path [FILENAME_MAX]; /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ - void about_init (void); - void snprint_share_file (char *dest, int destsize, int share_file); - void print_share_file (int share_file); - void print_version (void); +void about_init (void); +void snprint_share_file (char *dest, int destsize, int share_file); +void print_share_file (int share_file); +void print_version (void); /****************************************************************************** diff --git a/modules/about/src/about.c b/modules/about/src/about.c index a9561e0..daae65a 100644 --- a/modules/about/src/about.c +++ b/modules/about/src/about.c @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -38,7 +39,8 @@ char share_path [FILENAME_MAX]; ******************************************************************************/ void about_init (void) { - snprintf(share_path, FILENAME_MAX, "%s/%s/", INSTALL_SHARE_DIR, SHARE_DIR); + snprintf(share_path, FILENAME_MAX, "%s/%s/", + INSTALL_SHARE_DIR, SHARE_DIR); } void snprint_share_file (char *dest, int destsize, int share_file) @@ -47,19 +49,24 @@ void snprint_share_file (char *dest, int destsize, int share_file) switch (share_file) { case SHARE_COPYRIGHT: - snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "COPYRIGHT.txt"); + snprintf(file_name, FILENAME_MAX, "%s/%s", + share_path, "COPYRIGHT.txt"); break; case SHARE_DISCLAIMER: - snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "DISCLAIMER.txt"); + snprintf(file_name, FILENAME_MAX, "%s/%s", + share_path, "DISCLAIMER.txt"); break; case SHARE_HELP: - snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "HELP.txt"); + snprintf(file_name, FILENAME_MAX, "%s/%s", + share_path, "HELP.txt"); break; case SHARE_LICENSE: - snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "LICENSE.txt"); + snprintf(file_name, FILENAME_MAX, "%s/%s", + share_path, "LICENSE.txt"); break; case SHARE_USAGE: - snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "USAGE.txt"); + snprintf(file_name, FILENAME_MAX, "%s/%s", + share_path, "USAGE.txt"); break; } diff --git a/modules/ctrl/inc/start.h b/modules/ctrl/inc/start.h index 1ef2af6..e8273f1 100644 --- a/modules/ctrl/inc/start.h +++ b/modules/ctrl/inc/start.h @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ diff --git a/modules/ctrl/src/start.c b/modules/ctrl/src/start.c index 37ea1b4..2022b32 100644 --- a/modules/ctrl/src/start.c +++ b/modules/ctrl/src/start.c @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -46,6 +47,7 @@ static void start_series (void); ******************************************************************************/ void start_switch (void) { + switch (start_mode) { case START_FOO: start_foo(); @@ -67,11 +69,13 @@ void start_switch (void) ******************************************************************************/ static void start_foo (void) { + /* empty */ } static void start_single (void) { + errno = 0; img_iface_load(NULL, saved_name); @@ -89,6 +93,7 @@ static void start_single (void) static void start_series (void) { int tmp; + tmp = user_iface_mode; user_iface_mode = USER_IFACE_CLUI; diff --git a/modules/image/inc/img_alx.hpp b/modules/image/inc/img_alx.hpp index d3867d6..6eb76ce 100644 --- a/modules/image/inc/img_alx.hpp +++ b/modules/image/inc/img_alx.hpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ diff --git a/modules/image/inc/img_calib3d.hpp b/modules/image/inc/img_calib3d.hpp index 7079d68..87ff946 100644 --- a/modules/image/inc/img_calib3d.hpp +++ b/modules/image/inc/img_calib3d.hpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -32,7 +33,7 @@ /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ - void img_calib3d_act (class cv::Mat *imgptr, int action, void *data); +void img_calib3d_act (class cv::Mat *imgptr, int action, void *data); /****************************************************************************** diff --git a/modules/image/inc/img_cv.hpp b/modules/image/inc/img_cv.hpp index 61cb78a..f1aa538 100644 --- a/modules/image/inc/img_cv.hpp +++ b/modules/image/inc/img_cv.hpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ diff --git a/modules/image/inc/img_iface.h b/modules/image/inc/img_iface.h index 460db47..c071971 100644 --- a/modules/image/inc/img_iface.h +++ b/modules/image/inc/img_iface.h @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -29,10 +30,7 @@ # define IMG_IFACE_THR_OTSU (-1) /* Functions -----------------------------------------------------------------*/ - # define img_iface_act_nodata(x) \ - do { \ - img_iface_act(x, NULL); \ - } while (0) + # define img_iface_act_nodata(x) img_iface_act(x, NULL) /****************************************************************************** @@ -160,20 +158,20 @@ /****************************************************************************** ******* variables ************************************************************ ******************************************************************************/ - extern char img_ocr_text [OCR_TEXT_MAX]; - extern struct Img_Iface_ZB_Codes zb_codes; +extern char img_ocr_text [OCR_TEXT_MAX]; +extern struct Img_Iface_ZB_Codes zb_codes; /****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void img_iface_cleanup_main (void); - void img_iface_load (const char *fpath, const char *fname); - void img_iface_cleanup (void); - void img_iface_act (int action, void *data); - void img_iface_show_img (void); - void img_iface_show_hist_c1 (void); - void img_iface_show_hist_c3 (void); +******* functions ************************************************************ +******************************************************************************/ +void img_iface_cleanup_main (void); +void img_iface_load (const char *fpath, const char *fname); +void img_iface_cleanup (void); +void img_iface_act (int action, void *data); +void img_iface_show_img (void); +void img_iface_show_hist_c1 (void); +void img_iface_show_hist_c3 (void); /****************************************************************************** diff --git a/modules/image/inc/img_iface.hpp b/modules/image/inc/img_iface.hpp index 6448578..b1904df 100644 --- a/modules/image/inc/img_iface.hpp +++ b/modules/image/inc/img_iface.hpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -310,20 +311,20 @@ extern "C" { /****************************************************************************** ******* variables ************************************************************ ******************************************************************************/ - extern char img_ocr_text [OCR_TEXT_MAX]; - extern struct Img_Iface_ZB_Codes zb_codes; +extern char img_ocr_text [OCR_TEXT_MAX]; +extern struct Img_Iface_ZB_Codes zb_codes; /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ - void img_iface_cleanup_main (void); - void img_iface_load (const char *fpath, const char *fname); - void img_iface_cleanup (void); - void img_iface_act (int action, void *data); - void img_iface_show_img (void); - void img_iface_show_hist_c1 (void); - void img_iface_show_hist_c3 (void); +void img_iface_cleanup_main (void); +void img_iface_load (const char *fpath, const char *fname); +void img_iface_cleanup (void); +void img_iface_act (int action, void *data); +void img_iface_show_img (void); +void img_iface_show_hist_c1 (void); +void img_iface_show_hist_c3 (void); /****************************************************************************** diff --git a/modules/image/inc/img_ocr.h b/modules/image/inc/img_ocr.h index 62d248a..e6c1bca 100644 --- a/modules/image/inc/img_ocr.h +++ b/modules/image/inc/img_ocr.h @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ diff --git a/modules/image/inc/img_ocr.hpp b/modules/image/inc/img_ocr.hpp index 355a124..dfd759a 100644 --- a/modules/image/inc/img_ocr.hpp +++ b/modules/image/inc/img_ocr.hpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -30,7 +31,7 @@ extern "C" { /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ - void img_ocr_act (int action, void *data); +void img_ocr_act (int action, void *data); /****************************************************************************** diff --git a/modules/image/inc/img_orb.hpp b/modules/image/inc/img_orb.hpp index ce5a914..18db3a7 100644 --- a/modules/image/inc/img_orb.hpp +++ b/modules/image/inc/img_orb.hpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -31,8 +32,8 @@ /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ - void img_orb_act (class cv::Mat *pattern, - class cv::Mat *imgptr, int action); +void img_orb_act (class cv::Mat *pattern, + class cv::Mat *imgptr, int action); /****************************************************************************** diff --git a/modules/image/inc/img_zbar.hpp b/modules/image/inc/img_zbar.hpp index 72f1020..d638ed5 100644 --- a/modules/image/inc/img_zbar.hpp +++ b/modules/image/inc/img_zbar.hpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ diff --git a/modules/image/src/img_calib3d.cpp b/modules/image/src/img_calib3d.cpp index 63a64f4..8aaa408 100644 --- a/modules/image/src/img_calib3d.cpp +++ b/modules/image/src/img_calib3d.cpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ diff --git a/modules/image/src/img_cv.cpp b/modules/image/src/img_cv.cpp index 0d76bb8..d9c2343 100644 --- a/modules/image/src/img_cv.cpp +++ b/modules/image/src/img_cv.cpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ diff --git a/modules/image/src/img_iface.cpp b/modules/image/src/img_iface.cpp index 0c896f6..6c5d64e 100644 --- a/modules/image/src/img_iface.cpp +++ b/modules/image/src/img_iface.cpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -757,7 +758,7 @@ static void img_iface_set_ROI (void *data) title, NULL); snprintf(title, 80, "Width:"); - data_tmp.rect.width = user_iface_getint(1, + data_tmp.rect.width = user_iface_getint(1, image_copy_tmp.cols - data_tmp.rect.x, image_copy_tmp.cols - data_tmp.rect.x, title, NULL); diff --git a/modules/image/src/img_ocr.c b/modules/image/src/img_ocr.c index c406abf..35e0db3 100644 --- a/modules/image/src/img_ocr.c +++ b/modules/image/src/img_ocr.c @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -52,15 +53,18 @@ void img_ocr_act (int action, void *data) ******************************************************************************/ static void img_ocr_read (void *data) { - struct TessBaseAPI *handle_ocr; + struct Img_Iface_Data_Read *data_cast; + struct TessBaseAPI *handle_ocr; + int lang; + char lang_str [20 + 1]; + int conf; + char conf_str [FILENAME_MAX]; + char *txt; /* Data */ - struct Img_Iface_Data_Read *data_cast; data_cast = (struct Img_Iface_Data_Read *)data; /* Language */ - int lang; - char lang_str [20 + 1]; lang = data_cast->lang; switch (lang) { case IMG_IFACE_OCR_LANG_ENG: @@ -81,8 +85,6 @@ static void img_ocr_read (void *data) } /* Config file */ - int conf; - char conf_str [FILENAME_MAX]; conf = data_cast->conf; switch (conf) { case IMG_IFACE_OCR_CONF_PRICE: @@ -92,13 +94,12 @@ static void img_ocr_read (void *data) /* init OCR */ handle_ocr = TessBaseAPICreate(); - TessBaseAPIInit2(handle_ocr, NULL, lang_str, #ifdef OEM_LSTM_ONLY - OEM_LSTM_ONLY); + TessBaseAPIInit2(handle_ocr, NULL, lang_str, OEM_LSTM_ONLY); #else - OEM_DEFAULT); + TessBaseAPIInit2(handle_ocr, NULL, lang_str, OEM_DEFAULT); #endif -// OEM_TESSERACT_LSTM_COMBINED); +/* TessBaseAPIInit2(handle_ocr, NULL, lang_str, OEM_TESSERACT_LSTM_COMBINED);*/ if (conf) { /* Configure OCR (whitelist chars) */ TessBaseAPIReadConfigFile(handle_ocr, conf_str); @@ -110,7 +111,6 @@ static void img_ocr_read (void *data) data_cast->img.B_per_pix, data_cast->img.B_per_line); TessBaseAPIRecognize(handle_ocr, NULL); - char *txt; txt = TessBaseAPIGetUTF8Text(handle_ocr); /* Copy text to global variable */ diff --git a/modules/image/src/img_orb.cpp b/modules/image/src/img_orb.cpp index 6d91085..113f3dd 100644 --- a/modules/image/src/img_orb.cpp +++ b/modules/image/src/img_orb.cpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ diff --git a/modules/image/src/img_zbar.cpp b/modules/image/src/img_zbar.cpp index 5a976a6..fe2b669 100644 --- a/modules/image/src/img_zbar.cpp +++ b/modules/image/src/img_zbar.cpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ diff --git a/modules/menu/inc/menu_clui.h b/modules/menu/inc/menu_clui.h index 49de943..a915645 100644 --- a/modules/menu/inc/menu_clui.h +++ b/modules/menu/inc/menu_clui.h @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -13,7 +14,7 @@ /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ - void menu_clui (void); +void menu_clui (void); /****************************************************************************** diff --git a/modules/menu/inc/menu_iface.h b/modules/menu/inc/menu_iface.h index 09a1164..1b76e0b 100644 --- a/modules/menu/inc/menu_iface.h +++ b/modules/menu/inc/menu_iface.h @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ diff --git a/modules/menu/inc/menu_iface.hpp b/modules/menu/inc/menu_iface.hpp index 1b5b60c..6128711 100644 --- a/modules/menu/inc/menu_iface.hpp +++ b/modules/menu/inc/menu_iface.hpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -29,13 +30,13 @@ extern "C" { /****************************************************************************** ******* variables ************************************************************ ******************************************************************************/ - extern int menu_iface_mode; +extern int menu_iface_mode; /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ - void menu_iface (void); +void menu_iface (void); /****************************************************************************** diff --git a/modules/menu/inc/menu_tui.h b/modules/menu/inc/menu_tui.h index 74cfd5f..0f8e442 100644 --- a/modules/menu/inc/menu_tui.h +++ b/modules/menu/inc/menu_tui.h @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -13,7 +14,7 @@ /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ - void menu_tui (void); +void menu_tui (void); /****************************************************************************** diff --git a/modules/menu/inc/parser.h b/modules/menu/inc/parser.h index a29afcd..3843017 100644 --- a/modules/menu/inc/parser.h +++ b/modules/menu/inc/parser.h @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ diff --git a/modules/menu/inc/parser.hpp b/modules/menu/inc/parser.hpp index 700a0aa..e40bbd3 100644 --- a/modules/menu/inc/parser.hpp +++ b/modules/menu/inc/parser.hpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -19,7 +20,7 @@ extern "C" { /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ - void parser (int argc, char *argv[]); +void parser (int argc, char *argv[]); /****************************************************************************** diff --git a/modules/menu/src/menu_clui.c b/modules/menu/src/menu_clui.c index db2a11e..f5bb045 100644 --- a/modules/menu/src/menu_clui.c +++ b/modules/menu/src/menu_clui.c @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -42,32 +43,38 @@ void menu_clui (void) ch = 'n'; printf("Read 'Disclaimer of warranty'? (yes/NO): "); fgets(buff, BUFF_SIZE, stdin); - sscanf(buff, " %c", &ch); + if (sscanf(buff, " %c", &ch)) { + return; + } if (ch == 'y' || ch == 'Y') { - puts (" >yes"); + printf(" >yes\n"); print_share_file(SHARE_DISCLAIMER); } else { - puts (" >NO"); + printf(" >NO\n"); } ch = 'n'; printf("Read 'License'? (yes/NO): "); fgets(buff, BUFF_SIZE, stdin); - sscanf(buff, " %c", &ch); + if (sscanf(buff, " %c", &ch)) { + return; + } if (ch == 'y' || ch == 'Y') { - puts (" >yes"); + printf(" >yes\n"); print_share_file(SHARE_LICENSE); } else { - puts (" >NO"); + printf(" >NO\n"); } #if 0 printf("Game interface? (NCURSES/text): "); - scanf(" %c%*s ", &ch); + if (sscanf(buff, " %c", &ch)) { + return; + } if (ch == 't' || ch == 'T') { - puts (" >text"); + printf(" >text\n"); // FIXME } else { - puts (" >NCURSES"); + printf(" >NCURSES\n"); // FIXME } #endif @@ -81,7 +88,7 @@ void menu_clui (void) static void menu_clui_load (void) { #if 0 - /* File name */ // FIXME + /* File name */ /* FIXME */ alx_w_getfname(USER_SAVED_DIR, saved_name, "File name:", saved_name, NULL); #endif menu_clui_start(); @@ -89,7 +96,7 @@ static void menu_clui_load (void) static void menu_clui_start (void) { - puts(" >>START:"); + printf(" >>START:\n"); start_switch(); char buff [BUFF_SIZE]; @@ -98,14 +105,16 @@ static void menu_clui_start (void) ch = 'm'; printf("Load again? (MENU/load/exit): "); fgets(buff, BUFF_SIZE, stdin); - sscanf(buff, " %c", &ch); + if (sscanf(buff, " %c", &ch)) { + return; + } if (ch == 'p' || ch == 'P') { - puts (" >load"); + printf(" >load\n"); menu_clui_start(); } else if (ch == 'e' || ch == 'E') { - puts (" >exit!"); + printf(" >exit!\n"); } else { - puts (" >MENU"); + printf(" >MENU\n"); menu_clui(); } } diff --git a/modules/menu/src/menu_iface.c b/modules/menu/src/menu_iface.c index 03b1413..384fa35 100644 --- a/modules/menu/src/menu_iface.c +++ b/modules/menu/src/menu_iface.c @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ diff --git a/modules/menu/src/menu_tui.c b/modules/menu/src/menu_tui.c index fd760cf..5654b40 100644 --- a/modules/menu/src/menu_tui.c +++ b/modules/menu/src/menu_tui.c @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -44,16 +45,19 @@ static void menu_tui_devel (void); ******************************************************************************/ void menu_tui (void) { + int h; + int w; + int N; + bool wh; + int sw; + alx_resume_curses(); /* Menu dimensions & options */ - int h; - int w; h = 23; w = 80; - int N; N = 4; - struct Alx_Menu mnu[4] = { + static const struct Alx_Menu mnu[4] = { {7, 4, "[0] Exit program"}, {2, 4, "[1] Continue"}, {4, 4, "[2] Disclaimer of warranty"}, @@ -61,8 +65,6 @@ void menu_tui (void) }; /* Menu */ - bool wh; - int sw; wh = true; while (wh) { /* Menu loop */ @@ -103,19 +105,24 @@ void menu_tui (void) ******************************************************************************/ static void menu_tui_continue (void) { - /* Menu dimensions & options */ WINDOW *win; int h; int w; int r; int c; + int N; + int w2; + int r2; + bool wh; + int sw; + + /* Menu dimensions & options */ h = 23; w = 80; r = 1; c = (80 - w) / 2; - int N; N = 6; - struct Alx_Menu mnu[6] = { + static const struct Alx_Menu mnu[6] = { {8, 4, "[0] Back"}, {2, 4, "[1] Start"}, {3, 4, "[2] Select"}, @@ -125,15 +132,11 @@ static void menu_tui_continue (void) }; /* Input box */ - int w2; - int r2; w2 = w - 8; r2 = r + h - 5; - char *txt[] = {"File name:"}; + static const char *txt[] = {"File name:"}; /* Menu */ - bool wh; - int sw; wh = true; while (wh) { /* Menu loop */ @@ -186,21 +189,22 @@ static void menu_tui_continue (void) static void menu_tui_select (void) { - /* Menu dimensions & options */ int h; int w; + int N; + int sw; + + /* Menu dimensions & options */ h = 23; w = 80; - int N; N = 3; - struct Alx_Menu mnu[3] = { + static const struct Alx_Menu mnu[3] = { {6, 4, "[0] Back"}, {2, 4, "[1] Single image"}, {4, 4, "[2] Series"} }; /* Menu loop */ - int sw; sw = alx_menu(h, w, N, mnu, "SELECT MODE:"); /* Selection */ @@ -218,14 +222,16 @@ static void menu_tui_select (void) static void menu_tui_series (void) { - /* Menu dimensions & options */ int h; int w; + int N; + int sw; + + /* Menu dimensions & options */ h = 23; w = 80; - int N; N = 6; - struct Alx_Menu mnu[6] = { + static const struct Alx_Menu mnu[6] = { {8, 4, "[0] Back"}, {2, 4, "[1] Label"}, {3, 4, "[2] Objects"}, @@ -235,7 +241,6 @@ static void menu_tui_series (void) }; /* Menu loop */ - int sw; sw = alx_menu(h, w, N, mnu, "SELECT LEVEL:"); /* Selection */ @@ -266,13 +271,18 @@ static void menu_tui_devel (void) int w; int r; int c; + int N; + int w2; + int r2; + bool wh; + int sw; + h = 23; w = 80; r = 1; c = (80 - w) / 2; - int N; N = 4; - struct Alx_Menu mnu[4] = { + static const struct Alx_Menu mnu[4] = { {6, 4, "[0] Back"}, {2, 4, "[1] Change process mode"}, {3, 4, "[2] Change log mode"}, @@ -280,11 +290,9 @@ static void menu_tui_devel (void) }; /* Input box */ - int w2; - int r2; w2 = w - 8; r2 = r + h - 5; - char *txt[] = { + static const char *txt[] = { "Modes: 0=Auto; 1=Stop@prod; 2=Delay@step; 3=Stop@step", "Modes: 0=Results; 1=Operations; 2=All", "Modes: 1=CLUI; 2=TUI" @@ -294,8 +302,6 @@ static void menu_tui_devel (void) win = newwin(h, w, r, c); /* Menu loop */ - bool wh; - int sw; wh = true; while (wh) { /* Selection */ @@ -308,8 +314,8 @@ static void menu_tui_devel (void) case 1: proc_debug = alx_w_getint(w2, r2, txt[0], - PROC_DBG_NO, 0, PROC_DBG_STOP_STEP, - NULL); + PROC_DBG_NO, 0, + PROC_DBG_STOP_STEP, NULL); break; case 2: diff --git a/modules/menu/src/parser.c b/modules/menu/src/parser.c index ef8cec9..d9faaf6 100644 --- a/modules/menu/src/parser.c +++ b/modules/menu/src/parser.c @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -37,8 +38,8 @@ /****************************************************************************** ******* static functions ***************************************************** ******************************************************************************/ -static void parse_file (char* argument); -static void parse_iface (char* argument); +static void parse_file (char *argument); +static void parse_iface (char *argument); /****************************************************************************** @@ -106,10 +107,11 @@ void parser (int argc, char *argv[]) /****************************************************************************** ******* static functions ***************************************************** ******************************************************************************/ -static void parse_file (char* argument) +static void parse_file (char *argument) { - // FIXME FILE *fp; + + /* FIXME */ fp = fopen(argument, "r"); if (!fp) { printf("--file argument not valid\n"); @@ -123,13 +125,16 @@ static void parse_file (char* argument) } } -static void parse_iface (char* argument) +static void parse_iface (char *argument) { + menu_iface_mode = atoi(argument); user_iface_mode = menu_iface_mode; - if (menu_iface_mode < MENU_IFACE_CLUI || menu_iface_mode > MENU_IFACE_TUI) { + if ((menu_iface_mode < MENU_IFACE_CLUI) || + (menu_iface_mode > MENU_IFACE_TUI)) { printf("--iface argument not valid\n"); - printf("It must be an integer [%i U %i]\n", MENU_IFACE_CLUI, MENU_IFACE_TUI); + printf("It must be an integer [%i U %i]\n", + MENU_IFACE_CLUI, MENU_IFACE_TUI); exit(EXIT_FAILURE); } } diff --git a/modules/proc/inc/proc_coins.h b/modules/proc/inc/proc_coins.h index 7e29d7d..0052eb2 100644 --- a/modules/proc/inc/proc_coins.h +++ b/modules/proc/inc/proc_coins.h @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -34,7 +35,7 @@ /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ - int proc_coins (void); +int proc_coins (void); /****************************************************************************** diff --git a/modules/proc/inc/proc_coins.hpp b/modules/proc/inc/proc_coins.hpp index 9315324..f1b0824 100644 --- a/modules/proc/inc/proc_coins.hpp +++ b/modules/proc/inc/proc_coins.hpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -40,7 +41,7 @@ extern "C" { /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ - int proc_coins (void); +int proc_coins (void); /****************************************************************************** diff --git a/modules/proc/inc/proc_common.h b/modules/proc/inc/proc_common.h index 1d4077e..9f84504 100644 --- a/modules/proc/inc/proc_common.h +++ b/modules/proc/inc/proc_common.h @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -28,10 +29,10 @@ /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ - void proc_show_img (void); +void proc_show_img (void); - void clock_start (void); - void clock_stop (const char *txt); +void clock_start (void); +void clock_stop (const char *txt); /****************************************************************************** diff --git a/modules/proc/inc/proc_common.hpp b/modules/proc/inc/proc_common.hpp index 7332b84..5ba5faf 100644 --- a/modules/proc/inc/proc_common.hpp +++ b/modules/proc/inc/proc_common.hpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ diff --git a/modules/proc/inc/proc_iface.h b/modules/proc/inc/proc_iface.h index 8ce304c..1001702 100644 --- a/modules/proc/inc/proc_iface.h +++ b/modules/proc/inc/proc_iface.h @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -50,15 +51,15 @@ /****************************************************************************** ******* variables ************************************************************ ******************************************************************************/ - extern int proc_debug; - extern int proc_mode; +extern int proc_debug; +extern int proc_mode; /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ - int proc_iface_single (int action); - void proc_iface_series (void); +int proc_iface_single (int action); +void proc_iface_series (void); /****************************************************************************** diff --git a/modules/proc/inc/proc_iface.hpp b/modules/proc/inc/proc_iface.hpp index ede95f7..a0d0f7d 100644 --- a/modules/proc/inc/proc_iface.hpp +++ b/modules/proc/inc/proc_iface.hpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -56,15 +57,15 @@ extern "C" { /****************************************************************************** ******* variables ************************************************************ ******************************************************************************/ - extern int proc_debug; - extern int proc_mode; +extern int proc_debug; +extern int proc_mode; /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ - int proc_iface_single (int action); - void proc_iface_series (void); +int proc_iface_single (int action); +void proc_iface_series (void); /****************************************************************************** diff --git a/modules/proc/inc/proc_label.h b/modules/proc/inc/proc_label.h index a1091b8..d1b78f1 100644 --- a/modules/proc/inc/proc_label.h +++ b/modules/proc/inc/proc_label.h @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -36,7 +37,7 @@ /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ - int proc_label (void); +int proc_label (void); /****************************************************************************** diff --git a/modules/proc/inc/proc_label.hpp b/modules/proc/inc/proc_label.hpp index b456a55..ebb4446 100644 --- a/modules/proc/inc/proc_label.hpp +++ b/modules/proc/inc/proc_label.hpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -42,7 +43,7 @@ extern "C" { /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ - int proc_label (void); +int proc_label (void); /****************************************************************************** diff --git a/modules/proc/inc/proc_lighters.h b/modules/proc/inc/proc_lighters.h index f10c533..5771aad 100644 --- a/modules/proc/inc/proc_lighters.h +++ b/modules/proc/inc/proc_lighters.h @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -33,7 +34,7 @@ /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ - int proc_lighter (void); +int proc_lighter (void); /****************************************************************************** diff --git a/modules/proc/inc/proc_lighters.hpp b/modules/proc/inc/proc_lighters.hpp index cc16a79..7d69dc6 100644 --- a/modules/proc/inc/proc_lighters.hpp +++ b/modules/proc/inc/proc_lighters.hpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -39,7 +40,7 @@ extern "C" { /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ - int proc_lighter (void); +int proc_lighter (void); /****************************************************************************** diff --git a/modules/proc/inc/proc_objects.h b/modules/proc/inc/proc_objects.h index be841ba..ed865fd 100644 --- a/modules/proc/inc/proc_objects.h +++ b/modules/proc/inc/proc_objects.h @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -34,8 +35,8 @@ /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ - int proc_objects_calibrate (void); - int proc_objects (void); +int proc_objects_calibrate (void); +int proc_objects (void); /****************************************************************************** diff --git a/modules/proc/inc/proc_objects.hpp b/modules/proc/inc/proc_objects.hpp index 1a3084f..8794150 100644 --- a/modules/proc/inc/proc_objects.hpp +++ b/modules/proc/inc/proc_objects.hpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -40,8 +41,8 @@ extern "C" { /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ - int proc_objects_calibrate (void); - int proc_objects (void); +int proc_objects_calibrate (void); +int proc_objects (void); /****************************************************************************** diff --git a/modules/proc/inc/proc_resistor.h b/modules/proc/inc/proc_resistor.h index ca60a8a..dea2ed7 100644 --- a/modules/proc/inc/proc_resistor.h +++ b/modules/proc/inc/proc_resistor.h @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -36,7 +37,7 @@ /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ - int proc_resistor (void); +int proc_resistor (void); /****************************************************************************** diff --git a/modules/proc/inc/proc_resistor.hpp b/modules/proc/inc/proc_resistor.hpp index fce85d8..31f70cf 100644 --- a/modules/proc/inc/proc_resistor.hpp +++ b/modules/proc/inc/proc_resistor.hpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -42,7 +43,7 @@ extern "C" { /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ - int proc_resistor (void); +int proc_resistor (void); /****************************************************************************** diff --git a/modules/proc/src/proc_coins.cpp b/modules/proc/src/proc_coins.cpp index 8f26e71..dd347c9 100644 --- a/modules/proc/src/proc_coins.cpp +++ b/modules/proc/src/proc_coins.cpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ diff --git a/modules/proc/src/proc_common.cpp b/modules/proc/src/proc_common.cpp index 10a8a93..c1e19d5 100644 --- a/modules/proc/src/proc_common.cpp +++ b/modules/proc/src/proc_common.cpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ diff --git a/modules/proc/src/proc_iface.c b/modules/proc/src/proc_iface.c index 4372b3c..3948039 100644 --- a/modules/proc/src/proc_iface.c +++ b/modules/proc/src/proc_iface.c @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ diff --git a/modules/proc/src/proc_label.cpp b/modules/proc/src/proc_label.cpp index 57acf09..840e29e 100644 --- a/modules/proc/src/proc_label.cpp +++ b/modules/proc/src/proc_label.cpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ diff --git a/modules/proc/src/proc_lighters.cpp b/modules/proc/src/proc_lighters.cpp index f7519a3..a9543b8 100644 --- a/modules/proc/src/proc_lighters.cpp +++ b/modules/proc/src/proc_lighters.cpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ diff --git a/modules/proc/src/proc_objects.cpp b/modules/proc/src/proc_objects.cpp index 026cb25..6caa919 100644 --- a/modules/proc/src/proc_objects.cpp +++ b/modules/proc/src/proc_objects.cpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ diff --git a/modules/proc/src/proc_resistor.cpp b/modules/proc/src/proc_resistor.cpp index 58f1fe4..26ef739 100644 --- a/modules/proc/src/proc_resistor.cpp +++ b/modules/proc/src/proc_resistor.cpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ diff --git a/modules/save/inc/save.h b/modules/save/inc/save.h index a3388d7..4ab65ab 100644 --- a/modules/save/inc/save.h +++ b/modules/save/inc/save.h @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -41,30 +42,30 @@ /****************************************************************************** ******* variables ************************************************************ ******************************************************************************/ - extern char home_path [FILENAME_MAX]; - extern char user_prog_path [FILENAME_MAX]; - extern char saved_path [FILENAME_MAX]; - extern char labels_path [FILENAME_MAX]; - extern char labels_fail_path [FILENAME_MAX]; - extern char lighters_path [FILENAME_MAX]; - extern char lighters_fail_path [FILENAME_MAX]; - extern char objects_path [FILENAME_MAX]; - extern char objects_fail_path [FILENAME_MAX]; - extern char coins_path [FILENAME_MAX]; - extern char coins_fail_path [FILENAME_MAX]; - extern char resistors_path [FILENAME_MAX]; - extern char resistors_fail_path [FILENAME_MAX]; - extern char saved_name [FILENAME_MAX]; +extern char home_path [FILENAME_MAX]; +extern char user_prog_path [FILENAME_MAX]; +extern char saved_path [FILENAME_MAX]; +extern char labels_path [FILENAME_MAX]; +extern char labels_fail_path [FILENAME_MAX]; +extern char lighters_path [FILENAME_MAX]; +extern char lighters_fail_path [FILENAME_MAX]; +extern char objects_path [FILENAME_MAX]; +extern char objects_fail_path [FILENAME_MAX]; +extern char coins_path [FILENAME_MAX]; +extern char coins_fail_path [FILENAME_MAX]; +extern char resistors_path [FILENAME_MAX]; +extern char resistors_fail_path [FILENAME_MAX]; +extern char saved_name [FILENAME_MAX]; /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ - void save_init (void); - void save_cleanup (void); - void save_clr (void); - void load_image_file (const char *fpath, const char *fname); - void save_image_file (const char *fpath, const char *save_as); +void save_init (void); +void save_cleanup (void); +void save_clr (void); +void load_image_file (const char *fpath, const char *fname); +void save_image_file (const char *fpath, const char *save_as); /****************************************************************************** diff --git a/modules/save/inc/save.hpp b/modules/save/inc/save.hpp index d7640a1..bf60bca 100644 --- a/modules/save/inc/save.hpp +++ b/modules/save/inc/save.hpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -51,31 +52,31 @@ extern "C" { /****************************************************************************** ******* variables ************************************************************ ******************************************************************************/ - extern class cv::Mat image; - extern char home_path [FILENAME_MAX]; - extern char user_prog_path [FILENAME_MAX]; - extern char saved_path [FILENAME_MAX]; - extern char labels_path [FILENAME_MAX]; - extern char labels_fail_path [FILENAME_MAX]; - extern char lighters_path [FILENAME_MAX]; - extern char lighters_fail_path [FILENAME_MAX]; - extern char objects_path [FILENAME_MAX]; - extern char objects_fail_path [FILENAME_MAX]; - extern char coins_path [FILENAME_MAX]; - extern char coins_fail_path [FILENAME_MAX]; - extern char resistors_path [FILENAME_MAX]; - extern char resistors_fail_path [FILENAME_MAX]; - extern char saved_name [FILENAME_MAX]; +extern class cv::Mat image; +extern char home_path [FILENAME_MAX]; +extern char user_prog_path [FILENAME_MAX]; +extern char saved_path [FILENAME_MAX]; +extern char labels_path [FILENAME_MAX]; +extern char labels_fail_path [FILENAME_MAX]; +extern char lighters_path [FILENAME_MAX]; +extern char lighters_fail_path [FILENAME_MAX]; +extern char objects_path [FILENAME_MAX]; +extern char objects_fail_path [FILENAME_MAX]; +extern char coins_path [FILENAME_MAX]; +extern char coins_fail_path [FILENAME_MAX]; +extern char resistors_path [FILENAME_MAX]; +extern char resistors_fail_path [FILENAME_MAX]; +extern char saved_name [FILENAME_MAX]; /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ - void save_init (void); - void save_cleanup (void); - void save_clr (void); - void load_image_file (const char *fpath, const char *fname); - void save_image_file (const char *fpath, const char *save_as); +void save_init (void); +void save_cleanup (void); +void save_clr (void); +void load_image_file (const char *fpath, const char *fname); +void save_image_file (const char *fpath, const char *save_as); /****************************************************************************** diff --git a/modules/save/src/save.cpp b/modules/save/src/save.cpp index 6e948a8..f9e45f8 100644 --- a/modules/save/src/save.cpp +++ b/modules/save/src/save.cpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ diff --git a/modules/user/inc/user_clui.h b/modules/user/inc/user_clui.h index 916fe00..807c508 100644 --- a/modules/user/inc/user_clui.h +++ b/modules/user/inc/user_clui.h @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ diff --git a/modules/user/inc/user_iface.h b/modules/user/inc/user_iface.h index dde7b64..a994ae1 100644 --- a/modules/user/inc/user_iface.h +++ b/modules/user/inc/user_iface.h @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -136,22 +137,22 @@ /****************************************************************************** ******* variables ************************************************************ ******************************************************************************/ - extern int user_iface_mode; - extern struct User_Iface_Log user_iface_log; +extern int user_iface_mode; +extern struct User_Iface_Log user_iface_log; /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ - void user_iface_init (void); - void user_iface_cleanup (void); - void user_iface (void); - void user_iface_show_log (const char *title, const char *subtitle); - void user_iface_fname (const char *filepath, char *filename); - double user_iface_getdbl (double m, double def, double M, - const char *title, const char *help); - int64_t user_iface_getint (double m, int64_t def, double M, - const char *title, const char *help); +void user_iface_init (void); +void user_iface_cleanup (void); +void user_iface (void); +void user_iface_show_log (const char *title, const char *subtitle); +void user_iface_fname (const char *filepath, char *filename); +double user_iface_getdbl (double m, double def, double M, + const char *title, const char *help); +int64_t user_iface_getint (double m, int64_t def, double M, + const char *title, const char *help); /****************************************************************************** diff --git a/modules/user/inc/user_iface.hpp b/modules/user/inc/user_iface.hpp index d01f3a3..26fadfb 100644 --- a/modules/user/inc/user_iface.hpp +++ b/modules/user/inc/user_iface.hpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -142,22 +143,22 @@ extern "C" { /****************************************************************************** ******* variables ************************************************************ ******************************************************************************/ - extern int user_iface_mode; - extern struct User_Iface_Log user_iface_log; +extern int user_iface_mode; +extern struct User_Iface_Log user_iface_log; /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ - void user_iface_init (void); - void user_iface_cleanup (void); - void user_iface (void); - void user_iface_show_log (const char *title, const char *subtitle); - void user_iface_fname (const char *filepath, char *filename); - double user_iface_getdbl (double m, double def, double M, - const char *title, const char *help); - int64_t user_iface_getint (double m, int64_t def, double M, - const char *title, const char *help); +void user_iface_init (void); +void user_iface_cleanup (void); +void user_iface (void); +void user_iface_show_log (const char *title, const char *subtitle); +void user_iface_fname (const char *filepath, char *filename); +double user_iface_getdbl (double m, double def, double M, + const char *title, const char *help); +int64_t user_iface_getint (double m, int64_t def, double M, + const char *title, const char *help); /****************************************************************************** diff --git a/modules/user/inc/user_tui.h b/modules/user/inc/user_tui.h index c9c027c..64dd880 100644 --- a/modules/user/inc/user_tui.h +++ b/modules/user/inc/user_tui.h @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ diff --git a/modules/user/src/user_clui.c b/modules/user/src/user_clui.c index 218c14b..11e7db1 100644 --- a/modules/user/src/user_clui.c +++ b/modules/user/src/user_clui.c @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -70,22 +71,22 @@ int user_clui (const char *title, const char *subtitle) void user_clui_fname (const char *filepath, char *filename) { - puts("File name:"); - puts("Valid extensions: .bmp .dib .jpeg .png .pbm .pgm .ppm .tiff"); + printf("File name:\n"); + printf("Valid extensions: .bmp .dib .jpeg .png .pbm .pgm .ppm .tiff\n"); fgets(filename, FILENAME_MAX, stdin); alx_sscan_fname(filepath, filename, false, filename); } void user_clui_show_log (const char *title, const char *subtitle) { - puts("________________________________________________________________________________"); + printf("________________________________________________________________________________\n"); /* Board */ log_loop(); /* Subtitle & title */ printf("%s - %s\n", subtitle, title); - puts("--------------------------------------------------------------------------------"); + printf("--------------------------------------------------------------------------------\n"); } @@ -128,7 +129,10 @@ static int usr_input (void) fgets(buff, BUFF_SIZE, stdin); /* Interpret input */ - sscanf(buff, " %c%c%c%c%c", &ch[0], &ch[1], &ch[2], &ch[3], &ch[4]); + if (sscanf(buff, " %c%c%c%c%c", &ch[0], &ch[1], &ch[2], &ch[3], &ch[4])) { + ch[0] = '\0'; + } + action = USER_IFACE_ACT_FOO; switch (ch[0]) { case '+': action = USER_IFACE_ACT_APPLY; diff --git a/modules/user/src/user_iface.c b/modules/user/src/user_iface.c index f465944..46576f3 100644 --- a/modules/user/src/user_iface.c +++ b/modules/user/src/user_iface.c @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -43,8 +44,8 @@ struct User_Iface_Log user_iface_log; /****************************************************************************** ******* static functions ***************************************************** ******************************************************************************/ -void user_iface_act (int action); -void user_iface_show_ocr (void); +static void user_iface_act (int action); +static void user_iface_show_ocr (void); /****************************************************************************** @@ -188,7 +189,7 @@ double user_iface_getdbl (double m, double def, double M, /****************************************************************************** ******* static functions ***************************************************** ******************************************************************************/ -void user_iface_act (int action) +static void user_iface_act (int action) { if (action & USER_IFACE_ACT_USRI) { switch (action) { @@ -208,7 +209,7 @@ void user_iface_act (int action) } } -void user_iface_show_ocr (void) +static void user_iface_show_ocr (void) { switch (user_iface_mode) { case USER_IFACE_CLUI: diff --git a/modules/user/src/user_tui.c b/modules/user/src/user_tui.c index 83c729d..70220fc 100644 --- a/modules/user/src/user_tui.c +++ b/modules/user/src/user_tui.c @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ @@ -49,21 +50,30 @@ static void show_help (void); ******************************************************************************/ void user_tui_init (void) { + int h1; + int w1; + int r1; + int c1; + int h2; + int w2; + int r2; + int c2; + /* Use curses mode */ alx_resume_curses(); /* Dimensions: log */ - const int h1 = 54; - const int w1 = 40; - const int r1 = 0; - const int c1 = 30; - win_log = newwin(h1, w1, r1, c1); + h1 = 54; + w1 = 40; + r1 = 0; + c1 = 30; + win_log = newwin(h1, w1, r1, c1); /* Dimensions: help */ - const int h2 = 54; - const int w2 = 40; - const int r2 = 0; - const int c2 = 0; + h2 = 54; + w2 = 40; + r2 = 0; + c2 = 0; win_help = newwin(h2, w2, r2, c2); /* Activate keypad, don't echo input */ @@ -73,6 +83,7 @@ void user_tui_init (void) void user_tui_cleanup (void) { + /* Del wins & return to terminal mode */ alx_win_del(win_log); alx_win_del(win_help); @@ -82,7 +93,6 @@ void user_tui_cleanup (void) int user_tui (const char *title, const char *subtitle) { int action; -// action = USER_IFACE_ACT_FOO; show_help(); user_tui_show_log(title, subtitle); @@ -93,9 +103,10 @@ int user_tui (const char *title, const char *subtitle) void user_tui_fname (const char *filepath, char *filename) { - /* Input box */ int w; int r; + + /* Input box */ w = 75; r = 10; @@ -106,6 +117,7 @@ void user_tui_fname (const char *filepath, char *filename) void user_tui_show_log (const char *title, const char *subtitle) { + /* Clear & box */ werase(win_log); box(win_log, 0, 0); @@ -125,15 +137,17 @@ void user_tui_show_log (const char *title, const char *subtitle) double user_tui_getdbl (double m, double def, double M, const char *title, const char *help) { - /* Input box */ int w; int r; + double R; + + /* Input box */ w = 75; r = 10; /* Request int */ - double R; R = alx_w_getdbl(w, r, title, m, def, M, help); + return R; } @@ -143,17 +157,20 @@ int64_t user_tui_getint (double m, int64_t def, double M, /* Input box */ int w; int r; + int64_t i; + w = 75; r = 10; /* Request int */ - int64_t i; i = alx_w_getint(w, r, title, m, def, M, help); + return i; } void user_tui_show_ocr (void) { + alx_pause_curses(); printf("%s", img_ocr_text); @@ -705,12 +722,12 @@ static int usr_input (void) * * * * * * * * * */ static void show_help (void) { - /* Clear */ - werase(win_help); - int r; int c; + /* Clear */ + werase(win_help); + r = 0; c = 0; mvwprintw(win_help, r++, c, "Apply: %s", "Space"); diff --git a/src/main.cpp b/src/main.cpp index f672b68..c213594 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,5 +1,6 @@ /****************************************************************************** * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * ******************************************************************************/ -- cgit v1.2.3 From 00997aad869e5b6ef6863dc0f5eab284bdf17b18 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Sat, 5 Jan 2019 15:55:19 +0100 Subject: Fix bugs: handle format truncation && zero lenght strings substituted by str[0]='\0'; --- Makefile | 13 ++++++------- modules/about/src/about.c | 37 +++++++++++++++++++++++++++---------- modules/image/src/img_ocr.c | 7 ++++++- modules/menu/src/parser.c | 2 +- modules/proc/src/proc_iface.c | 25 +++++++++++++++++-------- 5 files changed, 57 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index 2d63163..772c7b1 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ #!/usr/bin/make -f VERSION = 2 -PATCHLEVEL = ~b5 -SUBLEVEL = +PATCHLEVEL = 0 +SUBLEVEL = 0 EXTRAVERSION = NAME = @@ -66,7 +66,7 @@ export BUILD_VERBOSE MAKEFLAGS += --no-print-directory ################################################################################ -PROGRAMVERSION = $(VERSION)$(if $(PATCHLEVEL),$(PATCHLEVEL)$(if $(SUBLEVEL),$(SUBLEVEL)))$(EXTRAVERSION) +PROGRAMVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION) export PROGRAMVERSION ################################################################################ @@ -86,6 +86,7 @@ export LD ################################################################################ # cflags CFLAGS_STD = -std=c11 +CFLAGS_STD += -Wpedantic CFLAGS_OPT = -O3 CFLAGS_OPT += -march=native @@ -94,10 +95,8 @@ CFLAGS_W = -Wall CFLAGS_W += -Wextra CFLAGS_W += -Wstrict-prototypes CFLAGS_W += -Werror -CFLAGS_W += -Wno-format-truncation -CFLAGS_W += -Wno-format-zero-length -#CFLAGS_W += -Wno-unused-function -CFLAGS_W += -Wno-unused-parameter +#CFLAGS_W += -Wno-error=unused-function +#CFLAGS_W += -Wno-error=unused-parameter CFLAGS_PKG = `pkg-config --cflags ncurses` CFLAGS_PKG += `pkg-config --cflags opencv` diff --git a/modules/about/src/about.c b/modules/about/src/about.c index daae65a..fd03c68 100644 --- a/modules/about/src/about.c +++ b/modules/about/src/about.c @@ -49,28 +49,45 @@ void snprint_share_file (char *dest, int destsize, int share_file) switch (share_file) { case SHARE_COPYRIGHT: - snprintf(file_name, FILENAME_MAX, "%s/%s", - share_path, "COPYRIGHT.txt"); + if (snprintf(file_name, FILENAME_MAX, "%s/%s", + share_path, "COPYRIGHT.txt")) { + goto err_path; + } break; case SHARE_DISCLAIMER: - snprintf(file_name, FILENAME_MAX, "%s/%s", - share_path, "DISCLAIMER.txt"); + if (snprintf(file_name, FILENAME_MAX, "%s/%s", + share_path, "DISCLAIMER.txt")) { + goto err_path; + } break; case SHARE_HELP: - snprintf(file_name, FILENAME_MAX, "%s/%s", - share_path, "HELP.txt"); + if (snprintf(file_name, FILENAME_MAX, "%s/%s", + share_path, "HELP.txt")) { + goto err_path; + } break; case SHARE_LICENSE: - snprintf(file_name, FILENAME_MAX, "%s/%s", - share_path, "LICENSE.txt"); + if (snprintf(file_name, FILENAME_MAX, "%s/%s", + share_path, "LICENSE.txt")) { + goto err_path; + } break; case SHARE_USAGE: - snprintf(file_name, FILENAME_MAX, "%s/%s", - share_path, "USAGE.txt"); + if (snprintf(file_name, FILENAME_MAX, "%s/%s", + share_path, "USAGE.txt")) { + goto err_path; + } break; } alx_snprint_file(dest, destsize, file_name); + + return; + + +err_path: + printf("Path is too large and has been truncated\n"); + printf("File could not be shown!\n"); } void print_share_file (int share_file) diff --git a/modules/image/src/img_ocr.c b/modules/image/src/img_ocr.c index 35e0db3..0f49b7c 100644 --- a/modules/image/src/img_ocr.c +++ b/modules/image/src/img_ocr.c @@ -88,7 +88,12 @@ static void img_ocr_read (void *data) conf = data_cast->conf; switch (conf) { case IMG_IFACE_OCR_CONF_PRICE: - snprintf(conf_str, 6, "%s/%s", share_path, "price"); + if (snprintf(conf_str, FILENAME_MAX, "%s/%s", + share_path, "price")) { + printf("Path is too large and has been truncated\n"); + printf("Price configuration was not possible!\n"); + conf = IMG_IFACE_OCR_CONF_NONE; + } break; } diff --git a/modules/menu/src/parser.c b/modules/menu/src/parser.c index d9faaf6..a7ed4a8 100644 --- a/modules/menu/src/parser.c +++ b/modules/menu/src/parser.c @@ -120,7 +120,7 @@ static void parse_file (char *argument) } else { fclose(fp); - sprintf(saved_path, ""); + saved_path[0] = '\0'; snprintf(saved_name, FILENAME_MAX, "%s", argument); } } diff --git a/modules/proc/src/proc_iface.c b/modules/proc/src/proc_iface.c index 3948039..157b17b 100644 --- a/modules/proc/src/proc_iface.c +++ b/modules/proc/src/proc_iface.c @@ -171,8 +171,10 @@ void proc_iface_series (void) wh = true; for (; wh; i++) { - snprintf(file_name, FILENAME_MAX, "%s%04i%s", - file_basename, i, file_ext); + if (snprintf(file_name, FILENAME_MAX, "%s%04i%s", + file_basename, i, file_ext)) { + goto err_path; + } file_error = alx_sscan_fname(proc_path, file_name, true, file_name); @@ -190,13 +192,15 @@ void proc_iface_series (void) if (proc_error) { /* Save failed image into file */ proc_show_img(); - snprintf(save_error_as, FILENAME_MAX, - "%s%0*i_err%s", - file_basename, - num_len, i, - file_ext); + if (snprintf(save_error_as, FILENAME_MAX, + "%s%0*i_err%s", + file_basename, + num_len, i, + file_ext)) { + goto err_path; + } save_image_file(proc_fail_path, - save_error_as); + save_error_as); } /* Show log */ @@ -215,6 +219,11 @@ void proc_iface_series (void) proc_mode--; } } + + return; + +err_path: + printf("Path is too large and has been truncated\n"); } -- cgit v1.2.3 From 320d2bd71a2a78a5c9bc7bc93a9bcc93fb0d9beb Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Sat, 5 Jan 2019 19:12:45 +0100 Subject: Fix bugs in c++ code: -Wall -Werror --- Makefile | 12 ++-- modules/about/tmp/Makefile | 6 +- modules/proc/src/proc_iface.c | 4 ++ modules/proc/src/proc_lighters.cpp | 6 +- modules/save/src/save.cpp | 115 +++++++++++++++++++++++++++++++------ 5 files changed, 112 insertions(+), 31 deletions(-) diff --git a/Makefile b/Makefile index 772c7b1..2753526 100644 --- a/Makefile +++ b/Makefile @@ -95,6 +95,7 @@ CFLAGS_W = -Wall CFLAGS_W += -Wextra CFLAGS_W += -Wstrict-prototypes CFLAGS_W += -Werror +#CFLAGS_W += -Wno-error=format-truncation #CFLAGS_W += -Wno-error=unused-function #CFLAGS_W += -Wno-error=unused-parameter @@ -128,10 +129,9 @@ CXXFLAGS_OPT += -march=native CXXFLAGS_W = -Wall CXXFLAGS_W += -Wextra CXXFLAGS_W += -Werror -CXXFLAGS_W += -Wno-format-truncation -CXXFLAGS_W += -Wno-format-zero-length -CXXFLAGS_W += -Wno-unused-function -CXXFLAGS_W += -Wno-unused-parameter +CXXFLAGS_W += -Wno-error=format-truncation +CXXFLAGS_W += -Wno-error=unused-function +CXXFLAGS_W += -Wno-error=unused-parameter CXXFLAGS_PKG = `pkg-config --cflags ncurses` CXXFLAGS_PKG += `pkg-config --cflags opencv` @@ -252,9 +252,9 @@ install: uninstall PHONY += uninstall uninstall: @echo " Clean old installations:" - @echo ' RM binary' + @echo " RM bin" $(Q)rm -f $(DESTDIR)/$(INSTALL_BIN_DIR)/$(BIN_NAME) - @echo ' RM share/*' + @echo " RM -r $(INSTALL_SHARE_DIR)/$(SHARE_DIR)/" $(Q)rm -f -r $(DESTDIR)/$(INSTALL_SHARE_DIR)/$(SHARE_DIR)/ @echo " Done" @echo diff --git a/modules/about/tmp/Makefile b/modules/about/tmp/Makefile index 5516dd7..d55d1d8 100644 --- a/modules/about/tmp/Makefile +++ b/modules/about/tmp/Makefile @@ -29,16 +29,16 @@ all: $(ALL) about_mod.o: $(_ALL) - $(Q)$(LD) -r $^ -o $@ @echo " LD $@" + $(Q)$(LD) -r $^ -o $@ about.s: $(ABOU_DEPS) - $(Q)$(CC) $(CFLAGS) $(ABOU_INC_DIRS) -S $< -o $@ @echo " CC $@" + $(Q)$(CC) $(CFLAGS) $(ABOU_INC_DIRS) -S $< -o $@ about.o: about.s - $(Q)$(AS) $< -o $@ @echo " AS $@" + $(Q)$(AS) $< -o $@ clean: diff --git a/modules/proc/src/proc_iface.c b/modules/proc/src/proc_iface.c index 157b17b..7a085d0 100644 --- a/modules/proc/src/proc_iface.c +++ b/modules/proc/src/proc_iface.c @@ -13,6 +13,8 @@ #include /* snprintf() & fflush() */ #include + /* exit() */ + #include /* clock_t & clock() & CLOCKS_PER_SEC */ #include @@ -222,8 +224,10 @@ void proc_iface_series (void) return; + err_path: printf("Path is too large and has been truncated\n"); + exit(EXIT_FAILURE); } diff --git a/modules/proc/src/proc_lighters.cpp b/modules/proc/src/proc_lighters.cpp index a9543b8..69b7e4b 100644 --- a/modules/proc/src/proc_lighters.cpp +++ b/modules/proc/src/proc_lighters.cpp @@ -102,7 +102,7 @@ static void lighter_segment_body (int i); static void lighter_rm_body (int i); static void lighter_crop_head (int i); static void lighter_chk_hood (int i); -static void lighter_rm_hood (int i); +static void lighter_rm_hood (void); static void lighter_chk_fork (int i); static void lighter_chk_wheel (int i); static void lighter_chk_valve (int i); @@ -141,7 +141,7 @@ int proc_lighter (void) lighter_crop_head(i); lighter_chk_hood(i); if (lighter[i].hood_ != HOOD_NOT_PRESENT) { - lighter_rm_hood(i); + lighter_rm_hood(); } else { proc_load_mem(7); proc_save_mem(8); @@ -367,7 +367,7 @@ static void lighter_chk_hood (int i) } } -static void lighter_rm_hood (int i) +static void lighter_rm_hood (void) { proc_load_mem(7); diff --git a/modules/save/src/save.cpp b/modules/save/src/save.cpp index f9e45f8..2abb58c 100644 --- a/modules/save/src/save.cpp +++ b/modules/save/src/save.cpp @@ -56,20 +56,58 @@ char saved_name [FILENAME_MAX]; ******************************************************************************/ void save_init (void) { - snprintf(home_path, FILENAME_MAX, "%s/", getenv(ENV_HOME)); - snprintf(user_prog_path, FILENAME_MAX, "%s/%s/", home_path, USER_PROG_DIR); - snprintf(saved_path, FILENAME_MAX, "%s/%s/", home_path, USER_SAVED_DIR); - snprintf(labels_path, FILENAME_MAX, "%s/%s/", home_path, USER_LABELS_DIR); - snprintf(labels_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_LABELS_FAIL_DIR); - snprintf(lighters_path, FILENAME_MAX, "%s/%s/", home_path, USER_LIGHTERS_DIR); - snprintf(lighters_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_LIGHTERS_FAIL_DIR); - snprintf(objects_path, FILENAME_MAX, "%s/%s/", home_path, USER_OBJECTS_DIR); - snprintf(objects_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_OBJECTS_FAIL_DIR); - snprintf(coins_path, FILENAME_MAX, "%s/%s/", home_path, USER_COINS_DIR); - snprintf(coins_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_COINS_FAIL_DIR); - snprintf(resistors_path, FILENAME_MAX, "%s/%s/", home_path, USER_RESISTORS_DIR); - snprintf(resistors_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_RESISTORS_FAIL_DIR); - sprintf(saved_name, ""); + if (snprintf(home_path, FILENAME_MAX, "%s/", getenv(ENV_HOME))) { + goto err_path; + } + if (snprintf(user_prog_path, FILENAME_MAX, "%s/%s/", + home_path, USER_PROG_DIR)) { + goto err_path; + } + if (snprintf(saved_path, FILENAME_MAX, "%s/%s/", + home_path, USER_SAVED_DIR)) { + goto err_path; + } + if (snprintf(labels_path, FILENAME_MAX, "%s/%s/", + home_path, USER_LABELS_DIR)) { + goto err_path; + } + if (snprintf(labels_fail_path, FILENAME_MAX, "%s/%s/", + home_path, USER_LABELS_FAIL_DIR)) { + goto err_path; + } + if (snprintf(lighters_path, FILENAME_MAX, "%s/%s/", + home_path, USER_LIGHTERS_DIR)) { + goto err_path; + } + if (snprintf(lighters_fail_path, FILENAME_MAX, "%s/%s/", + home_path, USER_LIGHTERS_FAIL_DIR)) { + goto err_path; + } + if (snprintf(objects_path, FILENAME_MAX, "%s/%s/", + home_path, USER_OBJECTS_DIR)) { + goto err_path; + } + if (snprintf(objects_fail_path, FILENAME_MAX, "%s/%s/", + home_path, USER_OBJECTS_FAIL_DIR)) { + goto err_path; + } + if (snprintf(coins_path, FILENAME_MAX, "%s/%s/", + home_path, USER_COINS_DIR)) { + goto err_path; + } + if (snprintf(coins_fail_path, FILENAME_MAX, "%s/%s/", + home_path, USER_COINS_FAIL_DIR)) { + goto err_path; + } + if (snprintf(resistors_path, FILENAME_MAX, "%s/%s/", + home_path, USER_RESISTORS_DIR)) { + goto err_path; + } + if (snprintf(resistors_fail_path, FILENAME_MAX, "%s/%s/", + home_path, USER_RESISTORS_FAIL_DIR)) { + goto err_path; + } + saved_name[0] = '\0'; int err; err = mkdir(user_prog_path, 0700); @@ -96,11 +134,28 @@ void save_init (void) mkdir(saved_path, 0700); mkdir(labels_path, 0700); mkdir(labels_fail_path, 0700); + + return; + + +err_path: + printf("Path is too large and has been truncated\n"); + exit(EXIT_FAILURE); } void save_clr (void) { - snprintf(saved_path, FILENAME_MAX, "%s/%s/", home_path, USER_SAVED_DIR); + if (snprintf(saved_path, FILENAME_MAX, "%s/%s/", + home_path, USER_SAVED_DIR)) { + goto err_path; + } + + return; + + +err_path: + printf("Path is too large and has been truncated\n"); + exit(EXIT_FAILURE); } void load_image_file (const char *fpath, const char *fname) @@ -129,7 +184,9 @@ void load_image_file (const char *fpath, const char *fname) } /* File name */ - snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name); + if (snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name)) { + goto err_path; + } /* Load image */ image = cv::imread(file_name, CV_LOAD_IMAGE_COLOR); @@ -139,6 +196,13 @@ void load_image_file (const char *fpath, const char *fname) printf("Could not load file: %s\n", file_name); // exit(0); } + + return; + + +err_path: + printf("Path is too large and has been truncated\n"); + exit(EXIT_FAILURE); } void save_cleanup (void) @@ -173,24 +237,37 @@ void save_image_file (const char *fpath, const char *save_as) } /* Prepend the path */ - snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name); + if (snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name)) { + goto err_path; + } fp = fopen(file_name, "r"); if (fp) { /* Name in use; ask once more */ fclose(fp); user_iface_fname(saved_path, saved_name); - snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name); + if (snprintf(file_name, FILENAME_MAX, "%s/%s", + file_path, saved_name)) { + goto err_path; + } } /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "%s", saved_name); + (void)snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "%s", saved_name); user_iface_log.lvl[user_iface_log.len] = 2; (user_iface_log.len)++; /* Write to a new file */ cv::imwrite(file_name, image); + + return; + + +err_path: + printf("Path is too large and has been truncated\n"); + exit(EXIT_FAILURE); } -- cgit v1.2.3 From bc49dc725201e6d2e791760873ca7f474bf01c6c Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Mon, 7 Jan 2019 04:38:50 +0100 Subject: Fix style --- modules/about/src/about.c | 14 ++++++++++++-- modules/proc/src/proc_coins.cpp | 3 +-- modules/save/src/save.cpp | 41 ++++++++++++++++++++++------------------- 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/modules/about/src/about.c b/modules/about/src/about.c index fd03c68..b5637f5 100644 --- a/modules/about/src/about.c +++ b/modules/about/src/about.c @@ -10,6 +10,7 @@ /* Standard C ----------------------------------------------------------------*/ /* printf() */ #include + #include /* libalx --------------------------------------------------------------------*/ /* alx_snprint_file() */ @@ -39,8 +40,17 @@ char share_path [FILENAME_MAX]; ******************************************************************************/ void about_init (void) { - snprintf(share_path, FILENAME_MAX, "%s/%s/", - INSTALL_SHARE_DIR, SHARE_DIR); + if (snprintf(share_path, FILENAME_MAX, "%s/%s/", + INSTALL_SHARE_DIR, SHARE_DIR)) { + goto err_path; + } + + return; + + +err_path: + printf("Path is too large and has been truncated\n"); + exit(EXIT_FAILURE); } void snprint_share_file (char *dest, int destsize, int share_file) diff --git a/modules/proc/src/proc_coins.cpp b/modules/proc/src/proc_coins.cpp index dd347c9..0b1398d 100644 --- a/modules/proc/src/proc_coins.cpp +++ b/modules/proc/src/proc_coins.cpp @@ -15,7 +15,7 @@ /* openCV */ #include -/* libalx ------------------------------------------------------------------*/ +/* libalx --------------------------------------------------------------------*/ /* alx_maximum_u8() */ #include "alx_math.hpp" @@ -56,7 +56,6 @@ struct Coins_Properties { ******* variables ************************************************************ ******************************************************************************/ /* Global --------------------------------------------------------------------*/ - /* Static --------------------------------------------------------------------*/ static class std::vector >> contours; static class cv::Mat hierarchy; diff --git a/modules/save/src/save.cpp b/modules/save/src/save.cpp index 2abb58c..90941fe 100644 --- a/modules/save/src/save.cpp +++ b/modules/save/src/save.cpp @@ -12,7 +12,7 @@ #include /* fscanf() & fprintf() & FILE & FILENAME_MAX & snprintf() */ #include - /* getenv() */ + /* getenv() & exit() */ #include /* Linux ---------------------------------------------------------------------*/ @@ -34,28 +34,30 @@ /****************************************************************************** ******* variables ************************************************************ ******************************************************************************/ -class cv::Mat image; -char home_path [FILENAME_MAX]; -char user_prog_path [FILENAME_MAX]; -char saved_path [FILENAME_MAX]; -char labels_path [FILENAME_MAX]; -char labels_fail_path [FILENAME_MAX]; -char lighters_path [FILENAME_MAX]; -char lighters_fail_path [FILENAME_MAX]; -char objects_path [FILENAME_MAX]; -char objects_fail_path [FILENAME_MAX]; -char coins_path [FILENAME_MAX]; -char coins_fail_path [FILENAME_MAX]; -char resistors_path [FILENAME_MAX]; -char resistors_fail_path [FILENAME_MAX]; -char saved_name [FILENAME_MAX]; + class cv::Mat image; + char home_path [FILENAME_MAX]; + char user_prog_path [FILENAME_MAX]; + char saved_path [FILENAME_MAX]; + char labels_path [FILENAME_MAX]; + char labels_fail_path [FILENAME_MAX]; + char lighters_path [FILENAME_MAX]; + char lighters_fail_path [FILENAME_MAX]; + char objects_path [FILENAME_MAX]; + char objects_fail_path [FILENAME_MAX]; + char coins_path [FILENAME_MAX]; + char coins_fail_path [FILENAME_MAX]; + char resistors_path [FILENAME_MAX]; + char resistors_fail_path [FILENAME_MAX]; + char saved_name [FILENAME_MAX]; /****************************************************************************** - ******* main ***************************************************************** + ******* global functions ***************************************************** ******************************************************************************/ void save_init (void) { + int err; + if (snprintf(home_path, FILENAME_MAX, "%s/", getenv(ENV_HOME))) { goto err_path; } @@ -109,10 +111,10 @@ void save_init (void) } saved_name[0] = '\0'; - int err; err = mkdir(user_prog_path, 0700); if (!err) { + ; } else { switch (errno) { @@ -145,6 +147,7 @@ err_path: void save_clr (void) { + if (snprintf(saved_path, FILENAME_MAX, "%s/%s/", home_path, USER_SAVED_DIR)) { goto err_path; @@ -207,7 +210,7 @@ err_path: void save_cleanup (void) { - /* Free old image */ + image.release(); } -- cgit v1.2.3 From 0789c82bbbdec16f8e3cb33f57eae2072b9138ad Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Mon, 7 Jan 2019 04:51:15 +0100 Subject: Fix bug: return value of snprintf --- modules/about/src/about.c | 18 ++++++++++----- modules/proc/src/proc_iface.c | 11 +++++---- modules/save/src/save.cpp | 53 +++++++++++++++++++++++++++++-------------- 3 files changed, 54 insertions(+), 28 deletions(-) diff --git a/modules/about/src/about.c b/modules/about/src/about.c index b5637f5..662ee42 100644 --- a/modules/about/src/about.c +++ b/modules/about/src/about.c @@ -41,7 +41,8 @@ char share_path [FILENAME_MAX]; void about_init (void) { if (snprintf(share_path, FILENAME_MAX, "%s/%s/", - INSTALL_SHARE_DIR, SHARE_DIR)) { + INSTALL_SHARE_DIR, + SHARE_DIR) >= FILENAME_MAX) { goto err_path; } @@ -60,31 +61,36 @@ void snprint_share_file (char *dest, int destsize, int share_file) switch (share_file) { case SHARE_COPYRIGHT: if (snprintf(file_name, FILENAME_MAX, "%s/%s", - share_path, "COPYRIGHT.txt")) { + share_path, + "COPYRIGHT.txt") >= FILENAME_MAX) { goto err_path; } break; case SHARE_DISCLAIMER: if (snprintf(file_name, FILENAME_MAX, "%s/%s", - share_path, "DISCLAIMER.txt")) { + share_path, + "DISCLAIMER.txt") >= FILENAME_MAX) { goto err_path; } break; case SHARE_HELP: if (snprintf(file_name, FILENAME_MAX, "%s/%s", - share_path, "HELP.txt")) { + share_path, + "HELP.txt") >= FILENAME_MAX) { goto err_path; } break; case SHARE_LICENSE: if (snprintf(file_name, FILENAME_MAX, "%s/%s", - share_path, "LICENSE.txt")) { + share_path, + "LICENSE.txt") >= FILENAME_MAX) { goto err_path; } break; case SHARE_USAGE: if (snprintf(file_name, FILENAME_MAX, "%s/%s", - share_path, "USAGE.txt")) { + share_path, + "USAGE.txt") >= FILENAME_MAX) { goto err_path; } break; diff --git a/modules/proc/src/proc_iface.c b/modules/proc/src/proc_iface.c index 7a085d0..6767e26 100644 --- a/modules/proc/src/proc_iface.c +++ b/modules/proc/src/proc_iface.c @@ -174,7 +174,8 @@ void proc_iface_series (void) wh = true; for (; wh; i++) { if (snprintf(file_name, FILENAME_MAX, "%s%04i%s", - file_basename, i, file_ext)) { + file_basename, + i, file_ext) >= FILENAME_MAX) { goto err_path; } @@ -195,10 +196,10 @@ void proc_iface_series (void) /* Save failed image into file */ proc_show_img(); if (snprintf(save_error_as, FILENAME_MAX, - "%s%0*i_err%s", - file_basename, - num_len, i, - file_ext)) { + "%s%0*i_err%s", + file_basename, + num_len, i, + file_ext) >= FILENAME_MAX) { goto err_path; } save_image_file(proc_fail_path, diff --git a/modules/save/src/save.cpp b/modules/save/src/save.cpp index 90941fe..30c7ff3 100644 --- a/modules/save/src/save.cpp +++ b/modules/save/src/save.cpp @@ -58,55 +58,68 @@ void save_init (void) { int err; - if (snprintf(home_path, FILENAME_MAX, "%s/", getenv(ENV_HOME))) { + if (snprintf(home_path, FILENAME_MAX, "%s/", + getenv(ENV_HOME)) >= FILENAME_MAX) { goto err_path; } if (snprintf(user_prog_path, FILENAME_MAX, "%s/%s/", - home_path, USER_PROG_DIR)) { + home_path, + USER_PROG_DIR) >= FILENAME_MAX) { goto err_path; } if (snprintf(saved_path, FILENAME_MAX, "%s/%s/", - home_path, USER_SAVED_DIR)) { + home_path, + USER_SAVED_DIR) >= FILENAME_MAX) { goto err_path; } if (snprintf(labels_path, FILENAME_MAX, "%s/%s/", - home_path, USER_LABELS_DIR)) { + home_path, + USER_LABELS_DIR) >= FILENAME_MAX) { goto err_path; } if (snprintf(labels_fail_path, FILENAME_MAX, "%s/%s/", - home_path, USER_LABELS_FAIL_DIR)) { + home_path, + USER_LABELS_FAIL_DIR) >= FILENAME_MAX) { goto err_path; } if (snprintf(lighters_path, FILENAME_MAX, "%s/%s/", - home_path, USER_LIGHTERS_DIR)) { + home_path, + USER_LIGHTERS_DIR) >= FILENAME_MAX) { goto err_path; } if (snprintf(lighters_fail_path, FILENAME_MAX, "%s/%s/", - home_path, USER_LIGHTERS_FAIL_DIR)) { + home_path, + USER_LIGHTERS_FAIL_DIR) >= FILENAME_MAX) { goto err_path; } if (snprintf(objects_path, FILENAME_MAX, "%s/%s/", - home_path, USER_OBJECTS_DIR)) { + home_path, + USER_OBJECTS_DIR) >= FILENAME_MAX) { goto err_path; } if (snprintf(objects_fail_path, FILENAME_MAX, "%s/%s/", - home_path, USER_OBJECTS_FAIL_DIR)) { + home_path, + USER_OBJECTS_FAIL_DIR) >= FILENAME_MAX) { goto err_path; } if (snprintf(coins_path, FILENAME_MAX, "%s/%s/", - home_path, USER_COINS_DIR)) { + home_path, + USER_COINS_DIR) >= FILENAME_MAX) { goto err_path; } if (snprintf(coins_fail_path, FILENAME_MAX, "%s/%s/", - home_path, USER_COINS_FAIL_DIR)) { + home_path, + USER_COINS_FAIL_DIR) >= FILENAME_MAX) { goto err_path; } if (snprintf(resistors_path, FILENAME_MAX, "%s/%s/", - home_path, USER_RESISTORS_DIR)) { + home_path, + USER_RESISTORS_DIR) >= FILENAME_MAX) { goto err_path; } if (snprintf(resistors_fail_path, FILENAME_MAX, "%s/%s/", - home_path, USER_RESISTORS_FAIL_DIR)) { + home_path, + USER_RESISTORS_FAIL_DIR) >= FILENAME_MAX) { goto err_path; } saved_name[0] = '\0'; @@ -149,7 +162,8 @@ void save_clr (void) { if (snprintf(saved_path, FILENAME_MAX, "%s/%s/", - home_path, USER_SAVED_DIR)) { + home_path, + USER_SAVED_DIR) >= FILENAME_MAX) { goto err_path; } @@ -187,7 +201,9 @@ void load_image_file (const char *fpath, const char *fname) } /* File name */ - if (snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name)) { + if (snprintf(file_name, FILENAME_MAX, "%s/%s", + file_path, + saved_name) >= FILENAME_MAX) { goto err_path; } @@ -240,7 +256,9 @@ void save_image_file (const char *fpath, const char *save_as) } /* Prepend the path */ - if (snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name)) { + if (snprintf(file_name, FILENAME_MAX, "%s/%s", + file_path, + saved_name) >= FILENAME_MAX) { goto err_path; } @@ -250,7 +268,8 @@ void save_image_file (const char *fpath, const char *save_as) fclose(fp); user_iface_fname(saved_path, saved_name); if (snprintf(file_name, FILENAME_MAX, "%s/%s", - file_path, saved_name)) { + file_path, + saved_name) >= FILENAME_MAX) { goto err_path; } } -- cgit v1.2.3 From 6866215b3fce7a768ce8ccaab7c4f73a2e435a81 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Mon, 7 Jan 2019 18:44:02 +0100 Subject: Update libalx --- libalx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libalx b/libalx index e67da56..207eade 160000 --- a/libalx +++ b/libalx @@ -1 +1 @@ -Subproject commit e67da562ef5e2dda524c86da3367d537caee4d4c +Subproject commit 207eade1bd19c0934da8f64571a1bff58a2d29f8 -- cgit v1.2.3 From cc6a18ae9748eccfc6dc6df404b2f69a99418937 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Tue, 8 Jan 2019 00:57:08 +0100 Subject: Fix style; Add const to most structs; Fix minor bugs --- Makefile | 12 +- bin/Makefile | 6 +- modules/image/inc/img_alx.hpp | 2 +- modules/image/inc/img_calib3d.hpp | 2 +- modules/image/inc/img_cv.hpp | 2 +- modules/image/inc/img_iface.h | 2 +- modules/image/inc/img_iface.hpp | 14 +- modules/image/inc/img_ocr.h | 2 +- modules/image/inc/img_ocr.hpp | 2 +- modules/image/inc/img_orb.hpp | 2 +- modules/image/inc/img_zbar.hpp | 2 +- modules/image/src/img_alx.cpp | 2 +- modules/image/src/img_calib3d.cpp | 32 +-- modules/image/src/img_cv.cpp | 475 ++++++++++++++++---------------------- modules/image/src/img_iface.cpp | 465 ++++++++++++++++++++----------------- modules/image/src/img_ocr.c | 15 +- modules/image/src/img_orb.cpp | 6 +- modules/image/src/img_zbar.cpp | 24 +- modules/image/tmp/Makefile | 32 +-- modules/proc/inc/proc_common.hpp | 10 +- modules/proc/src/proc_common.cpp | 68 +++--- 21 files changed, 572 insertions(+), 605 deletions(-) diff --git a/Makefile b/Makefile index 2753526..4e409a2 100644 --- a/Makefile +++ b/Makefile @@ -71,17 +71,19 @@ export PROGRAMVERSION ################################################################################ # Make variables (CC, etc...) - CC = gcc - CXX = g++ - AS = as - AR = ar - LD = ld + CC = gcc + CXX = g++ + AS = as + AR = ar + LD = ld + SZ = size export CC export CXX export AS export AR export LD +export SZ ################################################################################ # cflags diff --git a/bin/Makefile b/bin/Makefile index 79add73..e1f17df 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -9,7 +9,7 @@ MODULES_TMP_DIR = $(MODULES_DIR)/tmp/ TMP_DIR = $(MAIN_DIR)/tmp/ # dependencies -ALL = $(BIN_NAME) +ALL = $(BIN_NAME) size MAIN_OBJ_MODULES = modules.o MAIN_OBJS = $(TMP_DIR)/main.o \ @@ -36,6 +36,10 @@ $(BIN_NAME): $(MAIN_OBJS) $(MAIN_LIBS) @echo " CXX $@" $(Q)$(CXX) $(MAIN_OBJS) -o $@ $(STATIC_LIBS) $(LIBS) +size: $(BIN_NAME) + @echo " SZ $(BIN_NAME)" + $(Q)$(SZ) $(BIN_NAME) + clean: @echo " RM $(ALL)" diff --git a/modules/image/inc/img_alx.hpp b/modules/image/inc/img_alx.hpp index 6eb76ce..0c2558a 100644 --- a/modules/image/inc/img_alx.hpp +++ b/modules/image/inc/img_alx.hpp @@ -39,7 +39,7 @@ /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ -void img_alx_act (class cv::Mat *imgptr, int action, void *data); +void img_alx_act (class cv::Mat *imgptr, int action, const void *data); /****************************************************************************** diff --git a/modules/image/inc/img_calib3d.hpp b/modules/image/inc/img_calib3d.hpp index 87ff946..a2c9f7c 100644 --- a/modules/image/inc/img_calib3d.hpp +++ b/modules/image/inc/img_calib3d.hpp @@ -33,7 +33,7 @@ /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ -void img_calib3d_act (class cv::Mat *imgptr, int action, void *data); +void img_calib3d_act (class cv::Mat *imgptr, int action, const void *data); /****************************************************************************** diff --git a/modules/image/inc/img_cv.hpp b/modules/image/inc/img_cv.hpp index f1aa538..1840ca6 100644 --- a/modules/image/inc/img_cv.hpp +++ b/modules/image/inc/img_cv.hpp @@ -58,7 +58,7 @@ /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ -void img_cv_act (class cv::Mat *imgptr, int action, void *data); +void img_cv_act (class cv::Mat *imgptr, int action, const void *data); /****************************************************************************** diff --git a/modules/image/inc/img_iface.h b/modules/image/inc/img_iface.h index c071971..1b755aa 100644 --- a/modules/image/inc/img_iface.h +++ b/modules/image/inc/img_iface.h @@ -168,7 +168,7 @@ extern struct Img_Iface_ZB_Codes zb_codes; void img_iface_cleanup_main (void); void img_iface_load (const char *fpath, const char *fname); void img_iface_cleanup (void); -void img_iface_act (int action, void *data); +void img_iface_act (int action, const void *data); void img_iface_show_img (void); void img_iface_show_hist_c1 (void); void img_iface_show_hist_c3 (void); diff --git a/modules/image/inc/img_iface.hpp b/modules/image/inc/img_iface.hpp index b1904df..fb80451 100644 --- a/modules/image/inc/img_iface.hpp +++ b/modules/image/inc/img_iface.hpp @@ -204,7 +204,7 @@ struct Img_Iface_Data_Rotate { class cv::Point_ center; - double angle; + double angle; }; struct Img_Iface_Data_Adaptive_Thr { @@ -235,19 +235,19 @@ }; struct Img_Iface_Data_Contours_Size { - class std::vector >> *contours; + const class std::vector >> *contours; double *area; double *perimeter; }; struct Img_Iface_Data_Bounding_Rect { - class std::vector > *contour; + const class std::vector > *contour; class cv::Rect_ *rect; bool show; }; struct Img_Iface_Data_MinARect { - class std::vector > *contour; + const class std::vector > *contour; class cv::RotatedRect *rect; bool show; }; @@ -270,8 +270,8 @@ }; struct Img_Iface_Data_Undistort { - class cv::Mat *intrinsic_mat; - class cv::Mat *dist_coefs; + const class cv::Mat *intrinsic_mat; + const class cv::Mat *dist_coefs; }; /* img_zbar -------------------------------------------------------------------*/ @@ -321,7 +321,7 @@ extern struct Img_Iface_ZB_Codes zb_codes; void img_iface_cleanup_main (void); void img_iface_load (const char *fpath, const char *fname); void img_iface_cleanup (void); -void img_iface_act (int action, void *data); +void img_iface_act (int action, const void *data); void img_iface_show_img (void); void img_iface_show_hist_c1 (void); void img_iface_show_hist_c3 (void); diff --git a/modules/image/inc/img_ocr.h b/modules/image/inc/img_ocr.h index e6c1bca..febe2dd 100644 --- a/modules/image/inc/img_ocr.h +++ b/modules/image/inc/img_ocr.h @@ -25,7 +25,7 @@ /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ -void img_ocr_act (int action, void *data); +void img_ocr_act (int action, const void *data); /****************************************************************************** diff --git a/modules/image/inc/img_ocr.hpp b/modules/image/inc/img_ocr.hpp index dfd759a..6791a36 100644 --- a/modules/image/inc/img_ocr.hpp +++ b/modules/image/inc/img_ocr.hpp @@ -31,7 +31,7 @@ extern "C" { /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ -void img_ocr_act (int action, void *data); +void img_ocr_act (int action, const void *data); /****************************************************************************** diff --git a/modules/image/inc/img_orb.hpp b/modules/image/inc/img_orb.hpp index 18db3a7..9f6a1c3 100644 --- a/modules/image/inc/img_orb.hpp +++ b/modules/image/inc/img_orb.hpp @@ -32,7 +32,7 @@ /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ -void img_orb_act (class cv::Mat *pattern, +void img_orb_act (const class cv::Mat *img_ref, class cv::Mat *imgptr, int action); diff --git a/modules/image/inc/img_zbar.hpp b/modules/image/inc/img_zbar.hpp index d638ed5..b9a5143 100644 --- a/modules/image/inc/img_zbar.hpp +++ b/modules/image/inc/img_zbar.hpp @@ -33,7 +33,7 @@ /****************************************************************************** ******* functions ************************************************************ ******************************************************************************/ -void img_zb_act (class cv::Mat *imgptr, int action, void *data); +void img_zb_act (class cv::Mat *imgptr, int action, const void *data); /****************************************************************************** diff --git a/modules/image/src/img_alx.cpp b/modules/image/src/img_alx.cpp index 7a3662e..d6a7fe4 100644 --- a/modules/image/src/img_alx.cpp +++ b/modules/image/src/img_alx.cpp @@ -46,7 +46,7 @@ static void img_alx_median_vertical (class cv::Mat *imgptr); /****************************************************************************** ******* global functions ***************************************************** ******************************************************************************/ -void img_alx_act (class cv::Mat *imgptr, int action, void *data) +void img_alx_act (class cv::Mat *imgptr, int action, const void *data) { switch (action) { diff --git a/modules/image/src/img_calib3d.cpp b/modules/image/src/img_calib3d.cpp index 8aaa408..6b96d77 100644 --- a/modules/image/src/img_calib3d.cpp +++ b/modules/image/src/img_calib3d.cpp @@ -37,14 +37,14 @@ /****************************************************************************** ******* static functions ***************************************************** ******************************************************************************/ -static void img_calib3d_calibrate (class cv::Mat *imgptr, void *data); -static void img_calib3d_undistort (class cv::Mat *imgptr, void *data); +static void img_calib3d_calibrate (class cv::Mat *imgptr, const void *data); +static void img_calib3d_undistort (class cv::Mat *imgptr, const void *data); /****************************************************************************** ******* main ***************************************************************** ******************************************************************************/ -void img_calib3d_act (class cv::Mat *imgptr, int action, void *data) +void img_calib3d_act (class cv::Mat *imgptr, int action, const void *data) { switch (action) { case IMG_CALIB3D_ACT_CALIBRATE: @@ -61,11 +61,9 @@ void img_calib3d_act (class cv::Mat *imgptr, int action, void *data) /****************************************************************************** ******* static functions ***************************************************** ******************************************************************************/ -static void img_calib3d_calibrate (class cv::Mat *imgptr, void *data) +static void img_calib3d_calibrate (class cv::Mat *imgptr, const void *data) { - /* Data */ - struct Img_Iface_Data_Calibrate *data_cast; - + const struct Img_Iface_Data_Calibrate *data_cast; class cv::Mat *intrinsic_mat; class cv::Mat *dist_coefs; class std::vector *rvecs; @@ -76,12 +74,11 @@ static void img_calib3d_calibrate (class cv::Mat *imgptr, void *data) class std::vector >> image_points; class std::vector > corners; class std::vector > obj; - bool found; int i; int j; - data_cast = (struct Img_Iface_Data_Calibrate *)data; + data_cast = (const struct Img_Iface_Data_Calibrate *)data; intrinsic_mat = data_cast->intrinsic_mat; dist_coefs = data_cast->dist_coefs; rvecs = data_cast->rvecs; @@ -111,28 +108,23 @@ static void img_calib3d_calibrate (class cv::Mat *imgptr, void *data) image_points.push_back(corners); object_points.push_back(obj); - /* Calibrate */ cv::calibrateCamera(object_points, image_points, imgptr->size(), *intrinsic_mat, *dist_coefs, *rvecs, *tvecs); } -static void img_calib3d_undistort (class cv::Mat *imgptr, void *data) +static void img_calib3d_undistort (class cv::Mat *imgptr, const void *data) { - class cv::Mat imgtmp; - - /* Data */ - struct Img_Iface_Data_Undistort *data_cast; - - class cv::Mat *intrinsic_mat; - class cv::Mat *dist_coefs; + class cv::Mat imgtmp; + const struct Img_Iface_Data_Undistort *data_cast; + const class cv::Mat *intrinsic_mat; + const class cv::Mat *dist_coefs; - data_cast = (struct Img_Iface_Data_Undistort *)data; + data_cast = (const struct Img_Iface_Data_Undistort *)data; intrinsic_mat = data_cast->intrinsic_mat; dist_coefs = data_cast->dist_coefs; cv::undistort(*imgptr, imgtmp, *intrinsic_mat, *dist_coefs); - /* Write tmp into imgptr */ imgptr->release(); imgtmp.copyTo(*imgptr); } diff --git a/modules/image/src/img_cv.cpp b/modules/image/src/img_cv.cpp index d9c2343..14ed08f 100644 --- a/modules/image/src/img_cv.cpp +++ b/modules/image/src/img_cv.cpp @@ -35,48 +35,48 @@ ******************************************************************************/ /* Core: The core functionality */ /* Pixel */ -static void img_cv_pixel_get (class cv::Mat *imgptr, void *data); -static void img_cv_pixel_set (class cv::Mat *imgptr, void *data); +static void img_cv_pixel_get (const class cv::Mat *imgptr, const void *data); +static void img_cv_pixel_set (class cv::Mat *imgptr, const void *data); /* ROI */ -static void img_cv_set_ROI (class cv::Mat *imgptr, void *data); +static void img_cv_set_ROI (class cv::Mat *imgptr, const void *data); /* Operations on Arrays */ -static void img_cv_and_2ref (class cv::Mat *imgptr, void *data); -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_component (class cv::Mat *imgptr, void *data); +static void img_cv_and_2ref (class cv::Mat *imgptr, const void *data); +static void img_cv_not (class cv::Mat *imgptr); +static void img_cv_or_2ref (class cv::Mat *imgptr, const void *data); +static void img_cv_component (class cv::Mat *imgptr, const void *data); /* Imgproc: Image processing */ /* Image filtering */ -static void img_cv_dilate (class cv::Mat *imgptr, void *data); -static void img_cv_erode (class cv::Mat *imgptr, void *data); -static void img_cv_smooth (class cv::Mat *imgptr, void *data); -static void img_cv_sobel (class cv::Mat *imgptr, void *data); -static void img_cv_border (class cv::Mat *imgptr, void *data); +static void img_cv_dilate (class cv::Mat *imgptr, const void *data); +static void img_cv_erode (class cv::Mat *imgptr, const void *data); +static void img_cv_smooth (class cv::Mat *imgptr, const void *data); +static void img_cv_sobel (class cv::Mat *imgptr, const void *data); +static void img_cv_border (class cv::Mat *imgptr, const void *data); /* Geometric image transformations */ -static void img_cv_mirror (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_mirror (class cv::Mat *imgptr, const void *data); +static void img_cv_rotate_orto (class cv::Mat *imgptr, const void *data); +static void img_cv_rotate (class cv::Mat *imgptr, const void *data); /* Miscellaneous image transformations */ -static void img_cv_adaptive_thr (class cv::Mat *imgptr, void *data); -static void img_cv_cvt_color (class cv::Mat *imgptr, void *data); -static void img_cv_distance_transform (class cv::Mat *imgptr); -static void img_cv_threshold (class cv::Mat *imgptr, void *data); +static void img_cv_adaptive_thr (class cv::Mat *imgptr, const void *data); +static void img_cv_cvt_color (class cv::Mat *imgptr, const void *data); +static void img_cv_distance_transform (class cv::Mat *imgptr); +static void img_cv_threshold (class cv::Mat *imgptr, const void *data); /* Histograms */ -static void img_cv_histogram (class cv::Mat *imgptr, void *data); -static void img_cv_histogram_c3 (class cv::Mat *imgptr, void *data); +static void img_cv_histogram (class cv::Mat *imgptr, const void *data); +static void img_cv_histogram_c3 (class cv::Mat *imgptr, const void *data); /* Structural analysis and shape descriptors */ -static void img_cv_contours (class cv::Mat *imgptr, void *data); -static void img_cv_contours_size (void *data); -static void img_cv_bounding_rect (class cv::Mat *imgptr, void *data); -static void img_cv_fit_ellipse (class cv::Mat *imgptr, void *data); -static void img_cv_min_area_rect (class cv::Mat *imgptr, void *data); +static void img_cv_contours (class cv::Mat *imgptr, const void *data); +static void img_cv_contours_size (const void *data); +static void img_cv_bounding_rect (class cv::Mat *imgptr, const void *data); +static void img_cv_fit_ellipse (class cv::Mat *imgptr, const void *data); +static void img_cv_min_area_rect (class cv::Mat *imgptr, const void *data); /* Feature detection */ -static void img_cv_hough_circles (class cv::Mat *imgptr, void *data); +static void img_cv_hough_circles (class cv::Mat *imgptr, const void *data); /****************************************************************************** ******* main ***************************************************************** ******************************************************************************/ -void img_cv_act (class cv::Mat *imgptr, int action, void *data) +void img_cv_act (class cv::Mat *imgptr, int action, const void *data) { switch (action) { case IMG_CV_ACT_PIXEL_GET: @@ -177,112 +177,94 @@ void img_cv_act (class cv::Mat *imgptr, int action, void *data) ******************************************************************************/ /* Core: The core functionality */ /* ----- Pixel */ -static void img_cv_pixel_get (class cv::Mat *imgptr, void *data) +static void img_cv_pixel_get (const class cv::Mat *imgptr, const void *data) { - struct Img_Iface_Data_Pixel_Get *data_cast; + const struct Img_Iface_Data_Pixel_Get *data_cast; unsigned char *val; int x; int y; - /* Data */ - data_cast = (struct Img_Iface_Data_Pixel_Get *)data; - /* Value */ + data_cast = (const struct Img_Iface_Data_Pixel_Get *)data; val = data_cast->val; - /* Position */ x = data_cast->x; y = data_cast->y; - /* Get value */ *val = imgptr->at(y, x); } -static void img_cv_pixel_set (class cv::Mat *imgptr, void *data) +static void img_cv_pixel_set (class cv::Mat *imgptr, const void *data) { - struct Img_Iface_Data_Pixel_Set *data_cast; + const struct Img_Iface_Data_Pixel_Set *data_cast; unsigned char val; int x; int y; - /* Data */ - data_cast = (struct Img_Iface_Data_Pixel_Set *)data; - - /* Value */ + data_cast = (const struct Img_Iface_Data_Pixel_Set *)data; val = data_cast->val; - /* Position */ x = data_cast->x; y = data_cast->y; - /* Set value */ imgptr->at(y, x) = val; } /* ----- ROI */ -static void img_cv_set_ROI (class cv::Mat *imgptr, void *data) +static void img_cv_set_ROI (class cv::Mat *imgptr, const void *data) { - class cv::Mat imgtmp; - struct Img_Iface_Data_SetROI *data_cast; - class cv::Rect_ *rect; + class cv::Mat imgtmp; + const struct Img_Iface_Data_SetROI *data_cast; + const class cv::Rect_ *rect; - /* Data */ - data_cast = (struct Img_Iface_Data_SetROI *)data; - - /* Rectangle */ + data_cast = (const struct Img_Iface_Data_SetROI *)data; rect = &(data_cast->rect); - /* Set ROI */ (*imgptr)(*rect).copyTo(imgtmp); imgtmp.copyTo(*imgptr); - /* Write tmp into imgptr */ imgptr->release(); imgtmp.copyTo(*imgptr); - /* clean up */ imgtmp.release(); } /* ----- Operations on arrays */ -static void img_cv_and_2ref (class cv::Mat *imgptr, void *data) +static void img_cv_and_2ref (class cv::Mat *imgptr, const void *data) { - class cv::Mat *img_ref; - img_ref = (class cv::Mat *)data; + const class cv::Mat *img_ref; + + img_ref = (const class cv::Mat *)data; cv::bitwise_and(*imgptr, *img_ref, *imgptr); } -static void img_cv_not (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) +static void img_cv_or_2ref (class cv::Mat *imgptr, const void *data) { - class cv::Mat *img_ref; - img_ref = (class cv::Mat *)data; + const class cv::Mat *img_ref; + + img_ref = (const class cv::Mat *)data; cv::bitwise_or(*imgptr, *img_ref, *imgptr); } -static void img_cv_component (class cv::Mat *imgptr, void *data) +static void img_cv_component (class cv::Mat *imgptr, const void *data) { - class cv::Mat cmp_img[3]; - struct Img_Iface_Data_Component *data_cast; + class cv::Mat cmp_img[3]; + const struct Img_Iface_Data_Component *data_cast; int cmp; - /* Data */ - data_cast = (struct Img_Iface_Data_Component *)data; - - /* Color component */ + data_cast = (const struct Img_Iface_Data_Component *)data; cmp = data_cast->cmp; - /* Write components into cmp_img[] */ cv::split(*imgptr, cmp_img); - /* Write tmp into imgptr */ imgptr->release(); cmp_img[cmp].copyTo(*imgptr); - /* clean up */ cmp_img[0].release(); cmp_img[1].release(); cmp_img[2].release(); @@ -290,47 +272,38 @@ static void img_cv_component (class cv::Mat *imgptr, void *data) /* Imgproc: Image processing */ /* ----- Image filtering */ -static void img_cv_dilate (class cv::Mat *imgptr, void *data) +static void img_cv_dilate (class cv::Mat *imgptr, const void *data) { - /* Data */ - struct Img_Iface_Data_Dilate_Erode *data_cast; - data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; - - /* Iterations */ + const struct Img_Iface_Data_Dilate_Erode *data_cast; int i; + + data_cast = (const struct Img_Iface_Data_Dilate_Erode *)data; i = data_cast->i; - /* Dilate */ cv::dilate(*imgptr, *imgptr, cv::Mat(), cv::Point(-1,-1), i, cv::BORDER_CONSTANT, cv::Scalar(0)); } -static void img_cv_erode (class cv::Mat *imgptr, void *data) +static void img_cv_erode (class cv::Mat *imgptr, const void *data) { - /* Data */ - struct Img_Iface_Data_Dilate_Erode *data_cast; - data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; - - /* Iterations */ + const struct Img_Iface_Data_Dilate_Erode *data_cast; int i; + + data_cast = (const struct Img_Iface_Data_Dilate_Erode *)data; i = data_cast->i; - /* Erode */ cv::erode(*imgptr, *imgptr, cv::Mat(), cv::Point(-1,-1), i, cv::BORDER_CONSTANT, cv::Scalar(0)); } -static void img_cv_smooth (class cv::Mat *imgptr, void *data) +static void img_cv_smooth (class cv::Mat *imgptr, const void *data) { - /* Data */ - struct Img_Iface_Data_Smooth *data_cast; - data_cast = (struct Img_Iface_Data_Smooth *)data; - - /* Smoothing method */ + const struct Img_Iface_Data_Smooth *data_cast; int method; - method = data_cast->method; - /* Kernel size */ int ksize; + + data_cast = (const struct Img_Iface_Data_Smooth *)data; + method = data_cast->method; ksize = data_cast->ksize; if (!(ksize % 2)) { ksize++; @@ -351,20 +324,16 @@ static void img_cv_smooth (class cv::Mat *imgptr, void *data) } } -static void img_cv_sobel (class cv::Mat *imgptr, void *data) +static void img_cv_sobel (class cv::Mat *imgptr, const void *data) { - /* Data */ - struct Img_Iface_Data_Sobel *data_cast; - data_cast = (struct Img_Iface_Data_Sobel *)data; - - /* Order of the derivative x */ + const struct Img_Iface_Data_Sobel *data_cast; int dx; - dx = data_cast->dx; - /* Order of the derivative y */ int dy; - dy = data_cast->dy; - /* Size of the extended Sobel kernel */ int ksize; + + data_cast = (const struct Img_Iface_Data_Sobel *)data; + dx = data_cast->dx; + dy = data_cast->dy; ksize = data_cast->ksize; if (!(ksize % 2)) { ksize++; @@ -374,53 +343,44 @@ static void img_cv_sobel (class cv::Mat *imgptr, void *data) cv::BORDER_DEFAULT); } -static void img_cv_border (class cv::Mat *imgptr, void *data) +static void img_cv_border (class cv::Mat *imgptr, const void *data) { - class cv::Mat imgtmp; - struct Img_Iface_Data_Border *data_cast; - int size; + class cv::Mat imgtmp; + const struct Img_Iface_Data_Border *data_cast; + int sz; /* Data */ data_cast = (struct Img_Iface_Data_Border *)data; + sz = data_cast->size; - size = data_cast->size; + imgtmp = cv::Mat(cv::Size(imgptr->cols + sz, imgptr->rows + sz), CV_8U); - imgtmp = cv::Mat(cv::Size(imgptr->cols + size, imgptr->rows + size), - CV_8U); - /* Get transform */ - cv::copyMakeBorder(*imgptr, imgtmp, size, size, size, size, - cv::BORDER_CONSTANT, cv::Scalar(0)); + cv::copyMakeBorder(*imgptr, imgtmp, sz, sz, sz, sz, + cv::BORDER_CONSTANT, cv::Scalar(0)); imgtmp.copyTo(*imgptr); - /* Cleanup */ imgtmp.release(); } /* ----- Geometric image transformations */ -static void img_cv_mirror (class cv::Mat *imgptr, void *data) +static void img_cv_mirror (class cv::Mat *imgptr, const void *data) { - struct Img_Iface_Data_Mirror *data_cast; + const struct Img_Iface_Data_Mirror *data_cast; int axis; - /* Data */ - data_cast = (struct Img_Iface_Data_Mirror *)data; - - /* Rotate n * pi/2 rad */ + data_cast = (const struct Img_Iface_Data_Mirror *)data; axis = data_cast->axis; - /* flip around axis */ cv::flip(*imgptr, *imgptr, axis); } -static void img_cv_rotate_orto (class cv::Mat *imgptr, void *data) +static void img_cv_rotate_orto (class cv::Mat *imgptr, const void *data) { - /* Data */ - struct Img_Iface_Data_Rotate_Orto *data_cast; - data_cast = (struct Img_Iface_Data_Rotate_Orto *)data; - - /* Rotate n * pi/2 rad */ + const struct Img_Iface_Data_Rotate_Orto *data_cast; int n; + + data_cast = (struct Img_Iface_Data_Rotate_Orto *)data; n = data_cast->n; switch (n) { @@ -443,121 +403,100 @@ 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_rotate (class cv::Mat *imgptr, const void *data) { - class cv::Mat map_matrix; - - /* Data */ - struct Img_Iface_Data_Rotate *data_cast; - data_cast = (struct Img_Iface_Data_Rotate *)data; + class cv::Mat map_matrix; + const struct Img_Iface_Data_Rotate *data_cast; + const class cv::Point_ *center; + double angle; - /* Angle of rotation */ - class cv::Point_ *center; + data_cast = (const struct Img_Iface_Data_Rotate *)data; center = &(data_cast->center); - double angle; angle = data_cast->angle; - /* 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)); - /* clean up */ map_matrix.release(); } /* ----- Miscellaneous image transformations */ -static void img_cv_adaptive_thr (class cv::Mat *imgptr, void *data) +static void img_cv_adaptive_thr (class cv::Mat *imgptr, const void *data) { - /* Data */ - struct Img_Iface_Data_Adaptive_Thr *data_cast; - data_cast = (struct Img_Iface_Data_Adaptive_Thr *)data; - - /* Threshold method */ + const struct Img_Iface_Data_Adaptive_Thr *data_cast; int method; - method = data_cast->method; - /* Threshold type */ int thr_typ; - thr_typ = data_cast->thr_typ; - /* Neighbourhood size */ int ksize; + + data_cast = (const struct Img_Iface_Data_Adaptive_Thr *)data; + method = data_cast->method; + thr_typ = data_cast->thr_typ; ksize = data_cast->ksize; if (!(ksize % 2)) { ksize++; } - /* Apply adaptive threshold */ - cv::adaptiveThreshold(*imgptr, *imgptr, 255, method, thr_typ, ksize, - 0); + cv::adaptiveThreshold(*imgptr, *imgptr, 255, method, thr_typ, ksize, 0); } -static void img_cv_cvt_color (class cv::Mat *imgptr, void *data) +static void img_cv_cvt_color (class cv::Mat *imgptr, const void *data) { - /* Data */ - struct Img_Iface_Data_Cvt_Color *data_cast; - data_cast = (struct Img_Iface_Data_Cvt_Color *)data; - - /* Conversion method */ + const struct Img_Iface_Data_Cvt_Color *data_cast; int method; + + data_cast = (const struct Img_Iface_Data_Cvt_Color *)data; method = data_cast->method; cv::cvtColor(*imgptr, *imgptr, method, 0); } -static void img_cv_distance_transform (class cv::Mat *imgptr) +static void img_cv_distance_transform (class cv::Mat *imgptr) { class cv::Mat imgtmp; - /* Get transform */ - cv::distanceTransform(*imgptr, imgtmp, CV_DIST_L2, CV_DIST_MASK_PRECISE); + cv::distanceTransform(*imgptr,imgtmp, CV_DIST_L2, CV_DIST_MASK_PRECISE); - /* DistanceTransform gives CV_32F image */ + /* DistanceTransform gives CV_32F image */ imgtmp.convertTo(*imgptr, CV_8U); - /* Cleanup */ imgtmp.release(); } -static void img_cv_threshold (class cv::Mat *imgptr, void *data) +static void img_cv_threshold (class cv::Mat *imgptr, const void *data) { - /* Data */ - struct Img_Iface_Data_Threshold *data_cast; - data_cast = (struct Img_Iface_Data_Threshold *)data; - - /* Threshold type */ + const struct Img_Iface_Data_Threshold *data_cast; int thr_typ; - thr_typ = data_cast->thr_typ; - /* Threshold value */ int thr_val; + + data_cast = (const struct Img_Iface_Data_Threshold *)data; + thr_typ = data_cast->thr_typ; thr_val = data_cast->thr_val; if (thr_val == -1) { thr_typ |= cv::THRESH_OTSU; } - /* Threshold */ cv::threshold(*imgptr, *imgptr, thr_val, 0xFF, thr_typ); } /* ----- Histograms */ -static void img_cv_histogram (class cv::Mat *imgptr, void *data) +static void img_cv_histogram (class cv::Mat *imgptr, const void *data) { - /* Data */ - struct Img_Iface_Data_Histogram *data_cast; - data_cast = (struct Img_Iface_Data_Histogram *)data; + const struct Img_Iface_Data_Histogram *data_cast; + class cv::Mat *hist; + class cv::Mat *hist_img; + const int h_size = 256; + const float h_range_arr[] = {0.0, 256.0}; + const float *h_range = {h_range_arr}; + int i; - /* Contours */ - class cv::Mat *hist; + data_cast = (const struct Img_Iface_Data_Histogram *)data; hist = data_cast->hist_c0; - class cv::Mat *hist_img; hist_img = data_cast->hist_img; /* Write components into cmp_img[] */ - int h_size = 256; - float h_range_arr[] = {0.0, 256.0}; - const float *h_range = {h_range_arr}; cv::calcHist(imgptr, 1, 0, cv::Mat(), *hist, 1, &h_size, &h_range, true, false); @@ -569,10 +508,10 @@ static void img_cv_histogram (class cv::Mat *imgptr, void *data) cv::Mat()); /* Draw hist into hist_img */ - int i; - for(i = 0; i < 256; i++ ) { + for(i = 0; i < h_size; i++ ) { cv::line(*hist_img, cv::Point(i, hist_img->rows - 0), - cv::Point(i, hist_img->rows - hist->at(i)), + cv::Point(i, + hist_img->rows - hist->at(i)), cv::Scalar(255, 0, 0), 1, 8, 0); } @@ -580,31 +519,29 @@ static void img_cv_histogram (class cv::Mat *imgptr, void *data) img_iface_show_hist_c1(); } -static void img_cv_histogram_c3 (class cv::Mat *imgptr, void *data) +static void img_cv_histogram_c3 (class cv::Mat *imgptr, const void *data) { - class cv::Mat cmp_img[3]; - - /* Write components into cmp_img[] */ - cv::split(*imgptr, cmp_img); - - /* Data */ - struct Img_Iface_Data_Histogram *data_cast; - data_cast = (struct Img_Iface_Data_Histogram *)data; + class cv::Mat cmp_img[3]; + const struct Img_Iface_Data_Histogram *data_cast; + class cv::Mat *hist_c0; + class cv::Mat *hist_c1; + class cv::Mat *hist_c2; + class cv::Mat *hist_img; + const int h_size = 256; + const float h_range_arr[] = {0.0, 256.0}; + const float *h_range = {h_range_arr}; + int i; - /* Contours */ - class cv::Mat *hist_c0; + data_cast = (const struct Img_Iface_Data_Histogram *)data; hist_c0 = data_cast->hist_c0; - class cv::Mat *hist_c1; hist_c1 = data_cast->hist_c1; - class cv::Mat *hist_c2; hist_c2 = data_cast->hist_c2; - class cv::Mat *hist_img; hist_img = data_cast->hist_img; /* Write components into cmp_img[] */ - int h_size = 256; - float h_range_arr[] = {0.0, 256.0}; - const float *h_range = {h_range_arr}; + cv::split(*imgptr, cmp_img); + + /* Write components into cmp_img[] */ cv::calcHist(&cmp_img[0], 1, 0, cv::Mat(), *hist_c0, 1, &h_size, &h_range, true, false); cv::calcHist(&cmp_img[1], 1, 0, cv::Mat(), *hist_c1, 1, &h_size, @@ -624,44 +561,42 @@ static void img_cv_histogram_c3 (class cv::Mat *imgptr, void *data) cv::NORM_MINMAX, -1, cv::Mat()); /* Draw hist into hist_img */ - int i; for(i = 0; i < 256; i++ ) { - cv::line(*hist_img, cv::Point(3*i, hist_img->rows - 0), - cv::Point(3*i, - hist_img->rows - hist_c0->at(i)), + cv::line(*hist_img, cv::Point(3 * i, hist_img->rows - 0), + cv::Point(3 * i, + hist_img->rows - hist_c0->at(i)), cv::Scalar(255, 0, 0), 1, 8, 0); } for(i = 0; i < 256; i++ ) { - cv::line(*hist_img, cv::Point(3*i + 1, hist_img->rows - 0), - cv::Point(3*i+1, - hist_img->rows - hist_c1->at(i)), + cv::line(*hist_img, cv::Point(3 * i + 1, hist_img->rows - 0), + cv::Point(3 * i + 1, + hist_img->rows - hist_c1->at(i)), cv::Scalar(0, 255, 0), 1, 8, 0); } for(i = 0; i < 256; i++ ) { - cv::line(*hist_img, cv::Point(3*i + 2, hist_img->rows - 0), - cv::Point(3*i + 2, - hist_img->rows - hist_c2->at(i)), + cv::line(*hist_img, cv::Point(3 * i + 2, hist_img->rows - 0), + cv::Point(3 * i + 2, + hist_img->rows - hist_c2->at(i)), cv::Scalar(0, 0, 255), 1, 8, 0); } /* Show histogram */ img_iface_show_hist_c3(); - /* Cleanup */ cmp_img[0].release(); cmp_img[1].release(); cmp_img[2].release(); } /* ----- Structural analysis and shape descriptors */ -static void img_cv_contours (class cv::Mat *imgptr, void *data) +static void img_cv_contours (class cv::Mat *imgptr, const void *data) { - struct Img_Iface_Data_Contours *data_cast; - class std::vector >> *contours; - class cv::Mat *hierarchy; + const struct Img_Iface_Data_Contours *data_cast; + class std::vector>> *contours; + class cv::Mat *hierarchy; /* Data */ - data_cast = (struct Img_Iface_Data_Contours *)data; + data_cast = (const struct Img_Iface_Data_Contours *)data; /* Contours */ contours = data_cast->contours; @@ -680,54 +615,45 @@ static void img_cv_contours (class cv::Mat *imgptr, void *data) *hierarchy, 1, cvPoint(0, 0)); } -static void img_cv_contours_size (void *data) +static void img_cv_contours_size (const void *data) { - struct Img_Iface_Data_Contours_Size *data_cast; - class std::vector >> *contours; - int i; + const struct Img_Iface_Data_Contours_Size *data_cast; + const class std::vector>> *contours; + unsigned i; - /* Data */ - data_cast = (struct Img_Iface_Data_Contours_Size *)data; - - /* Contours */ + data_cast = (const struct Img_Iface_Data_Contours_Size *)data; contours = data_cast->contours; - /* Get area and perimeter */ if (data_cast->area) { - for (i = 0; i < (int)contours->size(); i++) { + for (i = 0; i < contours->size(); i++) { data_cast->area[i] = cv::contourArea( (*contours)[i], false); } } if (data_cast->perimeter) { - for (i = 0; i < (int)contours->size(); i++) { + for (i = 0; i < contours->size(); i++) { data_cast->perimeter[i] = cv::arcLength( (*contours)[i], true); } } } -static void img_cv_bounding_rect (class cv::Mat *imgptr, void *data) +static void img_cv_bounding_rect (class cv::Mat *imgptr, const void *data) { - /* Data */ - struct Img_Iface_Data_Bounding_Rect *data_cast; - data_cast = (struct Img_Iface_Data_Bounding_Rect *)data; + class cv::Point_ vertices[4]; + const struct Img_Iface_Data_Bounding_Rect *data_cast; + const class std::vector > *contour; + class cv::Rect_ *rect; + bool show; - /* Contours */ - class std::vector > *contour; + data_cast = (const struct Img_Iface_Data_Bounding_Rect *)data; contour = data_cast->contour; - /* Rotated rectangle */ - class cv::Rect_ *rect; rect = data_cast->rect; - /* Show rectangle ? */ - bool show; show = data_cast->show; - /* Get rectangle */ *rect = cv::boundingRect(*contour); /* Draw rectangle */ - class cv::Point_ vertices[4]; if (show) { vertices[0].x = rect->x; vertices[0].y = rect->y; @@ -752,27 +678,22 @@ static void img_cv_bounding_rect (class cv::Mat *imgptr, void *data) } } -static void img_cv_fit_ellipse (class cv::Mat *imgptr, void *data) +static void img_cv_fit_ellipse (class cv::Mat *imgptr, const void *data) { - /* Data */ - struct Img_Iface_Data_MinARect *data_cast; - data_cast = (struct Img_Iface_Data_MinARect *)data; + class cv::Point_ vertices[4]; + const struct Img_Iface_Data_MinARect *data_cast; + const class std::vector > *contour; + class cv::RotatedRect *rect; + bool show; - /* Contours */ - class std::vector > *contour; + data_cast = (const struct Img_Iface_Data_MinARect *)data; contour = data_cast->contour; - /* Rotated rectangle */ - class cv::RotatedRect *rect; rect = data_cast->rect; - /* Show rectangle ? */ - bool show; show = data_cast->show; - /* Get rectangle */ *rect = cv::fitEllipse(*contour); /* Draw rectangle */ - class cv::Point_ vertices[4]; if (show) { rect->points(vertices); cv::line(*imgptr, cv::Point(vertices[0].x, vertices[0].y), @@ -790,27 +711,22 @@ static void img_cv_fit_ellipse (class cv::Mat *imgptr, void *data) } } -static void img_cv_min_area_rect (class cv::Mat *imgptr, void *data) +static void img_cv_min_area_rect (class cv::Mat *imgptr, const void *data) { - /* Data */ - struct Img_Iface_Data_MinARect *data_cast; - data_cast = (struct Img_Iface_Data_MinARect *)data; + class cv::Point_ vertices[4]; + const struct Img_Iface_Data_MinARect *data_cast; + const class std::vector > *contour; + class cv::RotatedRect *rect; + bool show; - /* Contours */ - class std::vector > *contour; + data_cast = (const struct Img_Iface_Data_MinARect *)data; contour = data_cast->contour; - /* 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_ vertices[4]; if (show) { rect->points(vertices); cv::line(*imgptr, cv::Point(vertices[0].x, vertices[0].y), @@ -829,21 +745,21 @@ static void img_cv_min_area_rect (class cv::Mat *imgptr, void *data) } /* ----- Feature detection */ -static void img_cv_hough_circles (class cv::Mat *imgptr, void *data) +static void img_cv_hough_circles (class cv::Mat *imgptr, const void *data) { - /* Data */ - struct Img_Iface_Data_Hough_Circles *data_cast; - data_cast = (struct Img_Iface_Data_Hough_Circles *)data; - - /* Contours */ + class cv::Point_ center; + int radius; + unsigned i; + const struct Img_Iface_Data_Hough_Circles *data_cast; class std::vector > *circles; + double dist_min; + double param_1; + double param_2; + int radius_min; + int radius_max; + + data_cast = (const struct Img_Iface_Data_Hough_Circles *)data; circles = data_cast->circles; - /* Parameters */ - double dist_min; - double param_1; - double param_2; - int radius_min; - int radius_max; dist_min = data_cast->dist_min; param_1 = data_cast->param_1; param_2 = data_cast->param_2; @@ -858,10 +774,7 @@ static void img_cv_hough_circles (class cv::Mat *imgptr, void *data) imgptr->setTo(cv::Scalar(0)); /* Draw circles */ - class cv::Point_ center; - int radius; - int i; - for (i = 0; i < (int)circles->size(); i++) { + for (i = 0; i < circles->size(); i++) { center.x = cvRound((*circles)[i][0]); center.y = cvRound((*circles)[i][1]); radius = cvRound((*circles)[i][2]); diff --git a/modules/image/src/img_iface.cpp b/modules/image/src/img_iface.cpp index 6c5d64e..51404c9 100644 --- a/modules/image/src/img_iface.cpp +++ b/modules/image/src/img_iface.cpp @@ -103,63 +103,63 @@ static void img_iface_median_vertical (void); /* img_cv */ /* Core: The core functionality */ /* Pixel */ -static void img_iface_pixel_get (void *data); -static void img_iface_pixel_set (void *data); +static void img_iface_pixel_get (const void *data); +static void img_iface_pixel_set (const void *data); /* ROI */ -static void img_iface_set_ROI (void *data); -static void img_iface_set_ROI_2rect (void *data); +static void img_iface_set_ROI (const void *data); +static void img_iface_set_ROI_2rect (const void *data); /* Operations on Arrays */ static void img_iface_and_2ref (void); static void img_iface_not (void); static void img_iface_or_2ref (void); -static void img_iface_component (void *data); +static void img_iface_component (const void *data); /* Imgproc: Image processing */ /* Image filtering */ -static void img_iface_dilate (void *data); -static void img_iface_erode (void *data); -static void img_iface_dilate_erode (void *data); -static void img_iface_erode_dilate (void *data); -static void img_iface_smooth (void *data); -static void img_iface_sobel (void *data); -static void img_iface_border (void *data); +static void img_iface_dilate (const void *data); +static void img_iface_erode (const void *data); +static void img_iface_dilate_erode (const void *data); +static void img_iface_erode_dilate (const void *data); +static void img_iface_smooth (const void *data); +static void img_iface_sobel (const void *data); +static void img_iface_border (const void *data); /* Geometric image transformations */ -static void img_iface_mirror (void *data); -static void img_iface_rotate_orto (void *data); -static void img_iface_rotate (void *data); -static void img_iface_rotate_2rect (void *data); +static void img_iface_mirror (const void *data); +static void img_iface_rotate_orto (const void *data); +static void img_iface_rotate (const void *data); +static void img_iface_rotate_2rect (const void *data); /* Miscellaneous image transformations */ -static void img_iface_adaptive_thr (void *data); -static void img_iface_cvt_color (void *data); +static void img_iface_adaptive_thr (const void *data); +static void img_iface_cvt_color (const void *data); static void img_iface_distance_transform (void); -static void img_iface_threshold (void *data); +static void img_iface_threshold (const void *data); /* Histograms */ -static void img_iface_histogram (void *data); -static void img_iface_histogram_c3 (void *data); +static void img_iface_histogram (const void *data); +static void img_iface_histogram_c3 (const void *data); /* Structural analysis and shape descriptors */ -static void img_iface_contours (void *data); -static void img_iface_contours_size (void *data); -static void img_iface_bounding_rect (void *data); -static void img_iface_fit_ellipse (void *data); -static void img_iface_min_area_rect (void *data); +static void img_iface_contours (const void *data); +static void img_iface_contours_size (const void *data); +static void img_iface_bounding_rect (const void *data); +static void img_iface_fit_ellipse (const void *data); +static void img_iface_min_area_rect (const void *data); /* Feature detection */ -static void img_iface_hough_circles (void *data); +static void img_iface_hough_circles (const void *data); /* img_orb */ static void img_iface_align (void); /* img_calib3d */ -static void img_iface_calibrate (void *data); -static void img_iface_undistort (void *data); +static void img_iface_calibrate (const void *data); +static void img_iface_undistort (const void *data); /* img_zbar */ -static void img_iface_decode (void *data); +static void img_iface_decode (const void *data); /* img_ocr */ -static void img_iface_read (void *data); +static void img_iface_read (const void *data); /* img_iface */ static void img_iface_apply (void); static void img_iface_discard (void); -static void img_iface_save_mem (void *data); -static void img_iface_load_mem (void *data); +static void img_iface_save_mem (const void *data); +static void img_iface_load_mem (const void *data); static void img_iface_save_ref (void); /* save */ static void img_iface_save_file (void); @@ -237,7 +237,7 @@ void img_iface_cleanup (void) hist_img_c3.release(); } -void img_iface_act (int action, void *data) +void img_iface_act (int action, const void *data) { switch (action) { /* img_alx */ @@ -636,12 +636,12 @@ static void img_iface_median_vertical (void) /* img_cv --------------------------------------------------------------------*/ /* ----- Core: The core functionality */ /* ----- ------- Pixel */ -static void img_iface_pixel_get (void *data) +static void img_iface_pixel_get (const void *data) { - struct Img_Iface_Data_Pixel_Get data_tmp; - struct Img_Iface_Data_Pixel_Get *data_cast; + struct Img_Iface_Data_Pixel_Get data_tmp; + const struct Img_Iface_Data_Pixel_Get *data_cast; unsigned char val; - char title [80]; + char title [80]; /* Must have 1 channel */ if (image_copy_tmp.channels() != 1) { @@ -669,14 +669,14 @@ static void img_iface_pixel_get (void *data) image_copy_tmp.rows, title, NULL); - data = (void *)&data_tmp; + data = (const void *)&data_tmp; } /* Get pixel value */ img_cv_act(&image_copy_tmp, IMG_CV_ACT_PIXEL_GET, data); /* Write into log */ - data_cast = (struct Img_Iface_Data_Pixel_Get *)data; + data_cast = (const struct Img_Iface_Data_Pixel_Get *)data; snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Pixel get: (%i, %i): %i", data_cast->x, @@ -686,11 +686,11 @@ static void img_iface_pixel_get (void *data) (user_iface_log.len)++; } -static void img_iface_pixel_set (void *data) +static void img_iface_pixel_set (const void *data) { - struct Img_Iface_Data_Pixel_Set data_tmp; - struct Img_Iface_Data_Pixel_Set *data_cast; - char title [80]; + struct Img_Iface_Data_Pixel_Set data_tmp; + const struct Img_Iface_Data_Pixel_Set *data_cast; + char title [80]; /* Must have 1 channel */ if (image_copy_tmp.channels() != 1) { @@ -720,14 +720,14 @@ static void img_iface_pixel_set (void *data) data_tmp.val = user_iface_getint(0, 0, 255, title, NULL); - data = (void *)&data_tmp; + data = (const void *)&data_tmp; } /* Set pixel value */ img_cv_act(&image_copy_tmp, IMG_CV_ACT_PIXEL_SET, data); /* Write into log */ - data_cast = (struct Img_Iface_Data_Pixel_Set *)data; + data_cast = (const struct Img_Iface_Data_Pixel_Set *)data; snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Pixel get: (%i, %i): %i", data_cast->x, @@ -738,10 +738,10 @@ static void img_iface_pixel_set (void *data) } /* ----- ------- ROI */ -static void img_iface_set_ROI (void *data) +static void img_iface_set_ROI (const void *data) { - struct Img_Iface_Data_SetROI data_tmp; - struct Img_Iface_Data_SetROI *data_cast; + struct Img_Iface_Data_SetROI data_tmp; + const struct Img_Iface_Data_SetROI *data_cast; char title [80]; /* Data */ @@ -769,11 +769,11 @@ static void img_iface_set_ROI (void *data) image_copy_tmp.rows - data_tmp.rect.y, title, NULL); - data = (void *)&data_tmp; + data = (const void *)&data_tmp; } /* Write into log */ - data_cast = (struct Img_Iface_Data_SetROI *)data; + data_cast = (const struct Img_Iface_Data_SetROI *)data; snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "ROI: (%i,%i) w=%i,h=%i", data_cast->rect.x, @@ -787,10 +787,10 @@ static void img_iface_set_ROI (void *data) img_cv_act(&image_copy_tmp, IMG_CV_ACT_SET_ROI, data); } -static void img_iface_set_ROI_2rect (void *data) +static void img_iface_set_ROI_2rect (const void *data) { - struct Img_Iface_Data_SetROI data_tmp; - struct Img_Iface_Data_SetROI *data_cast; + struct Img_Iface_Data_SetROI data_tmp; + const struct Img_Iface_Data_SetROI *data_cast; /* Data */ if (!data) { @@ -799,11 +799,11 @@ static void img_iface_set_ROI_2rect (void *data) data_tmp.rect.width = rectangle.width; data_tmp.rect.height = rectangle.height; - data = (void *)&data_tmp; + data = (const void *)&data_tmp; } /* Write into log */ - data_cast = (struct Img_Iface_Data_SetROI *)data; + data_cast = (const struct Img_Iface_Data_SetROI *)data; snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "ROI: (%i,%i) w=%i,h=%i", data_cast->rect.x, @@ -820,6 +820,7 @@ static void img_iface_set_ROI_2rect (void *data) /* ----- ------- Operations on arrays */ static void img_iface_and_2ref (void) { + /* Must have same channels */ if (image_copy_tmp.channels() != image_ref.channels()) { /* Write into log */ @@ -838,11 +839,12 @@ static void img_iface_and_2ref (void) (user_iface_log.len)++; /* Bitwise AND to reference */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_AND_2REF, (void *)&image_ref); + img_cv_act(&image_copy_tmp, IMG_CV_ACT_AND_2REF, (const void *)&image_ref); } static void img_iface_not (void) { + /* Write into log */ snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Invert color"); @@ -855,6 +857,7 @@ static void img_iface_not (void) static void img_iface_or_2ref (void) { + /* Must have same channels */ if (image_copy_tmp.channels() != image_ref.channels()) { /* Write into log */ @@ -873,11 +876,15 @@ static void img_iface_or_2ref (void) (user_iface_log.len)++; /* Bitwise OR to reference */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_OR_2REF, (void *)&image_ref); + img_cv_act(&image_copy_tmp, IMG_CV_ACT_OR_2REF, (const void *)&image_ref); } -static void img_iface_component (void *data) +static void img_iface_component (const void *data) { + struct Img_Iface_Data_Component data_tmp; + const struct Img_Iface_Data_Component *data_cast; + char title [80]; + /* Must have at least 3 channels */ if (image_copy_tmp.channels() < 3) { /* Write into log */ @@ -890,21 +897,18 @@ static void img_iface_component (void *data) } /* Data */ - struct Img_Iface_Data_Component data_tmp; if (!data) { /* Ask user */ - char title [80]; snprintf(title, 80, "Component:"); data_tmp.cmp = user_iface_getint(0, 0, image_copy_tmp.channels() - 1, title, NULL); - data = (void *)&data_tmp; + data = (const void *)&data_tmp; } /* Write into log */ - struct Img_Iface_Data_Component *data_cast; - data_cast = (struct Img_Iface_Data_Component *)data; + data_cast = (const struct Img_Iface_Data_Component *)data; snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Component %i", data_cast->cmp); @@ -917,22 +921,23 @@ static void img_iface_component (void *data) /* ----- Imgproc: Image processing */ /* ----- ------- Image filtering */ -static void img_iface_dilate (void *data) +static void img_iface_dilate (const void *data) { + struct Img_Iface_Data_Dilate_Erode data_tmp; + const struct Img_Iface_Data_Dilate_Erode *data_cast; + char title [80]; + /* Data */ - struct Img_Iface_Data_Dilate_Erode data_tmp; if (!data) { /* Ask user */ - char title [80]; snprintf(title, 80, "Iterations:"); data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); - data = (void *)&data_tmp; + data = (const void *)&data_tmp; } /* Write into log */ - struct Img_Iface_Data_Dilate_Erode *data_cast; - data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; + data_cast = (const struct Img_Iface_Data_Dilate_Erode *)data; snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Dilate i=%i", data_cast->i); @@ -943,22 +948,23 @@ static void img_iface_dilate (void *data) img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data); } -static void img_iface_erode (void *data) +static void img_iface_erode (const void *data) { + struct Img_Iface_Data_Dilate_Erode data_tmp; + const struct Img_Iface_Data_Dilate_Erode *data_cast; + char title [80]; + /* Data */ - struct Img_Iface_Data_Dilate_Erode data_tmp; if (!data) { /* Ask user */ - char title [80]; snprintf(title, 80, "Iterations:"); data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); - data = (void *)&data_tmp; + data = (const void *)&data_tmp; } /* Write into log */ - struct Img_Iface_Data_Dilate_Erode *data_cast; - data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; + data_cast = (const struct Img_Iface_Data_Dilate_Erode *)data; snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Erode i=%i", data_cast->i); @@ -969,22 +975,23 @@ static void img_iface_erode (void *data) img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data); } -static void img_iface_dilate_erode (void *data) +static void img_iface_dilate_erode (const void *data) { + struct Img_Iface_Data_Dilate_Erode data_tmp; + const struct Img_Iface_Data_Dilate_Erode *data_cast; + char title [80]; + /* Data */ - struct Img_Iface_Data_Dilate_Erode data_tmp; if (!data) { /* Ask user */ - char title [80]; snprintf(title, 80, "Iterations:"); data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); - data = (void *)&data_tmp; + data = (const void *)&data_tmp; } /* Write into log */ - struct Img_Iface_Data_Dilate_Erode *data_cast; - data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; + data_cast = (const struct Img_Iface_Data_Dilate_Erode *)data; snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Dilate-erode i=%i", data_cast->i); @@ -996,22 +1003,23 @@ static void img_iface_dilate_erode (void *data) img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data); } -static void img_iface_erode_dilate (void *data) +static void img_iface_erode_dilate (const void *data) { - /* Data */ struct Img_Iface_Data_Dilate_Erode data_tmp; + const struct Img_Iface_Data_Dilate_Erode *data_cast; + char title [80]; + + /* Data */ if (!data) { /* Ask user */ - char title [80]; snprintf(title, 80, "Iterations:"); data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); - data = (void *)&data_tmp; + data = (const void *)&data_tmp; } /* Write into log */ - struct Img_Iface_Data_Dilate_Erode *data_cast; - data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; + data_cast = (const struct Img_Iface_Data_Dilate_Erode *)data; snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Erode-dilate i=%i", data_cast->i); @@ -1023,25 +1031,26 @@ static void img_iface_erode_dilate (void *data) img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data); } -static void img_iface_smooth (void *data) +static void img_iface_smooth (const void *data) { - /* Data */ struct Img_Iface_Data_Smooth data_tmp; + const struct Img_Iface_Data_Smooth *data_cast; + char title [80]; + + /* Data */ if (!data) { /* Ask user */ - char title [80]; snprintf(title, 80, "Method: MEAN=1, GAUSS=2, MEDIAN=3"); data_tmp.method = user_iface_getint(1, 3, 3, title, NULL); snprintf(title, 80, "Kernel size: 3, 5, 7, ..."); data_tmp.ksize = user_iface_getint(3, 3, INFINITY, title, NULL); - data = (void *)&data_tmp; + data = (const void *)&data_tmp; } /* Write into log */ - struct Img_Iface_Data_Smooth *data_cast; - data_cast = (struct Img_Iface_Data_Smooth *)data; + data_cast = (const struct Img_Iface_Data_Smooth *)data; snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Smooth mth=%i [%ix%i]", data_cast->method, @@ -1054,8 +1063,12 @@ static void img_iface_smooth (void *data) img_cv_act(&image_copy_tmp, IMG_CV_ACT_SMOOTH, data); } -static void img_iface_sobel (void *data) +static void img_iface_sobel (const void *data) { + struct Img_Iface_Data_Sobel data_tmp; + const struct Img_Iface_Data_Sobel *data_cast; + char title [80]; + /* Must have 1 channel */ if (image_copy_tmp.channels() != 1) { /* Write into log */ @@ -1068,10 +1081,8 @@ static void img_iface_sobel (void *data) } /* Data */ - struct Img_Iface_Data_Sobel data_tmp; if (!data) { /* Ask user */ - char title [80]; snprintf(title, 80, "Order of the derivative x"); data_tmp.dx = user_iface_getint(0, 1, 10, title, NULL); @@ -1081,12 +1092,11 @@ static void img_iface_sobel (void *data) snprintf(title, 80, "Size of the extended Sobel kernel (-1 -> Scharr"); data_tmp.ksize = user_iface_getint(-1, 3, 7, title, NULL); - data = (void *)&data_tmp; + data = (const void *)&data_tmp; } /* Write into log */ - struct Img_Iface_Data_Sobel *data_cast; - data_cast = (struct Img_Iface_Data_Sobel *)data; + data_cast = (const struct Img_Iface_Data_Sobel *)data; snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Sobel dx=%i;dy=%i [ks=%i]", data_cast->dx, @@ -1099,8 +1109,12 @@ static void img_iface_sobel (void *data) img_cv_act(&image_copy_tmp, IMG_CV_ACT_SOBEL, data); } -static void img_iface_border (void *data) +static void img_iface_border (const void *data) { + struct Img_Iface_Data_Border data_tmp; + const struct Img_Iface_Data_Border *data_cast; + char title [80]; + /* Must have 1 channel */ if (image_copy_tmp.channels() != 1) { /* Write into log */ @@ -1113,19 +1127,16 @@ static void img_iface_border (void *data) } /* Data */ - struct Img_Iface_Data_Border data_tmp; if (!data) { /* Ask user */ - char title [80]; snprintf(title, 80, "Size"); data_tmp.size = user_iface_getint(1, 1, 0xF000, title, NULL); - data = (void *)&data_tmp; + data = (const void *)&data_tmp; } /* Write into log */ - struct Img_Iface_Data_Border *data_cast; - data_cast = (struct Img_Iface_Data_Border *)data; + data_cast = (const struct Img_Iface_Data_Border *)data; snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Border size=%i", data_cast->size); @@ -1137,22 +1148,23 @@ static void img_iface_border (void *data) } /* ----- ------- Geometric image transformations */ -static void img_iface_mirror (void *data) +static void img_iface_mirror (const void *data) { + struct Img_Iface_Data_Mirror data_tmp; + const struct Img_Iface_Data_Mirror *data_cast; + char title [80]; + /* Data */ - struct Img_Iface_Data_Mirror data_tmp; if (!data) { /* Ask user */ - char title [80]; snprintf(title, 80, "Axis: 0=x; 1=y"); data_tmp.axis = user_iface_getint(0, 1, 1, title, NULL); - data = (void *)&data_tmp; + data = (const void *)&data_tmp; } /* Write into log */ - struct Img_Iface_Data_Mirror *data_cast; - data_cast = (struct Img_Iface_Data_Mirror *)data; + data_cast = (const struct Img_Iface_Data_Mirror *)data; snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Mirror axis: %i", data_cast->axis); @@ -1163,22 +1175,23 @@ static void img_iface_mirror (void *data) img_cv_act(&image_copy_tmp, IMG_CV_ACT_MIRROR, data); } -static void img_iface_rotate_orto (void *data) +static void img_iface_rotate_orto (const void *data) { + struct Img_Iface_Data_Rotate_Orto data_tmp; + const struct Img_Iface_Data_Rotate_Orto *data_cast; + char title [80]; + /* Data */ - struct Img_Iface_Data_Rotate_Orto data_tmp; if (!data) { /* Ask user */ - char title [80]; snprintf(title, 80, "Rotate (counterclockwise) n * pi/2 rad; n:"); data_tmp.n = user_iface_getint(1, 1, 3, title, NULL); - data = (void *)&data_tmp; + data = (const void *)&data_tmp; } /* Write into log */ - struct Img_Iface_Data_Rotate_Orto *data_cast; - data_cast = (struct Img_Iface_Data_Rotate_Orto *)data; + data_cast = (const struct Img_Iface_Data_Rotate_Orto *)data; snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Rotate %i * pi/2 rad", data_cast->n); @@ -1189,13 +1202,15 @@ static void img_iface_rotate_orto (void *data) img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE_ORTO, data); } -static void img_iface_rotate (void *data) +static void img_iface_rotate (const void *data) { - /* Data */ struct Img_Iface_Data_Rotate data_tmp; + const struct Img_Iface_Data_Rotate *data_cast; + char title [80]; + + /* Data */ if (!data) { /* Ask user */ - char title [80]; snprintf(title, 80, "Center: x:"); data_tmp.center.x = user_iface_getdbl(0, 0, INFINITY, title, NULL); @@ -1205,12 +1220,11 @@ static void img_iface_rotate (void *data) snprintf(title, 80, "Angle: (deg)"); data_tmp.angle = user_iface_getdbl(-INFINITY, 0, INFINITY, title, NULL); - data = (void *)&data_tmp; + data = (const void *)&data_tmp; } /* Write into log */ - struct Img_Iface_Data_Rotate *data_cast; - data_cast = (struct Img_Iface_Data_Rotate *)data; + data_cast = (const struct Img_Iface_Data_Rotate *)data; snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Rotate (%.2f,%.2f) %lfº", data_cast->center.x, @@ -1223,10 +1237,11 @@ static void img_iface_rotate (void *data) img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE, data); } -static void img_iface_rotate_2rect (void *data) +static void img_iface_rotate_2rect (const void *data) { - /* Data */ struct Img_Iface_Data_Rotate data_tmp; + + /* Data */ if (!data) { data_tmp.center.x = rectangle_rot.center.x; data_tmp.center.y = rectangle_rot.center.y; @@ -1237,7 +1252,7 @@ static void img_iface_rotate_2rect (void *data) data_tmp.angle += 90.0; } - data = (void *)&data_tmp; + data = (const void *)&data_tmp; } /* Write into log */ @@ -1251,8 +1266,11 @@ static void img_iface_rotate_2rect (void *data) } /* ----- ------- Miscellaneous image transformations */ -static void img_iface_adaptive_thr (void *data) +static void img_iface_adaptive_thr (const void *data) { + struct Img_Iface_Data_Adaptive_Thr data_tmp; + const struct Img_Iface_Data_Adaptive_Thr *data_cast; + /* Must have 1 channel */ if (image_copy_tmp.channels() != 1) { /* Write into log */ @@ -1265,7 +1283,6 @@ static void img_iface_adaptive_thr (void *data) } /* Data */ - struct Img_Iface_Data_Adaptive_Thr data_tmp; if (!data) { /* Ask user */ char title [80]; @@ -1278,12 +1295,11 @@ static void img_iface_adaptive_thr (void *data) snprintf(title, 80, "Kernel size: 3, 5, 7, ..."); data_tmp.ksize = user_iface_getint(3, 3, INFINITY, title, NULL); - data = (void *)&data_tmp; + data = (const void *)&data_tmp; } /* Write into log */ - struct Img_Iface_Data_Adaptive_Thr *data_cast; - data_cast = (struct Img_Iface_Data_Adaptive_Thr *)data; + data_cast = (const struct Img_Iface_Data_Adaptive_Thr *)data; snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Threshold mth=%i, typ=%i, ks=%i", data_cast->method, @@ -1296,8 +1312,12 @@ static void img_iface_adaptive_thr (void *data) img_cv_act(&image_copy_tmp, IMG_CV_ACT_ADAPTIVE_THRESHOLD, data); } -static void img_iface_cvt_color (void *data) +static void img_iface_cvt_color (const void *data) { + struct Img_Iface_Data_Cvt_Color data_tmp; + const struct Img_Iface_Data_Cvt_Color *data_cast; + char title [80]; + /* Must have at least 3 channels */ if (image_copy_tmp.channels() < 3) { /* Write into log */ @@ -1310,21 +1330,18 @@ static void img_iface_cvt_color (void *data) } /* Data */ - struct Img_Iface_Data_Cvt_Color data_tmp; if (!data) { /* Ask user */ - char title [80]; snprintf(title, 80, "Method: BGR2GRAY = 6, BGR2HSV = 40"); data_tmp.method = user_iface_getint(0, 0, cv::COLOR_COLORCVT_MAX, title, NULL); - data = (void *)&data_tmp; + data = (const void *)&data_tmp; } /* Write into log */ - struct Img_Iface_Data_Cvt_Color *data_cast; - data_cast = (struct Img_Iface_Data_Cvt_Color *)data; + data_cast = (const struct Img_Iface_Data_Cvt_Color *)data; snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Convert color %i", data_cast->method); @@ -1337,6 +1354,7 @@ static void img_iface_cvt_color (void *data) static void img_iface_distance_transform (void) { + /* Must have 1 channel */ if (image_copy_tmp.channels() != 1) { /* Write into log */ @@ -1358,8 +1376,12 @@ static void img_iface_distance_transform (void) img_cv_act(&image_copy_tmp, IMG_CV_ACT_DISTANCE_TRANSFORM, NULL); } -static void img_iface_threshold (void *data) +static void img_iface_threshold (const void *data) { + struct Img_Iface_Data_Threshold data_tmp; + const struct Img_Iface_Data_Threshold *data_cast; + char title [80]; + /* Must have 1 channel */ if (image_copy_tmp.channels() != 1) { /* Write into log */ @@ -1372,22 +1394,19 @@ static void img_iface_threshold (void *data) } /* Data */ - struct Img_Iface_Data_Threshold data_tmp; if (!data) { /* Ask user */ - char title [80]; snprintf(title, 80, "Type: BIN=0, BIN_INV=1, TRUNC=2, TOZ=3, TOZ_INV=4"); data_tmp.thr_typ = user_iface_getint(0, 0, 4, title, NULL); snprintf(title, 80, "Value: 0 to 255 (or -1 for Otsu's algorithm)"); data_tmp.thr_val = user_iface_getint(-1, 0, 255, title, NULL); - data = (void *)&data_tmp; + data = (const void *)&data_tmp; } /* Write into log */ - struct Img_Iface_Data_Threshold *data_cast; - data_cast = (struct Img_Iface_Data_Threshold *)data; + data_cast = (const struct Img_Iface_Data_Threshold *)data; snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Threshold typ=%i, val=%i", data_cast->thr_typ, @@ -1400,8 +1419,10 @@ static void img_iface_threshold (void *data) } /* ----- ------- Histograms */ -static void img_iface_histogram (void *data) +static void img_iface_histogram (const void *data) { + struct Img_Iface_Data_Histogram data_tmp; + /* Must have 1 channel */ if (image_copy_tmp.channels() != 1) { /* Write into log */ @@ -1414,12 +1435,11 @@ static void img_iface_histogram (void *data) } /* Data */ - struct Img_Iface_Data_Histogram data_tmp; if (!data) { - data_tmp.hist_c0 = &histogram_c0; + data_tmp.hist_c0 = &histogram_c0; data_tmp.hist_img = &hist_img_c1; - data = (void *)&data_tmp; + data = (const void *)&data_tmp; } /* Write into log */ @@ -1432,8 +1452,10 @@ static void img_iface_histogram (void *data) img_cv_act(&image_copy_tmp, IMG_CV_ACT_HISTOGRAM, data); } -static void img_iface_histogram_c3 (void *data) +static void img_iface_histogram_c3 (const void *data) { + struct Img_Iface_Data_Histogram data_tmp; + /* Must have 1 channel */ if (image_copy_tmp.channels() != 3) { /* Write into log */ @@ -1446,14 +1468,13 @@ static void img_iface_histogram_c3 (void *data) } /* Data */ - struct Img_Iface_Data_Histogram data_tmp; if (!data) { data_tmp.hist_c0 = &histogram_c0; data_tmp.hist_c1 = &histogram_c1; data_tmp.hist_c2 = &histogram_c2; data_tmp.hist_img = &hist_img_c3; - data = (void *)&data_tmp; + data = (const void *)&data_tmp; } /* Write into log */ @@ -1467,8 +1488,11 @@ static void img_iface_histogram_c3 (void *data) } /* ----- ------- Structural analysis and shape descriptors */ -static void img_iface_contours (void *data) +static void img_iface_contours (const void *data) { + struct Img_Iface_Data_Contours data_tmp; + const struct Img_Iface_Data_Contours *data_cast; + /* Must have 1 channel */ if (image_copy_tmp.channels() != 1) { /* Write into log */ @@ -1481,20 +1505,18 @@ static void img_iface_contours (void *data) } /* Data */ - struct Img_Iface_Data_Contours data_tmp; if (!data) { data_tmp.contours = &contours; data_tmp.hierarchy = &hierarchy; - data = (void *)&data_tmp; + data = (const void *)&data_tmp; } /* Contours */ img_cv_act(&image_copy_tmp, IMG_CV_ACT_CONTOURS, data); /* Write into log */ - struct Img_Iface_Data_Contours *data_cast; - data_cast = (struct Img_Iface_Data_Contours *)data; + data_cast = (const struct Img_Iface_Data_Contours *)data; snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Contours n=%i", (int)data_cast->contours->size()); @@ -1502,30 +1524,31 @@ static void img_iface_contours (void *data) (user_iface_log.len)++; } -static void img_iface_contours_size (void *data) +static void img_iface_contours_size (const void *data) { + struct Img_Iface_Data_Contours_Size data_tmp; + const struct Img_Iface_Data_Contours_Size *data_cast; + unsigned i; + /* 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; + data = (const void *)&data_tmp; } /* Contours size */ img_cv_act(&image_copy_tmp, IMG_CV_ACT_CONTOURS_SIZE, data); /* Write into log */ - struct Img_Iface_Data_Contours_Size *data_cast; - data_cast = (struct Img_Iface_Data_Contours_Size *)data; + data_cast = (const struct Img_Iface_Data_Contours_Size *)data; snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Contours size:"); user_iface_log.lvl[user_iface_log.len] = 1; (user_iface_log.len)++; - int i; - for (i = 0; i < (int)data_cast->contours->size(); i++) { + for (i = 0; i < data_cast->contours->size(); i++) { snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "cnt[%i]: A=%lf; P=%lf;", i, @@ -1536,10 +1559,10 @@ static void img_iface_contours_size (void *data) } } -static void img_iface_bounding_rect (void *data) +static void img_iface_bounding_rect (const void *data) { - /* Data */ struct Img_Iface_Data_Bounding_Rect data_tmp; + if (!data) { if(!contours.size()) { /* Write into log */ @@ -1555,7 +1578,7 @@ static void img_iface_bounding_rect (void *data) data_tmp.rect = &rectangle; data_tmp.show = true; - data = (void *)&data_tmp; + data = (const void *)&data_tmp; } /* Write into log */ @@ -1568,10 +1591,10 @@ static void img_iface_bounding_rect (void *data) img_cv_act(&image_copy_tmp, IMG_CV_ACT_BOUNDING_RECT, data); } -static void img_iface_fit_ellipse (void *data) +static void img_iface_fit_ellipse (const void *data) { - /* Data */ struct Img_Iface_Data_MinARect data_tmp; + if (!data) { if(!contours.size()) { /* Write into log */ @@ -1587,7 +1610,7 @@ static void img_iface_fit_ellipse (void *data) data_tmp.rect = &rectangle_rot; - data = (void *)&data_tmp; + data = (const void *)&data_tmp; } /* Write into log */ @@ -1600,10 +1623,10 @@ static void img_iface_fit_ellipse (void *data) img_cv_act(&image_copy_tmp, IMG_CV_ACT_FIT_ELLIPSE, data); } -static void img_iface_min_area_rect (void *data) +static void img_iface_min_area_rect (const void *data) { - /* Data */ struct Img_Iface_Data_MinARect data_tmp; + if (!data) { if(!contours.size()) { /* Write into log */ @@ -1619,7 +1642,7 @@ static void img_iface_min_area_rect (void *data) data_tmp.rect = &rectangle_rot; data_tmp.show = true; - data = (void *)&data_tmp; + data = (const void *)&data_tmp; } /* Write into log */ @@ -1633,8 +1656,12 @@ static void img_iface_min_area_rect (void *data) } /* ----- ------- Feature detection */ -static void img_iface_hough_circles (void *data) +static void img_iface_hough_circles (const void *data) { + struct Img_Iface_Data_Hough_Circles data_tmp; + const struct Img_Iface_Data_Hough_Circles *data_cast; + char title [80]; + /* Must have 1 channel */ if (image_copy_tmp.channels() != 1) { /* Write into log */ @@ -1647,12 +1674,10 @@ static void img_iface_hough_circles (void *data) } /* Data */ - struct Img_Iface_Data_Hough_Circles data_tmp; if (!data) { data_tmp.circles = &circles; /* Ask user */ - char title [80]; snprintf(title, 80, "Minimum distance:"); data_tmp.dist_min = user_iface_getdbl(0, 5, INFINITY, title, NULL); @@ -1668,15 +1693,14 @@ static void img_iface_hough_circles (void *data) snprintf(title, 80, "Maximum radius"); data_tmp.radius_max = user_iface_getint(0, 0, INFINITY, title, NULL); - data = (void *)&data_tmp; + data = (const void *)&data_tmp; } /* Circles */ img_cv_act(&image_copy_tmp, IMG_CV_ACT_HOUGH_CIRCLES, data); /* Write into log */ - struct Img_Iface_Data_Hough_Circles *data_cast; - data_cast = (struct Img_Iface_Data_Hough_Circles *)data; + data_cast = (const struct Img_Iface_Data_Hough_Circles *)data; snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Circles n=%i", (int)data_cast->circles->size()); @@ -1709,8 +1733,10 @@ static void img_iface_align (void) } /* img_calib3d ---------------------------------------------------------------*/ -static void img_iface_calibrate (void *data) +static void img_iface_calibrate (const void *data) { + struct Img_Iface_Data_Calibrate data_tmp; + /* Must have 1 channel */ if (image_copy_tmp.channels() != 1) { /* Write into log */ @@ -1723,14 +1749,13 @@ static void img_iface_calibrate (void *data) } /* Data */ - struct Img_Iface_Data_Calibrate data_tmp; if (!data) { data_tmp.intrinsic_mat = &intrinsic_mat; data_tmp.dist_coefs = &dist_coefs; data_tmp.rvecs = &rvecs; data_tmp.tvecs = &tvecs; - data = (void *)&data_tmp; + data = (const void *)&data_tmp; } /* Write into log */ @@ -1743,15 +1768,16 @@ static void img_iface_calibrate (void *data) img_calib3d_act(&image_copy_tmp, IMG_CALIB3D_ACT_CALIBRATE, data); } -static void img_iface_undistort (void *data) +static void img_iface_undistort (const void *data) { - /* Data */ struct Img_Iface_Data_Undistort data_tmp; + + /* Data */ if (!data) { data_tmp.intrinsic_mat = &intrinsic_mat; data_tmp.dist_coefs = &dist_coefs; - data = (void *)&data_tmp; + data = (const void *)&data_tmp; } /* Write into log */ @@ -1765,8 +1791,13 @@ static void img_iface_undistort (void *data) } /* img_zbar ------------------------------------------------------------------*/ -static void img_iface_decode (void *data) +static void img_iface_decode (const void *data) { + struct Img_Iface_Data_Decode data_tmp; + const struct Img_Iface_Data_Decode *data_cast; + char title [80]; + int i; + /* Must have 1 channel */ if (image_copy_tmp.channels() != 1) { /* Write into log */ @@ -1779,21 +1810,18 @@ static void img_iface_decode (void *data) } /* Data */ - struct Img_Iface_Data_Decode data_tmp; if (!data) { /* Ask user */ - char title [80]; snprintf(title, 80, "Type of code: (0 for all)"); data_tmp.code_type = (enum zbar::zbar_symbol_type_e) user_iface_getint(0, 0, INT_MAX, title, NULL); - data = (void *)&data_tmp; + data = (const void *)&data_tmp; } /* Write into log */ - struct Img_Iface_Data_Decode *data_cast; - data_cast = (struct Img_Iface_Data_Decode *)data; + data_cast = (const struct Img_Iface_Data_Decode *)data; snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Detect codes c=%i", data_cast->code_type); @@ -1812,7 +1840,6 @@ static void img_iface_decode (void *data) (user_iface_log.len)++; } else { /* Write results into log */ - int i; for (i = 0; i < zb_codes.n; i++) { snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "%s -- '%s'", @@ -1825,8 +1852,12 @@ static void img_iface_decode (void *data) } /* img_ocr -------------------------------------------------------------------*/ -static void img_iface_read (void *data) +static void img_iface_read (const void *data) { + struct Img_Iface_Data_Read data_tmp; + const struct Img_Iface_Data_Read *data_cast; + char title [80]; + /* Must have 1 channel */ if (image_copy_tmp.channels() != 1) { /* Write into log */ @@ -1838,23 +1869,31 @@ static void img_iface_read (void *data) return; } + data_cast = (const struct Img_Iface_Data_Read *)data; + /* Data */ - struct Img_Iface_Data_Read data_tmp; if (!data) { /* Ask user */ - char title [80]; snprintf(title, 80, "Language: ENG = 0, SPA = 1, CAT = 2"); data_tmp.lang = user_iface_getint(0, 1, 2, title, NULL); snprintf(title, 80, "Config: none = 0, Price = 1"); data_tmp.conf = user_iface_getint(0, 1, 2, title, NULL); - - data = (void *)&data_tmp; + } else { + data_tmp.lang = data_cast->lang; + data_tmp.conf = data_cast->conf; } + /* Adapt image data */ + data_tmp.img.data = image_copy_tmp.data; + data_tmp.img.width = image_copy_tmp.size().width; + data_tmp.img.height = image_copy_tmp.size().height; + data_tmp.img.B_per_pix = image_copy_tmp.channels(); + data_tmp.img.B_per_line = image_copy_tmp.step1(); + + data = (const void *)&data_tmp; + /* Write into log */ - struct Img_Iface_Data_Read *data_cast; - data_cast = (struct Img_Iface_Data_Read *)data; snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "OCR (lang=%i) [c=%i]", data_cast->lang, @@ -1862,13 +1901,6 @@ static void img_iface_read (void *data) user_iface_log.lvl[user_iface_log.len] = 1; (user_iface_log.len)++; - /* Adapt image data */ - data_cast->img.data = image_copy_tmp.data; - data_cast->img.width = image_copy_tmp.size().width; - data_cast->img.height = image_copy_tmp.size().height; - data_cast->img.B_per_pix = image_copy_tmp.channels(); - data_cast->img.B_per_line = image_copy_tmp.step1(); - /* OCR */ img_ocr_act(IMG_OCR_ACT_READ, data); @@ -1885,6 +1917,7 @@ static void img_iface_read (void *data) /* img_iface -----------------------------------------------------------------*/ static void img_iface_apply (void) { + /* Write into log */ snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Apply changes"); @@ -1898,6 +1931,7 @@ static void img_iface_apply (void) static void img_iface_discard (void) { + /* Write into log */ snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Discard changes"); @@ -1909,17 +1943,18 @@ static void img_iface_discard (void) image_copy_old.copyTo(image_copy_tmp); } -static void img_iface_save_mem (void *data) +static void img_iface_save_mem (const void *data) { - /* Which memory to use */ int x; + char title [80]; + + /* Which memory to use */ if (!data) { /* Ask user */ - char title [80]; snprintf(title, 80, "mem_X; X:"); x = user_iface_getint(0, 0, IMG_MEM_SIZE - 1, title, NULL); } else { - x = *(int *)data; + x = *(const int *)data; } /* Write into log */ @@ -1933,17 +1968,18 @@ static void img_iface_save_mem (void *data) image_copy_tmp.copyTo(image_mem[x]); } -static void img_iface_load_mem (void *data) +static void img_iface_load_mem (const void *data) { - /* Which memory to use */ int x; + char title [80]; + + /* Which memory to use */ if (!data) { /* Ask user which memory to use */ - char title [80]; snprintf(title, 80, "mem_X; X:"); x = user_iface_getint(0, 0, IMG_MEM_SIZE - 1, title, NULL); } else { - x = *(int *)data; + x = *(const int *)data; } /* Write into log */ @@ -1963,6 +1999,7 @@ static void img_iface_load_mem (void *data) static void img_iface_save_ref (void) { + /* Write into log */ snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Save to reference"); @@ -1977,6 +2014,7 @@ static void img_iface_save_ref (void) /* save ----------------------------------------------------------------------*/ static void img_iface_save_file (void) { + /* Write into log */ snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Save as..."); @@ -1993,6 +2031,7 @@ static void img_iface_save_file (void) static void img_iface_save_update (void) { + /* Write into log */ snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Save: update img"); diff --git a/modules/image/src/img_ocr.c b/modules/image/src/img_ocr.c index 0f49b7c..e829bdf 100644 --- a/modules/image/src/img_ocr.c +++ b/modules/image/src/img_ocr.c @@ -32,13 +32,13 @@ /****************************************************************************** ******* static functions ***************************************************** ******************************************************************************/ -static void img_ocr_read (void *data); +static void img_ocr_read (const void *data); /****************************************************************************** ******* main ***************************************************************** ******************************************************************************/ -void img_ocr_act (int action, void *data) +void img_ocr_act (int action, const void *data) { switch (action) { case IMG_OCR_ACT_READ: @@ -51,10 +51,10 @@ void img_ocr_act (int action, void *data) /****************************************************************************** ******* static functions ***************************************************** ******************************************************************************/ -static void img_ocr_read (void *data) +static void img_ocr_read (const void *data) { - struct Img_Iface_Data_Read *data_cast; - struct TessBaseAPI *handle_ocr; + const struct Img_Iface_Data_Read *data_cast; + struct TessBaseAPI *handle_ocr; int lang; char lang_str [20 + 1]; int conf; @@ -62,7 +62,7 @@ static void img_ocr_read (void *data) char *txt; /* Data */ - data_cast = (struct Img_Iface_Data_Read *)data; + data_cast = (const struct Img_Iface_Data_Read *)data; /* Language */ lang = data_cast->lang; @@ -89,7 +89,8 @@ static void img_ocr_read (void *data) switch (conf) { case IMG_IFACE_OCR_CONF_PRICE: if (snprintf(conf_str, FILENAME_MAX, "%s/%s", - share_path, "price")) { + share_path, + "price") >= FILENAME_MAX) { printf("Path is too large and has been truncated\n"); printf("Price configuration was not possible!\n"); conf = IMG_IFACE_OCR_CONF_NONE; diff --git a/modules/image/src/img_orb.cpp b/modules/image/src/img_orb.cpp index 113f3dd..d090dd0 100644 --- a/modules/image/src/img_orb.cpp +++ b/modules/image/src/img_orb.cpp @@ -34,14 +34,14 @@ /****************************************************************************** ******* static functions ***************************************************** ******************************************************************************/ -static void img_orb_align (class cv::Mat *img_0, +static void img_orb_align (const class cv::Mat *img_0, class cv::Mat *img_1); /****************************************************************************** ******* main ***************************************************************** ******************************************************************************/ -void img_orb_act (class cv::Mat *img_ref, +void img_orb_act (const class cv::Mat *img_ref, class cv::Mat *imgptr, int action) { switch (action) { @@ -55,7 +55,7 @@ void img_orb_act (class cv::Mat *img_ref, /****************************************************************************** ******* static functions ***************************************************** ******************************************************************************/ -static void img_orb_align (class cv::Mat *img_0, +static void img_orb_align (const class cv::Mat *img_0, class cv::Mat *img_1) { /* Variables to store keypoints & descriptors */ diff --git a/modules/image/src/img_zbar.cpp b/modules/image/src/img_zbar.cpp index fe2b669..f5df97a 100644 --- a/modules/image/src/img_zbar.cpp +++ b/modules/image/src/img_zbar.cpp @@ -30,13 +30,13 @@ /****************************************************************************** ******* static functions ***************************************************** ******************************************************************************/ -static void img_zb_decode (class cv::Mat *imgptr, void *data); +static void img_zb_decode (class cv::Mat *imgptr, const void *data); /****************************************************************************** ******* main ***************************************************************** ******************************************************************************/ -void img_zb_act (class cv::Mat *imgptr, int action, void *data) +void img_zb_act (class cv::Mat *imgptr, int action, const void *data) { switch (action) { case IMG_ZB_ACT_DECODE: @@ -49,23 +49,24 @@ void img_zb_act (class cv::Mat *imgptr, int action, void *data) /****************************************************************************** ******* static functions ***************************************************** ******************************************************************************/ -static void img_zb_decode (class cv::Mat *imgptr, void *data) +static void img_zb_decode (class cv::Mat *imgptr, const void *data) { struct zbar::zbar_image_scanner_s *scanner; struct zbar::zbar_image_s *image_zb; const struct zbar::zbar_symbol_s *symbol; + enum zbar::zbar_symbol_type_e code_type; + int i; /* Type of code to scan */ - enum zbar::zbar_symbol_type_e code_type; - code_type = ((struct Img_Iface_Data_Decode *)data)->code_type; + code_type = ((const struct Img_Iface_Data_Decode *)data)->code_type; /* create & configure a reader */ - scanner = zbar::zbar_image_scanner_create(); + scanner = zbar::zbar_image_scanner_create(); zbar::zbar_image_scanner_set_config(scanner, code_type, zbar::ZBAR_CFG_ENABLE, 1); /* wrap image data */ - image_zb = zbar::zbar_image_create(); + image_zb = zbar::zbar_image_create(); zbar::zbar_image_set_format(image_zb, *(int*)"GREY"); zbar::zbar_image_set_size(image_zb, imgptr->cols, imgptr->rows); zbar::zbar_image_set_data(image_zb, (void *)(imgptr->data), @@ -73,14 +74,13 @@ static void img_zb_decode (class cv::Mat *imgptr, void *data) NULL); /* scan the image for barcodes */ - int i; - zb_codes.n = zbar::zbar_scan_image(scanner, image_zb); + zb_codes.n = zbar::zbar_scan_image(scanner, image_zb); if (zb_codes.n) { /* extract results */ - symbol = zbar::zbar_image_first_symbol(image_zb); + symbol = zbar::zbar_image_first_symbol(image_zb); for (i = 0; i < ZB_CODES_MAX && symbol; i++) { /* Write results into array */ - zb_codes.arr[i].type = zbar::zbar_symbol_get_type(symbol); + zb_codes.arr[i].type = zbar::zbar_symbol_get_type(symbol); snprintf(zb_codes.arr[i].sym_name, 80, "%s", zbar::zbar_get_symbol_name( zb_codes.arr[i].type)); @@ -88,7 +88,7 @@ static void img_zb_decode (class cv::Mat *imgptr, void *data) zbar::zbar_symbol_get_data(symbol)); /* Load next symbol */ - symbol = zbar::zbar_symbol_next(symbol); + symbol = zbar::zbar_symbol_next(symbol); } } diff --git a/modules/image/tmp/Makefile b/modules/image/tmp/Makefile index e3fba87..fe8a913 100644 --- a/modules/image/tmp/Makefile +++ b/modules/image/tmp/Makefile @@ -57,8 +57,8 @@ IMGOCR_INC_DIRS = -I $(INC_DIR) \ IMGI_INC_SAVE = save.hpp IMGI_INC_USR = user_iface.hpp -IMGI_INC = img_iface.hpp img_alx.hpp img_cv.hpp img_zbar.hpp \ - img_ocr.hpp img_orb.hpp +IMGI_INC = img_iface.hpp img_alx.hpp img_calib3d.hpp img_cv.hpp \ + img_zbar.hpp img_ocr.hpp img_orb.hpp IMGI_DEPS = $(SRC_DIR)/img_iface.cpp \ $(patsubst %,$(INC_DIR)/%,$(IMGI_INC)) \ $(patsubst %,$(SAVE_INC_DIR)/%,$(IMGI_INC_SAVE)) \ @@ -80,53 +80,53 @@ img_mod.o: $(_ALL) img_alx.s: $(IMGALX_DEPS) - $(Q)$(CXX) $(CXXFLAGS) $(IMGALX_INC_DIRS) -S $< -o $@ @echo " CXX $@" + $(Q)$(CXX) $(CXXFLAGS) $(IMGALX_INC_DIRS) -S $< -o $@ img_alx.o: img_alx.s - $(Q)$(AS) $< -o $@ @echo " AS $@" + $(Q)$(AS) $< -o $@ img_cv.s: $(IMGCV_DEPS) - $(Q)$(CXX) $(CXXFLAGS) $(IMGCV_INC_DIRS) -S $< -o $@ @echo " CXX $@" + $(Q)$(CXX) $(CXXFLAGS) $(IMGCV_INC_DIRS) -S $< -o $@ img_cv.o: img_cv.s - $(Q)$(AS) $< -o $@ @echo " AS $@" + $(Q)$(AS) $< -o $@ img_orb.s: $(IMGORB_DEPS) - $(Q)$(CXX) $(CXXFLAGS) $(IMGORB_INC_DIRS) -S $< -o $@ @echo " CXX $@" + $(Q)$(CXX) $(CXXFLAGS) $(IMGORB_INC_DIRS) -S $< -o $@ img_orb.o: img_orb.s - $(Q)$(AS) $< -o $@ @echo " AS $@" + $(Q)$(AS) $< -o $@ img_calib3d.s: $(IMGC3D_DEPS) - $(Q)$(CXX) $(CXXFLAGS) $(IMGC3D_INC_DIRS) -S $< -o $@ @echo " CXX $@" + $(Q)$(CXX) $(CXXFLAGS) $(IMGC3D_INC_DIRS) -S $< -o $@ img_calib3d.o: img_calib3d.s - $(Q)$(AS) $< -o $@ @echo " AS $@" + $(Q)$(AS) $< -o $@ img_zbar.s: $(IMGZB_DEPS) - $(Q)$(CXX) $(CXXFLAGS) $(IMGZB_INC_DIRS) -S $< -o $@ @echo " CXX $@" + $(Q)$(CXX) $(CXXFLAGS) $(IMGZB_INC_DIRS) -S $< -o $@ img_zbar.o: img_zbar.s - $(Q)$(AS) $< -o $@ @echo " AS $@" + $(Q)$(AS) $< -o $@ img_ocr.s: $(IMGOCR_DEPS) - $(Q)$(CC) $(CFLAGS) $(IMGOCR_INC_DIRS) -S $< -o $@ @echo " CC $@" + $(Q)$(CC) $(CFLAGS) $(IMGOCR_INC_DIRS) -S $< -o $@ img_ocr.o: img_ocr.s - $(Q)$(AS) $< -o $@ @echo " AS $@" + $(Q)$(AS) $< -o $@ img_iface.s: $(IMGI_DEPS) - $(Q)$(CXX) $(CXXFLAGS) $(IMGI_INC_DIRS) -S $< -o $@ @echo " CXX $@" + $(Q)$(CXX) $(CXXFLAGS) $(IMGI_INC_DIRS) -S $< -o $@ img_iface.o: img_iface.s - $(Q)$(AS) $< -o $@ @echo " AS $@" + $(Q)$(AS) $< -o $@ PHONY += clean diff --git a/modules/proc/inc/proc_common.hpp b/modules/proc/inc/proc_common.hpp index 5ba5faf..4dc8ee1 100644 --- a/modules/proc/inc/proc_common.hpp +++ b/modules/proc/inc/proc_common.hpp @@ -67,22 +67,22 @@ void proc_cvt_color (int method); void proc_distance_transform (void); void proc_threshold (int type, int ksize); void proc_contours ( - std::vector >> *contours, + class std::vector >> *contours, class cv::Mat *hierarchy); void proc_contours_size ( - std::vector >> *contours, + const class std::vector >> *contours, double *area, double *perimeter); void proc_bounding_rect ( - std::vector > *contour, + const class std::vector > *contour, class cv::Rect_ *rect, bool show); void proc_fit_ellipse ( - std::vector > *contour, + const class std::vector > *contour, class cv::RotatedRect *rect, bool show); void proc_min_area_rect ( - std::vector > *contour, + const class std::vector > *contour, class cv::RotatedRect *rect, bool show); diff --git a/modules/proc/src/proc_common.cpp b/modules/proc/src/proc_common.cpp index c1e19d5..e0ff8f7 100644 --- a/modules/proc/src/proc_common.cpp +++ b/modules/proc/src/proc_common.cpp @@ -53,38 +53,45 @@ static clock_t clock_1; ******************************************************************************/ 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); + + img_iface_act(IMG_IFACE_ACT_SAVE_MEM, (const void *)&n); } void proc_load_mem (int n) { - img_iface_act(IMG_IFACE_ACT_LOAD_MEM, (void *)&n); + + img_iface_act(IMG_IFACE_ACT_LOAD_MEM, (const 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(); @@ -92,6 +99,7 @@ void proc_local_max (void) void proc_skeleton (void) { + img_iface_act(IMG_IFACE_ACT_SKELETON, NULL); proc_show_img(); @@ -106,6 +114,7 @@ void proc_lines_vertical (void) void proc_median_horizontal (void) { + img_iface_act(IMG_IFACE_ACT_MEDIAN_HORIZONTAL, NULL); proc_show_img(); @@ -113,6 +122,7 @@ void proc_median_horizontal (void) void proc_median_vertical (void) { + img_iface_act(IMG_IFACE_ACT_MEDIAN_VERTICAL, NULL); proc_show_img(); @@ -124,7 +134,7 @@ void proc_pixel_get (int x, int y, unsigned char *val) data.x = x; data.y = y; data.val = val; - img_iface_act(IMG_IFACE_ACT_PIXEL_GET, (void *)&data); + img_iface_act(IMG_IFACE_ACT_PIXEL_GET, (const void *)&data); } void proc_pixel_set (int x, int y, unsigned char val) @@ -133,7 +143,7 @@ void proc_pixel_set (int x, int y, unsigned char val) data.x = x; data.y = y; data.val = val; - img_iface_act(IMG_IFACE_ACT_PIXEL_SET, (void *)&data); + img_iface_act(IMG_IFACE_ACT_PIXEL_SET, (const void *)&data); proc_show_img(); } @@ -146,13 +156,14 @@ void proc_ROI (int x, int y, int w, int h) data.rect.y = y; data.rect.width = w; data.rect.height = h; - img_iface_act(IMG_IFACE_ACT_SET_ROI, (void *)&data); + img_iface_act(IMG_IFACE_ACT_SET_ROI, (const void *)&data); proc_show_img(); } void proc_and_2ref (void) { + img_iface_act(USER_IFACE_ACT_AND_2REF, NULL); proc_show_img(); @@ -160,6 +171,7 @@ void proc_and_2ref (void) void proc_not (void) { + img_iface_act(USER_IFACE_ACT_NOT, NULL); proc_show_img(); @@ -167,6 +179,7 @@ void proc_not (void) void proc_or_2ref (void) { + img_iface_act(USER_IFACE_ACT_OR_2REF, NULL); proc_show_img(); @@ -177,7 +190,7 @@ void proc_cmp (int cmp) struct Img_Iface_Data_Component data; data.cmp = cmp; - img_iface_act(IMG_IFACE_ACT_COMPONENT, (void *)&data); + img_iface_act(IMG_IFACE_ACT_COMPONENT, (const void *)&data); proc_show_img(); } @@ -187,7 +200,7 @@ void proc_dilate (int size) struct Img_Iface_Data_Dilate_Erode data; data.i = size; - img_iface_act(IMG_IFACE_ACT_DILATE, (void *)&data); + img_iface_act(IMG_IFACE_ACT_DILATE, (const void *)&data); proc_show_img(); } @@ -197,7 +210,7 @@ void proc_erode (int size) struct Img_Iface_Data_Dilate_Erode data; data.i = size; - img_iface_act(IMG_IFACE_ACT_ERODE, (void *)&data); + img_iface_act(IMG_IFACE_ACT_ERODE, (const void *)&data); proc_show_img(); } @@ -207,7 +220,7 @@ 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); + img_iface_act(IMG_IFACE_ACT_DILATE_ERODE, (const void *)&data); proc_show_img(); } @@ -217,7 +230,7 @@ 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); + img_iface_act(IMG_IFACE_ACT_ERODE_DILATE, (const void *)&data); proc_show_img(); } @@ -228,7 +241,7 @@ void proc_smooth (int method, int ksize) data.method = method; data.ksize = ksize; - img_iface_act(IMG_IFACE_ACT_SMOOTH, (void *)&data); + img_iface_act(IMG_IFACE_ACT_SMOOTH, (const void *)&data); proc_show_img(); } @@ -238,7 +251,7 @@ void proc_border (int size) struct Img_Iface_Data_Border data; data.size = size; - img_iface_act(IMG_IFACE_ACT_BORDER, (void *)&data); + img_iface_act(IMG_IFACE_ACT_BORDER, (const void *)&data); proc_show_img(); } @@ -250,7 +263,7 @@ void proc_rotate (double center_x, double center_y, double angle) data.center.x = center_x; data.center.y = center_y; data.angle = angle; - img_iface_act(IMG_IFACE_ACT_ROTATE, (void *)&data); + img_iface_act(IMG_IFACE_ACT_ROTATE, (const void *)&data); proc_show_img(); } @@ -272,7 +285,7 @@ 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); + img_iface_act(IMG_IFACE_ACT_CVT_COLOR, (const void *)&data); proc_show_img(); } @@ -283,13 +296,14 @@ void proc_threshold (int type, int size) data.thr_typ = type; data.thr_val = size; - img_iface_act(IMG_IFACE_ACT_THRESHOLD, (void *)&data); + img_iface_act(IMG_IFACE_ACT_THRESHOLD, (const void *)&data); proc_show_img(); } void proc_distance_transform (void) { + img_iface_act(IMG_IFACE_ACT_DISTANCE_TRANSFORM, NULL); proc_show_img(); @@ -305,13 +319,13 @@ void proc_contours ( data.contours = contours; data.hierarchy = hierarchy; - img_iface_act(IMG_IFACE_ACT_CONTOURS, (void *)&data); + img_iface_act(IMG_IFACE_ACT_CONTOURS, (const void *)&data); proc_show_img(); } void proc_contours_size ( - class std::vector >> *contours, + const class std::vector >> *contours, double *area, double *perimeter ) @@ -321,11 +335,11 @@ void proc_contours_size ( data.contours = contours; data.area = area; data.perimeter = perimeter; - img_iface_act(IMG_IFACE_ACT_CONTOURS_SIZE, (void *)&data); + img_iface_act(IMG_IFACE_ACT_CONTOURS_SIZE, (const void *)&data); } void proc_bounding_rect ( - class std::vector > *contour, + const class std::vector > *contour, class cv::Rect_ *rect, bool show ) @@ -335,7 +349,7 @@ void proc_bounding_rect ( data.contour = contour; data.rect = rect; data.show = show; - img_iface_act(IMG_IFACE_ACT_BOUNDING_RECT, (void *)&data); + img_iface_act(IMG_IFACE_ACT_BOUNDING_RECT, (const void *)&data); if (show) { proc_show_img(); @@ -343,7 +357,7 @@ void proc_bounding_rect ( } void proc_fit_ellipse ( - class std::vector > *contour, + const class std::vector > *contour, class cv::RotatedRect *rect, bool show ) @@ -353,7 +367,7 @@ void proc_fit_ellipse ( data.contour = contour; data.rect = rect; data.show = show; - img_iface_act(IMG_IFACE_ACT_FIT_ELLIPSE, (void *)&data); + img_iface_act(IMG_IFACE_ACT_FIT_ELLIPSE, (const void *)&data); if (show) { @@ -362,7 +376,7 @@ void proc_fit_ellipse ( } void proc_min_area_rect ( - class std::vector > *contour, + const class std::vector > *contour, class cv::RotatedRect *rect, bool show ) @@ -372,7 +386,7 @@ void proc_min_area_rect ( data.contour = contour; data.rect = rect; data.show = show; - img_iface_act(IMG_IFACE_ACT_MIN_AREA_RECT, (void *)&data); + img_iface_act(IMG_IFACE_ACT_MIN_AREA_RECT, (const void *)&data); if (show) { proc_show_img(); @@ -385,7 +399,7 @@ void proc_OCR (int lang, int conf) 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); + img_iface_act(IMG_IFACE_ACT_READ, (const void *)&data); } void proc_zbar (int type) @@ -393,11 +407,12 @@ 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); + img_iface_act(IMG_IFACE_ACT_DECODE, (const void *)&data); } void proc_show_img (void) { + if (proc_debug >= PROC_DBG_DELAY_STEP) { img_iface_show_img(); @@ -409,6 +424,7 @@ void proc_show_img (void) void clock_start (void) { + clock_0 = clock(); } -- cgit v1.2.3 From ff9b3f3c50c67bfd4a9c9789f4cfee160431d703 Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Tue, 8 Jan 2019 01:40:05 +0100 Subject: Fix style; Fix minor bugs --- COPYING.txt | 10 +++++----- modules/menu/src/menu_clui.c | 43 ++++++++++++++++++++++++++----------------- modules/menu/src/menu_tui.c | 4 ++-- modules/menu/src/parser.c | 2 +- modules/save/tmp/Makefile | 2 +- modules/user/src/user_clui.c | 32 +++++++++++++++++--------------- share/LICENSE.txt | 10 +++++----- 7 files changed, 57 insertions(+), 46 deletions(-) diff --git a/COPYING.txt b/COPYING.txt index 9e98b13..0776f74 100644 --- a/COPYING.txt +++ b/COPYING.txt @@ -67,7 +67,7 @@ patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. - + GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION @@ -122,7 +122,7 @@ above, provided that you also meet all of these conditions: License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) - + These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in @@ -180,7 +180,7 @@ access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. - + 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is @@ -237,7 +237,7 @@ impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. - + 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License @@ -290,7 +290,7 @@ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS - + How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest diff --git a/modules/menu/src/menu_clui.c b/modules/menu/src/menu_clui.c index f5bb045..b5dc619 100644 --- a/modules/menu/src/menu_clui.c +++ b/modules/menu/src/menu_clui.c @@ -38,28 +38,32 @@ static void menu_clui_start (void); void menu_clui (void) { char buff [BUFF_SIZE]; - char ch; + char c; - ch = 'n'; + c = 'n'; printf("Read 'Disclaimer of warranty'? (yes/NO): "); - fgets(buff, BUFF_SIZE, stdin); - if (sscanf(buff, " %c", &ch)) { + if (!fgets(buff, BUFF_SIZE, stdin)) { return; } - if (ch == 'y' || ch == 'Y') { + if (sscanf(buff, " %c", &c) != 1) { + return; + } + if (c == 'y' || c == 'Y') { printf(" >yes\n"); print_share_file(SHARE_DISCLAIMER); } else { printf(" >NO\n"); } - ch = 'n'; + c = 'n'; printf("Read 'License'? (yes/NO): "); - fgets(buff, BUFF_SIZE, stdin); - if (sscanf(buff, " %c", &ch)) { + if (!fgets(buff, BUFF_SIZE, stdin)) { + return; + } + if (sscanf(buff, " %c", &c) != 1) { return; } - if (ch == 'y' || ch == 'Y') { + if (c == 'y' || c == 'Y') { printf(" >yes\n"); print_share_file(SHARE_LICENSE); } else { @@ -67,10 +71,13 @@ void menu_clui (void) } #if 0 printf("Game interface? (NCURSES/text): "); - if (sscanf(buff, " %c", &ch)) { + if (!fgets(buff, BUFF_SIZE, stdin)) { return; } - if (ch == 't' || ch == 'T') { + if (sscanf(buff, " %c", &c) != 1) { + return; + } + if (c == 't' || c == 'T') { printf(" >text\n"); // FIXME } else { @@ -100,18 +107,20 @@ static void menu_clui_start (void) start_switch(); char buff [BUFF_SIZE]; - char ch; + char c; - ch = 'm'; + c = 'm'; printf("Load again? (MENU/load/exit): "); - fgets(buff, BUFF_SIZE, stdin); - if (sscanf(buff, " %c", &ch)) { + if (!fgets(buff, BUFF_SIZE, stdin)) { + return; + } + if (sscanf(buff, " %c", &c) != 1) { return; } - if (ch == 'p' || ch == 'P') { + if (c == 'p' || c == 'P') { printf(" >load\n"); menu_clui_start(); - } else if (ch == 'e' || ch == 'E') { + } else if (c == 'e' || c == 'E') { printf(" >exit!\n"); } else { printf(" >MENU\n"); diff --git a/modules/menu/src/menu_tui.c b/modules/menu/src/menu_tui.c index 5654b40..8850e7f 100644 --- a/modules/menu/src/menu_tui.c +++ b/modules/menu/src/menu_tui.c @@ -134,7 +134,7 @@ static void menu_tui_continue (void) /* Input box */ w2 = w - 8; r2 = r + h - 5; - static const char *txt[] = {"File name:"}; + static const char *const txt[] = {"File name:"}; /* Menu */ wh = true; @@ -292,7 +292,7 @@ static void menu_tui_devel (void) /* Input box */ w2 = w - 8; r2 = r + h - 5; - static const char *txt[] = { + static const char *const txt[] = { "Modes: 0=Auto; 1=Stop@prod; 2=Delay@step; 3=Stop@step", "Modes: 0=Results; 1=Operations; 2=All", "Modes: 1=CLUI; 2=TUI" diff --git a/modules/menu/src/parser.c b/modules/menu/src/parser.c index a7ed4a8..d751182 100644 --- a/modules/menu/src/parser.c +++ b/modules/menu/src/parser.c @@ -50,7 +50,7 @@ void parser (int argc, char *argv[]) int opt = 0; int opt_index = 0; - struct option long_options[] = { + const struct option long_options[] = { /* Standard */ {"help", no_argument, 0, 'h'}, {"license", no_argument, 0, 'L'}, diff --git a/modules/save/tmp/Makefile b/modules/save/tmp/Makefile index 2003a10..4f2abf9 100644 --- a/modules/save/tmp/Makefile +++ b/modules/save/tmp/Makefile @@ -31,7 +31,7 @@ all: $(ALL) save_mod.o: $(_ALL) $(Q)$(LD) -r $^ -o $@ @echo " LD $@" - + save.s: $(SAVE_DEPS) $(Q)$(CXX) $(CXXFLAGS) $(SAVE_INC_DIRS) -S $< -o $@ diff --git a/modules/user/src/user_clui.c b/modules/user/src/user_clui.c index 11e7db1..9a61d7e 100644 --- a/modules/user/src/user_clui.c +++ b/modules/user/src/user_clui.c @@ -54,6 +54,7 @@ static void show_help (void); ******************************************************************************/ void user_clui_init (void) { + log_pos = 0; } @@ -71,6 +72,7 @@ int user_clui (const char *title, const char *subtitle) void user_clui_fname (const char *filepath, char *filename) { + printf("File name:\n"); printf("Valid extensions: .bmp .dib .jpeg .png .pbm .pgm .ppm .tiff\n"); fgets(filename, FILENAME_MAX, stdin); @@ -79,14 +81,13 @@ void user_clui_fname (const char *filepath, char *filename) void user_clui_show_log (const char *title, const char *subtitle) { - printf("________________________________________________________________________________\n"); - /* Board */ + printf("________________________________________" + "________________________________________\n"); log_loop(); - - /* Subtitle & title */ printf("%s - %s\n", subtitle, title); - printf("--------------------------------------------------------------------------------\n"); + printf("----------------------------------------" + "----------------------------------------\n"); } @@ -115,24 +116,23 @@ static void log_loop (void) static int usr_input (void) { int action; - char buff [BUFF_SIZE]; char ch [10]; - int i; + for (i = 0; i < 10; i++) { ch[i] = '\0'; } buff[0] = '\0'; + action = USER_IFACE_ACT_FOO; - /* Wait for input */ - fgets(buff, BUFF_SIZE, stdin); - - /* Interpret input */ - if (sscanf(buff, " %c%c%c%c%c", &ch[0], &ch[1], &ch[2], &ch[3], &ch[4])) { - ch[0] = '\0'; + if (!fgets(buff, BUFF_SIZE, stdin)) { + goto err_fgets; } - action = USER_IFACE_ACT_FOO; + if (!sscanf(buff, " %c%c%c%c%c", &ch[0], &ch[1], &ch[2], &ch[3], &ch[4])) { + goto err_sscanf; + } + switch (ch[0]) { case '+': action = USER_IFACE_ACT_APPLY; @@ -560,6 +560,8 @@ static int usr_input (void) break; } +err_fgets: +err_sscanf: return action; } @@ -568,7 +570,7 @@ static int usr_input (void) * * * * * * * * * */ static void show_help (void) { - // FIXME + printf("Apply: %s\n", "Space"); printf("Discard: %s\n", "Backspace"); printf("Save to mem: %c\n", 'm'); diff --git a/share/LICENSE.txt b/share/LICENSE.txt index 9e98b13..0776f74 100644 --- a/share/LICENSE.txt +++ b/share/LICENSE.txt @@ -67,7 +67,7 @@ patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. - + GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION @@ -122,7 +122,7 @@ above, provided that you also meet all of these conditions: License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) - + These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in @@ -180,7 +180,7 @@ access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. - + 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is @@ -237,7 +237,7 @@ impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. - + 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License @@ -290,7 +290,7 @@ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS - + How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest -- cgit v1.2.3 From 840a7c8ee149ae45f6bcae379854de631903c95b Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Tue, 8 Jan 2019 01:41:07 +0100 Subject: Update libalx --- libalx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libalx b/libalx index 207eade..d379a95 160000 --- a/libalx +++ b/libalx @@ -1 +1 @@ -Subproject commit 207eade1bd19c0934da8f64571a1bff58a2d29f8 +Subproject commit d379a95f687565b25a494979b6c852c9dfe23348 -- cgit v1.2.3 From 668ddca50e4ef4eb0ef80a80c8a2f8eae3d1a6cb Mon Sep 17 00:00:00 2001 From: AlejandroColomar Date: Tue, 8 Jan 2019 12:00:05 +0100 Subject: Update libalx --- libalx | 2 +- modules/about/src/about.c | 4 +--- modules/about/tmp/Makefile | 2 +- modules/ctrl/src/start.c | 2 -- modules/image/src/img_alx.cpp | 11 +---------- modules/image/src/img_calib3d.cpp | 7 ------- modules/image/src/img_cv.cpp | 9 --------- modules/image/src/img_iface.cpp | 17 ----------------- modules/image/src/img_ocr.c | 7 ------- modules/image/src/img_orb.cpp | 6 ------ modules/image/src/img_zbar.cpp | 7 ------- modules/image/tmp/Makefile | 2 +- modules/menu/src/menu_clui.c | 3 +-- modules/menu/src/menu_iface.c | 2 -- modules/menu/src/menu_tui.c | 10 +--------- modules/menu/src/parser.c | 8 -------- modules/menu/tmp/Makefile | 4 ++-- modules/proc/src/proc_coins.cpp | 11 +---------- modules/proc/src/proc_common.cpp | 10 ---------- modules/proc/src/proc_iface.c | 13 +------------ modules/proc/src/proc_label.cpp | 9 --------- modules/proc/src/proc_lighters.cpp | 10 +--------- modules/proc/src/proc_objects.cpp | 11 +---------- modules/proc/src/proc_resistor.cpp | 8 -------- modules/proc/tmp/Makefile | 8 ++++---- modules/save/src/save.cpp | 9 --------- modules/user/src/user_clui.c | 11 ++--------- modules/user/src/user_iface.c | 8 -------- modules/user/src/user_tui.c | 9 +-------- modules/user/tmp/Makefile | 4 ++-- src/main.cpp | 17 ++++------------- tmp/Makefile | 2 +- 32 files changed, 27 insertions(+), 216 deletions(-) diff --git a/libalx b/libalx index d379a95..683a19b 160000 --- a/libalx +++ b/libalx @@ -1 +1 @@ -Subproject commit d379a95f687565b25a494979b6c852c9dfe23348 +Subproject commit 683a19b251a72cbed5b8a6d2ed368ae1642ed63d diff --git a/modules/about/src/about.c b/modules/about/src/about.c index 662ee42..e101242 100644 --- a/modules/about/src/about.c +++ b/modules/about/src/about.c @@ -11,11 +11,9 @@ /* printf() */ #include #include - /* libalx --------------------------------------------------------------------*/ /* alx_snprint_file() */ - #include "alx_file.h" - + #include "libalx/alx_file.h" /* Module --------------------------------------------------------------------*/ #include "about.h" diff --git a/modules/about/tmp/Makefile b/modules/about/tmp/Makefile index d55d1d8..dee3dc3 100644 --- a/modules/about/tmp/Makefile +++ b/modules/about/tmp/Makefile @@ -14,7 +14,7 @@ SRC_DIR = $(ABOUT_DIR)/src/ _ALL = about.o ALL = $(_ALL) about_mod.o -ABOU_INC_LIBALX = alx_file.h +ABOU_INC_LIBALX = libalx/alx_file.h ABOU_INC = about.h ABOU_DEPS = $(SRC_DIR)/about.c \ $(patsubst %,$(LIBALX_INC_DIR)/%,$(ABOU_INC_LIBALX)) \ diff --git a/modules/ctrl/src/start.c b/modules/ctrl/src/start.c index 2022b32..8c33c93 100644 --- a/modules/ctrl/src/start.c +++ b/modules/ctrl/src/start.c @@ -13,7 +13,6 @@ #include /* printf() */ #include - /* Project -------------------------------------------------------------------*/ /* img_iface_load() */ #include "img_iface.h" @@ -23,7 +22,6 @@ #include "save.h" /* user_iface() */ #include "user_iface.h" - /* Module --------------------------------------------------------------------*/ #include "start.h" diff --git a/modules/image/src/img_alx.cpp b/modules/image/src/img_alx.cpp index d6a7fe4..e832b5d 100644 --- a/modules/image/src/img_alx.cpp +++ b/modules/image/src/img_alx.cpp @@ -8,23 +8,14 @@ ******* headers ************************************************************** ******************************************************************************/ /* Standard C ----------------------------------------------------------------*/ - /* true & false */ #include - /* abs() */ #include - /* snprintf() */ #include - /* Packages ------------------------------------------------------------------*/ - /* opencv */ #include - /* libalx --------------------------------------------------------------------*/ - /* alx_median_u8() */ - #include "alx_math.hpp" - + #include "libalx/alx_math.hpp" /* Module --------------------------------------------------------------------*/ - /* data */ #include "img_iface.hpp" #include "img_alx.hpp" diff --git a/modules/image/src/img_calib3d.cpp b/modules/image/src/img_calib3d.cpp index 6b96d77..cce54c3 100644 --- a/modules/image/src/img_calib3d.cpp +++ b/modules/image/src/img_calib3d.cpp @@ -8,20 +8,13 @@ ******* headers ************************************************************** ******************************************************************************/ /* Standard C++ --------------------------------------------------------------*/ - /* class std::vector */ #include - /* Standard C ----------------------------------------------------------------*/ - /* snprintf() */ #include - /* Packages ------------------------------------------------------------------*/ - /* opencv */ #include #include - /* Module -------------------------------------------------------------------*/ - /* data */ #include "img_iface.hpp" #include "img_calib3d.hpp" diff --git a/modules/image/src/img_cv.cpp b/modules/image/src/img_cv.cpp index 14ed08f..eacaf98 100644 --- a/modules/image/src/img_cv.cpp +++ b/modules/image/src/img_cv.cpp @@ -8,23 +8,14 @@ ******* headers ************************************************************** ******************************************************************************/ /* Standard C++ --------------------------------------------------------------*/ - /* class std::vector */ #include - /* Standard C ----------------------------------------------------------------*/ - /* fabs */ #include - /* true & false */ #include - /* snprintf() */ #include - /* Packages ------------------------------------------------------------------*/ - /* opencv */ #include - /* Module --------------------------------------------------------------------*/ - /* data */ #include "img_iface.hpp" #include "img_cv.hpp" diff --git a/modules/image/src/img_iface.cpp b/modules/image/src/img_iface.cpp index 51404c9..4411920 100644 --- a/modules/image/src/img_iface.cpp +++ b/modules/image/src/img_iface.cpp @@ -8,40 +8,23 @@ ******* headers ************************************************************** ******************************************************************************/ /* Standard C ----------------------------------------------------------------*/ - /* errno */ #include - /* INFINITY */ #include #include - /* snprintf() */ #include - /* Standard C++ --------------------------------------------------------------*/ - /* class std::vector */ #include - /* Packages ------------------------------------------------------------------*/ - /* openCV */ #include - /* Project -------------------------------------------------------------------*/ - /* load_image_file() */ #include "save.hpp" - /* user_iface_log */ #include "user_iface.hpp" - /* Module --------------------------------------------------------------------*/ - /* img_alx_act() */ #include "img_alx.hpp" - /* img_cv_act() */ #include "img_cv.hpp" - /* img_orb_act() */ #include "img_orb.hpp" - /* img_calib3d_act() */ #include "img_calib3d.hpp" - /* img_zb_act() */ #include "img_zbar.hpp" - /* img_ocr_act() */ #include "img_ocr.hpp" #include "img_iface.hpp" diff --git a/modules/image/src/img_ocr.c b/modules/image/src/img_ocr.c index e829bdf..6c92250 100644 --- a/modules/image/src/img_ocr.c +++ b/modules/image/src/img_ocr.c @@ -8,22 +8,15 @@ ******* headers ************************************************************** ******************************************************************************/ /* Standard C ----------------------------------------------------------------*/ - /* INT_MAX */ #include #include - /* snprintf() & FILENAME_MAX */ #include - /* Packages ------------------------------------------------------------------*/ - /* OCR Tesseract */ #include - /* Project -------------------------------------------------------------------*/ /* share_path */ #include "about.h" - /* Module --------------------------------------------------------------------*/ - /* data & img_ocr_text & OCR_TEXT_MAX */ #include "img_iface.h" #include "img_ocr.h" diff --git a/modules/image/src/img_orb.cpp b/modules/image/src/img_orb.cpp index d090dd0..5c716b1 100644 --- a/modules/image/src/img_orb.cpp +++ b/modules/image/src/img_orb.cpp @@ -8,18 +8,12 @@ ******* headers ************************************************************** ******************************************************************************/ /* Standard C++ --------------------------------------------------------------*/ - /* class std::vector */ #include - /* Standard C ----------------------------------------------------------------*/ - /* snprintf() */ #include - /* Packages ------------------------------------------------------------------*/ - /* opencv */ #include #include - /* Module -------------------------------------------------------------------*/ #include "img_orb.hpp" diff --git a/modules/image/src/img_zbar.cpp b/modules/image/src/img_zbar.cpp index f5df97a..952abe0 100644 --- a/modules/image/src/img_zbar.cpp +++ b/modules/image/src/img_zbar.cpp @@ -8,20 +8,13 @@ ******* headers ************************************************************** ******************************************************************************/ /* Standard C ----------------------------------------------------------------*/ - /* INT_MAX */ #include #include - /* snprintf() */ #include - /* Packages ------------------------------------------------------------------*/ - /* opencv */ #include - /* zbar */ #include - /* Module --------------------------------------------------------------------*/ - /* data & zb_codes */ #include "img_iface.hpp" #include "img_zbar.hpp" diff --git a/modules/image/tmp/Makefile b/modules/image/tmp/Makefile index fe8a913..2890fb6 100644 --- a/modules/image/tmp/Makefile +++ b/modules/image/tmp/Makefile @@ -19,7 +19,7 @@ _ALL = img_alx.o img_cv.o img_orb.o img_calib3d.o \ img_zbar.o img_ocr.o img_iface.o ALL = $(_ALL) img_mod.o -IMGALX_INC_LIBALX = alx_math.hpp +IMGALX_INC_LIBALX = libalx/alx_math.hpp IMGALX_INC = img_alx.hpp img_iface.hpp IMGALX_DEPS = $(SRC_DIR)/img_alx.cpp \ $(patsubst %,$(INC_DIR)/%,$(IMGALX_INC)) \ diff --git a/modules/menu/src/menu_clui.c b/modules/menu/src/menu_clui.c index b5dc619..d335b6e 100644 --- a/modules/menu/src/menu_clui.c +++ b/modules/menu/src/menu_clui.c @@ -7,11 +7,10 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ - #include "alx_input.h" + #include "libalx/alx_input.h" #include "about.h" // #include "save.h" - /* start_switch() */ #include "start.h" #include "menu_clui.h" diff --git a/modules/menu/src/menu_iface.c b/modules/menu/src/menu_iface.c index 384fa35..a09a463 100644 --- a/modules/menu/src/menu_iface.c +++ b/modules/menu/src/menu_iface.c @@ -7,9 +7,7 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ - /* menu_clui() */ #include "menu_clui.h" - /* menu_tui() */ #include "menu_tui.h" #include "menu_iface.h" diff --git a/modules/menu/src/menu_tui.c b/modules/menu/src/menu_tui.c index 8850e7f..3d5a484 100644 --- a/modules/menu/src/menu_tui.c +++ b/modules/menu/src/menu_tui.c @@ -11,22 +11,14 @@ #include #include #include - /* libalx --------------------------------------------------------------------*/ - #include "alx_ncur.h" - + #include "libalx/alx_ncur.h" /* Project -------------------------------------------------------------------*/ - /* printf_share_file() */ #include "about.h" - /* proc_debug */ #include "proc_iface.h" - /* saved_name */ #include "save.h" - /* start_switch() */ #include "start.h" - /* user_iface_log */ #include "user_iface.h" - /* Module --------------------------------------------------------------------*/ #include "menu_tui.h" diff --git a/modules/menu/src/parser.c b/modules/menu/src/parser.c index d751182..acce385 100644 --- a/modules/menu/src/parser.c +++ b/modules/menu/src/parser.c @@ -9,21 +9,13 @@ ******************************************************************************/ /* Standard C ----------------------------------------------------------------*/ #include - /* FILE & fopen() & snprintf() & FILENAME_MAX */ #include - /* exit() */ #include - /* Project -------------------------------------------------------------------*/ - /* print_share_...() */ #include "about.h" - /* user_iface_mode */ #include "user_iface.h" - /* saved_name */ #include "save.h" - /* Module --------------------------------------------------------------------*/ - /* menu_iface_mode */ #include "menu_iface.h" #include "parser.h" diff --git a/modules/menu/tmp/Makefile b/modules/menu/tmp/Makefile index 7da117c..f83b79d 100644 --- a/modules/menu/tmp/Makefile +++ b/modules/menu/tmp/Makefile @@ -39,7 +39,7 @@ MENUI_DEPS = $(SRC_DIR)/menu_iface.c \ $(patsubst %,$(INC_DIR)/%,$(MENUI_INC)) MENUI_INC_DIRS = -I $(INC_DIR) -MENUCLUI_INC_LIBALX = alx_input.h +MENUCLUI_INC_LIBALX = libalx/alx_input.h MENUCLUI_INC_ABOUT = about.h MENUCLUI_INC_CTRL = start.h MENUCLUI_INC_SAVE = save.h @@ -56,7 +56,7 @@ MENUCLUI_INC_DIRS = -I $(INC_DIR) \ -I $(CTRL_INC_DIR) \ -I $(SAVE_INC_DIR) -MENUTUI_INC_LIBALX = alx_ncur.h +MENUTUI_INC_LIBALX = libalx/alx_ncur.h MENUTUI_INC_ABOUT = about.h MENUTUI_INC_CTRL = start.h MENUTUI_INC_PROC = proc_iface.h diff --git a/modules/proc/src/proc_coins.cpp b/modules/proc/src/proc_coins.cpp index 0b1398d..f824fe2 100644 --- a/modules/proc/src/proc_coins.cpp +++ b/modules/proc/src/proc_coins.cpp @@ -8,23 +8,14 @@ ******* headers ************************************************************** ******************************************************************************/ /* Standard C ----------------------------------------------------------------*/ - /* snprintf() & fflush() */ #include - /* Packages ------------------------------------------------------------------*/ - /* openCV */ #include - /* libalx --------------------------------------------------------------------*/ - /* alx_maximum_u8() */ - #include "alx_math.hpp" - + #include "libalx/alx_math.hpp" /* Project -------------------------------------------------------------------*/ - /* constants */ #include "img_iface.hpp" - /* user_iface_log */ #include "user_iface.hpp" - /* Module --------------------------------------------------------------------*/ #include "proc_common.hpp" diff --git a/modules/proc/src/proc_common.cpp b/modules/proc/src/proc_common.cpp index e0ff8f7..d76e47f 100644 --- a/modules/proc/src/proc_common.cpp +++ b/modules/proc/src/proc_common.cpp @@ -9,25 +9,15 @@ ******************************************************************************/ /* Standard C ----------------------------------------------------------------*/ #include - /* snprintf() & fflush() */ #include - /* clock_t & clock() & CLOCKS_PER_SEC */ #include - /* Packages ------------------------------------------------------------------*/ - /* openCV */ #include - /* enum zbar::zbar_symbol_type_e */ #include - /* 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" diff --git a/modules/proc/src/proc_iface.c b/modules/proc/src/proc_iface.c index 6767e26..9111fc5 100644 --- a/modules/proc/src/proc_iface.c +++ b/modules/proc/src/proc_iface.c @@ -8,28 +8,17 @@ ******* headers ************************************************************** ******************************************************************************/ /* Standard C ----------------------------------------------------------------*/ - /* errno */ #include #include - /* snprintf() & fflush() */ #include - /* exit() */ #include - /* clock_t & clock() & CLOCKS_PER_SEC */ #include - /* libalx -------------------------------------------------------------------*/ - /* alx_sscan_fname() */ - #include "alx_input.h" - + #include "libalx/alx_input.h" /* Project -------------------------------------------------------------------*/ - /* img_iface_load() */ #include "img_iface.h" - /* user_iface_log */ #include "user_iface.h" - /* saved_path */ #include "save.h" - /* Module --------------------------------------------------------------------*/ #include "proc_label.h" #include "proc_lighters.h" diff --git a/modules/proc/src/proc_label.cpp b/modules/proc/src/proc_label.cpp index 840e29e..2f09c90 100644 --- a/modules/proc/src/proc_label.cpp +++ b/modules/proc/src/proc_label.cpp @@ -8,23 +8,14 @@ ******* headers ************************************************************** ******************************************************************************/ /* Standard C ----------------------------------------------------------------*/ - /* snprintf() */ #include - /* strcmp() */ #include - /* Packages ------------------------------------------------------------------*/ - /* openCV */ #include - /* zbar::ZBAR_EAN13 */ #include - /* Project -------------------------------------------------------------------*/ - /* zb_codes */ #include "img_iface.hpp" - /* user_iface_log */ #include "user_iface.hpp" - /* Module --------------------------------------------------------------------*/ #include "proc_common.hpp" diff --git a/modules/proc/src/proc_lighters.cpp b/modules/proc/src/proc_lighters.cpp index 69b7e4b..7242638 100644 --- a/modules/proc/src/proc_lighters.cpp +++ b/modules/proc/src/proc_lighters.cpp @@ -10,21 +10,13 @@ /* Standard C ----------------------------------------------------------------*/ #include #include - /* Packages ------------------------------------------------------------------*/ - /* openCV */ #include - /* libalx ------------------------------------------------------------------*/ - /* alx_maximum_u8() */ - #include "alx_math.hpp" - + #include "libalx/alx_math.hpp" /* Project -------------------------------------------------------------------*/ - /* constants */ #include "img_iface.hpp" - /* user_iface_log */ #include "user_iface.hpp" - /* Module --------------------------------------------------------------------*/ #include "proc_common.hpp" diff --git a/modules/proc/src/proc_objects.cpp b/modules/proc/src/proc_objects.cpp index 6caa919..db5d5e3 100644 --- a/modules/proc/src/proc_objects.cpp +++ b/modules/proc/src/proc_objects.cpp @@ -8,23 +8,14 @@ ******* headers ************************************************************** ******************************************************************************/ /* Standard C ----------------------------------------------------------------*/ - /* snprintf() */ #include - /* Packages ------------------------------------------------------------------*/ - /* openCV */ #include - /* libalx ------------------------------------------------------------------*/ - /* alx_maximum_u8() */ - #include "alx_math.hpp" - + #include "libalx/alx_math.hpp" /* Project -------------------------------------------------------------------*/ - /* constants */ #include "img_iface.hpp" - /* user_iface_log */ #include "user_iface.hpp" - /* Module --------------------------------------------------------------------*/ #include "proc_common.hpp" diff --git a/modules/proc/src/proc_resistor.cpp b/modules/proc/src/proc_resistor.cpp index 26ef739..33bb624 100644 --- a/modules/proc/src/proc_resistor.cpp +++ b/modules/proc/src/proc_resistor.cpp @@ -8,21 +8,13 @@ ******* headers ************************************************************** ******************************************************************************/ /* Standard C ----------------------------------------------------------------*/ - /* pow() */ #include - /* snprintf() & fflush() */ #include - /* Packages ------------------------------------------------------------------*/ - /* openCV */ #include - /* Project -------------------------------------------------------------------*/ - /* CONSTANTS */ #include "img_iface.hpp" - /* user_iface_log */ #include "user_iface.hpp" - /* Module --------------------------------------------------------------------*/ #include "proc_common.hpp" diff --git a/modules/proc/tmp/Makefile b/modules/proc/tmp/Makefile index fcb9d8b..0bdc990 100644 --- a/modules/proc/tmp/Makefile +++ b/modules/proc/tmp/Makefile @@ -31,7 +31,7 @@ PROC_LAB_INC_DIRS = -I $(INC_DIR) \ -I $(IMG_INC_DIR) \ -I $(USR_INC_DIR) -PROC_LGHT_INC_LIBALX = alx_math.hpp +PROC_LGHT_INC_LIBALX = libalx/alx_math.hpp PROC_LGHT_INC_IMG = img_iface.hpp PROC_LGHT_INC_USR = user_iface.hpp PROC_LGHT_INC = proc_lighters.hpp proc_common.hpp @@ -45,7 +45,7 @@ PROC_LGHT_INC_DIRS = -I $(INC_DIR) \ -I $(USR_INC_DIR) \ -I $(LIBALX_INC_DIR) -PROC_OBJS_INC_LIBALX = alx_math.hpp +PROC_OBJS_INC_LIBALX = libalx/alx_math.hpp PROC_OBJS_INC_IMG = img_iface.hpp PROC_OBJS_INC_USR = user_iface.hpp PROC_OBJS_INC = proc_objects.hpp proc_common.hpp @@ -59,7 +59,7 @@ PROC_OBJS_INC_DIRS = -I $(INC_DIR) \ -I $(USR_INC_DIR) \ -I $(LIBALX_INC_DIR) -PROC_COIN_INC_LIBALX = alx_math.hpp +PROC_COIN_INC_LIBALX = libalx/alx_math.hpp PROC_COIN_INC_IMG = img_iface.hpp PROC_COIN_INC_USR = user_iface.hpp PROC_COIN_INC = proc_coins.hpp proc_common.hpp @@ -95,7 +95,7 @@ PROC_CMN_INC_DIRS = -I $(INC_DIR) \ -I $(IMG_INC_DIR) \ -I $(USR_INC_DIR) -PROC_IFACE_INC_LIBALX = alx_input.h +PROC_IFACE_INC_LIBALX = libalx/alx_input.h PROC_IFACE_INC_IMG = img_iface.h PROC_IFACE_INC_SAVE = save.h PROC_IFACE_INC_USR = user_iface.h diff --git a/modules/save/src/save.cpp b/modules/save/src/save.cpp index 30c7ff3..30d3376 100644 --- a/modules/save/src/save.cpp +++ b/modules/save/src/save.cpp @@ -8,25 +8,16 @@ ******* headers ************************************************************** ******************************************************************************/ /* Standard C ----------------------------------------------------------------*/ - /* errno */ #include - /* fscanf() & fprintf() & FILE & FILENAME_MAX & snprintf() */ #include - /* getenv() & exit() */ #include - /* Linux ---------------------------------------------------------------------*/ /* mkdir */ #include - /* Packages ------------------------------------------------------------------*/ - /* opencv */ #include - /* Project -------------------------------------------------------------------*/ - /* user_iface_save_name() */ #include "user_iface.hpp" - /* Module --------------------------------------------------------------------*/ #include "save.hpp" diff --git a/modules/user/src/user_clui.c b/modules/user/src/user_clui.c index 9a61d7e..c48fb82 100644 --- a/modules/user/src/user_clui.c +++ b/modules/user/src/user_clui.c @@ -8,19 +8,12 @@ ******* headers ************************************************************** ******************************************************************************/ /* Standard C ----------------------------------------------------------------*/ - /* printf() & fgets() & sscanf() */ #include - +/* libalx --------------------------------------------------------------------*/ + #include "libalx/alx_input.h" /* Project -------------------------------------------------------------------*/ - /*img_ocr_text */ #include "img_iface.h" - -/* libalx --------------------------------------------------------------------*/ - /* alx_sscan_fname() */ - #include "alx_input.h" - /* Module --------------------------------------------------------------------*/ - /* user_iface_log */ #include "user_iface.h" #include "user_clui.h" diff --git a/modules/user/src/user_iface.c b/modules/user/src/user_iface.c index 46576f3..84aedfb 100644 --- a/modules/user/src/user_iface.c +++ b/modules/user/src/user_iface.c @@ -8,21 +8,13 @@ ******* headers ************************************************************** ******************************************************************************/ /* Standard C ----------------------------------------------------------------*/ - /* intX_t */ #include - /* snprintf() & fflush() */ #include - /* Project -------------------------------------------------------------------*/ - /* img_iface_act_nodata() */ #include "img_iface.h" - /* proc_iface() */ #include "proc_iface.h" - /* Module --------------------------------------------------------------------*/ - /* user_clui() & ...save_name() */ #include "user_clui.h" - /* user_tui() & ...init() & ...cleanup() & ...save_name() */ #include "user_tui.h" #include "user_iface.h" diff --git a/modules/user/src/user_tui.c b/modules/user/src/user_tui.c index 70220fc..90b457e 100644 --- a/modules/user/src/user_tui.c +++ b/modules/user/src/user_tui.c @@ -9,19 +9,12 @@ ******************************************************************************/ /* Standard C ----------------------------------------------------------------*/ #include - /* WINDOW & wgetch() & KEY_... & ... */ #include - /* libalx --------------------------------------------------------------------*/ - /* alx_..._curses() & alx_ncur_prn_...() */ - #include "alx_ncur.h" - + #include "libalx/alx_ncur.h" /* Project -------------------------------------------------------------------*/ - /*img_ocr_text */ #include "img_iface.h" - /* Module --------------------------------------------------------------------*/ - /* user_iface_log */ #include "user_iface.h" #include "user_tui.h" diff --git a/modules/user/tmp/Makefile b/modules/user/tmp/Makefile index 572a912..9ad6a8b 100644 --- a/modules/user/tmp/Makefile +++ b/modules/user/tmp/Makefile @@ -30,7 +30,7 @@ UI_INC_DIRS = -I $(INC_DIR) \ -I $(IMG_INC_DIR) \ -I $(PROC_INC_DIR) -UCLUI_INC_LIBALX = alx_ncur.h +UCLUI_INC_LIBALX = libalx/alx_ncur.h UCLUI_INC_IMG = img_iface.h UCLUI_INC = user_clui.h user_iface.h UCLUI_DEPS = $(SRC_DIR)/user_clui.c \ @@ -41,7 +41,7 @@ UCLUI_INC_DIRS = -I $(INC_DIR) \ -I $(LIBALX_INC_DIR) \ -I $(IMG_INC_DIR) -UTUI_INC_LIBALX = alx_ncur.h +UTUI_INC_LIBALX = libalx/alx_ncur.h UTUI_INC_IMG = img_iface.h UTUI_INC = user_tui.h user_iface.h UTUI_DEPS = $(SRC_DIR)/user_tui.c \ diff --git a/src/main.cpp b/src/main.cpp index c213594..2e05304 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,14 +8,10 @@ ******* headers ************************************************************** ******************************************************************************/ /* Standard C ----------------------------------------------------------------*/ - /* getchar() */ #include - /* libalx --------------------------------------------------------------------*/ - #include "alx_ncur.hpp" - + #include "libalx/alx_ncur.hpp" /* Project -------------------------------------------------------------------*/ - /* about_init() & print_cpright() */ #include "about.hpp" #include "img_iface.hpp" #include "menu_iface.hpp" @@ -36,13 +32,12 @@ static void cleanup (void); ******************************************************************************/ int main (int argc, char *argv[]) { + init_all(&argc, &argv); - /* Print copyright () and wait for any key to continue */ print_share_file(SHARE_COPYRIGHT); getchar(); - /* Menu () */ menu_iface(); cleanup(); @@ -56,29 +51,25 @@ int main (int argc, char *argv[]) ******************************************************************************/ static void init_all (int *argc, char *(*argv[])) { - /* Init curses */ + alx_start_curses(); alx_pause_curses(); - /* Init modules */ about_init(); save_init(); - /* Modes */ menu_iface_mode = MENU_IFACE_TUI; user_iface_mode = USER_IFACE_TUI; user_iface_log.visible = 2; - /* Parse command line options */ parser(*argc, *argv); } static void cleanup (void) { - /* Clean img buffers */ + img_iface_cleanup_main(); - /* End curses */ alx_resume_curses(); alx_end_curses(); } diff --git a/tmp/Makefile b/tmp/Makefile index 553d349..0d44af3 100644 --- a/tmp/Makefile +++ b/tmp/Makefile @@ -30,7 +30,7 @@ SRC_DIR = $(MAIN_DIR)/src/ ALL = main.o -MAIN_INC_LIBALX = alx_ncur.hpp +MAIN_INC_LIBALX = libalx/alx_ncur.hpp MAIN_INC_ABOUT = about.hpp MAIN_INC_IMG = img_iface.hpp MAIN_INC_MENU = parser.hpp menu_iface.hpp -- cgit v1.2.3 From bb0bba23cd6c2342462f3d4bf1363a7c9f13c4ce Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 2 Feb 2019 20:33:57 +0000 Subject: Update libalx --- libalx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libalx b/libalx index 683a19b..3e83ecf 160000 --- a/libalx +++ b/libalx @@ -1 +1 @@ -Subproject commit 683a19b251a72cbed5b8a6d2ed368ae1642ed63d +Subproject commit 3e83ecf11efc99fbba7e6b4a09c071ec20e87ddd -- cgit v1.2.3 From ad72343dd2192945bc82628bdf5830e1eeddf5c4 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 2 Feb 2019 20:35:05 +0000 Subject: Add checkstyle (using checkpatch.pl from Linux) --- Checkstyle/checkpatch.pl | 6720 ++++++++++++++++++++++++++++++++++++++++++++++ Checkstyle/checkstyle | 55 + Checkstyle/spelling.txt | 1344 ++++++++++ 3 files changed, 8119 insertions(+) create mode 100755 Checkstyle/checkpatch.pl create mode 100755 Checkstyle/checkstyle create mode 100644 Checkstyle/spelling.txt diff --git a/Checkstyle/checkpatch.pl b/Checkstyle/checkpatch.pl new file mode 100755 index 0000000..b737ca9 --- /dev/null +++ b/Checkstyle/checkpatch.pl @@ -0,0 +1,6720 @@ +#!/usr/bin/env perl +# SPDX-License-Identifier: GPL-2.0 +# +# (c) 2001, Dave Jones. (the file handling bit) +# (c) 2005, Joel Schopp (the ugly bit) +# (c) 2007,2008, Andy Whitcroft (new conditions, test suite) +# (c) 2008-2010 Andy Whitcroft +# (c) 2010-2018 Joe Perches + +use strict; +use warnings; +use POSIX; +use File::Basename; +use Cwd 'abs_path'; +use Term::ANSIColor qw(:constants); +use Encode qw(decode encode); + +my $P = $0; +my $D = dirname(abs_path($P)); + +my $V = '0.32'; + +use Getopt::Long qw(:config no_auto_abbrev); + +my $quiet = 0; +my $tree = 1; +my $chk_signoff = 1; +my $chk_patch = 1; +my $tst_only; +my $emacs = 0; +my $terse = 0; +my $showfile = 0; +my $file = 0; +my $git = 0; +my %git_commits = (); +my $check = 0; +my $check_orig = 0; +my $summary = 1; +my $mailback = 0; +my $summary_file = 0; +my $show_types = 0; +my $list_types = 0; +my $fix = 0; +my $fix_inplace = 0; +my $root; +my %debug; +my %camelcase = (); +my %use_type = (); +my @use = (); +my %ignore_type = (); +my @ignore = (); +my $help = 0; +my $configuration_file = ".checkpatch.conf"; +my $max_line_length = 80; +my $ignore_perl_version = 0; +my $minimum_perl_version = 5.10.0; +my $min_conf_desc_length = 4; +my $spelling_file = "$D/spelling.txt"; +my $codespell = 0; +my $codespellfile = "/usr/share/codespell/dictionary.txt"; +my $conststructsfile = "$D/const_structs.checkpatch"; +my $typedefsfile = ""; +my $color = "auto"; +my $allow_c99_comments = 1; + +sub help { + my ($exitcode) = @_; + + print << "EOM"; +Usage: $P [OPTION]... [FILE]... +Version: $V + +Options: + -q, --quiet quiet + --no-tree run without a kernel tree + --no-signoff do not check for 'Signed-off-by' line + --patch treat FILE as patchfile (default) + --emacs emacs compile window format + --terse one line per report + --showfile emit diffed file position, not input file position + -g, --git treat FILE as a single commit or git revision range + single git commit with: + + ^ + ~n + multiple git commits with: + .. + ... + - + git merges are ignored + -f, --file treat FILE as regular source file + --subjective, --strict enable more subjective tests + --list-types list the possible message types + --types TYPE(,TYPE2...) show only these comma separated message types + --ignore TYPE(,TYPE2...) ignore various comma separated message types + --show-types show the specific message type in the output + --max-line-length=n set the maximum line length, if exceeded, warn + --min-conf-desc-length=n set the min description length, if shorter, warn + --root=PATH PATH to the kernel tree root + --no-summary suppress the per-file summary + --mailback only produce a report in case of warnings/errors + --summary-file include the filename in summary + --debug KEY=[0|1] turn on/off debugging of KEY, where KEY is one of + 'values', 'possible', 'type', and 'attr' (default + is all off) + --test-only=WORD report only warnings/errors containing WORD + literally + --fix EXPERIMENTAL - may create horrible results + If correctable single-line errors exist, create + ".EXPERIMENTAL-checkpatch-fixes" + with potential errors corrected to the preferred + checkpatch style + --fix-inplace EXPERIMENTAL - may create horrible results + Is the same as --fix, but overwrites the input + file. It's your fault if there's no backup or git + --ignore-perl-version override checking of perl version. expect + runtime errors. + --codespell Use the codespell dictionary for spelling/typos + (default:/usr/share/codespell/dictionary.txt) + --codespellfile Use this codespell dictionary + --typedefsfile Read additional types from this file + --color[=WHEN] Use colors 'always', 'never', or only when output + is a terminal ('auto'). Default is 'auto'. + -h, --help, --version display this help and exit + +When FILE is - read standard input. +EOM + + exit($exitcode); +} + +sub uniq { + my %seen; + return grep { !$seen{$_}++ } @_; +} + +sub list_types { + my ($exitcode) = @_; + + my $count = 0; + + local $/ = undef; + + open(my $script, '<', abs_path($P)) or + die "$P: Can't read '$P' $!\n"; + + my $text = <$script>; + close($script); + + my @types = (); + # Also catch when type or level is passed through a variable + for ($text =~ /(?:(?:\bCHK|\bWARN|\bERROR|&\{\$msg_level})\s*\(|\$msg_type\s*=)\s*"([^"]+)"/g) { + push (@types, $_); + } + @types = sort(uniq(@types)); + print("#\tMessage type\n\n"); + foreach my $type (@types) { + print(++$count . "\t" . $type . "\n"); + } + + exit($exitcode); +} + +my $conf = which_conf($configuration_file); +if (-f $conf) { + my @conf_args; + open(my $conffile, '<', "$conf") + or warn "$P: Can't find a readable $configuration_file file $!\n"; + + while (<$conffile>) { + my $line = $_; + + $line =~ s/\s*\n?$//g; + $line =~ s/^\s*//g; + $line =~ s/\s+/ /g; + + next if ($line =~ m/^\s*#/); + next if ($line =~ m/^\s*$/); + + my @words = split(" ", $line); + foreach my $word (@words) { + last if ($word =~ m/^#/); + push (@conf_args, $word); + } + } + close($conffile); + unshift(@ARGV, @conf_args) if @conf_args; +} + +# Perl's Getopt::Long allows options to take optional arguments after a space. +# Prevent --color by itself from consuming other arguments +foreach (@ARGV) { + if ($_ eq "--color" || $_ eq "-color") { + $_ = "--color=$color"; + } +} + +GetOptions( + 'q|quiet+' => \$quiet, + 'tree!' => \$tree, + 'signoff!' => \$chk_signoff, + 'patch!' => \$chk_patch, + 'emacs!' => \$emacs, + 'terse!' => \$terse, + 'showfile!' => \$showfile, + 'f|file!' => \$file, + 'g|git!' => \$git, + 'subjective!' => \$check, + 'strict!' => \$check, + 'ignore=s' => \@ignore, + 'types=s' => \@use, + 'show-types!' => \$show_types, + 'list-types!' => \$list_types, + 'max-line-length=i' => \$max_line_length, + 'min-conf-desc-length=i' => \$min_conf_desc_length, + 'root=s' => \$root, + 'summary!' => \$summary, + 'mailback!' => \$mailback, + 'summary-file!' => \$summary_file, + 'fix!' => \$fix, + 'fix-inplace!' => \$fix_inplace, + 'ignore-perl-version!' => \$ignore_perl_version, + 'debug=s' => \%debug, + 'test-only=s' => \$tst_only, + 'codespell!' => \$codespell, + 'codespellfile=s' => \$codespellfile, + 'typedefsfile=s' => \$typedefsfile, + 'color=s' => \$color, + 'no-color' => \$color, #keep old behaviors of -nocolor + 'nocolor' => \$color, #keep old behaviors of -nocolor + 'h|help' => \$help, + 'version' => \$help +) or help(1); + +help(0) if ($help); + +list_types(0) if ($list_types); + +$fix = 1 if ($fix_inplace); +$check_orig = $check; + +my $exit = 0; + +my $perl_version_ok = 1; +if ($^V && $^V lt $minimum_perl_version) { + $perl_version_ok = 0; + printf "$P: requires at least perl version %vd\n", $minimum_perl_version; + exit(1) if (!$ignore_perl_version); +} + +#if no filenames are given, push '-' to read patch from stdin +if ($#ARGV < 0) { + push(@ARGV, '-'); +} + +if ($color =~ /^[01]$/) { + $color = !$color; +} elsif ($color =~ /^always$/i) { + $color = 1; +} elsif ($color =~ /^never$/i) { + $color = 0; +} elsif ($color =~ /^auto$/i) { + $color = (-t STDOUT); +} else { + die "Invalid color mode: $color\n"; +} + +sub hash_save_array_words { + my ($hashRef, $arrayRef) = @_; + + my @array = split(/,/, join(',', @$arrayRef)); + foreach my $word (@array) { + $word =~ s/\s*\n?$//g; + $word =~ s/^\s*//g; + $word =~ s/\s+/ /g; + $word =~ tr/[a-z]/[A-Z]/; + + next if ($word =~ m/^\s*#/); + next if ($word =~ m/^\s*$/); + + $hashRef->{$word}++; + } +} + +sub hash_show_words { + my ($hashRef, $prefix) = @_; + + if (keys %$hashRef) { + print "\nNOTE: $prefix message types:"; + foreach my $word (sort keys %$hashRef) { + print " $word"; + } + print "\n"; + } +} + +hash_save_array_words(\%ignore_type, \@ignore); +hash_save_array_words(\%use_type, \@use); + +my $dbg_values = 0; +my $dbg_possible = 0; +my $dbg_type = 0; +my $dbg_attr = 0; +for my $key (keys %debug) { + ## no critic + eval "\${dbg_$key} = '$debug{$key}';"; + die "$@" if ($@); +} + +my $rpt_cleaners = 0; + +if ($terse) { + $emacs = 1; + $quiet++; +} + +if ($tree) { + if (defined $root) { + if (!top_of_kernel_tree($root)) { + die "$P: $root: --root does not point at a valid tree\n"; + } + } else { + if (top_of_kernel_tree('.')) { + $root = '.'; + } elsif ($0 =~ m@(.*)/scripts/[^/]*$@ && + top_of_kernel_tree($1)) { + $root = $1; + } + } + + if (!defined $root) { + print "Must be run from the top-level dir. of a kernel tree\n"; + exit(2); + } +} + +my $emitted_corrupt = 0; + +our $Ident = qr{ + [A-Za-z_][A-Za-z\d_]* + (?:\s*\#\#\s*[A-Za-z_][A-Za-z\d_]*)* + }x; +our $Storage = qr{extern|static|asmlinkage}; +our $Sparse = qr{ + __user| + __kernel| + __force| + __iomem| + __must_check| + __kprobes| + __ref| + __refconst| + __refdata| + __rcu| + __private + }x; +our $InitAttributePrefix = qr{__(?:mem|cpu|dev|net_|)}; +our $InitAttributeData = qr{$InitAttributePrefix(?:initdata\b)}; +our $InitAttributeConst = qr{$InitAttributePrefix(?:initconst\b)}; +our $InitAttributeInit = qr{$InitAttributePrefix(?:init\b)}; +our $InitAttribute = qr{$InitAttributeData|$InitAttributeConst|$InitAttributeInit}; + +# Notes to $Attribute: +# We need \b after 'init' otherwise 'initconst' will cause a false positive in a check +our $Attribute = qr{ + const| + __percpu| + __nocast| + __safe| + __bitwise| + __packed__| + __packed2__| + __naked| + __maybe_unused| + __always_unused| + __noreturn| + __used| + __cold| + __pure| + __noclone| + __deprecated| + __read_mostly| + __ro_after_init| + __kprobes| + $InitAttribute| + ____cacheline_aligned| + ____cacheline_aligned_in_smp| + ____cacheline_internodealigned_in_smp| + __weak + }x; +our $Modifier; +our $Inline = qr{inline|__always_inline|noinline|__inline|__inline__}; +our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]}; +our $Lval = qr{$Ident(?:$Member)*}; + +our $Int_type = qr{(?i)llu|ull|ll|lu|ul|l|u}; +our $Binary = qr{(?i)0b[01]+$Int_type?}; +our $Hex = qr{(?i)0x[0-9a-f]+$Int_type?}; +our $Int = qr{[0-9]+$Int_type?}; +our $Octal = qr{0[0-7]+$Int_type?}; +our $String = qr{"[X\t]*"}; +our $Float_hex = qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?}; +our $Float_dec = qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?}; +our $Float_int = qr{(?i)[0-9]+e-?[0-9]+[fl]?}; +our $Float = qr{$Float_hex|$Float_dec|$Float_int}; +our $Constant = qr{$Float|$Binary|$Octal|$Hex|$Int}; +our $Assignment = qr{\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=}; +our $Compare = qr{<=|>=|==|!=|<|(?}; +our $Arithmetic = qr{\+|-|\*|\/|%}; +our $Operators = qr{ + <=|>=|==|!=| + =>|->|<<|>>|<|>|!|~| + &&|\|\||,|\^|\+\+|--|&|\||$Arithmetic + }x; + +our $c90_Keywords = qr{do|for|while|if|else|return|goto|continue|switch|default|case|break}x; + +our $BasicType; +our $NonptrType; +our $NonptrTypeMisordered; +our $NonptrTypeWithAttr; +our $Type; +our $TypeMisordered; +our $Declare; +our $DeclareMisordered; + +our $NON_ASCII_UTF8 = qr{ + [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte + | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs + | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte + | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates + | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 + | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 + | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 +}x; + +our $UTF8 = qr{ + [\x09\x0A\x0D\x20-\x7E] # ASCII + | $NON_ASCII_UTF8 +}x; + +our $typeC99Typedefs = qr{(?:__)?(?:[us]_?)?int_?(?:8|16|32|64)_t}; +our $typeOtherOSTypedefs = qr{(?x: + u_(?:char|short|int|long) | # bsd + u(?:nchar|short|int|long) # sysv +)}; +our $typeKernelTypedefs = qr{(?x: + (?:__)?(?:u|s|be|le)(?:8|16|32|64)| + atomic_t +)}; +our $typeTypedefs = qr{(?x: + $typeC99Typedefs\b| + $typeOtherOSTypedefs\b| + $typeKernelTypedefs\b +)}; + +our $zero_initializer = qr{(?:(?:0[xX])?0+$Int_type?|NULL|false)\b}; + +our $logFunctions = qr{(?x: + printk(?:_ratelimited|_once|_deferred_once|_deferred|)| + (?:[a-z0-9]+_){1,2}(?:printk|emerg|alert|crit|err|warning|warn|notice|info|debug|dbg|vdbg|devel|cont|WARN)(?:_ratelimited|_once|)| + TP_printk| + WARN(?:_RATELIMIT|_ONCE|)| + panic| + MODULE_[A-Z_]+| + seq_vprintf|seq_printf|seq_puts +)}; + +our $signature_tags = qr{(?xi: + Signed-off-by:| + Co-developed-by:| + Acked-by:| + Tested-by:| + Reviewed-by:| + Reported-by:| + Suggested-by:| + To:| + Cc: +)}; + +our @typeListMisordered = ( + qr{char\s+(?:un)?signed}, + qr{int\s+(?:(?:un)?signed\s+)?short\s}, + qr{int\s+short(?:\s+(?:un)?signed)}, + qr{short\s+int(?:\s+(?:un)?signed)}, + qr{(?:un)?signed\s+int\s+short}, + qr{short\s+(?:un)?signed}, + qr{long\s+int\s+(?:un)?signed}, + qr{int\s+long\s+(?:un)?signed}, + qr{long\s+(?:un)?signed\s+int}, + qr{int\s+(?:un)?signed\s+long}, + qr{int\s+(?:un)?signed}, + qr{int\s+long\s+long\s+(?:un)?signed}, + qr{long\s+long\s+int\s+(?:un)?signed}, + qr{long\s+long\s+(?:un)?signed\s+int}, + qr{long\s+long\s+(?:un)?signed}, + qr{long\s+(?:un)?signed}, +); + +our @typeList = ( + qr{void}, + qr{(?:(?:un)?signed\s+)?char}, + qr{(?:(?:un)?signed\s+)?short\s+int}, + qr{(?:(?:un)?signed\s+)?short}, + qr{(?:(?:un)?signed\s+)?int}, + qr{(?:(?:un)?signed\s+)?long\s+int}, + qr{(?:(?:un)?signed\s+)?long\s+long\s+int}, + qr{(?:(?:un)?signed\s+)?long\s+long}, + qr{(?:(?:un)?signed\s+)?long}, + qr{(?:un)?signed}, + qr{float}, + qr{double}, + qr{bool}, + qr{struct\s+$Ident}, + qr{union\s+$Ident}, + qr{enum\s+$Ident}, + qr{${Ident}_t}, + qr{${Ident}_handler}, + qr{${Ident}_handler_fn}, + @typeListMisordered, +); + +our $C90_int_types = qr{(?x: + long\s+long\s+int\s+(?:un)?signed| + long\s+long\s+(?:un)?signed\s+int| + long\s+long\s+(?:un)?signed| + (?:(?:un)?signed\s+)?long\s+long\s+int| + (?:(?:un)?signed\s+)?long\s+long| + int\s+long\s+long\s+(?:un)?signed| + int\s+(?:(?:un)?signed\s+)?long\s+long| + + long\s+int\s+(?:un)?signed| + long\s+(?:un)?signed\s+int| + long\s+(?:un)?signed| + (?:(?:un)?signed\s+)?long\s+int| + (?:(?:un)?signed\s+)?long| + int\s+long\s+(?:un)?signed| + int\s+(?:(?:un)?signed\s+)?long| + + int\s+(?:un)?signed| + (?:(?:un)?signed\s+)?int +)}; + +our @typeListFile = (); +our @typeListWithAttr = ( + @typeList, + qr{struct\s+$InitAttribute\s+$Ident}, + qr{union\s+$InitAttribute\s+$Ident}, +); + +our @modifierList = ( + qr{fastcall}, +); +our @modifierListFile = (); + +our @mode_permission_funcs = ( + ["module_param", 3], + ["module_param_(?:array|named|string)", 4], + ["module_param_array_named", 5], + ["debugfs_create_(?:file|u8|u16|u32|u64|x8|x16|x32|x64|size_t|atomic_t|bool|blob|regset32|u32_array)", 2], + ["proc_create(?:_data|)", 2], + ["(?:CLASS|DEVICE|SENSOR|SENSOR_DEVICE|IIO_DEVICE)_ATTR", 2], + ["IIO_DEV_ATTR_[A-Z_]+", 1], + ["SENSOR_(?:DEVICE_|)ATTR_2", 2], + ["SENSOR_TEMPLATE(?:_2|)", 3], + ["__ATTR", 2], +); + +#Create a search pattern for all these functions to speed up a loop below +our $mode_perms_search = ""; +foreach my $entry (@mode_permission_funcs) { + $mode_perms_search .= '|' if ($mode_perms_search ne ""); + $mode_perms_search .= $entry->[0]; +} +$mode_perms_search = "(?:${mode_perms_search})"; + +our %deprecated_apis = ( + "synchronize_rcu_bh" => "synchronize_rcu", + "synchronize_rcu_bh_expedited" => "synchronize_rcu_expedited", + "call_rcu_bh" => "call_rcu", + "rcu_barrier_bh" => "rcu_barrier", + "synchronize_sched" => "synchronize_rcu", + "synchronize_sched_expedited" => "synchronize_rcu_expedited", + "call_rcu_sched" => "call_rcu", + "rcu_barrier_sched" => "rcu_barrier", + "get_state_synchronize_sched" => "get_state_synchronize_rcu", + "cond_synchronize_sched" => "cond_synchronize_rcu", +); + +#Create a search pattern for all these strings to speed up a loop below +our $deprecated_apis_search = ""; +foreach my $entry (keys %deprecated_apis) { + $deprecated_apis_search .= '|' if ($deprecated_apis_search ne ""); + $deprecated_apis_search .= $entry; +} +$deprecated_apis_search = "(?:${deprecated_apis_search})"; + +our $mode_perms_world_writable = qr{ + S_IWUGO | + S_IWOTH | + S_IRWXUGO | + S_IALLUGO | + 0[0-7][0-7][2367] +}x; + +our %mode_permission_string_types = ( + "S_IRWXU" => 0700, + "S_IRUSR" => 0400, + "S_IWUSR" => 0200, + "S_IXUSR" => 0100, + "S_IRWXG" => 0070, + "S_IRGRP" => 0040, + "S_IWGRP" => 0020, + "S_IXGRP" => 0010, + "S_IRWXO" => 0007, + "S_IROTH" => 0004, + "S_IWOTH" => 0002, + "S_IXOTH" => 0001, + "S_IRWXUGO" => 0777, + "S_IRUGO" => 0444, + "S_IWUGO" => 0222, + "S_IXUGO" => 0111, +); + +#Create a search pattern for all these strings to speed up a loop below +our $mode_perms_string_search = ""; +foreach my $entry (keys %mode_permission_string_types) { + $mode_perms_string_search .= '|' if ($mode_perms_string_search ne ""); + $mode_perms_string_search .= $entry; +} +our $single_mode_perms_string_search = "(?:${mode_perms_string_search})"; +our $multi_mode_perms_string_search = qr{ + ${single_mode_perms_string_search} + (?:\s*\|\s*${single_mode_perms_string_search})* +}x; + +sub perms_to_octal { + my ($string) = @_; + + return trim($string) if ($string =~ /^\s*0[0-7]{3,3}\s*$/); + + my $val = ""; + my $oval = ""; + my $to = 0; + my $curpos = 0; + my $lastpos = 0; + while ($string =~ /\b(($single_mode_perms_string_search)\b(?:\s*\|\s*)?\s*)/g) { + $curpos = pos($string); + my $match = $2; + my $omatch = $1; + last if ($lastpos > 0 && ($curpos - length($omatch) != $lastpos)); + $lastpos = $curpos; + $to |= $mode_permission_string_types{$match}; + $val .= '\s*\|\s*' if ($val ne ""); + $val .= $match; + $oval .= $omatch; + } + $oval =~ s/^\s*\|\s*//; + $oval =~ s/\s*\|\s*$//; + return sprintf("%04o", $to); +} + +our $allowed_asm_includes = qr{(?x: + irq| + memory| + time| + reboot +)}; +# memory.h: ARM has a custom one + +# Load common spelling mistakes and build regular expression list. +my $misspellings; +my %spelling_fix; + +if (open(my $spelling, '<', $spelling_file)) { + while (<$spelling>) { + my $line = $_; + + $line =~ s/\s*\n?$//g; + $line =~ s/^\s*//g; + + next if ($line =~ m/^\s*#/); + next if ($line =~ m/^\s*$/); + + my ($suspect, $fix) = split(/\|\|/, $line); + + $spelling_fix{$suspect} = $fix; + } + close($spelling); +} else { + warn "No typos will be found - file '$spelling_file': $!\n"; +} + +if ($codespell) { + if (open(my $spelling, '<', $codespellfile)) { + while (<$spelling>) { + my $line = $_; + + $line =~ s/\s*\n?$//g; + $line =~ s/^\s*//g; + + next if ($line =~ m/^\s*#/); + next if ($line =~ m/^\s*$/); + next if ($line =~ m/, disabled/i); + + $line =~ s/,.*$//; + + my ($suspect, $fix) = split(/->/, $line); + + $spelling_fix{$suspect} = $fix; + } + close($spelling); + } else { + warn "No codespell typos will be found - file '$codespellfile': $!\n"; + } +} + +$misspellings = join("|", sort keys %spelling_fix) if keys %spelling_fix; + +sub read_words { + my ($wordsRef, $file) = @_; + + if (open(my $words, '<', $file)) { + while (<$words>) { + my $line = $_; + + $line =~ s/\s*\n?$//g; + $line =~ s/^\s*//g; + + next if ($line =~ m/^\s*#/); + next if ($line =~ m/^\s*$/); + if ($line =~ /\s/) { + print("$file: '$line' invalid - ignored\n"); + next; + } + + $$wordsRef .= '|' if ($$wordsRef ne ""); + $$wordsRef .= $line; + } + close($file); + return 1; + } + + return 0; +} + +my $const_structs = ""; +read_words(\$const_structs, $conststructsfile) + or warn "No structs that should be const will be found - file '$conststructsfile': $!\n"; + +my $typeOtherTypedefs = ""; +if (length($typedefsfile)) { + read_words(\$typeOtherTypedefs, $typedefsfile) + or warn "No additional types will be considered - file '$typedefsfile': $!\n"; +} +$typeTypedefs .= '|' . $typeOtherTypedefs if ($typeOtherTypedefs ne ""); + +sub build_types { + my $mods = "(?x: \n" . join("|\n ", (@modifierList, @modifierListFile)) . "\n)"; + my $all = "(?x: \n" . join("|\n ", (@typeList, @typeListFile)) . "\n)"; + my $Misordered = "(?x: \n" . join("|\n ", @typeListMisordered) . "\n)"; + my $allWithAttr = "(?x: \n" . join("|\n ", @typeListWithAttr) . "\n)"; + $Modifier = qr{(?:$Attribute|$Sparse|$mods)}; + $BasicType = qr{ + (?:$typeTypedefs\b)| + (?:${all}\b) + }x; + $NonptrType = qr{ + (?:$Modifier\s+|const\s+)* + (?: + (?:typeof|__typeof__)\s*\([^\)]*\)| + (?:$typeTypedefs\b)| + (?:${all}\b) + ) + (?:\s+$Modifier|\s+const)* + }x; + $NonptrTypeMisordered = qr{ + (?:$Modifier\s+|const\s+)* + (?: + (?:${Misordered}\b) + ) + (?:\s+$Modifier|\s+const)* + }x; + $NonptrTypeWithAttr = qr{ + (?:$Modifier\s+|const\s+)* + (?: + (?:typeof|__typeof__)\s*\([^\)]*\)| + (?:$typeTypedefs\b)| + (?:${allWithAttr}\b) + ) + (?:\s+$Modifier|\s+const)* + }x; + $Type = qr{ + $NonptrType + (?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+)? + (?:\s+$Inline|\s+$Modifier)* + }x; + $TypeMisordered = qr{ + $NonptrTypeMisordered + (?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+)? + (?:\s+$Inline|\s+$Modifier)* + }x; + $Declare = qr{(?:$Storage\s+(?:$Inline\s+)?)?$Type}; + $DeclareMisordered = qr{(?:$Storage\s+(?:$Inline\s+)?)?$TypeMisordered}; +} +build_types(); + +our $Typecast = qr{\s*(\(\s*$NonptrType\s*\)){0,1}\s*}; + +# Using $balanced_parens, $LvalOrFunc, or $FuncArg +# requires at least perl version v5.10.0 +# Any use must be runtime checked with $^V + +our $balanced_parens = qr/(\((?:[^\(\)]++|(?-1))*\))/; +our $LvalOrFunc = qr{((?:[\&\*]\s*)?$Lval)\s*($balanced_parens{0,1})\s*}; +our $FuncArg = qr{$Typecast{0,1}($LvalOrFunc|$Constant|$String)}; + +our $declaration_macros = qr{(?x: + (?:$Storage\s+)?(?:[A-Z_][A-Z0-9]*_){0,2}(?:DEFINE|DECLARE)(?:_[A-Z0-9]+){1,6}\s*\(| + (?:$Storage\s+)?[HLP]?LIST_HEAD\s*\(| + (?:$Storage\s+)?${Type}\s+uninitialized_var\s*\(| + (?:SKCIPHER_REQUEST|SHASH_DESC|AHASH_REQUEST)_ON_STACK\s*\( +)}; + +sub deparenthesize { + my ($string) = @_; + return "" if (!defined($string)); + + while ($string =~ /^\s*\(.*\)\s*$/) { + $string =~ s@^\s*\(\s*@@; + $string =~ s@\s*\)\s*$@@; + } + + $string =~ s@\s+@ @g; + + return $string; +} + +sub seed_camelcase_file { + my ($file) = @_; + + return if (!(-f $file)); + + local $/; + + open(my $include_file, '<', "$file") + or warn "$P: Can't read '$file' $!\n"; + my $text = <$include_file>; + close($include_file); + + my @lines = split('\n', $text); + + foreach my $line (@lines) { + next if ($line !~ /(?:[A-Z][a-z]|[a-z][A-Z])/); + if ($line =~ /^[ \t]*(?:#[ \t]*define|typedef\s+$Type)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)/) { + $camelcase{$1} = 1; + } elsif ($line =~ /^\s*$Declare\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[\(\[,;]/) { + $camelcase{$1} = 1; + } elsif ($line =~ /^\s*(?:union|struct|enum)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[;\{]/) { + $camelcase{$1} = 1; + } + } +} + +sub is_maintained_obsolete { + my ($filename) = @_; + + return 0 if (!$tree || !(-e "$root/scripts/get_maintainer.pl")); + + my $status = `perl $root/scripts/get_maintainer.pl --status --nom --nol --nogit --nogit-fallback -f $filename 2>&1`; + + return $status =~ /obsolete/i; +} + +sub is_SPDX_License_valid { + my ($license) = @_; + + return 1 if (!$tree || which("python") eq "" || !(-e "$root/scripts/spdxcheck.py") || !(-e "$root/.git")); + + my $root_path = abs_path($root); + my $status = `cd "$root_path"; echo "$license" | python scripts/spdxcheck.py -`; + return 0 if ($status ne ""); + return 1; +} + +my $camelcase_seeded = 0; +sub seed_camelcase_includes { + return if ($camelcase_seeded); + + my $files; + my $camelcase_cache = ""; + my @include_files = (); + + $camelcase_seeded = 1; + + if (-e ".git") { + my $git_last_include_commit = `git log --no-merges --pretty=format:"%h%n" -1 -- include`; + chomp $git_last_include_commit; + $camelcase_cache = ".checkpatch-camelcase.git.$git_last_include_commit"; + } else { + my $last_mod_date = 0; + $files = `find $root/include -name "*.h"`; + @include_files = split('\n', $files); + foreach my $file (@include_files) { + my $date = POSIX::strftime("%Y%m%d%H%M", + localtime((stat $file)[9])); + $last_mod_date = $date if ($last_mod_date < $date); + } + $camelcase_cache = ".checkpatch-camelcase.date.$last_mod_date"; + } + + if ($camelcase_cache ne "" && -f $camelcase_cache) { + open(my $camelcase_file, '<', "$camelcase_cache") + or warn "$P: Can't read '$camelcase_cache' $!\n"; + while (<$camelcase_file>) { + chomp; + $camelcase{$_} = 1; + } + close($camelcase_file); + + return; + } + + if (-e ".git") { + $files = `git ls-files "include/*.h"`; + @include_files = split('\n', $files); + } + + foreach my $file (@include_files) { + seed_camelcase_file($file); + } + + if ($camelcase_cache ne "") { + unlink glob ".checkpatch-camelcase.*"; + open(my $camelcase_file, '>', "$camelcase_cache") + or warn "$P: Can't write '$camelcase_cache' $!\n"; + foreach (sort { lc($a) cmp lc($b) } keys(%camelcase)) { + print $camelcase_file ("$_\n"); + } + close($camelcase_file); + } +} + +sub git_commit_info { + my ($commit, $id, $desc) = @_; + + return ($id, $desc) if ((which("git") eq "") || !(-e ".git")); + + my $output = `git log --no-color --format='%H %s' -1 $commit 2>&1`; + $output =~ s/^\s*//gm; + my @lines = split("\n", $output); + + return ($id, $desc) if ($#lines < 0); + + if ($lines[0] =~ /^error: short SHA1 $commit is ambiguous\./) { +# Maybe one day convert this block of bash into something that returns +# all matching commit ids, but it's very slow... +# +# echo "checking commits $1..." +# git rev-list --remotes | grep -i "^$1" | +# while read line ; do +# git log --format='%H %s' -1 $line | +# echo "commit $(cut -c 1-12,41-)" +# done + } elsif ($lines[0] =~ /^fatal: ambiguous argument '$commit': unknown revision or path not in the working tree\./) { + $id = undef; + } else { + $id = substr($lines[0], 0, 12); + $desc = substr($lines[0], 41); + } + + return ($id, $desc); +} + +$chk_signoff = 0 if ($file); + +my @rawlines = (); +my @lines = (); +my @fixed = (); +my @fixed_inserted = (); +my @fixed_deleted = (); +my $fixlinenr = -1; + +# If input is git commits, extract all commits from the commit expressions. +# For example, HEAD-3 means we need check 'HEAD, HEAD~1, HEAD~2'. +die "$P: No git repository found\n" if ($git && !-e ".git"); + +if ($git) { + my @commits = (); + foreach my $commit_expr (@ARGV) { + my $git_range; + if ($commit_expr =~ m/^(.*)-(\d+)$/) { + $git_range = "-$2 $1"; + } elsif ($commit_expr =~ m/\.\./) { + $git_range = "$commit_expr"; + } else { + $git_range = "-1 $commit_expr"; + } + my $lines = `git log --no-color --no-merges --pretty=format:'%H %s' $git_range`; + foreach my $line (split(/\n/, $lines)) { + $line =~ /^([0-9a-fA-F]{40,40}) (.*)$/; + next if (!defined($1) || !defined($2)); + my $sha1 = $1; + my $subject = $2; + unshift(@commits, $sha1); + $git_commits{$sha1} = $subject; + } + } + die "$P: no git commits after extraction!\n" if (@commits == 0); + @ARGV = @commits; +} + +my $vname; +for my $filename (@ARGV) { + my $FILE; + if ($git) { + open($FILE, '-|', "git format-patch -M --stdout -1 $filename") || + die "$P: $filename: git format-patch failed - $!\n"; + } elsif ($file) { + open($FILE, '-|', "diff -u /dev/null $filename") || + die "$P: $filename: diff failed - $!\n"; + } elsif ($filename eq '-') { + open($FILE, '<&STDIN'); + } else { + open($FILE, '<', "$filename") || + die "$P: $filename: open failed - $!\n"; + } + if ($filename eq '-') { + $vname = 'Your patch'; + } elsif ($git) { + $vname = "Commit " . substr($filename, 0, 12) . ' ("' . $git_commits{$filename} . '")'; + } else { + $vname = $filename; + } + while (<$FILE>) { + chomp; + push(@rawlines, $_); + } + close($FILE); + + if ($#ARGV > 0 && $quiet == 0) { + print '-' x length($vname) . "\n"; + print "$vname\n"; + print '-' x length($vname) . "\n"; + } + + if (!process($filename)) { + $exit = 1; + } + @rawlines = (); + @lines = (); + @fixed = (); + @fixed_inserted = (); + @fixed_deleted = (); + $fixlinenr = -1; + @modifierListFile = (); + @typeListFile = (); + build_types(); +} + +if (!$quiet) { + hash_show_words(\%use_type, "Used"); + hash_show_words(\%ignore_type, "Ignored"); + + if (!$perl_version_ok) { + print << "EOM" + +NOTE: perl $^V is not modern enough to detect all possible issues. + An upgrade to at least perl $minimum_perl_version is suggested. +EOM + } + if ($exit) { + print << "EOM" + +NOTE: If any of the errors are false positives, please report + them to the maintainer, see CHECKPATCH in MAINTAINERS. +EOM + } +} + +exit($exit); + +sub top_of_kernel_tree { + my ($root) = @_; + + my @tree_check = ( + "COPYING", "CREDITS", "Kbuild", "MAINTAINERS", "Makefile", + "README", "Documentation", "arch", "include", "drivers", + "fs", "init", "ipc", "kernel", "lib", "scripts", + ); + + foreach my $check (@tree_check) { + if (! -e $root . '/' . $check) { + return 0; + } + } + return 1; +} + +sub parse_email { + my ($formatted_email) = @_; + + my $name = ""; + my $address = ""; + my $comment = ""; + + if ($formatted_email =~ /^(.*)<(\S+\@\S+)>(.*)$/) { + $name = $1; + $address = $2; + $comment = $3 if defined $3; + } elsif ($formatted_email =~ /^\s*<(\S+\@\S+)>(.*)$/) { + $address = $1; + $comment = $2 if defined $2; + } elsif ($formatted_email =~ /(\S+\@\S+)(.*)$/) { + $address = $1; + $comment = $2 if defined $2; + $formatted_email =~ s/\Q$address\E.*$//; + $name = $formatted_email; + $name = trim($name); + $name =~ s/^\"|\"$//g; + # If there's a name left after stripping spaces and + # leading quotes, and the address doesn't have both + # leading and trailing angle brackets, the address + # is invalid. ie: + # "joe smith joe@smith.com" bad + # "joe smith ]+>$/) { + $name = ""; + $address = ""; + $comment = ""; + } + } + + $name = trim($name); + $name =~ s/^\"|\"$//g; + $address = trim($address); + $address =~ s/^\<|\>$//g; + + if ($name =~ /[^\w \-]/i) { ##has "must quote" chars + $name =~ s/(?"; + } + + return $formatted_email; +} + +sub which { + my ($bin) = @_; + + foreach my $path (split(/:/, $ENV{PATH})) { + if (-e "$path/$bin") { + return "$path/$bin"; + } + } + + return ""; +} + +sub which_conf { + my ($conf) = @_; + + foreach my $path (split(/:/, ".:$ENV{HOME}:.scripts")) { + if (-e "$path/$conf") { + return "$path/$conf"; + } + } + + return ""; +} + +sub expand_tabs { + my ($str) = @_; + + my $res = ''; + my $n = 0; + for my $c (split(//, $str)) { + if ($c eq "\t") { + $res .= ' '; + $n++; + for (; ($n % 8) != 0; $n++) { + $res .= ' '; + } + next; + } + $res .= $c; + $n++; + } + + return $res; +} +sub copy_spacing { + (my $res = shift) =~ tr/\t/ /c; + return $res; +} + +sub line_stats { + my ($line) = @_; + + # Drop the diff line leader and expand tabs + $line =~ s/^.//; + $line = expand_tabs($line); + + # Pick the indent from the front of the line. + my ($white) = ($line =~ /^(\s*)/); + + return (length($line), length($white)); +} + +my $sanitise_quote = ''; + +sub sanitise_line_reset { + my ($in_comment) = @_; + + if ($in_comment) { + $sanitise_quote = '*/'; + } else { + $sanitise_quote = ''; + } +} +sub sanitise_line { + my ($line) = @_; + + my $res = ''; + my $l = ''; + + my $qlen = 0; + my $off = 0; + my $c; + + # Always copy over the diff marker. + $res = substr($line, 0, 1); + + for ($off = 1; $off < length($line); $off++) { + $c = substr($line, $off, 1); + + # Comments we are whacking completely including the begin + # and end, all to $;. + if ($sanitise_quote eq '' && substr($line, $off, 2) eq '/*') { + $sanitise_quote = '*/'; + + substr($res, $off, 2, "$;$;"); + $off++; + next; + } + if ($sanitise_quote eq '*/' && substr($line, $off, 2) eq '*/') { + $sanitise_quote = ''; + substr($res, $off, 2, "$;$;"); + $off++; + next; + } + if ($sanitise_quote eq '' && substr($line, $off, 2) eq '//') { + $sanitise_quote = '//'; + + substr($res, $off, 2, $sanitise_quote); + $off++; + next; + } + + # A \ in a string means ignore the next character. + if (($sanitise_quote eq "'" || $sanitise_quote eq '"') && + $c eq "\\") { + substr($res, $off, 2, 'XX'); + $off++; + next; + } + # Regular quotes. + if ($c eq "'" || $c eq '"') { + if ($sanitise_quote eq '') { + $sanitise_quote = $c; + + substr($res, $off, 1, $c); + next; + } elsif ($sanitise_quote eq $c) { + $sanitise_quote = ''; + } + } + + #print "c<$c> SQ<$sanitise_quote>\n"; + if ($off != 0 && $sanitise_quote eq '*/' && $c ne "\t") { + substr($res, $off, 1, $;); + } elsif ($off != 0 && $sanitise_quote eq '//' && $c ne "\t") { + substr($res, $off, 1, $;); + } elsif ($off != 0 && $sanitise_quote && $c ne "\t") { + substr($res, $off, 1, 'X'); + } else { + substr($res, $off, 1, $c); + } + } + + if ($sanitise_quote eq '//') { + $sanitise_quote = ''; + } + + # The pathname on a #include may be surrounded by '<' and '>'. + if ($res =~ /^.\s*\#\s*include\s+\<(.*)\>/) { + my $clean = 'X' x length($1); + $res =~ s@\<.*\>@<$clean>@; + + # The whole of a #error is a string. + } elsif ($res =~ /^.\s*\#\s*(?:error|warning)\s+(.*)\b/) { + my $clean = 'X' x length($1); + $res =~ s@(\#\s*(?:error|warning)\s+).*@$1$clean@; + } + + if ($allow_c99_comments && $res =~ m@(//.*$)@) { + my $match = $1; + $res =~ s/\Q$match\E/"$;" x length($match)/e; + } + + return $res; +} + +sub get_quoted_string { + my ($line, $rawline) = @_; + + return "" if (!defined($line) || !defined($rawline)); + return "" if ($line !~ m/($String)/g); + return substr($rawline, $-[0], $+[0] - $-[0]); +} + +sub ctx_statement_block { + my ($linenr, $remain, $off) = @_; + my $line = $linenr - 1; + my $blk = ''; + my $soff = $off; + my $coff = $off - 1; + my $coff_set = 0; + + my $loff = 0; + + my $type = ''; + my $level = 0; + my @stack = (); + my $p; + my $c; + my $len = 0; + + my $remainder; + while (1) { + @stack = (['', 0]) if ($#stack == -1); + + #warn "CSB: blk<$blk> remain<$remain>\n"; + # If we are about to drop off the end, pull in more + # context. + if ($off >= $len) { + for (; $remain > 0; $line++) { + last if (!defined $lines[$line]); + next if ($lines[$line] =~ /^-/); + $remain--; + $loff = $len; + $blk .= $lines[$line] . "\n"; + $len = length($blk); + $line++; + last; + } + # Bail if there is no further context. + #warn "CSB: blk<$blk> off<$off> len<$len>\n"; + if ($off >= $len) { + last; + } + if ($level == 0 && substr($blk, $off) =~ /^.\s*#\s*define/) { + $level++; + $type = '#'; + } + } + $p = $c; + $c = substr($blk, $off, 1); + $remainder = substr($blk, $off); + + #warn "CSB: c<$c> type<$type> level<$level> remainder<$remainder> coff_set<$coff_set>\n"; + + # Handle nested #if/#else. + if ($remainder =~ /^#\s*(?:ifndef|ifdef|if)\s/) { + push(@stack, [ $type, $level ]); + } elsif ($remainder =~ /^#\s*(?:else|elif)\b/) { + ($type, $level) = @{$stack[$#stack - 1]}; + } elsif ($remainder =~ /^#\s*endif\b/) { + ($type, $level) = @{pop(@stack)}; + } + + # Statement ends at the ';' or a close '}' at the + # outermost level. + if ($level == 0 && $c eq ';') { + last; + } + + # An else is really a conditional as long as its not else if + if ($level == 0 && $coff_set == 0 && + (!defined($p) || $p =~ /(?:\s|\}|\+)/) && + $remainder =~ /^(else)(?:\s|{)/ && + $remainder !~ /^else\s+if\b/) { + $coff = $off + length($1) - 1; + $coff_set = 1; + #warn "CSB: mark coff<$coff> soff<$soff> 1<$1>\n"; + #warn "[" . substr($blk, $soff, $coff - $soff + 1) . "]\n"; + } + + if (($type eq '' || $type eq '(') && $c eq '(') { + $level++; + $type = '('; + } + if ($type eq '(' && $c eq ')') { + $level--; + $type = ($level != 0)? '(' : ''; + + if ($level == 0 && $coff < $soff) { + $coff = $off; + $coff_set = 1; + #warn "CSB: mark coff<$coff>\n"; + } + } + if (($type eq '' || $type eq '{') && $c eq '{') { + $level++; + $type = '{'; + } + if ($type eq '{' && $c eq '}') { + $level--; + $type = ($level != 0)? '{' : ''; + + if ($level == 0) { + if (substr($blk, $off + 1, 1) eq ';') { + $off++; + } + last; + } + } + # Preprocessor commands end at the newline unless escaped. + if ($type eq '#' && $c eq "\n" && $p ne "\\") { + $level--; + $type = ''; + $off++; + last; + } + $off++; + } + # We are truly at the end, so shuffle to the next line. + if ($off == $len) { + $loff = $len + 1; + $line++; + $remain--; + } + + my $statement = substr($blk, $soff, $off - $soff + 1); + my $condition = substr($blk, $soff, $coff - $soff + 1); + + #warn "STATEMENT<$statement>\n"; + #warn "CONDITION<$condition>\n"; + + #print "coff<$coff> soff<$off> loff<$loff>\n"; + + return ($statement, $condition, + $line, $remain + 1, $off - $loff + 1, $level); +} + +sub statement_lines { + my ($stmt) = @_; + + # Strip the diff line prefixes and rip blank lines at start and end. + $stmt =~ s/(^|\n)./$1/g; + $stmt =~ s/^\s*//; + $stmt =~ s/\s*$//; + + my @stmt_lines = ($stmt =~ /\n/g); + + return $#stmt_lines + 2; +} + +sub statement_rawlines { + my ($stmt) = @_; + + my @stmt_lines = ($stmt =~ /\n/g); + + return $#stmt_lines + 2; +} + +sub statement_block_size { + my ($stmt) = @_; + + $stmt =~ s/(^|\n)./$1/g; + $stmt =~ s/^\s*{//; + $stmt =~ s/}\s*$//; + $stmt =~ s/^\s*//; + $stmt =~ s/\s*$//; + + my @stmt_lines = ($stmt =~ /\n/g); + my @stmt_statements = ($stmt =~ /;/g); + + my $stmt_lines = $#stmt_lines + 2; + my $stmt_statements = $#stmt_statements + 1; + + if ($stmt_lines > $stmt_statements) { + return $stmt_lines; + } else { + return $stmt_statements; + } +} + +sub ctx_statement_full { + my ($linenr, $remain, $off) = @_; + my ($statement, $condition, $level); + + my (@chunks); + + # Grab the first conditional/block pair. + ($statement, $condition, $linenr, $remain, $off, $level) = + ctx_statement_block($linenr, $remain, $off); + #print "F: c<$condition> s<$statement> remain<$remain>\n"; + push(@chunks, [ $condition, $statement ]); + if (!($remain > 0 && $condition =~ /^\s*(?:\n[+-])?\s*(?:if|else|do)\b/s)) { + return ($level, $linenr, @chunks); + } + + # Pull in the following conditional/block pairs and see if they + # could continue the statement. + for (;;) { + ($statement, $condition, $linenr, $remain, $off, $level) = + ctx_statement_block($linenr, $remain, $off); + #print "C: c<$condition> s<$statement> remain<$remain>\n"; + last if (!($remain > 0 && $condition =~ /^(?:\s*\n[+-])*\s*(?:else|do)\b/s)); + #print "C: push\n"; + push(@chunks, [ $condition, $statement ]); + } + + return ($level, $linenr, @chunks); +} + +sub ctx_block_get { + my ($linenr, $remain, $outer, $open, $close, $off) = @_; + my $line; + my $start = $linenr - 1; + my $blk = ''; + my @o; + my @c; + my @res = (); + + my $level = 0; + my @stack = ($level); + for ($line = $start; $remain > 0; $line++) { + next if ($rawlines[$line] =~ /^-/); + $remain--; + + $blk .= $rawlines[$line]; + + # Handle nested #if/#else. + if ($lines[$line] =~ /^.\s*#\s*(?:ifndef|ifdef|if)\s/) { + push(@stack, $level); + } elsif ($lines[$line] =~ /^.\s*#\s*(?:else|elif)\b/) { + $level = $stack[$#stack - 1]; + } elsif ($lines[$line] =~ /^.\s*#\s*endif\b/) { + $level = pop(@stack); + } + + foreach my $c (split(//, $lines[$line])) { + ##print "C<$c>L<$level><$open$close>O<$off>\n"; + if ($off > 0) { + $off--; + next; + } + + if ($c eq $close && $level > 0) { + $level--; + last if ($level == 0); + } elsif ($c eq $open) { + $level++; + } + } + + if (!$outer || $level <= 1) { + push(@res, $rawlines[$line]); + } + + last if ($level == 0); + } + + return ($level, @res); +} +sub ctx_block_outer { + my ($linenr, $remain) = @_; + + my ($level, @r) = ctx_block_get($linenr, $remain, 1, '{', '}', 0); + return @r; +} +sub ctx_block { + my ($linenr, $remain) = @_; + + my ($level, @r) = ctx_block_get($linenr, $remain, 0, '{', '}', 0); + return @r; +} +sub ctx_statement { + my ($linenr, $remain, $off) = @_; + + my ($level, @r) = ctx_block_get($linenr, $remain, 0, '(', ')', $off); + return @r; +} +sub ctx_block_level { + my ($linenr, $remain) = @_; + + return ctx_block_get($linenr, $remain, 0, '{', '}', 0); +} +sub ctx_statement_level { + my ($linenr, $remain, $off) = @_; + + return ctx_block_get($linenr, $remain, 0, '(', ')', $off); +} + +sub ctx_locate_comment { + my ($first_line, $end_line) = @_; + + # Catch a comment on the end of the line itself. + my ($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*(?:\\\s*)?$@); + return $current_comment if (defined $current_comment); + + # Look through the context and try and figure out if there is a + # comment. + my $in_comment = 0; + $current_comment = ''; + for (my $linenr = $first_line; $linenr < $end_line; $linenr++) { + my $line = $rawlines[$linenr - 1]; + #warn " $line\n"; + if ($linenr == $first_line and $line =~ m@^.\s*\*@) { + $in_comment = 1; + } + if ($line =~ m@/\*@) { + $in_comment = 1; + } + if (!$in_comment && $current_comment ne '') { + $current_comment = ''; + } + $current_comment .= $line . "\n" if ($in_comment); + if ($line =~ m@\*/@) { + $in_comment = 0; + } + } + + chomp($current_comment); + return($current_comment); +} +sub ctx_has_comment { + my ($first_line, $end_line) = @_; + my $cmt = ctx_locate_comment($first_line, $end_line); + + ##print "LINE: $rawlines[$end_line - 1 ]\n"; + ##print "CMMT: $cmt\n"; + + return ($cmt ne ''); +} + +sub raw_line { + my ($linenr, $cnt) = @_; + + my $offset = $linenr - 1; + $cnt++; + + my $line; + while ($cnt) { + $line = $rawlines[$offset++]; + next if (defined($line) && $line =~ /^-/); + $cnt--; + } + + return $line; +} + +sub get_stat_real { + my ($linenr, $lc) = @_; + + my $stat_real = raw_line($linenr, 0); + for (my $count = $linenr + 1; $count <= $lc; $count++) { + $stat_real = $stat_real . "\n" . raw_line($count, 0); + } + + return $stat_real; +} + +sub get_stat_here { + my ($linenr, $cnt, $here) = @_; + + my $herectx = $here . "\n"; + for (my $n = 0; $n < $cnt; $n++) { + $herectx .= raw_line($linenr, $n) . "\n"; + } + + return $herectx; +} + +sub cat_vet { + my ($vet) = @_; + my ($res, $coded); + + $res = ''; + while ($vet =~ /([^[:cntrl:]]*)([[:cntrl:]]|$)/g) { + $res .= $1; + if ($2 ne '') { + $coded = sprintf("^%c", unpack('C', $2) + 64); + $res .= $coded; + } + } + $res =~ s/$/\$/; + + return $res; +} + +my $av_preprocessor = 0; +my $av_pending; +my @av_paren_type; +my $av_pend_colon; + +sub annotate_reset { + $av_preprocessor = 0; + $av_pending = '_'; + @av_paren_type = ('E'); + $av_pend_colon = 'O'; +} + +sub annotate_values { + my ($stream, $type) = @_; + + my $res; + my $var = '_' x length($stream); + my $cur = $stream; + + print "$stream\n" if ($dbg_values > 1); + + while (length($cur)) { + @av_paren_type = ('E') if ($#av_paren_type < 0); + print " <" . join('', @av_paren_type) . + "> <$type> <$av_pending>" if ($dbg_values > 1); + if ($cur =~ /^(\s+)/o) { + print "WS($1)\n" if ($dbg_values > 1); + if ($1 =~ /\n/ && $av_preprocessor) { + $type = pop(@av_paren_type); + $av_preprocessor = 0; + } + + } elsif ($cur =~ /^(\(\s*$Type\s*)\)/ && $av_pending eq '_') { + print "CAST($1)\n" if ($dbg_values > 1); + push(@av_paren_type, $type); + $type = 'c'; + + } elsif ($cur =~ /^($Type)\s*(?:$Ident|,|\)|\(|\s*$)/) { + print "DECLARE($1)\n" if ($dbg_values > 1); + $type = 'T'; + + } elsif ($cur =~ /^($Modifier)\s*/) { + print "MODIFIER($1)\n" if ($dbg_values > 1); + $type = 'T'; + + } elsif ($cur =~ /^(\#\s*define\s*$Ident)(\(?)/o) { + print "DEFINE($1,$2)\n" if ($dbg_values > 1); + $av_preprocessor = 1; + push(@av_paren_type, $type); + if ($2 ne '') { + $av_pending = 'N'; + } + $type = 'E'; + + } elsif ($cur =~ /^(\#\s*(?:undef\s*$Ident|include\b))/o) { + print "UNDEF($1)\n" if ($dbg_values > 1); + $av_preprocessor = 1; + push(@av_paren_type, $type); + + } elsif ($cur =~ /^(\#\s*(?:ifdef|ifndef|if))/o) { + print "PRE_START($1)\n" if ($dbg_values > 1); + $av_preprocessor = 1; + + push(@av_paren_type, $type); + push(@av_paren_type, $type); + $type = 'E'; + + } elsif ($cur =~ /^(\#\s*(?:else|elif))/o) { + print "PRE_RESTART($1)\n" if ($dbg_values > 1); + $av_preprocessor = 1; + + push(@av_paren_type, $av_paren_type[$#av_paren_type]); + + $type = 'E'; + + } elsif ($cur =~ /^(\#\s*(?:endif))/o) { + print "PRE_END($1)\n" if ($dbg_values > 1); + + $av_preprocessor = 1; + + # Assume all arms of the conditional end as this + # one does, and continue as if the #endif was not here. + pop(@av_paren_type); + push(@av_paren_type, $type); + $type = 'E'; + + } elsif ($cur =~ /^(\\\n)/o) { + print "PRECONT($1)\n" if ($dbg_values > 1); + + } elsif ($cur =~ /^(__attribute__)\s*\(?/o) { + print "ATTR($1)\n" if ($dbg_values > 1); + $av_pending = $type; + $type = 'N'; + + } elsif ($cur =~ /^(sizeof)\s*(\()?/o) { + print "SIZEOF($1)\n" if ($dbg_values > 1); + if (defined $2) { + $av_pending = 'V'; + } + $type = 'N'; + + } elsif ($cur =~ /^(if|while|for)\b/o) { + print "COND($1)\n" if ($dbg_values > 1); + $av_pending = 'E'; + $type = 'N'; + + } elsif ($cur =~/^(case)/o) { + print "CASE($1)\n" if ($dbg_values > 1); + $av_pend_colon = 'C'; + $type = 'N'; + + } elsif ($cur =~/^(return|else|goto|typeof|__typeof__)\b/o) { + print "KEYWORD($1)\n" if ($dbg_values > 1); + $type = 'N'; + + } elsif ($cur =~ /^(\()/o) { + print "PAREN('$1')\n" if ($dbg_values > 1); + push(@av_paren_type, $av_pending); + $av_pending = '_'; + $type = 'N'; + + } elsif ($cur =~ /^(\))/o) { + my $new_type = pop(@av_paren_type); + if ($new_type ne '_') { + $type = $new_type; + print "PAREN('$1') -> $type\n" + if ($dbg_values > 1); + } else { + print "PAREN('$1')\n" if ($dbg_values > 1); + } + + } elsif ($cur =~ /^($Ident)\s*\(/o) { + print "FUNC($1)\n" if ($dbg_values > 1); + $type = 'V'; + $av_pending = 'V'; + + } elsif ($cur =~ /^($Ident\s*):(?:\s*\d+\s*(,|=|;))?/) { + if (defined $2 && $type eq 'C' || $type eq 'T') { + $av_pend_colon = 'B'; + } elsif ($type eq 'E') { + $av_pend_colon = 'L'; + } + print "IDENT_COLON($1,$type>$av_pend_colon)\n" if ($dbg_values > 1); + $type = 'V'; + + } elsif ($cur =~ /^($Ident|$Constant)/o) { + print "IDENT($1)\n" if ($dbg_values > 1); + $type = 'V'; + + } elsif ($cur =~ /^($Assignment)/o) { + print "ASSIGN($1)\n" if ($dbg_values > 1); + $type = 'N'; + + } elsif ($cur =~/^(;|{|})/) { + print "END($1)\n" if ($dbg_values > 1); + $type = 'E'; + $av_pend_colon = 'O'; + + } elsif ($cur =~/^(,)/) { + print "COMMA($1)\n" if ($dbg_values > 1); + $type = 'C'; + + } elsif ($cur =~ /^(\?)/o) { + print "QUESTION($1)\n" if ($dbg_values > 1); + $type = 'N'; + + } elsif ($cur =~ /^(:)/o) { + print "COLON($1,$av_pend_colon)\n" if ($dbg_values > 1); + + substr($var, length($res), 1, $av_pend_colon); + if ($av_pend_colon eq 'C' || $av_pend_colon eq 'L') { + $type = 'E'; + } else { + $type = 'N'; + } + $av_pend_colon = 'O'; + + } elsif ($cur =~ /^(\[)/o) { + print "CLOSE($1)\n" if ($dbg_values > 1); + $type = 'N'; + + } elsif ($cur =~ /^(-(?![->])|\+(?!\+)|\*|\&\&|\&)/o) { + my $variant; + + print "OPV($1)\n" if ($dbg_values > 1); + if ($type eq 'V') { + $variant = 'B'; + } else { + $variant = 'U'; + } + + substr($var, length($res), 1, $variant); + $type = 'N'; + + } elsif ($cur =~ /^($Operators)/o) { + print "OP($1)\n" if ($dbg_values > 1); + if ($1 ne '++' && $1 ne '--') { + $type = 'N'; + } + + } elsif ($cur =~ /(^.)/o) { + print "C($1)\n" if ($dbg_values > 1); + } + if (defined $1) { + $cur = substr($cur, length($1)); + $res .= $type x length($1); + } + } + + return ($res, $var); +} + +sub possible { + my ($possible, $line) = @_; + my $notPermitted = qr{(?: + ^(?: + $Modifier| + $Storage| + $Type| + DEFINE_\S+ + )$| + ^(?: + goto| + return| + case| + else| + asm|__asm__| + do| + \#| + \#\#| + )(?:\s|$)| + ^(?:typedef|struct|enum)\b + )}x; + warn "CHECK<$possible> ($line)\n" if ($dbg_possible > 2); + if ($possible !~ $notPermitted) { + # Check for modifiers. + $possible =~ s/\s*$Storage\s*//g; + $possible =~ s/\s*$Sparse\s*//g; + if ($possible =~ /^\s*$/) { + + } elsif ($possible =~ /\s/) { + $possible =~ s/\s*$Type\s*//g; + for my $modifier (split(' ', $possible)) { + if ($modifier !~ $notPermitted) { + warn "MODIFIER: $modifier ($possible) ($line)\n" if ($dbg_possible); + push(@modifierListFile, $modifier); + } + } + + } else { + warn "POSSIBLE: $possible ($line)\n" if ($dbg_possible); + push(@typeListFile, $possible); + } + build_types(); + } else { + warn "NOTPOSS: $possible ($line)\n" if ($dbg_possible > 1); + } +} + +my $prefix = ''; + +sub show_type { + my ($type) = @_; + + $type =~ tr/[a-z]/[A-Z]/; + + return defined $use_type{$type} if (scalar keys %use_type > 0); + + return !defined $ignore_type{$type}; +} + +sub report { + my ($level, $type, $msg) = @_; + + if (!show_type($type) || + (defined $tst_only && $msg !~ /\Q$tst_only\E/)) { + return 0; + } + my $output = ''; + if ($color) { + if ($level eq 'ERROR') { + $output .= RED; + } elsif ($level eq 'WARNING') { + $output .= YELLOW; + } else { + $output .= GREEN; + } + } + $output .= $prefix . $level . ':'; + if ($show_types) { + $output .= BLUE if ($color); + $output .= "$type:"; + } + $output .= RESET if ($color); + $output .= ' ' . $msg . "\n"; + + if ($showfile) { + my @lines = split("\n", $output, -1); + splice(@lines, 1, 1); + $output = join("\n", @lines); + } + $output = (split('\n', $output))[0] . "\n" if ($terse); + + push(our @report, $output); + + return 1; +} + +sub report_dump { + our @report; +} + +sub fixup_current_range { + my ($lineRef, $offset, $length) = @_; + + if ($$lineRef =~ /^\@\@ -\d+,\d+ \+(\d+),(\d+) \@\@/) { + my $o = $1; + my $l = $2; + my $no = $o + $offset; + my $nl = $l + $length; + $$lineRef =~ s/\+$o,$l \@\@/\+$no,$nl \@\@/; + } +} + +sub fix_inserted_deleted_lines { + my ($linesRef, $insertedRef, $deletedRef) = @_; + + my $range_last_linenr = 0; + my $delta_offset = 0; + + my $old_linenr = 0; + my $new_linenr = 0; + + my $next_insert = 0; + my $next_delete = 0; + + my @lines = (); + + my $inserted = @{$insertedRef}[$next_insert++]; + my $deleted = @{$deletedRef}[$next_delete++]; + + foreach my $old_line (@{$linesRef}) { + my $save_line = 1; + my $line = $old_line; #don't modify the array + if ($line =~ /^(?:\+\+\+|\-\-\-)\s+\S+/) { #new filename + $delta_offset = 0; + } elsif ($line =~ /^\@\@ -\d+,\d+ \+\d+,\d+ \@\@/) { #new hunk + $range_last_linenr = $new_linenr; + fixup_current_range(\$line, $delta_offset, 0); + } + + while (defined($deleted) && ${$deleted}{'LINENR'} == $old_linenr) { + $deleted = @{$deletedRef}[$next_delete++]; + $save_line = 0; + fixup_current_range(\$lines[$range_last_linenr], $delta_offset--, -1); + } + + while (defined($inserted) && ${$inserted}{'LINENR'} == $old_linenr) { + push(@lines, ${$inserted}{'LINE'}); + $inserted = @{$insertedRef}[$next_insert++]; + $new_linenr++; + fixup_current_range(\$lines[$range_last_linenr], $delta_offset++, 1); + } + + if ($save_line) { + push(@lines, $line); + $new_linenr++; + } + + $old_linenr++; + } + + return @lines; +} + +sub fix_insert_line { + my ($linenr, $line) = @_; + + my $inserted = { + LINENR => $linenr, + LINE => $line, + }; + push(@fixed_inserted, $inserted); +} + +sub fix_delete_line { + my ($linenr, $line) = @_; + + my $deleted = { + LINENR => $linenr, + LINE => $line, + }; + + push(@fixed_deleted, $deleted); +} + +sub ERROR { + my ($type, $msg) = @_; + + if (report("ERROR", $type, $msg)) { + our $clean = 0; + our $cnt_error++; + return 1; + } + return 0; +} +sub WARN { + my ($type, $msg) = @_; + + if (report("WARNING", $type, $msg)) { + our $clean = 0; + our $cnt_warn++; + return 1; + } + return 0; +} +sub CHK { + my ($type, $msg) = @_; + + if ($check && report("CHECK", $type, $msg)) { + our $clean = 0; + our $cnt_chk++; + return 1; + } + return 0; +} + +sub check_absolute_file { + my ($absolute, $herecurr) = @_; + my $file = $absolute; + + ##print "absolute<$absolute>\n"; + + # See if any suffix of this path is a path within the tree. + while ($file =~ s@^[^/]*/@@) { + if (-f "$root/$file") { + ##print "file<$file>\n"; + last; + } + } + if (! -f _) { + return 0; + } + + # It is, so see if the prefix is acceptable. + my $prefix = $absolute; + substr($prefix, -length($file)) = ''; + + ##print "prefix<$prefix>\n"; + if ($prefix ne ".../") { + WARN("USE_RELATIVE_PATH", + "use relative pathname instead of absolute in changelog text\n" . $herecurr); + } +} + +sub trim { + my ($string) = @_; + + $string =~ s/^\s+|\s+$//g; + + return $string; +} + +sub ltrim { + my ($string) = @_; + + $string =~ s/^\s+//; + + return $string; +} + +sub rtrim { + my ($string) = @_; + + $string =~ s/\s+$//; + + return $string; +} + +sub string_find_replace { + my ($string, $find, $replace) = @_; + + $string =~ s/$find/$replace/g; + + return $string; +} + +sub tabify { + my ($leading) = @_; + + my $source_indent = 8; + my $max_spaces_before_tab = $source_indent - 1; + my $spaces_to_tab = " " x $source_indent; + + #convert leading spaces to tabs + 1 while $leading =~ s@^([\t]*)$spaces_to_tab@$1\t@g; + #Remove spaces before a tab + 1 while $leading =~ s@^([\t]*)( {1,$max_spaces_before_tab})\t@$1\t@g; + + return "$leading"; +} + +sub pos_last_openparen { + my ($line) = @_; + + my $pos = 0; + + my $opens = $line =~ tr/\(/\(/; + my $closes = $line =~ tr/\)/\)/; + + my $last_openparen = 0; + + if (($opens == 0) || ($closes >= $opens)) { + return -1; + } + + my $len = length($line); + + for ($pos = 0; $pos < $len; $pos++) { + my $string = substr($line, $pos); + if ($string =~ /^($FuncArg|$balanced_parens)/) { + $pos += length($1) - 1; + } elsif (substr($line, $pos, 1) eq '(') { + $last_openparen = $pos; + } elsif (index($string, '(') == -1) { + last; + } + } + + return length(expand_tabs(substr($line, 0, $last_openparen))) + 1; +} + +sub process { + my $filename = shift; + + my $linenr=0; + my $prevline=""; + my $prevrawline=""; + my $stashline=""; + my $stashrawline=""; + + my $length; + my $indent; + my $previndent=0; + my $stashindent=0; + + our $clean = 1; + my $signoff = 0; + my $author = ''; + my $authorsignoff = 0; + my $is_patch = 0; + my $is_binding_patch = -1; + my $in_header_lines = $file ? 0 : 1; + my $in_commit_log = 0; #Scanning lines before patch + my $has_commit_log = 0; #Encountered lines before patch + my $commit_log_lines = 0; #Number of commit log lines + my $commit_log_possible_stack_dump = 0; + my $commit_log_long_line = 0; + my $commit_log_has_diff = 0; + my $reported_maintainer_file = 0; + my $non_utf8_charset = 0; + + my $last_blank_line = 0; + my $last_coalesced_string_linenr = -1; + + our @report = (); + our $cnt_lines = 0; + our $cnt_error = 0; + our $cnt_warn = 0; + our $cnt_chk = 0; + + # Trace the real file/line as we go. + my $realfile = ''; + my $realline = 0; + my $realcnt = 0; + my $here = ''; + my $context_function; #undef'd unless there's a known function + my $in_comment = 0; + my $comment_edge = 0; + my $first_line = 0; + my $p1_prefix = ''; + + my $prev_values = 'E'; + + # suppression flags + my %suppress_ifbraces; + my %suppress_whiletrailers; + my %suppress_export; + my $suppress_statement = 0; + + my %signatures = (); + + # Pre-scan the patch sanitizing the lines. + # Pre-scan the patch looking for any __setup documentation. + # + my @setup_docs = (); + my $setup_docs = 0; + + my $camelcase_file_seeded = 0; + + my $checklicenseline = 1; + + sanitise_line_reset(); + my $line; + foreach my $rawline (@rawlines) { + $linenr++; + $line = $rawline; + + push(@fixed, $rawline) if ($fix); + + if ($rawline=~/^\+\+\+\s+(\S+)/) { + $setup_docs = 0; + if ($1 =~ m@Documentation/admin-guide/kernel-parameters.rst$@) { + $setup_docs = 1; + } + #next; + } + if ($rawline =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) { + $realline=$1-1; + if (defined $2) { + $realcnt=$3+1; + } else { + $realcnt=1+1; + } + $in_comment = 0; + + # Guestimate if this is a continuing comment. Run + # the context looking for a comment "edge". If this + # edge is a close comment then we must be in a comment + # at context start. + my $edge; + my $cnt = $realcnt; + for (my $ln = $linenr + 1; $cnt > 0; $ln++) { + next if (defined $rawlines[$ln - 1] && + $rawlines[$ln - 1] =~ /^-/); + $cnt--; + #print "RAW<$rawlines[$ln - 1]>\n"; + last if (!defined $rawlines[$ln - 1]); + if ($rawlines[$ln - 1] =~ m@(/\*|\*/)@ && + $rawlines[$ln - 1] !~ m@"[^"]*(?:/\*|\*/)[^"]*"@) { + ($edge) = $1; + last; + } + } + if (defined $edge && $edge eq '*/') { + $in_comment = 1; + } + + # Guestimate if this is a continuing comment. If this + # is the start of a diff block and this line starts + # ' *' then it is very likely a comment. + if (!defined $edge && + $rawlines[$linenr] =~ m@^.\s*(?:\*\*+| \*)(?:\s|$)@) + { + $in_comment = 1; + } + + ##print "COMMENT:$in_comment edge<$edge> $rawline\n"; + sanitise_line_reset($in_comment); + + } elsif ($realcnt && $rawline =~ /^(?:\+| |$)/) { + # Standardise the strings and chars within the input to + # simplify matching -- only bother with positive lines. + $line = sanitise_line($rawline); + } + push(@lines, $line); + + if ($realcnt > 1) { + $realcnt-- if ($line =~ /^(?:\+| |$)/); + } else { + $realcnt = 0; + } + + #print "==>$rawline\n"; + #print "-->$line\n"; + + if ($setup_docs && $line =~ /^\+/) { + push(@setup_docs, $line); + } + } + + $prefix = ''; + + $realcnt = 0; + $linenr = 0; + $fixlinenr = -1; + foreach my $line (@lines) { + $linenr++; + $fixlinenr++; + my $sline = $line; #copy of $line + $sline =~ s/$;/ /g; #with comments as spaces + + my $rawline = $rawlines[$linenr - 1]; + +# check if it's a mode change, rename or start of a patch + if (!$in_commit_log && + ($line =~ /^ mode change [0-7]+ => [0-7]+ \S+\s*$/ || + ($line =~ /^rename (?:from|to) \S+\s*$/ || + $line =~ /^diff --git a\/[\w\/\.\_\-]+ b\/\S+\s*$/))) { + $is_patch = 1; + } + +#extract the line range in the file after the patch is applied + if (!$in_commit_log && + $line =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@(.*)/) { + my $context = $4; + $is_patch = 1; + $first_line = $linenr + 1; + $realline=$1-1; + if (defined $2) { + $realcnt=$3+1; + } else { + $realcnt=1+1; + } + annotate_reset(); + $prev_values = 'E'; + + %suppress_ifbraces = (); + %suppress_whiletrailers = (); + %suppress_export = (); + $suppress_statement = 0; + if ($context =~ /\b(\w+)\s*\(/) { + $context_function = $1; + } else { + undef $context_function; + } + next; + +# track the line number as we move through the hunk, note that +# new versions of GNU diff omit the leading space on completely +# blank context lines so we need to count that too. + } elsif ($line =~ /^( |\+|$)/) { + $realline++; + $realcnt-- if ($realcnt != 0); + + # Measure the line length and indent. + ($length, $indent) = line_stats($rawline); + + # Track the previous line. + ($prevline, $stashline) = ($stashline, $line); + ($previndent, $stashindent) = ($stashindent, $indent); + ($prevrawline, $stashrawline) = ($stashrawline, $rawline); + + #warn "line<$line>\n"; + + } elsif ($realcnt == 1) { + $realcnt--; + } + + my $hunk_line = ($realcnt != 0); + + $here = "#$linenr: " if (!$file); + $here = "#$realline: " if ($file); + + my $found_file = 0; + # extract the filename as it passes + if ($line =~ /^diff --git.*?(\S+)$/) { + $realfile = $1; + $realfile =~ s@^([^/]*)/@@ if (!$file); + $in_commit_log = 0; + $found_file = 1; + } elsif ($line =~ /^\+\+\+\s+(\S+)/) { + $realfile = $1; + $realfile =~ s@^([^/]*)/@@ if (!$file); + $in_commit_log = 0; + + $p1_prefix = $1; + if (!$file && $tree && $p1_prefix ne '' && + -e "$root/$p1_prefix") { + WARN("PATCH_PREFIX", + "patch prefix '$p1_prefix' exists, appears to be a -p0 patch\n"); + } + + if ($realfile =~ m@^include/asm/@) { + ERROR("MODIFIED_INCLUDE_ASM", + "do not modify files in include/asm, change architecture specific files in include/asm-\n" . "$here$rawline\n"); + } + $found_file = 1; + } + +#make up the handle for any error we report on this line + if ($showfile) { + $prefix = "$realfile:$realline: " + } elsif ($emacs) { + if ($file) { + $prefix = "$filename:$realline: "; + } else { + $prefix = "$filename:$linenr: "; + } + } + + if ($found_file) { + if (is_maintained_obsolete($realfile)) { + WARN("OBSOLETE", + "$realfile is marked as 'obsolete' in the MAINTAINERS hierarchy. No unnecessary modifications please.\n"); + } + if ($realfile =~ m@^(?:drivers/net/|net/|drivers/staging/)@) { + $check = 1; + } else { + $check = $check_orig; + } + $checklicenseline = 1; + + if ($realfile !~ /^MAINTAINERS/) { + my $last_binding_patch = $is_binding_patch; + + $is_binding_patch = () = $realfile =~ m@^(?:Documentation/devicetree/|include/dt-bindings/)@; + + if (($last_binding_patch != -1) && + ($last_binding_patch ^ $is_binding_patch)) { + WARN("DT_SPLIT_BINDING_PATCH", + "DT binding docs and includes should be a separate patch. See: Documentation/devicetree/bindings/submitting-patches.txt\n"); + } + } + + next; + } + + $here .= "FILE: $realfile:$realline:" if ($realcnt != 0); + + my $hereline = "$here\n$rawline\n"; + my $herecurr = "$here\n$rawline\n"; + my $hereprev = "$here\n$prevrawline\n$rawline\n"; + + $cnt_lines++ if ($realcnt != 0); + +# Verify the existence of a commit log if appropriate +# 2 is used because a $signature is counted in $commit_log_lines + if ($in_commit_log) { + if ($line !~ /^\s*$/) { + $commit_log_lines++; #could be a $signature + } + } elsif ($has_commit_log && $commit_log_lines < 2) { + WARN("COMMIT_MESSAGE", + "Missing commit description - Add an appropriate one\n"); + $commit_log_lines = 2; #warn only once + } + +# Check if the commit log has what seems like a diff which can confuse patch + if ($in_commit_log && !$commit_log_has_diff && + (($line =~ m@^\s+diff\b.*a/[\w/]+@ && + $line =~ m@^\s+diff\b.*a/([\w/]+)\s+b/$1\b@) || + $line =~ m@^\s*(?:\-\-\-\s+a/|\+\+\+\s+b/)@ || + $line =~ m/^\s*\@\@ \-\d+,\d+ \+\d+,\d+ \@\@/)) { + ERROR("DIFF_IN_COMMIT_MSG", + "Avoid using diff content in the commit message - patch(1) might not work\n" . $herecurr); + $commit_log_has_diff = 1; + } + +# Check for incorrect file permissions + if ($line =~ /^new (file )?mode.*[7531]\d{0,2}$/) { + my $permhere = $here . "FILE: $realfile\n"; + if ($realfile !~ m@scripts/@ && + $realfile !~ /\.(py|pl|awk|sh)$/) { + ERROR("EXECUTE_PERMISSIONS", + "do not set execute permissions for source files\n" . $permhere); + } + } + +# Check the patch for a From: + if (decode("MIME-Header", $line) =~ /^From:\s*(.*)/) { + $author = $1; + $author = encode("utf8", $author) if ($line =~ /=\?utf-8\?/i); + $author =~ s/"//g; + } + +# Check the patch for a signoff: + if ($line =~ /^\s*signed-off-by:/i) { + $signoff++; + $in_commit_log = 0; + if ($author ne '') { + my $l = $line; + $l =~ s/"//g; + if ($l =~ /^\s*signed-off-by:\s*\Q$author\E/i) { + $authorsignoff = 1; + } + } + } + +# Check if MAINTAINERS is being updated. If so, there's probably no need to +# emit the "does MAINTAINERS need updating?" message on file add/move/delete + if ($line =~ /^\s*MAINTAINERS\s*\|/) { + $reported_maintainer_file = 1; + } + +# Check signature styles + if (!$in_header_lines && + $line =~ /^(\s*)([a-z0-9_-]+by:|$signature_tags)(\s*)(.*)/i) { + my $space_before = $1; + my $sign_off = $2; + my $space_after = $3; + my $email = $4; + my $ucfirst_sign_off = ucfirst(lc($sign_off)); + + if ($sign_off !~ /$signature_tags/) { + WARN("BAD_SIGN_OFF", + "Non-standard signature: $sign_off\n" . $herecurr); + } + if (defined $space_before && $space_before ne "") { + if (WARN("BAD_SIGN_OFF", + "Do not use whitespace before $ucfirst_sign_off\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] = + "$ucfirst_sign_off $email"; + } + } + if ($sign_off =~ /-by:$/i && $sign_off ne $ucfirst_sign_off) { + if (WARN("BAD_SIGN_OFF", + "'$ucfirst_sign_off' is the preferred signature form\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] = + "$ucfirst_sign_off $email"; + } + + } + if (!defined $space_after || $space_after ne " ") { + if (WARN("BAD_SIGN_OFF", + "Use a single space after $ucfirst_sign_off\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] = + "$ucfirst_sign_off $email"; + } + } + + my ($email_name, $email_address, $comment) = parse_email($email); + my $suggested_email = format_email(($email_name, $email_address)); + if ($suggested_email eq "") { + ERROR("BAD_SIGN_OFF", + "Unrecognized email address: '$email'\n" . $herecurr); + } else { + my $dequoted = $suggested_email; + $dequoted =~ s/^"//; + $dequoted =~ s/" $comment" ne $email && + "$suggested_email$comment" ne $email) { + WARN("BAD_SIGN_OFF", + "email address '$email' might be better as '$suggested_email$comment'\n" . $herecurr); + } + } + +# Check for duplicate signatures + my $sig_nospace = $line; + $sig_nospace =~ s/\s//g; + $sig_nospace = lc($sig_nospace); + if (defined $signatures{$sig_nospace}) { + WARN("BAD_SIGN_OFF", + "Duplicate signature\n" . $herecurr); + } else { + $signatures{$sig_nospace} = 1; + } + } + +# Check email subject for common tools that don't need to be mentioned + if ($in_header_lines && + $line =~ /^Subject:.*\b(?:checkpatch|sparse|smatch)\b[^:]/i) { + WARN("EMAIL_SUBJECT", + "A patch subject line should describe the change not the tool that found it\n" . $herecurr); + } + +# Check for unwanted Gerrit info + if ($in_commit_log && $line =~ /^\s*change-id:/i) { + ERROR("GERRIT_CHANGE_ID", + "Remove Gerrit Change-Id's before submitting upstream.\n" . $herecurr); + } + +# Check if the commit log is in a possible stack dump + if ($in_commit_log && !$commit_log_possible_stack_dump && + ($line =~ /^\s*(?:WARNING:|BUG:)/ || + $line =~ /^\s*\[\s*\d+\.\d{6,6}\s*\]/ || + # timestamp + $line =~ /^\s*\[\<[0-9a-fA-F]{8,}\>\]/)) { + # stack dump address + $commit_log_possible_stack_dump = 1; + } + +# Check for line lengths > 75 in commit log, warn once + if ($in_commit_log && !$commit_log_long_line && + length($line) > 75 && + !($line =~ /^\s*[a-zA-Z0-9_\/\.]+\s+\|\s+\d+/ || + # file delta changes + $line =~ /^\s*(?:[\w\.\-]+\/)++[\w\.\-]+:/ || + # filename then : + $line =~ /^\s*(?:Fixes:|Link:)/i || + # A Fixes: or Link: line + $commit_log_possible_stack_dump)) { + WARN("COMMIT_LOG_LONG_LINE", + "Possible unwrapped commit description (prefer a maximum 75 chars per line)\n" . $herecurr); + $commit_log_long_line = 1; + } + +# Reset possible stack dump if a blank line is found + if ($in_commit_log && $commit_log_possible_stack_dump && + $line =~ /^\s*$/) { + $commit_log_possible_stack_dump = 0; + } + +# Check for git id commit length and improperly formed commit descriptions + if ($in_commit_log && !$commit_log_possible_stack_dump && + $line !~ /^\s*(?:Link|Patchwork|http|https|BugLink):/i && + $line !~ /^This reverts commit [0-9a-f]{7,40}/ && + ($line =~ /\bcommit\s+[0-9a-f]{5,}\b/i || + ($line =~ /(?:\s|^)[0-9a-f]{12,40}(?:[\s"'\(\[]|$)/i && + $line !~ /[\<\[][0-9a-f]{12,40}[\>\]]/i && + $line !~ /\bfixes:\s*[0-9a-f]{12,40}/i))) { + my $init_char = "c"; + my $orig_commit = ""; + my $short = 1; + my $long = 0; + my $case = 1; + my $space = 1; + my $hasdesc = 0; + my $hasparens = 0; + my $id = '0123456789ab'; + my $orig_desc = "commit description"; + my $description = ""; + + if ($line =~ /\b(c)ommit\s+([0-9a-f]{5,})\b/i) { + $init_char = $1; + $orig_commit = lc($2); + } elsif ($line =~ /\b([0-9a-f]{12,40})\b/i) { + $orig_commit = lc($1); + } + + $short = 0 if ($line =~ /\bcommit\s+[0-9a-f]{12,40}/i); + $long = 1 if ($line =~ /\bcommit\s+[0-9a-f]{41,}/i); + $space = 0 if ($line =~ /\bcommit [0-9a-f]/i); + $case = 0 if ($line =~ /\b[Cc]ommit\s+[0-9a-f]{5,40}[^A-F]/); + if ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)"\)/i) { + $orig_desc = $1; + $hasparens = 1; + } elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s*$/i && + defined $rawlines[$linenr] && + $rawlines[$linenr] =~ /^\s*\("([^"]+)"\)/) { + $orig_desc = $1; + $hasparens = 1; + } elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("[^"]+$/i && + defined $rawlines[$linenr] && + $rawlines[$linenr] =~ /^\s*[^"]+"\)/) { + $line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)$/i; + $orig_desc = $1; + $rawlines[$linenr] =~ /^\s*([^"]+)"\)/; + $orig_desc .= " " . $1; + $hasparens = 1; + } + + ($id, $description) = git_commit_info($orig_commit, + $id, $orig_desc); + + if (defined($id) && + ($short || $long || $space || $case || ($orig_desc ne $description) || !$hasparens)) { + ERROR("GIT_COMMIT_ID", + "Please use git commit description style 'commit <12+ chars of sha1> (\"\")' - ie: '${init_char}ommit $id (\"$description\")'\n" . $herecurr); + } + } + +# Check for added, moved or deleted files + if (!$reported_maintainer_file && !$in_commit_log && + ($line =~ /^(?:new|deleted) file mode\s*\d+\s*$/ || + $line =~ /^rename (?:from|to) [\w\/\.\-]+\s*$/ || + ($line =~ /\{\s*([\w\/\.\-]*)\s*\=\>\s*([\w\/\.\-]*)\s*\}/ && + (defined($1) || defined($2))))) { + $is_patch = 1; + $reported_maintainer_file = 1; + WARN("FILE_PATH_CHANGES", + "added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr); + } + +# Check for wrappage within a valid hunk of the file + if ($realcnt != 0 && $line !~ m{^(?:\+|-| |\\ No newline|$)}) { + ERROR("CORRUPTED_PATCH", + "patch seems to be corrupt (line wrapped?)\n" . + $herecurr) if (!$emitted_corrupt++); + } + +# UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php + if (($realfile =~ /^$/ || $line =~ /^\+/) && + $rawline !~ m/^$UTF8*$/) { + my ($utf8_prefix) = ($rawline =~ /^($UTF8*)/); + + my $blank = copy_spacing($rawline); + my $ptr = substr($blank, 0, length($utf8_prefix)) . "^"; + my $hereptr = "$hereline$ptr\n"; + + CHK("INVALID_UTF8", + "Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr); + } + +# Check if it's the start of a commit log +# (not a header line and we haven't seen the patch filename) + if ($in_header_lines && $realfile =~ /^$/ && + !($rawline =~ /^\s+(?:\S|$)/ || + $rawline =~ /^(?:commit\b|from\b|[\w-]+:)/i)) { + $in_header_lines = 0; + $in_commit_log = 1; + $has_commit_log = 1; + } + +# Check if there is UTF-8 in a commit log when a mail header has explicitly +# declined it, i.e defined some charset where it is missing. + if ($in_header_lines && + $rawline =~ /^Content-Type:.+charset="(.+)".*$/ && + $1 !~ /utf-8/i) { + $non_utf8_charset = 1; + } + + if ($in_commit_log && $non_utf8_charset && $realfile =~ /^$/ && + $rawline =~ /$NON_ASCII_UTF8/) { + WARN("UTF8_BEFORE_PATCH", + "8-bit UTF-8 used in possible commit log\n" . $herecurr); + } + +# Check for absolute kernel paths in commit message + if ($tree && $in_commit_log) { + while ($line =~ m{(?:^|\s)(/\S*)}g) { + my $file = $1; + + if ($file =~ m{^(.*?)(?::\d+)+:?$} && + check_absolute_file($1, $herecurr)) { + # + } else { + check_absolute_file($file, $herecurr); + } + } + } + +# Check for various typo / spelling mistakes + if (defined($misspellings) && + ($in_commit_log || $line =~ /^(?:\+|Subject:)/i)) { + while ($rawline =~ /(?:^|[^a-z@])($misspellings)(?:\b|$|[^a-z@])/gi) { + my $typo = $1; + my $typo_fix = $spelling_fix{lc($typo)}; + $typo_fix = ucfirst($typo_fix) if ($typo =~ /^[A-Z]/); + $typo_fix = uc($typo_fix) if ($typo =~ /^[A-Z]+$/); + my $msg_level = \&WARN; + $msg_level = \&CHK if ($file); + if (&{$msg_level}("TYPO_SPELLING", + "'$typo' may be misspelled - perhaps '$typo_fix'?\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/(^|[^A-Za-z@])($typo)($|[^A-Za-z@])/$1$typo_fix$3/; + } + } + } + +# ignore non-hunk lines and lines being removed + next if (!$hunk_line || $line =~ /^-/); + +#trailing whitespace + if ($line =~ /^\+.*\015/) { + my $herevet = "$here\n" . cat_vet($rawline) . "\n"; + if (ERROR("DOS_LINE_ENDINGS", + "DOS line endings\n" . $herevet) && + $fix) { + $fixed[$fixlinenr] =~ s/[\s\015]+$//; + } + } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) { + my $herevet = "$here\n" . cat_vet($rawline) . "\n"; + if (ERROR("TRAILING_WHITESPACE", + "trailing whitespace\n" . $herevet) && + $fix) { + $fixed[$fixlinenr] =~ s/\s+$//; + } + + $rpt_cleaners = 1; + } + +# Check for FSF mailing addresses. + if ($rawline =~ /\bwrite to the Free/i || + $rawline =~ /\b675\s+Mass\s+Ave/i || + $rawline =~ /\b59\s+Temple\s+Pl/i || + $rawline =~ /\b51\s+Franklin\s+St/i) { + my $herevet = "$here\n" . cat_vet($rawline) . "\n"; + my $msg_level = \&ERROR; + $msg_level = \&CHK if ($file); + &{$msg_level}("FSF_MAILING_ADDRESS", + "Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.\n" . $herevet) + } + +# check for Kconfig help text having a real description +# Only applies when adding the entry originally, after that we do not have +# sufficient context to determine whether it is indeed long enough. + if ($realfile =~ /Kconfig/ && + # 'choice' is usually the last thing on the line (though + # Kconfig supports named choices), so use a word boundary + # (\b) rather than a whitespace character (\s) + $line =~ /^\+\s*(?:config|menuconfig|choice)\b/) { + my $length = 0; + my $cnt = $realcnt; + my $ln = $linenr + 1; + my $f; + my $is_start = 0; + my $is_end = 0; + for (; $cnt > 0 && defined $lines[$ln - 1]; $ln++) { + $f = $lines[$ln - 1]; + $cnt-- if ($lines[$ln - 1] !~ /^-/); + $is_end = $lines[$ln - 1] =~ /^\+/; + + next if ($f =~ /^-/); + last if (!$file && $f =~ /^\@\@/); + + if ($lines[$ln - 1] =~ /^\+\s*(?:bool|tristate|prompt)\s*["']/) { + $is_start = 1; + } elsif ($lines[$ln - 1] =~ /^\+\s*(?:help|---help---)\s*$/) { + if ($lines[$ln - 1] =~ "---help---") { + WARN("CONFIG_DESCRIPTION", + "prefer 'help' over '---help---' for new help texts\n" . $herecurr); + } + $length = -1; + } + + $f =~ s/^.//; + $f =~ s/#.*//; + $f =~ s/^\s+//; + next if ($f =~ /^$/); + + # This only checks context lines in the patch + # and so hopefully shouldn't trigger false + # positives, even though some of these are + # common words in help texts + if ($f =~ /^\s*(?:config|menuconfig|choice|endchoice| + if|endif|menu|endmenu|source)\b/x) { + $is_end = 1; + last; + } + $length++; + } + if ($is_start && $is_end && $length < $min_conf_desc_length) { + WARN("CONFIG_DESCRIPTION", + "please write a paragraph that describes the config symbol fully\n" . $herecurr); + } + #print "is_start<$is_start> is_end<$is_end> length<$length>\n"; + } + +# check for MAINTAINERS entries that don't have the right form + if ($realfile =~ /^MAINTAINERS$/ && + $rawline =~ /^\+[A-Z]:/ && + $rawline !~ /^\+[A-Z]:\t\S/) { + if (WARN("MAINTAINERS_STYLE", + "MAINTAINERS entries use one tab after TYPE:\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/^(\+[A-Z]):\s*/$1:\t/; + } + } + +# discourage the use of boolean for type definition attributes of Kconfig options + if ($realfile =~ /Kconfig/ && + $line =~ /^\+\s*\bboolean\b/) { + WARN("CONFIG_TYPE_BOOLEAN", + "Use of boolean is deprecated, please use bool instead.\n" . $herecurr); + } + + if (($realfile =~ /Makefile.*/ || $realfile =~ /Kbuild.*/) && + ($line =~ /\+(EXTRA_[A-Z]+FLAGS).*/)) { + my $flag = $1; + my $replacement = { + 'EXTRA_AFLAGS' => 'asflags-y', + 'EXTRA_CFLAGS' => 'ccflags-y', + 'EXTRA_CPPFLAGS' => 'cppflags-y', + 'EXTRA_LDFLAGS' => 'ldflags-y', + }; + + WARN("DEPRECATED_VARIABLE", + "Use of $flag is deprecated, please use \`$replacement->{$flag} instead.\n" . $herecurr) if ($replacement->{$flag}); + } + +# check for DT compatible documentation + if (defined $root && + (($realfile =~ /\.dtsi?$/ && $line =~ /^\+\s*compatible\s*=\s*\"/) || + ($realfile =~ /\.[ch]$/ && $line =~ /^\+.*\.compatible\s*=\s*\"/))) { + + my @compats = $rawline =~ /\"([a-zA-Z0-9\-\,\.\+_]+)\"/g; + + my $dt_path = $root . "/Documentation/devicetree/bindings/"; + my $vp_file = $dt_path . "vendor-prefixes.txt"; + + foreach my $compat (@compats) { + my $compat2 = $compat; + $compat2 =~ s/\,[a-zA-Z0-9]*\-/\,<\.\*>\-/; + my $compat3 = $compat; + $compat3 =~ s/\,([a-z]*)[0-9]*\-/\,$1<\.\*>\-/; + `grep -Erq "$compat|$compat2|$compat3" $dt_path`; + if ( $? >> 8 ) { + WARN("UNDOCUMENTED_DT_STRING", + "DT compatible string \"$compat\" appears un-documented -- check $dt_path\n" . $herecurr); + } + + next if $compat !~ /^([a-zA-Z0-9\-]+)\,/; + my $vendor = $1; + `grep -Eq "^$vendor\\b" $vp_file`; + if ( $? >> 8 ) { + WARN("UNDOCUMENTED_DT_STRING", + "DT compatible string vendor \"$vendor\" appears un-documented -- check $vp_file\n" . $herecurr); + } + } + } + +# check for using SPDX license tag at beginning of files + if ($realline == $checklicenseline) { + if ($rawline =~ /^[ \+]\s*\#\!\s*\//) { + $checklicenseline = 2; + } elsif ($rawline =~ /^\+/) { + my $comment = ""; + if ($realfile =~ /\.(h|s|S)$/) { + $comment = '/*'; + } elsif ($realfile =~ /\.(c|dts|dtsi)$/) { + $comment = '//'; + } elsif (($checklicenseline == 2) || $realfile =~ /\.(sh|pl|py|awk|tc)$/) { + $comment = '#'; + } elsif ($realfile =~ /\.rst$/) { + $comment = '..'; + } + + if ($comment !~ /^$/ && + $rawline !~ /^\+\Q$comment\E SPDX-License-Identifier: /) { + WARN("SPDX_LICENSE_TAG", + "Missing or malformed SPDX-License-Identifier tag in line $checklicenseline\n" . $herecurr); + } elsif ($rawline =~ /(SPDX-License-Identifier: .*)/) { + my $spdx_license = $1; + if (!is_SPDX_License_valid($spdx_license)) { + WARN("SPDX_LICENSE_TAG", + "'$spdx_license' is not supported in LICENSES/...\n" . $herecurr); + } + } + } + } + +# check we are in a valid source file if not then ignore this hunk + next if ($realfile !~ /\.(h|c|s|S|sh|dtsi|dts)$/); + +# line length limit (with some exclusions) +# +# There are a few types of lines that may extend beyond $max_line_length: +# logging functions like pr_info that end in a string +# lines with a single string +# #defines that are a single string +# lines with an RFC3986 like URL +# +# There are 3 different line length message types: +# LONG_LINE_COMMENT a comment starts before but extends beyond $max_line_length +# LONG_LINE_STRING a string starts before but extends beyond $max_line_length +# LONG_LINE all other lines longer than $max_line_length +# +# if LONG_LINE is ignored, the other 2 types are also ignored +# + + if ($line =~ /^\+/ && $length > $max_line_length) { + my $msg_type = "LONG_LINE"; + + # Check the allowed long line types first + + # logging functions that end in a string that starts + # before $max_line_length + if ($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(?:KERN_\S+\s*|[^"]*))?($String\s*(?:|,|\)\s*;)\s*)$/ && + length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) { + $msg_type = ""; + + # lines with only strings (w/ possible termination) + # #defines with only strings + } elsif ($line =~ /^\+\s*$String\s*(?:\s*|,|\)\s*;)\s*$/ || + $line =~ /^\+\s*#\s*define\s+\w+\s+$String$/) { + $msg_type = ""; + + # More special cases + } elsif ($line =~ /^\+.*\bEFI_GUID\s*\(/ || + $line =~ /^\+\s*(?:\w+)?\s*DEFINE_PER_CPU/) { + $msg_type = ""; + + # URL ($rawline is used in case the URL is in a comment) + } elsif ($rawline =~ /^\+.*\b[a-z][\w\.\+\-]*:\/\/\S+/i) { + $msg_type = ""; + + # Otherwise set the alternate message types + + # a comment starts before $max_line_length + } elsif ($line =~ /($;[\s$;]*)$/ && + length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) { + $msg_type = "LONG_LINE_COMMENT" + + # a quoted string starts before $max_line_length + } elsif ($sline =~ /\s*($String(?:\s*(?:\\|,\s*|\)\s*;\s*))?)$/ && + length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) { + $msg_type = "LONG_LINE_STRING" + } + + if ($msg_type ne "" && + (show_type("LONG_LINE") || show_type($msg_type))) { + WARN($msg_type, + "line over $max_line_length characters\n" . $herecurr); + } + } + +# check for adding lines without a newline. + if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) { + WARN("MISSING_EOF_NEWLINE", + "adding a line without newline at end of file\n" . $herecurr); + } + +# check we are in a valid source file C or perl if not then ignore this hunk + next if ($realfile !~ /\.(h|c|pl|dtsi|dts)$/); + +# at the beginning of a line any tabs must come first and anything +# more than 8 must use tabs. + if ($rawline =~ /^\+\s* \t\s*\S/ || + $rawline =~ /^\+\s* \s*/) { + my $herevet = "$here\n" . cat_vet($rawline) . "\n"; + $rpt_cleaners = 1; + if (ERROR("CODE_INDENT", + "code indent should use tabs where possible\n" . $herevet) && + $fix) { + $fixed[$fixlinenr] =~ s/^\+([ \t]+)/"\+" . tabify($1)/e; + } + } + +# check for space before tabs. + if ($rawline =~ /^\+/ && $rawline =~ / \t/) { + my $herevet = "$here\n" . cat_vet($rawline) . "\n"; + if (WARN("SPACE_BEFORE_TAB", + "please, no space before tabs\n" . $herevet) && + $fix) { + while ($fixed[$fixlinenr] =~ + s/(^\+.*) {8,8}\t/$1\t\t/) {} + while ($fixed[$fixlinenr] =~ + s/(^\+.*) +\t/$1\t/) {} + } + } + +# check for assignments on the start of a line + if ($sline =~ /^\+\s+($Assignment)[^=]/) { + CHK("ASSIGNMENT_CONTINUATIONS", + "Assignment operator '$1' should be on the previous line\n" . $hereprev); + } + +# check for && or || at the start of a line + if ($rawline =~ /^\+\s*(&&|\|\|)/) { + CHK("LOGICAL_CONTINUATIONS", + "Logical continuations should be on the previous line\n" . $hereprev); + } + +# check indentation starts on a tab stop + if ($perl_version_ok && + $sline =~ /^\+\t+( +)(?:$c90_Keywords\b|\{\s*$|\}\s*(?:else\b|while\b|\s*$)|$Declare\s*$Ident\s*[;=])/) { + my $indent = length($1); + if ($indent % 8) { + if (WARN("TABSTOP", + "Statements should start on a tabstop\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s@(^\+\t+) +@$1 . "\t" x ($indent/8)@e; + } + } + } + +# check multi-line statement indentation matches previous line + if ($perl_version_ok && + $prevline =~ /^\+([ \t]*)((?:$c90_Keywords(?:\s+if)\s*)|(?:$Declare\s*)?(?:$Ident|\(\s*\*\s*$Ident\s*\))\s*|(?:\*\s*)*$Lval\s*=\s*$Ident\s*)\(.*(\&\&|\|\||,)\s*$/) { + $prevline =~ /^\+(\t*)(.*)$/; + my $oldindent = $1; + my $rest = $2; + + my $pos = pos_last_openparen($rest); + if ($pos >= 0) { + $line =~ /^(\+| )([ \t]*)/; + my $newindent = $2; + + my $goodtabindent = $oldindent . + "\t" x ($pos / 8) . + " " x ($pos % 8); + my $goodspaceindent = $oldindent . " " x $pos; + + if ($newindent ne $goodtabindent && + $newindent ne $goodspaceindent) { + + if (CHK("PARENTHESIS_ALIGNMENT", + "Alignment should match open parenthesis\n" . $hereprev) && + $fix && $line =~ /^\+/) { + $fixed[$fixlinenr] =~ + s/^\+[ \t]*/\+$goodtabindent/; + } + } + } + } + +# check for space after cast like "(int) foo" or "(struct foo) bar" +# avoid checking a few false positives: +# "sizeof(<type>)" or "__alignof__(<type>)" +# function pointer declarations like "(*foo)(int) = bar;" +# structure definitions like "(struct foo) { 0 };" +# multiline macros that define functions +# known attributes or the __attribute__ keyword + if ($line =~ /^\+(.*)\(\s*$Type\s*\)([ \t]++)((?![={]|\\$|$Attribute|__attribute__))/ && + (!defined($1) || $1 !~ /\b(?:sizeof|__alignof__)\s*$/)) { + if (CHK("SPACING", + "No space is necessary after a cast\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ + s/(\(\s*$Type\s*\))[ \t]+/$1/; + } + } + +# Block comment styles +# Networking with an initial /* + if ($realfile =~ m@^(drivers/net/|net/)@ && + $prevrawline =~ /^\+[ \t]*\/\*[ \t]*$/ && + $rawline =~ /^\+[ \t]*\*/ && + $realline > 2) { + WARN("NETWORKING_BLOCK_COMMENT_STYLE", + "networking block comments don't use an empty /* line, use /* Comment...\n" . $hereprev); + } + +# Block comments use * on subsequent lines + if ($prevline =~ /$;[ \t]*$/ && #ends in comment + $prevrawline =~ /^\+.*?\/\*/ && #starting /* + $prevrawline !~ /\*\/[ \t]*$/ && #no trailing */ + $rawline =~ /^\+/ && #line is new + $rawline !~ /^\+[ \t]*\*/) { #no leading * + WARN("BLOCK_COMMENT_STYLE", + "Block comments use * on subsequent lines\n" . $hereprev); + } + +# Block comments use */ on trailing lines + if ($rawline !~ m@^\+[ \t]*\*/[ \t]*$@ && #trailing */ + $rawline !~ m@^\+.*/\*.*\*/[ \t]*$@ && #inline /*...*/ + $rawline !~ m@^\+.*\*{2,}/[ \t]*$@ && #trailing **/ + $rawline =~ m@^\+[ \t]*.+\*\/[ \t]*$@) { #non blank */ + WARN("BLOCK_COMMENT_STYLE", + "Block comments use a trailing */ on a separate line\n" . $herecurr); + } + +# Block comment * alignment + if ($prevline =~ /$;[ \t]*$/ && #ends in comment + $line =~ /^\+[ \t]*$;/ && #leading comment + $rawline =~ /^\+[ \t]*\*/ && #leading * + (($prevrawline =~ /^\+.*?\/\*/ && #leading /* + $prevrawline !~ /\*\/[ \t]*$/) || #no trailing */ + $prevrawline =~ /^\+[ \t]*\*/)) { #leading * + my $oldindent; + $prevrawline =~ m@^\+([ \t]*/?)\*@; + if (defined($1)) { + $oldindent = expand_tabs($1); + } else { + $prevrawline =~ m@^\+(.*/?)\*@; + $oldindent = expand_tabs($1); + } + $rawline =~ m@^\+([ \t]*)\*@; + my $newindent = $1; + $newindent = expand_tabs($newindent); + if (length($oldindent) ne length($newindent)) { + WARN("BLOCK_COMMENT_STYLE", + "Block comments should align the * on each line\n" . $hereprev); + } + } + +# check for missing blank lines after struct/union declarations +# with exceptions for various attributes and macros + if ($prevline =~ /^[\+ ]};?\s*$/ && + $line =~ /^\+/ && + !($line =~ /^\+\s*$/ || + $line =~ /^\+\s*EXPORT_SYMBOL/ || + $line =~ /^\+\s*MODULE_/i || + $line =~ /^\+\s*\#\s*(?:end|elif|else)/ || + $line =~ /^\+[a-z_]*init/ || + $line =~ /^\+\s*(?:static\s+)?[A-Z_]*ATTR/ || + $line =~ /^\+\s*DECLARE/ || + $line =~ /^\+\s*builtin_[\w_]*driver/ || + $line =~ /^\+\s*__setup/)) { + if (CHK("LINE_SPACING", + "Please use a blank line after function/struct/union/enum declarations\n" . $hereprev) && + $fix) { + fix_insert_line($fixlinenr, "\+"); + } + } + +# check for multiple consecutive blank lines + if ($prevline =~ /^[\+ ]\s*$/ && + $line =~ /^\+\s*$/ && + $last_blank_line != ($linenr - 1)) { + if (CHK("LINE_SPACING", + "Please don't use multiple blank lines\n" . $hereprev) && + $fix) { + fix_delete_line($fixlinenr, $rawline); + } + + $last_blank_line = $linenr; + } + +# check for missing blank lines after declarations + if ($sline =~ /^\+\s+\S/ && #Not at char 1 + # actual declarations + ($prevline =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ || + # function pointer declarations + $prevline =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ || + # foo bar; where foo is some local typedef or #define + $prevline =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ || + # known declaration macros + $prevline =~ /^\+\s+$declaration_macros/) && + # for "else if" which can look like "$Ident $Ident" + !($prevline =~ /^\+\s+$c90_Keywords\b/ || + # other possible extensions of declaration lines + $prevline =~ /(?:$Compare|$Assignment|$Operators)\s*$/ || + # not starting a section or a macro "\" extended line + $prevline =~ /(?:\{\s*|\\)$/) && + # looks like a declaration + !($sline =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ || + # function pointer declarations + $sline =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ || + # foo bar; where foo is some local typedef or #define + $sline =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ || + # known declaration macros + $sline =~ /^\+\s+$declaration_macros/ || + # start of struct or union or enum + $sline =~ /^\+\s+(?:static\s+)?(?:const\s+)?(?:union|struct|enum|typedef)\b/ || + # start or end of block or continuation of declaration + $sline =~ /^\+\s+(?:$|[\{\}\.\#\"\?\:\(\[])/ || + # bitfield continuation + $sline =~ /^\+\s+$Ident\s*:\s*\d+\s*[,;]/ || + # other possible extensions of declaration lines + $sline =~ /^\+\s+\(?\s*(?:$Compare|$Assignment|$Operators)/) && + # indentation of previous and current line are the same + (($prevline =~ /\+(\s+)\S/) && $sline =~ /^\+$1\S/)) { + if (WARN("LINE_SPACING", + "Missing a blank line after declarations\n" . $hereprev) && + $fix) { + fix_insert_line($fixlinenr, "\+"); + } + } + +# check for spaces at the beginning of a line. +# Exceptions: +# 1) within comments +# 2) indented preprocessor commands +# 3) hanging labels + if ($rawline =~ /^\+ / && $line !~ /^\+ *(?:$;|#|$Ident:)/) { + my $herevet = "$here\n" . cat_vet($rawline) . "\n"; + if (WARN("LEADING_SPACE", + "please, no spaces at the start of a line\n" . $herevet) && + $fix) { + $fixed[$fixlinenr] =~ s/^\+([ \t]+)/"\+" . tabify($1)/e; + } + } + +# check we are in a valid C source file if not then ignore this hunk + next if ($realfile !~ /\.(h|c)$/); + +# check for unusual line ending [ or ( + if ($line =~ /^\+.*([\[\(])\s*$/) { + CHK("OPEN_ENDED_LINE", + "Lines should not end with a '$1'\n" . $herecurr); + } + +# check if this appears to be the start function declaration, save the name + if ($sline =~ /^\+\{\s*$/ && + $prevline =~ /^\+(?:(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*)?($Ident)\(/) { + $context_function = $1; + } + +# check if this appears to be the end of function declaration + if ($sline =~ /^\+\}\s*$/) { + undef $context_function; + } + +# check indentation of any line with a bare else +# (but not if it is a multiple line "if (foo) return bar; else return baz;") +# if the previous line is a break or return and is indented 1 tab more... + if ($sline =~ /^\+([\t]+)(?:}[ \t]*)?else(?:[ \t]*{)?\s*$/) { + my $tabs = length($1) + 1; + if ($prevline =~ /^\+\t{$tabs,$tabs}break\b/ || + ($prevline =~ /^\+\t{$tabs,$tabs}return\b/ && + defined $lines[$linenr] && + $lines[$linenr] !~ /^[ \+]\t{$tabs,$tabs}return/)) { + WARN("UNNECESSARY_ELSE", + "else is not generally useful after a break or return\n" . $hereprev); + } + } + +# check indentation of a line with a break; +# if the previous line is a goto or return and is indented the same # of tabs + if ($sline =~ /^\+([\t]+)break\s*;\s*$/) { + my $tabs = $1; + if ($prevline =~ /^\+$tabs(?:goto|return)\b/) { + WARN("UNNECESSARY_BREAK", + "break is not useful after a goto or return\n" . $hereprev); + } + } + +# check for RCS/CVS revision markers + if ($rawline =~ /^\+.*\$(Revision|Log|Id)(?:\$|)/) { + WARN("CVS_KEYWORD", + "CVS style keyword markers, these will _not_ be updated\n". $herecurr); + } + +# check for old HOTPLUG __dev<foo> section markings + if ($line =~ /\b(__dev(init|exit)(data|const|))\b/) { + WARN("HOTPLUG_SECTION", + "Using $1 is unnecessary\n" . $herecurr); + } + +# Check for potential 'bare' types + my ($stat, $cond, $line_nr_next, $remain_next, $off_next, + $realline_next); +#print "LINE<$line>\n"; + if ($linenr > $suppress_statement && + $realcnt && $sline =~ /.\s*\S/) { + ($stat, $cond, $line_nr_next, $remain_next, $off_next) = + ctx_statement_block($linenr, $realcnt, 0); + $stat =~ s/\n./\n /g; + $cond =~ s/\n./\n /g; + +#print "linenr<$linenr> <$stat>\n"; + # If this statement has no statement boundaries within + # it there is no point in retrying a statement scan + # until we hit end of it. + my $frag = $stat; $frag =~ s/;+\s*$//; + if ($frag !~ /(?:{|;)/) { +#print "skip<$line_nr_next>\n"; + $suppress_statement = $line_nr_next; + } + + # Find the real next line. + $realline_next = $line_nr_next; + if (defined $realline_next && + (!defined $lines[$realline_next - 1] || + substr($lines[$realline_next - 1], $off_next) =~ /^\s*$/)) { + $realline_next++; + } + + my $s = $stat; + $s =~ s/{.*$//s; + + # Ignore goto labels. + if ($s =~ /$Ident:\*$/s) { + + # Ignore functions being called + } elsif ($s =~ /^.\s*$Ident\s*\(/s) { + + } elsif ($s =~ /^.\s*else\b/s) { + + # declarations always start with types + } elsif ($prev_values eq 'E' && $s =~ /^.\s*(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?((?:\s*$Ident)+?)\b(?:\s+$Sparse)?\s*\**\s*(?:$Ident|\(\*[^\)]*\))(?:\s*$Modifier)?\s*(?:;|=|,|\()/s) { + my $type = $1; + $type =~ s/\s+/ /g; + possible($type, "A:" . $s); + + # definitions in global scope can only start with types + } elsif ($s =~ /^.(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?($Ident)\b\s*(?!:)/s) { + possible($1, "B:" . $s); + } + + # any (foo ... *) is a pointer cast, and foo is a type + while ($s =~ /\(($Ident)(?:\s+$Sparse)*[\s\*]+\s*\)/sg) { + possible($1, "C:" . $s); + } + + # Check for any sort of function declaration. + # int foo(something bar, other baz); + # void (*store_gdt)(x86_descr_ptr *); + if ($prev_values eq 'E' && $s =~ /^(.(?:typedef\s*)?(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*(?:\b$Ident|\(\*\s*$Ident\))\s*)\(/s) { + my ($name_len) = length($1); + + my $ctx = $s; + substr($ctx, 0, $name_len + 1, ''); + $ctx =~ s/\)[^\)]*$//; + + for my $arg (split(/\s*,\s*/, $ctx)) { + if ($arg =~ /^(?:const\s+)?($Ident)(?:\s+$Sparse)*\s*\**\s*(:?\b$Ident)?$/s || $arg =~ /^($Ident)$/s) { + + possible($1, "D:" . $s); + } + } + } + + } + +# +# Checks which may be anchored in the context. +# + +# Check for switch () and associated case and default +# statements should be at the same indent. + if ($line=~/\bswitch\s*\(.*\)/) { + my $err = ''; + my $sep = ''; + my @ctx = ctx_block_outer($linenr, $realcnt); + shift(@ctx); + for my $ctx (@ctx) { + my ($clen, $cindent) = line_stats($ctx); + if ($ctx =~ /^\+\s*(case\s+|default:)/ && + $indent != $cindent) { + $err .= "$sep$ctx\n"; + $sep = ''; + } else { + $sep = "[...]\n"; + } + } + if ($err ne '') { + ERROR("SWITCH_CASE_INDENT_LEVEL", + "switch and case should be at the same indent\n$hereline$err"); + } + } + +# if/while/etc brace do not go on next line, unless defining a do while loop, +# or if that brace on the next line is for something else + if ($line =~ /(.*)\b((?:if|while|for|switch|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|do\b|else\b)/ && $line !~ /^.\s*\#/) { + my $pre_ctx = "$1$2"; + + my ($level, @ctx) = ctx_statement_level($linenr, $realcnt, 0); + + if ($line =~ /^\+\t{6,}/) { + WARN("DEEP_INDENTATION", + "Too many leading tabs - consider code refactoring\n" . $herecurr); + } + + my $ctx_cnt = $realcnt - $#ctx - 1; + my $ctx = join("\n", @ctx); + + my $ctx_ln = $linenr; + my $ctx_skip = $realcnt; + + while ($ctx_skip > $ctx_cnt || ($ctx_skip == $ctx_cnt && + defined $lines[$ctx_ln - 1] && + $lines[$ctx_ln - 1] =~ /^-/)) { + ##print "SKIP<$ctx_skip> CNT<$ctx_cnt>\n"; + $ctx_skip-- if (!defined $lines[$ctx_ln - 1] || $lines[$ctx_ln - 1] !~ /^-/); + $ctx_ln++; + } + + #print "realcnt<$realcnt> ctx_cnt<$ctx_cnt>\n"; + #print "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n"; + + if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln - 1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) { + ERROR("OPEN_BRACE", + "that open brace { should be on the previous line\n" . + "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n"); + } + if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ && + $ctx =~ /\)\s*\;\s*$/ && + defined $lines[$ctx_ln - 1]) + { + my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]); + if ($nindent > $indent) { + WARN("TRAILING_SEMICOLON", + "trailing semicolon indicates no statements, indent implies otherwise\n" . + "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n"); + } + } + } + +# Check relative indent for conditionals and blocks. + if ($line =~ /\b(?:(?:if|while|for|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|(?:do|else)\b)/ && $line !~ /^.\s*#/ && $line !~ /\}\s*while\s*/) { + ($stat, $cond, $line_nr_next, $remain_next, $off_next) = + ctx_statement_block($linenr, $realcnt, 0) + if (!defined $stat); + my ($s, $c) = ($stat, $cond); + + substr($s, 0, length($c), ''); + + # remove inline comments + $s =~ s/$;/ /g; + $c =~ s/$;/ /g; + + # Find out how long the conditional actually is. + my @newlines = ($c =~ /\n/gs); + my $cond_lines = 1 + $#newlines; + + # Make sure we remove the line prefixes as we have + # none on the first line, and are going to readd them + # where necessary. + $s =~ s/\n./\n/gs; + while ($s =~ /\n\s+\\\n/) { + $cond_lines += $s =~ s/\n\s+\\\n/\n/g; + } + + # We want to check the first line inside the block + # starting at the end of the conditional, so remove: + # 1) any blank line termination + # 2) any opening brace { on end of the line + # 3) any do (...) { + my $continuation = 0; + my $check = 0; + $s =~ s/^.*\bdo\b//; + $s =~ s/^\s*{//; + if ($s =~ s/^\s*\\//) { + $continuation = 1; + } + if ($s =~ s/^\s*?\n//) { + $check = 1; + $cond_lines++; + } + + # Also ignore a loop construct at the end of a + # preprocessor statement. + if (($prevline =~ /^.\s*#\s*define\s/ || + $prevline =~ /\\\s*$/) && $continuation == 0) { + $check = 0; + } + + my $cond_ptr = -1; + $continuation = 0; + while ($cond_ptr != $cond_lines) { + $cond_ptr = $cond_lines; + + # If we see an #else/#elif then the code + # is not linear. + if ($s =~ /^\s*\#\s*(?:else|elif)/) { + $check = 0; + } + + # Ignore: + # 1) blank lines, they should be at 0, + # 2) preprocessor lines, and + # 3) labels. + if ($continuation || + $s =~ /^\s*?\n/ || + $s =~ /^\s*#\s*?/ || + $s =~ /^\s*$Ident\s*:/) { + $continuation = ($s =~ /^.*?\\\n/) ? 1 : 0; + if ($s =~ s/^.*?\n//) { + $cond_lines++; + } + } + } + + my (undef, $sindent) = line_stats("+" . $s); + my $stat_real = raw_line($linenr, $cond_lines); + + # Check if either of these lines are modified, else + # this is not this patch's fault. + if (!defined($stat_real) || + $stat !~ /^\+/ && $stat_real !~ /^\+/) { + $check = 0; + } + if (defined($stat_real) && $cond_lines > 1) { + $stat_real = "[...]\n$stat_real"; + } + + #print "line<$line> prevline<$prevline> indent<$indent> sindent<$sindent> check<$check> continuation<$continuation> s<$s> cond_lines<$cond_lines> stat_real<$stat_real> stat<$stat>\n"; + + if ($check && $s ne '' && + (($sindent % 8) != 0 || + ($sindent < $indent) || + ($sindent == $indent && + ($s !~ /^\s*(?:\}|\{|else\b)/)) || + ($sindent > $indent + 8))) { + WARN("SUSPECT_CODE_INDENT", + "suspect code indent for conditional statements ($indent, $sindent)\n" . $herecurr . "$stat_real\n"); + } + } + + # Track the 'values' across context and added lines. + my $opline = $line; $opline =~ s/^./ /; + my ($curr_values, $curr_vars) = + annotate_values($opline . "\n", $prev_values); + $curr_values = $prev_values . $curr_values; + if ($dbg_values) { + my $outline = $opline; $outline =~ s/\t/ /g; + print "$linenr > .$outline\n"; + print "$linenr > $curr_values\n"; + print "$linenr > $curr_vars\n"; + } + $prev_values = substr($curr_values, -1); + +#ignore lines not being added + next if ($line =~ /^[^\+]/); + +# check for dereferences that span multiple lines + if ($prevline =~ /^\+.*$Lval\s*(?:\.|->)\s*$/ && + $line =~ /^\+\s*(?!\#\s*(?!define\s+|if))\s*$Lval/) { + $prevline =~ /($Lval\s*(?:\.|->))\s*$/; + my $ref = $1; + $line =~ /^.\s*($Lval)/; + $ref .= $1; + $ref =~ s/\s//g; + WARN("MULTILINE_DEREFERENCE", + "Avoid multiple line dereference - prefer '$ref'\n" . $hereprev); + } + +# check for declarations of signed or unsigned without int + while ($line =~ m{\b($Declare)\s*(?!char\b|short\b|int\b|long\b)\s*($Ident)?\s*[=,;\[\)\(]}g) { + my $type = $1; + my $var = $2; + $var = "" if (!defined $var); + if ($type =~ /^(?:(?:$Storage|$Inline|$Attribute)\s+)*((?:un)?signed)((?:\s*\*)*)\s*$/) { + my $sign = $1; + my $pointer = $2; + + $pointer = "" if (!defined $pointer); + + if (WARN("UNSPECIFIED_INT", + "Prefer '" . trim($sign) . " int" . rtrim($pointer) . "' to bare use of '$sign" . rtrim($pointer) . "'\n" . $herecurr) && + $fix) { + my $decl = trim($sign) . " int "; + my $comp_pointer = $pointer; + $comp_pointer =~ s/\s//g; + $decl .= $comp_pointer; + $decl = rtrim($decl) if ($var eq ""); + $fixed[$fixlinenr] =~ s@\b$sign\s*\Q$pointer\E\s*$var\b@$decl$var@; + } + } + } + +# TEST: allow direct testing of the type matcher. + if ($dbg_type) { + if ($line =~ /^.\s*$Declare\s*$/) { + ERROR("TEST_TYPE", + "TEST: is type\n" . $herecurr); + } elsif ($dbg_type > 1 && $line =~ /^.+($Declare)/) { + ERROR("TEST_NOT_TYPE", + "TEST: is not type ($1 is)\n". $herecurr); + } + next; + } +# TEST: allow direct testing of the attribute matcher. + if ($dbg_attr) { + if ($line =~ /^.\s*$Modifier\s*$/) { + ERROR("TEST_ATTR", + "TEST: is attr\n" . $herecurr); + } elsif ($dbg_attr > 1 && $line =~ /^.+($Modifier)/) { + ERROR("TEST_NOT_ATTR", + "TEST: is not attr ($1 is)\n". $herecurr); + } + next; + } + +# check for initialisation to aggregates open brace on the next line + if ($line =~ /^.\s*{/ && + $prevline =~ /(?:^|[^=])=\s*$/) { + if (ERROR("OPEN_BRACE", + "that open brace { should be on the previous line\n" . $hereprev) && + $fix && $prevline =~ /^\+/ && $line =~ /^\+/) { + fix_delete_line($fixlinenr - 1, $prevrawline); + fix_delete_line($fixlinenr, $rawline); + my $fixedline = $prevrawline; + $fixedline =~ s/\s*=\s*$/ = {/; + fix_insert_line($fixlinenr, $fixedline); + $fixedline = $line; + $fixedline =~ s/^(.\s*)\{\s*/$1/; + fix_insert_line($fixlinenr, $fixedline); + } + } + +# +# Checks which are anchored on the added line. +# + +# check for malformed paths in #include statements (uses RAW line) + if ($rawline =~ m{^.\s*\#\s*include\s+[<"](.*)[">]}) { + my $path = $1; + if ($path =~ m{//}) { + ERROR("MALFORMED_INCLUDE", + "malformed #include filename\n" . $herecurr); + } + if ($path =~ "^uapi/" && $realfile =~ m@\binclude/uapi/@) { + ERROR("UAPI_INCLUDE", + "No #include in ...include/uapi/... should use a uapi/ path prefix\n" . $herecurr); + } + } + +# no C99 // comments + if ($line =~ m{//}) { + if (ERROR("C99_COMMENTS", + "do not use C99 // comments\n" . $herecurr) && + $fix) { + my $line = $fixed[$fixlinenr]; + if ($line =~ /\/\/(.*)$/) { + my $comment = trim($1); + $fixed[$fixlinenr] =~ s@\/\/(.*)$@/\* $comment \*/@; + } + } + } + # Remove C99 comments. + $line =~ s@//.*@@; + $opline =~ s@//.*@@; + +# EXPORT_SYMBOL should immediately follow the thing it is exporting, consider +# the whole statement. +#print "APW <$lines[$realline_next - 1]>\n"; + if (defined $realline_next && + exists $lines[$realline_next - 1] && + !defined $suppress_export{$realline_next} && + ($lines[$realline_next - 1] =~ /EXPORT_SYMBOL.*\((.*)\)/ || + $lines[$realline_next - 1] =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) { + # Handle definitions which produce identifiers with + # a prefix: + # XXX(foo); + # EXPORT_SYMBOL(something_foo); + my $name = $1; + if ($stat =~ /^(?:.\s*}\s*\n)?.([A-Z_]+)\s*\(\s*($Ident)/ && + $name =~ /^${Ident}_$2/) { +#print "FOO C name<$name>\n"; + $suppress_export{$realline_next} = 1; + + } elsif ($stat !~ /(?: + \n.}\s*$| + ^.DEFINE_$Ident\(\Q$name\E\)| + ^.DECLARE_$Ident\(\Q$name\E\)| + ^.LIST_HEAD\(\Q$name\E\)| + ^.(?:$Storage\s+)?$Type\s*\(\s*\*\s*\Q$name\E\s*\)\s*\(| + \b\Q$name\E(?:\s+$Attribute)*\s*(?:;|=|\[|\() + )/x) { +#print "FOO A<$lines[$realline_next - 1]> stat<$stat> name<$name>\n"; + $suppress_export{$realline_next} = 2; + } else { + $suppress_export{$realline_next} = 1; + } + } + if (!defined $suppress_export{$linenr} && + $prevline =~ /^.\s*$/ && + ($line =~ /EXPORT_SYMBOL.*\((.*)\)/ || + $line =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) { +#print "FOO B <$lines[$linenr - 1]>\n"; + $suppress_export{$linenr} = 2; + } + if (defined $suppress_export{$linenr} && + $suppress_export{$linenr} == 2) { + WARN("EXPORT_SYMBOL", + "EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr); + } + +# check for global initialisers. + if ($line =~ /^\+$Type\s*$Ident(?:\s+$Modifier)*\s*=\s*($zero_initializer)\s*;/) { + if (ERROR("GLOBAL_INITIALISERS", + "do not initialise globals to $1\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/(^.$Type\s*$Ident(?:\s+$Modifier)*)\s*=\s*$zero_initializer\s*;/$1;/; + } + } +# check for static initialisers. + if ($line =~ /^\+.*\bstatic\s.*=\s*($zero_initializer)\s*;/) { + if (ERROR("INITIALISED_STATIC", + "do not initialise statics to $1\n" . + $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/(\bstatic\s.*?)\s*=\s*$zero_initializer\s*;/$1;/; + } + } + +# check for misordered declarations of char/short/int/long with signed/unsigned + while ($sline =~ m{(\b$TypeMisordered\b)}g) { + my $tmp = trim($1); + WARN("MISORDERED_TYPE", + "type '$tmp' should be specified in [[un]signed] [short|int|long|long long] order\n" . $herecurr); + } + +# check for unnecessary <signed> int declarations of short/long/long long + while ($sline =~ m{\b($TypeMisordered(\s*\*)*|$C90_int_types)\b}g) { + my $type = trim($1); + next if ($type !~ /\bint\b/); + next if ($type !~ /\b(?:short|long\s+long|long)\b/); + my $new_type = $type; + $new_type =~ s/\b\s*int\s*\b/ /; + $new_type =~ s/\b\s*(?:un)?signed\b\s*/ /; + $new_type =~ s/^const\s+//; + $new_type = "unsigned $new_type" if ($type =~ /\bunsigned\b/); + $new_type = "const $new_type" if ($type =~ /^const\b/); + $new_type =~ s/\s+/ /g; + $new_type = trim($new_type); + if (WARN("UNNECESSARY_INT", + "Prefer '$new_type' over '$type' as the int is unnecessary\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\b\Q$type\E\b/$new_type/; + } + } + +# check for static const char * arrays. + if ($line =~ /\bstatic\s+const\s+char\s*\*\s*(\w+)\s*\[\s*\]\s*=\s*/) { + WARN("STATIC_CONST_CHAR_ARRAY", + "static const char * array should probably be static const char * const\n" . + $herecurr); + } + +# check for initialized const char arrays that should be static const + if ($line =~ /^\+\s*const\s+(char|unsigned\s+char|_*u8|(?:[us]_)?int8_t)\s+\w+\s*\[\s*(?:\w+\s*)?\]\s*=\s*"/) { + if (WARN("STATIC_CONST_CHAR_ARRAY", + "const array should probably be static const\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/(^.\s*)const\b/${1}static const/; + } + } + +# check for static char foo[] = "bar" declarations. + if ($line =~ /\bstatic\s+char\s+(\w+)\s*\[\s*\]\s*=\s*"/) { + WARN("STATIC_CONST_CHAR_ARRAY", + "static char array declaration should probably be static const char\n" . + $herecurr); + } + +# check for const <foo> const where <foo> is not a pointer or array type + if ($sline =~ /\bconst\s+($BasicType)\s+const\b/) { + my $found = $1; + if ($sline =~ /\bconst\s+\Q$found\E\s+const\b\s*\*/) { + WARN("CONST_CONST", + "'const $found const *' should probably be 'const $found * const'\n" . $herecurr); + } elsif ($sline !~ /\bconst\s+\Q$found\E\s+const\s+\w+\s*\[/) { + WARN("CONST_CONST", + "'const $found const' should probably be 'const $found'\n" . $herecurr); + } + } + +# check for non-global char *foo[] = {"bar", ...} declarations. + if ($line =~ /^.\s+(?:static\s+|const\s+)?char\s+\*\s*\w+\s*\[\s*\]\s*=\s*\{/) { + WARN("STATIC_CONST_CHAR_ARRAY", + "char * array declaration might be better as static const\n" . + $herecurr); + } + +# check for sizeof(foo)/sizeof(foo[0]) that could be ARRAY_SIZE(foo) + if ($line =~ m@\bsizeof\s*\(\s*($Lval)\s*\)@) { + my $array = $1; + if ($line =~ m@\b(sizeof\s*\(\s*\Q$array\E\s*\)\s*/\s*sizeof\s*\(\s*\Q$array\E\s*\[\s*0\s*\]\s*\))@) { + my $array_div = $1; + if (WARN("ARRAY_SIZE", + "Prefer ARRAY_SIZE($array)\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\Q$array_div\E/ARRAY_SIZE($array)/; + } + } + } + +# check for function declarations without arguments like "int foo()" + if ($line =~ /(\b$Type\s+$Ident)\s*\(\s*\)/) { + if (ERROR("FUNCTION_WITHOUT_ARGS", + "Bad function definition - $1() should probably be $1(void)\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/(\b($Type)\s+($Ident))\s*\(\s*\)/$2 $3(void)/; + } + } + +# check for new typedefs, only function parameters and sparse annotations +# make sense. + if ($line =~ /\btypedef\s/ && + $line !~ /\btypedef\s+$Type\s*\(\s*\*?$Ident\s*\)\s*\(/ && + $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ && + $line !~ /\b$typeTypedefs\b/ && + $line !~ /\b__bitwise\b/) { + WARN("NEW_TYPEDEFS", + "do not add new typedefs\n" . $herecurr); + } + +# * goes on variable not on type + # (char*[ const]) + while ($line =~ m{(\($NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)\))}g) { + #print "AA<$1>\n"; + my ($ident, $from, $to) = ($1, $2, $2); + + # Should start with a space. + $to =~ s/^(\S)/ $1/; + # Should not end with a space. + $to =~ s/\s+$//; + # '*'s should not have spaces between. + while ($to =~ s/\*\s+\*/\*\*/) { + } + +## print "1: from<$from> to<$to> ident<$ident>\n"; + if ($from ne $to) { + if (ERROR("POINTER_LOCATION", + "\"(foo$from)\" should be \"(foo$to)\"\n" . $herecurr) && + $fix) { + my $sub_from = $ident; + my $sub_to = $ident; + $sub_to =~ s/\Q$from\E/$to/; + $fixed[$fixlinenr] =~ + s@\Q$sub_from\E@$sub_to@; + } + } + } + while ($line =~ m{(\b$NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)($Ident))}g) { + #print "BB<$1>\n"; + my ($match, $from, $to, $ident) = ($1, $2, $2, $3); + + # Should start with a space. + $to =~ s/^(\S)/ $1/; + # Should not end with a space. + $to =~ s/\s+$//; + # '*'s should not have spaces between. + while ($to =~ s/\*\s+\*/\*\*/) { + } + # Modifiers should have spaces. + $to =~ s/(\b$Modifier$)/$1 /; + +## print "2: from<$from> to<$to> ident<$ident>\n"; + if ($from ne $to && $ident !~ /^$Modifier$/) { + if (ERROR("POINTER_LOCATION", + "\"foo${from}bar\" should be \"foo${to}bar\"\n" . $herecurr) && + $fix) { + + my $sub_from = $match; + my $sub_to = $match; + $sub_to =~ s/\Q$from\E/$to/; + $fixed[$fixlinenr] =~ + s@\Q$sub_from\E@$sub_to@; + } + } + } + +# avoid BUG() or BUG_ON() + if ($line =~ /\b(?:BUG|BUG_ON)\b/) { + my $msg_level = \&WARN; + $msg_level = \&CHK if ($file); + &{$msg_level}("AVOID_BUG", + "Avoid crashing the kernel - try using WARN_ON & recovery code rather than BUG() or BUG_ON()\n" . $herecurr); + } + +# avoid LINUX_VERSION_CODE + if ($line =~ /\bLINUX_VERSION_CODE\b/) { + WARN("LINUX_VERSION_CODE", + "LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged\n" . $herecurr); + } + +# check for uses of printk_ratelimit + if ($line =~ /\bprintk_ratelimit\s*\(/) { + WARN("PRINTK_RATELIMITED", + "Prefer printk_ratelimited or pr_<level>_ratelimited to printk_ratelimit\n" . $herecurr); + } + +# printk should use KERN_* levels + if ($line =~ /\bprintk\s*\(\s*(?!KERN_[A-Z]+\b)/) { + WARN("PRINTK_WITHOUT_KERN_LEVEL", + "printk() should include KERN_<LEVEL> facility level\n" . $herecurr); + } + + if ($line =~ /\bprintk\s*\(\s*KERN_([A-Z]+)/) { + my $orig = $1; + my $level = lc($orig); + $level = "warn" if ($level eq "warning"); + my $level2 = $level; + $level2 = "dbg" if ($level eq "debug"); + WARN("PREFER_PR_LEVEL", + "Prefer [subsystem eg: netdev]_$level2([subsystem]dev, ... then dev_$level2(dev, ... then pr_$level(... to printk(KERN_$orig ...\n" . $herecurr); + } + + if ($line =~ /\bpr_warning\s*\(/) { + if (WARN("PREFER_PR_LEVEL", + "Prefer pr_warn(... to pr_warning(...\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ + s/\bpr_warning\b/pr_warn/; + } + } + + if ($line =~ /\bdev_printk\s*\(\s*KERN_([A-Z]+)/) { + my $orig = $1; + my $level = lc($orig); + $level = "warn" if ($level eq "warning"); + $level = "dbg" if ($level eq "debug"); + WARN("PREFER_DEV_LEVEL", + "Prefer dev_$level(... to dev_printk(KERN_$orig, ...\n" . $herecurr); + } + +# ENOSYS means "bad syscall nr" and nothing else. This will have a small +# number of false positives, but assembly files are not checked, so at +# least the arch entry code will not trigger this warning. + if ($line =~ /\bENOSYS\b/) { + WARN("ENOSYS", + "ENOSYS means 'invalid syscall nr' and nothing else\n" . $herecurr); + } + +# function brace can't be on same line, except for #defines of do while, +# or if closed on same line + if ($perl_version_ok && + $sline =~ /$Type\s*$Ident\s*$balanced_parens\s*\{/ && + $sline !~ /\#\s*define\b.*do\s*\{/ && + $sline !~ /}/) { + if (ERROR("OPEN_BRACE", + "open brace '{' following function definitions go on the next line\n" . $herecurr) && + $fix) { + fix_delete_line($fixlinenr, $rawline); + my $fixed_line = $rawline; + $fixed_line =~ /(^..*$Type\s*$Ident\(.*\)\s*){(.*)$/; + my $line1 = $1; + my $line2 = $2; + fix_insert_line($fixlinenr, ltrim($line1)); + fix_insert_line($fixlinenr, "\+{"); + if ($line2 !~ /^\s*$/) { + fix_insert_line($fixlinenr, "\+\t" . trim($line2)); + } + } + } + +# open braces for enum, union and struct go on the same line. + if ($line =~ /^.\s*{/ && + $prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) { + if (ERROR("OPEN_BRACE", + "open brace '{' following $1 go on the same line\n" . $hereprev) && + $fix && $prevline =~ /^\+/ && $line =~ /^\+/) { + fix_delete_line($fixlinenr - 1, $prevrawline); + fix_delete_line($fixlinenr, $rawline); + my $fixedline = rtrim($prevrawline) . " {"; + fix_insert_line($fixlinenr, $fixedline); + $fixedline = $rawline; + $fixedline =~ s/^(.\s*)\{\s*/$1\t/; + if ($fixedline !~ /^\+\s*$/) { + fix_insert_line($fixlinenr, $fixedline); + } + } + } + +# missing space after union, struct or enum definition + if ($line =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident){1,2}[=\{]/) { + if (WARN("SPACING", + "missing space after $1 definition\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ + s/^(.\s*(?:typedef\s+)?(?:enum|union|struct)(?:\s+$Ident){1,2})([=\{])/$1 $2/; + } + } + +# Function pointer declarations +# check spacing between type, funcptr, and args +# canonical declaration is "type (*funcptr)(args...)" + if ($line =~ /^.\s*($Declare)\((\s*)\*(\s*)($Ident)(\s*)\)(\s*)\(/) { + my $declare = $1; + my $pre_pointer_space = $2; + my $post_pointer_space = $3; + my $funcname = $4; + my $post_funcname_space = $5; + my $pre_args_space = $6; + +# the $Declare variable will capture all spaces after the type +# so check it for a missing trailing missing space but pointer return types +# don't need a space so don't warn for those. + my $post_declare_space = ""; + if ($declare =~ /(\s+)$/) { + $post_declare_space = $1; + $declare = rtrim($declare); + } + if ($declare !~ /\*$/ && $post_declare_space =~ /^$/) { + WARN("SPACING", + "missing space after return type\n" . $herecurr); + $post_declare_space = " "; + } + +# unnecessary space "type (*funcptr)(args...)" +# This test is not currently implemented because these declarations are +# equivalent to +# int foo(int bar, ...) +# and this is form shouldn't/doesn't generate a checkpatch warning. +# +# elsif ($declare =~ /\s{2,}$/) { +# WARN("SPACING", +# "Multiple spaces after return type\n" . $herecurr); +# } + +# unnecessary space "type ( *funcptr)(args...)" + if (defined $pre_pointer_space && + $pre_pointer_space =~ /^\s/) { + WARN("SPACING", + "Unnecessary space after function pointer open parenthesis\n" . $herecurr); + } + +# unnecessary space "type (* funcptr)(args...)" + if (defined $post_pointer_space && + $post_pointer_space =~ /^\s/) { + WARN("SPACING", + "Unnecessary space before function pointer name\n" . $herecurr); + } + +# unnecessary space "type (*funcptr )(args...)" + if (defined $post_funcname_space && + $post_funcname_space =~ /^\s/) { + WARN("SPACING", + "Unnecessary space after function pointer name\n" . $herecurr); + } + +# unnecessary space "type (*funcptr) (args...)" + if (defined $pre_args_space && + $pre_args_space =~ /^\s/) { + WARN("SPACING", + "Unnecessary space before function pointer arguments\n" . $herecurr); + } + + if (show_type("SPACING") && $fix) { + $fixed[$fixlinenr] =~ + s/^(.\s*)$Declare\s*\(\s*\*\s*$Ident\s*\)\s*\(/$1 . $declare . $post_declare_space . '(*' . $funcname . ')('/ex; + } + } + +# check for spacing round square brackets; allowed: +# 1. with a type on the left -- int [] a; +# 2. at the beginning of a line for slice initialisers -- [0...10] = 5, +# 3. inside a curly brace -- = { [0...10] = 5 } + while ($line =~ /(.*?\s)\[/g) { + my ($where, $prefix) = ($-[1], $1); + if ($prefix !~ /$Type\s+$/ && + ($where != 0 || $prefix !~ /^.\s+$/) && + $prefix !~ /[{,:]\s+$/) { + if (ERROR("BRACKET_SPACE", + "space prohibited before open square bracket '['\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ + s/^(\+.*?)\s+\[/$1\[/; + } + } + } + +# check for spaces between functions and their parentheses. + while ($line =~ /($Ident)\s+\(/g) { + my $name = $1; + my $ctx_before = substr($line, 0, $-[1]); + my $ctx = "$ctx_before$name"; + + # Ignore those directives where spaces _are_ permitted. + if ($name =~ /^(?: + if|for|while|switch|return|case| + volatile|__volatile__| + __attribute__|format|__extension__| + asm|__asm__)$/x) + { + # cpp #define statements have non-optional spaces, ie + # if there is a space between the name and the open + # parenthesis it is simply not a parameter group. + } elsif ($ctx_before =~ /^.\s*\#\s*define\s*$/) { + + # cpp #elif statement condition may start with a ( + } elsif ($ctx =~ /^.\s*\#\s*elif\s*$/) { + + # If this whole things ends with a type its most + # likely a typedef for a function. + } elsif ($ctx =~ /$Type$/) { + + } else { + if (WARN("SPACING", + "space prohibited between function name and open parenthesis '('\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ + s/\b$name\s+\(/$name\(/; + } + } + } + +# Check operator spacing. + if (!($line=~/\#\s*include/)) { + my $fixed_line = ""; + my $line_fixed = 0; + + my $ops = qr{ + <<=|>>=|<=|>=|==|!=| + \+=|-=|\*=|\/=|%=|\^=|\|=|&=| + =>|->|<<|>>|<|>|=|!|~| + &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|%| + \?:|\?|: + }x; + my @elements = split(/($ops|;)/, $opline); + +## print("element count: <" . $#elements . ">\n"); +## foreach my $el (@elements) { +## print("el: <$el>\n"); +## } + + my @fix_elements = (); + my $off = 0; + + foreach my $el (@elements) { + push(@fix_elements, substr($rawline, $off, length($el))); + $off += length($el); + } + + $off = 0; + + my $blank = copy_spacing($opline); + my $last_after = -1; + + for (my $n = 0; $n < $#elements; $n += 2) { + + my $good = $fix_elements[$n] . $fix_elements[$n + 1]; + +## print("n: <$n> good: <$good>\n"); + + $off += length($elements[$n]); + + # Pick up the preceding and succeeding characters. + my $ca = substr($opline, 0, $off); + my $cc = ''; + if (length($opline) >= ($off + length($elements[$n + 1]))) { + $cc = substr($opline, $off + length($elements[$n + 1])); + } + my $cb = "$ca$;$cc"; + + my $a = ''; + $a = 'V' if ($elements[$n] ne ''); + $a = 'W' if ($elements[$n] =~ /\s$/); + $a = 'C' if ($elements[$n] =~ /$;$/); + $a = 'B' if ($elements[$n] =~ /(\[|\()$/); + $a = 'O' if ($elements[$n] eq ''); + $a = 'E' if ($ca =~ /^\s*$/); + + my $op = $elements[$n + 1]; + + my $c = ''; + if (defined $elements[$n + 2]) { + $c = 'V' if ($elements[$n + 2] ne ''); + $c = 'W' if ($elements[$n + 2] =~ /^\s/); + $c = 'C' if ($elements[$n + 2] =~ /^$;/); + $c = 'B' if ($elements[$n + 2] =~ /^(\)|\]|;)/); + $c = 'O' if ($elements[$n + 2] eq ''); + $c = 'E' if ($elements[$n + 2] =~ /^\s*\\$/); + } else { + $c = 'E'; + } + + my $ctx = "${a}x${c}"; + + my $at = "(ctx:$ctx)"; + + my $ptr = substr($blank, 0, $off) . "^"; + my $hereptr = "$hereline$ptr\n"; + + # Pull out the value of this operator. + my $op_type = substr($curr_values, $off + 1, 1); + + # Get the full operator variant. + my $opv = $op . substr($curr_vars, $off, 1); + + # Ignore operators passed as parameters. + if ($op_type ne 'V' && + $ca =~ /\s$/ && $cc =~ /^\s*[,\)]/) { + +# # Ignore comments +# } elsif ($op =~ /^$;+$/) { + + # ; should have either the end of line or a space or \ after it + } elsif ($op eq ';') { + if ($ctx !~ /.x[WEBC]/ && + $cc !~ /^\\/ && $cc !~ /^;/) { + if (ERROR("SPACING", + "space required after that '$op' $at\n" . $hereptr)) { + $good = $fix_elements[$n] . trim($fix_elements[$n + 1]) . " "; + $line_fixed = 1; + } + } + + # // is a comment + } elsif ($op eq '//') { + + # : when part of a bitfield + } elsif ($opv eq ':B') { + # skip the bitfield test for now + + # No spaces for: + # -> + } elsif ($op eq '->') { + if ($ctx =~ /Wx.|.xW/) { + if (ERROR("SPACING", + "spaces prohibited around that '$op' $at\n" . $hereptr)) { + $good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]); + if (defined $fix_elements[$n + 2]) { + $fix_elements[$n + 2] =~ s/^\s+//; + } + $line_fixed = 1; + } + } + + # , must not have a space before and must have a space on the right. + } elsif ($op eq ',') { + my $rtrim_before = 0; + my $space_after = 0; + if ($ctx =~ /Wx./) { + if (ERROR("SPACING", + "space prohibited before that '$op' $at\n" . $hereptr)) { + $line_fixed = 1; + $rtrim_before = 1; + } + } + if ($ctx !~ /.x[WEC]/ && $cc !~ /^}/) { + if (ERROR("SPACING", + "space required after that '$op' $at\n" . $hereptr)) { + $line_fixed = 1; + $last_after = $n; + $space_after = 1; + } + } + if ($rtrim_before || $space_after) { + if ($rtrim_before) { + $good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]); + } else { + $good = $fix_elements[$n] . trim($fix_elements[$n + 1]); + } + if ($space_after) { + $good .= " "; + } + } + + # '*' as part of a type definition -- reported already. + } elsif ($opv eq '*_') { + #warn "'*' is part of type\n"; + + # unary operators should have a space before and + # none after. May be left adjacent to another + # unary operator, or a cast + } elsif ($op eq '!' || $op eq '~' || + $opv eq '*U' || $opv eq '-U' || + $opv eq '&U' || $opv eq '&&U') { + if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) { + if (ERROR("SPACING", + "space required before that '$op' $at\n" . $hereptr)) { + if ($n != $last_after + 2) { + $good = $fix_elements[$n] . " " . ltrim($fix_elements[$n + 1]); + $line_fixed = 1; + } + } + } + if ($op eq '*' && $cc =~/\s*$Modifier\b/) { + # A unary '*' may be const + + } elsif ($ctx =~ /.xW/) { + if (ERROR("SPACING", + "space prohibited after that '$op' $at\n" . $hereptr)) { + $good = $fix_elements[$n] . rtrim($fix_elements[$n + 1]); + if (defined $fix_elements[$n + 2]) { + $fix_elements[$n + 2] =~ s/^\s+//; + } + $line_fixed = 1; + } + } + + # unary ++ and unary -- are allowed no space on one side. + } elsif ($op eq '++' or $op eq '--') { + if ($ctx !~ /[WEOBC]x[^W]/ && $ctx !~ /[^W]x[WOBEC]/) { + if (ERROR("SPACING", + "space required one side of that '$op' $at\n" . $hereptr)) { + $good = $fix_elements[$n] . trim($fix_elements[$n + 1]) . " "; + $line_fixed = 1; + } + } + if ($ctx =~ /Wx[BE]/ || + ($ctx =~ /Wx./ && $cc =~ /^;/)) { + if (ERROR("SPACING", + "space prohibited before that '$op' $at\n" . $hereptr)) { + $good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]); + $line_fixed = 1; + } + } + if ($ctx =~ /ExW/) { + if (ERROR("SPACING", + "space prohibited after that '$op' $at\n" . $hereptr)) { + $good = $fix_elements[$n] . trim($fix_elements[$n + 1]); + if (defined $fix_elements[$n + 2]) { + $fix_elements[$n + 2] =~ s/^\s+//; + } + $line_fixed = 1; + } + } + + # << and >> may either have or not have spaces both sides + } elsif ($op eq '<<' or $op eq '>>' or + $op eq '&' or $op eq '^' or $op eq '|' or + $op eq '+' or $op eq '-' or + $op eq '*' or $op eq '/' or + $op eq '%') + { + if ($check) { + if (defined $fix_elements[$n + 2] && $ctx !~ /[EW]x[EW]/) { + if (CHK("SPACING", + "spaces preferred around that '$op' $at\n" . $hereptr)) { + $good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " "; + $fix_elements[$n + 2] =~ s/^\s+//; + $line_fixed = 1; + } + } elsif (!defined $fix_elements[$n + 2] && $ctx !~ /Wx[OE]/) { + if (CHK("SPACING", + "space preferred before that '$op' $at\n" . $hereptr)) { + $good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]); + $line_fixed = 1; + } + } + } elsif ($ctx =~ /Wx[^WCE]|[^WCE]xW/) { + if (ERROR("SPACING", + "need consistent spacing around '$op' $at\n" . $hereptr)) { + $good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " "; + if (defined $fix_elements[$n + 2]) { + $fix_elements[$n + 2] =~ s/^\s+//; + } + $line_fixed = 1; + } + } + + # A colon needs no spaces before when it is + # terminating a case value or a label. + } elsif ($opv eq ':C' || $opv eq ':L') { + if ($ctx =~ /Wx./) { + if (ERROR("SPACING", + "space prohibited before that '$op' $at\n" . $hereptr)) { + $good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]); + $line_fixed = 1; + } + } + + # All the others need spaces both sides. + } elsif ($ctx !~ /[EWC]x[CWE]/) { + my $ok = 0; + + # Ignore email addresses <foo@bar> + if (($op eq '<' && + $cc =~ /^\S+\@\S+>/) || + ($op eq '>' && + $ca =~ /<\S+\@\S+$/)) + { + $ok = 1; + } + + # for asm volatile statements + # ignore a colon with another + # colon immediately before or after + if (($op eq ':') && + ($ca =~ /:$/ || $cc =~ /^:/)) { + $ok = 1; + } + + # messages are ERROR, but ?: are CHK + if ($ok == 0) { + my $msg_level = \&ERROR; + $msg_level = \&CHK if (($op eq '?:' || $op eq '?' || $op eq ':') && $ctx =~ /VxV/); + + if (&{$msg_level}("SPACING", + "spaces required around that '$op' $at\n" . $hereptr)) { + $good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " "; + if (defined $fix_elements[$n + 2]) { + $fix_elements[$n + 2] =~ s/^\s+//; + } + $line_fixed = 1; + } + } + } + $off += length($elements[$n + 1]); + +## print("n: <$n> GOOD: <$good>\n"); + + $fixed_line = $fixed_line . $good; + } + + if (($#elements % 2) == 0) { + $fixed_line = $fixed_line . $fix_elements[$#elements]; + } + + if ($fix && $line_fixed && $fixed_line ne $fixed[$fixlinenr]) { + $fixed[$fixlinenr] = $fixed_line; + } + + + } + +# check for whitespace before a non-naked semicolon + if ($line =~ /^\+.*\S\s+;\s*$/) { + if (WARN("SPACING", + "space prohibited before semicolon\n" . $herecurr) && + $fix) { + 1 while $fixed[$fixlinenr] =~ + s/^(\+.*\S)\s+;/$1;/; + } + } + +# check for multiple assignments + if ($line =~ /^.\s*$Lval\s*=\s*$Lval\s*=(?!=)/) { + CHK("MULTIPLE_ASSIGNMENTS", + "multiple assignments should be avoided\n" . $herecurr); + } + +## # check for multiple declarations, allowing for a function declaration +## # continuation. +## if ($line =~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Ident.*/ && +## $line !~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Type\s*$Ident.*/) { +## +## # Remove any bracketed sections to ensure we do not +## # falsly report the parameters of functions. +## my $ln = $line; +## while ($ln =~ s/\([^\(\)]*\)//g) { +## } +## if ($ln =~ /,/) { +## WARN("MULTIPLE_DECLARATION", +## "declaring multiple variables together should be avoided\n" . $herecurr); +## } +## } + +#need space before brace following if, while, etc + if (($line =~ /\(.*\)\{/ && $line !~ /\($Type\)\{/) || + $line =~ /\b(?:else|do)\{/) { + if (ERROR("SPACING", + "space required before the open brace '{'\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/^(\+.*(?:do|else|\)))\{/$1 {/; + } + } + +## # check for blank lines before declarations +## if ($line =~ /^.\t+$Type\s+$Ident(?:\s*=.*)?;/ && +## $prevrawline =~ /^.\s*$/) { +## WARN("SPACING", +## "No blank lines before declarations\n" . $hereprev); +## } +## + +# closing brace should have a space following it when it has anything +# on the line + if ($line =~ /}(?!(?:,|;|\)))\S/) { + if (ERROR("SPACING", + "space required after that close brace '}'\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ + s/}((?!(?:,|;|\)))\S)/} $1/; + } + } + +# check spacing on square brackets + if ($line =~ /\[\s/ && $line !~ /\[\s*$/) { + if (ERROR("SPACING", + "space prohibited after that open square bracket '['\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ + s/\[\s+/\[/; + } + } + if ($line =~ /\s\]/) { + if (ERROR("SPACING", + "space prohibited before that close square bracket ']'\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ + s/\s+\]/\]/; + } + } + +# check spacing on parentheses + if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ && + $line !~ /for\s*\(\s+;/) { + if (ERROR("SPACING", + "space prohibited after that open parenthesis '('\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ + s/\(\s+/\(/; + } + } + if ($line =~ /(\s+)\)/ && $line !~ /^.\s*\)/ && + $line !~ /for\s*\(.*;\s+\)/ && + $line !~ /:\s+\)/) { + if (ERROR("SPACING", + "space prohibited before that close parenthesis ')'\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ + s/\s+\)/\)/; + } + } + +# check unnecessary parentheses around addressof/dereference single $Lvals +# ie: &(foo->bar) should be &foo->bar and *(foo->bar) should be *foo->bar + + while ($line =~ /(?:[^&]&\s*|\*)\(\s*($Ident\s*(?:$Member\s*)+)\s*\)/g) { + my $var = $1; + if (CHK("UNNECESSARY_PARENTHESES", + "Unnecessary parentheses around $var\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\(\s*\Q$var\E\s*\)/$var/; + } + } + +# check for unnecessary parentheses around function pointer uses +# ie: (foo->bar)(); should be foo->bar(); +# but not "if (foo->bar) (" to avoid some false positives + if ($line =~ /(\bif\s*|)(\(\s*$Ident\s*(?:$Member\s*)+\))[ \t]*\(/ && $1 !~ /^if/) { + my $var = $2; + if (CHK("UNNECESSARY_PARENTHESES", + "Unnecessary parentheses around function pointer $var\n" . $herecurr) && + $fix) { + my $var2 = deparenthesize($var); + $var2 =~ s/\s//g; + $fixed[$fixlinenr] =~ s/\Q$var\E/$var2/; + } + } + +# check for unnecessary parentheses around comparisons in if uses +# when !drivers/staging or command-line uses --strict + if (($realfile !~ m@^(?:drivers/staging/)@ || $check_orig) && + $perl_version_ok && defined($stat) && + $stat =~ /(^.\s*if\s*($balanced_parens))/) { + my $if_stat = $1; + my $test = substr($2, 1, -1); + my $herectx; + while ($test =~ /(?:^|[^\w\&\!\~])+\s*\(\s*([\&\!\~]?\s*$Lval\s*(?:$Compare\s*$FuncArg)?)\s*\)/g) { + my $match = $1; + # avoid parentheses around potential macro args + next if ($match =~ /^\s*\w+\s*$/); + if (!defined($herectx)) { + $herectx = $here . "\n"; + my $cnt = statement_rawlines($if_stat); + for (my $n = 0; $n < $cnt; $n++) { + my $rl = raw_line($linenr, $n); + $herectx .= $rl . "\n"; + last if $rl =~ /^[ \+].*\{/; + } + } + CHK("UNNECESSARY_PARENTHESES", + "Unnecessary parentheses around '$match'\n" . $herectx); + } + } + +#goto labels aren't indented, allow a single space however + if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and + !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) { + if (WARN("INDENTED_LABEL", + "labels should not be indented\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ + s/^(.)\s+/$1/; + } + } + +# return is not a function + if (defined($stat) && $stat =~ /^.\s*return(\s*)\(/s) { + my $spacing = $1; + if ($perl_version_ok && + $stat =~ /^.\s*return\s*($balanced_parens)\s*;\s*$/) { + my $value = $1; + $value = deparenthesize($value); + if ($value =~ m/^\s*$FuncArg\s*(?:\?|$)/) { + ERROR("RETURN_PARENTHESES", + "return is not a function, parentheses are not required\n" . $herecurr); + } + } elsif ($spacing !~ /\s+/) { + ERROR("SPACING", + "space required before the open parenthesis '('\n" . $herecurr); + } + } + +# unnecessary return in a void function +# at end-of-function, with the previous line a single leading tab, then return; +# and the line before that not a goto label target like "out:" + if ($sline =~ /^[ \+]}\s*$/ && + $prevline =~ /^\+\treturn\s*;\s*$/ && + $linenr >= 3 && + $lines[$linenr - 3] =~ /^[ +]/ && + $lines[$linenr - 3] !~ /^[ +]\s*$Ident\s*:/) { + WARN("RETURN_VOID", + "void function return statements are not generally useful\n" . $hereprev); + } + +# if statements using unnecessary parentheses - ie: if ((foo == bar)) + if ($perl_version_ok && + $line =~ /\bif\s*((?:\(\s*){2,})/) { + my $openparens = $1; + my $count = $openparens =~ tr@\(@\(@; + my $msg = ""; + if ($line =~ /\bif\s*(?:\(\s*){$count,$count}$LvalOrFunc\s*($Compare)\s*$LvalOrFunc(?:\s*\)){$count,$count}/) { + my $comp = $4; #Not $1 because of $LvalOrFunc + $msg = " - maybe == should be = ?" if ($comp eq "=="); + WARN("UNNECESSARY_PARENTHESES", + "Unnecessary parentheses$msg\n" . $herecurr); + } + } + +# comparisons with a constant or upper case identifier on the left +# avoid cases like "foo + BAR < baz" +# only fix matches surrounded by parentheses to avoid incorrect +# conversions like "FOO < baz() + 5" being "misfixed" to "baz() > FOO + 5" + if ($perl_version_ok && + $line =~ /^\+(.*)\b($Constant|[A-Z_][A-Z0-9_]*)\s*($Compare)\s*($LvalOrFunc)/) { + my $lead = $1; + my $const = $2; + my $comp = $3; + my $to = $4; + my $newcomp = $comp; + if ($lead !~ /(?:$Operators|\.)\s*$/ && + $to !~ /^(?:Constant|[A-Z_][A-Z0-9_]*)$/ && + WARN("CONSTANT_COMPARISON", + "Comparisons should place the constant on the right side of the test\n" . $herecurr) && + $fix) { + if ($comp eq "<") { + $newcomp = ">"; + } elsif ($comp eq "<=") { + $newcomp = ">="; + } elsif ($comp eq ">") { + $newcomp = "<"; + } elsif ($comp eq ">=") { + $newcomp = "<="; + } + $fixed[$fixlinenr] =~ s/\(\s*\Q$const\E\s*$Compare\s*\Q$to\E\s*\)/($to $newcomp $const)/; + } + } + +# Return of what appears to be an errno should normally be negative + if ($sline =~ /\breturn(?:\s*\(+\s*|\s+)(E[A-Z]+)(?:\s*\)+\s*|\s*)[;:,]/) { + my $name = $1; + if ($name ne 'EOF' && $name ne 'ERROR') { + WARN("USE_NEGATIVE_ERRNO", + "return of an errno should typically be negative (ie: return -$1)\n" . $herecurr); + } + } + +# Need a space before open parenthesis after if, while etc + if ($line =~ /\b(if|while|for|switch)\(/) { + if (ERROR("SPACING", + "space required before the open parenthesis '('\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ + s/\b(if|while|for|switch)\(/$1 \(/; + } + } + +# Check for illegal assignment in if conditional -- and check for trailing +# statements after the conditional. + if ($line =~ /do\s*(?!{)/) { + ($stat, $cond, $line_nr_next, $remain_next, $off_next) = + ctx_statement_block($linenr, $realcnt, 0) + if (!defined $stat); + my ($stat_next) = ctx_statement_block($line_nr_next, + $remain_next, $off_next); + $stat_next =~ s/\n./\n /g; + ##print "stat<$stat> stat_next<$stat_next>\n"; + + if ($stat_next =~ /^\s*while\b/) { + # If the statement carries leading newlines, + # then count those as offsets. + my ($whitespace) = + ($stat_next =~ /^((?:\s*\n[+-])*\s*)/s); + my $offset = + statement_rawlines($whitespace) - 1; + + $suppress_whiletrailers{$line_nr_next + + $offset} = 1; + } + } + if (!defined $suppress_whiletrailers{$linenr} && + defined($stat) && defined($cond) && + $line =~ /\b(?:if|while|for)\s*\(/ && $line !~ /^.\s*#/) { + my ($s, $c) = ($stat, $cond); + + if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/s) { + ERROR("ASSIGN_IN_IF", + "do not use assignment in if condition\n" . $herecurr); + } + + # Find out what is on the end of the line after the + # conditional. + substr($s, 0, length($c), ''); + $s =~ s/\n.*//g; + $s =~ s/$;//g; # Remove any comments + if (length($c) && $s !~ /^\s*{?\s*\\*\s*$/ && + $c !~ /}\s*while\s*/) + { + # Find out how long the conditional actually is. + my @newlines = ($c =~ /\n/gs); + my $cond_lines = 1 + $#newlines; + my $stat_real = ''; + + $stat_real = raw_line($linenr, $cond_lines) + . "\n" if ($cond_lines); + if (defined($stat_real) && $cond_lines > 1) { + $stat_real = "[...]\n$stat_real"; + } + + ERROR("TRAILING_STATEMENTS", + "trailing statements should be on next line\n" . $herecurr . $stat_real); + } + } + +# Check for bitwise tests written as boolean + if ($line =~ / + (?: + (?:\[|\(|\&\&|\|\|) + \s*0[xX][0-9]+\s* + (?:\&\&|\|\|) + | + (?:\&\&|\|\|) + \s*0[xX][0-9]+\s* + (?:\&\&|\|\||\)|\]) + )/x) + { + WARN("HEXADECIMAL_BOOLEAN_TEST", + "boolean test with hexadecimal, perhaps just 1 \& or \|?\n" . $herecurr); + } + +# if and else should not have general statements after it + if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/) { + my $s = $1; + $s =~ s/$;//g; # Remove any comments + if ($s !~ /^\s*(?:\sif|(?:{|)\s*\\?\s*$)/) { + ERROR("TRAILING_STATEMENTS", + "trailing statements should be on next line\n" . $herecurr); + } + } +# if should not continue a brace + if ($line =~ /}\s*if\b/) { + ERROR("TRAILING_STATEMENTS", + "trailing statements should be on next line (or did you mean 'else if'?)\n" . + $herecurr); + } +# case and default should not have general statements after them + if ($line =~ /^.\s*(?:case\s*.*|default\s*):/g && + $line !~ /\G(?: + (?:\s*$;*)(?:\s*{)?(?:\s*$;*)(?:\s*\\)?\s*$| + \s*return\s+ + )/xg) + { + ERROR("TRAILING_STATEMENTS", + "trailing statements should be on next line\n" . $herecurr); + } + + # Check for }<nl>else {, these must be at the same + # indent level to be relevant to each other. + if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ && + $previndent == $indent) { + if (ERROR("ELSE_AFTER_BRACE", + "else should follow close brace '}'\n" . $hereprev) && + $fix && $prevline =~ /^\+/ && $line =~ /^\+/) { + fix_delete_line($fixlinenr - 1, $prevrawline); + fix_delete_line($fixlinenr, $rawline); + my $fixedline = $prevrawline; + $fixedline =~ s/}\s*$//; + if ($fixedline !~ /^\+\s*$/) { + fix_insert_line($fixlinenr, $fixedline); + } + $fixedline = $rawline; + $fixedline =~ s/^(.\s*)else/$1} else/; + fix_insert_line($fixlinenr, $fixedline); + } + } + + if ($prevline=~/}\s*$/ and $line=~/^.\s*while\s*/ && + $previndent == $indent) { + my ($s, $c) = ctx_statement_block($linenr, $realcnt, 0); + + # Find out what is on the end of the line after the + # conditional. + substr($s, 0, length($c), ''); + $s =~ s/\n.*//g; + + if ($s =~ /^\s*;/) { + if (ERROR("WHILE_AFTER_BRACE", + "while should follow close brace '}'\n" . $hereprev) && + $fix && $prevline =~ /^\+/ && $line =~ /^\+/) { + fix_delete_line($fixlinenr - 1, $prevrawline); + fix_delete_line($fixlinenr, $rawline); + my $fixedline = $prevrawline; + my $trailing = $rawline; + $trailing =~ s/^\+//; + $trailing = trim($trailing); + $fixedline =~ s/}\s*$/} $trailing/; + fix_insert_line($fixlinenr, $fixedline); + } + } + } + +#Specific variable tests + while ($line =~ m{($Constant|$Lval)}g) { + my $var = $1; + +#CamelCase + if ($var !~ /^$Constant$/ && + $var =~ /[A-Z][a-z]|[a-z][A-Z]/ && +#Ignore Page<foo> variants + $var !~ /^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ && +#Ignore SI style variants like nS, mV and dB (ie: max_uV, regulator_min_uA_show) + $var !~ /^(?:[a-z_]*?)_?[a-z][A-Z](?:_[a-z_]+)?$/ && +#Ignore some three character SI units explicitly, like MiB and KHz + $var !~ /^(?:[a-z_]*?)_?(?:[KMGT]iB|[KMGT]?Hz)(?:_[a-z_]+)?$/) { + while ($var =~ m{($Ident)}g) { + my $word = $1; + next if ($word !~ /[A-Z][a-z]|[a-z][A-Z]/); + if ($check) { + seed_camelcase_includes(); + if (!$file && !$camelcase_file_seeded) { + seed_camelcase_file($realfile); + $camelcase_file_seeded = 1; + } + } + if (!defined $camelcase{$word}) { + $camelcase{$word} = 1; + CHK("CAMELCASE", + "Avoid CamelCase: <$word>\n" . $herecurr); + } + } + } + } + +#no spaces allowed after \ in define + if ($line =~ /\#\s*define.*\\\s+$/) { + if (WARN("WHITESPACE_AFTER_LINE_CONTINUATION", + "Whitespace after \\ makes next lines useless\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\s+$//; + } + } + +# warn if <asm/foo.h> is #included and <linux/foo.h> is available and includes +# itself <asm/foo.h> (uses RAW line) + if ($tree && $rawline =~ m{^.\s*\#\s*include\s*\<asm\/(.*)\.h\>}) { + my $file = "$1.h"; + my $checkfile = "include/linux/$file"; + if (-f "$root/$checkfile" && + $realfile ne $checkfile && + $1 !~ /$allowed_asm_includes/) + { + my $asminclude = `grep -Ec "#include\\s+<asm/$file>" $root/$checkfile`; + if ($asminclude > 0) { + if ($realfile =~ m{^arch/}) { + CHK("ARCH_INCLUDE_LINUX", + "Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr); + } else { + WARN("INCLUDE_LINUX", + "Use #include <linux/$file> instead of <asm/$file>\n" . $herecurr); + } + } + } + } + +# multi-statement macros should be enclosed in a do while loop, grab the +# first statement and ensure its the whole macro if its not enclosed +# in a known good container + if ($realfile !~ m@/vmlinux.lds.h$@ && + $line =~ /^.\s*\#\s*define\s*$Ident(\()?/) { + my $ln = $linenr; + my $cnt = $realcnt; + my ($off, $dstat, $dcond, $rest); + my $ctx = ''; + my $has_flow_statement = 0; + my $has_arg_concat = 0; + ($dstat, $dcond, $ln, $cnt, $off) = + ctx_statement_block($linenr, $realcnt, 0); + $ctx = $dstat; + #print "dstat<$dstat> dcond<$dcond> cnt<$cnt> off<$off>\n"; + #print "LINE<$lines[$ln-1]> len<" . length($lines[$ln-1]) . "\n"; + + $has_flow_statement = 1 if ($ctx =~ /\b(goto|return)\b/); + $has_arg_concat = 1 if ($ctx =~ /\#\#/ && $ctx !~ /\#\#\s*(?:__VA_ARGS__|args)\b/); + + $dstat =~ s/^.\s*\#\s*define\s+$Ident(\([^\)]*\))?\s*//; + my $define_args = $1; + my $define_stmt = $dstat; + my @def_args = (); + + if (defined $define_args && $define_args ne "") { + $define_args = substr($define_args, 1, length($define_args) - 2); + $define_args =~ s/\s*//g; + $define_args =~ s/\\\+?//g; + @def_args = split(",", $define_args); + } + + $dstat =~ s/$;//g; + $dstat =~ s/\\\n.//g; + $dstat =~ s/^\s*//s; + $dstat =~ s/\s*$//s; + + # Flatten any parentheses and braces + while ($dstat =~ s/\([^\(\)]*\)/1/ || + $dstat =~ s/\{[^\{\}]*\}/1/ || + $dstat =~ s/.\[[^\[\]]*\]/1/) + { + } + + # Flatten any obvious string concatentation. + while ($dstat =~ s/($String)\s*$Ident/$1/ || + $dstat =~ s/$Ident\s*($String)/$1/) + { + } + + # Make asm volatile uses seem like a generic function + $dstat =~ s/\b_*asm_*\s+_*volatile_*\b/asm_volatile/g; + + my $exceptions = qr{ + $Declare| + module_param_named| + MODULE_PARM_DESC| + DECLARE_PER_CPU| + DEFINE_PER_CPU| + __typeof__\(| + union| + struct| + \.$Ident\s*=\s*| + ^\"|\"$| + ^\[ + }x; + #print "REST<$rest> dstat<$dstat> ctx<$ctx>\n"; + + $ctx =~ s/\n*$//; + my $stmt_cnt = statement_rawlines($ctx); + my $herectx = get_stat_here($linenr, $stmt_cnt, $here); + + if ($dstat ne '' && + $dstat !~ /^(?:$Ident|-?$Constant),$/ && # 10, // foo(), + $dstat !~ /^(?:$Ident|-?$Constant);$/ && # foo(); + $dstat !~ /^[!~-]?(?:$Lval|$Constant)$/ && # 10 // foo() // !foo // ~foo // -foo // foo->bar // foo.bar->baz + $dstat !~ /^'X'$/ && $dstat !~ /^'XX'$/ && # character constants + $dstat !~ /$exceptions/ && + $dstat !~ /^\.$Ident\s*=/ && # .foo = + $dstat !~ /^(?:\#\s*$Ident|\#\s*$Constant)\s*$/ && # stringification #foo + $dstat !~ /^do\s*$Constant\s*while\s*$Constant;?$/ && # do {...} while (...); // do {...} while (...) + $dstat !~ /^for\s*$Constant$/ && # for (...) + $dstat !~ /^for\s*$Constant\s+(?:$Ident|-?$Constant)$/ && # for (...) bar() + $dstat !~ /^do\s*{/ && # do {... + $dstat !~ /^\(\{/ && # ({... + $ctx !~ /^.\s*#\s*define\s+TRACE_(?:SYSTEM|INCLUDE_FILE|INCLUDE_PATH)\b/) + { + if ($dstat =~ /^\s*if\b/) { + ERROR("MULTISTATEMENT_MACRO_USE_DO_WHILE", + "Macros starting with if should be enclosed by a do - while loop to avoid possible if/else logic defects\n" . "$herectx"); + } elsif ($dstat =~ /;/) { + ERROR("MULTISTATEMENT_MACRO_USE_DO_WHILE", + "Macros with multiple statements should be enclosed in a do - while loop\n" . "$herectx"); + } else { + ERROR("COMPLEX_MACRO", + "Macros with complex values should be enclosed in parentheses\n" . "$herectx"); + } + + } + + # Make $define_stmt single line, comment-free, etc + my @stmt_array = split('\n', $define_stmt); + my $first = 1; + $define_stmt = ""; + foreach my $l (@stmt_array) { + $l =~ s/\\$//; + if ($first) { + $define_stmt = $l; + $first = 0; + } elsif ($l =~ /^[\+ ]/) { + $define_stmt .= substr($l, 1); + } + } + $define_stmt =~ s/$;//g; + $define_stmt =~ s/\s+/ /g; + $define_stmt = trim($define_stmt); + +# check if any macro arguments are reused (ignore '...' and 'type') + foreach my $arg (@def_args) { + next if ($arg =~ /\.\.\./); + next if ($arg =~ /^type$/i); + my $tmp_stmt = $define_stmt; + $tmp_stmt =~ s/\b(typeof|__typeof__|__builtin\w+|typecheck\s*\(\s*$Type\s*,|\#+)\s*\(*\s*$arg\s*\)*\b//g; + $tmp_stmt =~ s/\#+\s*$arg\b//g; + $tmp_stmt =~ s/\b$arg\s*\#\#//g; + my $use_cnt = () = $tmp_stmt =~ /\b$arg\b/g; + if ($use_cnt > 1) { + CHK("MACRO_ARG_REUSE", + "Macro argument reuse '$arg' - possible side-effects?\n" . "$herectx"); + } +# check if any macro arguments may have other precedence issues + if ($tmp_stmt =~ m/($Operators)?\s*\b$arg\b\s*($Operators)?/m && + ((defined($1) && $1 ne ',') || + (defined($2) && $2 ne ','))) { + CHK("MACRO_ARG_PRECEDENCE", + "Macro argument '$arg' may be better as '($arg)' to avoid precedence issues\n" . "$herectx"); + } + } + +# check for macros with flow control, but without ## concatenation +# ## concatenation is commonly a macro that defines a function so ignore those + if ($has_flow_statement && !$has_arg_concat) { + my $cnt = statement_rawlines($ctx); + my $herectx = get_stat_here($linenr, $cnt, $here); + + WARN("MACRO_WITH_FLOW_CONTROL", + "Macros with flow control statements should be avoided\n" . "$herectx"); + } + +# check for line continuations outside of #defines, preprocessor #, and asm + + } else { + if ($prevline !~ /^..*\\$/ && + $line !~ /^\+\s*\#.*\\$/ && # preprocessor + $line !~ /^\+.*\b(__asm__|asm)\b.*\\$/ && # asm + $line =~ /^\+.*\\$/) { + WARN("LINE_CONTINUATIONS", + "Avoid unnecessary line continuations\n" . $herecurr); + } + } + +# do {} while (0) macro tests: +# single-statement macros do not need to be enclosed in do while (0) loop, +# macro should not end with a semicolon + if ($perl_version_ok && + $realfile !~ m@/vmlinux.lds.h$@ && + $line =~ /^.\s*\#\s*define\s+$Ident(\()?/) { + my $ln = $linenr; + my $cnt = $realcnt; + my ($off, $dstat, $dcond, $rest); + my $ctx = ''; + ($dstat, $dcond, $ln, $cnt, $off) = + ctx_statement_block($linenr, $realcnt, 0); + $ctx = $dstat; + + $dstat =~ s/\\\n.//g; + $dstat =~ s/$;/ /g; + + if ($dstat =~ /^\+\s*#\s*define\s+$Ident\s*${balanced_parens}\s*do\s*{(.*)\s*}\s*while\s*\(\s*0\s*\)\s*([;\s]*)\s*$/) { + my $stmts = $2; + my $semis = $3; + + $ctx =~ s/\n*$//; + my $cnt = statement_rawlines($ctx); + my $herectx = get_stat_here($linenr, $cnt, $here); + + if (($stmts =~ tr/;/;/) == 1 && + $stmts !~ /^\s*(if|while|for|switch)\b/) { + WARN("SINGLE_STATEMENT_DO_WHILE_MACRO", + "Single statement macros should not use a do {} while (0) loop\n" . "$herectx"); + } + if (defined $semis && $semis ne "") { + WARN("DO_WHILE_MACRO_WITH_TRAILING_SEMICOLON", + "do {} while (0) macros should not be semicolon terminated\n" . "$herectx"); + } + } elsif ($dstat =~ /^\+\s*#\s*define\s+$Ident.*;\s*$/) { + $ctx =~ s/\n*$//; + my $cnt = statement_rawlines($ctx); + my $herectx = get_stat_here($linenr, $cnt, $here); + + WARN("TRAILING_SEMICOLON", + "macros should not use a trailing semicolon\n" . "$herectx"); + } + } + +# check for redundant bracing round if etc + if ($line =~ /(^.*)\bif\b/ && $1 !~ /else\s*$/) { + my ($level, $endln, @chunks) = + ctx_statement_full($linenr, $realcnt, 1); + #print "chunks<$#chunks> linenr<$linenr> endln<$endln> level<$level>\n"; + #print "APW: <<$chunks[1][0]>><<$chunks[1][1]>>\n"; + if ($#chunks > 0 && $level == 0) { + my @allowed = (); + my $allow = 0; + my $seen = 0; + my $herectx = $here . "\n"; + my $ln = $linenr - 1; + for my $chunk (@chunks) { + my ($cond, $block) = @{$chunk}; + + # If the condition carries leading newlines, then count those as offsets. + my ($whitespace) = ($cond =~ /^((?:\s*\n[+-])*\s*)/s); + my $offset = statement_rawlines($whitespace) - 1; + + $allowed[$allow] = 0; + #print "COND<$cond> whitespace<$whitespace> offset<$offset>\n"; + + # We have looked at and allowed this specific line. + $suppress_ifbraces{$ln + $offset} = 1; + + $herectx .= "$rawlines[$ln + $offset]\n[...]\n"; + $ln += statement_rawlines($block) - 1; + + substr($block, 0, length($cond), ''); + + $seen++ if ($block =~ /^\s*{/); + + #print "cond<$cond> block<$block> allowed<$allowed[$allow]>\n"; + if (statement_lines($cond) > 1) { + #print "APW: ALLOWED: cond<$cond>\n"; + $allowed[$allow] = 1; + } + if ($block =~/\b(?:if|for|while)\b/) { + #print "APW: ALLOWED: block<$block>\n"; + $allowed[$allow] = 1; + } + if (statement_block_size($block) > 1) { + #print "APW: ALLOWED: lines block<$block>\n"; + $allowed[$allow] = 1; + } + $allow++; + } + if ($seen) { + my $sum_allowed = 0; + foreach (@allowed) { + $sum_allowed += $_; + } + if ($sum_allowed == 0) { + WARN("BRACES", + "braces {} are not necessary for any arm of this statement\n" . $herectx); + } elsif ($sum_allowed != $allow && + $seen != $allow) { + CHK("BRACES", + "braces {} should be used on all arms of this statement\n" . $herectx); + } + } + } + } + if (!defined $suppress_ifbraces{$linenr - 1} && + $line =~ /\b(if|while|for|else)\b/) { + my $allowed = 0; + + # Check the pre-context. + if (substr($line, 0, $-[0]) =~ /(\}\s*)$/) { + #print "APW: ALLOWED: pre<$1>\n"; + $allowed = 1; + } + + my ($level, $endln, @chunks) = + ctx_statement_full($linenr, $realcnt, $-[0]); + + # Check the condition. + my ($cond, $block) = @{$chunks[0]}; + #print "CHECKING<$linenr> cond<$cond> block<$block>\n"; + if (defined $cond) { + substr($block, 0, length($cond), ''); + } + if (statement_lines($cond) > 1) { + #print "APW: ALLOWED: cond<$cond>\n"; + $allowed = 1; + } + if ($block =~/\b(?:if|for|while)\b/) { + #print "APW: ALLOWED: block<$block>\n"; + $allowed = 1; + } + if (statement_block_size($block) > 1) { + #print "APW: ALLOWED: lines block<$block>\n"; + $allowed = 1; + } + # Check the post-context. + if (defined $chunks[1]) { + my ($cond, $block) = @{$chunks[1]}; + if (defined $cond) { + substr($block, 0, length($cond), ''); + } + if ($block =~ /^\s*\{/) { + #print "APW: ALLOWED: chunk-1 block<$block>\n"; + $allowed = 1; + } + } + if ($level == 0 && $block =~ /^\s*\{/ && !$allowed) { + my $cnt = statement_rawlines($block); + my $herectx = get_stat_here($linenr, $cnt, $here); + + WARN("BRACES", + "braces {} are not necessary for single statement blocks\n" . $herectx); + } + } + +# check for single line unbalanced braces + if ($sline =~ /^.\s*\}\s*else\s*$/ || + $sline =~ /^.\s*else\s*\{\s*$/) { + CHK("BRACES", "Unbalanced braces around else statement\n" . $herecurr); + } + +# check for unnecessary blank lines around braces + if (($line =~ /^.\s*}\s*$/ && $prevrawline =~ /^.\s*$/)) { + if (CHK("BRACES", + "Blank lines aren't necessary before a close brace '}'\n" . $hereprev) && + $fix && $prevrawline =~ /^\+/) { + fix_delete_line($fixlinenr - 1, $prevrawline); + } + } + if (($rawline =~ /^.\s*$/ && $prevline =~ /^..*{\s*$/)) { + if (CHK("BRACES", + "Blank lines aren't necessary after an open brace '{'\n" . $hereprev) && + $fix) { + fix_delete_line($fixlinenr, $rawline); + } + } + +# no volatiles please + my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b}; + if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) { + WARN("VOLATILE", + "Use of volatile is usually wrong: see Documentation/process/volatile-considered-harmful.rst\n" . $herecurr); + } + +# Check for user-visible strings broken across lines, which breaks the ability +# to grep for the string. Make exceptions when the previous string ends in a +# newline (multiple lines in one string constant) or '\t', '\r', ';', or '{' +# (common in inline assembly) or is a octal \123 or hexadecimal \xaf value + if ($line =~ /^\+\s*$String/ && + $prevline =~ /"\s*$/ && + $prevrawline !~ /(?:\\(?:[ntr]|[0-7]{1,3}|x[0-9a-fA-F]{1,2})|;\s*|\{\s*)"\s*$/) { + if (WARN("SPLIT_STRING", + "quoted string split across lines\n" . $hereprev) && + $fix && + $prevrawline =~ /^\+.*"\s*$/ && + $last_coalesced_string_linenr != $linenr - 1) { + my $extracted_string = get_quoted_string($line, $rawline); + my $comma_close = ""; + if ($rawline =~ /\Q$extracted_string\E(\s*\)\s*;\s*$|\s*,\s*)/) { + $comma_close = $1; + } + + fix_delete_line($fixlinenr - 1, $prevrawline); + fix_delete_line($fixlinenr, $rawline); + my $fixedline = $prevrawline; + $fixedline =~ s/"\s*$//; + $fixedline .= substr($extracted_string, 1) . trim($comma_close); + fix_insert_line($fixlinenr - 1, $fixedline); + $fixedline = $rawline; + $fixedline =~ s/\Q$extracted_string\E\Q$comma_close\E//; + if ($fixedline !~ /\+\s*$/) { + fix_insert_line($fixlinenr, $fixedline); + } + $last_coalesced_string_linenr = $linenr; + } + } + +# check for missing a space in a string concatenation + if ($prevrawline =~ /[^\\]\w"$/ && $rawline =~ /^\+[\t ]+"\w/) { + WARN('MISSING_SPACE', + "break quoted strings at a space character\n" . $hereprev); + } + +# check for an embedded function name in a string when the function is known +# This does not work very well for -f --file checking as it depends on patch +# context providing the function name or a single line form for in-file +# function declarations + if ($line =~ /^\+.*$String/ && + defined($context_function) && + get_quoted_string($line, $rawline) =~ /\b$context_function\b/ && + length(get_quoted_string($line, $rawline)) != (length($context_function) + 2)) { + WARN("EMBEDDED_FUNCTION_NAME", + "Prefer using '\"%s...\", __func__' to using '$context_function', this function's name, in a string\n" . $herecurr); + } + +# check for spaces before a quoted newline + if ($rawline =~ /^.*\".*\s\\n/) { + if (WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE", + "unnecessary whitespace before a quoted newline\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/^(\+.*\".*)\s+\\n/$1\\n/; + } + + } + +# concatenated string without spaces between elements + if ($line =~ /$String[A-Za-z0-9_]/ || $line =~ /[A-Za-z0-9_]$String/) { + if (CHK("CONCATENATED_STRING", + "Concatenated strings should use spaces between elements\n" . $herecurr) && + $fix) { + while ($line =~ /($String)/g) { + my $extracted_string = substr($rawline, $-[0], $+[0] - $-[0]); + $fixed[$fixlinenr] =~ s/\Q$extracted_string\E([A-Za-z0-9_])/$extracted_string $1/; + $fixed[$fixlinenr] =~ s/([A-Za-z0-9_])\Q$extracted_string\E/$1 $extracted_string/; + } + } + } + +# uncoalesced string fragments + if ($line =~ /$String\s*"/) { + if (WARN("STRING_FRAGMENTS", + "Consecutive strings are generally better as a single string\n" . $herecurr) && + $fix) { + while ($line =~ /($String)(?=\s*")/g) { + my $extracted_string = substr($rawline, $-[0], $+[0] - $-[0]); + $fixed[$fixlinenr] =~ s/\Q$extracted_string\E\s*"/substr($extracted_string, 0, -1)/e; + } + } + } + +# check for non-standard and hex prefixed decimal printf formats + my $show_L = 1; #don't show the same defect twice + my $show_Z = 1; + while ($line =~ /(?:^|")([X\t]*)(?:"|$)/g) { + my $string = substr($rawline, $-[1], $+[1] - $-[1]); + $string =~ s/%%/__/g; + # check for %L + if ($show_L && $string =~ /%[\*\d\.\$]*L([diouxX])/) { + WARN("PRINTF_L", + "\%L$1 is non-standard C, use %ll$1\n" . $herecurr); + $show_L = 0; + } + # check for %Z + if ($show_Z && $string =~ /%[\*\d\.\$]*Z([diouxX])/) { + WARN("PRINTF_Z", + "%Z$1 is non-standard C, use %z$1\n" . $herecurr); + $show_Z = 0; + } + # check for 0x<decimal> + if ($string =~ /0x%[\*\d\.\$\Llzth]*[diou]/) { + ERROR("PRINTF_0XDECIMAL", + "Prefixing 0x with decimal output is defective\n" . $herecurr); + } + } + +# check for line continuations in quoted strings with odd counts of " + if ($rawline =~ /\\$/ && $sline =~ tr/"/"/ % 2) { + WARN("LINE_CONTINUATIONS", + "Avoid line continuations in quoted strings\n" . $herecurr); + } + +# warn about #if 0 + if ($line =~ /^.\s*\#\s*if\s+0\b/) { + WARN("IF_0", + "Consider removing the code enclosed by this #if 0 and its #endif\n" . $herecurr); + } + +# warn about #if 1 + if ($line =~ /^.\s*\#\s*if\s+1\b/) { + WARN("IF_1", + "Consider removing the #if 1 and its #endif\n" . $herecurr); + } + +# check for needless "if (<foo>) fn(<foo>)" uses + if ($prevline =~ /\bif\s*\(\s*($Lval)\s*\)/) { + my $tested = quotemeta($1); + my $expr = '\s*\(\s*' . $tested . '\s*\)\s*;'; + if ($line =~ /\b(kfree|usb_free_urb|debugfs_remove(?:_recursive)?|(?:kmem_cache|mempool|dma_pool)_destroy)$expr/) { + my $func = $1; + if (WARN('NEEDLESS_IF', + "$func(NULL) is safe and this check is probably not required\n" . $hereprev) && + $fix) { + my $do_fix = 1; + my $leading_tabs = ""; + my $new_leading_tabs = ""; + if ($lines[$linenr - 2] =~ /^\+(\t*)if\s*\(\s*$tested\s*\)\s*$/) { + $leading_tabs = $1; + } else { + $do_fix = 0; + } + if ($lines[$linenr - 1] =~ /^\+(\t+)$func\s*\(\s*$tested\s*\)\s*;\s*$/) { + $new_leading_tabs = $1; + if (length($leading_tabs) + 1 ne length($new_leading_tabs)) { + $do_fix = 0; + } + } else { + $do_fix = 0; + } + if ($do_fix) { + fix_delete_line($fixlinenr - 1, $prevrawline); + $fixed[$fixlinenr] =~ s/^\+$new_leading_tabs/\+$leading_tabs/; + } + } + } + } + +# check for unnecessary "Out of Memory" messages + if ($line =~ /^\+.*\b$logFunctions\s*\(/ && + $prevline =~ /^[ \+]\s*if\s*\(\s*(\!\s*|NULL\s*==\s*)?($Lval)(\s*==\s*NULL\s*)?\s*\)/ && + (defined $1 || defined $3) && + $linenr > 3) { + my $testval = $2; + my $testline = $lines[$linenr - 3]; + + my ($s, $c) = ctx_statement_block($linenr - 3, $realcnt, 0); +# print("line: <$line>\nprevline: <$prevline>\ns: <$s>\nc: <$c>\n\n\n"); + + if ($s =~ /(?:^|\n)[ \+]\s*(?:$Type\s*)?\Q$testval\E\s*=\s*(?:\([^\)]*\)\s*)?\s*(?:devm_)?(?:[kv][czm]alloc(?:_node|_array)?\b|kstrdup|kmemdup|(?:dev_)?alloc_skb)/) { + WARN("OOM_MESSAGE", + "Possible unnecessary 'out of memory' message\n" . $hereprev); + } + } + +# check for logging functions with KERN_<LEVEL> + if ($line !~ /printk(?:_ratelimited|_once)?\s*\(/ && + $line =~ /\b$logFunctions\s*\(.*\b(KERN_[A-Z]+)\b/) { + my $level = $1; + if (WARN("UNNECESSARY_KERN_LEVEL", + "Possible unnecessary $level\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\s*$level\s*//; + } + } + +# check for logging continuations + if ($line =~ /\bprintk\s*\(\s*KERN_CONT\b|\bpr_cont\s*\(/) { + WARN("LOGGING_CONTINUATION", + "Avoid logging continuation uses where feasible\n" . $herecurr); + } + +# check for mask then right shift without a parentheses + if ($perl_version_ok && + $line =~ /$LvalOrFunc\s*\&\s*($LvalOrFunc)\s*>>/ && + $4 !~ /^\&/) { # $LvalOrFunc may be &foo, ignore if so + WARN("MASK_THEN_SHIFT", + "Possible precedence defect with mask then right shift - may need parentheses\n" . $herecurr); + } + +# check for pointer comparisons to NULL + if ($perl_version_ok) { + while ($line =~ /\b$LvalOrFunc\s*(==|\!=)\s*NULL\b/g) { + my $val = $1; + my $equal = "!"; + $equal = "" if ($4 eq "!="); + if (CHK("COMPARISON_TO_NULL", + "Comparison to NULL could be written \"${equal}${val}\"\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\b\Q$val\E\s*(?:==|\!=)\s*NULL\b/$equal$val/; + } + } + } + +# check for bad placement of section $InitAttribute (e.g.: __initdata) + if ($line =~ /(\b$InitAttribute\b)/) { + my $attr = $1; + if ($line =~ /^\+\s*static\s+(?:const\s+)?(?:$attr\s+)?($NonptrTypeWithAttr)\s+(?:$attr\s+)?($Ident(?:\[[^]]*\])?)\s*[=;]/) { + my $ptr = $1; + my $var = $2; + if ((($ptr =~ /\b(union|struct)\s+$attr\b/ && + ERROR("MISPLACED_INIT", + "$attr should be placed after $var\n" . $herecurr)) || + ($ptr !~ /\b(union|struct)\s+$attr\b/ && + WARN("MISPLACED_INIT", + "$attr should be placed after $var\n" . $herecurr))) && + $fix) { + $fixed[$fixlinenr] =~ s/(\bstatic\s+(?:const\s+)?)(?:$attr\s+)?($NonptrTypeWithAttr)\s+(?:$attr\s+)?($Ident(?:\[[^]]*\])?)\s*([=;])\s*/"$1" . trim(string_find_replace($2, "\\s*$attr\\s*", " ")) . " " . trim(string_find_replace($3, "\\s*$attr\\s*", "")) . " $attr" . ("$4" eq ";" ? ";" : " = ")/e; + } + } + } + +# check for $InitAttributeData (ie: __initdata) with const + if ($line =~ /\bconst\b/ && $line =~ /($InitAttributeData)/) { + my $attr = $1; + $attr =~ /($InitAttributePrefix)(.*)/; + my $attr_prefix = $1; + my $attr_type = $2; + if (ERROR("INIT_ATTRIBUTE", + "Use of const init definition must use ${attr_prefix}initconst\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ + s/$InitAttributeData/${attr_prefix}initconst/; + } + } + +# check for $InitAttributeConst (ie: __initconst) without const + if ($line !~ /\bconst\b/ && $line =~ /($InitAttributeConst)/) { + my $attr = $1; + if (ERROR("INIT_ATTRIBUTE", + "Use of $attr requires a separate use of const\n" . $herecurr) && + $fix) { + my $lead = $fixed[$fixlinenr] =~ + /(^\+\s*(?:static\s+))/; + $lead = rtrim($1); + $lead = "$lead " if ($lead !~ /^\+$/); + $lead = "${lead}const "; + $fixed[$fixlinenr] =~ s/(^\+\s*(?:static\s+))/$lead/; + } + } + +# check for __read_mostly with const non-pointer (should just be const) + if ($line =~ /\b__read_mostly\b/ && + $line =~ /($Type)\s*$Ident/ && $1 !~ /\*\s*$/ && $1 =~ /\bconst\b/) { + if (ERROR("CONST_READ_MOSTLY", + "Invalid use of __read_mostly with const type\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\s+__read_mostly\b//; + } + } + +# don't use __constant_<foo> functions outside of include/uapi/ + if ($realfile !~ m@^include/uapi/@ && + $line =~ /(__constant_(?:htons|ntohs|[bl]e(?:16|32|64)_to_cpu|cpu_to_[bl]e(?:16|32|64)))\s*\(/) { + my $constant_func = $1; + my $func = $constant_func; + $func =~ s/^__constant_//; + if (WARN("CONSTANT_CONVERSION", + "$constant_func should be $func\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\b$constant_func\b/$func/g; + } + } + +# prefer usleep_range over udelay + if ($line =~ /\budelay\s*\(\s*(\d+)\s*\)/) { + my $delay = $1; + # ignore udelay's < 10, however + if (! ($delay < 10) ) { + CHK("USLEEP_RANGE", + "usleep_range is preferred over udelay; see Documentation/timers/timers-howto.txt\n" . $herecurr); + } + if ($delay > 2000) { + WARN("LONG_UDELAY", + "long udelay - prefer mdelay; see arch/arm/include/asm/delay.h\n" . $herecurr); + } + } + +# warn about unexpectedly long msleep's + if ($line =~ /\bmsleep\s*\((\d+)\);/) { + if ($1 < 20) { + WARN("MSLEEP", + "msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.txt\n" . $herecurr); + } + } + +# check for comparisons of jiffies + if ($line =~ /\bjiffies\s*$Compare|$Compare\s*jiffies\b/) { + WARN("JIFFIES_COMPARISON", + "Comparing jiffies is almost always wrong; prefer time_after, time_before and friends\n" . $herecurr); + } + +# check for comparisons of get_jiffies_64() + if ($line =~ /\bget_jiffies_64\s*\(\s*\)\s*$Compare|$Compare\s*get_jiffies_64\s*\(\s*\)/) { + WARN("JIFFIES_COMPARISON", + "Comparing get_jiffies_64() is almost always wrong; prefer time_after64, time_before64 and friends\n" . $herecurr); + } + +# warn about #ifdefs in C files +# if ($line =~ /^.\s*\#\s*if(|n)def/ && ($realfile =~ /\.c$/)) { +# print "#ifdef in C files should be avoided\n"; +# print "$herecurr"; +# $clean = 0; +# } + +# warn about spacing in #ifdefs + if ($line =~ /^.\s*\#\s*(ifdef|ifndef|elif)\s\s+/) { + if (ERROR("SPACING", + "exactly one space required after that #$1\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ + s/^(.\s*\#\s*(ifdef|ifndef|elif))\s{2,}/$1 /; + } + + } + +# check for spinlock_t definitions without a comment. + if ($line =~ /^.\s*(struct\s+mutex|spinlock_t)\s+\S+;/ || + $line =~ /^.\s*(DEFINE_MUTEX)\s*\(/) { + my $which = $1; + if (!ctx_has_comment($first_line, $linenr)) { + CHK("UNCOMMENTED_DEFINITION", + "$1 definition without comment\n" . $herecurr); + } + } +# check for memory barriers without a comment. + + my $barriers = qr{ + mb| + rmb| + wmb| + read_barrier_depends + }x; + my $barrier_stems = qr{ + mb__before_atomic| + mb__after_atomic| + store_release| + load_acquire| + store_mb| + (?:$barriers) + }x; + my $all_barriers = qr{ + (?:$barriers)| + smp_(?:$barrier_stems)| + virt_(?:$barrier_stems) + }x; + + if ($line =~ /\b(?:$all_barriers)\s*\(/) { + if (!ctx_has_comment($first_line, $linenr)) { + WARN("MEMORY_BARRIER", + "memory barrier without comment\n" . $herecurr); + } + } + + my $underscore_smp_barriers = qr{__smp_(?:$barrier_stems)}x; + + if ($realfile !~ m@^include/asm-generic/@ && + $realfile !~ m@/barrier\.h$@ && + $line =~ m/\b(?:$underscore_smp_barriers)\s*\(/ && + $line !~ m/^.\s*\#\s*define\s+(?:$underscore_smp_barriers)\s*\(/) { + WARN("MEMORY_BARRIER", + "__smp memory barriers shouldn't be used outside barrier.h and asm-generic\n" . $herecurr); + } + +# check for waitqueue_active without a comment. + if ($line =~ /\bwaitqueue_active\s*\(/) { + if (!ctx_has_comment($first_line, $linenr)) { + WARN("WAITQUEUE_ACTIVE", + "waitqueue_active without comment\n" . $herecurr); + } + } + +# check for smp_read_barrier_depends and read_barrier_depends + if (!$file && $line =~ /\b(smp_|)read_barrier_depends\s*\(/) { + WARN("READ_BARRIER_DEPENDS", + "$1read_barrier_depends should only be used in READ_ONCE or DEC Alpha code\n" . $herecurr); + } + +# check of hardware specific defines + if ($line =~ m@^.\s*\#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@include/asm-@) { + CHK("ARCH_DEFINES", + "architecture specific defines should be avoided\n" . $herecurr); + } + +# check that the storage class is not after a type + if ($line =~ /\b($Type)\s+($Storage)\b/) { + WARN("STORAGE_CLASS", + "storage class '$2' should be located before type '$1'\n" . $herecurr); + } +# Check that the storage class is at the beginning of a declaration + if ($line =~ /\b$Storage\b/ && + $line !~ /^.\s*$Storage/ && + $line =~ /^.\s*(.+?)\$Storage\s/ && + $1 !~ /[\,\)]\s*$/) { + WARN("STORAGE_CLASS", + "storage class should be at the beginning of the declaration\n" . $herecurr); + } + +# check the location of the inline attribute, that it is between +# storage class and type. + if ($line =~ /\b$Type\s+$Inline\b/ || + $line =~ /\b$Inline\s+$Storage\b/) { + ERROR("INLINE_LOCATION", + "inline keyword should sit between storage class and type\n" . $herecurr); + } + +# Check for __inline__ and __inline, prefer inline + if ($realfile !~ m@\binclude/uapi/@ && + $line =~ /\b(__inline__|__inline)\b/) { + if (WARN("INLINE", + "plain inline is preferred over $1\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\b(__inline__|__inline)\b/inline/; + + } + } + +# Check for __attribute__ packed, prefer __packed + if ($realfile !~ m@\binclude/uapi/@ && + $line =~ /\b__attribute__\s*\(\s*\(.*\bpacked\b/) { + WARN("PREFER_PACKED", + "__packed is preferred over __attribute__((packed))\n" . $herecurr); + } + +# Check for __attribute__ aligned, prefer __aligned + if ($realfile !~ m@\binclude/uapi/@ && + $line =~ /\b__attribute__\s*\(\s*\(.*aligned/) { + WARN("PREFER_ALIGNED", + "__aligned(size) is preferred over __attribute__((aligned(size)))\n" . $herecurr); + } + +# Check for __attribute__ format(printf, prefer __printf + if ($realfile !~ m@\binclude/uapi/@ && + $line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf/) { + if (WARN("PREFER_PRINTF", + "__printf(string-index, first-to-check) is preferred over __attribute__((format(printf, string-index, first-to-check)))\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf\s*,\s*(.*)\)\s*\)\s*\)/"__printf(" . trim($1) . ")"/ex; + + } + } + +# Check for __attribute__ format(scanf, prefer __scanf + if ($realfile !~ m@\binclude/uapi/@ && + $line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\b/) { + if (WARN("PREFER_SCANF", + "__scanf(string-index, first-to-check) is preferred over __attribute__((format(scanf, string-index, first-to-check)))\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\s*,\s*(.*)\)\s*\)\s*\)/"__scanf(" . trim($1) . ")"/ex; + } + } + +# Check for __attribute__ weak, or __weak declarations (may have link issues) + if ($perl_version_ok && + $line =~ /(?:$Declare|$DeclareMisordered)\s*$Ident\s*$balanced_parens\s*(?:$Attribute)?\s*;/ && + ($line =~ /\b__attribute__\s*\(\s*\(.*\bweak\b/ || + $line =~ /\b__weak\b/)) { + ERROR("WEAK_DECLARATION", + "Using weak declarations can have unintended link defects\n" . $herecurr); + } + +# check for c99 types like uint8_t used outside of uapi/ and tools/ + if ($realfile !~ m@\binclude/uapi/@ && + $realfile !~ m@\btools/@ && + $line =~ /\b($Declare)\s*$Ident\s*[=;,\[]/) { + my $type = $1; + if ($type =~ /\b($typeC99Typedefs)\b/) { + $type = $1; + my $kernel_type = 'u'; + $kernel_type = 's' if ($type =~ /^_*[si]/); + $type =~ /(\d+)/; + $kernel_type .= $1; + if (CHK("PREFER_KERNEL_TYPES", + "Prefer kernel type '$kernel_type' over '$type'\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\b$type\b/$kernel_type/; + } + } + } + +# check for cast of C90 native int or longer types constants + if ($line =~ /(\(\s*$C90_int_types\s*\)\s*)($Constant)\b/) { + my $cast = $1; + my $const = $2; + if (WARN("TYPECAST_INT_CONSTANT", + "Unnecessary typecast of c90 int constant\n" . $herecurr) && + $fix) { + my $suffix = ""; + my $newconst = $const; + $newconst =~ s/${Int_type}$//; + $suffix .= 'U' if ($cast =~ /\bunsigned\b/); + if ($cast =~ /\blong\s+long\b/) { + $suffix .= 'LL'; + } elsif ($cast =~ /\blong\b/) { + $suffix .= 'L'; + } + $fixed[$fixlinenr] =~ s/\Q$cast\E$const\b/$newconst$suffix/; + } + } + +# check for sizeof(&) + if ($line =~ /\bsizeof\s*\(\s*\&/) { + WARN("SIZEOF_ADDRESS", + "sizeof(& should be avoided\n" . $herecurr); + } + +# check for sizeof without parenthesis + if ($line =~ /\bsizeof\s+((?:\*\s*|)$Lval|$Type(?:\s+$Lval|))/) { + if (WARN("SIZEOF_PARENTHESIS", + "sizeof $1 should be sizeof($1)\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\bsizeof\s+((?:\*\s*|)$Lval|$Type(?:\s+$Lval|))/"sizeof(" . trim($1) . ")"/ex; + } + } + +# check for struct spinlock declarations + if ($line =~ /^.\s*\bstruct\s+spinlock\s+\w+\s*;/) { + WARN("USE_SPINLOCK_T", + "struct spinlock should be spinlock_t\n" . $herecurr); + } + +# check for seq_printf uses that could be seq_puts + if ($sline =~ /\bseq_printf\s*\(.*"\s*\)\s*;\s*$/) { + my $fmt = get_quoted_string($line, $rawline); + $fmt =~ s/%%//g; + if ($fmt !~ /%/) { + if (WARN("PREFER_SEQ_PUTS", + "Prefer seq_puts to seq_printf\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\bseq_printf\b/seq_puts/; + } + } + } + +# check for vsprintf extension %p<foo> misuses + if ($perl_version_ok && + defined $stat && + $stat =~ /^\+(?![^\{]*\{\s*).*\b(\w+)\s*\(.*$String\s*,/s && + $1 !~ /^_*volatile_*$/) { + my $stat_real; + + my $lc = $stat =~ tr@\n@@; + $lc = $lc + $linenr; + for (my $count = $linenr; $count <= $lc; $count++) { + my $specifier; + my $extension; + my $bad_specifier = ""; + my $fmt = get_quoted_string($lines[$count - 1], raw_line($count, 0)); + $fmt =~ s/%%//g; + + while ($fmt =~ /(\%[\*\d\.]*p(\w))/g) { + $specifier = $1; + $extension = $2; + if ($extension !~ /[SsBKRraEhMmIiUDdgVCbGNOx]/) { + $bad_specifier = $specifier; + last; + } + if ($extension eq "x" && !defined($stat_real)) { + if (!defined($stat_real)) { + $stat_real = get_stat_real($linenr, $lc); + } + WARN("VSPRINTF_SPECIFIER_PX", + "Using vsprintf specifier '\%px' potentially exposes the kernel memory layout, if you don't really need the address please consider using '\%p'.\n" . "$here\n$stat_real\n"); + } + } + if ($bad_specifier ne "") { + my $stat_real = get_stat_real($linenr, $lc); + my $ext_type = "Invalid"; + my $use = ""; + if ($bad_specifier =~ /p[Ff]/) { + $ext_type = "Deprecated"; + $use = " - use %pS instead"; + $use =~ s/pS/ps/ if ($bad_specifier =~ /pf/); + } + + WARN("VSPRINTF_POINTER_EXTENSION", + "$ext_type vsprintf pointer extension '$bad_specifier'$use\n" . "$here\n$stat_real\n"); + } + } + } + +# Check for misused memsets + if ($perl_version_ok && + defined $stat && + $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*$FuncArg\s*\)/) { + + my $ms_addr = $2; + my $ms_val = $7; + my $ms_size = $12; + + if ($ms_size =~ /^(0x|)0$/i) { + ERROR("MEMSET", + "memset to 0's uses 0 as the 2nd argument, not the 3rd\n" . "$here\n$stat\n"); + } elsif ($ms_size =~ /^(0x|)1$/i) { + WARN("MEMSET", + "single byte memset is suspicious. Swapped 2nd/3rd argument?\n" . "$here\n$stat\n"); + } + } + +# Check for memcpy(foo, bar, ETH_ALEN) that could be ether_addr_copy(foo, bar) +# if ($perl_version_ok && +# defined $stat && +# $stat =~ /^\+(?:.*?)\bmemcpy\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) { +# if (WARN("PREFER_ETHER_ADDR_COPY", +# "Prefer ether_addr_copy() over memcpy() if the Ethernet addresses are __aligned(2)\n" . "$here\n$stat\n") && +# $fix) { +# $fixed[$fixlinenr] =~ s/\bmemcpy\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/ether_addr_copy($2, $7)/; +# } +# } + +# Check for memcmp(foo, bar, ETH_ALEN) that could be ether_addr_equal*(foo, bar) +# if ($perl_version_ok && +# defined $stat && +# $stat =~ /^\+(?:.*?)\bmemcmp\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) { +# WARN("PREFER_ETHER_ADDR_EQUAL", +# "Prefer ether_addr_equal() or ether_addr_equal_unaligned() over memcmp()\n" . "$here\n$stat\n") +# } + +# check for memset(foo, 0x0, ETH_ALEN) that could be eth_zero_addr +# check for memset(foo, 0xFF, ETH_ALEN) that could be eth_broadcast_addr +# if ($perl_version_ok && +# defined $stat && +# $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) { +# +# my $ms_val = $7; +# +# if ($ms_val =~ /^(?:0x|)0+$/i) { +# if (WARN("PREFER_ETH_ZERO_ADDR", +# "Prefer eth_zero_addr over memset()\n" . "$here\n$stat\n") && +# $fix) { +# $fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*,\s*ETH_ALEN\s*\)/eth_zero_addr($2)/; +# } +# } elsif ($ms_val =~ /^(?:0xff|255)$/i) { +# if (WARN("PREFER_ETH_BROADCAST_ADDR", +# "Prefer eth_broadcast_addr() over memset()\n" . "$here\n$stat\n") && +# $fix) { +# $fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*,\s*ETH_ALEN\s*\)/eth_broadcast_addr($2)/; +# } +# } +# } + +# typecasts on min/max could be min_t/max_t + if ($perl_version_ok && + defined $stat && + $stat =~ /^\+(?:.*?)\b(min|max)\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\)/) { + if (defined $2 || defined $7) { + my $call = $1; + my $cast1 = deparenthesize($2); + my $arg1 = $3; + my $cast2 = deparenthesize($7); + my $arg2 = $8; + my $cast; + + if ($cast1 ne "" && $cast2 ne "" && $cast1 ne $cast2) { + $cast = "$cast1 or $cast2"; + } elsif ($cast1 ne "") { + $cast = $cast1; + } else { + $cast = $cast2; + } + WARN("MINMAX", + "$call() should probably be ${call}_t($cast, $arg1, $arg2)\n" . "$here\n$stat\n"); + } + } + +# check usleep_range arguments + if ($perl_version_ok && + defined $stat && + $stat =~ /^\+(?:.*?)\busleep_range\s*\(\s*($FuncArg)\s*,\s*($FuncArg)\s*\)/) { + my $min = $1; + my $max = $7; + if ($min eq $max) { + WARN("USLEEP_RANGE", + "usleep_range should not use min == max args; see Documentation/timers/timers-howto.txt\n" . "$here\n$stat\n"); + } elsif ($min =~ /^\d+$/ && $max =~ /^\d+$/ && + $min > $max) { + WARN("USLEEP_RANGE", + "usleep_range args reversed, use min then max; see Documentation/timers/timers-howto.txt\n" . "$here\n$stat\n"); + } + } + +# check for naked sscanf + if ($perl_version_ok && + defined $stat && + $line =~ /\bsscanf\b/ && + ($stat !~ /$Ident\s*=\s*sscanf\s*$balanced_parens/ && + $stat !~ /\bsscanf\s*$balanced_parens\s*(?:$Compare)/ && + $stat !~ /(?:$Compare)\s*\bsscanf\s*$balanced_parens/)) { + my $lc = $stat =~ tr@\n@@; + $lc = $lc + $linenr; + my $stat_real = get_stat_real($linenr, $lc); + WARN("NAKED_SSCANF", + "unchecked sscanf return value\n" . "$here\n$stat_real\n"); + } + +# check for simple sscanf that should be kstrto<foo> + if ($perl_version_ok && + defined $stat && + $line =~ /\bsscanf\b/) { + my $lc = $stat =~ tr@\n@@; + $lc = $lc + $linenr; + my $stat_real = get_stat_real($linenr, $lc); + if ($stat_real =~ /\bsscanf\b\s*\(\s*$FuncArg\s*,\s*("[^"]+")/) { + my $format = $6; + my $count = $format =~ tr@%@%@; + if ($count == 1 && + $format =~ /^"\%(?i:ll[udxi]|[udxi]ll|ll|[hl]h?[udxi]|[udxi][hl]h?|[hl]h?|[udxi])"$/) { + WARN("SSCANF_TO_KSTRTO", + "Prefer kstrto<type> to single variable sscanf\n" . "$here\n$stat_real\n"); + } + } + } + +# check for new externs in .h files. + if ($realfile =~ /\.h$/ && + $line =~ /^\+\s*(extern\s+)$Type\s*$Ident\s*\(/s) { + if (CHK("AVOID_EXTERNS", + "extern prototypes should be avoided in .h files\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/(.*)\bextern\b\s*(.*)/$1$2/; + } + } + +# check for new externs in .c files. + if ($realfile =~ /\.c$/ && defined $stat && + $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s) + { + my $function_name = $1; + my $paren_space = $2; + + my $s = $stat; + if (defined $cond) { + substr($s, 0, length($cond), ''); + } + if ($s =~ /^\s*;/ && + $function_name ne 'uninitialized_var') + { + WARN("AVOID_EXTERNS", + "externs should be avoided in .c files\n" . $herecurr); + } + + if ($paren_space =~ /\n/) { + WARN("FUNCTION_ARGUMENTS", + "arguments for function declarations should follow identifier\n" . $herecurr); + } + + } elsif ($realfile =~ /\.c$/ && defined $stat && + $stat =~ /^.\s*extern\s+/) + { + WARN("AVOID_EXTERNS", + "externs should be avoided in .c files\n" . $herecurr); + } + +# check for function declarations that have arguments without identifier names + if (defined $stat && + $stat =~ /^.\s*(?:extern\s+)?$Type\s*(?:$Ident|\(\s*\*\s*$Ident\s*\))\s*\(\s*([^{]+)\s*\)\s*;/s && + $1 ne "void") { + my $args = trim($1); + while ($args =~ m/\s*($Type\s*(?:$Ident|\(\s*\*\s*$Ident?\s*\)\s*$balanced_parens)?)/g) { + my $arg = trim($1); + if ($arg =~ /^$Type$/ && $arg !~ /enum\s+$Ident$/) { + WARN("FUNCTION_ARGUMENTS", + "function definition argument '$arg' should also have an identifier name\n" . $herecurr); + } + } + } + +# check for function definitions + if ($perl_version_ok && + defined $stat && + $stat =~ /^.\s*(?:$Storage\s+)?$Type\s*($Ident)\s*$balanced_parens\s*{/s) { + $context_function = $1; + +# check for multiline function definition with misplaced open brace + my $ok = 0; + my $cnt = statement_rawlines($stat); + my $herectx = $here . "\n"; + for (my $n = 0; $n < $cnt; $n++) { + my $rl = raw_line($linenr, $n); + $herectx .= $rl . "\n"; + $ok = 1 if ($rl =~ /^[ \+]\{/); + $ok = 1 if ($rl =~ /\{/ && $n == 0); + last if $rl =~ /^[ \+].*\{/; + } + if (!$ok) { + ERROR("OPEN_BRACE", + "open brace '{' following function definitions go on the next line\n" . $herectx); + } + } + +# checks for new __setup's + if ($rawline =~ /\b__setup\("([^"]*)"/) { + my $name = $1; + + if (!grep(/$name/, @setup_docs)) { + CHK("UNDOCUMENTED_SETUP", + "__setup appears un-documented -- check Documentation/admin-guide/kernel-parameters.rst\n" . $herecurr); + } + } + +# check for pointless casting of kmalloc return + if ($line =~ /\*\s*\)\s*[kv][czm]alloc(_node){0,1}\b/) { + WARN("UNNECESSARY_CASTS", + "unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr); + } + +# alloc style +# p = alloc(sizeof(struct foo), ...) should be p = alloc(sizeof(*p), ...) + if ($perl_version_ok && + $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*([kv][mz]alloc(?:_node)?)\s*\(\s*(sizeof\s*\(\s*struct\s+$Lval\s*\))/) { + CHK("ALLOC_SIZEOF_STRUCT", + "Prefer $3(sizeof(*$1)...) over $3($4...)\n" . $herecurr); + } + +# check for k[mz]alloc with multiplies that could be kmalloc_array/kcalloc + if ($perl_version_ok && + defined $stat && + $stat =~ /^\+\s*($Lval)\s*\=\s*(?:$balanced_parens)?\s*(k[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)\s*,/) { + my $oldfunc = $3; + my $a1 = $4; + my $a2 = $10; + my $newfunc = "kmalloc_array"; + $newfunc = "kcalloc" if ($oldfunc eq "kzalloc"); + my $r1 = $a1; + my $r2 = $a2; + if ($a1 =~ /^sizeof\s*\S/) { + $r1 = $a2; + $r2 = $a1; + } + if ($r1 !~ /^sizeof\b/ && $r2 =~ /^sizeof\s*\S/ && + !($r1 =~ /^$Constant$/ || $r1 =~ /^[A-Z_][A-Z0-9_]*$/)) { + my $cnt = statement_rawlines($stat); + my $herectx = get_stat_here($linenr, $cnt, $here); + + if (WARN("ALLOC_WITH_MULTIPLY", + "Prefer $newfunc over $oldfunc with multiply\n" . $herectx) && + $cnt == 1 && + $fix) { + $fixed[$fixlinenr] =~ s/\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*(k[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)/$1 . ' = ' . "$newfunc(" . trim($r1) . ', ' . trim($r2)/e; + } + } + } + +# check for krealloc arg reuse + if ($perl_version_ok && + $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*krealloc\s*\(\s*($Lval)\s*,/ && + $1 eq $3) { + WARN("KREALLOC_ARG_REUSE", + "Reusing the krealloc arg is almost always a bug\n" . $herecurr); + } + +# check for alloc argument mismatch + if ($line =~ /\b(kcalloc|kmalloc_array)\s*\(\s*sizeof\b/) { + WARN("ALLOC_ARRAY_ARGS", + "$1 uses number as first arg, sizeof is generally wrong\n" . $herecurr); + } + +# check for multiple semicolons + if ($line =~ /;\s*;\s*$/) { + if (WARN("ONE_SEMICOLON", + "Statements terminations use 1 semicolon\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/(\s*;\s*){2,}$/;/g; + } + } + +# check for #defines like: 1 << <digit> that could be BIT(digit), it is not exported to uapi + if ($realfile !~ m@^include/uapi/@ && + $line =~ /#\s*define\s+\w+\s+\(?\s*1\s*([ulUL]*)\s*\<\<\s*(?:\d+|$Ident)\s*\)?/) { + my $ull = ""; + $ull = "_ULL" if (defined($1) && $1 =~ /ll/i); + if (CHK("BIT_MACRO", + "Prefer using the BIT$ull macro\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\(?\s*1\s*[ulUL]*\s*<<\s*(\d+|$Ident)\s*\)?/BIT${ull}($1)/; + } + } + +# check for #if defined CONFIG_<FOO> || defined CONFIG_<FOO>_MODULE + if ($line =~ /^\+\s*#\s*if\s+defined(?:\s*\(?\s*|\s+)(CONFIG_[A-Z_]+)\s*\)?\s*\|\|\s*defined(?:\s*\(?\s*|\s+)\1_MODULE\s*\)?\s*$/) { + my $config = $1; + if (WARN("PREFER_IS_ENABLED", + "Prefer IS_ENABLED(<FOO>) to CONFIG_<FOO> || CONFIG_<FOO>_MODULE\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] = "\+#if IS_ENABLED($config)"; + } + } + +# check for case / default statements not preceded by break/fallthrough/switch + if ($line =~ /^.\s*(?:case\s+(?:$Ident|$Constant)\s*|default):/) { + my $has_break = 0; + my $has_statement = 0; + my $count = 0; + my $prevline = $linenr; + while ($prevline > 1 && ($file || $count < 3) && !$has_break) { + $prevline--; + my $rline = $rawlines[$prevline - 1]; + my $fline = $lines[$prevline - 1]; + last if ($fline =~ /^\@\@/); + next if ($fline =~ /^\-/); + next if ($fline =~ /^.(?:\s*(?:case\s+(?:$Ident|$Constant)[\s$;]*|default):[\s$;]*)*$/); + $has_break = 1 if ($rline =~ /fall[\s_-]*(through|thru)/i); + next if ($fline =~ /^.[\s$;]*$/); + $has_statement = 1; + $count++; + $has_break = 1 if ($fline =~ /\bswitch\b|\b(?:break\s*;[\s$;]*$|exit\s*\(\b|return\b|goto\b|continue\b)/); + } + if (!$has_break && $has_statement) { + WARN("MISSING_BREAK", + "Possible switch case/default not preceded by break or fallthrough comment\n" . $herecurr); + } + } + +# check for switch/default statements without a break; + if ($perl_version_ok && + defined $stat && + $stat =~ /^\+[$;\s]*(?:case[$;\s]+\w+[$;\s]*:[$;\s]*|)*[$;\s]*\bdefault[$;\s]*:[$;\s]*;/g) { + my $cnt = statement_rawlines($stat); + my $herectx = get_stat_here($linenr, $cnt, $here); + + WARN("DEFAULT_NO_BREAK", + "switch default: should use break\n" . $herectx); + } + +# check for gcc specific __FUNCTION__ + if ($line =~ /\b__FUNCTION__\b/) { + if (WARN("USE_FUNC", + "__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\b__FUNCTION__\b/__func__/g; + } + } + +# check for uses of __DATE__, __TIME__, __TIMESTAMP__ + while ($line =~ /\b(__(?:DATE|TIME|TIMESTAMP)__)\b/g) { + ERROR("DATE_TIME", + "Use of the '$1' macro makes the build non-deterministic\n" . $herecurr); + } + +# check for use of yield() + if ($line =~ /\byield\s*\(\s*\)/) { + WARN("YIELD", + "Using yield() is generally wrong. See yield() kernel-doc (sched/core.c)\n" . $herecurr); + } + +# check for comparisons against true and false + if ($line =~ /\+\s*(.*?)\b(true|false|$Lval)\s*(==|\!=)\s*(true|false|$Lval)\b(.*)$/i) { + my $lead = $1; + my $arg = $2; + my $test = $3; + my $otype = $4; + my $trail = $5; + my $op = "!"; + + ($arg, $otype) = ($otype, $arg) if ($arg =~ /^(?:true|false)$/i); + + my $type = lc($otype); + if ($type =~ /^(?:true|false)$/) { + if (("$test" eq "==" && "$type" eq "true") || + ("$test" eq "!=" && "$type" eq "false")) { + $op = ""; + } + + CHK("BOOL_COMPARISON", + "Using comparison to $otype is error prone\n" . $herecurr); + +## maybe suggesting a correct construct would better +## "Using comparison to $otype is error prone. Perhaps use '${lead}${op}${arg}${trail}'\n" . $herecurr); + + } + } + +# check for bool bitfields + if ($sline =~ /^.\s+bool\s*$Ident\s*:\s*\d+\s*;/) { + WARN("BOOL_BITFIELD", + "Avoid using bool as bitfield. Prefer bool bitfields as unsigned int or u<8|16|32>\n" . $herecurr); + } + +# check for bool use in .h files + if ($realfile =~ /\.h$/ && + $sline =~ /^.\s+bool\s*$Ident\s*(?::\s*d+\s*)?;/) { + CHK("BOOL_MEMBER", + "Avoid using bool structure members because of possible alignment issues - see: https://lkml.org/lkml/2017/11/21/384\n" . $herecurr); + } + +# check for semaphores initialized locked + if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) { + WARN("CONSIDER_COMPLETION", + "consider using a completion\n" . $herecurr); + } + +# recommend kstrto* over simple_strto* and strict_strto* + if ($line =~ /\b((simple|strict)_(strto(l|ll|ul|ull)))\s*\(/) { + WARN("CONSIDER_KSTRTO", + "$1 is obsolete, use k$3 instead\n" . $herecurr); + } + +# check for __initcall(), use device_initcall() explicitly or more appropriate function please + if ($line =~ /^.\s*__initcall\s*\(/) { + WARN("USE_DEVICE_INITCALL", + "please use device_initcall() or more appropriate function instead of __initcall() (see include/linux/init.h)\n" . $herecurr); + } + +# check for spin_is_locked(), suggest lockdep instead + if ($line =~ /\bspin_is_locked\(/) { + WARN("USE_LOCKDEP", + "Where possible, use lockdep_assert_held instead of assertions based on spin_is_locked\n" . $herecurr); + } + +# check for deprecated apis + if ($line =~ /\b($deprecated_apis_search)\b\s*\(/) { + my $deprecated_api = $1; + my $new_api = $deprecated_apis{$deprecated_api}; + WARN("DEPRECATED_API", + "Deprecated use of '$deprecated_api', prefer '$new_api' instead\n" . $herecurr); + } + +# check for various structs that are normally const (ops, kgdb, device_tree) +# and avoid what seem like struct definitions 'struct foo {' + if ($line !~ /\bconst\b/ && + $line =~ /\bstruct\s+($const_structs)\b(?!\s*\{)/) { + WARN("CONST_STRUCT", + "struct $1 should normally be const\n" . $herecurr); + } + +# use of NR_CPUS is usually wrong +# ignore definitions of NR_CPUS and usage to define arrays as likely right + if ($line =~ /\bNR_CPUS\b/ && + $line !~ /^.\s*\s*#\s*if\b.*\bNR_CPUS\b/ && + $line !~ /^.\s*\s*#\s*define\b.*\bNR_CPUS\b/ && + $line !~ /^.\s*$Declare\s.*\[[^\]]*NR_CPUS[^\]]*\]/ && + $line !~ /\[[^\]]*\.\.\.[^\]]*NR_CPUS[^\]]*\]/ && + $line !~ /\[[^\]]*NR_CPUS[^\]]*\.\.\.[^\]]*\]/) + { + WARN("NR_CPUS", + "usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_possible_cpu(), etc\n" . $herecurr); + } + +# Use of __ARCH_HAS_<FOO> or ARCH_HAVE_<BAR> is wrong. + if ($line =~ /\+\s*#\s*define\s+((?:__)?ARCH_(?:HAS|HAVE)\w*)\b/) { + ERROR("DEFINE_ARCH_HAS", + "#define of '$1' is wrong - use Kconfig variables or standard guards instead\n" . $herecurr); + } + +# likely/unlikely comparisons similar to "(likely(foo) > 0)" + if ($perl_version_ok && + $line =~ /\b((?:un)?likely)\s*\(\s*$FuncArg\s*\)\s*$Compare/) { + WARN("LIKELY_MISUSE", + "Using $1 should generally have parentheses around the comparison\n" . $herecurr); + } + +# whine mightly about in_atomic + if ($line =~ /\bin_atomic\s*\(/) { + if ($realfile =~ m@^drivers/@) { + ERROR("IN_ATOMIC", + "do not use in_atomic in drivers\n" . $herecurr); + } elsif ($realfile !~ m@^kernel/@) { + WARN("IN_ATOMIC", + "use of in_atomic() is incorrect outside core kernel code\n" . $herecurr); + } + } + +# check for mutex_trylock_recursive usage + if ($line =~ /mutex_trylock_recursive/) { + ERROR("LOCKING", + "recursive locking is bad, do not use this ever.\n" . $herecurr); + } + +# check for lockdep_set_novalidate_class + if ($line =~ /^.\s*lockdep_set_novalidate_class\s*\(/ || + $line =~ /__lockdep_no_validate__\s*\)/ ) { + if ($realfile !~ m@^kernel/lockdep@ && + $realfile !~ m@^include/linux/lockdep@ && + $realfile !~ m@^drivers/base/core@) { + ERROR("LOCKDEP", + "lockdep_no_validate class is reserved for device->mutex.\n" . $herecurr); + } + } + + if ($line =~ /debugfs_create_\w+.*\b$mode_perms_world_writable\b/ || + $line =~ /DEVICE_ATTR.*\b$mode_perms_world_writable\b/) { + WARN("EXPORTED_WORLD_WRITABLE", + "Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr); + } + +# check for DEVICE_ATTR uses that could be DEVICE_ATTR_<FOO> +# and whether or not function naming is typical and if +# DEVICE_ATTR permissions uses are unusual too + if ($perl_version_ok && + defined $stat && + $stat =~ /\bDEVICE_ATTR\s*\(\s*(\w+)\s*,\s*\(?\s*(\s*(?:${multi_mode_perms_string_search}|0[0-7]{3,3})\s*)\s*\)?\s*,\s*(\w+)\s*,\s*(\w+)\s*\)/) { + my $var = $1; + my $perms = $2; + my $show = $3; + my $store = $4; + my $octal_perms = perms_to_octal($perms); + if ($show =~ /^${var}_show$/ && + $store =~ /^${var}_store$/ && + $octal_perms eq "0644") { + if (WARN("DEVICE_ATTR_RW", + "Use DEVICE_ATTR_RW\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\bDEVICE_ATTR\s*\(\s*$var\s*,\s*\Q$perms\E\s*,\s*$show\s*,\s*$store\s*\)/DEVICE_ATTR_RW(${var})/; + } + } elsif ($show =~ /^${var}_show$/ && + $store =~ /^NULL$/ && + $octal_perms eq "0444") { + if (WARN("DEVICE_ATTR_RO", + "Use DEVICE_ATTR_RO\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\bDEVICE_ATTR\s*\(\s*$var\s*,\s*\Q$perms\E\s*,\s*$show\s*,\s*NULL\s*\)/DEVICE_ATTR_RO(${var})/; + } + } elsif ($show =~ /^NULL$/ && + $store =~ /^${var}_store$/ && + $octal_perms eq "0200") { + if (WARN("DEVICE_ATTR_WO", + "Use DEVICE_ATTR_WO\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\bDEVICE_ATTR\s*\(\s*$var\s*,\s*\Q$perms\E\s*,\s*NULL\s*,\s*$store\s*\)/DEVICE_ATTR_WO(${var})/; + } + } elsif ($octal_perms eq "0644" || + $octal_perms eq "0444" || + $octal_perms eq "0200") { + my $newshow = "$show"; + $newshow = "${var}_show" if ($show ne "NULL" && $show ne "${var}_show"); + my $newstore = $store; + $newstore = "${var}_store" if ($store ne "NULL" && $store ne "${var}_store"); + my $rename = ""; + if ($show ne $newshow) { + $rename .= " '$show' to '$newshow'"; + } + if ($store ne $newstore) { + $rename .= " '$store' to '$newstore'"; + } + WARN("DEVICE_ATTR_FUNCTIONS", + "Consider renaming function(s)$rename\n" . $herecurr); + } else { + WARN("DEVICE_ATTR_PERMS", + "DEVICE_ATTR unusual permissions '$perms' used\n" . $herecurr); + } + } + +# Mode permission misuses where it seems decimal should be octal +# This uses a shortcut match to avoid unnecessary uses of a slow foreach loop +# o Ignore module_param*(...) uses with a decimal 0 permission as that has a +# specific definition of not visible in sysfs. +# o Ignore proc_create*(...) uses with a decimal 0 permission as that means +# use the default permissions + if ($perl_version_ok && + defined $stat && + $line =~ /$mode_perms_search/) { + foreach my $entry (@mode_permission_funcs) { + my $func = $entry->[0]; + my $arg_pos = $entry->[1]; + + my $lc = $stat =~ tr@\n@@; + $lc = $lc + $linenr; + my $stat_real = get_stat_real($linenr, $lc); + + my $skip_args = ""; + if ($arg_pos > 1) { + $arg_pos--; + $skip_args = "(?:\\s*$FuncArg\\s*,\\s*){$arg_pos,$arg_pos}"; + } + my $test = "\\b$func\\s*\\(${skip_args}($FuncArg(?:\\|\\s*$FuncArg)*)\\s*[,\\)]"; + if ($stat =~ /$test/) { + my $val = $1; + $val = $6 if ($skip_args ne ""); + if (!($func =~ /^(?:module_param|proc_create)/ && $val eq "0") && + (($val =~ /^$Int$/ && $val !~ /^$Octal$/) || + ($val =~ /^$Octal$/ && length($val) ne 4))) { + ERROR("NON_OCTAL_PERMISSIONS", + "Use 4 digit octal (0777) not decimal permissions\n" . "$here\n" . $stat_real); + } + if ($val =~ /^$Octal$/ && (oct($val) & 02)) { + ERROR("EXPORTED_WORLD_WRITABLE", + "Exporting writable files is usually an error. Consider more restrictive permissions.\n" . "$here\n" . $stat_real); + } + } + } + } + +# check for uses of S_<PERMS> that could be octal for readability + while ($line =~ m{\b($multi_mode_perms_string_search)\b}g) { + my $oval = $1; + my $octal = perms_to_octal($oval); + if (WARN("SYMBOLIC_PERMS", + "Symbolic permissions '$oval' are not preferred. Consider using octal permissions '$octal'.\n" . $herecurr) && + $fix) { + $fixed[$fixlinenr] =~ s/\Q$oval\E/$octal/; + } + } + +# validate content of MODULE_LICENSE against list from include/linux/module.h + if ($line =~ /\bMODULE_LICENSE\s*\(\s*($String)\s*\)/) { + my $extracted_string = get_quoted_string($line, $rawline); + my $valid_licenses = qr{ + GPL| + GPL\ v2| + GPL\ and\ additional\ rights| + Dual\ BSD/GPL| + Dual\ MIT/GPL| + Dual\ MPL/GPL| + Proprietary + }x; + if ($extracted_string !~ /^"(?:$valid_licenses)"$/x) { + WARN("MODULE_LICENSE", + "unknown module license " . $extracted_string . "\n" . $herecurr); + } + } + } + + # If we have no input at all, then there is nothing to report on + # so just keep quiet. + if ($#rawlines == -1) { + exit(0); + } + + # In mailback mode only produce a report in the negative, for + # things that appear to be patches. + if ($mailback && ($clean == 1 || !$is_patch)) { + exit(0); + } + + # This is not a patch, and we are are in 'no-patch' mode so + # just keep quiet. + if (!$chk_patch && !$is_patch) { + exit(0); + } + + if (!$is_patch && $filename !~ /cover-letter\.patch$/) { + ERROR("NOT_UNIFIED_DIFF", + "Does not appear to be a unified-diff format patch\n"); + } + if ($is_patch && $has_commit_log && $chk_signoff) { + if ($signoff == 0) { + ERROR("MISSING_SIGN_OFF", + "Missing Signed-off-by: line(s)\n"); + } elsif (!$authorsignoff) { + WARN("NO_AUTHOR_SIGN_OFF", + "Missing Signed-off-by: line by nominal patch author '$author'\n"); + } + } + + print report_dump(); + if ($summary && !($clean == 1 && $quiet == 1)) { + print "$filename " if ($summary_file); + print "total: $cnt_error errors, $cnt_warn warnings, " . + (($check)? "$cnt_chk checks, " : "") . + "$cnt_lines lines checked\n"; + } + + if ($quiet == 0) { + # If there were any defects found and not already fixing them + if (!$clean and !$fix) { + print << "EOM" + +NOTE: For some of the reported defects, checkpatch may be able to + mechanically convert to the typical style using --fix or --fix-inplace. +EOM + } + # If there were whitespace errors which cleanpatch can fix + # then suggest that. + if ($rpt_cleaners) { + $rpt_cleaners = 0; + print << "EOM" + +NOTE: Whitespace errors detected. + You may wish to use scripts/cleanpatch or scripts/cleanfile +EOM + } + } + + if ($clean == 0 && $fix && + ("@rawlines" ne "@fixed" || + $#fixed_inserted >= 0 || $#fixed_deleted >= 0)) { + my $newfile = $filename; + $newfile .= ".EXPERIMENTAL-checkpatch-fixes" if (!$fix_inplace); + my $linecount = 0; + my $f; + + @fixed = fix_inserted_deleted_lines(\@fixed, \@fixed_inserted, \@fixed_deleted); + + open($f, '>', $newfile) + or die "$P: Can't open $newfile for write\n"; + foreach my $fixed_line (@fixed) { + $linecount++; + if ($file) { + if ($linecount > 3) { + $fixed_line =~ s/^\+//; + print $f $fixed_line . "\n"; + } + } else { + print $f $fixed_line . "\n"; + } + } + close($f); + + if (!$quiet) { + print << "EOM"; + +Wrote EXPERIMENTAL --fix correction(s) to '$newfile' + +Do _NOT_ trust the results written to this file. +Do _NOT_ submit these changes without inspecting them for correctness. + +This EXPERIMENTAL file is simply a convenience to help rewrite patches. +No warranties, expressed or implied... +EOM + } + } + + if ($quiet == 0) { + print "\n"; + if ($clean == 1) { + print "$vname has no obvious style problems and is ready for submission.\n"; + } else { + print "$vname has style problems, please review.\n"; + } + } + return $clean; +} diff --git a/Checkstyle/checkstyle b/Checkstyle/checkstyle new file mode 100755 index 0000000..052c674 --- /dev/null +++ b/Checkstyle/checkstyle @@ -0,0 +1,55 @@ +#!/bin/bash +################################################################################ +# +# Author: Alejandro Colomar Andrés +# +# This script checks the style in all files of type (.c .cpp .h .hpp) in the +# selected dirs. +# + + +################################################################################ +# variables # +################################################################################ +dirs=( + ../src/ + ../inc/ + ../modules/ + ../libalx/ +) + + +################################################################################ +# functions # +################################################################################ +check_style() +{ + + ./checkpatch.pl --show-types --no-tree -f $1 \ + --ignore SPDX_LICENSE_TAG,IF_0,SPACING,BRACKET_SPACE +} + +find_source_files() +{ + + source_files=$(find $1 -type f \( -iname \*.c -o -iname \*.h -o -iname \*.cpp -o -iname \*.hpp \)) +} + + +################################################################################ +# main # +################################################################################ +for i in ${dirs[*]} +do + find_source_files ${i} + + for j in ${source_files} + do + check_style ${j} + done +done + + +################################################################################ +# end of file # +################################################################################ diff --git a/Checkstyle/spelling.txt b/Checkstyle/spelling.txt new file mode 100644 index 0000000..517d0c3 --- /dev/null +++ b/Checkstyle/spelling.txt @@ -0,0 +1,1344 @@ +# Originally from Debian's Lintian tool. Various false positives have been +# removed, and various additions have been made as they've been discovered +# in the kernel source. +# +# License: GPLv2 +# +# The format of each line is: +# mistake||correction +# +abandonning||abandoning +abigious||ambiguous +abitrate||arbitrate +abord||abort +aboslute||absolute +abov||above +abreviated||abbreviated +absense||absence +absolut||absolute +absoulte||absolute +acccess||access +acceess||access +acceleratoin||acceleration +accelleration||acceleration +accesing||accessing +accesnt||accent +accessable||accessible +accesss||access +accidentaly||accidentally +accidentually||accidentally +acclerated||accelerated +accoding||according +accomodate||accommodate +accomodates||accommodates +accordign||according +accoring||according +accout||account +accquire||acquire +accquired||acquired +accross||across +acessable||accessible +acess||access +achitecture||architecture +acient||ancient +acitions||actions +acitve||active +acknowldegement||acknowledgment +acknowledgement||acknowledgment +ackowledge||acknowledge +ackowledged||acknowledged +acording||according +activete||activate +actived||activated +actualy||actually +acumulating||accumulating +acumulator||accumulator +adapater||adapter +addional||additional +additionaly||additionally +additonal||additional +addres||address +adddress||address +addreses||addresses +addresss||address +addrress||address +aditional||additional +aditionally||additionally +aditionaly||additionally +adminstrative||administrative +adress||address +adresses||addresses +adrresses||addresses +advertisment||advertisement +adviced||advised +afecting||affecting +againt||against +agaist||against +aggreataon||aggregation +aggreation||aggregation +albumns||albums +alegorical||allegorical +algined||aligned +algorith||algorithm +algorithmical||algorithmically +algoritm||algorithm +algoritms||algorithms +algorrithm||algorithm +algorritm||algorithm +aligment||alignment +alignement||alignment +allign||align +alligned||aligned +alllocate||allocate +alloated||allocated +allocatote||allocate +allocatrd||allocated +allocte||allocate +allpication||application +alocate||allocate +alogirhtms||algorithms +alogrithm||algorithm +alot||a lot +alow||allow +alows||allows +altough||although +alue||value +ambigious||ambiguous +amoung||among +amout||amount +amplifer||amplifier +an union||a union +an user||a user +an userspace||a userspace +an one||a one +analysator||analyzer +ang||and +anniversery||anniversary +annoucement||announcement +anomolies||anomalies +anomoly||anomaly +anway||anyway +aplication||application +appearence||appearance +applicaion||application +appliction||application +applictions||applications +applys||applies +appplications||applications +appropiate||appropriate +appropriatly||appropriately +approriate||appropriate +approriately||appropriately +apropriate||appropriate +aquainted||acquainted +aquired||acquired +aquisition||acquisition +arbitary||arbitrary +architechture||architecture +arguement||argument +arguements||arguments +aritmetic||arithmetic +arne't||aren't +arraival||arrival +artifical||artificial +artillary||artillery +asign||assign +asser||assert +assertation||assertion +assiged||assigned +assigment||assignment +assigments||assignments +assistent||assistant +assocation||association +associcated||associated +assotiated||associated +asssert||assert +assum||assume +assumtpion||assumption +asuming||assuming +asycronous||asynchronous +asynchnous||asynchronous +asynchromous||asynchronous +asymetric||asymmetric +asymmeric||asymmetric +atomatically||automatically +atomicly||atomically +atempt||attempt +attachement||attachment +attched||attached +attemps||attempts +attemping||attempting +attruibutes||attributes +authentification||authentication +automaticaly||automatically +automaticly||automatically +automatize||automate +automatized||automated +automatizes||automates +autonymous||autonomous +auxillary||auxiliary +auxilliary||auxiliary +avaiable||available +avaible||available +availabe||available +availabled||available +availablity||availability +availaible||available +availale||available +availavility||availability +availble||available +availiable||available +availible||available +avalable||available +avaliable||available +aysnc||async +backgroud||background +backword||backward +backwords||backwards +bahavior||behavior +bakup||backup +baloon||balloon +baloons||balloons +bandwith||bandwidth +banlance||balance +batery||battery +beacuse||because +becasue||because +becomming||becoming +becuase||because +beeing||being +befor||before +begining||beginning +beter||better +betweeen||between +bianries||binaries +bitmast||bitmask +boardcast||broadcast +borad||board +boundry||boundary +brievely||briefly +broadcat||broadcast +bufufer||buffer +cacluated||calculated +caculate||calculate +caculation||calculation +cadidate||candidate +calender||calendar +calescing||coalescing +calle||called +callibration||calibration +calucate||calculate +calulate||calculate +cancelation||cancellation +cancle||cancel +capabilites||capabilities +capabilty||capability +capabitilies||capabilities +capatibilities||capabilities +capapbilities||capabilities +caputure||capture +carefuly||carefully +cariage||carriage +catagory||category +cehck||check +challange||challenge +challanges||challenges +chache||cache +chanell||channel +changable||changeable +chanined||chained +channle||channel +channnel||channel +charachter||character +charachters||characters +charactor||character +charater||character +charaters||characters +charcter||character +chcek||check +chck||check +checksumed||checksummed +checksuming||checksumming +childern||children +childs||children +chiled||child +chked||checked +chnage||change +chnages||changes +chnnel||channel +choosen||chosen +chouse||chose +circumvernt||circumvent +claread||cleared +clared||cleared +closeing||closing +clustred||clustered +coexistance||coexistence +collapsable||collapsible +colorfull||colorful +comand||command +comit||commit +commerical||commercial +comming||coming +comminucation||communication +commited||committed +commiting||committing +committ||commit +commoditiy||commodity +comsume||consume +comsumer||consumer +comsuming||consuming +compability||compatibility +compaibility||compatibility +compatability||compatibility +compatable||compatible +compatibiliy||compatibility +compatibilty||compatibility +compatiblity||compatibility +competion||completion +compilant||compliant +compleatly||completely +completition||completion +completly||completely +complient||compliant +componnents||components +compoment||component +compres||compress +compresion||compression +comression||compression +comunication||communication +conbination||combination +conditionaly||conditionally +conected||connected +conector||connector +connecetd||connected +configuartion||configuration +configuation||configuration +configuratoin||configuration +configuraton||configuration +configuretion||configuration +configutation||configuration +conider||consider +conjuction||conjunction +connectinos||connections +connnection||connection +connnections||connections +consistancy||consistency +consistant||consistent +containes||contains +containts||contains +contaisn||contains +contant||contact +contence||contents +continious||continuous +continous||continuous +continously||continuously +continueing||continuing +contraints||constraints +contruct||construct +contol||control +contoller||controller +controled||controlled +controler||controller +controll||control +contruction||construction +contry||country +conuntry||country +convertion||conversion +convertor||converter +convienient||convenient +convinient||convenient +corected||corrected +correponding||corresponding +correponds||corresponds +correspoding||corresponding +cotrol||control +cound||could +couter||counter +coutner||counter +cryptocraphic||cryptographic +cunter||counter +curently||currently +cylic||cyclic +dafault||default +deafult||default +deamon||daemon +decompres||decompress +decsribed||described +decription||description +dectected||detected +defailt||default +defferred||deferred +definate||definite +definately||definitely +defintion||definition +defintions||definitions +defualt||default +defult||default +deintializing||deinitializing +deintialize||deinitialize +deintialized||deinitialized +deivce||device +delared||declared +delare||declare +delares||declares +delaring||declaring +delemiter||delimiter +demodualtor||demodulator +demension||dimension +dependancies||dependencies +dependancy||dependency +dependant||dependent +depreacted||deprecated +depreacte||deprecate +desactivate||deactivate +desciptor||descriptor +desciptors||descriptors +descripton||description +descrition||description +descritptor||descriptor +desctiptor||descriptor +desriptor||descriptor +desriptors||descriptors +destionation||destination +destoried||destroyed +destory||destroy +destoryed||destroyed +destorys||destroys +destroied||destroyed +detabase||database +deteced||detected +develope||develop +developement||development +developped||developed +developpement||development +developper||developer +developpment||development +deveolpment||development +devided||divided +deviece||device +diable||disable +dictionnary||dictionary +didnt||didn't +diferent||different +differrence||difference +diffrent||different +differenciate||differentiate +diffrentiate||differentiate +difinition||definition +dimesions||dimensions +diplay||display +directon||direction +direectly||directly +diregard||disregard +disassocation||disassociation +disapear||disappear +disapeared||disappeared +disappared||disappeared +disbale||disable +disbaled||disabled +disble||disable +disbled||disabled +disconnet||disconnect +discontinous||discontinuous +disharge||discharge +dispertion||dispersion +dissapears||disappears +distiction||distinction +divisable||divisible +divsiors||divisors +docuentation||documentation +documantation||documentation +documentaion||documentation +documment||document +doesnt||doesn't +dorp||drop +dosen||doesn +downlad||download +downlads||downloads +druing||during +dynmaic||dynamic +eanable||enable +easilly||easily +ecspecially||especially +edditable||editable +editting||editing +efective||effective +efficently||efficiently +ehther||ether +eigth||eight +elementry||elementary +eletronic||electronic +embeded||embedded +enabledi||enabled +enchanced||enhanced +encorporating||incorporating +encrupted||encrypted +encrypiton||encryption +encryptio||encryption +endianess||endianness +enhaced||enhanced +enlightnment||enlightenment +entrys||entries +enocded||encoded +enterily||entirely +enviroiment||environment +enviroment||environment +environement||environment +environent||environment +eqivalent||equivalent +equiped||equipped +equivelant||equivalent +equivilant||equivalent +eror||error +errorr||error +estbalishment||establishment +etsablishment||establishment +etsbalishment||establishment +excecutable||executable +exceded||exceeded +excellant||excellent +exeed||exceed +existance||existence +existant||existent +exixt||exist +exlcude||exclude +exlcusive||exclusive +exmaple||example +expecially||especially +explicite||explicit +explicitely||explicitly +explict||explicit +explictely||explicitly +explictly||explicitly +expresion||expression +exprimental||experimental +extened||extended +extensability||extensibility +extention||extension +extenstion||extension +extracter||extractor +faield||failed +falied||failed +faild||failed +failer||failure +faill||fail +failied||failed +faillure||failure +failue||failure +failuer||failure +failng||failing +faireness||fairness +falied||failed +faliure||failure +fallbck||fallback +familar||familiar +fatser||faster +feauture||feature +feautures||features +fetaure||feature +fetaures||features +fileystem||filesystem +fimware||firmware +firware||firmware +finanize||finalize +findn||find +finilizes||finalizes +finsih||finish +flusing||flushing +folloing||following +followign||following +followings||following +follwing||following +fonud||found +forseeable||foreseeable +forse||force +fortan||fortran +forwardig||forwarding +frambuffer||framebuffer +framming||framing +framwork||framework +frequncy||frequency +frome||from +fucntion||function +fuction||function +fuctions||functions +funcation||function +funcion||function +functionallity||functionality +functionaly||functionally +functionnality||functionality +functonality||functionality +funtion||function +funtions||functions +furthur||further +futhermore||furthermore +futrue||future +gaurenteed||guaranteed +generiously||generously +genereate||generate +genereted||generated +genric||generic +globel||global +grabing||grabbing +grahical||graphical +grahpical||graphical +grapic||graphic +grranted||granted +guage||gauge +guarenteed||guaranteed +guarentee||guarantee +halfs||halves +hander||handler +handfull||handful +hanlde||handle +hanled||handled +happend||happened +harware||hardware +heirarchically||hierarchically +helpfull||helpful +hybernate||hibernate +hierachy||hierarchy +hierarchie||hierarchy +homogenous||homogeneous +howver||however +hsould||should +hypervior||hypervisor +hypter||hyper +identidier||identifier +iligal||illegal +illigal||illegal +illgal||illegal +iomaped||iomapped +imblance||imbalance +immeadiately||immediately +immedaite||immediate +immediatelly||immediately +immediatly||immediately +immidiate||immediate +impelentation||implementation +impementated||implemented +implemantation||implementation +implemenation||implementation +implementaiton||implementation +implementated||implemented +implemention||implementation +implementd||implemented +implemetation||implementation +implemntation||implementation +implentation||implementation +implmentation||implementation +implmenting||implementing +incative||inactive +incomming||incoming +incompatabilities||incompatibilities +incompatable||incompatible +inconsistant||inconsistent +increas||increase +incremeted||incremented +incrment||increment +indendation||indentation +indended||intended +independant||independent +independantly||independently +independed||independent +indiate||indicate +indicat||indicate +inexpect||inexpected +infomation||information +informatiom||information +informations||information +informtion||information +infromation||information +ingore||ignore +inital||initial +initalized||initialized +initalised||initialized +initalise||initialize +initalize||initialize +initation||initiation +initators||initiators +initialiazation||initialization +initializiation||initialization +initialze||initialize +initialzed||initialized +initilization||initialization +initilize||initialize +inofficial||unofficial +inrerface||interface +insititute||institute +instal||install +instanciate||instantiate +instanciated||instantiated +inteface||interface +integreated||integrated +integrety||integrity +integrey||integrity +intendet||intended +intented||intended +interanl||internal +interchangable||interchangeable +interferring||interfering +interger||integer +intermittant||intermittent +internel||internal +interoprability||interoperability +interuupt||interrupt +interrface||interface +interrrupt||interrupt +interrup||interrupt +interrups||interrupts +interruptted||interrupted +interupted||interrupted +interupt||interrupt +intial||initial +intialisation||initialisation +intialised||initialised +intialise||initialise +intialization||initialization +intialized||initialized +intialize||initialize +intregral||integral +intrrupt||interrupt +intterrupt||interrupt +intuative||intuitive +inavlid||invalid +invaid||invalid +invald||invalid +invalde||invalid +invalide||invalid +invalidiate||invalidate +invalud||invalid +invididual||individual +invokation||invocation +invokations||invocations +irrelevent||irrelevant +isnt||isn't +isssue||issue +iternations||iterations +itertation||iteration +itslef||itself +jave||java +jeffies||jiffies +juse||just +jus||just +kown||known +langage||language +langauage||language +langauge||language +langugage||language +lauch||launch +layed||laid +legnth||length +leightweight||lightweight +lengh||length +lenght||length +lenth||length +lesstiff||lesstif +libaries||libraries +libary||library +librairies||libraries +libraris||libraries +licenceing||licencing +loggging||logging +loggin||login +logile||logfile +loobpack||loopback +loosing||losing +losted||lost +machinary||machinery +maintainance||maintenance +maintainence||maintenance +maintan||maintain +makeing||making +mailformed||malformed +malplaced||misplaced +malplace||misplace +managable||manageable +managment||management +mangement||management +manoeuvering||maneuvering +mappping||mapping +matchs||matches +mathimatical||mathematical +mathimatic||mathematic +mathimatics||mathematics +maxium||maximum +mechamism||mechanism +meetign||meeting +ment||meant +mergable||mergeable +mesage||message +messags||messages +messgaes||messages +messsage||message +messsages||messages +micropone||microphone +microprocesspr||microprocessor +migrateable||migratable +milliseonds||milliseconds +minium||minimum +minimam||minimum +minumum||minimum +misalinged||misaligned +miscelleneous||miscellaneous +misformed||malformed +mispelled||misspelled +mispelt||misspelt +mising||missing +mismactch||mismatch +missmanaged||mismanaged +missmatch||mismatch +miximum||maximum +mmnemonic||mnemonic +mnay||many +modfiy||modify +modulues||modules +momery||memory +memomry||memory +monochorome||monochrome +monochromo||monochrome +monocrome||monochrome +mopdule||module +mroe||more +mulitplied||multiplied +multidimensionnal||multidimensional +multple||multiple +mumber||number +muticast||multicast +mutilcast||multicast +mutiple||multiple +mutli||multi +nams||names +navagating||navigating +nead||need +neccecary||necessary +neccesary||necessary +neccessary||necessary +necesary||necessary +neded||needed +negaive||negative +negoitation||negotiation +negotation||negotiation +nerver||never +nescessary||necessary +nessessary||necessary +noticable||noticeable +notications||notifications +notifed||notified +numebr||number +numner||number +obtaion||obtain +obusing||abusing +occassionally||occasionally +occationally||occasionally +occurance||occurrence +occurances||occurrences +occured||occurred +occurence||occurrence +occure||occurred +occured||occurred +occuring||occurring +offet||offset +offloded||offloaded +omited||omitted +omiting||omitting +omitt||omit +ommiting||omitting +ommitted||omitted +onself||oneself +ony||only +operatione||operation +opertaions||operations +optionnal||optional +optmizations||optimizations +orientatied||orientated +orientied||oriented +orignal||original +otherise||otherwise +ouput||output +oustanding||outstanding +overaall||overall +overhread||overhead +overlaping||overlapping +overide||override +overrided||overridden +overriden||overridden +overun||overrun +overwritting||overwriting +overwriten||overwritten +pacakge||package +pachage||package +packacge||package +packege||package +packge||package +packtes||packets +pakage||package +pallette||palette +paln||plan +paramameters||parameters +paramaters||parameters +paramater||parameter +parametes||parameters +parametised||parametrised +paramter||parameter +paramters||parameters +parmaters||parameters +particuarly||particularly +particularily||particularly +partiton||partition +pased||passed +passin||passing +pathes||paths +pecularities||peculiarities +peformance||performance +peforming||performing +peice||piece +pendantic||pedantic +peprocessor||preprocessor +perfoming||performing +permissons||permissions +peroid||period +persistance||persistence +persistant||persistent +plalform||platform +platfoem||platform +platfrom||platform +plattform||platform +pleaes||please +ploting||plotting +plugable||pluggable +poinnter||pointer +pointeur||pointer +poiter||pointer +posible||possible +positon||position +possibilites||possibilities +powerfull||powerful +preamle||preamble +preample||preamble +preapre||prepare +preceeded||preceded +preceeding||preceding +preceed||precede +precendence||precedence +precission||precision +preemptable||preemptible +prefered||preferred +prefferably||preferably +premption||preemption +prepaired||prepared +preperation||preparation +pressre||pressure +primative||primitive +princliple||principle +priorty||priority +privilaged||privileged +privilage||privilege +priviledge||privilege +priviledges||privileges +probaly||probably +procceed||proceed +proccesors||processors +procesed||processed +proces||process +procesing||processing +processessing||processing +processess||processes +processpr||processor +processsed||processed +processsing||processing +procteted||protected +prodecure||procedure +progams||programs +progess||progress +programers||programmers +programm||program +programms||programs +progresss||progress +promiscous||promiscuous +promps||prompts +pronnounced||pronounced +prononciation||pronunciation +pronouce||pronounce +pronunce||pronounce +propery||property +propigate||propagate +propigation||propagation +propogate||propagate +prosess||process +protable||portable +protcol||protocol +protecion||protection +protocoll||protocol +promixity||proximity +psudo||pseudo +psuedo||pseudo +psychadelic||psychedelic +pwoer||power +quering||querying +randomally||randomly +raoming||roaming +reasearcher||researcher +reasearchers||researchers +reasearch||research +recepient||recipient +receving||receiving +recieved||received +recieve||receive +reciever||receiver +recieves||receives +recogniced||recognised +recognizeable||recognizable +recommanded||recommended +recyle||recycle +redircet||redirect +redirectrion||redirection +redundacy||redundancy +reename||rename +refcounf||refcount +refence||reference +refered||referred +referenace||reference +refering||referring +refernces||references +refernnce||reference +refrence||reference +registerd||registered +registeration||registration +registeresd||registered +registerred||registered +registes||registers +registraration||registration +regsiter||register +regster||register +regualar||regular +reguator||regulator +regulamentations||regulations +reigstration||registration +releated||related +relevent||relevant +remoote||remote +remore||remote +removeable||removable +repectively||respectively +replacable||replaceable +replacments||replacements +replys||replies +reponse||response +representaion||representation +reqeust||request +requestied||requested +requiere||require +requirment||requirement +requred||required +requried||required +requst||request +reregisteration||reregistration +reseting||resetting +reseverd||reserved +resizeable||resizable +resouce||resource +resouces||resources +resoures||resources +responce||response +ressizes||resizes +ressource||resource +ressources||resources +restesting||retesting +retransmited||retransmitted +retreived||retrieved +retreive||retrieve +retrive||retrieve +retuned||returned +reudce||reduce +reuest||request +reuqest||request +reutnred||returned +revsion||revision +rmeoved||removed +rmeove||remove +rmeoves||removes +rountine||routine +routins||routines +rquest||request +runing||running +runned||ran +runnning||running +runtine||runtime +sacrifying||sacrificing +safly||safely +safty||safety +savable||saveable +scaleing||scaling +scaned||scanned +scaning||scanning +scarch||search +seach||search +searchs||searches +secquence||sequence +secund||second +segement||segment +semaphone||semaphore +senario||scenario +senarios||scenarios +sentivite||sensitive +separatly||separately +sepcify||specify +sepc||spec +seperated||separated +seperately||separately +seperate||separate +seperatly||separately +seperator||separator +sepperate||separate +seqeunce||sequence +seqeuncer||sequencer +seqeuencer||sequencer +sequece||sequence +sequencial||sequential +serveral||several +servive||service +setts||sets +settting||setting +shotdown||shutdown +shoud||should +shouldnt||shouldn't +shoule||should +shrinked||shrunk +siginificantly||significantly +signabl||signal +similary||similarly +similiar||similar +simlar||similar +simliar||similar +simpified||simplified +singaled||signaled +singal||signal +singed||signed +sleeped||slept +softwares||software +speach||speech +specfic||specific +speciefied||specified +specifc||specific +specifed||specified +specificatin||specification +specificaton||specification +specifing||specifying +specifiying||specifying +speficied||specified +speicify||specify +speling||spelling +spinlcok||spinlock +spinock||spinlock +splitted||split +spreaded||spread +spurrious||spurious +sructure||structure +stablilization||stabilization +staically||statically +staion||station +standardss||standards +standartization||standardization +standart||standard +staticly||statically +stoped||stopped +stoping||stopping +stoppped||stopped +straming||streaming +struc||struct +structres||structures +stuct||struct +strucuture||structure +stucture||structure +sturcture||structure +subdirectoires||subdirectories +suble||subtle +substract||subtract +submition||submission +suceed||succeed +succesfully||successfully +succesful||successful +successed||succeeded +successfull||successful +successfuly||successfully +sucessfully||successfully +sucess||success +superflous||superfluous +superseeded||superseded +suplied||supplied +suported||supported +suport||support +supportet||supported +suppored||supported +supportin||supporting +suppoted||supported +suppported||supported +suppport||support +supress||suppress +surpressed||suppressed +surpresses||suppresses +susbsystem||subsystem +suspeneded||suspended +suspsend||suspend +suspicously||suspiciously +swaping||swapping +switchs||switches +swith||switch +swithable||switchable +swithc||switch +swithced||switched +swithcing||switching +swithed||switched +swithing||switching +swtich||switch +symetric||symmetric +synax||syntax +synchonized||synchronized +synchronuously||synchronously +syncronize||synchronize +syncronized||synchronized +syncronizing||synchronizing +syncronus||synchronous +syste||system +sytem||system +sythesis||synthesis +taht||that +tansmit||transmit +targetted||targeted +targetting||targeting +taskelt||tasklet +teh||the +temorary||temporary +temproarily||temporarily +thead||thread +therfore||therefore +thier||their +threds||threads +threshhold||threshold +thresold||threshold +throught||through +troughput||throughput +thses||these +tiggers||triggers +tiggered||triggered +tipically||typically +timeing||timing +timout||timeout +tmis||this +torerable||tolerable +traking||tracking +tramsmitted||transmitted +tramsmit||transmit +tranasction||transaction +tranfer||transfer +transciever||transceiver +transferd||transferred +transfered||transferred +transfering||transferring +transision||transition +transmittd||transmitted +transormed||transformed +trasfer||transfer +trasmission||transmission +treshold||threshold +trigerred||triggered +trigerring||triggering +trun||turn +tunning||tuning +ture||true +tyep||type +udpate||update +uesd||used +uknown||unknown +usupported||unsupported +uncommited||uncommitted +unconditionaly||unconditionally +underun||underrun +unecessary||unnecessary +unexecpted||unexpected +unexepected||unexpected +unexpcted||unexpected +unexpectd||unexpected +unexpeted||unexpected +unexpexted||unexpected +unfortunatelly||unfortunately +unifiy||unify +uniterrupted||uninterrupted +unintialized||uninitialized +unkmown||unknown +unknonw||unknown +unknow||unknown +unkown||unknown +unamed||unnamed +uneeded||unneeded +unneded||unneeded +unneccecary||unnecessary +unneccesary||unnecessary +unneccessary||unnecessary +unnecesary||unnecessary +unneedingly||unnecessarily +unnsupported||unsupported +unmached||unmatched +unregester||unregister +unresgister||unregister +unrgesiter||unregister +unsinged||unsigned +unstabel||unstable +unsolicitied||unsolicited +unsuccessfull||unsuccessful +unsuported||unsupported +untill||until +unuseful||useless +upate||update +usefule||useful +usefull||useful +usege||usage +usera||users +usualy||usually +usupported||unsupported +utilites||utilities +utillities||utilities +utilties||utilities +utiltity||utility +utitity||utility +utitlty||utility +vaid||valid +vaild||valid +valide||valid +variantions||variations +varible||variable +varient||variant +vaule||value +verbse||verbose +verisons||versions +verison||version +verson||version +vicefersa||vice-versa +virtal||virtual +virtaul||virtual +virtiual||virtual +visiters||visitors +vitual||virtual +vunerable||vulnerable +wakeus||wakeups +wathdog||watchdog +wating||waiting +wiat||wait +wether||whether +whataver||whatever +whcih||which +whenver||whenever +wheter||whether +whe||when +wierd||weird +wiil||will +wirte||write +withing||within +wnat||want +workarould||workaround +writeing||writing +writting||writing +zombe||zombie +zomebie||zombie -- cgit v1.2.3 From 3d4e4e0733e8628d17a79881738ee3f236fed3e7 Mon Sep 17 00:00:00 2001 From: Alex <colomar.6.4.3@gmail.com> Date: Sat, 2 Feb 2019 20:35:28 +0000 Subject: Update libalx; Fix style --- modules/about/src/about.c | 2 +- modules/about/tmp/Makefile | 2 +- modules/menu/src/menu_clui.c | 26 ++++------ modules/menu/src/menu_tui.c | 2 +- modules/menu/tmp/Makefile | 4 +- modules/proc/src/proc_iface.c | 56 ++++++++++----------- modules/proc/tmp/Makefile | 2 +- modules/user/src/user_clui.c | 114 ++++-------------------------------------- modules/user/src/user_tui.c | 98 ++---------------------------------- modules/user/tmp/Makefile | 4 +- src/main.cpp | 2 +- tmp/Makefile | 2 +- 12 files changed, 58 insertions(+), 256 deletions(-) diff --git a/modules/about/src/about.c b/modules/about/src/about.c index e101242..e36828b 100644 --- a/modules/about/src/about.c +++ b/modules/about/src/about.c @@ -13,7 +13,7 @@ #include <stdlib.h> /* libalx --------------------------------------------------------------------*/ /* alx_snprint_file() */ - #include "libalx/alx_file.h" + #include "libalx/io/alx_file.h" /* Module --------------------------------------------------------------------*/ #include "about.h" diff --git a/modules/about/tmp/Makefile b/modules/about/tmp/Makefile index dee3dc3..21afd1b 100644 --- a/modules/about/tmp/Makefile +++ b/modules/about/tmp/Makefile @@ -14,7 +14,7 @@ SRC_DIR = $(ABOUT_DIR)/src/ _ALL = about.o ALL = $(_ALL) about_mod.o -ABOU_INC_LIBALX = libalx/alx_file.h +ABOU_INC_LIBALX = libalx/io/alx_file.h ABOU_INC = about.h ABOU_DEPS = $(SRC_DIR)/about.c \ $(patsubst %,$(LIBALX_INC_DIR)/%,$(ABOU_INC_LIBALX)) \ diff --git a/modules/menu/src/menu_clui.c b/modules/menu/src/menu_clui.c index d335b6e..964d176 100644 --- a/modules/menu/src/menu_clui.c +++ b/modules/menu/src/menu_clui.c @@ -7,7 +7,7 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ - #include "libalx/alx_input.h" + #include "libalx/io/alx_input.h" #include "about.h" // #include "save.h" @@ -41,12 +41,10 @@ void menu_clui (void) c = 'n'; printf("Read 'Disclaimer of warranty'? (yes/NO): "); - if (!fgets(buff, BUFF_SIZE, stdin)) { + if (!fgets(buff, BUFF_SIZE, stdin)) return; - } - if (sscanf(buff, " %c", &c) != 1) { + if (sscanf(buff, " %c", &c) != 1) return; - } if (c == 'y' || c == 'Y') { printf(" >yes\n"); print_share_file(SHARE_DISCLAIMER); @@ -56,12 +54,10 @@ void menu_clui (void) c = 'n'; printf("Read 'License'? (yes/NO): "); - if (!fgets(buff, BUFF_SIZE, stdin)) { + if (!fgets(buff, BUFF_SIZE, stdin)) return; - } - if (sscanf(buff, " %c", &c) != 1) { + if (sscanf(buff, " %c", &c) != 1) return; - } if (c == 'y' || c == 'Y') { printf(" >yes\n"); print_share_file(SHARE_LICENSE); @@ -70,12 +66,10 @@ void menu_clui (void) } #if 0 printf("Game interface? (NCURSES/text): "); - if (!fgets(buff, BUFF_SIZE, stdin)) { + if (!fgets(buff, BUFF_SIZE, stdin)) return; - } - if (sscanf(buff, " %c", &c) != 1) { + if (sscanf(buff, " %c", &c) != 1) return; - } if (c == 't' || c == 'T') { printf(" >text\n"); // FIXME @@ -110,12 +104,10 @@ static void menu_clui_start (void) c = 'm'; printf("Load again? (MENU/load/exit): "); - if (!fgets(buff, BUFF_SIZE, stdin)) { + if (!fgets(buff, BUFF_SIZE, stdin)) return; - } - if (sscanf(buff, " %c", &c) != 1) { + if (sscanf(buff, " %c", &c) != 1) return; - } if (c == 'p' || c == 'P') { printf(" >load\n"); menu_clui_start(); diff --git a/modules/menu/src/menu_tui.c b/modules/menu/src/menu_tui.c index 3d5a484..8a6cb0b 100644 --- a/modules/menu/src/menu_tui.c +++ b/modules/menu/src/menu_tui.c @@ -12,7 +12,7 @@ #include <stdbool.h> #include <stddef.h> /* libalx --------------------------------------------------------------------*/ - #include "libalx/alx_ncur.h" + #include "libalx/curses/alx_ncur.h" /* Project -------------------------------------------------------------------*/ #include "about.h" #include "proc_iface.h" diff --git a/modules/menu/tmp/Makefile b/modules/menu/tmp/Makefile index f83b79d..cd39b92 100644 --- a/modules/menu/tmp/Makefile +++ b/modules/menu/tmp/Makefile @@ -39,7 +39,7 @@ MENUI_DEPS = $(SRC_DIR)/menu_iface.c \ $(patsubst %,$(INC_DIR)/%,$(MENUI_INC)) MENUI_INC_DIRS = -I $(INC_DIR) -MENUCLUI_INC_LIBALX = libalx/alx_input.h +MENUCLUI_INC_LIBALX = libalx/io/alx_input.h MENUCLUI_INC_ABOUT = about.h MENUCLUI_INC_CTRL = start.h MENUCLUI_INC_SAVE = save.h @@ -56,7 +56,7 @@ MENUCLUI_INC_DIRS = -I $(INC_DIR) \ -I $(CTRL_INC_DIR) \ -I $(SAVE_INC_DIR) -MENUTUI_INC_LIBALX = libalx/alx_ncur.h +MENUTUI_INC_LIBALX = libalx/curses/alx_ncur.h MENUTUI_INC_ABOUT = about.h MENUTUI_INC_CTRL = start.h MENUTUI_INC_PROC = proc_iface.h diff --git a/modules/proc/src/proc_iface.c b/modules/proc/src/proc_iface.c index 9111fc5..f14ba1d 100644 --- a/modules/proc/src/proc_iface.c +++ b/modules/proc/src/proc_iface.c @@ -14,7 +14,7 @@ #include <stdlib.h> #include <time.h> /* libalx -------------------------------------------------------------------*/ - #include "libalx/alx_input.h" + #include "libalx/io/alx_input.h" /* Project -------------------------------------------------------------------*/ #include "img_iface.h" #include "user_iface.h" @@ -107,7 +107,6 @@ void proc_iface_series (void) char file_basename [FILENAME_MAX]; char file_ext [FILENAME_MAX]; char file_name [FILENAME_MAX]; - bool proc_error; char save_error_as [FILENAME_MAX]; bool wh; /* if i starts being 0, the camera needs calibration */ @@ -177,39 +176,36 @@ void proc_iface_series (void) errno = 0; img_iface_load(proc_path, file_name); - if (!errno) { - /* Process */ - proc_error = proc_iface_single(proc_mode); - - if (proc_error) { - /* Save failed image into file */ - proc_show_img(); - if (snprintf(save_error_as, FILENAME_MAX, - "%s%0*i_err%s", - file_basename, - num_len, i, - file_ext) >= FILENAME_MAX) { - goto err_path; - } - save_image_file(proc_fail_path, - save_error_as); - } - - /* Show log */ - snprintf(txt_tmp, FILENAME_MAX, "%04i", i); - user_iface_show_log(txt_tmp, "Item"); + if (errno) { + printf("errno:%i\n", errno); + goto err_load; + } - if (proc_debug >= PROC_DBG_STOP_ITEM) { - getchar(); + /* Process */ + if (proc_iface_single(proc_mode)) { + /* Save failed image into file */ + proc_show_img(); + if (snprintf(save_error_as, FILENAME_MAX, + "%s%0*i_err%s", + file_basename, + num_len, i, + file_ext) >= FILENAME_MAX) { + goto err_path; } - } else { - printf("errno:%i\n", errno); + save_image_file(proc_fail_path, + save_error_as); } - } - if (!i) { - proc_mode--; + /* Show log */ + snprintf(txt_tmp, FILENAME_MAX, "%04i", i); + user_iface_show_log(txt_tmp, "Item"); + + if (proc_debug >= PROC_DBG_STOP_ITEM) + getchar(); } +err_load: + if (!i) + proc_mode--; } return; diff --git a/modules/proc/tmp/Makefile b/modules/proc/tmp/Makefile index 0bdc990..531b63e 100644 --- a/modules/proc/tmp/Makefile +++ b/modules/proc/tmp/Makefile @@ -95,7 +95,7 @@ PROC_CMN_INC_DIRS = -I $(INC_DIR) \ -I $(IMG_INC_DIR) \ -I $(USR_INC_DIR) -PROC_IFACE_INC_LIBALX = libalx/alx_input.h +PROC_IFACE_INC_LIBALX = libalx/io/alx_input.h PROC_IFACE_INC_IMG = img_iface.h PROC_IFACE_INC_SAVE = save.h PROC_IFACE_INC_USR = user_iface.h diff --git a/modules/user/src/user_clui.c b/modules/user/src/user_clui.c index c48fb82..bcd44c8 100644 --- a/modules/user/src/user_clui.c +++ b/modules/user/src/user_clui.c @@ -7,13 +7,11 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ #include <stdio.h> -/* libalx --------------------------------------------------------------------*/ - #include "libalx/alx_input.h" -/* Project -------------------------------------------------------------------*/ + + #include "libalx/io/alx_input.h" + #include "img_iface.h" -/* Module --------------------------------------------------------------------*/ #include "user_iface.h" #include "user_clui.h" @@ -75,12 +73,10 @@ void user_clui_fname (const char *filepath, char *filename) void user_clui_show_log (const char *title, const char *subtitle) { - printf("________________________________________" - "________________________________________\n"); + printf("________________________________________________________________________________\n"); log_loop(); printf("%s - %s\n", subtitle, title); - printf("----------------------------------------" - "----------------------------------------\n"); + printf("--------------------------------------------------------------------------------\n"); } @@ -96,9 +92,8 @@ static void log_loop (void) putchar('\n'); 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++) { + for (lvl = 0; lvl < user_iface_log.lvl[log_pos]; lvl++) printf("\t"); - } printf("%s\n", user_iface_log.line[log_pos]); } } @@ -113,18 +108,15 @@ static int usr_input (void) char ch [10]; int i; - for (i = 0; i < 10; i++) { + for (i = 0; i < 10; i++) ch[i] = '\0'; - } buff[0] = '\0'; action = USER_IFACE_ACT_FOO; - if (!fgets(buff, BUFF_SIZE, stdin)) { + if (!fgets(buff, BUFF_SIZE, stdin)) goto err_fgets; - } - if (!sscanf(buff, " %c%c%c%c%c", &ch[0], &ch[1], &ch[2], &ch[3], &ch[4])) { + if (sscanf(buff, " %5c", ch) <= 0) goto err_sscanf; - } switch (ch[0]) { case '+': @@ -144,9 +136,6 @@ static int usr_input (void) case '1': action = USER_IFACE_ACT_PROC_LABEL_SERIES; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '2': @@ -158,9 +147,6 @@ static int usr_input (void) case '1': action = USER_IFACE_ACT_PROC_OBJECTS_SERIES; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '3': @@ -169,9 +155,6 @@ static int usr_input (void) case '1': action = USER_IFACE_ACT_PROC_COINS_SERIES; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '4': @@ -180,9 +163,6 @@ static int usr_input (void) case '1': action = USER_IFACE_ACT_PROC_RESISTOR_SERIES; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '5': @@ -191,14 +171,8 @@ static int usr_input (void) case '1': action = USER_IFACE_ACT_PROC_LIGHTERS_SERIES; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; @@ -217,9 +191,6 @@ static int usr_input (void) case '1': action = USER_IFACE_ACT_SKELETON; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '1': @@ -231,9 +202,6 @@ static int usr_input (void) case '1': action = USER_IFACE_ACT_LINES_VERTICAL; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '2': @@ -251,14 +219,8 @@ static int usr_input (void) case '3': action = USER_IFACE_ACT_MEDIAN_VERTICAL; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '1': @@ -276,9 +238,6 @@ static int usr_input (void) case '1': action = USER_IFACE_ACT_PIXEL_SET; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '1': @@ -290,9 +249,6 @@ static int usr_input (void) case '1': action = USER_IFACE_ACT_SET_ROI_2RECT; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '2': @@ -310,14 +266,8 @@ static int usr_input (void) case '3': action = USER_IFACE_ACT_COMPONENT; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '1': @@ -347,9 +297,6 @@ static int usr_input (void) case '6': action = USER_IFACE_ACT_BORDER; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '1': @@ -367,9 +314,6 @@ static int usr_input (void) case '3': action = USER_IFACE_ACT_ROTATE_2RECT; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '2': @@ -387,9 +331,6 @@ static int usr_input (void) case '3': action = USER_IFACE_ACT_THRESHOLD; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '3': @@ -401,9 +342,6 @@ static int usr_input (void) case '1': action = USER_IFACE_ACT_HISTOGRAM_C3; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '4': @@ -424,9 +362,6 @@ static int usr_input (void) case '4': action = USER_IFACE_ACT_MIN_AREA_RECT; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '5': @@ -435,19 +370,10 @@ static int usr_input (void) case '0': action = USER_IFACE_ACT_HOUGH_CIRCLES; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '2': @@ -456,9 +382,6 @@ static int usr_input (void) case '0': action = USER_IFACE_ACT_ALIGN; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '3': @@ -470,9 +393,6 @@ static int usr_input (void) case '1': action = USER_IFACE_ACT_UNDISTORT; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '4': @@ -481,9 +401,6 @@ static int usr_input (void) case '0': action = USER_IFACE_ACT_DECODE; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '5': @@ -492,14 +409,8 @@ static int usr_input (void) case '0': action = USER_IFACE_ACT_READ; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; @@ -529,9 +440,6 @@ static int usr_input (void) case '1': action = USER_IFACE_ACT_SHOW_OCR; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; @@ -547,10 +455,6 @@ static int usr_input (void) } } break; - - default: - action = USER_IFACE_ACT_FOO; - break; } err_fgets: diff --git a/modules/user/src/user_tui.c b/modules/user/src/user_tui.c index 90b457e..9b0285b 100644 --- a/modules/user/src/user_tui.c +++ b/modules/user/src/user_tui.c @@ -7,14 +7,12 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ #include <inttypes.h> #include <ncurses.h> -/* libalx --------------------------------------------------------------------*/ - #include "libalx/alx_ncur.h" -/* Project -------------------------------------------------------------------*/ + + #include "libalx/curses/alx_ncur.h" + #include "img_iface.h" -/* Module --------------------------------------------------------------------*/ #include "user_iface.h" #include "user_tui.h" @@ -212,7 +210,7 @@ static int usr_input (void) int action; wchar_t ch; - /* Interpret input */ + action = USER_IFACE_ACT_FOO; ch = wgetch(win_log); switch (ch) { case ' ': @@ -238,9 +236,6 @@ static int usr_input (void) case '1': action = USER_IFACE_ACT_PROC_LABEL_SERIES; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '2': @@ -254,9 +249,6 @@ static int usr_input (void) case '1': action = USER_IFACE_ACT_PROC_OBJECTS_SERIES; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '3': @@ -267,9 +259,6 @@ static int usr_input (void) case '1': action = USER_IFACE_ACT_PROC_COINS_SERIES; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '4': @@ -280,9 +269,6 @@ static int usr_input (void) case '1': action = USER_IFACE_ACT_PROC_RESISTOR_SERIES; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '5': @@ -293,14 +279,8 @@ static int usr_input (void) case '1': action = USER_IFACE_ACT_PROC_LIGHTERS_SERIES; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; @@ -325,9 +305,6 @@ static int usr_input (void) case '1': action = USER_IFACE_ACT_SKELETON; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '1': @@ -341,9 +318,6 @@ static int usr_input (void) case '1': action = USER_IFACE_ACT_LINES_VERTICAL; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '2': @@ -363,14 +337,8 @@ static int usr_input (void) case '3': action = USER_IFACE_ACT_MEDIAN_VERTICAL; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '1': @@ -394,9 +362,6 @@ static int usr_input (void) case '1': action = USER_IFACE_ACT_PIXEL_SET; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '1': @@ -410,9 +375,6 @@ static int usr_input (void) case '1': action = USER_IFACE_ACT_SET_ROI_2RECT; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '2': @@ -432,14 +394,8 @@ static int usr_input (void) case '3': action = USER_IFACE_ACT_COMPONENT; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '1': @@ -473,9 +429,6 @@ static int usr_input (void) case '6': action = USER_IFACE_ACT_BORDER; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '1': @@ -495,9 +448,6 @@ static int usr_input (void) case '3': action = USER_IFACE_ACT_ROTATE_2RECT; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '2': @@ -517,9 +467,6 @@ static int usr_input (void) case '3': action = USER_IFACE_ACT_THRESHOLD; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '3': @@ -533,9 +480,6 @@ static int usr_input (void) case '1': action = USER_IFACE_ACT_HISTOGRAM_C3; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '4': @@ -558,9 +502,6 @@ static int usr_input (void) case '4': action = USER_IFACE_ACT_MIN_AREA_RECT; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '5': @@ -571,19 +512,10 @@ static int usr_input (void) case '0': action = USER_IFACE_ACT_HOUGH_CIRCLES; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '2': @@ -594,9 +526,6 @@ static int usr_input (void) case '0': action = USER_IFACE_ACT_ALIGN; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '3': @@ -610,9 +539,6 @@ static int usr_input (void) case '1': action = USER_IFACE_ACT_UNDISTORT; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '4': @@ -623,9 +549,6 @@ static int usr_input (void) case '0': action = USER_IFACE_ACT_DECODE; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; case '5': @@ -636,14 +559,8 @@ static int usr_input (void) case '0': action = USER_IFACE_ACT_READ; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; @@ -675,9 +592,6 @@ static int usr_input (void) case '1': action = USER_IFACE_ACT_SHOW_OCR; break; - default: - action = USER_IFACE_ACT_FOO; - break; } break; @@ -701,10 +615,6 @@ static int usr_input (void) } } break; - - default: - action = USER_IFACE_ACT_FOO; - break; } return action; diff --git a/modules/user/tmp/Makefile b/modules/user/tmp/Makefile index 9ad6a8b..bc4f607 100644 --- a/modules/user/tmp/Makefile +++ b/modules/user/tmp/Makefile @@ -30,7 +30,7 @@ UI_INC_DIRS = -I $(INC_DIR) \ -I $(IMG_INC_DIR) \ -I $(PROC_INC_DIR) -UCLUI_INC_LIBALX = libalx/alx_ncur.h +UCLUI_INC_LIBALX = libalx/curses/alx_ncur.h UCLUI_INC_IMG = img_iface.h UCLUI_INC = user_clui.h user_iface.h UCLUI_DEPS = $(SRC_DIR)/user_clui.c \ @@ -41,7 +41,7 @@ UCLUI_INC_DIRS = -I $(INC_DIR) \ -I $(LIBALX_INC_DIR) \ -I $(IMG_INC_DIR) -UTUI_INC_LIBALX = libalx/alx_ncur.h +UTUI_INC_LIBALX = libalx/curses/alx_ncur.h UTUI_INC_IMG = img_iface.h UTUI_INC = user_tui.h user_iface.h UTUI_DEPS = $(SRC_DIR)/user_tui.c \ diff --git a/src/main.cpp b/src/main.cpp index 2e05304..b1bc046 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,7 +10,7 @@ /* Standard C ----------------------------------------------------------------*/ #include <cstdio> /* libalx --------------------------------------------------------------------*/ - #include "libalx/alx_ncur.hpp" + #include "libalx/curses/alx_ncur.hpp" /* Project -------------------------------------------------------------------*/ #include "about.hpp" #include "img_iface.hpp" diff --git a/tmp/Makefile b/tmp/Makefile index 0d44af3..a49f078 100644 --- a/tmp/Makefile +++ b/tmp/Makefile @@ -30,7 +30,7 @@ SRC_DIR = $(MAIN_DIR)/src/ ALL = main.o -MAIN_INC_LIBALX = libalx/alx_ncur.hpp +MAIN_INC_LIBALX = libalx/curses/alx_ncur.hpp MAIN_INC_ABOUT = about.hpp MAIN_INC_IMG = img_iface.hpp MAIN_INC_MENU = parser.hpp menu_iface.hpp -- cgit v1.2.3 From 667ea210f5423a3ccc7fb806087688df24271a2f Mon Sep 17 00:00:00 2001 From: Alex <colomar.6.4.3@gmail.com> Date: Sun, 7 Apr 2019 18:56:08 +0100 Subject: Restructure code; Use libalx v1~b2; --- .gitignore | 2 +- Checkstyle/checkstyle | 5 +- Makefile | 148 ++- bin/Makefile | 72 +- inc/vision-artificial/about/about.h | 79 ++ inc/vision-artificial/about/about.hpp | 84 ++ inc/vision-artificial/ctrl/start.h | 64 + inc/vision-artificial/image/alx.hpp | 77 ++ inc/vision-artificial/image/calib3d.hpp | 71 ++ inc/vision-artificial/image/cv.hpp | 71 ++ inc/vision-artificial/image/iface.h | 191 +++ inc/vision-artificial/image/iface.hpp | 333 +++++ inc/vision-artificial/image/ocr.h | 64 + inc/vision-artificial/image/ocr.hpp | 66 + inc/vision-artificial/image/orb.hpp | 71 ++ inc/vision-artificial/image/zbar.hpp | 70 ++ inc/vision-artificial/menu/clui.h | 63 + inc/vision-artificial/menu/iface.h | 69 ++ inc/vision-artificial/menu/iface.hpp | 72 ++ inc/vision-artificial/menu/parse.h | 63 + inc/vision-artificial/menu/parse.hpp | 66 + inc/vision-artificial/menu/tui.h | 63 + inc/vision-artificial/proc/coins.h | 69 ++ inc/vision-artificial/proc/coins.hpp | 72 ++ inc/vision-artificial/proc/common.h | 65 + inc/vision-artificial/proc/common.hpp | 127 ++ inc/vision-artificial/proc/iface.h | 88 ++ inc/vision-artificial/proc/iface.hpp | 91 ++ inc/vision-artificial/proc/label.h | 71 ++ inc/vision-artificial/proc/label.hpp | 74 ++ inc/vision-artificial/proc/lighters.h | 68 ++ inc/vision-artificial/proc/lighters.hpp | 71 ++ inc/vision-artificial/proc/objects.h | 70 ++ inc/vision-artificial/proc/objects.hpp | 73 ++ inc/vision-artificial/proc/resistor.h | 71 ++ inc/vision-artificial/proc/resistor.hpp | 74 ++ inc/vision-artificial/save/save.h | 99 ++ inc/vision-artificial/save/save.hpp | 105 ++ inc/vision-artificial/user/clui.h | 59 + inc/vision-artificial/user/iface.h | 182 +++ inc/vision-artificial/user/iface.hpp | 187 +++ inc/vision-artificial/user/tui.h | 67 + libalx | 2 +- modules/Makefile | 66 - modules/about/Makefile | 20 - modules/about/inc/about.h | 64 - modules/about/inc/about.hpp | 76 -- modules/about/src/about.c | 126 -- modules/about/tmp/Makefile | 49 - modules/ctrl/Makefile | 30 - modules/ctrl/inc/start.h | 44 - modules/ctrl/src/start.c | 108 -- modules/ctrl/tmp/Makefile | 70 -- modules/image/Makefile | 20 - modules/image/inc/img_alx.hpp | 53 - modules/image/inc/img_calib3d.hpp | 47 - modules/image/inc/img_cv.hpp | 72 -- modules/image/inc/img_iface.h | 185 --- modules/image/inc/img_iface.hpp | 344 ------ modules/image/inc/img_ocr.h | 39 - modules/image/inc/img_ocr.hpp | 51 - modules/image/inc/img_orb.hpp | 47 - modules/image/inc/img_zbar.hpp | 47 - modules/image/src/img_alx.cpp | 370 ------ modules/image/src/img_calib3d.cpp | 128 -- modules/image/src/img_cv.cpp | 786 ------------ modules/image/src/img_iface.cpp | 2032 ------------------------------- modules/image/src/img_ocr.c | 127 -- modules/image/src/img_orb.cpp | 121 -- modules/image/src/img_zbar.cpp | 96 -- modules/image/tmp/Makefile | 149 --- modules/menu/Makefile | 24 - modules/menu/inc/menu_clui.h | 28 - modules/menu/inc/menu_iface.h | 44 - modules/menu/inc/menu_iface.hpp | 56 - modules/menu/inc/menu_tui.h | 28 - modules/menu/inc/parser.h | 28 - modules/menu/inc/parser.hpp | 40 - modules/menu/src/menu_clui.c | 125 -- modules/menu/src/menu_iface.c | 44 - modules/menu/src/menu_tui.c | 332 ----- modules/menu/src/parser.c | 137 --- modules/menu/tmp/Makefile | 123 -- modules/proc/Makefile | 20 - modules/proc/inc/proc_coins.h | 49 - modules/proc/inc/proc_coins.hpp | 61 - modules/proc/inc/proc_common.h | 46 - modules/proc/inc/proc_common.hpp | 112 -- modules/proc/inc/proc_iface.h | 73 -- modules/proc/inc/proc_iface.hpp | 85 -- modules/proc/inc/proc_label.h | 51 - modules/proc/inc/proc_label.hpp | 63 - modules/proc/inc/proc_lighters.h | 48 - modules/proc/inc/proc_lighters.hpp | 60 - modules/proc/inc/proc_objects.h | 50 - modules/proc/inc/proc_objects.hpp | 62 - modules/proc/inc/proc_resistor.h | 51 - modules/proc/inc/proc_resistor.hpp | 63 - modules/proc/src/proc_coins.cpp | 369 ------ modules/proc/src/proc_common.cpp | 441 ------- modules/proc/src/proc_iface.c | 227 ---- modules/proc/src/proc_label.cpp | 377 ------ modules/proc/src/proc_lighters.cpp | 505 -------- modules/proc/src/proc_objects.cpp | 689 ----------- modules/proc/src/proc_resistor.cpp | 1452 ---------------------- modules/proc/tmp/Makefile | 177 --- modules/save/Makefile | 24 - modules/save/inc/save.h | 79 -- modules/save/inc/save.hpp | 96 -- modules/save/src/save.cpp | 289 ----- modules/save/tmp/Makefile | 45 - modules/tmp/Makefile | 46 - modules/user/Makefile | 20 - modules/user/inc/user_clui.h | 31 - modules/user/inc/user_iface.h | 166 --- modules/user/inc/user_iface.hpp | 178 --- modules/user/inc/user_tui.h | 37 - modules/user/src/user_clui.c | 537 -------- modules/user/src/user_iface.c | 220 ---- modules/user/src/user_tui.c | 705 ----------- modules/user/tmp/Makefile | 89 -- share/COPYRIGHT.txt | 8 - share/DISCLAIMER.txt | 16 - share/HELP.txt | 25 - share/LICENSE.txt | 352 ------ share/README.txt | 84 -- share/USAGE.txt | 5 - share/price | 1 - share/vision-artificial/COPYRIGHT.txt | 8 + share/vision-artificial/DISCLAIMER.txt | 16 + share/vision-artificial/HELP.txt | 25 + share/vision-artificial/LICENSE.txt | 352 ++++++ share/vision-artificial/README.txt | 84 ++ share/vision-artificial/USAGE.txt | 5 + share/vision-artificial/price | 1 + src/about/about.c | 144 +++ src/ctrl/start.c | 100 ++ src/image/alx.cpp | 430 +++++++ src/image/calib3d.cpp | 125 ++ src/image/cv.cpp | 802 ++++++++++++ src/image/iface.cpp | 1489 ++++++++++++++++++++++ src/image/ocr.c | 145 +++ src/image/orb.cpp | 136 +++ src/image/zbar.cpp | 122 ++ src/main.cpp | 48 +- src/menu/clui.c | 125 ++ src/menu/iface.c | 68 ++ src/menu/parse.c | 152 +++ src/menu/tui.c | 315 +++++ src/proc/coins.cpp | 291 +++++ src/proc/common.cpp | 461 +++++++ src/proc/iface.c | 224 ++++ src/proc/label.cpp | 295 +++++ src/proc/lighters.cpp | 426 +++++++ src/proc/objects.cpp | 550 +++++++++ src/proc/resistor.cpp | 1279 +++++++++++++++++++ src/save/save.cpp | 280 +++++ src/user/clui.c | 471 +++++++ src/user/iface.c | 234 ++++ src/user/tui.c | 611 ++++++++++ tmp/Makefile | 110 +- tmp/about/Makefile | 53 + tmp/ctrl/Makefile | 54 + tmp/image/Makefile | 145 +++ tmp/menu/Makefile | 110 ++ tmp/proc/Makefile | 167 +++ tmp/save/Makefile | 54 + tmp/user/Makefile | 92 ++ 168 files changed, 14072 insertions(+), 14736 deletions(-) create mode 100644 inc/vision-artificial/about/about.h create mode 100644 inc/vision-artificial/about/about.hpp create mode 100644 inc/vision-artificial/ctrl/start.h create mode 100644 inc/vision-artificial/image/alx.hpp create mode 100644 inc/vision-artificial/image/calib3d.hpp create mode 100644 inc/vision-artificial/image/cv.hpp create mode 100644 inc/vision-artificial/image/iface.h create mode 100644 inc/vision-artificial/image/iface.hpp create mode 100644 inc/vision-artificial/image/ocr.h create mode 100644 inc/vision-artificial/image/ocr.hpp create mode 100644 inc/vision-artificial/image/orb.hpp create mode 100644 inc/vision-artificial/image/zbar.hpp create mode 100644 inc/vision-artificial/menu/clui.h create mode 100644 inc/vision-artificial/menu/iface.h create mode 100644 inc/vision-artificial/menu/iface.hpp create mode 100644 inc/vision-artificial/menu/parse.h create mode 100644 inc/vision-artificial/menu/parse.hpp create mode 100644 inc/vision-artificial/menu/tui.h create mode 100644 inc/vision-artificial/proc/coins.h create mode 100644 inc/vision-artificial/proc/coins.hpp create mode 100644 inc/vision-artificial/proc/common.h create mode 100644 inc/vision-artificial/proc/common.hpp create mode 100644 inc/vision-artificial/proc/iface.h create mode 100644 inc/vision-artificial/proc/iface.hpp create mode 100644 inc/vision-artificial/proc/label.h create mode 100644 inc/vision-artificial/proc/label.hpp create mode 100644 inc/vision-artificial/proc/lighters.h create mode 100644 inc/vision-artificial/proc/lighters.hpp create mode 100644 inc/vision-artificial/proc/objects.h create mode 100644 inc/vision-artificial/proc/objects.hpp create mode 100644 inc/vision-artificial/proc/resistor.h create mode 100644 inc/vision-artificial/proc/resistor.hpp create mode 100644 inc/vision-artificial/save/save.h create mode 100644 inc/vision-artificial/save/save.hpp create mode 100644 inc/vision-artificial/user/clui.h create mode 100644 inc/vision-artificial/user/iface.h create mode 100644 inc/vision-artificial/user/iface.hpp create mode 100644 inc/vision-artificial/user/tui.h delete mode 100644 modules/Makefile delete mode 100644 modules/about/Makefile delete mode 100644 modules/about/inc/about.h delete mode 100644 modules/about/inc/about.hpp delete mode 100644 modules/about/src/about.c delete mode 100644 modules/about/tmp/Makefile delete mode 100644 modules/ctrl/Makefile delete mode 100644 modules/ctrl/inc/start.h delete mode 100644 modules/ctrl/src/start.c delete mode 100644 modules/ctrl/tmp/Makefile delete mode 100644 modules/image/Makefile delete mode 100644 modules/image/inc/img_alx.hpp delete mode 100644 modules/image/inc/img_calib3d.hpp delete mode 100644 modules/image/inc/img_cv.hpp delete mode 100644 modules/image/inc/img_iface.h delete mode 100644 modules/image/inc/img_iface.hpp delete mode 100644 modules/image/inc/img_ocr.h delete mode 100644 modules/image/inc/img_ocr.hpp delete mode 100644 modules/image/inc/img_orb.hpp delete mode 100644 modules/image/inc/img_zbar.hpp delete mode 100644 modules/image/src/img_alx.cpp delete mode 100644 modules/image/src/img_calib3d.cpp delete mode 100644 modules/image/src/img_cv.cpp delete mode 100644 modules/image/src/img_iface.cpp delete mode 100644 modules/image/src/img_ocr.c delete mode 100644 modules/image/src/img_orb.cpp delete mode 100644 modules/image/src/img_zbar.cpp delete mode 100644 modules/image/tmp/Makefile delete mode 100644 modules/menu/Makefile delete mode 100644 modules/menu/inc/menu_clui.h delete mode 100644 modules/menu/inc/menu_iface.h delete mode 100644 modules/menu/inc/menu_iface.hpp delete mode 100644 modules/menu/inc/menu_tui.h delete mode 100644 modules/menu/inc/parser.h delete mode 100644 modules/menu/inc/parser.hpp delete mode 100644 modules/menu/src/menu_clui.c delete mode 100644 modules/menu/src/menu_iface.c delete mode 100644 modules/menu/src/menu_tui.c delete mode 100644 modules/menu/src/parser.c delete mode 100644 modules/menu/tmp/Makefile delete mode 100644 modules/proc/Makefile delete mode 100644 modules/proc/inc/proc_coins.h delete mode 100644 modules/proc/inc/proc_coins.hpp delete mode 100644 modules/proc/inc/proc_common.h delete mode 100644 modules/proc/inc/proc_common.hpp delete mode 100644 modules/proc/inc/proc_iface.h delete mode 100644 modules/proc/inc/proc_iface.hpp delete mode 100644 modules/proc/inc/proc_label.h delete mode 100644 modules/proc/inc/proc_label.hpp delete mode 100644 modules/proc/inc/proc_lighters.h delete mode 100644 modules/proc/inc/proc_lighters.hpp delete mode 100644 modules/proc/inc/proc_objects.h delete mode 100644 modules/proc/inc/proc_objects.hpp delete mode 100644 modules/proc/inc/proc_resistor.h delete mode 100644 modules/proc/inc/proc_resistor.hpp delete mode 100644 modules/proc/src/proc_coins.cpp delete mode 100644 modules/proc/src/proc_common.cpp delete mode 100644 modules/proc/src/proc_iface.c delete mode 100644 modules/proc/src/proc_label.cpp delete mode 100644 modules/proc/src/proc_lighters.cpp delete mode 100644 modules/proc/src/proc_objects.cpp delete mode 100644 modules/proc/src/proc_resistor.cpp delete mode 100644 modules/proc/tmp/Makefile delete mode 100644 modules/save/Makefile delete mode 100644 modules/save/inc/save.h delete mode 100644 modules/save/inc/save.hpp delete mode 100644 modules/save/src/save.cpp delete mode 100644 modules/save/tmp/Makefile delete mode 100644 modules/tmp/Makefile delete mode 100644 modules/user/Makefile delete mode 100644 modules/user/inc/user_clui.h delete mode 100644 modules/user/inc/user_iface.h delete mode 100644 modules/user/inc/user_iface.hpp delete mode 100644 modules/user/inc/user_tui.h delete mode 100644 modules/user/src/user_clui.c delete mode 100644 modules/user/src/user_iface.c delete mode 100644 modules/user/src/user_tui.c delete mode 100644 modules/user/tmp/Makefile delete mode 100644 share/COPYRIGHT.txt delete mode 100644 share/DISCLAIMER.txt delete mode 100644 share/HELP.txt delete mode 100644 share/LICENSE.txt delete mode 100644 share/README.txt delete mode 100644 share/USAGE.txt delete mode 100644 share/price create mode 100644 share/vision-artificial/COPYRIGHT.txt create mode 100644 share/vision-artificial/DISCLAIMER.txt create mode 100644 share/vision-artificial/HELP.txt create mode 100644 share/vision-artificial/LICENSE.txt create mode 100644 share/vision-artificial/README.txt create mode 100644 share/vision-artificial/USAGE.txt create mode 100644 share/vision-artificial/price create mode 100644 src/about/about.c create mode 100644 src/ctrl/start.c create mode 100644 src/image/alx.cpp create mode 100644 src/image/calib3d.cpp create mode 100644 src/image/cv.cpp create mode 100644 src/image/iface.cpp create mode 100644 src/image/ocr.c create mode 100644 src/image/orb.cpp create mode 100644 src/image/zbar.cpp create mode 100644 src/menu/clui.c create mode 100644 src/menu/iface.c create mode 100644 src/menu/parse.c create mode 100644 src/menu/tui.c create mode 100644 src/proc/coins.cpp create mode 100644 src/proc/common.cpp create mode 100644 src/proc/iface.c create mode 100644 src/proc/label.cpp create mode 100644 src/proc/lighters.cpp create mode 100644 src/proc/objects.cpp create mode 100644 src/proc/resistor.cpp create mode 100644 src/save/save.cpp create mode 100644 src/user/clui.c create mode 100644 src/user/iface.c create mode 100644 src/user/tui.c create mode 100644 tmp/about/Makefile create mode 100644 tmp/ctrl/Makefile create mode 100644 tmp/image/Makefile create mode 100644 tmp/menu/Makefile create mode 100644 tmp/proc/Makefile create mode 100644 tmp/save/Makefile create mode 100644 tmp/user/Makefile diff --git a/.gitignore b/.gitignore index 40bf91d..f04b795 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ *.o *.s *.a -bin/vision-artificial2 +bin/vision-artificial* diff --git a/Checkstyle/checkstyle b/Checkstyle/checkstyle index 052c674..02cfad2 100755 --- a/Checkstyle/checkstyle +++ b/Checkstyle/checkstyle @@ -12,10 +12,7 @@ # variables # ################################################################################ dirs=( - ../src/ - ../inc/ - ../modules/ - ../libalx/ + ../ ) diff --git a/Makefile b/Makefile index 4e409a2..f3bf5a4 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ -#!/usr/bin/make -f +#! /usr/bin/make -f VERSION = 2 -PATCHLEVEL = 0 +PATCHLEVEL = 1 SUBLEVEL = 0 EXTRAVERSION = NAME = @@ -69,6 +69,40 @@ MAKEFLAGS += --no-print-directory PROGRAMVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION) export PROGRAMVERSION +################################################################################ +# directories + +MAIN_DIR = $(CURDIR) + +LIBALX_DIR = $(CURDIR)/libalx/ +LIBALX_INC_DIR = $(LIBALX_DIR)/inc/ +LIBALX_LIB_DIR = $(LIBALX_DIR)/lib/libalx/ + +BIN_DIR = $(CURDIR)/bin/ +INC_DIR = $(CURDIR)/inc/ +SRC_DIR = $(CURDIR)/src/ +TMP_DIR = $(CURDIR)/tmp/ + +export MAIN_DIR +export LIBALX_DIR +export LIBALX_INC_DIR +export LIBALX_LIB_DIR +export BIN_DIR +export INC_DIR +export SRC_DIR +export TMP_DIR + +# FIXME: Set local or not local when building a package +INSTALL_BIN_DIR = /usr/local/bin/ +#INSTALL_BIN_DIR = /usr/bin/ +INSTALL_SHARE_DIR = /usr/local/share/ +#INSTALL_SHARE_DIR = /usr/share/ +INSTALL_VAR_DIR = /var/local/ +#INSTALL_VAR_DIR = /var/lib/ + +export INSTALL_DIR +export INSTALL_SHARE_DIR + ################################################################################ # Make variables (CC, etc...) CC = gcc @@ -87,7 +121,7 @@ export SZ ################################################################################ # cflags -CFLAGS_STD = -std=c11 +CFLAGS_STD = -std=c17 CFLAGS_STD += -Wpedantic CFLAGS_OPT = -O3 @@ -106,12 +140,11 @@ CFLAGS_PKG += `pkg-config --cflags opencv` CFLAGS_PKG += `pkg-config --cflags zbar` CFLAGS_PKG += `pkg-config --cflags tesseract` CFLAGS_PKG += `pkg-config --cflags lept` +CFLAGS_PKG += -I $(LIBALX_INC_DIR) CFLAGS_D = -D PROG_VERSION=\"$(PROGRAMVERSION)\" CFLAGS_D += -D INSTALL_SHARE_DIR=\"$(INSTALL_SHARE_DIR)\" -CFLAGS_D += -D SHARE_DIR=\"$(SHARE_DIR)\" CFLAGS_D += -D INSTALL_VAR_DIR=\"$(INSTALL_VAR_DIR)\" -CFLAGS_D += -D VAR_DIR=\"$(VAR_DIR)\" CFLAGS = $(CFLAGS_STD) CFLAGS += $(CFLAGS_OPT) @@ -140,12 +173,11 @@ CXXFLAGS_PKG += `pkg-config --cflags opencv` CXXFLAGS_PKG += `pkg-config --cflags zbar` CXXFLAGS_PKG += `pkg-config --cflags tesseract` CXXFLAGS_PKG += `pkg-config --cflags lept` +CXXFLAGS_PKG += -I $(LIBALX_INC_DIR) CXXFLAGS_D = -D PROG_VERSION=\"$(PROGRAMVERSION)\" CXXFLAGS_D += -D INSTALL_SHARE_DIR=\"$(INSTALL_SHARE_DIR)\" -CXXFLAGS_D += -D SHARE_DIR=\"$(SHARE_DIR)\" CXXFLAGS_D += -D INSTALL_VAR_DIR=\"$(INSTALL_VAR_DIR)\" -CXXFLAGS_D += -D VAR_DIR=\"$(VAR_DIR)\" CXXFLAGS = $(CXXFLAGS_STD) CXXFLAGS += $(CXXFLAGS_OPT) @@ -167,34 +199,6 @@ LIBS = $(LIBS_PKG) export LIBS -################################################################################ -# directories - -MAIN_DIR = $(CURDIR) - -LIBALX_DIR = $(CURDIR)/libalx/ -MODULES_DIR = $(CURDIR)/modules/ -TMP_DIR = $(CURDIR)/tmp/ -BIN_DIR = $(CURDIR)/bin/ - -export MAIN_DIR -export LIBALX_DIR -export MODULES_DIR - -# FIXME: Set local or not local when building a package -INSTALL_BIN_DIR = /usr/local/bin/ -#INSTALL_BIN_DIR = /usr/bin/ -INSTALL_SHARE_DIR = /usr/local/share/ -#INSTALL_SHARE_DIR = /usr/share/ -SHARE_DIR = vision-artificial/ -INSTALL_VAR_DIR = /var/local/ -#INSTALL_VAR_DIR = /var/lib/ -VAR_DIR = vision-artificial/ - -export INSTALL_DIR -export INSTALL_SHARE_DIR -export SHARE_DIR - ################################################################################ # executables @@ -208,33 +212,30 @@ export BIN_NAME # That's the default target when none is given on the command line PHONY := all -all: libalx modules main binary +all: bin PHONY += libalx libalx: - @echo ' MAKE libalx' - $(Q)$(MAKE) base -C $(LIBALX_DIR) - $(Q)$(MAKE) io -C $(LIBALX_DIR) - $(Q)$(MAKE) curses -C $(LIBALX_DIR) - @echo - -PHONY += modules -modules: libalx - @echo ' MAKE modules' - $(Q)$(MAKE) -C $(MODULES_DIR) + @echo " MAKE $@" + $(Q)$(MAKE) errno -C $(LIBALX_DIR) + $(Q)$(MAKE) math -C $(LIBALX_DIR) + $(Q)$(MAKE) stdio -C $(LIBALX_DIR) + $(Q)$(MAKE) stdlib -C $(LIBALX_DIR) + $(Q)$(MAKE) string -C $(LIBALX_DIR) + $(Q)$(MAKE) ncurses -C $(LIBALX_DIR) @echo -PHONY += main -main: modules libalx - @echo ' MAKE main' - $(Q)$(MAKE) -C $(TMP_DIR) +PHONY += tmp +tmp: + @echo " MAKE $@" + $(Q)$(MAKE) -C $(TMP_DIR) @echo -PHONY += binary -binary: main - @echo ' MAKE binary' - $(Q)$(MAKE) -C $(BIN_DIR) +PHONY += bin +bin: tmp libalx + @echo " MAKE $@" + $(Q)$(MAKE) -C $(BIN_DIR) @echo PHONY += install @@ -243,11 +244,11 @@ install: uninstall @echo " MKDIR $(INSTALL_BIN_DIR)/" $(Q)mkdir -p $(DESTDIR)/$(INSTALL_BIN_DIR)/ @echo " CP $(BIN_NAME)" - $(Q)cp $(BIN_DIR)/$(BIN_NAME) $(DESTDIR)/$(INSTALL_BIN_DIR)/ - @echo " MKDIR $(INSTALL_SHARE_DIR)/$(SHARE_DIR)/" - $(Q)mkdir -p $(DESTDIR)/$(INSTALL_SHARE_DIR)/$(SHARE_DIR)/ - @echo " CP -r share/*" - $(Q)cp -r ./share/* $(DESTDIR)/$(INSTALL_SHARE_DIR)/$(SHARE_DIR)/ + $(Q)cp -v $(BIN_DIR)/$(BIN_NAME) $(DESTDIR)/$(INSTALL_BIN_DIR)/ + @echo " MKDIR $(INSTALL_SHARE_DIR)/vision-artificial/" + $(Q)mkdir -p $(DESTDIR)/$(INSTALL_SHARE_DIR)/vision-artificial/ + @echo " CP -r share/vision-artificial/*" + $(Q)cp -r -v ./share/vision-artificial/* $(DESTDIR)/$(INSTALL_SHARE_DIR)/vision-artificial/ @echo " Done" @echo @@ -256,24 +257,22 @@ uninstall: @echo " Clean old installations:" @echo " RM bin" $(Q)rm -f $(DESTDIR)/$(INSTALL_BIN_DIR)/$(BIN_NAME) - @echo " RM -r $(INSTALL_SHARE_DIR)/$(SHARE_DIR)/" - $(Q)rm -f -r $(DESTDIR)/$(INSTALL_SHARE_DIR)/$(SHARE_DIR)/ + @echo " RM -r $(INSTALL_SHARE_DIR)/vision-artificial/" + $(Q)rm -f -r $(DESTDIR)/$(INSTALL_SHARE_DIR)/vision-artificial/ @echo " Done" @echo PHONY += clean clean: - @echo ' CLEAN modules' - $(Q)$(MAKE) clean -C $(MODULES_DIR) - @echo ' CLEAN tmp' - $(Q)$(MAKE) clean -C $(TMP_DIR) - @echo ' CLEAN bin' - $(Q)$(MAKE) clean -C $(BIN_DIR) + @echo " RM *.o *.s *.a $(BIN_NAME)" + $(Q)find $(TMP_DIR) -type f -name '*.o' -exec rm '{}' '+' + $(Q)find $(TMP_DIR) -type f -name '*.s' -exec rm '{}' '+' + $(Q)find $(BIN_DIR) -type f -name '*$(BIN_NAME)' -exec rm '{}' '+' @echo -PHONY += mrproper -mrproper: clean - @echo ' CLEAN libalx' +PHONY += distclean +distclean: clean + @echo " CLEAN libalx" $(Q)$(MAKE) clean -C $(LIBALX_DIR) @echo @@ -281,14 +280,13 @@ PHONY += help help: @echo 'Cleaning targets:' @echo ' clean - Remove all generated files' - @echo ' mrproper - Remove all generated files (including libraries)' + @echo ' distclean - Remove all generated files (including libraries)' @echo @echo 'Other generic targets:' @echo ' all - Build all targets marked with [*]' @echo '* libalx - Build the libalx library' - @echo '* modules - Build all modules' - @echo '* object - Build the main object' - @echo '* binary - Build the binary' + @echo '* tmp - Compile all files' + @echo '* bin - Build the binary' @echo ' install - Install the program into the filesystem' @echo ' uninstall - Uninstall the program off the filesystem' @echo @@ -302,8 +300,6 @@ help: .PHONY: $(PHONY) - - ################################################################################ ######## End of file ########################################################### ################################################################################ diff --git a/bin/Makefile b/bin/Makefile index e1f17df..d0b2d7b 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -1,40 +1,64 @@ -# -*- MakeFile -*- - -# directories - -LIBALX_LIB_DIR = $(LIBALX_DIR)/lib/ - -MODULES_TMP_DIR = $(MODULES_DIR)/tmp/ - -TMP_DIR = $(MAIN_DIR)/tmp/ +#! /usr/bin/make -f # dependencies -ALL = $(BIN_NAME) size -MAIN_OBJ_MODULES = modules.o -MAIN_OBJS = $(TMP_DIR)/main.o \ - $(patsubst %,$(MODULES_TMP_DIR)/%,$(MAIN_OBJ_MODULES)) +OBJS = \ + $(TMP_DIR)/main.o \ + $(TMP_DIR)/about/about.o \ + $(TMP_DIR)/ctrl/start.o \ + $(TMP_DIR)/image/alx.o \ + $(TMP_DIR)/image/calib3d.o \ + $(TMP_DIR)/image/cv.o \ + $(TMP_DIR)/image/iface.o \ + $(TMP_DIR)/image/ocr.o \ + $(TMP_DIR)/image/orb.o \ + $(TMP_DIR)/image/zbar.o \ + $(TMP_DIR)/menu/clui.o \ + $(TMP_DIR)/menu/iface.o \ + $(TMP_DIR)/menu/parse.o \ + $(TMP_DIR)/menu/tui.o \ + $(TMP_DIR)/proc/coins.o \ + $(TMP_DIR)/proc/common.o \ + $(TMP_DIR)/proc/iface.o \ + $(TMP_DIR)/proc/label.o \ + $(TMP_DIR)/proc/lighters.o \ + $(TMP_DIR)/proc/objects.o \ + $(TMP_DIR)/proc/resistor.o \ + $(TMP_DIR)/save/save.o \ + $(TMP_DIR)/user/clui.o \ + $(TMP_DIR)/user/iface.o \ + $(TMP_DIR)/user/tui.o +DEPS_LIBS = \ + $(LIBALX_LIB_DIR)/libalx-ncurses.a \ + $(LIBALX_LIB_DIR)/libalx-stdio.a \ + $(LIBALX_LIB_DIR)/libalx-errno.a \ + $(LIBALX_LIB_DIR)/libalx-math.a \ + $(LIBALX_LIB_DIR)/libalx-stdlib.a \ + $(LIBALX_LIB_DIR)/libalx-string.a -MAIN_LIB_LIBALX = libalx-base.a libalx-io.a libalx-curses.a -MAIN_LIBS = \ - $(patsubst %,$(LIBALX_LIB_DIR)/%,$(MAIN_LIB_LIBALX)) +ALL = $(BIN_NAME) size # static libs -STATIC_LIB_LIBALX = -L $(LIBALX_LIB_DIR) \ - -l alx-curses -l alx-io -l alx-base -STATIC_LIBS = $(STATIC_LIB_LIBALX) +STATIC_LIBS = -L $(LIBALX_LIB_DIR) \ + -l alx-ncurses \ + -l alx-stdio \ + -l alx-string \ + -l alx-errno \ + -l alx-math \ + -l alx-stdlib # target: dependencies # action +PHONY := all all: $(ALL) -$(BIN_NAME): $(MAIN_OBJS) $(MAIN_LIBS) +$(BIN_NAME): $(OBJS) $(DEPS_LIBS) @echo " CXX $@" - $(Q)$(CXX) $(MAIN_OBJS) -o $@ $(STATIC_LIBS) $(LIBS) + $(Q)$(CXX) $(OBJS) -o $@ $(STATIC_LIBS) $(LIBS) size: $(BIN_NAME) @echo " SZ $(BIN_NAME)" @@ -43,7 +67,11 @@ size: $(BIN_NAME) clean: @echo " RM $(ALL)" - $(Q)rm -f $(ALL) + $(Q)rm -f $(ALL) + +################################################################################ +# Declare the contents of the .PHONY variable as phony. +.PHONY: $(PHONY) ################################################################################ ######## End of file ########################################################### diff --git a/inc/vision-artificial/about/about.h b/inc/vision-artificial/about/about.h new file mode 100644 index 0000000..4faa574 --- /dev/null +++ b/inc/vision-artificial/about/about.h @@ -0,0 +1,79 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_ABOUT_ABOUT_H +#define VA_ABOUT_ABOUT_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include <stddef.h> +#include <stdio.h> + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +#define PROG_NAME "vision-artificial" +#define PROG_YEAR "2018" + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Share_File { + SHARE_COPYRIGHT, + SHARE_DISCLAIMER, + SHARE_HELP, + SHARE_LICENSE, + SHARE_USAGE +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +extern char share_path [FILENAME_MAX]; + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void about_init (void); +void snprint_share_file (ptrdiff_t size, char buff[restrict size], + int file); +void print_share_file (int share_file); +void print_version (void); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/about/about.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/about/about.hpp b/inc/vision-artificial/about/about.hpp new file mode 100644 index 0000000..1970a2b --- /dev/null +++ b/inc/vision-artificial/about/about.hpp @@ -0,0 +1,84 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_ABOUT_ABOUT_HPP +#define VA_ABOUT_ABOUT_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include <cstddef> +#include <cstdio> + +#include "libalx/base/stddef/restrict.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +#define PROG_NAME "vision-artificial" +#define PROG_YEAR "2018" + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Share_File { + SHARE_COPYRIGHT, + SHARE_DISCLAIMER, + SHARE_HELP, + SHARE_LICENSE, + SHARE_USAGE +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +extern char share_path [FILENAME_MAX]; + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +extern "C" +{ +void about_init (void); +void snprint_share_file (ptrdiff_t size, char *restrict buff, + int file); +void print_share_file (int share_file); +void print_version (void); +} + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/about/about.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/ctrl/start.h b/inc/vision-artificial/ctrl/start.h new file mode 100644 index 0000000..c7daeff --- /dev/null +++ b/inc/vision-artificial/ctrl/start.h @@ -0,0 +1,64 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_CTRL_START_H +#define VA_CTRL_START_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Start_Mode { + START_FOO = 0, + START_SINGLE, + START_SERIES +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +extern int start_mode; + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void start_switch (void); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/ctrl/start.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/image/alx.hpp b/inc/vision-artificial/image/alx.hpp new file mode 100644 index 0000000..cecb3a7 --- /dev/null +++ b/inc/vision-artificial/image/alx.hpp @@ -0,0 +1,77 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_IMAGE_ALX_H +#define VA_IMAGE_ALX_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include <opencv2/opencv.hpp> + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Img_Alx_Action { + IMG_ALX_ACT_FOO = 0x000000u, + + IMG_ALX_ACT_ALX = 0x000010u, + IMG_ALX_ACT_LOCAL_MAX, + IMG_ALX_ACT_SKELETON, + IMG_ALX_ACT_LINES_HORIZONTAL, + IMG_ALX_ACT_LINES_VERTICAL, + IMG_ALX_ACT_MEAN_HORIZONTAL, + IMG_ALX_ACT_MEAN_VERTICAL, + IMG_ALX_ACT_MEDIAN_HORIZONTAL, + IMG_ALX_ACT_MEDIAN_VERTICAL +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void img_alx_act (class cv::Mat *imgptr, int action, const void *data); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/image/alx.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/image/calib3d.hpp b/inc/vision-artificial/image/calib3d.hpp new file mode 100644 index 0000000..97a561a --- /dev/null +++ b/inc/vision-artificial/image/calib3d.hpp @@ -0,0 +1,71 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_IMAGE_CALIB3D_HPP +#define VA_IMAGE_CALIB3D_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include <opencv2/opencv.hpp> + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Img_Calib3d_Action { + IMG_CALIB3D_ACT_FOO = 0x000000u, + + IMG_CALIB3D_ACT_CALIB3D = 0x000400u, + IMG_CALIB3D_ACT_CALIBRATE, + IMG_CALIB3D_ACT_UNDISTORT +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void img_calib3d_act(class cv::Mat *imgptr, int action, const void *data); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/image/calib3d.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/image/cv.hpp b/inc/vision-artificial/image/cv.hpp new file mode 100644 index 0000000..681497a --- /dev/null +++ b/inc/vision-artificial/image/cv.hpp @@ -0,0 +1,71 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_IMAGE_CV_H +#define VA_IMAGE_CV_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include <opencv2/opencv.hpp> + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Img_Cv_Action { + IMG_CV_ACT_FOO = 0x000000u, + + IMG_CV_ACT_CV = 0x000100u, + IMG_CV_ACT_PIXEL_GET, + IMG_CV_ACT_PIXEL_SET, + IMG_CV_ACT_SET_ROI, + IMG_CV_ACT_AND_2REF, + IMG_CV_ACT_NOT, + IMG_CV_ACT_OR_2REF, + IMG_CV_ACT_COMPONENT, + IMG_CV_ACT_DILATE, + IMG_CV_ACT_ERODE, + IMG_CV_ACT_SMOOTH, + IMG_CV_ACT_SOBEL, + IMG_CV_ACT_BORDER, + IMG_CV_ACT_MIRROR, + IMG_CV_ACT_ROTATE_ORTO, + IMG_CV_ACT_ROTATE, + IMG_CV_ACT_ADAPTIVE_THRESHOLD, + IMG_CV_ACT_CVT_COLOR, + IMG_CV_ACT_DISTANCE_TRANSFORM, + IMG_CV_ACT_THRESHOLD, + IMG_CV_ACT_HISTOGRAM, + IMG_CV_ACT_HISTOGRAM_C3, + IMG_CV_ACT_CONTOURS, + IMG_CV_ACT_CONTOURS_SIZE, + IMG_CV_ACT_BOUNDING_RECT, + IMG_CV_ACT_FIT_ELLIPSE, + IMG_CV_ACT_MIN_AREA_RECT, + IMG_CV_ACT_HOUGH_CIRCLES +}; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void img_cv_act (class cv::Mat *imgptr, int action, const void *data); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/image/cv.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/image/iface.h b/inc/vision-artificial/image/iface.h new file mode 100644 index 0000000..f98a553 --- /dev/null +++ b/inc/vision-artificial/image/iface.h @@ -0,0 +1,191 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_IMAGE_IFACE_H +#define VA_IMAGE_IFACE_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include <stddef.h> + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +#define CONTOURS_MAX (0xFFFF) +#define OCR_TEXT_MAX (0xFFFFFF) +#define ZB_CODES_MAX (10) +#define ZBAR_LEN_MAX (0xFFFFFF) + +#define IMG_IFACE_THR_OTSU (-1) + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Img_Iface_Action { + IMG_IFACE_ACT_FOO = 0x000000u, + + IMG_IFACE_ACT_ALX = 0x000010u, + IMG_IFACE_ACT_LOCAL_MAX, + IMG_IFACE_ACT_SKELETON, + IMG_IFACE_ACT_LINES_HORIZONTAL, + IMG_IFACE_ACT_LINES_VERTICAL, + IMG_IFACE_ACT_MEAN_HORIZONTAL, + IMG_IFACE_ACT_MEAN_VERTICAL, + IMG_IFACE_ACT_MEDIAN_HORIZONTAL, + IMG_IFACE_ACT_MEDIAN_VERTICAL, + + IMG_IFACE_ACT_CV = 0x000100u, + IMG_IFACE_ACT_PIXEL_GET, + IMG_IFACE_ACT_PIXEL_SET, + IMG_IFACE_ACT_SET_ROI, + IMG_IFACE_ACT_SET_ROI_2RECT, + IMG_IFACE_ACT_AND_2REF, + IMG_IFACE_ACT_NOT, + IMG_IFACE_ACT_OR_2REF, + IMG_IFACE_ACT_COMPONENT, + IMG_IFACE_ACT_DILATE, + IMG_IFACE_ACT_ERODE, + IMG_IFACE_ACT_DILATE_ERODE, + IMG_IFACE_ACT_ERODE_DILATE, + IMG_IFACE_ACT_SMOOTH, + IMG_IFACE_ACT_SOBEL, + IMG_IFACE_ACT_BORDER, + IMG_IFACE_ACT_MIRROR, + IMG_IFACE_ACT_ROTATE_ORTO, + IMG_IFACE_ACT_ROTATE, + IMG_IFACE_ACT_ROTATE_2RECT, + IMG_IFACE_ACT_ADAPTIVE_THRESHOLD, + IMG_IFACE_ACT_CVT_COLOR, + IMG_IFACE_ACT_DISTANCE_TRANSFORM, + IMG_IFACE_ACT_THRESHOLD, + IMG_IFACE_ACT_HISTOGRAM, + IMG_IFACE_ACT_HISTOGRAM_C3, + IMG_IFACE_ACT_CONTOURS, + IMG_IFACE_ACT_CONTOURS_SIZE, + IMG_IFACE_ACT_BOUNDING_RECT, + IMG_IFACE_ACT_FIT_ELLIPSE, + IMG_IFACE_ACT_MIN_AREA_RECT, + IMG_IFACE_ACT_HOUGH_CIRCLES, + + IMG_IFACE_ACT_ORB = 0x000200u, + IMG_IFACE_ACT_ALIGN, + + IMG_IFACE_ACT_CALIB3D = 0x000400u, + IMG_IFACE_ACT_CALIBRATE, + IMG_IFACE_ACT_UNDISTORT, + + IMG_IFACE_ACT_ZB = 0x000800u, + IMG_IFACE_ACT_DECODE, + + IMG_IFACE_ACT_OCR = 0x001000u, + IMG_IFACE_ACT_READ, + + IMG_IFACE_ACT_IMGI = 0x002000u, + IMG_IFACE_ACT_APPLY, + IMG_IFACE_ACT_DISCARD, + IMG_IFACE_ACT_SAVE_MEM, + IMG_IFACE_ACT_LOAD_MEM, + IMG_IFACE_ACT_SAVE_REF, + + IMG_IFACE_ACT_SAVE = 0x004000u, + IMG_IFACE_ACT_SAVE_FILE, + IMG_IFACE_ACT_SAVE_UPDT +}; + +enum Img_Iface_Cmp_BGR { + IMG_IFACE_CMP_BLUE = 0, + IMG_IFACE_CMP_GREEN, + IMG_IFACE_CMP_RED +}; + +enum Img_Iface_Cmp_HSV { + IMG_IFACE_CMP_HUE = 0, + IMG_IFACE_CMP_SATURATION, + IMG_IFACE_CMP_VALUE +}; + +enum ImgI_Smooth { + IMGI_SMOOTH_MEAN = 0, + IMGI_SMOOTH_GAUSS, + IMGI_SMOOTH_MEDIAN +}; + +enum Img_Iface_OCR_Lang { + IMG_IFACE_OCR_LANG_ENG = 0, + IMG_IFACE_OCR_LANG_SPA, + IMG_IFACE_OCR_LANG_CAT, + IMG_IFACE_OCR_LANG_DIGITS, + IMG_IFACE_OCR_LANG_DIGITS_COMMA +}; + +enum Img_Iface_OCR_Conf { + IMG_IFACE_OCR_CONF_NONE = 0, + IMG_IFACE_OCR_CONF_PRICE +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ +struct Img_Iface_Data_Read { + int lang; + int conf; + struct { + void *data; + ptrdiff_t width; + ptrdiff_t height; + int B_per_pix; + int B_per_line; + } img; +}; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +extern char img_ocr_text [OCR_TEXT_MAX]; +extern struct Img_Iface_ZB_Codes zb_codes; + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void img_iface_init (void); +void img_iface_deinit (void); +void img_iface_load (const char *fpath, const char *fname); +void img_iface_cleanup (void); +void img_iface_act (int action, const void *data); +void img_iface_show_img (void); +void img_iface_show_hist_c1 (void); +void img_iface_show_hist_c3 (void); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/image/iface.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/image/iface.hpp b/inc/vision-artificial/image/iface.hpp new file mode 100644 index 0000000..3d1fdd4 --- /dev/null +++ b/inc/vision-artificial/image/iface.hpp @@ -0,0 +1,333 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_IMAGE_IFACE_HPP +#define VA_IMAGE_IFACE_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include <cstddef> + +#include <vector> + +#include <opencv2/opencv.hpp> + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +#define CONTOURS_MAX (0xFFFF) +#define OCR_TEXT_MAX (0xFFFFFF) +#define ZB_CODES_MAX (10) +#define ZBAR_LEN_MAX (0xFFFFFF) + +#define IMG_IFACE_THR_OTSU (-1) + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Img_Iface_Action { + IMG_IFACE_ACT_FOO = 0x000000u, + + IMG_IFACE_ACT_ALX = 0x000010u, + IMG_IFACE_ACT_LOCAL_MAX, + IMG_IFACE_ACT_SKELETON, + IMG_IFACE_ACT_LINES_HORIZONTAL, + IMG_IFACE_ACT_LINES_VERTICAL, + IMG_IFACE_ACT_MEAN_HORIZONTAL, + IMG_IFACE_ACT_MEAN_VERTICAL, + IMG_IFACE_ACT_MEDIAN_HORIZONTAL, + IMG_IFACE_ACT_MEDIAN_VERTICAL, + + IMG_IFACE_ACT_CV = 0x000100u, + IMG_IFACE_ACT_PIXEL_GET, + IMG_IFACE_ACT_PIXEL_SET, + IMG_IFACE_ACT_SET_ROI, + IMG_IFACE_ACT_SET_ROI_2RECT, + IMG_IFACE_ACT_AND_2REF, + IMG_IFACE_ACT_NOT, + IMG_IFACE_ACT_OR_2REF, + IMG_IFACE_ACT_COMPONENT, + IMG_IFACE_ACT_DILATE, + IMG_IFACE_ACT_ERODE, + IMG_IFACE_ACT_DILATE_ERODE, + IMG_IFACE_ACT_ERODE_DILATE, + IMG_IFACE_ACT_SMOOTH, + IMG_IFACE_ACT_SOBEL, + IMG_IFACE_ACT_BORDER, + IMG_IFACE_ACT_MIRROR, + IMG_IFACE_ACT_ROTATE_ORTO, + IMG_IFACE_ACT_ROTATE, + IMG_IFACE_ACT_ROTATE_2RECT, + IMG_IFACE_ACT_ADAPTIVE_THRESHOLD, + IMG_IFACE_ACT_CVT_COLOR, + IMG_IFACE_ACT_DISTANCE_TRANSFORM, + IMG_IFACE_ACT_THRESHOLD, + IMG_IFACE_ACT_HISTOGRAM, + IMG_IFACE_ACT_HISTOGRAM_C3, + IMG_IFACE_ACT_CONTOURS, + IMG_IFACE_ACT_CONTOURS_SIZE, + IMG_IFACE_ACT_BOUNDING_RECT, + IMG_IFACE_ACT_FIT_ELLIPSE, + IMG_IFACE_ACT_MIN_AREA_RECT, + IMG_IFACE_ACT_HOUGH_CIRCLES, + + IMG_IFACE_ACT_ORB = 0x000200u, + IMG_IFACE_ACT_ALIGN, + + IMG_IFACE_ACT_CALIB3D = 0x000400u, + IMG_IFACE_ACT_CALIBRATE, + IMG_IFACE_ACT_UNDISTORT, + + IMG_IFACE_ACT_ZB = 0x000800u, + IMG_IFACE_ACT_DECODE, + + IMG_IFACE_ACT_OCR = 0x001000u, + IMG_IFACE_ACT_READ, + + IMG_IFACE_ACT_IMGI = 0x002000u, + IMG_IFACE_ACT_APPLY, + IMG_IFACE_ACT_DISCARD, + IMG_IFACE_ACT_SAVE_MEM, + IMG_IFACE_ACT_LOAD_MEM, + IMG_IFACE_ACT_SAVE_REF, + + IMG_IFACE_ACT_SAVE = 0x004000u, + IMG_IFACE_ACT_SAVE_FILE, + IMG_IFACE_ACT_SAVE_UPDT +}; + +enum Img_Iface_Cmp { + IMG_IFACE_CMP_BLUE = 0, + IMG_IFACE_CMP_GREEN, + IMG_IFACE_CMP_RED +}; + +enum Img_Iface_Cmp_HSV { + IMG_IFACE_CMP_HUE = 0, + IMG_IFACE_CMP_SATURATION, + IMG_IFACE_CMP_VALUE +}; + +enum ImgI_Smooth { + IMGI_SMOOTH_MEAN = 1, + IMGI_SMOOTH_GAUSS, + IMGI_SMOOTH_MEDIAN +}; + +enum Img_Iface_OCR_Lang { + IMG_IFACE_OCR_LANG_ENG = 0, + IMG_IFACE_OCR_LANG_SPA, + IMG_IFACE_OCR_LANG_CAT, + IMG_IFACE_OCR_LANG_DIGITS, + IMG_IFACE_OCR_LANG_DIGITS_COMMA +}; + +enum Img_Iface_OCR_Conf { + IMG_IFACE_OCR_CONF_NONE = 0, + IMG_IFACE_OCR_CONF_PRICE +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ +/* cv ------------------------------------------------------------------------*/ +struct Img_Iface_Data_Pixel_Get { + unsigned char *val; + ptrdiff_t x; + ptrdiff_t y; +}; + +struct Img_Iface_Data_Pixel_Set { + unsigned char val; + ptrdiff_t x; + ptrdiff_t y; +}; + +struct Img_Iface_Data_SetROI { + class cv::Rect_ <int> rect; +}; + +struct Img_Iface_Data_Component { + ptrdiff_t cmp; +}; + +struct Img_Iface_Data_Dilate_Erode { + int i; +}; + +struct Img_Iface_Data_Smooth { + int method; + int ksize; +}; + +struct Img_Iface_Data_Sobel { + int dx; + int dy; + int ksize; +}; + +struct Img_Iface_Data_Border { + ptrdiff_t size; +}; + +struct Img_Iface_Data_Mirror { + int axis; +}; + +struct Img_Iface_Data_Rotate_Orto { + int n; +}; + +struct Img_Iface_Data_Rotate { + class cv::Point_ <float> center; + double angle; +}; + +struct Img_Iface_Data_Adaptive_Thr { + int method; + int thr_typ; + int ksize; +}; + +struct Img_Iface_Data_Cvt_Color { + int method; +}; + +struct Img_Iface_Data_Threshold { + int thr_typ; + int thr_val; +}; + +struct Img_Iface_Data_Histogram { + class cv::Mat *hist_c0; + class cv::Mat *hist_c1; + class cv::Mat *hist_c2; + class cv::Mat *hist_img; +}; + +struct Img_Iface_Data_Contours { + class std::vector <class std::vector <class cv::Point_ <int>>> *contours; + class cv::Mat *hierarchy; +}; + +struct Img_Iface_Data_Contours_Size { + const class std::vector <class std::vector <class cv::Point_ <int>>> *contours; + double *area; + double *perimeter; +}; + +struct Img_Iface_Data_Bounding_Rect { + const class std::vector <class cv::Point_ <int>> *contour; + class cv::Rect_ <int> *rect; + bool show; +}; + +struct Img_Iface_Data_MinARect { + const class std::vector <class cv::Point_ <int>> *contour; + class cv::RotatedRect *rect; + bool show; +}; + +struct Img_Iface_Data_Hough_Circles { + class std::vector <class cv::Vec <float, 3>> *circles; + double dist_min; + double param_1; + double param_2; + int radius_min; + int radius_max; +}; + +/* calib3d -------------------------------------------------------------------*/ +struct Img_Iface_Data_Calibrate { + class cv::Mat *intrinsic_mat; + class cv::Mat *dist_coefs; + class std::vector <class cv::Mat> *rvecs; + class std::vector <class cv::Mat> *tvecs; +}; + +struct Img_Iface_Data_Undistort { + const class cv::Mat *intrinsic_mat; + const class cv::Mat *dist_coefs; +}; + +/* zbar ----------------------------------------------------------------------*/ +struct Img_Iface_Data_Decode { + int code_type; +}; + +struct Img_Iface_ZB_Codes { + ptrdiff_t n; + struct { + int type; + char sym_name [80]; + char data [ZBAR_LEN_MAX]; + } arr [ZB_CODES_MAX]; +}; + +/* ocr -----------------------------------------------------------------------*/ +struct Img_Iface_Data_Read { + int lang; + int conf; + struct { + void *data; + ptrdiff_t width; + ptrdiff_t height; + int B_per_pix; + int B_per_line; + } img; +}; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +extern char img_ocr_text [OCR_TEXT_MAX]; +extern struct Img_Iface_ZB_Codes zb_codes; + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +extern "C" +{ +void img_iface_init (void); +void img_iface_deinit (void); +void img_iface_load (const char *fpath, const char *fname); +void img_iface_cleanup (void); +void img_iface_act (int action, const void *data); +void img_iface_show_img (void); +void img_iface_show_hist_c1 (void); +void img_iface_show_hist_c3 (void); +} + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/image/iface.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/image/ocr.h b/inc/vision-artificial/image/ocr.h new file mode 100644 index 0000000..adf30b9 --- /dev/null +++ b/inc/vision-artificial/image/ocr.h @@ -0,0 +1,64 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_IMAGE_OCR_H +#define VA_IMAGE_OCR_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Img_OCR_Action { + IMG_OCR_ACT_FOO = 0x000000u, + + IMG_OCR_ACT_OCR = 0x001000u, + IMG_OCR_ACT_READ +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void img_ocr_act (int action, const void *data); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/image/ocr.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/image/ocr.hpp b/inc/vision-artificial/image/ocr.hpp new file mode 100644 index 0000000..7984152 --- /dev/null +++ b/inc/vision-artificial/image/ocr.hpp @@ -0,0 +1,66 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_IMG_OCR_HPP +#define VA_IMG_OCR_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Img_OCR_Action { + IMG_OCR_ACT_FOO = 0x000000u, + + IMG_OCR_ACT_OCR = 0x001000u, + IMG_OCR_ACT_READ +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +extern "C" { +void img_ocr_act (int action, const void *data); +} + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/image/ocr.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/image/orb.hpp b/inc/vision-artificial/image/orb.hpp new file mode 100644 index 0000000..98f5b14 --- /dev/null +++ b/inc/vision-artificial/image/orb.hpp @@ -0,0 +1,71 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_IMAGE_ORB_HPP +#define VA_IMAGE_ORB_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include <opencv2/opencv.hpp> + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Img_ORB_Action { + IMG_ORB_ACT_FOO = 0x000000u, + + IMG_ORB_ACT_ORB = 0x000200u, + IMG_ORB_ACT_ALIGN +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void img_orb_act (const class cv::Mat *img_ref, + class cv::Mat *imgptr, int action); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/image/orb.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/image/zbar.hpp b/inc/vision-artificial/image/zbar.hpp new file mode 100644 index 0000000..6072289 --- /dev/null +++ b/inc/vision-artificial/image/zbar.hpp @@ -0,0 +1,70 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_IMAGE_ZBAR_HPP +#define VA_IMAGE_ZBAR_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include <opencv2/opencv.hpp> + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Img_ZB_Action { + IMG_ZB_ACT_FOO = 0x000000u, + + IMG_ZB_ACT_ZB = 0x000800u, + IMG_ZB_ACT_DECODE +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void img_zb_act (class cv::Mat *imgptr, int action, const void *data); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/image/zbar.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/menu/clui.h b/inc/vision-artificial/menu/clui.h new file mode 100644 index 0000000..02ac0d5 --- /dev/null +++ b/inc/vision-artificial/menu/clui.h @@ -0,0 +1,63 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_MENU_CLUI_H +#define VA_MENU_CLUI_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void menu_clui (void); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/menu/clui.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/menu/iface.h b/inc/vision-artificial/menu/iface.h new file mode 100644 index 0000000..e671c8d --- /dev/null +++ b/inc/vision-artificial/menu/iface.h @@ -0,0 +1,69 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_MENU_IFACE_H +#define VA_MENU_IFACE_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Menu_Iface_Mode { + MENU_IFACE_FOO = 0, + MENU_IFACE_CLUI, + MENU_IFACE_TUI + }; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +extern int menu_iface_mode; + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void menu_iface (void); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/menu/iface.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/menu/iface.hpp b/inc/vision-artificial/menu/iface.hpp new file mode 100644 index 0000000..825c1eb --- /dev/null +++ b/inc/vision-artificial/menu/iface.hpp @@ -0,0 +1,72 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_MENU_IFACE_HPP +#define VA_MENU_IFACE_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Menu_Iface_Mode { + MENU_IFACE_FOO = 0, + MENU_IFACE_CLUI, + MENU_IFACE_TUI + }; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +extern int menu_iface_mode; + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +extern "C" +{ +void menu_iface (void); +} + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/menu/iface.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/menu/parse.h b/inc/vision-artificial/menu/parse.h new file mode 100644 index 0000000..9bd1182 --- /dev/null +++ b/inc/vision-artificial/menu/parse.h @@ -0,0 +1,63 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_PARSE_H +#define VA_PARSE_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void parse (int argc, char *argv[]); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/menu/parse.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/menu/parse.hpp b/inc/vision-artificial/menu/parse.hpp new file mode 100644 index 0000000..85dcbef --- /dev/null +++ b/inc/vision-artificial/menu/parse.hpp @@ -0,0 +1,66 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PARSER_HPP + # define VA_PARSER_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +extern "C" +{ +void parse (int argc, char *argv[]); +} + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/menu/parse.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/menu/tui.h b/inc/vision-artificial/menu/tui.h new file mode 100644 index 0000000..a55ab49 --- /dev/null +++ b/inc/vision-artificial/menu/tui.h @@ -0,0 +1,63 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_MENU_TUI_H +#define VA_MENU_TUI_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void menu_tui (void); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/menu/tui.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/proc/coins.h b/inc/vision-artificial/proc/coins.h new file mode 100644 index 0000000..74c7ede --- /dev/null +++ b/inc/vision-artificial/proc/coins.h @@ -0,0 +1,69 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_PROC_COINS_H +#define VA_PROC_COINS_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Proc_Coins { + COINS_OK, + COINS_NOK_COINS, + COINS_NOK_OVERLAP, + COINS_NOK_SIZE +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +int proc_coins (void); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/proc/coins.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/proc/coins.hpp b/inc/vision-artificial/proc/coins.hpp new file mode 100644 index 0000000..d64486e --- /dev/null +++ b/inc/vision-artificial/proc/coins.hpp @@ -0,0 +1,72 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_PROC_COINS_HPP +#define VA_PROC_COINS_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Proc_Coins { + COINS_OK, + COINS_NOK_COINS, + COINS_NOK_OVERLAP, + COINS_NOK_SIZE +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +extern "C" +{ +int proc_coins (void); +} + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/proc/coins.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/proc/common.h b/inc/vision-artificial/proc/common.h new file mode 100644 index 0000000..f5844fc --- /dev/null +++ b/inc/vision-artificial/proc/common.h @@ -0,0 +1,65 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_PROC_COMMON_H +#define VA_PROC_COMMON_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void proc_show_img (void); +void clock_start (void); +void clock_stop (const char *txt); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/proc/common.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/proc/common.hpp b/inc/vision-artificial/proc/common.hpp new file mode 100644 index 0000000..0b65f05 --- /dev/null +++ b/inc/vision-artificial/proc/common.hpp @@ -0,0 +1,127 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_PROC_COMMON_HPP +#define VA_PROC_COMMON_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include <cstdbool> + +#include <vector> + +#include <opencv2/opencv.hpp> + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +extern "C" +{ +void proc_apply (void); +void proc_save_mem (ptrdiff_t n); +void proc_load_mem (ptrdiff_t n); +void proc_save_ref (void); +void proc_save_file (void); +void proc_save_update (void); + +void proc_local_max (void); +void proc_skeleton (void); +void proc_lines_vertical (void); +void proc_median_horizontal (void); +void proc_median_vertical (void); + +void proc_pixel_get (ptrdiff_t x, ptrdiff_t y, unsigned char *val); +void proc_pixel_set (ptrdiff_t x, ptrdiff_t y, unsigned char val); +void proc_ROI (int x, int y, int w, int h); +void proc_and_2ref (void); +void proc_not (void); +void proc_or_2ref (void); +void proc_cmp (int cmp); +void proc_dilate (int size); +void proc_erode (int size); +void proc_dilate_erode (int size); +void proc_erode_dilate (int size); +void proc_smooth (int method, int ksize); +void proc_border (int size); +void proc_rotate (float center_x, float center_y, double angle); +void proc_adaptive_threshold (int method, int type, int ksize); +void proc_cvt_color (int method); +void proc_distance_transform (void); +void proc_threshold (int type, int ksize); +void proc_contours ( + class std::vector <class std::vector <class cv::Point_ <int>>> *contours, + class cv::Mat *hierarchy); +void proc_contours_size ( + const class std::vector <class std::vector <class cv::Point_ <int>>> *contours, + double *area, + double *perimeter); +void proc_bounding_rect ( + const class std::vector <class cv::Point_ <int>> *contour, + class cv::Rect_ <int> *rect, + bool show); +void proc_fit_ellipse ( + const class std::vector <class cv::Point_ <int>> *contour, + class cv::RotatedRect *rect, + bool show); +void proc_min_area_rect ( + const class std::vector <class cv::Point_ <int>> *contour, + class cv::RotatedRect *rect, + bool show); + +void proc_OCR (int lang, int conf); +void proc_zbar (int type); + +void proc_show_img (void); +void clock_start (void); +void clock_stop (const char *txt); +} + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/proc/common.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/proc/iface.h b/inc/vision-artificial/proc/iface.h new file mode 100644 index 0000000..267809c --- /dev/null +++ b/inc/vision-artificial/proc/iface.h @@ -0,0 +1,88 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_PROC_IFACE_H +#define VA_PROC_IFACE_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Proc_Mode { + PROC_MODE_FOO, + + PROC_MODE = 0x008000u, + PROC_MODE_LABEL_SERIES, + PROC_MODE_LABEL_CALIB, + PROC_MODE_OBJECTS_SERIES, + PROC_MODE_OBJECTS_CALIB, + PROC_MODE_COINS_SERIES, + PROC_MODE_COINS_CALIB, + PROC_MODE_RESISTOR_SERIES, + PROC_MODE_RESISTOR_CALIB, + PROC_MODE_LIGHTERS_SERIES, + PROC_MODE_LIGHTERS_CALIB +}; + +enum Proc_DBG { + PROC_DBG_NO, + PROC_DBG_STOP_ITEM, + PROC_DBG_DELAY_STEP, + PROC_DBG_STOP_STEP +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +extern int proc_debug; +extern int proc_mode; + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +int proc_iface_single (int action); +void proc_iface_series (void); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/proc/iface.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/proc/iface.hpp b/inc/vision-artificial/proc/iface.hpp new file mode 100644 index 0000000..ce54ead --- /dev/null +++ b/inc/vision-artificial/proc/iface.hpp @@ -0,0 +1,91 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_PROC_IFACE_HPP +#define VA_PROC_IFACE_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Proc_Mode { + PROC_MODE_FOO, + + PROC_MODE = 0x008000u, + PROC_MODE_LABEL_SERIES, + PROC_MODE_LABEL_CALIB, + PROC_MODE_OBJECTS_SERIES, + PROC_MODE_OBJECTS_CALIB, + PROC_MODE_COINS_SERIES, + PROC_MODE_COINS_CALIB, + PROC_MODE_RESISTOR_SERIES, + PROC_MODE_RESISTOR_CALIB, + PROC_MODE_LIGHTERS_SERIES, + PROC_MODE_LIGHTERS_CALIB +}; + +enum Proc_DBG { + PROC_DBG_NO, + PROC_DBG_STOP_ITEM, + PROC_DBG_DELAY_STEP, + PROC_DBG_STOP_STEP +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +extern int proc_debug; +extern int proc_mode; + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +extern "C" +{ +int proc_iface_single (int action); +void proc_iface_series (void); +} + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/proc/iface.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/proc/label.h b/inc/vision-artificial/proc/label.h new file mode 100644 index 0000000..0731ada --- /dev/null +++ b/inc/vision-artificial/proc/label.h @@ -0,0 +1,71 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_PROC_LABEL_H +#define VA_PROC_LABEL_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Proc_Label { + LABEL_OK, + LABEL_NOK_LABEL, + LABEL_NOK_CERDO, + LABEL_NOK_BCODE, + LABEL_NOK_PRODUCT, + LABEL_NOK_PRICE +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +int proc_label (void); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/proc/label.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/proc/label.hpp b/inc/vision-artificial/proc/label.hpp new file mode 100644 index 0000000..e4a2adf --- /dev/null +++ b/inc/vision-artificial/proc/label.hpp @@ -0,0 +1,74 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_PROC_LABEL_HPP +#define VA_PROC_LABEL_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Proc_Label { + LABEL_OK, + LABEL_NOK_LABEL, + LABEL_NOK_CERDO, + LABEL_NOK_BCODE, + LABEL_NOK_PRODUCT, + LABEL_NOK_PRICE +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +extern "C" +{ +int proc_label (void); +} + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/proc/label.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/proc/lighters.h b/inc/vision-artificial/proc/lighters.h new file mode 100644 index 0000000..1b6eea4 --- /dev/null +++ b/inc/vision-artificial/proc/lighters.h @@ -0,0 +1,68 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_PROC_LIGHTERS_H +#define VA_PROC_LIGHTERS_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Proc_Lighter { + LIGHTER_OK, + LIGHTER_NOK_LIGHTER, + LIGHTER_NOK_SIZE +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +int proc_lighter (void); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/proc/lighters.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/proc/lighters.hpp b/inc/vision-artificial/proc/lighters.hpp new file mode 100644 index 0000000..daf3ac0 --- /dev/null +++ b/inc/vision-artificial/proc/lighters.hpp @@ -0,0 +1,71 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_PROC_LIGHTERS_HPP +#define VA_PROC_LIGHTERS_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Proc_Lighter { + LIGHTER_OK, + LIGHTER_NOK_LIGHTER, + LIGHTER_NOK_SIZE +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +extern "C" +{ +int proc_lighter (void); +} + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/proc/lighters.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/proc/objects.h b/inc/vision-artificial/proc/objects.h new file mode 100644 index 0000000..32e57ff --- /dev/null +++ b/inc/vision-artificial/proc/objects.h @@ -0,0 +1,70 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_PROC_OBJECTS_H +#define VA_PROC_OBJECTS_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Proc_Objects { + OBJECTS_OK, + OBJECTS_NOK_PATTERN, + OBJECTS_NOK_OBJECTS, + OBJECTS_NOK_SIZE +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +int proc_objects_calibrate (void); +int proc_objects (void); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/proc/objects.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/proc/objects.hpp b/inc/vision-artificial/proc/objects.hpp new file mode 100644 index 0000000..405ef82 --- /dev/null +++ b/inc/vision-artificial/proc/objects.hpp @@ -0,0 +1,73 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_PROC_OBJECTS_HPP +#define VA_PROC_OBJECTS_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Proc_Objects { + OBJECTS_OK, + OBJECTS_NOK_PATTERN, + OBJECTS_NOK_OBJECTS, + OBJECTS_NOK_SIZE +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +extern "C" +{ +int proc_objects_calibrate (void); +int proc_objects (void); +} + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/proc/objects.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/proc/resistor.h b/inc/vision-artificial/proc/resistor.h new file mode 100644 index 0000000..51dd735 --- /dev/null +++ b/inc/vision-artificial/proc/resistor.h @@ -0,0 +1,71 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_PROC_RESISTOR_H +#define VA_PROC_RESISTOR_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Proc_Resistor { + RESISTOR_OK, + RESISTOR_NOK_RESISTOR, + RESISTOR_NOK_BANDS, + RESISTOR_NOK_COLOR, + RESISTOR_NOK_STD_VALUE, + RESISTOR_NOK_TOLERANCE +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +int proc_resistor (void); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/proc/resistor.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/proc/resistor.hpp b/inc/vision-artificial/proc/resistor.hpp new file mode 100644 index 0000000..d69908e --- /dev/null +++ b/inc/vision-artificial/proc/resistor.hpp @@ -0,0 +1,74 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_PROC_RESISTOR_HPP +#define VA_PROC_RESISTOR_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Proc_Resistor { + RESISTOR_OK, + RESISTOR_NOK_RESISTOR, + RESISTOR_NOK_BANDS, + RESISTOR_NOK_COLOR, + RESISTOR_NOK_STD_VALUE, + RESISTOR_NOK_TOLERANCE +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +extern "C" +{ +int proc_resistor (void); +} + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/proc/resistor.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/save/save.h b/inc/vision-artificial/save/save.h new file mode 100644 index 0000000..87bddae --- /dev/null +++ b/inc/vision-artificial/save/save.h @@ -0,0 +1,99 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_SAVE_SAVE_H +#define VA_SAVE_SAVE_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include <stdio.h> + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +#define ENV_HOME "HOME" + +#define USER_PROG_DIR "vision-artificial/" +#define USER_SAVED_DIR "vision-artificial/saved/" +#define USER_LABELS_DIR "vision-artificial/labels/" +#define USER_LABELS_FAIL_DIR "vision-artificial/labels/fail" +#define USER_LIGHTERS_DIR "vision-artificial/lighters/" +#define USER_LIGHTERS_FAIL_DIR "vision-artificial/lighters/fail" +#define USER_OBJECTS_DIR "vision-artificial/objects/" +#define USER_OBJECTS_FAIL_DIR "vision-artificial/objects/fail" +#define USER_COINS_DIR "vision-artificial/coins/" +#define USER_COINS_FAIL_DIR "vision-artificial/coins/fail" +#define USER_RESISTORS_DIR "vision-artificial/resistors/" +#define USER_RESISTORS_FAIL_DIR "vision-artificial/resistors/fail" +#define SAVED_NAME_DEFAULT "saved" + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +extern char home_path [FILENAME_MAX]; +extern char user_prog_path [FILENAME_MAX]; +extern char saved_path [FILENAME_MAX]; +extern char labels_path [FILENAME_MAX]; +extern char labels_fail_path [FILENAME_MAX]; +extern char lighters_path [FILENAME_MAX]; +extern char lighters_fail_path [FILENAME_MAX]; +extern char objects_path [FILENAME_MAX]; +extern char objects_fail_path [FILENAME_MAX]; +extern char coins_path [FILENAME_MAX]; +extern char coins_fail_path [FILENAME_MAX]; +extern char resistors_path [FILENAME_MAX]; +extern char resistors_fail_path [FILENAME_MAX]; +extern char saved_name [FILENAME_MAX]; + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void save_init (void); +void save_cleanup (void); +void save_reset_fpath(void); +void load_image_file (const char *restrict fpath, + const char *restrict fname); +void save_image_file (const char *restrict fpath, + const char *restrict save_as); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/save/save.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/save/save.hpp b/inc/vision-artificial/save/save.hpp new file mode 100644 index 0000000..aa05474 --- /dev/null +++ b/inc/vision-artificial/save/save.hpp @@ -0,0 +1,105 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_SAVE_SAVE_HPP +#define VA_SAVE_SAVE_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include <cstdio> + +#include <opencv2/opencv.hpp> + +#include "libalx/base/stddef/restrict.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define ENV_HOME "HOME" + + # define USER_PROG_DIR "vision-artificial/" + # define USER_SAVED_DIR "vision-artificial/saved/" + # define USER_LABELS_DIR "vision-artificial/labels/" + # define USER_LABELS_FAIL_DIR "vision-artificial/labels/fail" + # define USER_LIGHTERS_DIR "vision-artificial/lighters/" + # define USER_LIGHTERS_FAIL_DIR "vision-artificial/lighters/fail" + # define USER_OBJECTS_DIR "vision-artificial/objects/" + # define USER_OBJECTS_FAIL_DIR "vision-artificial/objects/fail" + # define USER_COINS_DIR "vision-artificial/coins/" + # define USER_COINS_FAIL_DIR "vision-artificial/coins/fail" + # define USER_RESISTORS_DIR "vision-artificial/resistors/" + # define USER_RESISTORS_FAIL_DIR "vision-artificial/resistors/fail" + # define SAVED_NAME_DEFAULT "saved" + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +extern class cv::Mat image; +extern char home_path [FILENAME_MAX]; +extern char user_prog_path [FILENAME_MAX]; +extern char saved_path [FILENAME_MAX]; +extern char labels_path [FILENAME_MAX]; +extern char labels_fail_path [FILENAME_MAX]; +extern char lighters_path [FILENAME_MAX]; +extern char lighters_fail_path [FILENAME_MAX]; +extern char objects_path [FILENAME_MAX]; +extern char objects_fail_path [FILENAME_MAX]; +extern char coins_path [FILENAME_MAX]; +extern char coins_fail_path [FILENAME_MAX]; +extern char resistors_path [FILENAME_MAX]; +extern char resistors_fail_path [FILENAME_MAX]; +extern char saved_name [FILENAME_MAX]; + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +extern "C" +{ +void save_init (void); +void save_cleanup (void); +void save_reset_fpath(void); +void load_image_file (const char *fpath, const char *fname); +void save_image_file (const char *fpath, const char *save_as); +} + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/save/save.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/user/clui.h b/inc/vision-artificial/user/clui.h new file mode 100644 index 0000000..158c019 --- /dev/null +++ b/inc/vision-artificial/user/clui.h @@ -0,0 +1,59 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_USER_CLUI_H +#define VA_USER_CLUI_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +int user_clui (const char *restrict title, + const char *restrict subtitle); +void user_clui_fname (const char *restrict fpath, + char *restrict fname); +void user_clui_show_log (const char *restrict title, + const char *restrict subtitle); +void user_clui_show_ocr (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/user/clui.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/user/iface.h b/inc/vision-artificial/user/iface.h new file mode 100644 index 0000000..887493f --- /dev/null +++ b/inc/vision-artificial/user/iface.h @@ -0,0 +1,182 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_USER_IFACE_H +#define VA_USER_IFACE_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include <stddef.h> +#include <stdint.h> + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +#define LOG_LEN (0xFFFFF) +#define LOG_LINE_LEN (80) + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Player_Iface_Mode { + USER_IFACE_FOO, + USER_IFACE_CLUI, + USER_IFACE_TUI +}; + +enum Player_Iface_Action { + USER_IFACE_ACT_FOO = 0x000000u, + + USER_IFACE_ACT_ALX = 0x000010u, + USER_IFACE_ACT_LOCAL_MAX, + USER_IFACE_ACT_SKELETON, + USER_IFACE_ACT_LINES_HORIZONTAL, + USER_IFACE_ACT_LINES_VERTICAL, + USER_IFACE_ACT_MEAN_HORIZONTAL, + USER_IFACE_ACT_MEAN_VERTICAL, + USER_IFACE_ACT_MEDIAN_HORIZONTAL, + USER_IFACE_ACT_MEDIAN_VERTICAL, + + USER_IFACE_ACT_CV = 0x000100u, + USER_IFACE_ACT_PIXEL_GET, + USER_IFACE_ACT_PIXEL_SET, + USER_IFACE_ACT_SET_ROI, + USER_IFACE_ACT_SET_ROI_2RECT, + USER_IFACE_ACT_AND_2REF, + USER_IFACE_ACT_NOT, + USER_IFACE_ACT_OR_2REF, + USER_IFACE_ACT_COMPONENT, + USER_IFACE_ACT_DILATE, + USER_IFACE_ACT_ERODE, + USER_IFACE_ACT_DILATE_ERODE, + USER_IFACE_ACT_ERODE_DILATE, + USER_IFACE_ACT_SMOOTH, + USER_IFACE_ACT_SOBEL, + USER_IFACE_ACT_BORDER, + USER_IFACE_ACT_MIRROR, + USER_IFACE_ACT_ROTATE_ORTO, + USER_IFACE_ACT_ROTATE, + USER_IFACE_ACT_ROTATE_2RECT, + USER_IFACE_ACT_ADAPTIVE_THRESHOLD, + USER_IFACE_ACT_CVT_COLOR, + USER_IFACE_ACT_DISTANCE_TRANSFORM, + USER_IFACE_ACT_THRESHOLD, + USER_IFACE_ACT_HISTOGRAM, + USER_IFACE_ACT_HISTOGRAM_C3, + USER_IFACE_ACT_CONTOURS, + USER_IFACE_ACT_CONTOURS_SIZE, + USER_IFACE_ACT_BOUNDING_RECT, + USER_IFACE_ACT_FIT_ELLIPSE, + USER_IFACE_ACT_MIN_AREA_RECT, + USER_IFACE_ACT_HOUGH_CIRCLES, + + USER_IFACE_ACT_ORB = 0x000200u, + USER_IFACE_ACT_ALIGN, + + USER_IFACE_ACT_CALIB3D = 0x000400u, + USER_IFACE_ACT_CALIBRATE, + USER_IFACE_ACT_UNDISTORT, + + USER_IFACE_ACT_ZB = 0x000800u, + USER_IFACE_ACT_DECODE, + + USER_IFACE_ACT_OCR = 0x001000u, + USER_IFACE_ACT_READ, + + USER_IFACE_ACT_IMGI = 0x002000u, + USER_IFACE_ACT_APPLY, + USER_IFACE_ACT_DISCARD, + USER_IFACE_ACT_SAVE_MEM, + USER_IFACE_ACT_LOAD_MEM, + USER_IFACE_ACT_SAVE_REF, + + USER_IFACE_ACT_SAVE = 0x004000u, + USER_IFACE_ACT_SAVE_FILE, + USER_IFACE_ACT_SAVE_UPDT, + + USER_IFACE_ACT_PROC = 0x008000u, + USER_IFACE_ACT_PROC_LABEL_SERIES, + USER_IFACE_ACT_PROC_LABEL_CALIB, + USER_IFACE_ACT_PROC_OBJECTS_SERIES, + USER_IFACE_ACT_PROC_OBJECTS_CALIB, + USER_IFACE_ACT_PROC_COINS_SERIES, + USER_IFACE_ACT_PROC_COINS_CALIB, + USER_IFACE_ACT_PROC_RESISTOR_SERIES, + USER_IFACE_ACT_PROC_RESISTOR_CALIB, + USER_IFACE_ACT_PROC_LIGHTERS_SERIES, + USER_IFACE_ACT_PROC_LIGHTERS_CALIB, + + USER_IFACE_ACT_USRI = 0x010000u, + USER_IFACE_ACT_SHOW_OCR, + USER_IFACE_ACT_QUIT +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ +struct User_Iface_Log { + ptrdiff_t len; + ptrdiff_t pos; + char line[LOG_LEN][LOG_LINE_LEN]; + uint8_t lvl[LOG_LEN]; + uint8_t visible; +}; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +extern int user_iface_mode; +extern struct User_Iface_Log user_iface_log; + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void user_iface_init (void); +void user_iface_cleanup (void); +void user_iface (void); +void user_iface_show_log (const char *restrict title, + const char *restrict subtitle); +void user_iface_fname (const char *restrict filepath, + char *restrict filename); +double user_iface_getdbl (double m, double def, double M, + const char *restrict title, + const char *restrict help); +int user_iface_getint (double m, int64_t def, double M, + const char *restrict title, + const char *restrict help); +void user_iface_log_write (ptrdiff_t lvl, const char *restrict msg); +const char *user_iface_log_read (void); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/user/iface.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/user/iface.hpp b/inc/vision-artificial/user/iface.hpp new file mode 100644 index 0000000..a22c96c --- /dev/null +++ b/inc/vision-artificial/user/iface.hpp @@ -0,0 +1,187 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_USER_IFACE_HPP +#define VA_USER_IFACE_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include <cstddef> +#include <cstdint> + +#include "libalx/base/stddef/restrict.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +#define LOG_LEN (0xFFFFF) +#define LOG_LINE_LEN (80) + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Player_Iface_Mode { + USER_IFACE_FOO, + USER_IFACE_CLUI, + USER_IFACE_TUI +}; + +enum Player_Iface_Action { + USER_IFACE_ACT_FOO = 0x000000u, + + USER_IFACE_ACT_ALX = 0x000010u, + USER_IFACE_ACT_LOCAL_MAX, + USER_IFACE_ACT_SKELETON, + USER_IFACE_ACT_LINES_HORIZONTAL, + USER_IFACE_ACT_LINES_VERTICAL, + USER_IFACE_ACT_MEAN_HORIZONTAL, + USER_IFACE_ACT_MEAN_VERTICAL, + USER_IFACE_ACT_MEDIAN_HORIZONTAL, + USER_IFACE_ACT_MEDIAN_VERTICAL, + + USER_IFACE_ACT_CV = 0x000100u, + USER_IFACE_ACT_PIXEL_GET, + USER_IFACE_ACT_PIXEL_SET, + USER_IFACE_ACT_SET_ROI, + USER_IFACE_ACT_SET_ROI_2RECT, + USER_IFACE_ACT_AND_2REF, + USER_IFACE_ACT_NOT, + USER_IFACE_ACT_OR_2REF, + USER_IFACE_ACT_COMPONENT, + USER_IFACE_ACT_DILATE, + USER_IFACE_ACT_ERODE, + USER_IFACE_ACT_DILATE_ERODE, + USER_IFACE_ACT_ERODE_DILATE, + USER_IFACE_ACT_SMOOTH, + USER_IFACE_ACT_SOBEL, + USER_IFACE_ACT_BORDER, + USER_IFACE_ACT_MIRROR, + USER_IFACE_ACT_ROTATE_ORTO, + USER_IFACE_ACT_ROTATE, + USER_IFACE_ACT_ROTATE_2RECT, + USER_IFACE_ACT_ADAPTIVE_THRESHOLD, + USER_IFACE_ACT_CVT_COLOR, + USER_IFACE_ACT_DISTANCE_TRANSFORM, + USER_IFACE_ACT_THRESHOLD, + USER_IFACE_ACT_HISTOGRAM, + USER_IFACE_ACT_HISTOGRAM_C3, + USER_IFACE_ACT_CONTOURS, + USER_IFACE_ACT_CONTOURS_SIZE, + USER_IFACE_ACT_BOUNDING_RECT, + USER_IFACE_ACT_FIT_ELLIPSE, + USER_IFACE_ACT_MIN_AREA_RECT, + USER_IFACE_ACT_HOUGH_CIRCLES, + + USER_IFACE_ACT_ORB = 0x000200u, + USER_IFACE_ACT_ALIGN, + + USER_IFACE_ACT_CALIB3D = 0x000400u, + USER_IFACE_ACT_CALIBRATE, + USER_IFACE_ACT_UNDISTORT, + + USER_IFACE_ACT_ZB = 0x000800u, + USER_IFACE_ACT_DECODE, + + USER_IFACE_ACT_OCR = 0x001000u, + USER_IFACE_ACT_READ, + + USER_IFACE_ACT_IMGI = 0x002000u, + USER_IFACE_ACT_APPLY, + USER_IFACE_ACT_DISCARD, + USER_IFACE_ACT_SAVE_MEM, + USER_IFACE_ACT_LOAD_MEM, + USER_IFACE_ACT_SAVE_REF, + + USER_IFACE_ACT_SAVE = 0x004000u, + USER_IFACE_ACT_SAVE_FILE, + USER_IFACE_ACT_SAVE_UPDT, + + USER_IFACE_ACT_PROC = 0x008000u, + USER_IFACE_ACT_PROC_LABEL_SERIES, + USER_IFACE_ACT_PROC_LABEL_CALIB, + USER_IFACE_ACT_PROC_OBJECTS_SERIES, + USER_IFACE_ACT_PROC_OBJECTS_CALIB, + USER_IFACE_ACT_PROC_COINS_SERIES, + USER_IFACE_ACT_PROC_COINS_CALIB, + USER_IFACE_ACT_PROC_RESISTOR_SERIES, + USER_IFACE_ACT_PROC_RESISTOR_CALIB, + USER_IFACE_ACT_PROC_LIGHTERS_SERIES, + USER_IFACE_ACT_PROC_LIGHTERS_CALIB, + + USER_IFACE_ACT_USRI = 0x010000u, + USER_IFACE_ACT_SHOW_OCR, + USER_IFACE_ACT_QUIT +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ +struct User_Iface_Log { + ptrdiff_t len; + ptrdiff_t pos; + char line[LOG_LEN][LOG_LINE_LEN]; + uint8_t lvl[LOG_LEN]; + uint8_t visible; +}; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +extern int user_iface_mode; +extern struct User_Iface_Log user_iface_log; + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +extern "C" +{ +void user_iface_init (void); +void user_iface_cleanup (void); +void user_iface (void); +void user_iface_show_log (const char *restrict title, + const char *restrict subtitle); +void user_iface_fname (const char *restrict filepath, + char *restrict filename); +double user_iface_getdbl (double m, double def, double M, + const char *restrict title, + const char *restrict help); +int user_iface_getint (double m, int64_t def, double M, + const char *restrict title, + const char *restrict help); +void user_iface_log_write (ptrdiff_t lvl, const char *restrict msg); +const char *user_iface_log_read (void); +} + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/user/iface.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/user/tui.h b/inc/vision-artificial/user/tui.h new file mode 100644 index 0000000..1be58c9 --- /dev/null +++ b/inc/vision-artificial/user/tui.h @@ -0,0 +1,67 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_USER_TUI_H +#define VA_USER_TUI_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void user_tui_init (void); +void user_tui_cleanup (void); +int user_tui (const char *restrict title, + const char *restrict subtitle); +void user_tui_show_log (const char *restrict title, + const char *restrict subtitle); +void user_tui_fname (const char *restrict fpath, + char *restrict fname); +double user_tui_getdbl (double m, double def, double M, + const char *restrict title, + const char *restrict help); +int user_tui_getint (int m, int def, int M, + const char *restrict title, + const char *restrict help); +void user_tui_show_ocr (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/user/tui.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/libalx b/libalx index 3e83ecf..d95dd76 160000 --- a/libalx +++ b/libalx @@ -1 +1 @@ -Subproject commit 3e83ecf11efc99fbba7e6b4a09c071ec20e87ddd +Subproject commit d95dd760ac01bd2000f0a38d0a1cc9fa2c1125f5 diff --git a/modules/Makefile b/modules/Makefile deleted file mode 100644 index 61b5871..0000000 --- a/modules/Makefile +++ /dev/null @@ -1,66 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -ABOUT_DIR = $(MODULES_DIR)/about/ -CTRL_DIR = $(MODULES_DIR)/ctrl/ -IMG_DIR = $(MODULES_DIR)/image/ -MENU_DIR = $(MODULES_DIR)/menu/ -PROC_DIR = $(MODULES_DIR)/proc/ -SAVE_DIR = $(MODULES_DIR)/save/ -USR_DIR = $(MODULES_DIR)/user/ - -TMP_DIR = $(MODULES_DIR)/tmp/ - -export ABOUT_DIR -export CTRL_DIR -export IMG_DIR -export MENU_DIR -export PROC_DIR -export SAVE_DIR -export USR_DIR - -# dependencies - - -# target: dependencies -# action - -PHONY := all -all: - @echo ' MAKE modules: about' - $(Q)$(MAKE) -C $(ABOUT_DIR) - @echo ' MAKE modules: ctrl' - $(Q)$(MAKE) -C $(CTRL_DIR) - @echo ' MAKE modules: image' - $(Q)$(MAKE) -C $(IMG_DIR) - @echo ' MAKE modules: menu' - $(Q)$(MAKE) -C $(MENU_DIR) - @echo ' MAKE modules: proc' - $(Q)$(MAKE) -C $(PROC_DIR) - @echo ' MAKE modules: save' - $(Q)$(MAKE) -C $(SAVE_DIR) - @echo ' MAKE modules: usr' - $(Q)$(MAKE) -C $(USR_DIR) - @echo ' MAKE modules.o' - $(Q)$(MAKE) -C $(TMP_DIR) - - -PHONY += clean -clean: - @echo " RM *.o *.s" - $(Q)find . -type f -name '*.o' -exec rm '{}' '+' - $(Q)find . -type f -name '*.s' -exec rm '{}' '+' - -################################################################################ -# Declare the contents of the .PHONY variable as phony. -.PHONY: $(PHONY) - - - - -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/modules/about/Makefile b/modules/about/Makefile deleted file mode 100644 index c1c25ef..0000000 --- a/modules/about/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -TMP_DIR = $(ABOUT_DIR)/tmp/ - -# target: dependencies -# action - -all: - $(Q)cd $(TMP_DIR) && $(MAKE) && cd .. - -clean: - $(Q)cd $(TMP_DIR) && $(MAKE) clean && cd .. - -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/modules/about/inc/about.h b/modules/about/inc/about.h deleted file mode 100644 index 381f13d..0000000 --- a/modules/about/inc/about.h +++ /dev/null @@ -1,64 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_ABOUT_H - # define VA_ABOUT_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* FILENAME_MAX */ - #include <stdio.h> - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define PROG_NAME "vision-artificial" - # define PROG_YEAR "2018" - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Share_File { - SHARE_COPYRIGHT, - SHARE_DISCLAIMER, - SHARE_HELP, - SHARE_LICENSE, - SHARE_USAGE - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern char share_path [FILENAME_MAX]; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void about_init (void); -void snprint_share_file (char *dest, int destsize, int share_file); -void print_share_file (int share_file); -void print_version (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* about.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/about/inc/about.hpp b/modules/about/inc/about.hpp deleted file mode 100644 index 31d5977..0000000 --- a/modules/about/inc/about.hpp +++ /dev/null @@ -1,76 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_ABOUT_HPP - # define VA_ABOUT_HPP - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* FILENAME_MAX */ - #include <cstdio> - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define PROG_NAME "vision-artificial" - # define PROG_YEAR "2018" - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Share_File { - SHARE_COPYRIGHT, - SHARE_DISCLAIMER, - SHARE_HELP, - SHARE_LICENSE, - SHARE_USAGE - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern char share_path [FILENAME_MAX]; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void about_init (void); -void snprint_share_file (char *dest, int destsize, int share_file); -void print_share_file (int share_file); -void print_version (void); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* about.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/about/src/about.c b/modules/about/src/about.c deleted file mode 100644 index e36828b..0000000 --- a/modules/about/src/about.c +++ /dev/null @@ -1,126 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* printf() */ - #include <stdio.h> - #include <stdlib.h> -/* libalx --------------------------------------------------------------------*/ - /* alx_snprint_file() */ - #include "libalx/io/alx_file.h" -/* Module --------------------------------------------------------------------*/ - #include "about.h" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define BUFF_SIZE_TEXT (1048576) - - # define BEGINNING "\n┌──────────────────────────────────────────────────────────────────────────────┐\n" - # define ENDING "└──────────────────────────────────────────────────────────────────────────────┘\n\n" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -char share_path [FILENAME_MAX]; - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void about_init (void) -{ - if (snprintf(share_path, FILENAME_MAX, "%s/%s/", - INSTALL_SHARE_DIR, - SHARE_DIR) >= FILENAME_MAX) { - goto err_path; - } - - return; - - -err_path: - printf("Path is too large and has been truncated\n"); - exit(EXIT_FAILURE); -} - -void snprint_share_file (char *dest, int destsize, int share_file) -{ - char file_name [FILENAME_MAX]; - - switch (share_file) { - case SHARE_COPYRIGHT: - if (snprintf(file_name, FILENAME_MAX, "%s/%s", - share_path, - "COPYRIGHT.txt") >= FILENAME_MAX) { - goto err_path; - } - break; - case SHARE_DISCLAIMER: - if (snprintf(file_name, FILENAME_MAX, "%s/%s", - share_path, - "DISCLAIMER.txt") >= FILENAME_MAX) { - goto err_path; - } - break; - case SHARE_HELP: - if (snprintf(file_name, FILENAME_MAX, "%s/%s", - share_path, - "HELP.txt") >= FILENAME_MAX) { - goto err_path; - } - break; - case SHARE_LICENSE: - if (snprintf(file_name, FILENAME_MAX, "%s/%s", - share_path, - "LICENSE.txt") >= FILENAME_MAX) { - goto err_path; - } - break; - case SHARE_USAGE: - if (snprintf(file_name, FILENAME_MAX, "%s/%s", - share_path, - "USAGE.txt") >= FILENAME_MAX) { - goto err_path; - } - break; - } - - alx_snprint_file(dest, destsize, file_name); - - return; - - -err_path: - printf("Path is too large and has been truncated\n"); - printf("File could not be shown!\n"); -} - -void print_share_file (int share_file) -{ - char str [BUFF_SIZE_TEXT]; - - snprint_share_file(str, BUFF_SIZE_TEXT, share_file); - - printf(BEGINNING); - printf("%s", str); - printf(ENDING); -} - -void print_version (void) -{ - printf("" PROG_NAME " " PROG_VERSION "\n\n"); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/about/tmp/Makefile b/modules/about/tmp/Makefile deleted file mode 100644 index 21afd1b..0000000 --- a/modules/about/tmp/Makefile +++ /dev/null @@ -1,49 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -LIBALX_INC_DIR = $(LIBALX_DIR)/inc/ - -INC_DIR = $(ABOUT_DIR)/inc/ -SRC_DIR = $(ABOUT_DIR)/src/ - -# dependencies - -_ALL = about.o -ALL = $(_ALL) about_mod.o - -ABOU_INC_LIBALX = libalx/io/alx_file.h -ABOU_INC = about.h -ABOU_DEPS = $(SRC_DIR)/about.c \ - $(patsubst %,$(LIBALX_INC_DIR)/%,$(ABOU_INC_LIBALX)) \ - $(patsubst %,$(INC_DIR)/%,$(ABOU_INC)) -ABOU_INC_DIRS = -I $(INC_DIR) \ - -I $(LIBALX_INC_DIR) - -# target: dependencies -# action - -all: $(ALL) - - -about_mod.o: $(_ALL) - @echo " LD $@" - $(Q)$(LD) -r $^ -o $@ - - -about.s: $(ABOU_DEPS) - @echo " CC $@" - $(Q)$(CC) $(CFLAGS) $(ABOU_INC_DIRS) -S $< -o $@ -about.o: about.s - @echo " AS $@" - $(Q)$(AS) $< -o $@ - - -clean: - $(Q)rm -f *.o *.s - -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/modules/ctrl/Makefile b/modules/ctrl/Makefile deleted file mode 100644 index 966cac1..0000000 --- a/modules/ctrl/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -TMP_DIR = $(CTRL_DIR)/tmp/ - -# target: dependencies -# action - -PHONY := all -all: - $(Q)$(MAKE) -C $(TMP_DIR) - - -PHONY += clean -clean: - $(Q)$(MAKE) clean -C $(TMP_DIR) - -################################################################################ -# Declare the contents of the .PHONY variable as phony. -.PHONY: $(PHONY) - - - - -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/modules/ctrl/inc/start.h b/modules/ctrl/inc/start.h deleted file mode 100644 index e8273f1..0000000 --- a/modules/ctrl/inc/start.h +++ /dev/null @@ -1,44 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_START_H - # define VA_START_H - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Start_Mode { - START_FOO = 0, - START_SINGLE, - START_SERIES - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - extern int start_mode; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void start_switch (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* start.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/ctrl/src/start.c b/modules/ctrl/src/start.c deleted file mode 100644 index 8c33c93..0000000 --- a/modules/ctrl/src/start.c +++ /dev/null @@ -1,108 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* errno */ - #include <errno.h> - #include <stddef.h> - /* printf() */ - #include <stdio.h> -/* Project -------------------------------------------------------------------*/ - /* img_iface_load() */ - #include "img_iface.h" - /* proc_iface_series() */ - #include "proc_iface.h" - /* saved_name*/ - #include "save.h" - /* user_iface() */ - #include "user_iface.h" -/* Module --------------------------------------------------------------------*/ - #include "start.h" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -int start_mode; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void start_foo (void); -static void start_single (void); -static void start_series (void); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void start_switch (void) -{ - - switch (start_mode) { - case START_FOO: - start_foo(); - break; - - case START_SINGLE: - start_single(); - break; - - case START_SERIES: - start_series(); - break; - } -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void start_foo (void) -{ - - /* empty */ -} - -static void start_single (void) -{ - - errno = 0; - img_iface_load(NULL, saved_name); - - if (!errno) { - user_iface_init(); - user_iface(); - user_iface_cleanup(); - } else { - printf("errno:%i\n", errno); - } - - img_iface_cleanup(); -} - -static void start_series (void) -{ - int tmp; - - tmp = user_iface_mode; - user_iface_mode = USER_IFACE_CLUI; - - user_iface_init(); - proc_iface_series(); - user_iface_cleanup(); - - user_iface_mode = tmp; -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/ctrl/tmp/Makefile b/modules/ctrl/tmp/Makefile deleted file mode 100644 index 4859f7c..0000000 --- a/modules/ctrl/tmp/Makefile +++ /dev/null @@ -1,70 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -IMG_INC_DIR = $(IMG_DIR)/inc/ -PROC_INC_DIR = $(PROC_DIR)/inc/ -SAVE_INC_DIR = $(SAVE_DIR)/inc/ -USR_INC_DIR = $(USR_DIR)/inc/ - -INC_DIR = $(CTRL_DIR)/inc/ -SRC_DIR = $(CTRL_DIR)/src/ - -# dependencies - -_ALL = start.o -ALL = $(_ALL) ctrl_mod.o - -STRT_INC_IMG = img_iface.h -STRT_INC_PROC = proc_iface.h -STRT_INC_SAVE = save.h -STRT_INC_USR = user_iface.h -STRT_INC = start.h -STRT_DEPS = $(SRC_DIR)/start.c \ - $(patsubst %,$(IMG_INC_DIR)/%,$(STRT_INC_IMG)) \ - $(patsubst %,$(PROC_INC_DIR)/%,$(STRT_INC_PROC)) \ - $(patsubst %,$(SAVE_INC_DIR)/%,$(STRT_INC_SAVE)) \ - $(patsubst %,$(USR_INC_DIR)/%,$(STRT_INC_USR)) \ - $(patsubst %,$(INC_DIR)/%,$(STRT_INC)) -STRT_INC_DIRS = -I $(INC_DIR) \ - -I $(IMG_INC_DIR) \ - -I $(PROC_INC_DIR) \ - -I $(SAVE_INC_DIR) \ - -I $(USR_INC_DIR) - -# target: dependencies -# action - -PHONY := all -all: $(ALL) - - -ctrl_mod.o: $(_ALL) - $(Q)$(LD) -r $^ -o $@ - @echo " LD $@" - - -start.s: $(STRT_DEPS) - $(Q)$(CC) $(CFLAGS) $(STRT_INC_DIRS) -S $< -o $@ - @echo " CC $@" -start.o: start.s - $(Q)$(AS) $< -o $@ - @echo " AS $@" - - -PHONY += clean -clean: - $(Q)rm -f *.o *.s - -################################################################################ -# Declare the contents of the .PHONY variable as phony. -.PHONY: $(PHONY) - - - - -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/modules/image/Makefile b/modules/image/Makefile deleted file mode 100644 index 58a5792..0000000 --- a/modules/image/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -TMP_DIR = $(IMG_DIR)/tmp/ - -# target: dependencies -# action - -all: - $(Q)cd $(TMP_DIR) && $(MAKE) && cd .. - -clean: - $(Q)cd $(TMP_DIR) && $(MAKE) clean && cd .. - -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/modules/image/inc/img_alx.hpp b/modules/image/inc/img_alx.hpp deleted file mode 100644 index 0c2558a..0000000 --- a/modules/image/inc/img_alx.hpp +++ /dev/null @@ -1,53 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_ALX_H - # define VA_IMG_ALX_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - /* openCV */ - #include <opencv2/opencv.hpp> - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_Alx_Action { - IMG_ALX_ACT_FOO = 0x000000u, - - IMG_ALX_ACT_ALX = 0x000010u, - IMG_ALX_ACT_LOCAL_MAX, - IMG_ALX_ACT_SKELETON, - IMG_ALX_ACT_LINES_HORIZONTAL, - IMG_ALX_ACT_LINES_VERTICAL, - IMG_ALX_ACT_MEAN_HORIZONTAL, - IMG_ALX_ACT_MEAN_VERTICAL, - IMG_ALX_ACT_MEDIAN_HORIZONTAL, - IMG_ALX_ACT_MEDIAN_VERTICAL - }; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void img_alx_act (class cv::Mat *imgptr, int action, const void *data); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_alx.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/image/inc/img_calib3d.hpp b/modules/image/inc/img_calib3d.hpp deleted file mode 100644 index a2c9f7c..0000000 --- a/modules/image/inc/img_calib3d.hpp +++ /dev/null @@ -1,47 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_CALIB3D_HPP - # define VA_IMG_CALIB3D_HPP - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - /* openCV */ - #include <opencv2/opencv.hpp> - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_Calib3d_Action { - IMG_CALIB3D_ACT_FOO = 0x000000u, - - IMG_CALIB3D_ACT_CALIB3D = 0x000400u, - IMG_CALIB3D_ACT_CALIBRATE, - IMG_CALIB3D_ACT_UNDISTORT - }; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void img_calib3d_act (class cv::Mat *imgptr, int action, const void *data); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_calib3d.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/image/inc/img_cv.hpp b/modules/image/inc/img_cv.hpp deleted file mode 100644 index 1840ca6..0000000 --- a/modules/image/inc/img_cv.hpp +++ /dev/null @@ -1,72 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_CV_H - # define VA_IMG_CV_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* packages ------------------------------------------------------------------*/ - #include <opencv2/opencv.hpp> - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_Cv_Action { - IMG_CV_ACT_FOO = 0x000000u, - - IMG_CV_ACT_CV = 0x000100u, - IMG_CV_ACT_PIXEL_GET, - IMG_CV_ACT_PIXEL_SET, - IMG_CV_ACT_SET_ROI, - IMG_CV_ACT_AND_2REF, - IMG_CV_ACT_NOT, - IMG_CV_ACT_OR_2REF, - IMG_CV_ACT_COMPONENT, - IMG_CV_ACT_DILATE, - IMG_CV_ACT_ERODE, - IMG_CV_ACT_SMOOTH, - IMG_CV_ACT_SOBEL, - IMG_CV_ACT_BORDER, - IMG_CV_ACT_MIRROR, - IMG_CV_ACT_ROTATE_ORTO, - IMG_CV_ACT_ROTATE, - IMG_CV_ACT_ADAPTIVE_THRESHOLD, - IMG_CV_ACT_CVT_COLOR, - IMG_CV_ACT_DISTANCE_TRANSFORM, - IMG_CV_ACT_THRESHOLD, - IMG_CV_ACT_HISTOGRAM, - IMG_CV_ACT_HISTOGRAM_C3, - IMG_CV_ACT_CONTOURS, - IMG_CV_ACT_CONTOURS_SIZE, - IMG_CV_ACT_BOUNDING_RECT, - IMG_CV_ACT_FIT_ELLIPSE, - IMG_CV_ACT_MIN_AREA_RECT, - IMG_CV_ACT_HOUGH_CIRCLES - }; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void img_cv_act (class cv::Mat *imgptr, int action, const void *data); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_cv.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/image/inc/img_iface.h b/modules/image/inc/img_iface.h deleted file mode 100644 index 1b755aa..0000000 --- a/modules/image/inc/img_iface.h +++ /dev/null @@ -1,185 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_IFACE_H - # define VA_IMG_IFACE_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <stddef.h> - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ -/* Constants -----------------------------------------------------------------*/ - # define CONTOURS_MAX (65536) - # define OCR_TEXT_MAX (1048576) - # define ZB_CODES_MAX (10) - # define ZBAR_LEN_MAX (1048576) - - # define IMG_IFACE_THR_OTSU (-1) - -/* Functions -----------------------------------------------------------------*/ - # define img_iface_act_nodata(x) img_iface_act(x, NULL) - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_Iface_Action { - IMG_IFACE_ACT_FOO = 0x000000u, - - IMG_IFACE_ACT_ALX = 0x000010u, - IMG_IFACE_ACT_LOCAL_MAX, - IMG_IFACE_ACT_SKELETON, - IMG_IFACE_ACT_LINES_HORIZONTAL, - IMG_IFACE_ACT_LINES_VERTICAL, - IMG_IFACE_ACT_MEAN_HORIZONTAL, - IMG_IFACE_ACT_MEAN_VERTICAL, - IMG_IFACE_ACT_MEDIAN_HORIZONTAL, - IMG_IFACE_ACT_MEDIAN_VERTICAL, - - IMG_IFACE_ACT_CV = 0x000100u, - IMG_IFACE_ACT_PIXEL_GET, - IMG_IFACE_ACT_PIXEL_SET, - IMG_IFACE_ACT_SET_ROI, - IMG_IFACE_ACT_SET_ROI_2RECT, - IMG_IFACE_ACT_AND_2REF, - IMG_IFACE_ACT_NOT, - IMG_IFACE_ACT_OR_2REF, - IMG_IFACE_ACT_COMPONENT, - IMG_IFACE_ACT_DILATE, - IMG_IFACE_ACT_ERODE, - IMG_IFACE_ACT_DILATE_ERODE, - IMG_IFACE_ACT_ERODE_DILATE, - IMG_IFACE_ACT_SMOOTH, - IMG_IFACE_ACT_SOBEL, - IMG_IFACE_ACT_BORDER, - IMG_IFACE_ACT_MIRROR, - IMG_IFACE_ACT_ROTATE_ORTO, - IMG_IFACE_ACT_ROTATE, - IMG_IFACE_ACT_ROTATE_2RECT, - IMG_IFACE_ACT_ADAPTIVE_THRESHOLD, - IMG_IFACE_ACT_CVT_COLOR, - IMG_IFACE_ACT_DISTANCE_TRANSFORM, - IMG_IFACE_ACT_THRESHOLD, - IMG_IFACE_ACT_HISTOGRAM, - IMG_IFACE_ACT_HISTOGRAM_C3, - IMG_IFACE_ACT_CONTOURS, - IMG_IFACE_ACT_CONTOURS_SIZE, - IMG_IFACE_ACT_BOUNDING_RECT, - IMG_IFACE_ACT_FIT_ELLIPSE, - IMG_IFACE_ACT_MIN_AREA_RECT, - IMG_IFACE_ACT_HOUGH_CIRCLES, - - IMG_IFACE_ACT_ORB = 0x000200u, - IMG_IFACE_ACT_ALIGN, - - IMG_IFACE_ACT_CALIB3D = 0x000400u, - IMG_IFACE_ACT_CALIBRATE, - IMG_IFACE_ACT_UNDISTORT, - - IMG_IFACE_ACT_ZB = 0x000800u, - IMG_IFACE_ACT_DECODE, - - IMG_IFACE_ACT_OCR = 0x001000u, - IMG_IFACE_ACT_READ, - - IMG_IFACE_ACT_IMGI = 0x002000u, - IMG_IFACE_ACT_APPLY, - IMG_IFACE_ACT_DISCARD, - IMG_IFACE_ACT_SAVE_MEM, - IMG_IFACE_ACT_LOAD_MEM, - IMG_IFACE_ACT_SAVE_REF, - - IMG_IFACE_ACT_SAVE = 0x004000u, - IMG_IFACE_ACT_SAVE_FILE, - IMG_IFACE_ACT_SAVE_UPDT - }; - - enum Img_Iface_Cmp_BGR { - IMG_IFACE_CMP_BLUE = 0, - IMG_IFACE_CMP_GREEN, - IMG_IFACE_CMP_RED - }; - - enum Img_Iface_Cmp_HSV { - IMG_IFACE_CMP_HUE = 0, - IMG_IFACE_CMP_SATURATION, - IMG_IFACE_CMP_VALUE - }; - - enum ImgI_Smooth { - IMGI_SMOOTH_MEAN = 0, - IMGI_SMOOTH_GAUSS, - IMGI_SMOOTH_MEDIAN - }; - - enum Img_Iface_OCR_Lang { - IMG_IFACE_OCR_LANG_ENG = 0, - IMG_IFACE_OCR_LANG_SPA, - IMG_IFACE_OCR_LANG_CAT, - IMG_IFACE_OCR_LANG_DIGITS, - IMG_IFACE_OCR_LANG_DIGITS_COMMA - }; - - enum Img_Iface_OCR_Conf { - IMG_IFACE_OCR_CONF_NONE = 0, - IMG_IFACE_OCR_CONF_PRICE - }; - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ - struct Img_Iface_Data_Read { - int lang; - int conf; - struct { - void *data; - int width; - int height; - int B_per_pix; - int B_per_line; - } img; - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern char img_ocr_text [OCR_TEXT_MAX]; -extern struct Img_Iface_ZB_Codes zb_codes; - - -/****************************************************************************** -******* functions ************************************************************ -******************************************************************************/ -void img_iface_cleanup_main (void); -void img_iface_load (const char *fpath, const char *fname); -void img_iface_cleanup (void); -void img_iface_act (int action, const void *data); -void img_iface_show_img (void); -void img_iface_show_hist_c1 (void); -void img_iface_show_hist_c3 (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_iface.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/image/inc/img_iface.hpp b/modules/image/inc/img_iface.hpp deleted file mode 100644 index fb80451..0000000 --- a/modules/image/inc/img_iface.hpp +++ /dev/null @@ -1,344 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_IFACE_HPP - # define VA_IMG_IFACE_HPP - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <cstddef> - -/* Standard C++ --------------------------------------------------------------*/ - /* class std::vector */ - #include <vector> - -/* Packages ------------------------------------------------------------------*/ - /* opencv */ - #include <opencv2/opencv.hpp> - /* zbar */ - #include <zbar.h> - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define CONTOURS_MAX (65536) - # define OCR_TEXT_MAX (1048576) - # define ZB_CODES_MAX (10) - # define ZBAR_LEN_MAX (1048576) - - # define IMG_IFACE_THR_OTSU (-1) - -/* Functions -----------------------------------------------------------------*/ - # define img_iface_act_nodata(x) \ - do { \ - img_iface_act(x, NULL); \ - } while (0) - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_Iface_Action { - IMG_IFACE_ACT_FOO = 0x000000u, - - IMG_IFACE_ACT_ALX = 0x000010u, - IMG_IFACE_ACT_LOCAL_MAX, - IMG_IFACE_ACT_SKELETON, - IMG_IFACE_ACT_LINES_HORIZONTAL, - IMG_IFACE_ACT_LINES_VERTICAL, - IMG_IFACE_ACT_MEAN_HORIZONTAL, - IMG_IFACE_ACT_MEAN_VERTICAL, - IMG_IFACE_ACT_MEDIAN_HORIZONTAL, - IMG_IFACE_ACT_MEDIAN_VERTICAL, - - IMG_IFACE_ACT_CV = 0x000100u, - IMG_IFACE_ACT_PIXEL_GET, - IMG_IFACE_ACT_PIXEL_SET, - IMG_IFACE_ACT_SET_ROI, - IMG_IFACE_ACT_SET_ROI_2RECT, - IMG_IFACE_ACT_AND_2REF, - IMG_IFACE_ACT_NOT, - IMG_IFACE_ACT_OR_2REF, - IMG_IFACE_ACT_COMPONENT, - IMG_IFACE_ACT_DILATE, - IMG_IFACE_ACT_ERODE, - IMG_IFACE_ACT_DILATE_ERODE, - IMG_IFACE_ACT_ERODE_DILATE, - IMG_IFACE_ACT_SMOOTH, - IMG_IFACE_ACT_SOBEL, - IMG_IFACE_ACT_BORDER, - IMG_IFACE_ACT_MIRROR, - IMG_IFACE_ACT_ROTATE_ORTO, - IMG_IFACE_ACT_ROTATE, - IMG_IFACE_ACT_ROTATE_2RECT, - IMG_IFACE_ACT_ADAPTIVE_THRESHOLD, - IMG_IFACE_ACT_CVT_COLOR, - IMG_IFACE_ACT_DISTANCE_TRANSFORM, - IMG_IFACE_ACT_THRESHOLD, - IMG_IFACE_ACT_HISTOGRAM, - IMG_IFACE_ACT_HISTOGRAM_C3, - IMG_IFACE_ACT_CONTOURS, - IMG_IFACE_ACT_CONTOURS_SIZE, - IMG_IFACE_ACT_BOUNDING_RECT, - IMG_IFACE_ACT_FIT_ELLIPSE, - IMG_IFACE_ACT_MIN_AREA_RECT, - IMG_IFACE_ACT_HOUGH_CIRCLES, - - IMG_IFACE_ACT_ORB = 0x000200u, - IMG_IFACE_ACT_ALIGN, - - IMG_IFACE_ACT_CALIB3D = 0x000400u, - IMG_IFACE_ACT_CALIBRATE, - IMG_IFACE_ACT_UNDISTORT, - - IMG_IFACE_ACT_ZB = 0x000800u, - IMG_IFACE_ACT_DECODE, - - IMG_IFACE_ACT_OCR = 0x001000u, - IMG_IFACE_ACT_READ, - - IMG_IFACE_ACT_IMGI = 0x002000u, - IMG_IFACE_ACT_APPLY, - IMG_IFACE_ACT_DISCARD, - IMG_IFACE_ACT_SAVE_MEM, - IMG_IFACE_ACT_LOAD_MEM, - IMG_IFACE_ACT_SAVE_REF, - - IMG_IFACE_ACT_SAVE = 0x004000u, - IMG_IFACE_ACT_SAVE_FILE, - IMG_IFACE_ACT_SAVE_UPDT - }; - - enum Img_Iface_Cmp { - IMG_IFACE_CMP_BLUE = 0, - IMG_IFACE_CMP_GREEN, - IMG_IFACE_CMP_RED - }; - - enum Img_Iface_Cmp_HSV { - IMG_IFACE_CMP_HUE = 0, - IMG_IFACE_CMP_SATURATION, - IMG_IFACE_CMP_VALUE - }; - - enum ImgI_Smooth { - IMGI_SMOOTH_MEAN = 1, - IMGI_SMOOTH_GAUSS, - IMGI_SMOOTH_MEDIAN - }; - - enum Img_Iface_OCR_Lang { - IMG_IFACE_OCR_LANG_ENG = 0, - IMG_IFACE_OCR_LANG_SPA, - IMG_IFACE_OCR_LANG_CAT, - IMG_IFACE_OCR_LANG_DIGITS, - IMG_IFACE_OCR_LANG_DIGITS_COMMA - }; - - enum Img_Iface_OCR_Conf { - IMG_IFACE_OCR_CONF_NONE = 0, - IMG_IFACE_OCR_CONF_PRICE - }; - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ -/* img_cv --------------------------------------------------------------------*/ - struct Img_Iface_Data_Pixel_Get { - unsigned char *val; - int x; - int y; - }; - - struct Img_Iface_Data_Pixel_Set { - unsigned char val; - int x; - int y; - }; - - struct Img_Iface_Data_SetROI { - class cv::Rect_ <int> rect; - }; - - struct Img_Iface_Data_Component { - int cmp; - }; - - struct Img_Iface_Data_Dilate_Erode { - int i; - }; - - struct Img_Iface_Data_Smooth { - int method; - int ksize; - }; - - struct Img_Iface_Data_Sobel { - int dx; - int dy; - int ksize; - }; - - struct Img_Iface_Data_Border { - int size; - }; - - struct Img_Iface_Data_Mirror { - int axis; - }; - - struct Img_Iface_Data_Rotate_Orto { - int n; - }; - - struct Img_Iface_Data_Rotate { - class cv::Point_ <float> center; - double angle; - }; - - struct Img_Iface_Data_Adaptive_Thr { - int method; - int thr_typ; - int ksize; - }; - - struct Img_Iface_Data_Cvt_Color { - int method; - }; - - struct Img_Iface_Data_Threshold { - int thr_typ; - int thr_val; - }; - - struct Img_Iface_Data_Histogram { - class cv::Mat *hist_c0; - class cv::Mat *hist_c1; - class cv::Mat *hist_c2; - class cv::Mat *hist_img; - }; - - struct Img_Iface_Data_Contours { - class std::vector <class std::vector <class cv::Point_ <int>>> *contours; - class cv::Mat *hierarchy; - }; - - struct Img_Iface_Data_Contours_Size { - const class std::vector <class std::vector <class cv::Point_ <int>>> *contours; - double *area; - double *perimeter; - }; - - struct Img_Iface_Data_Bounding_Rect { - const class std::vector <class cv::Point_ <int>> *contour; - class cv::Rect_ <int> *rect; - bool show; - }; - - struct Img_Iface_Data_MinARect { - const class std::vector <class cv::Point_ <int>> *contour; - class cv::RotatedRect *rect; - bool show; - }; - - struct Img_Iface_Data_Hough_Circles { - class std::vector <class cv::Vec <float, 3>> *circles; - double dist_min; - double param_1; - double param_2; - int radius_min; - int radius_max; - }; - -/* img_calib3d ---------------------------------------------------------------*/ - struct Img_Iface_Data_Calibrate { - class cv::Mat *intrinsic_mat; - class cv::Mat *dist_coefs; - class std::vector <class cv::Mat> *rvecs; - class std::vector <class cv::Mat> *tvecs; - }; - - struct Img_Iface_Data_Undistort { - const class cv::Mat *intrinsic_mat; - const class cv::Mat *dist_coefs; - }; - -/* img_zbar -------------------------------------------------------------------*/ - struct Img_Iface_Data_Decode { - enum zbar::zbar_symbol_type_e code_type; - }; - - struct Img_Iface_ZB_Codes { - int n; - struct { - enum zbar::zbar_symbol_type_e type; - char sym_name [80]; - char data [ZBAR_LEN_MAX]; - } arr [ZB_CODES_MAX]; - }; - -/* img_ocr -------------------------------------------------------------------*/ - struct Img_Iface_Data_Read { - int lang; - int conf; - struct { - void *data; - int width; - int height; - int B_per_pix; - int B_per_line; - } img; - }; - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern char img_ocr_text [OCR_TEXT_MAX]; -extern struct Img_Iface_ZB_Codes zb_codes; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void img_iface_cleanup_main (void); -void img_iface_load (const char *fpath, const char *fname); -void img_iface_cleanup (void); -void img_iface_act (int action, const void *data); -void img_iface_show_img (void); -void img_iface_show_hist_c1 (void); -void img_iface_show_hist_c3 (void); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_iface.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/image/inc/img_ocr.h b/modules/image/inc/img_ocr.h deleted file mode 100644 index febe2dd..0000000 --- a/modules/image/inc/img_ocr.h +++ /dev/null @@ -1,39 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_OCR_H - # define VA_IMG_OCR_H - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_OCR_Action { - IMG_OCR_ACT_FOO = 0x000000u, - - IMG_OCR_ACT_OCR = 0x001000u, - IMG_OCR_ACT_READ - }; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void img_ocr_act (int action, const void *data); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_ocr.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/image/inc/img_ocr.hpp b/modules/image/inc/img_ocr.hpp deleted file mode 100644 index 6791a36..0000000 --- a/modules/image/inc/img_ocr.hpp +++ /dev/null @@ -1,51 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_OCR_HPP - # define VA_IMG_OCR_HPP - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_OCR_Action { - IMG_OCR_ACT_FOO = 0x000000u, - - IMG_OCR_ACT_OCR = 0x001000u, - IMG_OCR_ACT_READ - }; - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void img_ocr_act (int action, const void *data); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_ocr.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/image/inc/img_orb.hpp b/modules/image/inc/img_orb.hpp deleted file mode 100644 index 9f6a1c3..0000000 --- a/modules/image/inc/img_orb.hpp +++ /dev/null @@ -1,47 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_ORB_HPP - # define VA_IMG_ORB_HPP - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - /* openCV */ - #include <opencv2/opencv.hpp> - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_ORB_Action { - IMG_ORB_ACT_FOO = 0x000000u, - - IMG_ORB_ACT_ORB = 0x000200u, - IMG_ORB_ACT_ALIGN - }; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void img_orb_act (const class cv::Mat *img_ref, - class cv::Mat *imgptr, int action); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_orb.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/image/inc/img_zbar.hpp b/modules/image/inc/img_zbar.hpp deleted file mode 100644 index b9a5143..0000000 --- a/modules/image/inc/img_zbar.hpp +++ /dev/null @@ -1,47 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_ZBAR_H - # define VA_IMG_ZBAR_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Packages ------------------------------------------------------------------*/ - /* openCV */ - #include <opencv2/opencv.hpp> - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_ZB_Action { - IMG_ZB_ACT_FOO = 0x000000u, - - IMG_ZB_ACT_ZB = 0x000800u, - IMG_ZB_ACT_DECODE - }; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void img_zb_act (class cv::Mat *imgptr, int action, const void *data); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_zbar.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/image/src/img_alx.cpp b/modules/image/src/img_alx.cpp deleted file mode 100644 index e832b5d..0000000 --- a/modules/image/src/img_alx.cpp +++ /dev/null @@ -1,370 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: (GPL-2.0-only OR LGPL-3.0-only) * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <cstdbool> - #include <cstdlib> - #include <cstdio> -/* Packages ------------------------------------------------------------------*/ - #include <opencv2/opencv.hpp> -/* libalx --------------------------------------------------------------------*/ - #include "libalx/alx_math.hpp" -/* Module --------------------------------------------------------------------*/ - #include "img_iface.hpp" - - #include "img_alx.hpp" - - -/****************************************************************************** - ******* static functions (prototypes) **************************************** - ******************************************************************************/ -static void img_alx_local_max (class cv::Mat *imgptr); -static void img_alx_skeleton (class cv::Mat *imgptr); -static void img_alx_lines_horizontal (class cv::Mat *imgptr); -static void img_alx_lines_vertical (class cv::Mat *imgptr); -static void img_alx_mean_horizontal (class cv::Mat *imgptr); -static void img_alx_mean_vertical (class cv::Mat *imgptr); -static void img_alx_median_horizontal (class cv::Mat *imgptr); -static void img_alx_median_vertical (class cv::Mat *imgptr); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -void img_alx_act (class cv::Mat *imgptr, int action, const void *data) -{ - - switch (action) { - case IMG_ALX_ACT_LOCAL_MAX: - img_alx_local_max(imgptr); - break; - case IMG_ALX_ACT_SKELETON: - img_alx_skeleton(imgptr); - break; - - case IMG_ALX_ACT_LINES_HORIZONTAL: - img_alx_lines_horizontal(imgptr); - break; - case IMG_ALX_ACT_LINES_VERTICAL: - img_alx_lines_vertical(imgptr); - break; - - case IMG_ALX_ACT_MEAN_HORIZONTAL: - img_alx_mean_horizontal(imgptr); - break; - case IMG_ALX_ACT_MEAN_VERTICAL: - img_alx_mean_vertical(imgptr); - break; - case IMG_ALX_ACT_MEDIAN_HORIZONTAL: - img_alx_median_horizontal(imgptr); - break; - case IMG_ALX_ACT_MEDIAN_VERTICAL: - img_alx_median_vertical(imgptr); - break; - } -} - - -/****************************************************************************** - ******* static functions (definitions) *************************************** - ******************************************************************************/ -static void img_alx_local_max (class cv::Mat *imgptr) -{ - int i; - int j; - int k; - int l; - /* Minimum distance between local maxima */ - const int dist_min = 16; - /* Minimum value of local maxima */ - const int val_min = 16; - class cv::Mat imgtmp; - - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - /* pointer to a pixel near img_pix (in imgptr) */ - uint8_t *near_pix; - /* pointer to a pixel (same position as img_pix, but in imgtmp) */ - uint8_t *tmp_pix; - - /* Tmp image copy */ - imgptr->copyTo(imgtmp); - - for (i = 0; i < imgptr->rows; i++) { - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - tmp_pix = imgtmp.data + i * imgptr->step + j; - - if (*img_pix < val_min) { - goto next_pixel; - } - - for (k = (i - dist_min); k < (i + dist_min + 1); k++) { - for (l = (j - dist_min); l < (j + dist_min + 1); l++) { - near_pix = imgptr->data + k * imgptr->step + l; - if ((k >= 0) && (k < imgptr->rows)) { - if ((l >= 0) && (l < imgptr->cols)) { - if (*img_pix < *near_pix) { - goto next_pixel; - } - } - } - } - } - - *tmp_pix = *img_pix; - continue; - -next_pixel: - *tmp_pix = 0; - } - } - - /* Cleanup */ - imgtmp.copyTo(*imgptr); - imgtmp.release(); -} - -static void img_alx_skeleton (class cv::Mat *imgptr) -{ - /* (Half of the) width of the skeleton */ - const int width = 5; - int dist_x; - int dist_y; - bool skeleton; - int cnt_lo [width]; - int cnt_hi_or_eq [width]; - class cv::Mat imgtmp; - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - /* pointer to a pixel near img_pix (in imgptr) */ - uint8_t *near_pix; - /* pointer to a pixel (same position as img_pix, but in imgtmp) */ - uint8_t *tmp_pix; - - int i; - int j; - int k; - int l; - int r; - - /* Tmp image copy */ - imgptr->copyTo(imgtmp); - - for (i = 0; i < imgptr->rows; i++) { - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - tmp_pix = imgtmp.data + i * imgptr->step + j; - - if (!(*img_pix)) { - *tmp_pix = 0; - continue; - } - - for (r = 0; r < width; r++) { - cnt_lo[r] = 0; - cnt_hi_or_eq[r] = 0; - } - - for (k = i - width; k <= i + width; k++) { - for (l = j - width; l <= j + width; l++) { - near_pix = imgptr->data + k * imgptr->step + l; - - dist_x = abs(k - i); - dist_y = abs(l - j); - - if ((k >= 0) && (k < imgptr->rows)) { - if ((l >= 0) && (l < imgptr->cols)) { - if (dist_x || dist_y) { - if (*near_pix < *img_pix) { - cnt_lo[std::max(dist_x, dist_y)]++; - } else { - cnt_hi_or_eq[std::max(dist_x, dist_y)]++; - } - } - } - } - - } - } - - skeleton = false; - for (r = 0; r < width; r++) { - if (cnt_lo[r] > (cnt_hi_or_eq[r] + (1.6) * (r + 1))) { - skeleton = true; - } - } - - if (skeleton) { - *tmp_pix = *img_pix; - } else { - *tmp_pix = 0; - } - } - } - - /* Cleanup */ - imgtmp.copyTo(*imgptr); - imgtmp.release(); -} - -static void img_alx_lines_horizontal (class cv::Mat *imgptr) -{ - int i; - int j; - bool white; - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - - for (i = 0; i < imgptr->rows; i++) { - white = false; - - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - if (*img_pix) { - white = true; - break; - } - } - - if (white) { - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - *img_pix = 255; - } - } - } -} - -static void img_alx_lines_vertical (class cv::Mat *imgptr) -{ - int i; - int j; - bool white; - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - - for (i = 0; i < imgptr->cols; i++) { - white = false; - - for (j = 0; j < imgptr->rows; j++) { - img_pix = imgptr->data + j * imgptr->step + i; - if (*img_pix) { - white = true; - break; - } - } - - if (white) { - for (j = 0; j < imgptr->rows; j++) { - img_pix = imgptr->data + j * imgptr->step + i; - *img_pix = 255; - } - } - } -} - -static void img_alx_mean_horizontal (class cv::Mat *imgptr) -{ - int i; - int j; - uint32_t tmp; - uint8_t mean; - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - - for (i = 0; i < imgptr->rows; i++) { - tmp = 0; - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - tmp += *img_pix; - } - mean = tmp / imgptr->cols; - - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - *img_pix = mean; - } - } -} - -static void img_alx_mean_vertical (class cv::Mat *imgptr) -{ - int i; - int j; - uint32_t tmp; - uint8_t mean; - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - - for (i = 0; i < imgptr->cols; i++) { - tmp = 0; - for (j = 0; j < imgptr->rows; j++) { - img_pix = imgptr->data + j * imgptr->step + i; - tmp += *img_pix; - } - mean = tmp / imgptr->rows; - - for (j = 0; j < imgptr->rows; j++) { - img_pix = imgptr->data + j * imgptr->step + i; - *img_pix = mean; - } - } -} - -static void img_alx_median_horizontal (class cv::Mat *imgptr) -{ - int i; - int j; - uint8_t row [imgptr->cols]; - uint8_t median; - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - - for (i = 0; i < imgptr->rows; i++) { - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - row[j] = *img_pix; - } - median = alx_median_u8(imgptr->cols, row); - - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - *img_pix = median; - } - } -} - -static void img_alx_median_vertical (class cv::Mat *imgptr) -{ - int i; - int j; - uint8_t col [imgptr->rows]; - uint8_t median; - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - - for (i = 0; i < imgptr->cols; i++) { - for (j = 0; j < imgptr->rows; j++) { - img_pix = imgptr->data + j * imgptr->step + i; - col[j] = *img_pix; - } - median = alx_median_u8(imgptr->rows, col); - - for (j = 0; j < imgptr->rows; j++) { - img_pix = imgptr->data + j * imgptr->step + i; - *img_pix = median; - } - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/image/src/img_calib3d.cpp b/modules/image/src/img_calib3d.cpp deleted file mode 100644 index cce54c3..0000000 --- a/modules/image/src/img_calib3d.cpp +++ /dev/null @@ -1,128 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C++ --------------------------------------------------------------*/ - #include <vector> -/* Standard C ----------------------------------------------------------------*/ - #include <cstdio> -/* Packages ------------------------------------------------------------------*/ - #include <opencv2/opencv.hpp> - #include <opencv2/calib3d/calib3d.hpp> -/* Module -------------------------------------------------------------------*/ - #include "img_iface.hpp" - - #include "img_calib3d.hpp" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define CORNERS_HOR (16) - # define CORNERS_VER (13) - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void img_calib3d_calibrate (class cv::Mat *imgptr, const void *data); -static void img_calib3d_undistort (class cv::Mat *imgptr, const void *data); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void img_calib3d_act (class cv::Mat *imgptr, int action, const void *data) -{ - switch (action) { - case IMG_CALIB3D_ACT_CALIBRATE: - img_calib3d_calibrate(imgptr, data); - break; - - case IMG_CALIB3D_ACT_UNDISTORT: - img_calib3d_undistort(imgptr, data); - break; - } -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void img_calib3d_calibrate (class cv::Mat *imgptr, const void *data) -{ - const struct Img_Iface_Data_Calibrate *data_cast; - class cv::Mat *intrinsic_mat; - class cv::Mat *dist_coefs; - class std::vector <class cv::Mat> *rvecs; - class std::vector <class cv::Mat> *tvecs; - - class cv::Size_ <int> pattern_size; - class std::vector <class std::vector <class cv::Point3_ <float>>> object_points; - class std::vector <class std::vector <class cv::Point_ <float>>> image_points; - class std::vector <class cv::Point_ <float>> corners; - class std::vector <class cv::Point3_ <float>> obj; - bool found; - int i; - int j; - - data_cast = (const struct Img_Iface_Data_Calibrate *)data; - intrinsic_mat = data_cast->intrinsic_mat; - dist_coefs = data_cast->dist_coefs; - rvecs = data_cast->rvecs; - tvecs = data_cast->tvecs; - - pattern_size = cv::Size(CORNERS_HOR, CORNERS_VER); - *intrinsic_mat = cv::Mat(3, 3, CV_32FC1); - (*intrinsic_mat).ptr<float>(0)[0] = 1; - (*intrinsic_mat).ptr<float>(1)[1] = 1; - - for (i = 0; i < CORNERS_HOR; i++) { - for (j = 0; j < CORNERS_VER; j++) { - obj.push_back(cv::Point3f(i, j * 10.0, 0.0)); - } - } - - found = cv::findChessboardCorners(*imgptr, pattern_size, corners, - CV_CALIB_CB_ADAPTIVE_THRESH | - CV_CALIB_CB_FILTER_QUADS); - - cv::cornerSubPix(*imgptr, corners, cv::Size(11, 11), - cv::Size(-1, -1), - cv::TermCriteria(CV_TERMCRIT_EPS | - CV_TERMCRIT_ITER, 30, 0.1)); - cv::drawChessboardCorners(*imgptr, pattern_size, corners, found); - - image_points.push_back(corners); - object_points.push_back(obj); - - cv::calibrateCamera(object_points, image_points, imgptr->size(), - *intrinsic_mat, *dist_coefs, *rvecs, *tvecs); -} - -static void img_calib3d_undistort (class cv::Mat *imgptr, const void *data) -{ - class cv::Mat imgtmp; - const struct Img_Iface_Data_Undistort *data_cast; - const class cv::Mat *intrinsic_mat; - const class cv::Mat *dist_coefs; - - data_cast = (const struct Img_Iface_Data_Undistort *)data; - intrinsic_mat = data_cast->intrinsic_mat; - dist_coefs = data_cast->dist_coefs; - - cv::undistort(*imgptr, imgtmp, *intrinsic_mat, *dist_coefs); - - imgptr->release(); - imgtmp.copyTo(*imgptr); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/image/src/img_cv.cpp b/modules/image/src/img_cv.cpp deleted file mode 100644 index eacaf98..0000000 --- a/modules/image/src/img_cv.cpp +++ /dev/null @@ -1,786 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C++ --------------------------------------------------------------*/ - #include <vector> -/* Standard C ----------------------------------------------------------------*/ - #include <cmath> - #include <cstdbool> - #include <cstdio> -/* Packages ------------------------------------------------------------------*/ - #include <opencv2/opencv.hpp> -/* Module --------------------------------------------------------------------*/ - #include "img_iface.hpp" - - #include "img_cv.hpp" - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ - /* Core: The core functionality */ - /* Pixel */ -static void img_cv_pixel_get (const class cv::Mat *imgptr, const void *data); -static void img_cv_pixel_set (class cv::Mat *imgptr, const void *data); - /* ROI */ -static void img_cv_set_ROI (class cv::Mat *imgptr, const void *data); - /* Operations on Arrays */ -static void img_cv_and_2ref (class cv::Mat *imgptr, const void *data); -static void img_cv_not (class cv::Mat *imgptr); -static void img_cv_or_2ref (class cv::Mat *imgptr, const void *data); -static void img_cv_component (class cv::Mat *imgptr, const void *data); - /* Imgproc: Image processing */ - /* Image filtering */ -static void img_cv_dilate (class cv::Mat *imgptr, const void *data); -static void img_cv_erode (class cv::Mat *imgptr, const void *data); -static void img_cv_smooth (class cv::Mat *imgptr, const void *data); -static void img_cv_sobel (class cv::Mat *imgptr, const void *data); -static void img_cv_border (class cv::Mat *imgptr, const void *data); - /* Geometric image transformations */ -static void img_cv_mirror (class cv::Mat *imgptr, const void *data); -static void img_cv_rotate_orto (class cv::Mat *imgptr, const void *data); -static void img_cv_rotate (class cv::Mat *imgptr, const void *data); - /* Miscellaneous image transformations */ -static void img_cv_adaptive_thr (class cv::Mat *imgptr, const void *data); -static void img_cv_cvt_color (class cv::Mat *imgptr, const void *data); -static void img_cv_distance_transform (class cv::Mat *imgptr); -static void img_cv_threshold (class cv::Mat *imgptr, const void *data); - /* Histograms */ -static void img_cv_histogram (class cv::Mat *imgptr, const void *data); -static void img_cv_histogram_c3 (class cv::Mat *imgptr, const void *data); - /* Structural analysis and shape descriptors */ -static void img_cv_contours (class cv::Mat *imgptr, const void *data); -static void img_cv_contours_size (const void *data); -static void img_cv_bounding_rect (class cv::Mat *imgptr, const void *data); -static void img_cv_fit_ellipse (class cv::Mat *imgptr, const void *data); -static void img_cv_min_area_rect (class cv::Mat *imgptr, const void *data); - /* Feature detection */ -static void img_cv_hough_circles (class cv::Mat *imgptr, const void *data); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void img_cv_act (class cv::Mat *imgptr, int action, const void *data) -{ - switch (action) { - case IMG_CV_ACT_PIXEL_GET: - img_cv_pixel_get(imgptr, data); - break; - case IMG_CV_ACT_PIXEL_SET: - img_cv_pixel_set(imgptr, data); - break; - - case IMG_CV_ACT_SET_ROI: - img_cv_set_ROI(imgptr, data); - break; - - case IMG_CV_ACT_AND_2REF: - img_cv_and_2ref(imgptr, data); - break; - 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_COMPONENT: - img_cv_component(imgptr, data); - break; - - case IMG_CV_ACT_DILATE: - img_cv_dilate(imgptr, data); - break; - case IMG_CV_ACT_ERODE: - img_cv_erode(imgptr, data); - break; - case IMG_CV_ACT_SMOOTH: - img_cv_smooth(imgptr, data); - break; - case IMG_CV_ACT_SOBEL: - img_cv_sobel(imgptr, data); - break; - case IMG_CV_ACT_BORDER: - img_cv_border(imgptr, data); - break; - - case IMG_CV_ACT_MIRROR: - img_cv_mirror(imgptr, data); - break; - case IMG_CV_ACT_ROTATE_ORTO: - img_cv_rotate_orto(imgptr, data); - break; - case IMG_CV_ACT_ROTATE: - img_cv_rotate(imgptr, data); - break; - - case IMG_CV_ACT_ADAPTIVE_THRESHOLD: - img_cv_adaptive_thr(imgptr, data); - break; - case IMG_CV_ACT_CVT_COLOR: - img_cv_cvt_color(imgptr, data); - break; - case IMG_CV_ACT_DISTANCE_TRANSFORM: - img_cv_distance_transform(imgptr); - break; - case IMG_CV_ACT_THRESHOLD: - img_cv_threshold(imgptr, data); - break; - - case IMG_CV_ACT_HISTOGRAM: - img_cv_histogram(imgptr, data); - break; - case IMG_CV_ACT_HISTOGRAM_C3: - img_cv_histogram_c3(imgptr, data); - break; - - case IMG_CV_ACT_CONTOURS: - img_cv_contours(imgptr, data); - break; - case IMG_CV_ACT_CONTOURS_SIZE: - img_cv_contours_size(data); - break; - case IMG_CV_ACT_BOUNDING_RECT: - img_cv_bounding_rect(imgptr, data); - break; - case IMG_CV_ACT_FIT_ELLIPSE: - img_cv_fit_ellipse(imgptr, data); - break; - case IMG_CV_ACT_MIN_AREA_RECT: - img_cv_min_area_rect(imgptr, data); - break; - - case IMG_CV_ACT_HOUGH_CIRCLES: - img_cv_hough_circles(imgptr, data); - break; - } -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -/* Core: The core functionality */ -/* ----- Pixel */ -static void img_cv_pixel_get (const class cv::Mat *imgptr, const void *data) -{ - const struct Img_Iface_Data_Pixel_Get *data_cast; - unsigned char *val; - int x; - int y; - - data_cast = (const struct Img_Iface_Data_Pixel_Get *)data; - val = data_cast->val; - x = data_cast->x; - y = data_cast->y; - - *val = imgptr->at<unsigned char>(y, x); -} - -static void img_cv_pixel_set (class cv::Mat *imgptr, const void *data) -{ - const struct Img_Iface_Data_Pixel_Set *data_cast; - unsigned char val; - int x; - int y; - - data_cast = (const struct Img_Iface_Data_Pixel_Set *)data; - val = data_cast->val; - x = data_cast->x; - y = data_cast->y; - - imgptr->at<unsigned char>(y, x) = val; -} - -/* ----- ROI */ -static void img_cv_set_ROI (class cv::Mat *imgptr, const void *data) -{ - class cv::Mat imgtmp; - const struct Img_Iface_Data_SetROI *data_cast; - const class cv::Rect_ <int> *rect; - - data_cast = (const struct Img_Iface_Data_SetROI *)data; - rect = &(data_cast->rect); - - (*imgptr)(*rect).copyTo(imgtmp); - imgtmp.copyTo(*imgptr); - - imgptr->release(); - imgtmp.copyTo(*imgptr); - - imgtmp.release(); -} - -/* ----- Operations on arrays */ -static void img_cv_and_2ref (class cv::Mat *imgptr, const void *data) -{ - const class cv::Mat *img_ref; - - img_ref = (const class cv::Mat *)data; - - cv::bitwise_and(*imgptr, *img_ref, *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, const void *data) -{ - const class cv::Mat *img_ref; - - img_ref = (const class cv::Mat *)data; - - cv::bitwise_or(*imgptr, *img_ref, *imgptr); -} - -static void img_cv_component (class cv::Mat *imgptr, const void *data) -{ - class cv::Mat cmp_img[3]; - const struct Img_Iface_Data_Component *data_cast; - int cmp; - - data_cast = (const struct Img_Iface_Data_Component *)data; - cmp = data_cast->cmp; - - cv::split(*imgptr, cmp_img); - - imgptr->release(); - cmp_img[cmp].copyTo(*imgptr); - - cmp_img[0].release(); - cmp_img[1].release(); - cmp_img[2].release(); -} - -/* Imgproc: Image processing */ -/* ----- Image filtering */ -static void img_cv_dilate (class cv::Mat *imgptr, const void *data) -{ - const struct Img_Iface_Data_Dilate_Erode *data_cast; - int i; - - data_cast = (const struct Img_Iface_Data_Dilate_Erode *)data; - i = data_cast->i; - - cv::dilate(*imgptr, *imgptr, cv::Mat(), cv::Point(-1,-1), i, - cv::BORDER_CONSTANT, cv::Scalar(0)); -} - -static void img_cv_erode (class cv::Mat *imgptr, const void *data) -{ - const struct Img_Iface_Data_Dilate_Erode *data_cast; - int i; - - data_cast = (const struct Img_Iface_Data_Dilate_Erode *)data; - i = data_cast->i; - - cv::erode(*imgptr, *imgptr, cv::Mat(), cv::Point(-1,-1), i, - cv::BORDER_CONSTANT, cv::Scalar(0)); -} - -static void img_cv_smooth (class cv::Mat *imgptr, const void *data) -{ - const struct Img_Iface_Data_Smooth *data_cast; - int method; - int ksize; - - data_cast = (const struct Img_Iface_Data_Smooth *)data; - method = data_cast->method; - ksize = data_cast->ksize; - if (!(ksize % 2)) { - ksize++; - } - - switch (method) { - case IMGI_SMOOTH_MEAN: - cv::blur(*imgptr, *imgptr, cv::Size(ksize, ksize), - cv::Point(-1,-1), cv::BORDER_DEFAULT); - break; - case IMGI_SMOOTH_GAUSS: - cv::GaussianBlur(*imgptr, *imgptr, cv::Size(ksize, ksize), - 0, 0, cv::BORDER_DEFAULT); - break; - case IMGI_SMOOTH_MEDIAN: - cv::medianBlur(*imgptr, *imgptr, ksize); - break; - } -} - -static void img_cv_sobel (class cv::Mat *imgptr, const void *data) -{ - const struct Img_Iface_Data_Sobel *data_cast; - int dx; - int dy; - int ksize; - - data_cast = (const struct Img_Iface_Data_Sobel *)data; - dx = data_cast->dx; - dy = data_cast->dy; - ksize = data_cast->ksize; - if (!(ksize % 2)) { - ksize++; - } - - cv::Sobel(*imgptr, *imgptr, -1, dx, dy, ksize, 1, 0, - cv::BORDER_DEFAULT); -} - -static void img_cv_border (class cv::Mat *imgptr, const void *data) -{ - class cv::Mat imgtmp; - const struct Img_Iface_Data_Border *data_cast; - int sz; - - /* Data */ - data_cast = (struct Img_Iface_Data_Border *)data; - sz = data_cast->size; - - imgtmp = cv::Mat(cv::Size(imgptr->cols + sz, imgptr->rows + sz), CV_8U); - - cv::copyMakeBorder(*imgptr, imgtmp, sz, sz, sz, sz, - cv::BORDER_CONSTANT, cv::Scalar(0)); - - imgtmp.copyTo(*imgptr); - - imgtmp.release(); -} - -/* ----- Geometric image transformations */ -static void img_cv_mirror (class cv::Mat *imgptr, const void *data) -{ - const struct Img_Iface_Data_Mirror *data_cast; - int axis; - - data_cast = (const struct Img_Iface_Data_Mirror *)data; - axis = data_cast->axis; - - cv::flip(*imgptr, *imgptr, axis); -} - -static void img_cv_rotate_orto (class cv::Mat *imgptr, const void *data) -{ - const struct Img_Iface_Data_Rotate_Orto *data_cast; - int n; - - data_cast = (struct Img_Iface_Data_Rotate_Orto *)data; - n = data_cast->n; - - switch (n) { - case 1: - /* Rotate: transpose and flip around horizontal axis: flip_mode=0 */ - cv::transpose(*imgptr, *imgptr); - cv::flip(*imgptr, *imgptr, 0); - break; - - case 2: - /* Rotate: Flip both axises: flip_mode=-1 */ - cv::flip(*imgptr, *imgptr, -1); - break; - - case 3: - /* Rotate: transpose and flip around vertical axis: flip_mode=1 */ - cv::transpose(*imgptr, *imgptr); - cv::flip(*imgptr, *imgptr, 1); - break; - } -} - -static void img_cv_rotate (class cv::Mat *imgptr, const void *data) -{ - class cv::Mat map_matrix; - const struct Img_Iface_Data_Rotate *data_cast; - const class cv::Point_ <float> *center; - double angle; - - data_cast = (const struct Img_Iface_Data_Rotate *)data; - center = &(data_cast->center); - angle = data_cast->angle; - - map_matrix = cv::getRotationMatrix2D(*center, angle, 1); - - cv::warpAffine(*imgptr, *imgptr, map_matrix, imgptr->size(), - cv::INTER_LINEAR, cv::BORDER_CONSTANT, - cv::Scalar(0, 0, 0)); - - map_matrix.release(); -} - -/* ----- Miscellaneous image transformations */ -static void img_cv_adaptive_thr (class cv::Mat *imgptr, const void *data) -{ - const struct Img_Iface_Data_Adaptive_Thr *data_cast; - int method; - int thr_typ; - int ksize; - - data_cast = (const struct Img_Iface_Data_Adaptive_Thr *)data; - method = data_cast->method; - thr_typ = data_cast->thr_typ; - ksize = data_cast->ksize; - if (!(ksize % 2)) { - ksize++; - } - - cv::adaptiveThreshold(*imgptr, *imgptr, 255, method, thr_typ, ksize, 0); -} - -static void img_cv_cvt_color (class cv::Mat *imgptr, const void *data) -{ - const struct Img_Iface_Data_Cvt_Color *data_cast; - int method; - - data_cast = (const struct Img_Iface_Data_Cvt_Color *)data; - method = data_cast->method; - - cv::cvtColor(*imgptr, *imgptr, method, 0); -} - -static void img_cv_distance_transform (class cv::Mat *imgptr) -{ - class cv::Mat imgtmp; - - cv::distanceTransform(*imgptr,imgtmp, CV_DIST_L2, CV_DIST_MASK_PRECISE); - - /* DistanceTransform gives CV_32F image */ - imgtmp.convertTo(*imgptr, CV_8U); - - imgtmp.release(); -} - -static void img_cv_threshold (class cv::Mat *imgptr, const void *data) -{ - const struct Img_Iface_Data_Threshold *data_cast; - int thr_typ; - int thr_val; - - data_cast = (const struct Img_Iface_Data_Threshold *)data; - thr_typ = data_cast->thr_typ; - thr_val = data_cast->thr_val; - if (thr_val == -1) { - thr_typ |= cv::THRESH_OTSU; - } - - cv::threshold(*imgptr, *imgptr, thr_val, 0xFF, thr_typ); -} - -/* ----- Histograms */ -static void img_cv_histogram (class cv::Mat *imgptr, const void *data) -{ - const struct Img_Iface_Data_Histogram *data_cast; - class cv::Mat *hist; - class cv::Mat *hist_img; - const int h_size = 256; - const float h_range_arr[] = {0.0, 256.0}; - const float *h_range = {h_range_arr}; - int i; - - data_cast = (const struct Img_Iface_Data_Histogram *)data; - hist = data_cast->hist_c0; - hist_img = data_cast->hist_img; - - /* Write components into cmp_img[] */ - cv::calcHist(imgptr, 1, 0, cv::Mat(), *hist, 1, &h_size, &h_range, - true, false); - - /* Init */ - hist_img->setTo(cv::Scalar(0)); - - /* Normalize the result to [0, hist_img->rows - 1] */ - cv::normalize(*hist, *hist, 0, hist_img->rows - 1, cv::NORM_MINMAX, -1, - cv::Mat()); - - /* Draw hist into hist_img */ - for(i = 0; i < h_size; i++ ) { - cv::line(*hist_img, cv::Point(i, hist_img->rows - 0), - cv::Point(i, - hist_img->rows - hist->at<float>(i)), - cv::Scalar(255, 0, 0), 1, 8, 0); - } - - /* Show histogram */ - img_iface_show_hist_c1(); -} - -static void img_cv_histogram_c3 (class cv::Mat *imgptr, const void *data) -{ - class cv::Mat cmp_img[3]; - const struct Img_Iface_Data_Histogram *data_cast; - class cv::Mat *hist_c0; - class cv::Mat *hist_c1; - class cv::Mat *hist_c2; - class cv::Mat *hist_img; - const int h_size = 256; - const float h_range_arr[] = {0.0, 256.0}; - const float *h_range = {h_range_arr}; - int i; - - data_cast = (const struct Img_Iface_Data_Histogram *)data; - hist_c0 = data_cast->hist_c0; - hist_c1 = data_cast->hist_c1; - hist_c2 = data_cast->hist_c2; - hist_img = data_cast->hist_img; - - /* Write components into cmp_img[] */ - cv::split(*imgptr, cmp_img); - - /* Write components into cmp_img[] */ - cv::calcHist(&cmp_img[0], 1, 0, cv::Mat(), *hist_c0, 1, &h_size, - &h_range, true, false); - cv::calcHist(&cmp_img[1], 1, 0, cv::Mat(), *hist_c1, 1, &h_size, - &h_range, true, false); - cv::calcHist(&cmp_img[2], 1, 0, cv::Mat(), *hist_c2, 1, &h_size, - &h_range, true, false); - - /* Init */ - hist_img->setTo(cv::Scalar(0)); - - /* Normalize the result to [0, hist_img->rows - 1] */ - cv::normalize(*hist_c0, *hist_c0, 0, hist_img->rows - 1, - cv::NORM_MINMAX, -1, cv::Mat()); - cv::normalize(*hist_c1, *hist_c1, 0, hist_img->rows - 1, - cv::NORM_MINMAX, -1, cv::Mat()); - cv::normalize(*hist_c2, *hist_c2, 0, hist_img->rows - 1, - cv::NORM_MINMAX, -1, cv::Mat()); - - /* Draw hist into hist_img */ - for(i = 0; i < 256; i++ ) { - cv::line(*hist_img, cv::Point(3 * i, hist_img->rows - 0), - cv::Point(3 * i, - hist_img->rows - hist_c0->at<float>(i)), - cv::Scalar(255, 0, 0), 1, 8, 0); - } - for(i = 0; i < 256; i++ ) { - cv::line(*hist_img, cv::Point(3 * i + 1, hist_img->rows - 0), - cv::Point(3 * i + 1, - hist_img->rows - hist_c1->at<float>(i)), - cv::Scalar(0, 255, 0), 1, 8, 0); - } - for(i = 0; i < 256; i++ ) { - cv::line(*hist_img, cv::Point(3 * i + 2, hist_img->rows - 0), - cv::Point(3 * i + 2, - hist_img->rows - hist_c2->at<float>(i)), - cv::Scalar(0, 0, 255), 1, 8, 0); - } - - /* Show histogram */ - img_iface_show_hist_c3(); - - cmp_img[0].release(); - cmp_img[1].release(); - cmp_img[2].release(); -} - -/* ----- Structural analysis and shape descriptors */ -static void img_cv_contours (class cv::Mat *imgptr, const void *data) -{ - const struct Img_Iface_Data_Contours *data_cast; - class std::vector<class std::vector<class cv::Point_<int>>> *contours; - class cv::Mat *hierarchy; - - /* Data */ - data_cast = (const struct Img_Iface_Data_Contours *)data; - - /* Contours */ - contours = data_cast->contours; - hierarchy = data_cast->hierarchy; - - /* Get contours */ - - cv::findContours(*imgptr, *contours, *hierarchy, CV_RETR_EXTERNAL, - CV_CHAIN_APPROX_SIMPLE); - - /* Set image to black */ - imgptr->setTo(cv::Scalar(0)); - - /* Draw contours in color */ - cv::drawContours(*imgptr, *contours, -1, cv::Scalar(255), 1, 8, - *hierarchy, 1, cvPoint(0, 0)); -} - -static void img_cv_contours_size (const void *data) -{ - const struct Img_Iface_Data_Contours_Size *data_cast; - const class std::vector<class std::vector<class cv::Point_<int>>> *contours; - unsigned i; - - data_cast = (const struct Img_Iface_Data_Contours_Size *)data; - contours = data_cast->contours; - - if (data_cast->area) { - for (i = 0; i < contours->size(); i++) { - data_cast->area[i] = cv::contourArea( - (*contours)[i], false); - } - } - if (data_cast->perimeter) { - for (i = 0; i < contours->size(); i++) { - data_cast->perimeter[i] = cv::arcLength( - (*contours)[i], true); - } - } -} - -static void img_cv_bounding_rect (class cv::Mat *imgptr, const void *data) -{ - class cv::Point_ <float> vertices[4]; - const struct Img_Iface_Data_Bounding_Rect *data_cast; - const class std::vector <class cv::Point_ <int>> *contour; - class cv::Rect_ <int> *rect; - bool show; - - data_cast = (const struct Img_Iface_Data_Bounding_Rect *)data; - contour = data_cast->contour; - rect = data_cast->rect; - show = data_cast->show; - - *rect = cv::boundingRect(*contour); - - /* Draw rectangle */ - if (show) { - vertices[0].x = rect->x; - vertices[0].y = rect->y; - vertices[1].x = rect->x + rect->width; - vertices[1].y = rect->y; - vertices[2].x = rect->x + rect->width; - vertices[2].y = rect->y + rect->height; - vertices[3].x = rect->x; - vertices[3].y = rect->y + rect->height; - 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, const void *data) -{ - class cv::Point_ <float> vertices[4]; - const struct Img_Iface_Data_MinARect *data_cast; - const class std::vector <class cv::Point_ <int>> *contour; - class cv::RotatedRect *rect; - bool show; - - data_cast = (const struct Img_Iface_Data_MinARect *)data; - contour = data_cast->contour; - rect = data_cast->rect; - show = data_cast->show; - - *rect = cv::fitEllipse(*contour); - - /* Draw rectangle */ - 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_min_area_rect (class cv::Mat *imgptr, const void *data) -{ - class cv::Point_ <float> vertices[4]; - const struct Img_Iface_Data_MinARect *data_cast; - const class std::vector <class cv::Point_ <int>> *contour; - class cv::RotatedRect *rect; - bool show; - - data_cast = (const struct Img_Iface_Data_MinARect *)data; - contour = data_cast->contour; - rect = data_cast->rect; - show = data_cast->show; - - *rect = cv::minAreaRect(*contour); - - /* Draw rectangle */ - 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); - } -} - -/* ----- Feature detection */ -static void img_cv_hough_circles (class cv::Mat *imgptr, const void *data) -{ - class cv::Point_ <int> center; - int radius; - unsigned i; - const struct Img_Iface_Data_Hough_Circles *data_cast; - class std::vector <class cv::Vec <float, 3>> *circles; - double dist_min; - double param_1; - double param_2; - int radius_min; - int radius_max; - - data_cast = (const struct Img_Iface_Data_Hough_Circles *)data; - circles = data_cast->circles; - dist_min = data_cast->dist_min; - param_1 = data_cast->param_1; - param_2 = data_cast->param_2; - radius_min = data_cast->radius_min; - radius_max = data_cast->radius_max; - - /* Get circles */ - cv::HoughCircles(*imgptr, *circles, CV_HOUGH_GRADIENT, 1, dist_min, - param_1, param_2, radius_min, radius_max); - - /* Set image to black */ - imgptr->setTo(cv::Scalar(0)); - - /* Draw circles */ - for (i = 0; i < circles->size(); i++) { - center.x = cvRound((*circles)[i][0]); - center.y = cvRound((*circles)[i][1]); - radius = cvRound((*circles)[i][2]); - - /* Draw the circle center */ -/* cv::circle(*imgptr, center, 3, - cv::Scalar(0, 255, 0), -1, 8, 0);*/ - - /* Draw the circle outline */ - cv::circle(*imgptr, center, radius, - cv::Scalar(250), 1, 8, 0); - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/image/src/img_iface.cpp b/modules/image/src/img_iface.cpp deleted file mode 100644 index 4411920..0000000 --- a/modules/image/src/img_iface.cpp +++ /dev/null @@ -1,2032 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <cerrno> - #include <cmath> - #include <cstddef> - #include <cstdio> -/* Standard C++ --------------------------------------------------------------*/ - #include <vector> -/* Packages ------------------------------------------------------------------*/ - #include <opencv2/opencv.hpp> -/* Project -------------------------------------------------------------------*/ - #include "save.hpp" - #include "user_iface.hpp" -/* Module --------------------------------------------------------------------*/ - #include "img_alx.hpp" - #include "img_cv.hpp" - #include "img_orb.hpp" - #include "img_calib3d.hpp" - #include "img_zbar.hpp" - #include "img_ocr.hpp" - - #include "img_iface.hpp" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define IMG_MEM_SIZE (20) - - # define WIN_NAME_IMG "Image" - # define WIN_NAME_HIST "Hist" - # define WIN_TIMEOUT (500) - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ - char img_ocr_text [OCR_TEXT_MAX]; - struct Img_Iface_ZB_Codes zb_codes; - -/* Static --------------------------------------------------------------------*/ -static class cv::Mat image_copy_old; -static class cv::Mat image_copy_tmp; -static class cv::Mat image_mem [IMG_MEM_SIZE]; -static class cv::Mat image_ref; -static class cv::Mat histogram_c0; -static class cv::Mat histogram_c1; -static class cv::Mat histogram_c2; -static class cv::Mat hist_img_c1; -static class cv::Mat hist_img_c3; -static class std::vector <class std::vector <cv::Point_ <int>>> contours; -static double area [CONTOURS_MAX]; -static double perimeter [CONTOURS_MAX]; -static class cv::Mat hierarchy; -static class cv::Rect_ <int> rectangle; -static class cv::RotatedRect rectangle_rot; -static class std::vector <class cv::Vec <float, 3>> circles; -static class cv::Mat intrinsic_mat; -static class cv::Mat dist_coefs; -static class std::vector <class cv::Mat> rvecs; -static class std::vector <class cv::Mat> tvecs; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ - /* img_alx */ -static void img_iface_local_max (void); -static void img_iface_skeleton (void); -static void img_iface_lines_horizontal (void); -static void img_iface_lines_vertical (void); -static void img_iface_mean_horizontal (void); -static void img_iface_mean_vertical (void); -static void img_iface_median_horizontal (void); -static void img_iface_median_vertical (void); - - /* img_cv */ - /* Core: The core functionality */ - /* Pixel */ -static void img_iface_pixel_get (const void *data); -static void img_iface_pixel_set (const void *data); - /* ROI */ -static void img_iface_set_ROI (const void *data); -static void img_iface_set_ROI_2rect (const void *data); - /* Operations on Arrays */ -static void img_iface_and_2ref (void); -static void img_iface_not (void); -static void img_iface_or_2ref (void); -static void img_iface_component (const void *data); - /* Imgproc: Image processing */ - /* Image filtering */ -static void img_iface_dilate (const void *data); -static void img_iface_erode (const void *data); -static void img_iface_dilate_erode (const void *data); -static void img_iface_erode_dilate (const void *data); -static void img_iface_smooth (const void *data); -static void img_iface_sobel (const void *data); -static void img_iface_border (const void *data); - /* Geometric image transformations */ -static void img_iface_mirror (const void *data); -static void img_iface_rotate_orto (const void *data); -static void img_iface_rotate (const void *data); -static void img_iface_rotate_2rect (const void *data); - /* Miscellaneous image transformations */ -static void img_iface_adaptive_thr (const void *data); -static void img_iface_cvt_color (const void *data); -static void img_iface_distance_transform (void); -static void img_iface_threshold (const void *data); - /* Histograms */ -static void img_iface_histogram (const void *data); -static void img_iface_histogram_c3 (const void *data); - /* Structural analysis and shape descriptors */ -static void img_iface_contours (const void *data); -static void img_iface_contours_size (const void *data); -static void img_iface_bounding_rect (const void *data); -static void img_iface_fit_ellipse (const void *data); -static void img_iface_min_area_rect (const void *data); - /* Feature detection */ -static void img_iface_hough_circles (const void *data); - - /* img_orb */ -static void img_iface_align (void); - /* img_calib3d */ -static void img_iface_calibrate (const void *data); -static void img_iface_undistort (const void *data); - - /* img_zbar */ -static void img_iface_decode (const void *data); - /* img_ocr */ -static void img_iface_read (const void *data); - - /* img_iface */ -static void img_iface_apply (void); -static void img_iface_discard (void); -static void img_iface_save_mem (const void *data); -static void img_iface_load_mem (const void *data); -static void img_iface_save_ref (void); - /* save */ -static void img_iface_save_file (void); -static void img_iface_save_update (void); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -void img_iface_init (void) -{ - 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); - hist_img_c3.release(); - hist_img_c3 = cv::Mat::zeros(cv::Size(256 * 3, 100), CV_8UC3); -} - -void img_iface_cleanup_main (void) -{ - int i; - - for (i = 0; i < IMG_MEM_SIZE; i++) { - image_mem[i].release(); - } - image_ref.release(); - - cv::destroyAllWindows(); -} - -void img_iface_load (const char *fpath, const char *fname) -{ - char file_path [FILENAME_MAX]; - char file_name [FILENAME_MAX]; - - /* Init */ - img_iface_init(); - - /* Set file_path */ - if (!fpath) { - snprintf(file_path, FILENAME_MAX, "%s", saved_path); - } else { - snprintf(file_path, FILENAME_MAX, "%s", fpath); - } - - /* Set file_name */ - if (!fname) { - /* Request file name */ - user_iface_fname(file_path, file_name); - } else { - snprintf(file_name, FILENAME_MAX, "%s", fname); - } - - /* Load file */ - errno = 0; - load_image_file(file_path, file_name); - - if (!errno) { - /* Make a static copy of image */ - image.copyTo(image_copy_old); - image.copyTo(image_copy_tmp); - } -} - -void img_iface_cleanup (void) -{ - image_copy_old.release(); - image_copy_tmp.release(); - histogram_c0.release(); - histogram_c1.release(); - histogram_c2.release(); - hist_img_c1.release(); - hist_img_c3.release(); -} - -void img_iface_act (int action, const void *data) -{ - switch (action) { - /* img_alx */ - case IMG_IFACE_ACT_LOCAL_MAX: - img_iface_local_max(); - break; - case IMG_IFACE_ACT_SKELETON: - img_iface_skeleton(); - break; - case IMG_IFACE_ACT_LINES_HORIZONTAL: - img_iface_lines_horizontal(); - break; - case IMG_IFACE_ACT_LINES_VERTICAL: - img_iface_lines_vertical(); - break; - case IMG_IFACE_ACT_MEAN_HORIZONTAL: - img_iface_mean_horizontal(); - break; - case IMG_IFACE_ACT_MEAN_VERTICAL: - img_iface_mean_vertical(); - break; - case IMG_IFACE_ACT_MEDIAN_HORIZONTAL: - img_iface_median_horizontal(); - break; - case IMG_IFACE_ACT_MEDIAN_VERTICAL: - img_iface_median_vertical(); - break; - - /* img_cv */ - /* Core: The core functionality */ - /* Pixel */ - case IMG_IFACE_ACT_PIXEL_GET: - img_iface_pixel_get(data); - break; - case IMG_IFACE_ACT_PIXEL_SET: - img_iface_pixel_set(data); - break; - /* ROI */ - case IMG_IFACE_ACT_SET_ROI: - img_iface_set_ROI(data); - break; - case IMG_IFACE_ACT_SET_ROI_2RECT: - img_iface_set_ROI_2rect(data); - break; - /* Operations on Arrays */ - case IMG_IFACE_ACT_AND_2REF: - img_iface_and_2ref(); - break; - case IMG_IFACE_ACT_NOT: - img_iface_not(); - break; - case IMG_IFACE_ACT_OR_2REF: - img_iface_or_2ref(); - break; - case IMG_IFACE_ACT_COMPONENT: - img_iface_component(data); - break; - /* Imgproc: Image processing */ - /* Image filtering */ - case IMG_IFACE_ACT_DILATE: - img_iface_dilate(data); - break; - case IMG_IFACE_ACT_ERODE: - img_iface_erode(data); - break; - case IMG_IFACE_ACT_DILATE_ERODE: - img_iface_dilate_erode(data); - break; - case IMG_IFACE_ACT_ERODE_DILATE: - img_iface_erode_dilate(data); - break; - case IMG_IFACE_ACT_SMOOTH: - img_iface_smooth(data); - break; - case IMG_IFACE_ACT_SOBEL: - img_iface_sobel(data); - break; - case IMG_IFACE_ACT_BORDER: - img_iface_border(data); - break; - /* Geometric image transformations */ - case IMG_IFACE_ACT_MIRROR: - img_iface_mirror(data); - break; - case IMG_IFACE_ACT_ROTATE_ORTO: - img_iface_rotate_orto(data); - break; - case IMG_IFACE_ACT_ROTATE: - img_iface_rotate(data); - break; - case IMG_IFACE_ACT_ROTATE_2RECT: - img_iface_rotate_2rect(data); - break; - /* Miscellaneous image transformations */ - case IMG_IFACE_ACT_ADAPTIVE_THRESHOLD: - img_iface_adaptive_thr(data); - break; - case IMG_IFACE_ACT_CVT_COLOR: - img_iface_cvt_color(data); - break; - case IMG_IFACE_ACT_DISTANCE_TRANSFORM: - img_iface_distance_transform(); - break; - case IMG_IFACE_ACT_THRESHOLD: - img_iface_threshold(data); - break; - /* Histograms */ - case IMG_IFACE_ACT_HISTOGRAM: - img_iface_histogram(data); - break; - case IMG_IFACE_ACT_HISTOGRAM_C3: - img_iface_histogram_c3(data); - break; - /* Structural analysis and shape descriptors */ - case IMG_IFACE_ACT_CONTOURS: - img_iface_contours(data); - break; - case IMG_IFACE_ACT_CONTOURS_SIZE: - img_iface_contours_size(data); - break; - case IMG_IFACE_ACT_BOUNDING_RECT: - img_iface_bounding_rect(data); - break; - case IMG_IFACE_ACT_FIT_ELLIPSE: - img_iface_fit_ellipse(data); - break; - case IMG_IFACE_ACT_MIN_AREA_RECT: - img_iface_min_area_rect(data); - break; - /* Feature detection */ - case IMG_IFACE_ACT_HOUGH_CIRCLES: - img_iface_hough_circles(data); - break; - - /* img_orb */ - case IMG_IFACE_ACT_ALIGN: - img_iface_align(); - break; - - /* img_calib3d */ - case IMG_IFACE_ACT_CALIBRATE: - img_iface_calibrate(data); - break; - case IMG_IFACE_ACT_UNDISTORT: - img_iface_undistort(data); - break; - - /* img_zbar */ - case IMG_IFACE_ACT_DECODE: - img_iface_decode(data); - break; - - /* img_ocr */ - case IMG_IFACE_ACT_READ: - img_iface_read(data); - break; - - /* img_iface */ - case IMG_IFACE_ACT_APPLY: - img_iface_apply(); - break; - case IMG_IFACE_ACT_DISCARD: - img_iface_discard(); - break; - case IMG_IFACE_ACT_SAVE_MEM: - img_iface_save_mem(data); - break; - case IMG_IFACE_ACT_LOAD_MEM: - img_iface_load_mem(data); - break; - case IMG_IFACE_ACT_SAVE_REF: - img_iface_save_ref(); - break; - - /* save */ - case IMG_IFACE_ACT_SAVE_FILE: - img_iface_save_file(); - break; - case IMG_IFACE_ACT_SAVE_UPDT: - img_iface_save_update(); - break; - - default: - /* Invalid action */ - break; - } -} - -void img_iface_show_img (void) -{ - cv::imshow(WIN_NAME_IMG, image_copy_tmp); - cv::waitKey(WIN_TIMEOUT); -} - -void img_iface_show_hist_c1 (void) -{ - cv::imshow(WIN_NAME_HIST, hist_img_c1); - cv::waitKey(WIN_TIMEOUT); -} - -void img_iface_show_hist_c3 (void) -{ - cv::imshow(WIN_NAME_HIST, hist_img_c3); - cv::waitKey(WIN_TIMEOUT); -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -/* img_alx --------------------------------------------------------------------*/ -static void img_iface_local_max (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Local maxima */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_LOCAL_MAX, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Local maxima"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_skeleton (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Skeleton */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_SKELETON, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Skeleton"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_lines_horizontal (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Horizontal lines */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_LINES_HORIZONTAL, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Horizontal lines"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_lines_vertical (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Vertical lines */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_LINES_VERTICAL, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Vertical lines"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_mean_horizontal (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Horizontal lines */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEAN_HORIZONTAL, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Horizontal mean"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_mean_vertical (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Horizontal lines */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEAN_VERTICAL, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Vertical mean"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_median_horizontal (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Horizontal lines */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEDIAN_HORIZONTAL, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Horizontal median"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_median_vertical (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Horizontal lines */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEDIAN_VERTICAL, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Vertical median"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -/* img_cv --------------------------------------------------------------------*/ -/* ----- Core: The core functionality */ -/* ----- ------- Pixel */ -static void img_iface_pixel_get (const void *data) -{ - struct Img_Iface_Data_Pixel_Get data_tmp; - const struct Img_Iface_Data_Pixel_Get *data_cast; - unsigned char val; - char title [80]; - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - if (!data) { - data_tmp.val = &val; - - /* Ask user */ - 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 = (const void *)&data_tmp; - } - - /* Get pixel value */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_PIXEL_GET, data); - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Pixel_Get *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Pixel get: (%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)++; -} - -static void img_iface_pixel_set (const void *data) -{ - struct Img_Iface_Data_Pixel_Set data_tmp; - const struct Img_Iface_Data_Pixel_Set *data_cast; - char title [80]; - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - if (!data) { - /* Ask user */ - 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); - - snprintf(title, 80, "val:"); - data_tmp.val = user_iface_getint(0, 0, 255, - title, NULL); - - data = (const void *)&data_tmp; - } - - /* Set pixel value */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_PIXEL_SET, data); - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Pixel_Set *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Pixel get: (%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)++; -} - -/* ----- ------- ROI */ -static void img_iface_set_ROI (const void *data) -{ - struct Img_Iface_Data_SetROI data_tmp; - const struct Img_Iface_Data_SetROI *data_cast; - char title [80]; - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Origin: x:"); - data_tmp.rect.x = user_iface_getint(0, 0, - image_copy_tmp.cols, - title, NULL); - - snprintf(title, 80, "Origin: y:"); - data_tmp.rect.y = user_iface_getint(0, 0, - image_copy_tmp.rows, - title, NULL); - - snprintf(title, 80, "Width:"); - data_tmp.rect.width = user_iface_getint(1, - image_copy_tmp.cols - data_tmp.rect.x, - image_copy_tmp.cols - data_tmp.rect.x, - title, NULL); - - snprintf(title, 80, "Height:"); - data_tmp.rect.height = user_iface_getint(1, - image_copy_tmp.rows - data_tmp.rect.y, - image_copy_tmp.rows - data_tmp.rect.y, - title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_SetROI *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "ROI: (%i,%i) w=%i,h=%i", - data_cast->rect.x, - data_cast->rect.y, - data_cast->rect.width, - data_cast->rect.height); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Set ROI */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_SET_ROI, data); -} - -static void img_iface_set_ROI_2rect (const void *data) -{ - struct Img_Iface_Data_SetROI data_tmp; - const struct Img_Iface_Data_SetROI *data_cast; - - /* Data */ - if (!data) { - data_tmp.rect.x = rectangle.x; - data_tmp.rect.y = rectangle.y; - data_tmp.rect.width = rectangle.width; - data_tmp.rect.height = rectangle.height; - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_SetROI *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "ROI: (%i,%i) w=%i,h=%i", - data_cast->rect.x, - data_cast->rect.y, - data_cast->rect.width, - data_cast->rect.height); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Set ROI */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_SET_ROI, data); -} - -/* ----- ------- Operations on arrays */ -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, (const void *)&image_ref); -} - -static void img_iface_not (void) -{ - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Invert color"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* 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, (const void *)&image_ref); -} - -static void img_iface_component (const void *data) -{ - struct Img_Iface_Data_Component data_tmp; - const struct Img_Iface_Data_Component *data_cast; - char title [80]; - - /* Must have at least 3 channels */ - if (image_copy_tmp.channels() < 3) { - /* 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; - } - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Component:"); - data_tmp.cmp = user_iface_getint(0, 0, - image_copy_tmp.channels() - 1, - title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Component *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Component %i", - data_cast->cmp); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Filter: extract component */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_COMPONENT, data); -} - -/* ----- Imgproc: Image processing */ -/* ----- ------- Image filtering */ -static void img_iface_dilate (const void *data) -{ - struct Img_Iface_Data_Dilate_Erode data_tmp; - const struct Img_Iface_Data_Dilate_Erode *data_cast; - char title [80]; - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Iterations:"); - data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Dilate_Erode *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Dilate i=%i", - data_cast->i); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Dilate */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data); -} - -static void img_iface_erode (const void *data) -{ - struct Img_Iface_Data_Dilate_Erode data_tmp; - const struct Img_Iface_Data_Dilate_Erode *data_cast; - char title [80]; - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Iterations:"); - data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Dilate_Erode *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Erode i=%i", - data_cast->i); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Erode */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data); -} - -static void img_iface_dilate_erode (const void *data) -{ - struct Img_Iface_Data_Dilate_Erode data_tmp; - const struct Img_Iface_Data_Dilate_Erode *data_cast; - char title [80]; - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Iterations:"); - data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Dilate_Erode *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Dilate-erode i=%i", - data_cast->i); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Dilate */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data); - img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data); -} - -static void img_iface_erode_dilate (const void *data) -{ - struct Img_Iface_Data_Dilate_Erode data_tmp; - const struct Img_Iface_Data_Dilate_Erode *data_cast; - char title [80]; - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Iterations:"); - data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Dilate_Erode *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Erode-dilate i=%i", - data_cast->i); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Dilate */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data); - img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data); -} - -static void img_iface_smooth (const void *data) -{ - struct Img_Iface_Data_Smooth data_tmp; - const struct Img_Iface_Data_Smooth *data_cast; - char title [80]; - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Method: MEAN=1, GAUSS=2, MEDIAN=3"); - data_tmp.method = user_iface_getint(1, 3, 3, title, NULL); - - snprintf(title, 80, "Kernel size: 3, 5, 7, ..."); - data_tmp.ksize = user_iface_getint(3, 3, INFINITY, title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Smooth *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Smooth mth=%i [%ix%i]", - data_cast->method, - data_cast->ksize, - data_cast->ksize); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Filter: smooth */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_SMOOTH, data); -} - -static void img_iface_sobel (const void *data) -{ - struct Img_Iface_Data_Sobel data_tmp; - const struct Img_Iface_Data_Sobel *data_cast; - char title [80]; - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Order of the derivative x"); - data_tmp.dx = user_iface_getint(0, 1, 10, title, NULL); - - snprintf(title, 80, "Order of the derivative y"); - data_tmp.dy = user_iface_getint(0, 1, 10, title, NULL); - - snprintf(title, 80, "Size of the extended Sobel kernel (-1 -> Scharr"); - data_tmp.ksize = user_iface_getint(-1, 3, 7, title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Sobel *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Sobel dx=%i;dy=%i [ks=%i]", - data_cast->dx, - data_cast->dy, - data_cast->ksize); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Filter: sobel */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_SOBEL, data); -} - -static void img_iface_border (const void *data) -{ - struct Img_Iface_Data_Border data_tmp; - const struct Img_Iface_Data_Border *data_cast; - char title [80]; - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Size"); - data_tmp.size = user_iface_getint(1, 1, 0xF000, title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Border *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Border size=%i", - data_cast->size); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Add border */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_BORDER, data); -} - -/* ----- ------- Geometric image transformations */ -static void img_iface_mirror (const void *data) -{ - struct Img_Iface_Data_Mirror data_tmp; - const struct Img_Iface_Data_Mirror *data_cast; - char title [80]; - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Axis: 0=x; 1=y"); - data_tmp.axis = user_iface_getint(0, 1, 1, title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Mirror *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Mirror axis: %i", - data_cast->axis); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Mirror */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_MIRROR, data); -} - -static void img_iface_rotate_orto (const void *data) -{ - struct Img_Iface_Data_Rotate_Orto data_tmp; - const struct Img_Iface_Data_Rotate_Orto *data_cast; - char title [80]; - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Rotate (counterclockwise) n * pi/2 rad; n:"); - data_tmp.n = user_iface_getint(1, 1, 3, title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Rotate_Orto *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Rotate %i * pi/2 rad", - data_cast->n); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Rotate ortogonally */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE_ORTO, data); -} - -static void img_iface_rotate (const void *data) -{ - struct Img_Iface_Data_Rotate data_tmp; - const struct Img_Iface_Data_Rotate *data_cast; - char title [80]; - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Center: x:"); - data_tmp.center.x = user_iface_getdbl(0, 0, INFINITY, title, NULL); - - snprintf(title, 80, "Center: y:"); - data_tmp.center.y = user_iface_getdbl(0, 0, INFINITY, title, NULL); - - snprintf(title, 80, "Angle: (deg)"); - data_tmp.angle = user_iface_getdbl(-INFINITY, 0, INFINITY, title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Rotate *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Rotate (%.2f,%.2f) %lfº", - data_cast->center.x, - data_cast->center.y, - data_cast->angle); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Rotate ortogonally */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE, data); -} - -static void img_iface_rotate_2rect (const void *data) -{ - struct Img_Iface_Data_Rotate data_tmp; - - /* Data */ - if (!data) { - data_tmp.center.x = rectangle_rot.center.x; - data_tmp.center.y = rectangle_rot.center.y; - data_tmp.angle = rectangle_rot.angle; - - /* If angle is < -45º, it is taking into acount the incorrect side */ - if (data_tmp.angle < -45.0) { - data_tmp.angle += 90.0; - } - - data = (const void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Rotate to rectangle"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Rotate ortogonally */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE, data); -} - -/* ----- ------- Miscellaneous image transformations */ -static void img_iface_adaptive_thr (const void *data) -{ - struct Img_Iface_Data_Adaptive_Thr data_tmp; - const struct Img_Iface_Data_Adaptive_Thr *data_cast; - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Method: MEAN=0, GAUSS=1"); - data_tmp.method = user_iface_getint(0, 1, 1, title, NULL); - - snprintf(title, 80, "Type: BIN=0, BIN_INV=1"); - data_tmp.thr_typ = user_iface_getint(0, 0, 1, title, NULL); - - snprintf(title, 80, "Kernel size: 3, 5, 7, ..."); - data_tmp.ksize = user_iface_getint(3, 3, INFINITY, title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Adaptive_Thr *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Threshold mth=%i, typ=%i, ks=%i", - data_cast->method, - data_cast->thr_typ, - data_cast->ksize); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Filter: adaptive threshold */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_ADAPTIVE_THRESHOLD, data); -} - -static void img_iface_cvt_color (const void *data) -{ - struct Img_Iface_Data_Cvt_Color data_tmp; - const struct Img_Iface_Data_Cvt_Color *data_cast; - char title [80]; - - /* Must have at least 3 channels */ - if (image_copy_tmp.channels() < 3) { - /* 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; - } - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Method: BGR2GRAY = 6, BGR2HSV = 40"); - data_tmp.method = user_iface_getint(0, 0, - cv::COLOR_COLORCVT_MAX, - title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Cvt_Color *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Convert color %i", - data_cast->method); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Filter: BGR to gray */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_CVT_COLOR, data); -} - -static void img_iface_distance_transform (void) -{ - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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, - "Distance transform"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Distance transform */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_DISTANCE_TRANSFORM, NULL); -} - -static void img_iface_threshold (const void *data) -{ - struct Img_Iface_Data_Threshold data_tmp; - const struct Img_Iface_Data_Threshold *data_cast; - char title [80]; - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Type: BIN=0, BIN_INV=1, TRUNC=2, TOZ=3, TOZ_INV=4"); - data_tmp.thr_typ = user_iface_getint(0, 0, 4, title, NULL); - - snprintf(title, 80, "Value: 0 to 255 (or -1 for Otsu's algorithm)"); - data_tmp.thr_val = user_iface_getint(-1, 0, 255, title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Threshold *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Threshold typ=%i, val=%i", - data_cast->thr_typ, - data_cast->thr_val); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Filter: threshold */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_THRESHOLD, data); -} - -/* ----- ------- Histograms */ -static void img_iface_histogram (const void *data) -{ - struct Img_Iface_Data_Histogram data_tmp; - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - if (!data) { - data_tmp.hist_c0 = &histogram_c0; - data_tmp.hist_img = &hist_img_c1; - - data = (const void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Histogram"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Histogram */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_HISTOGRAM, data); -} - -static void img_iface_histogram_c3 (const void *data) -{ - struct Img_Iface_Data_Histogram data_tmp; - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 3) { - /* 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; - } - - /* Data */ - if (!data) { - data_tmp.hist_c0 = &histogram_c0; - data_tmp.hist_c1 = &histogram_c1; - data_tmp.hist_c2 = &histogram_c2; - data_tmp.hist_img = &hist_img_c3; - - data = (const void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Histogram (3 channels)"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Histogram */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_HISTOGRAM_C3, data); -} - -/* ----- ------- Structural analysis and shape descriptors */ -static void img_iface_contours (const void *data) -{ - struct Img_Iface_Data_Contours data_tmp; - const struct Img_Iface_Data_Contours *data_cast; - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - if (!data) { - data_tmp.contours = &contours; - data_tmp.hierarchy = &hierarchy; - - data = (const void *)&data_tmp; - } - - /* Contours */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_CONTOURS, data); - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Contours *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Contours n=%i", - (int)data_cast->contours->size()); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_contours_size (const void *data) -{ - struct Img_Iface_Data_Contours_Size data_tmp; - const struct Img_Iface_Data_Contours_Size *data_cast; - unsigned i; - - /* Data */ - if (!data) { - data_tmp.contours = &contours; - data_tmp.area = area; - data_tmp.perimeter = perimeter; - - data = (const void *)&data_tmp; - } - - /* Contours size */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_CONTOURS_SIZE, data); - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Contours_Size *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Contours size:"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - for (i = 0; i < data_cast->contours->size(); i++) { - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "cnt[%i]: A=%lf; P=%lf;", - i, - data_cast->area[i], - data_cast->perimeter[i]); - user_iface_log.lvl[user_iface_log.len] = 2; - (user_iface_log.len)++; - } -} - -static void img_iface_bounding_rect (const void *data) -{ - struct Img_Iface_Data_Bounding_Rect data_tmp; - - if (!data) { - if(!contours.size()) { - /* 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; - } - data_tmp.contour = &(contours[0]); - data_tmp.rect = &rectangle; - data_tmp.show = true; - - data = (const void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Bounding rectangle"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Enclosing rectangle */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_BOUNDING_RECT, data); -} - -static void img_iface_fit_ellipse (const void *data) -{ - struct Img_Iface_Data_MinARect data_tmp; - - if (!data) { - if(!contours.size()) { - /* 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; - } - data_tmp.contour = &(contours[0]); - - data_tmp.rect = &rectangle_rot; - - data = (const void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Fit ellipse"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Enclosing rectangle */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_FIT_ELLIPSE, data); -} - -static void img_iface_min_area_rect (const void *data) -{ - struct Img_Iface_Data_MinARect data_tmp; - - if (!data) { - if(!contours.size()) { - /* 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; - } - data_tmp.contour = &(contours[0]); - data_tmp.rect = &rectangle_rot; - data_tmp.show = true; - - data = (const void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Min area rectangle"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Enclosing rectangle */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_MIN_AREA_RECT, data); -} - -/* ----- ------- Feature detection */ -static void img_iface_hough_circles (const void *data) -{ - struct Img_Iface_Data_Hough_Circles data_tmp; - const struct Img_Iface_Data_Hough_Circles *data_cast; - char title [80]; - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - if (!data) { - data_tmp.circles = &circles; - - /* Ask user */ - snprintf(title, 80, "Minimum distance:"); - data_tmp.dist_min = user_iface_getdbl(0, 5, INFINITY, title, NULL); - - snprintf(title, 80, "param 1:"); - data_tmp.param_1 = user_iface_getdbl(0, 200, INFINITY, title, NULL); - - snprintf(title, 80, "param 2:"); - data_tmp.param_2 = user_iface_getdbl(0, 100, INFINITY, title, NULL); - - snprintf(title, 80, "Minimum radius"); - data_tmp.radius_min = user_iface_getint(0, 10, INFINITY, title, NULL); - - snprintf(title, 80, "Maximum radius"); - data_tmp.radius_max = user_iface_getint(0, 0, INFINITY, title, NULL); - - data = (const void *)&data_tmp; - } - - /* Circles */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_HOUGH_CIRCLES, data); - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Hough_Circles *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Circles n=%i", - (int)data_cast->circles->size()); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -/* img_orb -------------------------------------------------------------------*/ -static void img_iface_align (void) -{ - /* Must have defined a reference */ - if (image_ref.empty()) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Reference is NULL"); - 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, - "Align to reference"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Align to reference image_ref */ - img_orb_act(&image_ref, &image_copy_tmp, IMG_ORB_ACT_ALIGN); -} - -/* img_calib3d ---------------------------------------------------------------*/ -static void img_iface_calibrate (const void *data) -{ - struct Img_Iface_Data_Calibrate data_tmp; - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - if (!data) { - data_tmp.intrinsic_mat = &intrinsic_mat; - data_tmp.dist_coefs = &dist_coefs; - data_tmp.rvecs = &rvecs; - data_tmp.tvecs = &tvecs; - - data = (const void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Calibrate"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Contours */ - img_calib3d_act(&image_copy_tmp, IMG_CALIB3D_ACT_CALIBRATE, data); -} - -static void img_iface_undistort (const void *data) -{ - struct Img_Iface_Data_Undistort data_tmp; - - /* Data */ - if (!data) { - data_tmp.intrinsic_mat = &intrinsic_mat; - data_tmp.dist_coefs = &dist_coefs; - - data = (const void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Undistort"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Contours */ - img_calib3d_act(&image_copy_tmp, IMG_CALIB3D_ACT_UNDISTORT, data); -} - -/* img_zbar ------------------------------------------------------------------*/ -static void img_iface_decode (const void *data) -{ - struct Img_Iface_Data_Decode data_tmp; - const struct Img_Iface_Data_Decode *data_cast; - char title [80]; - int i; - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Type of code: (0 for all)"); - data_tmp.code_type = (enum zbar::zbar_symbol_type_e) - user_iface_getint(0, 0, INT_MAX, - title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Decode *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Detect codes c=%i", - data_cast->code_type); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Decode */ - img_zb_act(&image_copy_tmp, IMG_ZB_ACT_DECODE, data); - - /* Results */ - if (!zb_codes.n) { - /* No text found */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! No code detected"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - } else { - /* Write results into log */ - for (i = 0; i < zb_codes.n; i++) { - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "%s -- '%s'", - zb_codes.arr[i].sym_name, - zb_codes.arr[i].data); - user_iface_log.lvl[user_iface_log.len] = 2; - (user_iface_log.len)++; - } - } -} - -/* img_ocr -------------------------------------------------------------------*/ -static void img_iface_read (const void *data) -{ - struct Img_Iface_Data_Read data_tmp; - const struct Img_Iface_Data_Read *data_cast; - char title [80]; - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* 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; - } - - data_cast = (const struct Img_Iface_Data_Read *)data; - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Language: ENG = 0, SPA = 1, CAT = 2"); - data_tmp.lang = user_iface_getint(0, 1, 2, title, NULL); - - snprintf(title, 80, "Config: none = 0, Price = 1"); - data_tmp.conf = user_iface_getint(0, 1, 2, title, NULL); - } else { - data_tmp.lang = data_cast->lang; - data_tmp.conf = data_cast->conf; - } - - /* Adapt image data */ - data_tmp.img.data = image_copy_tmp.data; - data_tmp.img.width = image_copy_tmp.size().width; - data_tmp.img.height = image_copy_tmp.size().height; - data_tmp.img.B_per_pix = image_copy_tmp.channels(); - data_tmp.img.B_per_line = image_copy_tmp.step1(); - - data = (const void *)&data_tmp; - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "OCR (lang=%i) [c=%i]", - data_cast->lang, - data_cast->conf); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* OCR */ - img_ocr_act(IMG_OCR_ACT_READ, data); - - /* Results */ - if (img_ocr_text[0] == '\0') { - /* No text found */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! No text detected"); - user_iface_log.lvl[user_iface_log.len] = 2; - (user_iface_log.len)++; - } -} - -/* img_iface -----------------------------------------------------------------*/ -static void img_iface_apply (void) -{ - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Apply changes"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Write tmp into old */ - image_copy_old.release(); - image_copy_tmp.copyTo(image_copy_old); -} - -static void img_iface_discard (void) -{ - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Discard changes"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Discard tmp image copy */ - image_copy_tmp.release(); - image_copy_old.copyTo(image_copy_tmp); -} - -static void img_iface_save_mem (const void *data) -{ - int x; - char title [80]; - - /* Which memory to use */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "mem_X; X:"); - x = user_iface_getint(0, 0, IMG_MEM_SIZE - 1, title, NULL); - } else { - x = *(const int *)data; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Save to mem_%i", x); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Write into mem */ - image_mem[x].release(); - image_copy_tmp.copyTo(image_mem[x]); -} - -static void img_iface_load_mem (const void *data) -{ - int x; - char title [80]; - - /* Which memory to use */ - if (!data) { - /* Ask user which memory to use */ - snprintf(title, 80, "mem_X; X:"); - x = user_iface_getint(0, 0, IMG_MEM_SIZE - 1, title, NULL); - } else { - x = *(const int *)data; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Load from mem_%i", x); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - if (!image_mem[x].empty()) { - /* Discard tmp image copy */ - image_copy_tmp.release(); - - /* Load from mem */ - image_mem[x].copyTo(image_copy_tmp); - } -} - -static void img_iface_save_ref (void) -{ - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Save to reference"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Write into ref */ - image_ref.release(); - image_copy_tmp.copyTo(image_ref); -} - -/* save ----------------------------------------------------------------------*/ -static void img_iface_save_file (void) -{ - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Save as..."); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Write into image struct (save.c) */ - image.release(); - image_copy_tmp.copyTo(image); - - /* Save into file */ - save_image_file(NULL, NULL); -} - -static void img_iface_save_update (void) -{ - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Save: update img"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Write into image struct (save.c) */ - image.release(); - image_copy_tmp.copyTo(image); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/image/src/img_ocr.c b/modules/image/src/img_ocr.c deleted file mode 100644 index 6c92250..0000000 --- a/modules/image/src/img_ocr.c +++ /dev/null @@ -1,127 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <limits.h> - #include <stddef.h> - #include <stdio.h> -/* Packages ------------------------------------------------------------------*/ - #include <tesseract/capi.h> -/* Project -------------------------------------------------------------------*/ - /* share_path */ - #include "about.h" -/* Module --------------------------------------------------------------------*/ - #include "img_iface.h" - - #include "img_ocr.h" - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void img_ocr_read (const void *data); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void img_ocr_act (int action, const void *data) -{ - switch (action) { - case IMG_OCR_ACT_READ: - img_ocr_read(data); - break; - } -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void img_ocr_read (const void *data) -{ - const struct Img_Iface_Data_Read *data_cast; - struct TessBaseAPI *handle_ocr; - int lang; - char lang_str [20 + 1]; - int conf; - char conf_str [FILENAME_MAX]; - char *txt; - - /* Data */ - data_cast = (const struct Img_Iface_Data_Read *)data; - - /* Language */ - lang = data_cast->lang; - switch (lang) { - case IMG_IFACE_OCR_LANG_ENG: - sprintf(lang_str, "eng"); - break; - case IMG_IFACE_OCR_LANG_SPA: - sprintf(lang_str, "spa"); - break; - case IMG_IFACE_OCR_LANG_CAT: - sprintf(lang_str, "cat"); - break; - case IMG_IFACE_OCR_LANG_DIGITS: - sprintf(lang_str, "digits"); - break; - case IMG_IFACE_OCR_LANG_DIGITS_COMMA: - sprintf(lang_str, "digits_comma"); - break; - } - - /* Config file */ - conf = data_cast->conf; - switch (conf) { - case IMG_IFACE_OCR_CONF_PRICE: - if (snprintf(conf_str, FILENAME_MAX, "%s/%s", - share_path, - "price") >= FILENAME_MAX) { - printf("Path is too large and has been truncated\n"); - printf("Price configuration was not possible!\n"); - conf = IMG_IFACE_OCR_CONF_NONE; - } - break; - } - - /* init OCR */ - handle_ocr = TessBaseAPICreate(); -#ifdef OEM_LSTM_ONLY - TessBaseAPIInit2(handle_ocr, NULL, lang_str, OEM_LSTM_ONLY); -#else - TessBaseAPIInit2(handle_ocr, NULL, lang_str, OEM_DEFAULT); -#endif -/* TessBaseAPIInit2(handle_ocr, NULL, lang_str, OEM_TESSERACT_LSTM_COMBINED);*/ - if (conf) { - /* Configure OCR (whitelist chars) */ - TessBaseAPIReadConfigFile(handle_ocr, conf_str); - } - - /* scan image for text */ - TessBaseAPISetImage(handle_ocr, data_cast->img.data, - data_cast->img.width, data_cast->img.height, - data_cast->img.B_per_pix, - data_cast->img.B_per_line); - TessBaseAPIRecognize(handle_ocr, NULL); - txt = TessBaseAPIGetUTF8Text(handle_ocr); - - /* Copy text to global variable */ - snprintf(img_ocr_text, OCR_TEXT_MAX, "%s", txt); - - /* cleanup */ - TessDeleteText(txt); - TessBaseAPIEnd(handle_ocr); - TessBaseAPIDelete(handle_ocr); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/image/src/img_orb.cpp b/modules/image/src/img_orb.cpp deleted file mode 100644 index 5c716b1..0000000 --- a/modules/image/src/img_orb.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C++ --------------------------------------------------------------*/ - #include <vector> -/* Standard C ----------------------------------------------------------------*/ - #include <cstdio> -/* Packages ------------------------------------------------------------------*/ - #include <opencv2/opencv.hpp> - #include <opencv2/features2d/features2d.hpp> -/* Module -------------------------------------------------------------------*/ - #include "img_orb.hpp" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define MAX_FEATURES (50000) - # define GOOD_MATCH_P (0.25) - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void img_orb_align (const class cv::Mat *img_0, - class cv::Mat *img_1); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void img_orb_act (const class cv::Mat *img_ref, - class cv::Mat *imgptr, int action) -{ - switch (action) { - case IMG_ORB_ACT_ALIGN: - img_orb_align(img_ref, imgptr); - break; - } -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void img_orb_align (const class cv::Mat *img_0, - class cv::Mat *img_1) -{ - /* Variables to store keypoints & descriptors */ - class std::vector <class cv::KeyPoint> keypoints_0; - class std::vector <class cv::KeyPoint> keypoints_1; - class cv::Mat descriptors_0; - class cv::Mat descriptors_1; - - /* Detect ORB features & compute descriptors */ -#if 1 - /* OpenCV 2.x */ - class cv::ORB orb; - orb(*img_0, cv::Mat(), keypoints_0, descriptors_0); - orb(*img_1, cv::Mat(), keypoints_1, descriptors_1); -#else - /* OpenCV 3.x */ - class cv::Ptr <class cv::Feature2D> orb; - orb = cv::ORB::create(MAX_FEATURES); - orb->detectAndCompute(*img_0, cv::Mat(), keypoints_0, descriptors_0); - orb->detectAndCompute(*img_1, cv::Mat(), keypoints_1, descriptors_1); -#endif - - - /* Match structures */ - class std::vector <struct cv::DMatch> matches; - cv::Ptr <class cv::DescriptorMatcher> matcher; - matcher = cv::DescriptorMatcher::create("BruteForce-Hamming"); - matcher->match(descriptors_1, descriptors_0, matches, cv::Mat()); - - /* Sort matches by score */ - std::sort(matches.begin(), matches.end()); - - /* Remove not so good matches */ - int good_matches; - good_matches = GOOD_MATCH_P * matches.size(); - matches.erase(matches.begin() + good_matches, matches.end()); - - /* Draw top matches */ - class cv::Mat img_matches; - cv::drawMatches(*img_1, keypoints_1, *img_0, keypoints_0, matches, - img_matches); - cv::imwrite("matches.jpg", img_matches); - - /* Extract location of good matches */ - class std::vector <class cv::Point_ <float>> points_0; - class std::vector <class cv::Point_ <float>> points_1; - int i; - for (i = 0; i < (int)matches.size(); i++) { - points_1.push_back(keypoints_1[matches[i].queryIdx].pt); - points_0.push_back(keypoints_0[matches[i].trainIdx].pt); - } - - /* Find homography */ - class cv::Mat img_hg; - img_hg = cv::findHomography(points_1, points_0, CV_RANSAC); - - /* Use homography to warp image */ - class cv::Mat img_align; - cv::warpPerspective(*img_1, img_align, img_hg, img_0->size()); - - /* Write img_align into img_1 */ - *img_1 = img_align; - img_align.release(); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/image/src/img_zbar.cpp b/modules/image/src/img_zbar.cpp deleted file mode 100644 index 952abe0..0000000 --- a/modules/image/src/img_zbar.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <climits> - #include <cstddef> - #include <cstdio> -/* Packages ------------------------------------------------------------------*/ - #include <opencv2/opencv.hpp> - #include <zbar.h> -/* Module --------------------------------------------------------------------*/ - #include "img_iface.hpp" - - #include "img_zbar.hpp" - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void img_zb_decode (class cv::Mat *imgptr, const void *data); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void img_zb_act (class cv::Mat *imgptr, int action, const void *data) -{ - switch (action) { - case IMG_ZB_ACT_DECODE: - img_zb_decode(imgptr, data); - break; - } -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void img_zb_decode (class cv::Mat *imgptr, const void *data) -{ - struct zbar::zbar_image_scanner_s *scanner; - struct zbar::zbar_image_s *image_zb; - const struct zbar::zbar_symbol_s *symbol; - enum zbar::zbar_symbol_type_e code_type; - int i; - - /* Type of code to scan */ - code_type = ((const struct Img_Iface_Data_Decode *)data)->code_type; - - /* create & configure a reader */ - scanner = zbar::zbar_image_scanner_create(); - zbar::zbar_image_scanner_set_config(scanner, code_type, - zbar::ZBAR_CFG_ENABLE, 1); - - /* wrap image data */ - image_zb = zbar::zbar_image_create(); - zbar::zbar_image_set_format(image_zb, *(int*)"GREY"); - zbar::zbar_image_set_size(image_zb, imgptr->cols, imgptr->rows); - zbar::zbar_image_set_data(image_zb, (void *)(imgptr->data), - (imgptr->cols * imgptr->rows), - NULL); - - /* scan the image for barcodes */ - zb_codes.n = zbar::zbar_scan_image(scanner, image_zb); - if (zb_codes.n) { - /* extract results */ - symbol = zbar::zbar_image_first_symbol(image_zb); - for (i = 0; i < ZB_CODES_MAX && symbol; i++) { - /* Write results into array */ - zb_codes.arr[i].type = zbar::zbar_symbol_get_type(symbol); - snprintf(zb_codes.arr[i].sym_name, 80, "%s", - zbar::zbar_get_symbol_name( - zb_codes.arr[i].type)); - snprintf(zb_codes.arr[i].data, ZBAR_LEN_MAX, "%s", - zbar::zbar_symbol_get_data(symbol)); - - /* Load next symbol */ - symbol = zbar::zbar_symbol_next(symbol); - } - } - - /* clean up */ - zbar::zbar_image_destroy(image_zb); - zbar::zbar_image_scanner_destroy(scanner); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/image/tmp/Makefile b/modules/image/tmp/Makefile deleted file mode 100644 index 2890fb6..0000000 --- a/modules/image/tmp/Makefile +++ /dev/null @@ -1,149 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -LIBALX_INC_DIR = $(LIBALX_DIR)/inc/ - -ABOUT_INC_DIR = $(ABOUT_DIR)/inc/ -SAVE_INC_DIR = $(SAVE_DIR)/inc/ -USR_INC_DIR = $(USR_DIR)/inc/ - -INC_DIR = $(IMG_DIR)/inc/ -SRC_DIR = $(IMG_DIR)/src/ - -# dependencies - -_ALL = img_alx.o img_cv.o img_orb.o img_calib3d.o \ - img_zbar.o img_ocr.o img_iface.o -ALL = $(_ALL) img_mod.o - -IMGALX_INC_LIBALX = libalx/alx_math.hpp -IMGALX_INC = img_alx.hpp img_iface.hpp -IMGALX_DEPS = $(SRC_DIR)/img_alx.cpp \ - $(patsubst %,$(INC_DIR)/%,$(IMGALX_INC)) \ - $(patsubst %,$(LIBALX_INC_DIR)/%,$(IMGALX_INC_LIBALX)) -IMGALX_INC_DIRS = -I $(INC_DIR) \ - -I $(LIBALX_INC_DIR) - -IMGCV_INC = img_cv.hpp img_iface.hpp -IMGCV_DEPS = $(SRC_DIR)/img_cv.cpp \ - $(patsubst %,$(INC_DIR)/%,$(IMGCV_INC)) -IMGCV_INC_DIRS = -I $(INC_DIR) - -IMGORB_INC = img_orb.hpp img_iface.hpp -IMGORB_DEPS = $(SRC_DIR)/img_orb.cpp \ - $(patsubst %,$(INC_DIR)/%,$(IMGORB_INC)) -IMGORB_INC_DIRS = -I $(INC_DIR) - -IMGC3D_INC = img_calib3d.hpp img_iface.hpp -IMGC3D_DEPS = $(SRC_DIR)/img_calib3d.cpp \ - $(patsubst %,$(INC_DIR)/%,$(IMGC3D_INC)) -IMGC3D_INC_DIRS = -I $(INC_DIR) - -IMGZB_INC = img_zbar.hpp img_iface.hpp -IMGZB_DEPS = $(SRC_DIR)/img_zbar.cpp \ - $(patsubst %,$(INC_DIR)/%,$(IMGZB_INC)) -IMGZB_INC_DIRS = -I $(INC_DIR) - -IMGOCR_INC_ABOUT = about.h -IMGOCR_INC = img_ocr.h img_iface.h -IMGOCR_DEPS = $(SRC_DIR)/img_ocr.c \ - $(patsubst %,$(INC_DIR)/%,$(IMGOCR_INC)) \ - $(patsubst %,$(ABOUT_INC_DIR)/%,$(IMGOCR_INC_ABOUT)) -IMGOCR_INC_DIRS = -I $(INC_DIR) \ - -I $(ABOUT_INC_DIR) - -IMGI_INC_SAVE = save.hpp -IMGI_INC_USR = user_iface.hpp -IMGI_INC = img_iface.hpp img_alx.hpp img_calib3d.hpp img_cv.hpp \ - img_zbar.hpp img_ocr.hpp img_orb.hpp -IMGI_DEPS = $(SRC_DIR)/img_iface.cpp \ - $(patsubst %,$(INC_DIR)/%,$(IMGI_INC)) \ - $(patsubst %,$(SAVE_INC_DIR)/%,$(IMGI_INC_SAVE)) \ - $(patsubst %,$(USR_INC_DIR)/%,$(IMGI_INC_USR)) -IMGI_INC_DIRS = -I $(INC_DIR) \ - -I $(SAVE_INC_DIR) \ - -I $(USR_INC_DIR) - -# target: dependencies -# action - -PHONY := all -all: $(ALL) - - -img_mod.o: $(_ALL) - $(Q)$(LD) -r $^ -o $@ - @echo " LD $@" - - -img_alx.s: $(IMGALX_DEPS) - @echo " CXX $@" - $(Q)$(CXX) $(CXXFLAGS) $(IMGALX_INC_DIRS) -S $< -o $@ -img_alx.o: img_alx.s - @echo " AS $@" - $(Q)$(AS) $< -o $@ - -img_cv.s: $(IMGCV_DEPS) - @echo " CXX $@" - $(Q)$(CXX) $(CXXFLAGS) $(IMGCV_INC_DIRS) -S $< -o $@ -img_cv.o: img_cv.s - @echo " AS $@" - $(Q)$(AS) $< -o $@ - -img_orb.s: $(IMGORB_DEPS) - @echo " CXX $@" - $(Q)$(CXX) $(CXXFLAGS) $(IMGORB_INC_DIRS) -S $< -o $@ -img_orb.o: img_orb.s - @echo " AS $@" - $(Q)$(AS) $< -o $@ - -img_calib3d.s: $(IMGC3D_DEPS) - @echo " CXX $@" - $(Q)$(CXX) $(CXXFLAGS) $(IMGC3D_INC_DIRS) -S $< -o $@ -img_calib3d.o: img_calib3d.s - @echo " AS $@" - $(Q)$(AS) $< -o $@ - -img_zbar.s: $(IMGZB_DEPS) - @echo " CXX $@" - $(Q)$(CXX) $(CXXFLAGS) $(IMGZB_INC_DIRS) -S $< -o $@ -img_zbar.o: img_zbar.s - @echo " AS $@" - $(Q)$(AS) $< -o $@ - -img_ocr.s: $(IMGOCR_DEPS) - @echo " CC $@" - $(Q)$(CC) $(CFLAGS) $(IMGOCR_INC_DIRS) -S $< -o $@ -img_ocr.o: img_ocr.s - @echo " AS $@" - $(Q)$(AS) $< -o $@ - -img_iface.s: $(IMGI_DEPS) - @echo " CXX $@" - $(Q)$(CXX) $(CXXFLAGS) $(IMGI_INC_DIRS) -S $< -o $@ -img_iface.o: img_iface.s - @echo " AS $@" - $(Q)$(AS) $< -o $@ - - -PHONY += clean -clean: - $(Q)rm -f *.o *.s - -################################################################################ -# Declare the contents of the .PHONY variable as phony. -.PHONY: $(PHONY) - - - - -################################################################################ -######## End of file ########################################################### -################################################################################ - -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/modules/menu/Makefile b/modules/menu/Makefile deleted file mode 100644 index 48ed965..0000000 --- a/modules/menu/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -TMP_DIR = $(MENU_DIR)/tmp/ - -# target: dependencies -# action - -all: - $(Q)cd $(TMP_DIR) && $(MAKE) && cd .. - -clean: - $(Q)cd $(TMP_DIR) && $(MAKE) clean && cd .. - -################################################################################ -######## End of file ########################################################### -################################################################################ -######## End of file ########################################################### -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/modules/menu/inc/menu_clui.h b/modules/menu/inc/menu_clui.h deleted file mode 100644 index a915645..0000000 --- a/modules/menu/inc/menu_clui.h +++ /dev/null @@ -1,28 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_MENU_CLUI_H - # define VA_MENU_CLUI_H - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void menu_clui (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* menu_clui.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/menu/inc/menu_iface.h b/modules/menu/inc/menu_iface.h deleted file mode 100644 index 1b76e0b..0000000 --- a/modules/menu/inc/menu_iface.h +++ /dev/null @@ -1,44 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_MENU_IFACE_H - # define VA_MENU_IFACE_H - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Menu_Iface_Mode { - MENU_IFACE_FOO = 0, - MENU_IFACE_CLUI, - MENU_IFACE_TUI - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern int menu_iface_mode; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void menu_iface (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* menu_iface.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/menu/inc/menu_iface.hpp b/modules/menu/inc/menu_iface.hpp deleted file mode 100644 index 6128711..0000000 --- a/modules/menu/inc/menu_iface.hpp +++ /dev/null @@ -1,56 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_MENU_IFACE_HPP - # define VA_MENU_IFACE_HPP - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Menu_Iface_Mode { - MENU_IFACE_FOO = 0, - MENU_IFACE_CLUI, - MENU_IFACE_TUI - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern int menu_iface_mode; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void menu_iface (void); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* menu_iface.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/menu/inc/menu_tui.h b/modules/menu/inc/menu_tui.h deleted file mode 100644 index 0f8e442..0000000 --- a/modules/menu/inc/menu_tui.h +++ /dev/null @@ -1,28 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_MENU_TUI_H - # define VA_MENU_TUI_H - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void menu_tui (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* menu_tui.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/menu/inc/parser.h b/modules/menu/inc/parser.h deleted file mode 100644 index 3843017..0000000 --- a/modules/menu/inc/parser.h +++ /dev/null @@ -1,28 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PARSER_H - # define VA_PARSER_H - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void parser (int argc, char *argv[]); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* parser.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/menu/inc/parser.hpp b/modules/menu/inc/parser.hpp deleted file mode 100644 index e40bbd3..0000000 --- a/modules/menu/inc/parser.hpp +++ /dev/null @@ -1,40 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PARSER_HPP - # define VA_PARSER_HPP - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void parser (int argc, char *argv[]); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* parser.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/menu/src/menu_clui.c b/modules/menu/src/menu_clui.c deleted file mode 100644 index 964d176..0000000 --- a/modules/menu/src/menu_clui.c +++ /dev/null @@ -1,125 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - #include "libalx/io/alx_input.h" - - #include "about.h" -// #include "save.h" - #include "start.h" - - #include "menu_clui.h" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define BUFF_SIZE (1024) - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -//static void menu_clui_rand (void); -//static void menu_clui_custom (void); -static void menu_clui_load (void); -static void menu_clui_start (void); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void menu_clui (void) -{ - char buff [BUFF_SIZE]; - char c; - - c = 'n'; - printf("Read 'Disclaimer of warranty'? (yes/NO): "); - if (!fgets(buff, BUFF_SIZE, stdin)) - return; - if (sscanf(buff, " %c", &c) != 1) - return; - if (c == 'y' || c == 'Y') { - printf(" >yes\n"); - print_share_file(SHARE_DISCLAIMER); - } else { - printf(" >NO\n"); - } - - c = 'n'; - printf("Read 'License'? (yes/NO): "); - if (!fgets(buff, BUFF_SIZE, stdin)) - return; - if (sscanf(buff, " %c", &c) != 1) - return; - if (c == 'y' || c == 'Y') { - printf(" >yes\n"); - print_share_file(SHARE_LICENSE); - } else { - printf(" >NO\n"); - } -#if 0 - printf("Game interface? (NCURSES/text): "); - if (!fgets(buff, BUFF_SIZE, stdin)) - return; - if (sscanf(buff, " %c", &c) != 1) - return; - if (c == 't' || c == 'T') { - printf(" >text\n"); - // FIXME - } else { - printf(" >NCURSES\n"); - // FIXME - } -#endif - menu_clui_load(); -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void menu_clui_load (void) -{ -#if 0 - /* File name */ /* FIXME */ - alx_w_getfname(USER_SAVED_DIR, saved_name, "File name:", saved_name, NULL); -#endif - menu_clui_start(); -} - -static void menu_clui_start (void) -{ - printf(" >>START:\n"); - start_switch(); - - char buff [BUFF_SIZE]; - char c; - - c = 'm'; - printf("Load again? (MENU/load/exit): "); - if (!fgets(buff, BUFF_SIZE, stdin)) - return; - if (sscanf(buff, " %c", &c) != 1) - return; - if (c == 'p' || c == 'P') { - printf(" >load\n"); - menu_clui_start(); - } else if (c == 'e' || c == 'E') { - printf(" >exit!\n"); - } else { - printf(" >MENU\n"); - menu_clui(); - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/menu/src/menu_iface.c b/modules/menu/src/menu_iface.c deleted file mode 100644 index a09a463..0000000 --- a/modules/menu/src/menu_iface.c +++ /dev/null @@ -1,44 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - #include "menu_clui.h" - #include "menu_tui.h" - - #include "menu_iface.h" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -int menu_iface_mode; - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void menu_iface (void) -{ - switch (menu_iface_mode) { - case MENU_IFACE_FOO: - break; - - case MENU_IFACE_CLUI: - menu_clui(); - break; - - case MENU_IFACE_TUI: - menu_tui(); - break; - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/menu/src/menu_tui.c b/modules/menu/src/menu_tui.c deleted file mode 100644 index 8a6cb0b..0000000 --- a/modules/menu/src/menu_tui.c +++ /dev/null @@ -1,332 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <ncurses.h> - #include <stdbool.h> - #include <stddef.h> -/* libalx --------------------------------------------------------------------*/ - #include "libalx/curses/alx_ncur.h" -/* Project -------------------------------------------------------------------*/ - #include "about.h" - #include "proc_iface.h" - #include "save.h" - #include "start.h" - #include "user_iface.h" -/* Module --------------------------------------------------------------------*/ - #include "menu_tui.h" - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void menu_tui_continue (void); -static void menu_tui_select (void); -static void menu_tui_series (void); -static void menu_tui_devel (void); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void menu_tui (void) -{ - int h; - int w; - int N; - bool wh; - int sw; - - alx_resume_curses(); - - /* Menu dimensions & options */ - h = 23; - w = 80; - N = 4; - static const struct Alx_Menu mnu[4] = { - {7, 4, "[0] Exit program"}, - {2, 4, "[1] Continue"}, - {4, 4, "[2] Disclaimer of warranty"}, - {5, 4, "[3] Terms and conditions"} - }; - - /* Menu */ - wh = true; - while (wh) { - /* Menu loop */ - sw = alx_menu(h, w, N, mnu, "MENU:"); - - /* Selection */ - switch (sw) { - case 0: - wh = false; - break; - - case 1: - menu_tui_continue(); - break; - - case 2: - alx_pause_curses(); - print_share_file(SHARE_DISCLAIMER); - getchar(); - alx_resume_curses(); - break; - - case 3: - alx_pause_curses(); - print_share_file(SHARE_LICENSE); - getchar(); - alx_resume_curses(); - break; - } - } - - alx_pause_curses(); -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void menu_tui_continue (void) -{ - WINDOW *win; - int h; - int w; - int r; - int c; - int N; - int w2; - int r2; - bool wh; - int sw; - - /* Menu dimensions & options */ - h = 23; - w = 80; - r = 1; - c = (80 - w) / 2; - N = 6; - static const struct Alx_Menu mnu[6] = { - {8, 4, "[0] Back"}, - {2, 4, "[1] Start"}, - {3, 4, "[2] Select"}, - {4, 4, "[3] Series"}, - {5, 4, "[4] Change file name"}, - {6, 4, "[5] DEVEL"} - }; - - /* Input box */ - w2 = w - 8; - r2 = r + h - 5; - static const char *const txt[] = {"File name:"}; - - /* Menu */ - wh = true; - while (wh) { - /* Menu loop */ - win = newwin(h, w, r, c); - mvwprintw(win, mnu[1].r, mnu[1].c, "%s (File: \"%s\")", - mnu[1].t, saved_name); - wrefresh(win); - sw = alx_menu_2(win, N, mnu, "CONTINUE:"); - - /* Selection */ - switch (sw) { - case 0: - wh = false; - break; - - case 1: - alx_win_del(win); - alx_pause_curses(); - start_switch(); - alx_resume_curses(); - break; - - case 2: - alx_win_del(win); - menu_tui_select(); - break; - - case 3: - alx_win_del(win); - menu_tui_series(); - break; - - case 4: - save_clr(); - alx_w_getfname(saved_path, saved_name, true, w2, r2, - txt[0], NULL); - alx_win_del(win); - break; - - case 5: - alx_win_del(win); - menu_tui_devel(); - break; - } - } - - /* Cleanup */ - alx_win_del(win); -} - -static void menu_tui_select (void) -{ - int h; - int w; - int N; - int sw; - - /* Menu dimensions & options */ - h = 23; - w = 80; - N = 3; - static const struct Alx_Menu mnu[3] = { - {6, 4, "[0] Back"}, - {2, 4, "[1] Single image"}, - {4, 4, "[2] Series"} - }; - - /* Menu loop */ - sw = alx_menu(h, w, N, mnu, "SELECT MODE:"); - - /* Selection */ - switch (sw) { - case 1: - start_mode = START_SINGLE; - break; - - case 2: - start_mode = START_SERIES; - break; - } - -} - -static void menu_tui_series (void) -{ - int h; - int w; - int N; - int sw; - - /* Menu dimensions & options */ - h = 23; - w = 80; - N = 6; - static const struct Alx_Menu mnu[6] = { - {8, 4, "[0] Back"}, - {2, 4, "[1] Label"}, - {3, 4, "[2] Objects"}, - {4, 4, "[3] Coins"}, - {5, 4, "[4] Resistor"}, - {6, 4, "[5] Lighters"} - }; - - /* Menu loop */ - sw = alx_menu(h, w, N, mnu, "SELECT LEVEL:"); - - /* Selection */ - switch (sw) { - case 1: - proc_mode = PROC_MODE_LABEL_SERIES; - break; - case 2: - proc_mode = PROC_MODE_OBJECTS_SERIES; - break; - case 3: - proc_mode = PROC_MODE_COINS_SERIES; - break; - case 4: - proc_mode = PROC_MODE_RESISTOR_SERIES; - break; - case 5: - proc_mode = PROC_MODE_LIGHTERS_SERIES; - break; - } - -} - -static void menu_tui_devel (void) -{ - WINDOW *win; - int h; - int w; - int r; - int c; - int N; - int w2; - int r2; - bool wh; - int sw; - - h = 23; - w = 80; - r = 1; - c = (80 - w) / 2; - N = 4; - static const struct Alx_Menu mnu[4] = { - {6, 4, "[0] Back"}, - {2, 4, "[1] Change process mode"}, - {3, 4, "[2] Change log mode"}, - {4, 4, "[3] Change user iface mode"} - }; - - /* Input box */ - w2 = w - 8; - r2 = r + h - 5; - static const char *const txt[] = { - "Modes: 0=Auto; 1=Stop@prod; 2=Delay@step; 3=Stop@step", - "Modes: 0=Results; 1=Operations; 2=All", - "Modes: 1=CLUI; 2=TUI" - }; - - /* Menu */ - win = newwin(h, w, r, c); - - /* Menu loop */ - wh = true; - while (wh) { - /* Selection */ - sw = alx_menu_2(win, N, mnu, "DEVELOPER OPTIONS:"); - - switch (sw) { - case 0: - wh = false; - break; - - case 1: - proc_debug = alx_w_getint(w2, r2, txt[0], - PROC_DBG_NO, 0, - PROC_DBG_STOP_STEP, NULL); - break; - - case 2: - user_iface_log.visible = alx_w_getint(w2, r2, txt[1], - 0, 2, 2, NULL); - break; - - case 3: - user_iface_mode = alx_w_getint(w2, r2, txt[2], - 1, 2, 2, NULL); - break; - } - } - - /* Cleanup */ - alx_win_del(win); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/menu/src/parser.c b/modules/menu/src/parser.c deleted file mode 100644 index acce385..0000000 --- a/modules/menu/src/parser.c +++ /dev/null @@ -1,137 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <getopt.h> - #include <stdio.h> - #include <stdlib.h> -/* Project -------------------------------------------------------------------*/ - #include "about.h" - #include "user_iface.h" - #include "save.h" -/* Module --------------------------------------------------------------------*/ - #include "menu_iface.h" - - #include "parser.h" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define OPT_LIST "hLuv""f:i:" - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void parse_file (char *argument); -static void parse_iface (char *argument); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void parser (int argc, char *argv[]) -{ - int opt = 0; - int opt_index = 0; - - const struct option long_options[] = { - /* Standard */ - {"help", no_argument, 0, 'h'}, - {"license", no_argument, 0, 'L'}, - {"usage", no_argument, 0, 'u'}, - {"version", no_argument, 0, 'v'}, - /* Non-standard */ - {"file", required_argument, 0, 'f'}, - {"iface", required_argument, 0, 'i'}, - /* Null */ - {0, 0, 0, 0} - }; - - while ((opt = getopt_long(argc, argv, OPT_LIST, long_options, - &opt_index)) != -1) { - - switch (opt) { - /* Standard */ - case 'h': - print_share_file(SHARE_HELP); - exit(EXIT_SUCCESS); - - case 'L': - print_share_file(SHARE_LICENSE); - exit(EXIT_SUCCESS); - - case 'u': - print_share_file(SHARE_USAGE); - exit(EXIT_SUCCESS); - - case 'v': - print_version(); - exit(EXIT_SUCCESS); - - /* Non-standard */ - case 'f': - parse_file(optarg); - break; - - case 'i': - parse_iface(optarg); - break; - - case '?': - /* getopt_long already printed an error message. */ - - default: - print_share_file(SHARE_USAGE); - exit(EXIT_FAILURE); - } - } -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void parse_file (char *argument) -{ - FILE *fp; - - /* FIXME */ - fp = fopen(argument, "r"); - if (!fp) { - printf("--file argument not valid\n"); - printf("It must be a valid file name (relative to saved dir)\n"); - exit(EXIT_FAILURE); - } else { - fclose(fp); - - saved_path[0] = '\0'; - snprintf(saved_name, FILENAME_MAX, "%s", argument); - } -} - -static void parse_iface (char *argument) -{ - - menu_iface_mode = atoi(argument); - user_iface_mode = menu_iface_mode; - if ((menu_iface_mode < MENU_IFACE_CLUI) || - (menu_iface_mode > MENU_IFACE_TUI)) { - printf("--iface argument not valid\n"); - printf("It must be an integer [%i U %i]\n", - MENU_IFACE_CLUI, MENU_IFACE_TUI); - exit(EXIT_FAILURE); - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/menu/tmp/Makefile b/modules/menu/tmp/Makefile deleted file mode 100644 index cd39b92..0000000 --- a/modules/menu/tmp/Makefile +++ /dev/null @@ -1,123 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -LIBALX_INC_DIR = $(LIBALX_DIR)/inc/ - -ABOUT_INC_DIR = $(ABOUT_DIR)/inc/ -CTRL_INC_DIR = $(CTRL_DIR)/inc/ -PROC_INC_DIR = $(PROC_DIR)/inc/ -SAVE_INC_DIR = $(SAVE_DIR)/inc/ -USR_INC_DIR = $(USR_DIR)/inc/ - -INC_DIR = $(MENU_DIR)/inc/ -SRC_DIR = $(MENU_DIR)/src/ - -# dependencies - -_ALL = parser.o menu_iface.o menu_clui.o menu_tui.o -ALL = $(_ALL) menu_mod.o - -PARS_INC_ABOUT = about.h -PARS_INC_SAVE = save.h -PARS_INC_USR = user_iface.h -PARS_INC = parser.h menu_iface.h -PARS_DEPS = $(SRC_DIR)/parser.c \ - $(patsubst %,$(INC_DIR)/%,$(PARS_INC)) \ - $(patsubst %,$(ABOUT_INC_DIR)/%,$(PARS_INC_ABOUT)) \ - $(patsubst %,$(SAVE_INC_DIR)/%,$(PARS_INC_SAVE)) \ - $(patsubst %,$(USR_INC_DIR)/%,$(PARS_INC_USR)) -PARS_INC_DIRS = -I $(INC_DIR) \ - -I $(ABOUT_INC_DIR) \ - -I $(SAVE_INC_DIR) \ - -I $(USR_INC_DIR) - -MENUI_INC = menu_iface.h menu_clui.h menu_tui.h -MENUI_DEPS = $(SRC_DIR)/menu_iface.c \ - $(patsubst %,$(INC_DIR)/%,$(MENUI_INC)) -MENUI_INC_DIRS = -I $(INC_DIR) - -MENUCLUI_INC_LIBALX = libalx/io/alx_input.h -MENUCLUI_INC_ABOUT = about.h -MENUCLUI_INC_CTRL = start.h -MENUCLUI_INC_SAVE = save.h -MENUCLUI_INC = menu_clui.h -MENUCLUI_DEPS = $(SRC_DIR)/menu_clui.c \ - $(patsubst %,$(INC_DIR)/%,$(MENUCLUI_INC)) \ - $(patsubst %,$(LIBALX_INC_DIR)/%,$(MENUCLUI_INC_LIBALX)) \ - $(patsubst %,$(ABOUT_INC_DIR)/%,$(MENUCLUI_INC_ABOUT)) \ - $(patsubst %,$(CTRL_INC_DIR)/%,$(MENUCLUI_INC_CTRL)) \ - $(patsubst %,$(SAVE_INC_DIR)/%,$(MENUCLUI_INC_SAVE)) -MENUCLUI_INC_DIRS = -I $(INC_DIR) \ - -I $(LIBALX_INC_DIR) \ - -I $(ABOUT_INC_DIR) \ - -I $(CTRL_INC_DIR) \ - -I $(SAVE_INC_DIR) - -MENUTUI_INC_LIBALX = libalx/curses/alx_ncur.h -MENUTUI_INC_ABOUT = about.h -MENUTUI_INC_CTRL = start.h -MENUTUI_INC_PROC = proc_iface.h -MENUTUI_INC_SAVE = save.h -MENUTUI_INC_USR = user_iface.h -MENUTUI_INC = menu_tui.h -MENUTUI_DEPS = $(SRC_DIR)/menu_tui.c \ - $(patsubst %,$(INC_DIR)/%,$(MENUTUI_INC)) \ - $(patsubst %,$(LIBALX_INC_DIR)/%,$(MENUTUI_INC_LIBALX)) \ - $(patsubst %,$(ABOUT_INC_DIR)/%,$(MENUTUI_INC_ABOUT)) \ - $(patsubst %,$(CTRL_INC_DIR)/%,$(MENUTUI_INC_CTRL)) \ - $(patsubst %,$(PROC_INC_DIR)/%,$(MENUTUI_INC_PROC)) \ - $(patsubst %,$(SAVE_INC_DIR)/%,$(MENUTUI_INC_SAVE)) \ - $(patsubst %,$(USR_INC_DIR)/%,$(MENUTUI_INC_USR)) -MENUTUI_INC_DIRS = -I $(INC_DIR) \ - -I $(LIBALX_INC_DIR) \ - -I $(ABOUT_INC_DIR) \ - -I $(CTRL_INC_DIR) \ - -I $(PROC_INC_DIR) \ - -I $(SAVE_INC_DIR) \ - -I $(USR_INC_DIR) - -# target: dependencies -# action - -all: $(ALL) - - -menu_mod.o: $(_ALL) - $(Q)$(LD) -r $^ -o $@ - @echo " LD $@" - - -parser.s: $(PARS_DEPS) - $(Q)$(CC) $(CFLAGS) $(PARS_INC_DIRS) -S $< -o $@ - @echo " CC $@" -parser.o: parser.s - $(Q)$(AS) $< -o $@ - @echo " AS $@" - -menu_iface.s: $(MENUI_DEPS) - $(Q)$(CC) $(CFLAGS) $(MENUI_INC_DIRS) -S $< -o $@ - @echo " CC $@" -menu_iface.o: menu_iface.s - $(Q)$(AS) $< -o $@ - @echo " AS $@" - -menu_clui.s: $(MENUCLUI_DEPS) - $(Q)$(CC) $(CFLAGS) $(MENUCLUI_INC_DIRS) -S $< -o $@ - @echo " CC $@" -menu_clui.o: menu_clui.s - $(Q)$(AS) $< -o $@ - @echo " AS $@" - -menu_tui.s: $(MENUTUI_DEPS) - $(Q)$(CC) $(CFLAGS) $(MENUTUI_INC_DIRS) -S $< -o $@ - @echo " CC $@" -menu_tui.o: menu_tui.s - $(Q)$(AS) $< -o $@ - @echo " AS $@" - - -clean: - $(Q)rm -f *.o *.s diff --git a/modules/proc/Makefile b/modules/proc/Makefile deleted file mode 100644 index ea0eed1..0000000 --- a/modules/proc/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -TMP_DIR = $(PROC_DIR)/tmp/ - -# target: dependencies -# action - -all: - $(Q)cd $(TMP_DIR) && $(MAKE) && cd .. - -clean: - $(Q)cd $(TMP_DIR) && $(MAKE) clean && cd .. - -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/modules/proc/inc/proc_coins.h b/modules/proc/inc/proc_coins.h deleted file mode 100644 index 0052eb2..0000000 --- a/modules/proc/inc/proc_coins.h +++ /dev/null @@ -1,49 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_COINS_H - # define VA_PROC_COINS_H - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Coins { - COINS_OK, - COINS_NOK_COINS, - COINS_NOK_OVERLAP, - COINS_NOK_SIZE - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -int proc_coins (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_coins.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/inc/proc_coins.hpp b/modules/proc/inc/proc_coins.hpp deleted file mode 100644 index f1b0824..0000000 --- a/modules/proc/inc/proc_coins.hpp +++ /dev/null @@ -1,61 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_COINS_HPP - # define VA_PROC_COINS_HPP - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Coins { - COINS_OK, - COINS_NOK_COINS, - COINS_NOK_OVERLAP, - COINS_NOK_SIZE - }; - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -int proc_coins (void); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_coins.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/inc/proc_common.h b/modules/proc/inc/proc_common.h deleted file mode 100644 index 9f84504..0000000 --- a/modules/proc/inc/proc_common.h +++ /dev/null @@ -1,46 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_COMMON_H - # define VA_PROC_COMMON_H - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void proc_show_img (void); - -void clock_start (void); -void clock_stop (const char *txt); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_common.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/inc/proc_common.hpp b/modules/proc/inc/proc_common.hpp deleted file mode 100644 index 4dc8ee1..0000000 --- a/modules/proc/inc/proc_common.hpp +++ /dev/null @@ -1,112 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_COMMON_HPP - # define VA_PROC_COMMON_HPP - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void proc_apply (void); -void proc_save_mem (int n); -void proc_load_mem (int n); -void proc_save_ref (void); -void proc_save_file (void); -void proc_save_update (void); - -void proc_local_max (void); -void proc_skeleton (void); -void proc_lines_vertical (void); -void proc_median_horizontal (void); -void proc_median_vertical (void); - -void proc_pixel_get (int x, int y, unsigned char *val); -void proc_pixel_set (int x, int y, unsigned char val); -void proc_ROI (int x, int y, int w, int h); -void proc_and_2ref (void); -void proc_not (void); -void proc_or_2ref (void); -void proc_cmp (int cmp); -void proc_dilate (int size); -void proc_erode (int size); -void proc_dilate_erode (int size); -void proc_erode_dilate (int size); -void proc_smooth (int method, int ksize); -void proc_border (int size); -void proc_rotate (double center_x, double center_y, double angle); -void proc_adaptive_threshold (int method, int type, int ksize); -void proc_cvt_color (int method); -void proc_distance_transform (void); -void proc_threshold (int type, int ksize); -void proc_contours ( - class std::vector <class std::vector <class cv::Point_ <int>>> *contours, - class cv::Mat *hierarchy); -void proc_contours_size ( - const class std::vector <class std::vector <class cv::Point_ <int>>> *contours, - double *area, - double *perimeter); -void proc_bounding_rect ( - const class std::vector <class cv::Point_ <int>> *contour, - class cv::Rect_ <int> *rect, - bool show); -void proc_fit_ellipse ( - const class std::vector <class cv::Point_ <int>> *contour, - class cv::RotatedRect *rect, - bool show); -void proc_min_area_rect ( - const class std::vector <class cv::Point_ <int>> *contour, - class cv::RotatedRect *rect, - bool show); - -void proc_OCR (int lang, int conf); -void proc_zbar (int type); - -void proc_show_img (void); - -void clock_start (void); -void clock_stop (const char *txt); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_common.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/inc/proc_iface.h b/modules/proc/inc/proc_iface.h deleted file mode 100644 index 1001702..0000000 --- a/modules/proc/inc/proc_iface.h +++ /dev/null @@ -1,73 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_IFACE_H - # define VA_PROC_IFACE_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Mode { - PROC_MODE_FOO, - - PROC_MODE = 0x008000u, - PROC_MODE_LABEL_SERIES, - PROC_MODE_LABEL_CALIB, - PROC_MODE_OBJECTS_SERIES, - PROC_MODE_OBJECTS_CALIB, - PROC_MODE_COINS_SERIES, - PROC_MODE_COINS_CALIB, - PROC_MODE_RESISTOR_SERIES, - PROC_MODE_RESISTOR_CALIB, - PROC_MODE_LIGHTERS_SERIES, - PROC_MODE_LIGHTERS_CALIB - }; - - enum Proc_DBG { - PROC_DBG_NO, - PROC_DBG_STOP_ITEM, - PROC_DBG_DELAY_STEP, - PROC_DBG_STOP_STEP - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern int proc_debug; -extern int proc_mode; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -int proc_iface_single (int action); -void proc_iface_series (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_iface.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/inc/proc_iface.hpp b/modules/proc/inc/proc_iface.hpp deleted file mode 100644 index a0d0f7d..0000000 --- a/modules/proc/inc/proc_iface.hpp +++ /dev/null @@ -1,85 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_IFACE_H - # define VA_PROC_IFACE_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Mode { - PROC_MODE_FOO, - - PROC_MODE = 0x008000u, - PROC_MODE_LABEL_SERIES, - PROC_MODE_LABEL_CALIB, - PROC_MODE_OBJECTS_SERIES, - PROC_MODE_OBJECTS_CALIB, - PROC_MODE_COINS_SERIES, - PROC_MODE_COINS_CALIB, - PROC_MODE_RESISTOR_SERIES, - PROC_MODE_RESISTOR_CALIB, - PROC_MODE_LIGHTERS_SERIES, - PROC_MODE_LIGHTERS_CALIB - }; - - enum Proc_DBG { - PROC_DBG_NO, - PROC_DBG_STOP_ITEM, - PROC_DBG_DELAY_STEP, - PROC_DBG_STOP_STEP - }; - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern int proc_debug; -extern int proc_mode; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -int proc_iface_single (int action); -void proc_iface_series (void); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_iface.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/inc/proc_label.h b/modules/proc/inc/proc_label.h deleted file mode 100644 index d1b78f1..0000000 --- a/modules/proc/inc/proc_label.h +++ /dev/null @@ -1,51 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_LABEL_H - # define VA_PROC_LABEL_H - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Label { - LABEL_OK, - LABEL_NOK_LABEL, - LABEL_NOK_CERDO, - LABEL_NOK_BCODE, - LABEL_NOK_PRODUCT, - LABEL_NOK_PRICE - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -int proc_label (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_label.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/inc/proc_label.hpp b/modules/proc/inc/proc_label.hpp deleted file mode 100644 index ebb4446..0000000 --- a/modules/proc/inc/proc_label.hpp +++ /dev/null @@ -1,63 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_LABEL_HPP - # define VA_PROC_LABEL_HPP - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Label { - LABEL_OK, - LABEL_NOK_LABEL, - LABEL_NOK_CERDO, - LABEL_NOK_BCODE, - LABEL_NOK_PRODUCT, - LABEL_NOK_PRICE - }; - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -int proc_label (void); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_label.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/inc/proc_lighters.h b/modules/proc/inc/proc_lighters.h deleted file mode 100644 index 5771aad..0000000 --- a/modules/proc/inc/proc_lighters.h +++ /dev/null @@ -1,48 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_LIGHTERS_H - # define VA_PROC_LIGHTERS_H - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Lighter { - LIGHTER_OK, - LIGHTER_NOK_LIGHTER, - LIGHTER_NOK_SIZE - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -int proc_lighter (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_lighters.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/inc/proc_lighters.hpp b/modules/proc/inc/proc_lighters.hpp deleted file mode 100644 index 7d69dc6..0000000 --- a/modules/proc/inc/proc_lighters.hpp +++ /dev/null @@ -1,60 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_LIGHTERS_H - # define VA_PROC_LIGHTERS_H - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Lighter { - LIGHTER_OK, - LIGHTER_NOK_LIGHTER, - LIGHTER_NOK_SIZE - }; - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -int proc_lighter (void); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_lighters.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/inc/proc_objects.h b/modules/proc/inc/proc_objects.h deleted file mode 100644 index ed865fd..0000000 --- a/modules/proc/inc/proc_objects.h +++ /dev/null @@ -1,50 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_OBJECTS_H - # define VA_PROC_OBJECTS_H - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Objects { - OBJECTS_OK, - OBJECTS_NOK_PATTERN, - OBJECTS_NOK_OBJECTS, - OBJECTS_NOK_SIZE - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -int proc_objects_calibrate (void); -int proc_objects (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_objects.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/inc/proc_objects.hpp b/modules/proc/inc/proc_objects.hpp deleted file mode 100644 index 8794150..0000000 --- a/modules/proc/inc/proc_objects.hpp +++ /dev/null @@ -1,62 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_OBJECTS_HPP - # define VA_PROC_OBJECTS_HPP - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Objects { - OBJECTS_OK, - OBJECTS_NOK_PATTERN, - OBJECTS_NOK_OBJECTS, - OBJECTS_NOK_SIZE - }; - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -int proc_objects_calibrate (void); -int proc_objects (void); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_objects.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/inc/proc_resistor.h b/modules/proc/inc/proc_resistor.h deleted file mode 100644 index dea2ed7..0000000 --- a/modules/proc/inc/proc_resistor.h +++ /dev/null @@ -1,51 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_RESISTOR_H - # define VA_PROC_RESISTOR_H - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Resistor { - RESISTOR_OK, - RESISTOR_NOK_RESISTOR, - RESISTOR_NOK_BANDS, - RESISTOR_NOK_COLOR, - RESISTOR_NOK_STD_VALUE, - RESISTOR_NOK_TOLERANCE - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -int proc_resistor (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_resistor.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/inc/proc_resistor.hpp b/modules/proc/inc/proc_resistor.hpp deleted file mode 100644 index 31f70cf..0000000 --- a/modules/proc/inc/proc_resistor.hpp +++ /dev/null @@ -1,63 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_RESISTOR_HPP - # define VA_PROC_RESISTOR_HPP - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Resistor { - RESISTOR_OK, - RESISTOR_NOK_RESISTOR, - RESISTOR_NOK_BANDS, - RESISTOR_NOK_COLOR, - RESISTOR_NOK_STD_VALUE, - RESISTOR_NOK_TOLERANCE - }; - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -int proc_resistor (void); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_resistor.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/src/proc_coins.cpp b/modules/proc/src/proc_coins.cpp deleted file mode 100644 index f824fe2..0000000 --- a/modules/proc/src/proc_coins.cpp +++ /dev/null @@ -1,369 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <cstdio> -/* Packages ------------------------------------------------------------------*/ - #include <opencv2/opencv.hpp> -/* libalx --------------------------------------------------------------------*/ - #include "libalx/alx_math.hpp" -/* Project -------------------------------------------------------------------*/ - #include "img_iface.hpp" - #include "user_iface.hpp" -/* Module --------------------------------------------------------------------*/ - #include "proc_common.hpp" - - #include "proc_coins.hpp" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define COINS_MAX 1024 - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ -struct Coins_Properties { - /* position */ - int x; - int y; - - /* value */ - uint8_t diameter_pix; - double diameter_mm; - double value; -}; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ -/* Static --------------------------------------------------------------------*/ -static class std::vector <class std::vector <class cv::Point_ <int>>> contours; -static class cv::Mat hierarchy; -static class cv::Rect_ <int> rectangle [COINS_MAX]; -static int coins_n; -static struct Coins_Properties coins [COINS_MAX]; -static double ratio_mm_per_pix; -static double value_total; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_coins (int status); - -static void coins_segmentate (void); -static int coins_positions (void); -static void coins_diameters_pix (void); -static void calibrate_mm_per_pix (void); -static void coins_diameters_mm (void); -static int coins_values (void); -static double coin_value (double diameter_mm); -static void coins_total_value (void); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -int proc_coins (void) -{ - int status; - - proc_save_mem(0); - /* Segmentate coins */ - { - /* Measure time */ - clock_start(); - - coins_segmentate(); - - /* Measure time */ - clock_stop("Segmentate coins"); - } - /* Find coins positions */ - { - /* Measure time */ - clock_start(); - - status = coins_positions(); - if (status) { - result_coins(status); - return status; - } - - /* Measure time */ - clock_stop("Find coins positions"); - } - /* Get coin diameters in pixels */ - { - /* Measure time */ - clock_start(); - - coins_diameters_pix(); - - /* Measure time */ - clock_stop("Coins diameters in pixels"); - } - /* Calibrate with the biggest coin; every img should have a 2 € coin */ - { - /* Measure time */ - clock_start(); - - calibrate_mm_per_pix(); - - /* Measure time */ - clock_stop("Calibrate (mm per pix)"); - } - /* Get coins diameters in mm */ - { - /* Measure time */ - clock_start(); - - coins_diameters_mm(); - - /* Measure time */ - clock_stop("Coins diameters in mm"); - } - /* Get coins values (by their sizes) */ - { - /* Measure time */ - clock_start(); - - status = coins_values(); - if (status) { - result_coins(status); - return status; - } - - /* Measure time */ - clock_stop("Coins values"); - } - /* Add total value */ - { - /* Measure time */ - clock_start(); - - coins_total_value(); - - /* Measure time */ - clock_stop("Total value"); - } - - status = COINS_OK; - result_coins(status); - return status; -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_coins (int status) -{ - /* Cleanup */ - - /* Write result into log */ - switch (status) { - case COINS_OK: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: OK"); - break; - case COINS_NOK_COINS: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK_COINS"); - break; -#if 0 - case COINS_NOK_OVERLAP: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK_OVERLAP"); - break; -#endif - case COINS_NOK_SIZE: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK_SIZE"); - break; - default: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK"); - break; - } - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - -static void coins_segmentate (void) -{ - proc_load_mem(0); - - proc_cmp(IMG_IFACE_CMP_BLUE); - proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU); - proc_distance_transform(); - proc_local_max(); - proc_dilate(6); - proc_save_mem(1); -} - -static int coins_positions (void) -{ - int status; - int i; - - proc_load_mem(1); - - proc_contours(&contours, &hierarchy); - coins_n = contours.size(); - - /* If no contour is found, error: NOK_COINS */ - if (!coins_n) { - status = COINS_NOK_COINS; - return status; - } - - /* Get position of each contour */ - for (i = 0; i < coins_n; i++) { - proc_bounding_rect(&(contours[i]), &(rectangle[i]), true); - coins[i].x = rectangle[i].x + rectangle[i].width / 2.0; - coins[i].y = rectangle[i].y + rectangle[i].height / 2.0; - } - - status = COINS_OK; - return status; -} - -static void coins_diameters_pix (void) -{ - int i; - - proc_load_mem(1); - - /* Get coins diameters in pixels */ - for (i = 0; i < coins_n; i++) { - proc_pixel_get(coins[i].x, coins[i].y, - &(coins[i].diameter_pix)); - coins[i].diameter_pix *= 2; - } -} - -static void calibrate_mm_per_pix (void) -{ - uint8_t coins_size_pix [coins_n]; - int i; - int max_pos; - int max_size; - - for (i = 0; i < coins_n; i++) { - coins_size_pix[i] = coins[i].diameter_pix; - } - - max_pos = alx_maximum_u8(coins_n, coins_size_pix); - max_size = coins_size_pix[max_pos]; - ratio_mm_per_pix = 25.75 / max_size; -} - -static void coins_diameters_mm (void) -{ - int i; - - for (i = 0; i < coins_n; i++) { - coins[i].diameter_mm = ratio_mm_per_pix * - coins[i].diameter_pix; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin[%i]: %.2lf mm", - i, - coins[i].diameter_mm); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - } -} - -static int coins_values (void) -{ - int status; - int i; - - for (i = 0; i < coins_n; i++) { - coins[i].value = coin_value(coins[i].diameter_mm); - - /* If a coin is of invalid size, error: NOK_SIZE */ - if (coins[i].value < 0) { - status = COINS_NOK_SIZE; - return status; - } - - /* Write values into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin[%i]: %.2lf EUR", - i, - coins[i].value); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - } - - status = COINS_OK; - return status; -} - -static double coin_value (double diameter_mm) -{ - double value; - - /* Get coin value by its diameter in mm */ - if (diameter_mm > 27.00) { - value = -1; - } else if (diameter_mm > 25.00) { - value = 2.00; - } else if (diameter_mm > 23.75) { - value = 0.50; - } else if (diameter_mm > 22.75) { - value = 1.00; - } else if (diameter_mm > 21.75) { - value = 0.20; - } else if (diameter_mm > 20.50) { - value = 0.05; - } else if (diameter_mm > 19.25) { - value = 0.10; - } else if (diameter_mm > 17.50) { - value = 0.02; - } else if (diameter_mm > 15.00) { - value = 0.01; - } else { - value = -1; - } - - return value; -} - -static void coins_total_value (void) -{ - int i; - - value_total = 0.00; - - for (i = 0; i < coins_n; i++) { - value_total += coins[i].value; - } - - /* Write total value into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Total value: %.2lf EUR", - value_total); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/src/proc_common.cpp b/modules/proc/src/proc_common.cpp deleted file mode 100644 index d76e47f..0000000 --- a/modules/proc/src/proc_common.cpp +++ /dev/null @@ -1,441 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <cstddef> - #include <cstdio> - #include <ctime> -/* Packages ------------------------------------------------------------------*/ - #include <opencv2/opencv.hpp> - #include <zbar.h> -/* Project -------------------------------------------------------------------*/ - #include "img_iface.hpp" - #include "user_iface.hpp" -/* Module --------------------------------------------------------------------*/ - #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, (const void *)&n); -} - -void proc_load_mem (int n) -{ - - img_iface_act(IMG_IFACE_ACT_LOAD_MEM, (const 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_skeleton (void) -{ - - img_iface_act(IMG_IFACE_ACT_SKELETON, 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_get (int x, int y, unsigned char *val) -{ - struct Img_Iface_Data_Pixel_Get data; - data.x = x; - data.y = y; - data.val = val; - img_iface_act(IMG_IFACE_ACT_PIXEL_GET, (const void *)&data); -} - -void proc_pixel_set (int x, int y, unsigned char val) -{ - struct Img_Iface_Data_Pixel_Set data; - data.x = x; - data.y = y; - data.val = val; - img_iface_act(IMG_IFACE_ACT_PIXEL_SET, (const void *)&data); - - proc_show_img(); -} - -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, (const 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, (const 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, (const 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, (const 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, (const 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, (const 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, (const void *)&data); - - proc_show_img(); -} - -void proc_border (int size) -{ - struct Img_Iface_Data_Border data; - - data.size = size; - img_iface_act(IMG_IFACE_ACT_BORDER, (const void *)&data); - - proc_show_img(); -} - -void proc_rotate (double center_x, double center_y, double angle) -{ - struct Img_Iface_Data_Rotate data; - - data.center.x = center_x; - data.center.y = center_y; - data.angle = angle; - img_iface_act(IMG_IFACE_ACT_ROTATE, (const 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, (const 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, (const 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 ( - class std::vector <class 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, (const void *)&data); - - proc_show_img(); -} - -void proc_contours_size ( - const class std::vector <class 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, (const void *)&data); -} - -void proc_bounding_rect ( - const class 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, (const void *)&data); - - if (show) { - proc_show_img(); - } -} - -void proc_fit_ellipse ( - const class 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, (const void *)&data); - - - if (show) { - proc_show_img(); - } -} - -void proc_min_area_rect ( - const class 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, (const 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, (const 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, (const 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)", - time_diff, txt); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/src/proc_iface.c b/modules/proc/src/proc_iface.c deleted file mode 100644 index f14ba1d..0000000 --- a/modules/proc/src/proc_iface.c +++ /dev/null @@ -1,227 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <errno.h> - #include <stdbool.h> - #include <stdio.h> - #include <stdlib.h> - #include <time.h> -/* libalx -------------------------------------------------------------------*/ - #include "libalx/io/alx_input.h" -/* Project -------------------------------------------------------------------*/ - #include "img_iface.h" - #include "user_iface.h" - #include "save.h" -/* Module --------------------------------------------------------------------*/ - #include "proc_label.h" - #include "proc_lighters.h" - #include "proc_objects.h" - #include "proc_coins.h" - #include "proc_resistor.h" - #include "proc_common.h" - - #include "proc_iface.h" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ - int proc_debug; - int proc_mode; - -/* Static --------------------------------------------------------------------*/ -static char proc_path [FILENAME_MAX]; -static char proc_fail_path [FILENAME_MAX]; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -int proc_iface_single (int action) -{ - int error; - clock_t time_0; - clock_t time_1; - double time_tot; - - /* Init timer */ - time_0 = clock(); - - /* Process */ - switch (action) { - case PROC_MODE_LABEL_SERIES: - error = proc_label(); - break; - case PROC_MODE_OBJECTS_CALIB: - error = proc_objects_calibrate(); - break; - case PROC_MODE_OBJECTS_SERIES: - error = proc_objects(); - break; - case PROC_MODE_COINS_SERIES: - error = proc_coins(); - break; - case PROC_MODE_RESISTOR_SERIES: - error = proc_resistor(); - break; - case PROC_MODE_LIGHTERS_SERIES: - error = proc_lighter(); - break; - default: - error = -1; - } - - /* End timer */ - time_1 = clock(); - - /* Calculate time in seconds */ - time_tot = ((double) time_1 - time_0) / CLOCKS_PER_SEC; - - /* Write time into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Item total time: %.3lf", - time_tot); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - return error; -} - -void proc_iface_series (void) -{ - bool file_error; - int num_len; - char file_basename [FILENAME_MAX]; - char file_ext [FILENAME_MAX]; - char file_name [FILENAME_MAX]; - char save_error_as [FILENAME_MAX]; - bool wh; - /* if i starts being 0, the camera needs calibration */ - int i; - char txt_tmp [FILENAME_MAX]; - - switch (proc_mode) { - case PROC_MODE_LABEL_SERIES: - snprintf(proc_path, FILENAME_MAX, "%s", labels_path); - snprintf(proc_fail_path, FILENAME_MAX, "%s", labels_fail_path); - snprintf(file_basename, FILENAME_MAX, "b"); - num_len = 4; - snprintf(file_ext, FILENAME_MAX, ".BMP"); - i = 1; - break; - case PROC_MODE_OBJECTS_SERIES: - snprintf(proc_path, FILENAME_MAX, "%s", objects_path); - snprintf(proc_fail_path, FILENAME_MAX, "%s", objects_fail_path); - snprintf(file_basename, FILENAME_MAX, "o"); - num_len = 4; - snprintf(file_ext, FILENAME_MAX, ".jpeg"); - i = 0; - proc_mode++; - break; - case PROC_MODE_COINS_SERIES: - snprintf(proc_path, FILENAME_MAX, "%s", coins_path); - snprintf(proc_fail_path, FILENAME_MAX, "%s", coins_fail_path); - snprintf(file_basename, FILENAME_MAX, "c"); - num_len = 4; - snprintf(file_ext, FILENAME_MAX, ".jpeg"); - i = 1; - break; - case PROC_MODE_RESISTOR_SERIES: - snprintf(proc_path, FILENAME_MAX, "%s", resistors_path); - snprintf(proc_fail_path, FILENAME_MAX, "%s", resistors_fail_path); - snprintf(file_basename, FILENAME_MAX, "r"); - num_len = 4; - snprintf(file_ext, FILENAME_MAX, ".png"); - i = 1; - break; - case PROC_MODE_LIGHTERS_SERIES: - snprintf(proc_path, FILENAME_MAX, "%s", lighters_path); - snprintf(proc_fail_path, FILENAME_MAX, "%s", lighters_fail_path); - snprintf(file_basename, FILENAME_MAX, "lighters"); - num_len = 4; - snprintf(file_ext, FILENAME_MAX, ".png"); - i = 1; - break; - default: - return; - } - - wh = true; - for (; wh; i++) { - if (snprintf(file_name, FILENAME_MAX, "%s%04i%s", - file_basename, - i, file_ext) >= FILENAME_MAX) { - goto err_path; - } - - file_error = alx_sscan_fname(proc_path, file_name, - true, file_name); - - if (file_error) { - wh = false; - } else { - errno = 0; - img_iface_load(proc_path, file_name); - - if (errno) { - printf("errno:%i\n", errno); - goto err_load; - } - - /* Process */ - if (proc_iface_single(proc_mode)) { - /* Save failed image into file */ - proc_show_img(); - if (snprintf(save_error_as, FILENAME_MAX, - "%s%0*i_err%s", - file_basename, - num_len, i, - file_ext) >= FILENAME_MAX) { - goto err_path; - } - save_image_file(proc_fail_path, - save_error_as); - } - - /* Show log */ - snprintf(txt_tmp, FILENAME_MAX, "%04i", i); - user_iface_show_log(txt_tmp, "Item"); - - if (proc_debug >= PROC_DBG_STOP_ITEM) - getchar(); - } -err_load: - if (!i) - proc_mode--; - } - - return; - - -err_path: - printf("Path is too large and has been truncated\n"); - exit(EXIT_FAILURE); -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/src/proc_label.cpp b/modules/proc/src/proc_label.cpp deleted file mode 100644 index 2f09c90..0000000 --- a/modules/proc/src/proc_label.cpp +++ /dev/null @@ -1,377 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <cstdio> - #include <cstring> -/* Packages ------------------------------------------------------------------*/ - #include <opencv2/opencv.hpp> - #include <zbar.h> -/* Project -------------------------------------------------------------------*/ - #include "img_iface.hpp" - #include "user_iface.hpp" -/* Module --------------------------------------------------------------------*/ - #include "proc_common.hpp" - - #include "proc_label.hpp" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ - -/* Static --------------------------------------------------------------------*/ -static class std::vector <class std::vector <class cv::Point_ <int>>> contours; -static class cv::Mat hierarchy; -static class cv::RotatedRect rect; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_label (int status); - -static int label_find (void); -static void label_align (void); -static int find_cerdo (void); -static int barcode_read (void); -static int barcode_chk_prod (void); -static void price_read (void); -static int price_chk (void); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -int proc_label (void) -{ - int status; - - proc_save_mem(0); - /* Find label (position and angle) */ - { - /* Measure time */ - clock_start(); - - status = label_find(); - if (status) { - result_label(status); - return status; - } - - /* Measure time */ - clock_stop("Find label"); - } - /* Align label and extract green component */ - { - /* Measure time */ - clock_start(); - - label_align(); - - /* Measure time */ - clock_stop("Align label"); - } - /* Find "Cerdo" in aligned image */ - { - /* Measure time */ - clock_start(); - - status = find_cerdo(); - if (status) { - result_label(status); - return status; - } - - /* Measure time */ - clock_stop("Find cerdo (OCR)"); - } - /* Read barcode in original image */ - { - /* Measure time */ - clock_start(); - - status = barcode_read(); - if (status) { - result_label(status); - return status; - } - - /* Measure time */ - clock_stop("Read barcode (zbar)"); - } - /* Check product code in barcode */ - { - /* Measure time */ - clock_start(); - - status = barcode_chk_prod(); - if (status) { - result_label(status); - return status; - } - - /* Measure time */ - clock_stop("Chk product code"); - } - /* Read price in aligned image (green component) */ - { - /* Measure time */ - clock_start(); - - price_read(); - - /* Measure time */ - clock_stop("Read price (OCR)"); - } - /* Check label price with barcode price */ - { - /* Measure time */ - clock_start(); - - status = price_chk(); - if (status) { - result_label(status); - return status; - } - - /* Measure time */ - clock_stop("Check price"); - } - - status = LABEL_OK; - result_label(status); - return status; -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_label (int status) -{ - /* Cleanup */ - - /* Write result into log */ - switch (status) { - case LABEL_OK: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Label: OK"); - break; - case LABEL_NOK_LABEL: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Label: NOK_LABEL"); - break; - case LABEL_NOK_CERDO: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Label: NOK_CERDO"); - break; - case LABEL_NOK_BCODE: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Label: NOK_BCODE"); - break; - case LABEL_NOK_PRODUCT: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Label: NOK_PRODUCT"); - break; - case LABEL_NOK_PRICE: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Label: NOK_PRICE"); - break; - default: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Label: NOK"); - break; - } - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - -static int label_find (void) -{ - int status; - int tmp; - - proc_load_mem(0); - - 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_not(); -#endif - proc_smooth(IMGI_SMOOTH_MEAN, 21); - proc_threshold(cv::THRESH_BINARY_INV, 2); - proc_dilate_erode(100); - proc_contours(&contours, &hierarchy); - - /* If no contour is found, error: NOK_LABEL */ - if (!contours.size()) { - status = LABEL_NOK_LABEL; - return status; - } - - 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) { - rect.angle += 90.0; - tmp = rect.size.width; - rect.size.width = rect.size.height; - rect.size.height = tmp; - } - - status = LABEL_OK; - return status; -} - -static void label_align (void) -{ - proc_load_mem(0); - - proc_rotate(rect.center.x, rect.center.y, rect.angle); - proc_cmp(IMG_IFACE_CMP_GREEN); - proc_save_mem(1); -} - -static int find_cerdo (void) -{ - int status; - int x; - int y; - int w; - int h; - bool cerdo_nok; - - proc_load_mem(1); - - x = rect.center.x - (1.05 * rect.size.width / 2); - if (x < 0) { - x = 0; - } - y = rect.center.y - (1.47 * rect.size.height / 2); - if (y < 0) { - y = 0; - } - w = rect.size.width / 2; - h = rect.size.height * 0.20; - proc_ROI(x, y, w, h); - proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); - proc_erode(1); - proc_OCR(IMG_IFACE_OCR_LANG_ENG, IMG_IFACE_OCR_CONF_NONE); - - /* Compare Label text to "Cerdo". */ - cerdo_nok = strncmp(img_ocr_text, "Cerdo", - strlen("Cerdo")); - - /* If string doesn't match, error: NOK_CERDO */ - if (cerdo_nok) { - status = LABEL_NOK_CERDO; - return status; - } - - status = LABEL_OK; - return status; -} - -static int barcode_read (void) -{ - int status; - - proc_load_mem(0); - - proc_cmp(IMG_IFACE_CMP_GREEN); - proc_zbar(zbar::ZBAR_EAN13); - - /* Check that 1 and only 1 bcode is read. */ - if (zb_codes.n != 1) { - status = LABEL_NOK_BCODE; - return status; - } - - status = LABEL_OK; - return status; -} - -static int barcode_chk_prod (void) -{ - int status; - bool prod_nok; - - prod_nok = strncmp(zb_codes.arr[0].data, "2301703", - strlen("2301703")); - if (prod_nok) { - status = LABEL_NOK_PRODUCT; - return status; - } - - status = LABEL_OK; - return status; -} - -static void price_read (void) -{ - int x; - int y; - int w; - int h; - - proc_load_mem(1); - - x = rect.center.x + (0.33 * rect.size.width / 2); - y = rect.center.y + (0.64 * rect.size.height / 2); - w = rect.size.width * 0.225; - h = rect.size.height * 0.15; - proc_ROI(x, y, w, h); - proc_smooth(IMGI_SMOOTH_MEAN, 3); - proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); - proc_dilate_erode(1); - proc_threshold(cv::THRESH_BINARY, 1); - proc_OCR(IMG_IFACE_OCR_LANG_DIGITS, IMG_IFACE_OCR_CONF_PRICE); -} - -static int price_chk (void) -{ - int status; - char price [80]; - bool price_nok; - - /* Extract price from barcode */ - if (zb_codes.arr[0].data[8] != '0') { - snprintf(price, 80, "%c%c.%c%c", - zb_codes.arr[0].data[8], - zb_codes.arr[0].data[9], - zb_codes.arr[0].data[10], - zb_codes.arr[0].data[11]); - } else { - snprintf(price, 80, "%c.%c%c", - zb_codes.arr[0].data[9], - zb_codes.arr[0].data[10], - zb_codes.arr[0].data[11]); - } - - /* Compare price from barcode and from text */ - price_nok = strncmp(img_ocr_text, price, strlen(price)); - - if (price_nok) { - status = LABEL_NOK_PRICE; - return status; - } - - status = LABEL_OK; - return status; -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/src/proc_lighters.cpp b/modules/proc/src/proc_lighters.cpp deleted file mode 100644 index 7242638..0000000 --- a/modules/proc/src/proc_lighters.cpp +++ /dev/null @@ -1,505 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <cstddef> - #include <cstdio> -/* Packages ------------------------------------------------------------------*/ - #include <opencv2/opencv.hpp> -/* libalx ------------------------------------------------------------------*/ - #include "libalx/alx_math.hpp" -/* Project -------------------------------------------------------------------*/ - #include "img_iface.hpp" - #include "user_iface.hpp" -/* Module --------------------------------------------------------------------*/ - #include "proc_common.hpp" - - #include "proc_lighters.hpp" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ -enum Lighter_Hood { - HOOD_OK, - HOOD_NOT_PRESENT, - HOOD_NOT_OK -}; - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ -struct Point { - uint16_t x; - uint16_t y; -}; - -struct Size { - uint16_t h; - uint16_t w; -}; - -struct Lighter_Properties { - /* position */ - struct Point pos; - struct Size size; - double angle; - - bool fork; - bool valve; - int hood_; - bool hood; - bool wheel; - - bool ok; -}; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ - -/* Static --------------------------------------------------------------------*/ -static class std::vector <class std::vector <class cv::Point_ <int>>> contours_all; -static class std::vector <class std::vector <class cv::Point_ <int>>> contours_one; -static class cv::Mat hierarchy; -static class cv::RotatedRect rect_rot [CONTOURS_MAX]; -static class cv::Rect_ <int> rect; -static struct Lighter_Properties lighter [CONTOURS_MAX]; -static unsigned lighters_n; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_lighter (int status); - -static void lighters_bgr2gray (void); -static void lighters_segment_full (void); -static int lighters_find (void); -static void lighter_segment_body (int i); -static void lighter_rm_body (int i); -static void lighter_crop_head (int i); -static void lighter_chk_hood (int i); -static void lighter_rm_hood (void); -static void lighter_chk_fork (int i); -static void lighter_chk_wheel (int i); -static void lighter_chk_valve (int i); -static void lighters_log (void); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -int proc_lighter (void) -{ - int status; - int i; - - proc_save_mem(0); - /* Segment lighters */ - { - /* Measure time */ - clock_start(); - - lighters_bgr2gray(); - lighters_segment_full(); - lighters_find(); - - /* Measure time */ - clock_stop("Segment lighters"); - } - /* Check each lighter */ - for (i = 0; (unsigned)i < lighters_n; i++) { - /* Measure time */ - clock_start(); - - lighter[i].ok = true; - lighter_segment_body(i); - lighter_rm_body(i); - lighter_crop_head(i); - lighter_chk_hood(i); - if (lighter[i].hood_ != HOOD_NOT_PRESENT) { - lighter_rm_hood(); - } else { - proc_load_mem(7); - proc_save_mem(8); - } - lighter_chk_fork(i); - lighter_chk_wheel(i); - lighter_chk_valve(i); - - /* Measure time */ - clock_stop("Check parts"); - } - /* Print results of lighters into log */ - { - /* Measure time */ - clock_start(); - - lighters_log(); - - /* Measure time */ - clock_stop("Lighters properties (log)"); - } - - status = LIGHTER_OK; - result_lighter(status); - return status; -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_lighter (int status) -{ - - /* Write result into log */ - switch (status) { - case LIGHTER_OK: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: OK"); - break; - case LIGHTER_NOK_LIGHTER: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK_LIGHTER"); - break; - - case LIGHTER_NOK_SIZE: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK_SIZE"); - break; - default: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK"); - break; - } - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - -/* process -------------------------------------------------------------------*/ -static void lighters_bgr2gray (void) -{ - - proc_load_mem(0); - - proc_cvt_color(cv::COLOR_BGR2GRAY); - proc_not(); - proc_save_mem(1); - - proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); - proc_border(100); - proc_save_mem(3); - - proc_load_mem(1); - proc_border(100); - proc_save_mem(2); -} - -static void lighters_segment_full (void) -{ - - proc_load_mem(3); - proc_erode_dilate(1); - proc_dilate_erode(2); - proc_save_mem(4); -} - -static int lighters_find (void) -{ - int status; - int i; - int tmp; - - proc_load_mem(4); - proc_contours(&contours_all, &hierarchy); - lighters_n = contours_all.size(); - - /* If no contour is found, error: NOK_RESISTOR */ - if (!lighters_n) { - status = LIGHTER_NOK_LIGHTER; - return status; - } - - for (i = 0; (unsigned)i < lighters_n; i++) { - proc_min_area_rect(&(contours_all[i]), &rect_rot[i], true); - - /* If width > height, it is taking into acount the incorrect side */ - if (rect_rot[i].size.width > rect_rot[i].size.height) { - rect_rot[i].angle += 90.0; - tmp = rect_rot[i].size.width; - rect_rot[i].size.width = rect_rot[i].size.height; - rect_rot[i].size.height = tmp; - } - - lighter[i].pos.x = rect_rot[i].center.x; - lighter[i].pos.y = rect_rot[i].center.y; - lighter[i].angle = -rect_rot[i].angle; - lighter[i].size.h = rect_rot[i].size.height; - lighter[i].size.w = rect_rot[i].size.width; - } - - status = LIGHTER_OK; - return status; -} - -static void lighter_segment_body (int i) -{ - int x; - int y; - int w; - int h; - - proc_load_mem(2); - - proc_rotate(lighter[i].pos.x, lighter[i].pos.y, -lighter[i].angle); - w = lighter[i].size.w * 1.25; - h = lighter[i].size.h * 1.25; - x = lighter[i].pos.x - (w / 2.0); - y = lighter[i].pos.y - (h / 2.0); - proc_ROI(x, y, w, h); - proc_threshold(cv::THRESH_BINARY, 255 - 165); - - proc_erode_dilate(1); - proc_dilate_erode(1); - proc_erode_dilate(lighter[i].size.w * 0.43); - proc_save_mem(5); - - proc_contours(&contours_one, &hierarchy); - proc_bounding_rect(&(contours_one[0]), &rect, true); -} - -static void lighter_rm_body (int i) -{ - int x; - int y; - int w; - int h; - - proc_load_mem(5); - proc_not(); - proc_erode(5); - proc_save_ref(); - - proc_load_mem(3); - proc_rotate(lighter[i].pos.x, lighter[i].pos.y, -lighter[i].angle); - w = lighter[i].size.w * 1.25; - h = lighter[i].size.h * 1.25; - x = lighter[i].pos.x - (w / 2.0); - y = lighter[i].pos.y - (h / 2.0); - proc_ROI(x, y, w, h); - proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); - proc_and_2ref(); - proc_save_mem(6); -} - -static void lighter_crop_head (int i) -{ - int x; - int y; - int w; - int h; - - proc_load_mem(6); -// - w = rect.width * 1.15; - h = rect.width * 0.65; - x = rect.x - rect.width * 0.075; - y = rect.y - rect.width * 0.65; - proc_ROI(x, y, w, h); - rect.x = x; - rect.y = y; - rect.width = w; - rect.height = h; - lighter[i].size.w = w; - lighter[i].size.h = h; - proc_save_mem(7); -} - -static void lighter_chk_hood (int i) -{ - uint8_t val1; - uint8_t val2; - proc_load_mem(7); - - proc_pixel_get(rect.width * 0.2, rect.height * 0.3, &val1); - proc_pixel_set(rect.width * 0.2, rect.height * 0.3, UINT8_MAX / 2); - proc_save_mem(9); - - if (val1) { - proc_pixel_get(rect.width * 0.2, rect.height * 0.8, &val2); - proc_pixel_set(rect.width * 0.2, rect.height * 0.8, UINT8_MAX /2); - if (val2) { - lighter[i].hood_ = HOOD_OK; - lighter[i].hood = true; - } else { - lighter[i].hood_ = HOOD_NOT_OK; - lighter[i].hood = false; - lighter[i].ok = false; - } - } else { - lighter[i].hood_ = HOOD_NOT_PRESENT; - lighter[i].hood = false; - lighter[i].ok = false; - } -} - -static void lighter_rm_hood (void) -{ - - proc_load_mem(7); - proc_border(2); - proc_save_ref(); - - proc_dilate_erode(2); - proc_erode_dilate(rect.height * 0.25); - proc_dilate(2); - proc_not(); - proc_and_2ref(); - proc_save_mem(8); -} - -static void lighter_chk_fork (int i) -{ - uint8_t val; - - proc_load_mem(8); - - proc_dilate_erode(2); - proc_pixel_get(rect.width * 0.8, rect.height * 0.8, &val); - proc_pixel_set(rect.width * 0.8, rect.height * 0.8, UINT8_MAX / 2); - proc_save_mem(10); - - if (val) { - lighter[i].fork = true; - } else { - lighter[i].fork = false; - lighter[i].ok = false; - } -} - -static void lighter_chk_wheel (int i) -{ - uint8_t val; - - proc_load_mem(8); - - proc_dilate(5); - proc_pixel_get(rect.width * 0.58, rect.height * 0.19, &val); - proc_pixel_set(rect.width * 0.58, rect.height * 0.19, UINT8_MAX / 2); - proc_save_mem(11); - - if (val) { - lighter[i].wheel = true; - } else { - lighter[i].wheel = false; - lighter[i].ok = false; - } -} - -static void lighter_chk_valve (int i) -{ - uint8_t val; - - proc_load_mem(8); - - if (lighter[i].hood_ == HOOD_NOT_PRESENT) { - proc_dilate(5); - } else { - proc_dilate(10); - } - proc_pixel_get(rect.width * 0.07, rect.height * 0.92, &val); - proc_pixel_set(rect.width * 0.07, rect.height * 0.92, UINT8_MAX / 2); - proc_save_mem(12); - - if (val) { - lighter[i].valve = true; - } else { - lighter[i].valve = false; - lighter[i].ok = false; - } -} - -static void lighters_log (void) -{ - int i; - - for (i = 0; (unsigned)i < lighters_n; i++) { - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Lighter[%i]:", - i); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " pos: (%i, %i) pix", - lighter[i].pos.x, - lighter[i].pos.y); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " ang = %.1lf DEG", - lighter[i].angle); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " hood = %s", - lighter[i].hood ? "ok" : "nok"); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " fork = %s", - lighter[i].fork ? "ok" : "nok"); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " wheel = %s", - lighter[i].wheel ? "ok" : "nok"); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " valve = %s", - lighter[i].valve ? "ok" : "nok"); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " RESULT = %s", - lighter[i].ok ? "OK" : "NOK"); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/src/proc_objects.cpp b/modules/proc/src/proc_objects.cpp deleted file mode 100644 index db5d5e3..0000000 --- a/modules/proc/src/proc_objects.cpp +++ /dev/null @@ -1,689 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <cstdio> -/* Packages ------------------------------------------------------------------*/ - #include <opencv2/opencv.hpp> -/* libalx ------------------------------------------------------------------*/ - #include "libalx/alx_math.hpp" -/* Project -------------------------------------------------------------------*/ - #include "img_iface.hpp" - #include "user_iface.hpp" -/* Module --------------------------------------------------------------------*/ - #include "proc_common.hpp" - - #include "proc_objects.hpp" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define OBJECTS_MAX (1024) - # define PATTERN_SQUARE_LEN_MM (10.0) - - # define PATTERN_DILATE (2) - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ -struct Point { - uint16_t x_pix; - uint16_t y_pix; - - double x_mm; - double y_mm; -}; - -struct Pattern_Square { - struct Point pos; - - uint8_t len; -}; - -struct Pattern_Properties { - /* center */ - struct Point center; - struct Point origin; - - /* Angle */ - double angle; - - /* Size */ - uint16_t height; - uint16_t width; - - /* Squares (distance calibration) */ - struct Pattern_Square square [OBJECTS_MAX]; -}; - -struct Objects_Properties { - /* position */ - struct Point pos; - - /* Angle */ - double angle; - - /* Area */ - double area_pix2; - double area_mm2; - - /* Perimeter */ - double perimeter_pix; - double perimeter_mm; - - /* type */ - double ratio_p2_a; - double area_rect; - double ratio_a_arect; - double perimeter_rect; - double ratio_p_prect; -}; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ - -/* Static --------------------------------------------------------------------*/ -static class std::vector <class std::vector <class cv::Point_ <int>>> contours; -static class cv::Mat hierarchy; -static class cv::RotatedRect rect_rot [OBJECTS_MAX]; -static class cv::Rect_ <int> rect [OBJECTS_MAX]; -static struct Pattern_Properties pattern; -static int squares_n; -static double ratio_mm_pix; -static int objects_n; -static struct Objects_Properties objects [OBJECTS_MAX]; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_objects (int status); - -static void pattern_bgr2gray (void); -static int pattern_find (void); -static void pattern_rotation_get (void); -static void pattern_rotation_fix (void); -static void pattern_dimensions_get (void); -static void pattern_dimensions_fix (void); -static void pattern_squares_find (void); -static void pattern_squares_pos_get (void); -static void pattern_squares_len_get (void); -static void pattern_calib_mm_pix (void); - -static void objects_bgr2gray (void); -static void objects_rotation_fix (void); -static void objects_dimensions_fix (void); -static void objects_segment (void); -static int objects_contours (void); -static void objects_position_pix (void); -static void objects_size_pix (void); -static void objects_shape (void); -static void objects_position_mm (void); -static void objects_size_mm (void); -static void objects_log (void); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -int proc_objects_calibrate (void) -{ - int status; - - proc_save_mem(0); - /* Calibrate angle with the whole pattern */ - { - /* Measure time */ - clock_start(); - - pattern_bgr2gray(); - status = pattern_find(); - if (status) { - result_objects(status); - return status; - } - pattern_rotation_get(); - pattern_rotation_fix(); - - /* Measure time */ - clock_stop("Calibrate: rotation"); - } - /* Segmentate pattern squares */ - { - /* Measure time */ - clock_start(); - - pattern_dimensions_get(); - pattern_dimensions_fix(); - - /* Measure time */ - clock_stop("Calibrate: dimensions"); - } - /* Find squares */ - { - /* Measure time */ - clock_start(); - - pattern_squares_find(); - pattern_squares_pos_get(); - pattern_squares_len_get(); - pattern_calib_mm_pix(); - - /* Measure time */ - clock_stop("Calibrate (mm per pix)"); - } - - status = OBJECTS_OK; - result_objects(status); - return status; -} - -int proc_objects (void) -{ - int status; - - proc_save_mem(0); - /* Align image */ - { - /* Measure time */ - clock_start(); - - objects_bgr2gray(); - objects_rotation_fix(); - objects_dimensions_fix(); - - /* Measure time */ - clock_stop("Align image to pattern"); - } - /* Segment objects */ - { - /* Measure time */ - clock_start(); - - objects_segment(); - - /* Measure time */ - clock_stop("Segment objects"); - } - /* Find objects positions */ - { - /* Measure time */ - clock_start(); - - status = objects_contours(); - if (status) { - result_objects(status); - return status; - } - - /* Measure time */ - clock_stop("Find objects"); - } - /* Get objects properties in pixels */ - { - /* Measure time */ - clock_start(); - - objects_position_pix(); - objects_position_mm(); - - /* Measure time */ - clock_stop("Objects positions"); - } - /* Get objects properties in mm */ - { - /* Measure time */ - clock_start(); - - objects_size_pix(); - objects_size_mm(); - - /* Measure time */ - clock_stop("Objects sizes"); - } - /* Get objects properties in mm */ - { - /* Measure time */ - clock_start(); - - objects_shape(); - - /* Measure time */ - clock_stop("Objects shapes"); - } - /* Print properties of objects into log */ - { - /* Measure time */ - clock_start(); - - objects_log(); - - /* Measure time */ - clock_stop("Objects properties (log)"); - } - - status = OBJECTS_OK; - result_objects(status); - return status; -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_objects (int status) -{ - /* Write result into log */ - switch (status) { - case OBJECTS_OK: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: OK"); - break; - case OBJECTS_NOK_OBJECTS: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK_OBJECTS"); - break; - - case OBJECTS_NOK_SIZE: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK_SIZE"); - break; - default: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK"); - break; - } - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - -/* calibration ---------------------------------------------------------------*/ -static void pattern_bgr2gray (void) -{ - proc_load_mem(0); - - proc_cvt_color(cv::COLOR_BGR2GRAY); - proc_save_mem(1); -} - -static int pattern_find (void) -{ - int status; - - proc_load_mem(1); - - proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU); - proc_erode_dilate(16); - proc_dilate(2); - proc_contours(&contours, &hierarchy); - - /* If no contour is found, error: NOK_PATTERN */ - if (contours.size() != 1) { - status = OBJECTS_NOK_PATTERN; - return status; - } - - status = OBJECTS_OK; - return status; -} - -static void pattern_rotation_get (void) -{ - proc_min_area_rect(&(contours[0]), &(rect_rot[0]), true); - - /* If angle is < -45º, it is taking into account the incorrect side */ - if (rect_rot[0].angle < -45.0) { - rect_rot[0].angle += 90.0; - } - pattern.angle = rect_rot[0].angle; - pattern.center.x_pix = rect_rot[0].center.x; - pattern.center.y_pix = rect_rot[0].center.y; - - /* Write pattern properties into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "pattern angle = %lf DEG", - -pattern.angle); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "pattern center (x) = %i pix", - pattern.center.x_pix); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "pattern center (y) = %i pix", - pattern.center.y_pix); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - -static void pattern_rotation_fix (void) -{ - proc_load_mem(1); - - /* invert image before rotation to avoid black bands */ - proc_not(); - proc_rotate(pattern.center.x_pix, pattern.center.y_pix, pattern.angle); - proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); - proc_save_mem(2); -} - -static void pattern_dimensions_get (void) -{ - proc_load_mem(2); - - proc_erode_dilate(16); - proc_dilate(PATTERN_DILATE); - proc_contours(&contours, &hierarchy); - proc_bounding_rect(&(contours[0]), &(rect[0]), true); -} - -static void pattern_dimensions_fix (void) -{ - /* Need to correct also pattern dilatation (pattern_dimensions_get()) */ - pattern.origin.x_pix = rect[0].x; - pattern.origin.y_pix = rect[0].y; - pattern.width = rect[0].width; - pattern.height = rect[0].height; - - proc_load_mem(2); - - proc_ROI(pattern.origin.x_pix, pattern.origin.y_pix, - pattern.width, pattern.height); - proc_save_mem(3); -} - -static void pattern_squares_find (void) -{ - proc_load_mem(3); - - proc_distance_transform(); - proc_local_max(); - proc_dilate(6); - proc_save_mem(4); - - proc_contours(&contours, &hierarchy); - squares_n = contours.size(); -} - -static void pattern_squares_pos_get (void) -{ - int i; - - /* Get position of each contour */ - for (i = 0; i < squares_n; i++) { - proc_bounding_rect(&(contours[i]), &(rect[i]), true); - - pattern.square[i].pos.x_pix = rect[i].x + rect[i].width/2.0; - pattern.square[i].pos.y_pix = rect[i].y + rect[i].height/2.0; - } -} - -static void pattern_squares_len_get (void) -{ - int i; - - proc_load_mem(4); - - /* Get pattern square side lenght in pixels */ - for (i = 0; i < squares_n; i++) { - proc_pixel_get(pattern.square[i].pos.x_pix, - pattern.square[i].pos.y_pix, - &(pattern.square[i].len)); - pattern.square[i].len *= 2; - } -} - -static void pattern_calib_mm_pix (void) -{ - int i; - uint8_t pattern_len [OBJECTS_MAX]; - uint8_t median_size; - - for (i = 0; i < squares_n; i++) { - pattern_len[i] = pattern.square[i].len; - } - - median_size = alx_median_u8(squares_n, pattern_len); - ratio_mm_pix = PATTERN_SQUARE_LEN_MM / median_size; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "mm/pix = %lf", - ratio_mm_pix); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - -/* process -------------------------------------------------------------------*/ -static void objects_bgr2gray (void) -{ - proc_load_mem(0); - - proc_cvt_color(cv::COLOR_BGR2GRAY); - proc_save_mem(1); -} - -static void objects_rotation_fix (void) -{ - proc_load_mem(1); - - /* invert image before rotation to avoid black bands */ - proc_not(); - proc_rotate(pattern.center.x_pix, pattern.center.y_pix, pattern.angle); - proc_save_mem(2); -} - -static void objects_dimensions_fix (void) -{ - /* Need to correct also pattern dilatation (pattern_dimensions_get()) */ - proc_load_mem(2); - - proc_ROI(pattern.origin.x_pix, pattern.origin.y_pix, - pattern.width, pattern.height); - proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); - proc_save_mem(3); -} - -static void objects_segment (void) -{ - proc_load_mem(3); - - proc_dilate_erode(3); - proc_erode_dilate(3); - proc_save_mem(4); - - proc_distance_transform(); - proc_threshold(cv::THRESH_BINARY_INV, 30); - proc_distance_transform(); - proc_skeleton(); - proc_threshold(cv::THRESH_BINARY_INV, 10); - proc_save_ref(); - proc_save_mem(5); - - proc_load_mem(3); - proc_and_2ref(); - proc_distance_transform(); - proc_threshold(cv::THRESH_BINARY, 10); - proc_save_mem(6); -} - -static int objects_contours (void) -{ - int status; - - proc_load_mem(6); - - proc_contours(&contours, &hierarchy); - objects_n = contours.size(); - - /* If no contour is found, error: NOK_OBJECTS */ - if (!objects_n) { - status = OBJECTS_NOK_OBJECTS; - return status; - } - - status = OBJECTS_OK; - return status; -} - -static void objects_position_pix (void) -{ - int i; - - /* Get position of each contour */ - for (i = 0; i < objects_n; i++) { - proc_fit_ellipse(&(contours[i]), &(rect_rot[i]), true); - - objects[i].pos.x_pix = rect_rot[i].center.x; - objects[i].pos.y_pix = rect_rot[i].center.y; - - objects[i].angle = -rect_rot[i].angle + 90.0; - if (objects[i].angle < 0) { - objects[i].angle += 180.0; - } - } -} - -static void objects_position_mm (void) -{ - int i; - - /* Get position of each contour */ - for (i = 0; i < objects_n; i++) { - objects[i].pos.x_mm = ratio_mm_pix * objects[i].pos.x_pix; - objects[i].pos.y_mm = ratio_mm_pix * objects[i].pos.y_pix; - } -} - -static void objects_size_pix (void) -{ - double area [OBJECTS_MAX]; - double perimeter [OBJECTS_MAX]; - int i; - - /* Get size of each contour */ - proc_contours_size(&contours, area, perimeter); - for (i = 0; i < objects_n; i++) { - objects[i].area_pix2 = area[i]; - objects[i].perimeter_pix = perimeter[i]; - } -} - -static void objects_size_mm (void) -{ - int i; - - /* Get position of each contour */ - for (i = 0; i < objects_n; i++) { - objects[i].area_mm2 = pow(ratio_mm_pix, 2) * - objects[i].area_pix2; - objects[i].perimeter_mm = ratio_mm_pix * - objects[i].perimeter_pix; - } -} - -static void objects_shape (void) -{ - int i; - - /* Get shape of each contour */ - for (i = 0; i < objects_n; i++) { - proc_min_area_rect(&(contours[i]), &(rect_rot[i]), true); - - objects[i].ratio_p2_a = pow(objects[i].perimeter_pix, 2) / - objects[i].area_pix2; - - objects[i].area_rect = rect_rot[i].size.width * - rect_rot[i].size.height; - objects[i].perimeter_rect = 2.0 * - (rect_rot[i].size.width + - rect_rot[i].size.height); - - objects[i].ratio_p_prect = objects[i].perimeter_pix / - objects[i].perimeter_rect; - objects[i].ratio_a_arect = objects[i].area_pix2 / - objects[i].area_rect; - } -} - -static void objects_log (void) -{ - int i; - - /* Get coins diameters in mm */ - for (i = 0; i < objects_n; i++) { - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Object[%i]:", - i); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " pos: (%.1lf, %.1lf) mm", - objects[i].pos.x_mm, - objects[i].pos.y_mm); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " ang = %.1lf DEG", - objects[i].angle); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " A = %.1lf mm2", - objects[i].area_mm2); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " P = %.1lf mm", - objects[i].perimeter_mm); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " p2/A = %.2lf", - objects[i].ratio_p2_a); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " p/p_r = %.2lf", - objects[i].ratio_p_prect); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " A/A_r = %.2lf", - objects[i].ratio_a_arect); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/src/proc_resistor.cpp b/modules/proc/src/proc_resistor.cpp deleted file mode 100644 index 33bb624..0000000 --- a/modules/proc/src/proc_resistor.cpp +++ /dev/null @@ -1,1452 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <cmath> - #include <cstdio> -/* Packages ------------------------------------------------------------------*/ - #include <opencv2/opencv.hpp> -/* Project -------------------------------------------------------------------*/ - #include "img_iface.hpp" - #include "user_iface.hpp" -/* Module --------------------------------------------------------------------*/ - #include "proc_common.hpp" - - #include "proc_resistor.hpp" - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ -struct Resistor_Bands { - /* position */ - int x; - int y; - - /* value */ - unsigned char h; - unsigned char s; - unsigned char v; -}; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ - -/* Static --------------------------------------------------------------------*/ -static class std::vector <class std::vector <class cv::Point_ <int>>> contours; -static class cv::Mat hierarchy; -static class cv::RotatedRect rect_rot; -static class cv::Rect_ <int> rect; -static int bkgd; -static int bands_n; -static struct Resistor_Bands bands [5]; -static char code [6]; -static int base; -static float resistance; -static int tolerance; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_resistor (int status); - -static int resistor_find (void); -static void resistor_align (void); -static void resistor_dimensions_0 (void); -static void resistor_crop_0 (void); -static void resistor_bkgd (void); -static void resistor_dimensions_1 (void); -static void resistor_crop_1 (void); -static void separate_bkgd_bands_h (void); -static void separate_bkgd_bands_s (void); -static void separate_bkgd_bands_v (void); -static void bkgd_find (void); -static int bands_find (void); -static void bands_colors (void); -static void bands_code (void); -static char band_hsv2code (struct Resistor_Bands *band); -static void bands_code_deduce_0 (void); -static void bands_code_deduce_1 (void); -static int bands_code_deduce_no (void); -static void resistor_value (void); -static int resistor_tolerance (void); -static int chk_std_value (void); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -int proc_resistor (void) -{ - int status; - - proc_save_mem(0); - /* Find resistor (position and angle) */ - { - /* Measure time */ - clock_start(); - - status = resistor_find(); - if (status) { - result_resistor(status); - return status; - } - - /* Measure time */ - clock_stop("Find resistor"); - } - /* Align resistor, find its dimensions, and crop */ - { - /* Measure time */ - clock_start(); - - resistor_align(); - resistor_dimensions_0(); - resistor_crop_0(); - - /* Measure time */ - clock_stop("Align, dimensions, & crop"); - } - /* Find backgroung color */ - { - /* Measure time */ - clock_start(); - - resistor_bkgd(); - - /* Measure time */ - clock_stop("Background color"); - } - /* Crop more */ - { - /* Measure time */ - clock_start(); - - resistor_dimensions_1(); - resistor_crop_1(); - - /* Measure time */ - clock_stop("Crop more"); - } - /* Separate background (BK) and lines (WH) */ - { - /* Measure time */ - clock_start(); - - separate_bkgd_bands_h(); - separate_bkgd_bands_s(); - separate_bkgd_bands_v(); - bkgd_find(); - - /* Measure time */ - clock_stop("Separate bkgd from bands"); - } - /* Find bands: contours -> rectangles */ - { - /* Measure time */ - clock_start(); - - status = bands_find(); - if (status) { - result_resistor(status); - return status; - } - - /* Measure time */ - clock_stop("Find bands"); - } - /* Read values on the center of each band */ - { - /* Measure time */ - clock_start(); - - bands_colors(); - - /* Measure time */ - clock_stop("Bands' colors"); - } - /* Interpret colors */ - { - /* Measure time */ - clock_start(); - - bands_code(); - bands_code_deduce_0(); - bands_code_deduce_1(); - status = bands_code_deduce_no(); - if (status) { - result_resistor(status); - return status; - } - - /* Measure time */ - clock_stop("Interpret colors"); - } - /* Calculate resistor value & tolerance */ - { - /* Measure time */ - clock_start(); - - resistor_value(); - status = resistor_tolerance(); - if (status) { - result_resistor(status); - return status; - } - - /* Write resistor value into log */ - if (bands_n != 1) { - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistance: %.2E ± %i%% Ohm", - resistance, tolerance); - } else { - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistance: 0 Ohm"); - } - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Measure time */ - clock_stop("Calculate resistance & tolerance"); - } - /* Check STD value */ - { - /* Measure time */ - clock_start(); - - status = chk_std_value(); - if (status) { - result_resistor(status); - return status; - } - - /* Measure time */ - clock_stop("Chk STD values"); - } - - status = RESISTOR_OK; - result_resistor(status); - return status; -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_resistor (int status) -{ - /* Write result into log */ - switch (status) { - case RESISTOR_OK: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistor: OK"); - break; - case RESISTOR_NOK_RESISTOR: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistor: NOK_RESISTOR"); - break; - case RESISTOR_NOK_BANDS: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistor: NOK_BANDS"); - break; - case RESISTOR_NOK_COLOR: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistor: NOK_COLOR"); - break; - case RESISTOR_NOK_STD_VALUE: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistor: NOK_STD_VALUE"); - break; - case RESISTOR_NOK_TOLERANCE: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistor: NOK_TOLERANCE"); - break; - default: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistor: NOK"); - break; - } - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - -static int resistor_find (void) -{ - int status; - - proc_load_mem(0); - - /* BGR -> HSV */ - proc_cvt_color(cv::COLOR_BGR2HSV); - proc_save_mem(19); - - proc_cmp(IMG_IFACE_CMP_SATURATION); - proc_smooth(IMGI_SMOOTH_MEDIAN, 7); - proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); - proc_save_mem(1); - proc_dilate_erode(10); - proc_contours(&contours, &hierarchy); - - /* If no contour is found, error: NOK_RESISTOR */ - if (!contours.size()) { - status = RESISTOR_NOK_RESISTOR; - return status; - } - - proc_min_area_rect(&(contours[0]), &rect_rot, true); - - /* If angle is < -45º, it is taking into acount the incorrect side */ - if (rect_rot.angle < -45.0) { - rect_rot.angle += 90.0; - } - - status = RESISTOR_OK; - return status; -} - -static void resistor_align (void) -{ - proc_load_mem(19); - proc_rotate(rect_rot.center.x, rect_rot.center.y, rect_rot.angle); - proc_save_mem(2); - proc_load_mem(1); - proc_rotate(rect_rot.center.x, rect_rot.center.y, rect_rot.angle); - proc_save_mem(3); -} - -static void resistor_dimensions_0 (void) -{ - proc_load_mem(3); - - proc_dilate_erode(10); - proc_contours(&contours, &hierarchy); - proc_bounding_rect(&(contours[0]), &rect, true); -} - -static void resistor_crop_0 (void) -{ - int x; - int y; - int w; - int h; - - proc_load_mem(2); - - w = rect.width; - h = rect.height; - x = rect.x; - y = rect.y; - proc_ROI(x, y, w, h); - proc_save_mem(4); -} - -static void resistor_bkgd (void) -{ - uint8_t bkgd_hue; - uint8_t bkgd_sat; - - /* hue */ - proc_load_mem(4); - proc_cmp(IMG_IFACE_CMP_HUE); - proc_median_vertical(); - proc_median_horizontal(); - proc_pixel_get(0, 0, &bkgd_hue); - - /* saturation */ - proc_load_mem(4); - proc_cmp(IMG_IFACE_CMP_SATURATION); - proc_median_vertical(); - proc_median_horizontal(); - proc_pixel_get(0, 0, &bkgd_sat); - - if (bkgd_hue < 50) { - /* Beige */ - bkgd = 0; - } else { - /* Blue */ - if ((bkgd_hue < 90) || (bkgd_sat < 100)) { - /* Teal blue */ - bkgd = 1; - } else if (bkgd_hue >= 105) { - /* Dark blue */ - bkgd = 2; - } else { - /* Normal blue */ - bkgd = 3; - } - } -} - -static void resistor_dimensions_1 (void) -{ - proc_load_mem(3); - - proc_dilate_erode(10); - proc_erode_dilate((rect.height * 0.67) / 2); - proc_contours(&contours, &hierarchy); - proc_bounding_rect(&(contours[0]), &rect, true); -} - -static void resistor_crop_1 (void) -{ - int x; - int y; - int w; - int h; - - proc_load_mem(2); - - w = rect.width * 0.95; - h = rect.height * 0.8; - x = rect.x + w * (1.0 - 0.95) / 2.0; - y = rect.y + h * (1.0 - 0.8) / 2.0; - proc_ROI(x, y, w, h); - proc_save_mem(4); -} - -static void separate_bkgd_bands_h (void) -{ - proc_load_mem(4); - - proc_cmp(IMG_IFACE_CMP_HUE); - proc_median_vertical(); - proc_save_mem(9); - - switch (bkgd) { - case 0: - proc_threshold(cv::THRESH_TOZERO_INV, 20); - proc_threshold(cv::THRESH_TOZERO, 5); - break; - case 1: - proc_threshold(cv::THRESH_TOZERO_INV, 100); - proc_threshold(cv::THRESH_TOZERO, 70); - break; - case 2: - proc_threshold(cv::THRESH_TOZERO_INV, 115); - proc_threshold(cv::THRESH_TOZERO, 100); - break; - case 3: - proc_threshold(cv::THRESH_TOZERO_INV, 110); - proc_threshold(cv::THRESH_TOZERO, 90); - break; - } - proc_threshold(cv::THRESH_BINARY_INV, 1); - proc_save_mem(5); -} - -static void separate_bkgd_bands_s (void) -{ - proc_load_mem(4); - - proc_cmp(IMG_IFACE_CMP_SATURATION); - proc_median_vertical(); - proc_save_mem(10); - - switch (bkgd) { - - case 0: - proc_threshold(cv::THRESH_TOZERO_INV, 160); - proc_threshold(cv::THRESH_TOZERO, 110); - break; - case 1: - proc_threshold(cv::THRESH_TOZERO_INV, 180); - proc_threshold(cv::THRESH_TOZERO, 30); - break; - case 2: - proc_threshold(cv::THRESH_TOZERO_INV, 190); - proc_threshold(cv::THRESH_TOZERO, 170); - break; - case 3: - proc_threshold(cv::THRESH_TOZERO_INV, 210); - proc_threshold(cv::THRESH_TOZERO, 120); - break; - } - proc_threshold(cv::THRESH_BINARY_INV, 1); - proc_save_mem(6); -} - -static void separate_bkgd_bands_v (void) -{ - proc_load_mem(4); - - proc_cmp(IMG_IFACE_CMP_VALUE); - proc_median_vertical(); - proc_save_mem(11); - - switch (bkgd) { - case 0: - proc_threshold(cv::THRESH_TOZERO_INV, 170); - proc_threshold(cv::THRESH_TOZERO, 100); - break; - - case 1: - proc_threshold(cv::THRESH_TOZERO_INV, 180); - proc_threshold(cv::THRESH_TOZERO, 100); - break; - case 2: - proc_threshold(cv::THRESH_TOZERO_INV, 180); - proc_threshold(cv::THRESH_TOZERO, 150); - break; - case 3: - proc_threshold(cv::THRESH_TOZERO_INV, 190); - proc_threshold(cv::THRESH_TOZERO, 90); - break; - } - proc_threshold(cv::THRESH_BINARY_INV, 1); - proc_save_mem(7); -} - -static void bkgd_find (void) -{ - /* Merge the components: H | S | V */ - proc_load_mem(7); - proc_save_ref(); - proc_load_mem(6); - proc_or_2ref(); - proc_save_ref(); - proc_load_mem(5); - proc_or_2ref(); - if (rect.width * 0.95 > 80) { - proc_dilate_erode(1); - } - proc_save_mem(8); -} - -static int bands_find (void) -{ - int status; - - proc_load_mem(8); - - /* Contours */ - proc_contours(&contours, &hierarchy); - if (contours.size() > 5) { - proc_load_mem(8); - proc_dilate_erode(1); - proc_contours(&contours, &hierarchy); - } - - bands_n = contours.size(); - if ((bands_n == 0) || (bands_n == 2) || (bands_n > 5)) { - status = RESISTOR_NOK_BANDS; - return status; - } - - /* Band 0 (hundreds) */ - if (bands_n == 5) { - proc_bounding_rect(&(contours[4]), &rect, true); - bands[0].x = rect.x + rect.width / 2.0; - bands[0].y = rect.y + rect.height / 2.0; - } - - /* Band 1 (tens) */ - if (bands_n >= 3) { - if (bands_n > 3) { - proc_bounding_rect(&(contours[3]), &rect, true); - } else { - proc_bounding_rect(&(contours[2]), &rect, true); - } - bands[1].x = rect.x + rect.width / 2.0; - bands[1].y = rect.y + rect.height / 2.0; - } - - /* Band 2 (units) */ - if (bands_n > 3) { - proc_bounding_rect(&(contours[2]), &rect, true); - } else if (bands_n == 3) { - proc_bounding_rect(&(contours[1]), &rect, true); - } else { /* bands_n == 1 */ - proc_bounding_rect(&(contours[0]), &rect, true); - } - bands[2].x = rect.x + rect.width / 2.0; - bands[2].y = rect.y + rect.height / 2.0; - - /* Band 3 (multiplier) */ - if (bands_n >= 3) { - if (bands_n > 3) { - proc_bounding_rect(&(contours[1]), &rect, true); - } else { - proc_bounding_rect(&(contours[0]), &rect, true); - } - bands[3].x = rect.x + rect.width / 2.0; - bands[3].y = rect.y + rect.height / 2.0; - } - - /* Band 4 (tolerance) */ - if (bands_n > 3) { - proc_bounding_rect(&(contours[0]), &rect, true); - bands[4].x = rect.x + rect.width / 2.0; - bands[4].y = rect.y + rect.height / 2.0; - } - - status = RESISTOR_OK; - return status; -} - -static void bands_colors (void) -{ - /* Hue */ - proc_load_mem(9); - if (bands_n == 5) { - proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].h)); - } - if (bands_n >= 3) { - proc_pixel_get(bands[1].x, bands[1].y, &(bands[1].h)); - } - proc_pixel_get(bands[2].x, bands[2].y, &(bands[2].h)); - if (bands_n >= 3) { - proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].h)); - } - if (bands_n > 3) { - proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].h)); - } - - /* Saturation */ - proc_load_mem(10); - if (bands_n == 5) { - proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].s)); - } - if (bands_n >= 3) { - proc_pixel_get(bands[1].x, bands[1].y, &(bands[1].s)); - } - proc_pixel_get(bands[2].x, bands[2].y, &(bands[2].s)); - if (bands_n >= 3) { - proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].s)); - } - if (bands_n > 3) { - proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].s)); - } - - /* Value */ - proc_load_mem(11); - if (bands_n == 5) { - proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].v)); - } - if (bands_n >= 3) { - proc_pixel_get(bands[1].x, bands[1].y, &(bands[1].v)); - } - proc_pixel_get(bands[2].x, bands[2].y, &(bands[2].v)); - if (bands_n >= 3) { - proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].v)); - } - if (bands_n > 3) { - proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].v)); - } -} - -static void bands_code (void) -{ - int i; - - /* Init to 0 */ - for (i = 0; i < 6; i++) { - code[i] = '\0'; - } - - /* Band 0 (hundreds) */ - if (bands_n == 5) { - code[0] = band_hsv2code(&bands[0]); - } else { - code[0] = 'n'; - } - - - /* Band 1 (tens) */ - if (bands_n != 1) { - code[1] = band_hsv2code(&bands[1]); - } else { - code[1] = 'n'; - } - - /* Band 2 (units) */ - code[2] = band_hsv2code(&bands[2]); - - /* Band 3 (multiplier) */ - if (bands_n != 1) { - code[3] = band_hsv2code(&bands[3]); - } else { - code[3] = 'n'; - } - - /* Band 4 (tolerance) */ - if (bands_n > 3) { - code[4] = band_hsv2code(&bands[4]); - } else { - code[4] = 'n'; - } - - /* 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)++; -} - -static char band_hsv2code (struct Resistor_Bands *band) -{ - char ch; - - /* - * Not able to segmentate: - * q = 1 2 - * w = 2 3 - * e = 3 g - * r = 3 4 - * t = 1 8 - * y = 0 1 - * u = 0 1 8 - */ - - if (band->h < 10) { - // 1 2 3 - if (band->s < 90) { - // 1 3 - if (band->v < 85) { - ch = '1'; - } else { - ch = '3'; - } - } else if (band->s < 140) { - // 1 2 3 - if (band->v < 60) { - ch = '1'; - } else if (band->v < 85) { - // 1 2 - ch = 'q'; - } else if (band->v < 90) { - ch = '2'; - } else if (band->v < 150) { - // 2 3 - ch = 'w'; - } else { - ch = '3'; - } - } else if (band->s < 210) { - // 2 3 - if (band->v < 90) { - ch = '2'; - } else if (band->v < 150) { - // 2 3 - ch = 'w'; - } else { - ch = '3'; - } - } else { - ch = '3'; - } - } else if (band->h < 35) { - // 1 3 g - if (band->s < 130) { - // 1 3 - if (band->v < 85) { - ch = '1'; - } else { - ch = '3'; - } - } else if (band->s < 140) { - // 1 3 g - if (band->v < 85) { - ch = '1'; - } else if (band->v < 120) { - ch = '3'; - } else { - // 3 g - ch = 'e'; - } - } else if (band->s < 180) { - // 3 g - if (band->v < 120) { - ch = '3'; - } else { - // 3 g - ch = 'e'; - } - } else { - ch = '3'; - } - } else if (band->h < 50) { - // 1 3 - if (band->s < 140) { - // 1 3 - if (band->v < 85) { - ch = '1'; - } else { - ch = '3'; - } - } else { - ch = '3'; - } - } else if (band->h < 60) { - // 1 3 4 - if (band->s < 140) { - // 1 3 - if (band->v < 85) { - ch = '1'; - } else { - ch = '3'; - } - } else if (band->s < 160) { - ch = '3'; - } else if (band->s < 180) { - // 3 4 - if (band->v < 110) { - // 3 4 - ch = 'r'; - } else { - ch = '3'; - } - } else { - ch = '3'; - } - } else if (band->h < 80) { - // 1 5 - if (band->s < 165) { - ch = '1'; - } else { - ch = '5'; - } - } else if (band->h < 90) { - ch = '1'; - } else if (band->h < 100) { - // 0 1 8 9 - if (band->s < 40) { - // 1 8 9 - if (band->v < 55) { - ch = '1'; - } else if (band->v < 80) { - // 1 8 - ch = 't'; - } else if (band->v < 125) { - ch = '1'; - } else { - ch = '9'; - } - } else if (band->s < 70) { - // 0 1 8 9 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 55) { - // 0 1 - ch = 'y'; - } else if (band->v < 75) { - // 0 1 8 - ch = 'u'; - } else if (band->v < 80) { - // 1 8 - ch = 't'; - } else if (band->v < 125) { - ch = '1'; - } else { - ch = '9'; - } - } else if (band->s < 100) { - // 0 1 8 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 55) { - // 0 1 - ch = 'y'; - } else if (band->v < 75) { - // 0 1 8 - ch = 'u'; - } else if (band->v < 80) { - // 1 8 - ch = 't'; - } else { - ch = '1'; - } - } else if (band->s < 140) { - // 0 1 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else { - ch = '1'; - } - } else { - ch = '0'; - } - } else if (band->h < 110) { - // 0 1 6 8 - if (band->s < 40) { - // 1 8 - if (band->v < 55) { - ch = '1'; - } else if (band->v < 80) { - // 1 8 - ch = 't'; - } else { - ch = '1'; - } - } else if (band->s < 100) { - // 0 1 8 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 55) { - // 0 1 - ch = 'y'; - } else if (band->v < 75) { - // 0 1 8 - ch = 'u'; - } else if (band->v < 80) { - // 1 8 - ch = 't'; - } else { - ch = '1'; - } - } else if (band->s < 140) { - // 0 1 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else { - ch = '1'; - } - } else if (band->s < 200) { - ch = '0'; - } else { - ch = '6'; - } - } else if (band->h < 120) { - // 0 1 6 7 - if (band->s < 40) { - ch = '1'; - } else if (band->s < 90) { - // 0 1 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else { - ch = '1'; - } - } else if (band->s < 110) { - // 0 1 7 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else if (band->v < 120) { - ch = '1'; - } else { - ch = '7'; - } - } else if (band->s < 140) { - // 0 1 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else { - ch = '1'; - } - } else if (band->s < 200) { - ch = '0'; - } else { - ch = '6'; - } - } else if (band->h < 130) { - // 0 1 7 - if (band->s < 40) { - ch = '1'; - } else if (band->s < 90) { - // 0 1 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else { - ch = '1'; - } - } else if (band->s < 110) { - // 0 1 7 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else if (band->v < 120) { - ch = '1'; - } else { - ch = '7'; - } - } else if (band->s < 140) { - // 0 1 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else { - ch = '1'; - } - } else { - ch = '0'; - } - } else if (band->h < 140) { - // 0 1 - if (band->s < 40) { - ch = '1'; - } else if (band->s < 140) { - // 0 1 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else { - ch = '1'; - } - } else { - ch = '0'; - } - } else if (band->h < 150) { - ch = '0'; - } else { - ch = '2'; - } - - return ch; -} - -static void bands_code_deduce_0 (void) -{ - /* - * Not able to segmentate: - * q = 1 2 - * w = 2 3 - * e = 3 g - * r = 3 4 - * t = 1 8 - * y = 0 1 - * u = 0 1 8 - */ - - /* Band 0 (hundreds) */ - switch (code[0]) { - case 'e': - code[0] = '3'; - break; - case 'y': - code[0] = '1'; - break; - case 'u': - code[0] = 't'; - break; - } - - /* Band 2 (units) */ - switch (code[2]) { - case 'e': - code[2] = '3'; - break; - } - - /* Band 3 (multiplier) */ - switch (code[3]) { - case 't': - code[3] = '1'; - break; - case 'u': - code[3] = 'y'; - break; - } - - /* Band 4 (tolerance) */ - switch (code[4]) { - case 'w': - code[4] = '2'; - break; - case 'e': - code[4] = 'g'; - break; - case 't': - code[4] = '1'; - break; - case 'y': - code[4] = '1'; - break; - case 'u': - code[4] = '1'; - break; - } - - /* 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)++; -} - -static void bands_code_deduce_1 (void) -{ - /* - * Not able to segmentate: - - * q = 1 2 - * w = 2 3 - * e = 3 g - * r = 3 4 - * t = 1 8 - * y = 0 1 - - * u = 0 1 8 - */ - - /* Band 0 (hundreds) */ - switch (code[0]) { - case 'q': - switch (code[1]) { - case '1': - case '3': - case '5': - case '6': - case '8': - code[0] = '1'; - break; - case '2': - case '4': - case '7': - code[0] = '2'; - break; - case '0': - // q - break; - } - break; - case 'w': - switch (code[1]) { - case '2': - case '4': - case '7': - code[0] = '2'; - break; - case '3': - case '6': - case '9': - code[0] = '3'; - break; - case '0': - // w - break; - } - break; - case 'r': - switch (code[1]) { - case '0': - case '6': - case '9': - code[0] = '3'; - break; - case '7': - code[0] = '4'; - break; - case '3': - // r - break; - } - break; - case 't': - switch (code[1]) { - case '0': - case '1': - case '3': - case '5': - case '6': - case '8': - code[0] = '1'; - break; - case '2': - // t - break; - } - break; - } - - /* Band 1 (tens) */ - switch (code[1]) { - case 'q': - switch (code[0]) { - case '5': - case '9': - code[1] = '1'; - break; - case '2': - case '6': - case '8': - code[1] = '2'; - break; - case '1': - // q - break; - } - break; - case 'w': - switch (code[0]) { - case '2': - case '6': - case '8': - code[1] = '2'; - break; - case '3': - case '4': - code[1] = '3'; - break; - case '1': - // w - break; - } - break; - case 't': - switch (code[0]) { - case '5': - case '9': - code[1] = '1'; - break; - case '6': - code[1] = '8'; - break; - case '1': - // t - break; - } - break; - case 'y': - switch (code[0]) { - case '2': - case '3': - code[1] = '0'; - break; - case '5': - case '9': - code[1] = '1'; - break; - case '1': - // y - break; - } - break; - case 'u': - switch (code[0]) { - case '2': - case '3': - code[1] = '0'; - break; - case '5': - case '9': - code[1] = '1'; - break; - case '6': - code[1] = '8'; - break; - case '1': - // u - break; - } - break; - } - - /* Band 2 (units) */ - switch (code[2]) { - case 'y': - code[2] = '0'; - break; - case 'u': - code[2] = '0'; - break; - } - - /* Band 3 (multiplier) */ - switch (code[3]) { - case 'y': - code[3] = '0'; - break; - } - - /* Band 4 (tolerance) */ - switch (code[4]) { - case 'q': - code[4] = '2'; - break; - } - - /* 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)++; -} - -static int bands_code_deduce_no (void) -{ - int status; - int i; - - /* - * Not able to segmentate: - * q = 1 2 - * w = 2 3 - * e = 3 g - * r = 3 4 - * t = 1 8 - * y = 0 1 - * u = 0 1 8 - */ - - for (i = 0; i < 5; i++) { - switch (code[i]) { - case 'q': - case 'w': - case 'e': - case 'r': - case 't': - case 'y': - case 'u': - code[i] = '?'; - break; - } - } - - for (i = 0; i < 5; i++) { - if (code[i] == '?') { - status = RESISTOR_NOK_COLOR; - return status; - } - } - - /* 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)++; - - status = RESISTOR_OK; - return status; -} - -static void resistor_value (void) -{ - int power; - - /* Base value */ - base = code[2] - '0'; - if (code[1] != 'n') { - base += (code[1] - '0') * 10; - } - if (code[0] != 'n') { - base += (code[0] - '0') * 100; - } - - /* Calculate resistance */ - if ((code[3] > '0') && (code[3] < '9')) { - power = code[3] - '0'; - } else if (code[3] == 'g') { - power = -1; - } else if (code[3] == 's') { - power = -2; - } else { - // error - return; - } - resistance = base * pow(10, power); -} - -static int resistor_tolerance (void) -{ - int status; - - if (bands_n != 1) { - switch (code[4]) { - case '1': - tolerance = 1; - break; - case '2': - tolerance = 2; - break; - case '4': - case 'g': - case 'n': - tolerance = 5; - break; - case '8': - tolerance = 10; - break; - default: - status = RESISTOR_NOK_TOLERANCE; - return status; - } - } - - status = RESISTOR_OK; - return status; -} - -static int chk_std_value (void) -{ - int status; - /* Check that base value is a standard value */ - int std_values_10 [12] = {10,12,15,18,22,27,33,39,47,56,68,82}; - int std_values_5 [12] = {11,13,16,20,24,30,36,43,51,62,75,91}; - bool std_value_nok = true; - int i; - - if (bands_n != 1) { - for (i = 0; i < 12; i++) { - if (base == std_values_10[i]) { - std_value_nok = false; - } - if (base == (std_values_10[i] * 10)) { - std_value_nok = false; - } - } - if (tolerance <= 5) { - for (i = 0; i < 12; i++) { - if (base == std_values_5[i]) { - std_value_nok = false; - } - if (base == (std_values_5[i] * 10)) { - std_value_nok = false; - } - } - } - } else { - if (base == 0) { - std_value_nok = false; - } - } - - if (std_value_nok) { - status = RESISTOR_NOK_STD_VALUE; - return status; - } - - status = RESISTOR_OK; - return status; -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/tmp/Makefile b/modules/proc/tmp/Makefile deleted file mode 100644 index 531b63e..0000000 --- a/modules/proc/tmp/Makefile +++ /dev/null @@ -1,177 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -LIBALX_INC_DIR = $(LIBALX_DIR)/inc/ - -IMG_INC_DIR = $(IMG_DIR)/inc/ -SAVE_INC_DIR = $(SAVE_DIR)/inc/ -USR_INC_DIR = $(USR_DIR)/inc/ - -INC_DIR = $(PROC_DIR)/inc/ -SRC_DIR = $(PROC_DIR)/src/ - -# dependencies - -_ALL = proc_label.o proc_lighters.o proc_objects.o \ - proc_coins.o proc_resistor.o \ - proc_common.o proc_iface.o -ALL = $(_ALL) proc_mod.o - -PROC_LAB_INC_IMG = img_iface.hpp -PROC_LAB_INC_USR = user_iface.hpp -PROC_LAB_INC = proc_label.hpp proc_common.hpp -PROC_LAB_DEPS = $(SRC_DIR)/proc_label.cpp \ - $(patsubst %,$(INC_DIR)/%,$(PROC_LAB_INC)) \ - $(patsubst %,$(IMG_INC_DIR)/%,$(PROC_LAB_INC_IMG)) \ - $(patsubst %,$(USR_INC_DIR)/%,$(PROC_LAB_INC_USR)) -PROC_LAB_INC_DIRS = -I $(INC_DIR) \ - -I $(IMG_INC_DIR) \ - -I $(USR_INC_DIR) - -PROC_LGHT_INC_LIBALX = libalx/alx_math.hpp -PROC_LGHT_INC_IMG = img_iface.hpp -PROC_LGHT_INC_USR = user_iface.hpp -PROC_LGHT_INC = proc_lighters.hpp proc_common.hpp -PROC_LGHT_DEPS = $(SRC_DIR)/proc_lighters.cpp \ - $(patsubst %,$(INC_DIR)/%,$(PROC_LGHT_INC)) \ - $(patsubst %,$(IMG_INC_DIR)/%,$(PROC_LGHT_INC_IMG)) \ - $(patsubst %,$(USR_INC_DIR)/%,$(PROC_LGHT_INC_USR)) \ - $(patsubst %,$(LIBALX_INC_DIR)/%,$(PROC_LGHT_INC_LIBALX)) -PROC_LGHT_INC_DIRS = -I $(INC_DIR) \ - -I $(IMG_INC_DIR) \ - -I $(USR_INC_DIR) \ - -I $(LIBALX_INC_DIR) - -PROC_OBJS_INC_LIBALX = libalx/alx_math.hpp -PROC_OBJS_INC_IMG = img_iface.hpp -PROC_OBJS_INC_USR = user_iface.hpp -PROC_OBJS_INC = proc_objects.hpp proc_common.hpp -PROC_OBJS_DEPS = $(SRC_DIR)/proc_objects.cpp \ - $(patsubst %,$(INC_DIR)/%,$(PROC_OBJS_INC)) \ - $(patsubst %,$(IMG_INC_DIR)/%,$(PROC_OBJS_INC_IMG)) \ - $(patsubst %,$(USR_INC_DIR)/%,$(PROC_OBJS_INC_USR)) \ - $(patsubst %,$(LIBALX_INC_DIR)/%,$(PROC_OBJS_INC_LIBALX)) -PROC_OBJS_INC_DIRS = -I $(INC_DIR) \ - -I $(IMG_INC_DIR) \ - -I $(USR_INC_DIR) \ - -I $(LIBALX_INC_DIR) - -PROC_COIN_INC_LIBALX = libalx/alx_math.hpp -PROC_COIN_INC_IMG = img_iface.hpp -PROC_COIN_INC_USR = user_iface.hpp -PROC_COIN_INC = proc_coins.hpp proc_common.hpp -PROC_COIN_DEPS = $(SRC_DIR)/proc_coins.cpp \ - $(patsubst %,$(INC_DIR)/%,$(PROC_COIN_INC)) \ - $(patsubst %,$(IMG_INC_DIR)/%,$(PROC_COIN_INC_IMG)) \ - $(patsubst %,$(USR_INC_DIR)/%,$(PROC_COIN_INC_USR)) \ - $(patsubst %,$(LIBALX_INC_DIR)/%,$(PROC_COIN_INC_LIBALX)) -PROC_COIN_INC_DIRS = -I $(INC_DIR) \ - -I $(IMG_INC_DIR) \ - -I $(USR_INC_DIR) \ - -I $(LIBALX_INC_DIR) - -PROC_RES_INC_IMG = img_iface.hpp -PROC_RES_INC_USR = user_iface.hpp -PROC_RES_INC = proc_resistor.hpp proc_common.hpp -PROC_RES_DEPS = $(SRC_DIR)/proc_resistor.cpp \ - $(patsubst %,$(INC_DIR)/%,$(PROC_RES_INC)) \ - $(patsubst %,$(IMG_INC_DIR)/%,$(PROC_RES_INC_IMG)) \ - $(patsubst %,$(USR_INC_DIR)/%,$(PROC_RES_INC_USR)) -PROC_RES_INC_DIRS = -I $(INC_DIR) \ - -I $(IMG_INC_DIR) \ - -I $(USR_INC_DIR) - -PROC_CMN_INC_IMG = img_iface.hpp -PROC_CMN_INC_USR = user_iface.hpp -PROC_CMN_INC = proc_common.hpp -PROC_CMN_DEPS = $(SRC_DIR)/proc_common.cpp \ - $(patsubst %,$(INC_DIR)/%,$(PROC_CMN_INC)) \ - $(patsubst %,$(IMG_INC_DIR)/%,$(PROC_CMN_INC_IMG)) \ - $(patsubst %,$(USR_INC_DIR)/%,$(PROC_CMN_INC_USR)) -PROC_CMN_INC_DIRS = -I $(INC_DIR) \ - -I $(IMG_INC_DIR) \ - -I $(USR_INC_DIR) - -PROC_IFACE_INC_LIBALX = libalx/io/alx_input.h -PROC_IFACE_INC_IMG = img_iface.h -PROC_IFACE_INC_SAVE = save.h -PROC_IFACE_INC_USR = user_iface.h -PROC_IFACE_INC = proc_iface.h proc_label.h proc_coins.h proc_resistor.h -PROC_IFACE_DEPS = $(SRC_DIR)/proc_iface.c \ - $(patsubst %,$(INC_DIR)/%,$(PROC_IFACE_INC)) \ - $(patsubst %,$(IMG_INC_DIR)/%,$(PROC_IFACE_INC_IMG)) \ - $(patsubst %,$(SAVE_INC_DIR)/%,$(PROC_IFACE_INC_SAVE)) \ - $(patsubst %,$(USR_INC_DIR)/%,$(PROC_IFACE_INC_USR)) \ - $(patsubst %,$(LIBALX_INC_DIR)/%,$(PROC_IFACE_INC_LIBALX)) -PROC_IFACE_INC_DIRS = -I $(INC_DIR) \ - -I $(IMG_INC_DIR) \ - -I $(SAVE_INC_DIR) \ - -I $(USR_INC_DIR) \ - -I $(LIBALX_INC_DIR) - -# target: dependencies -# action - -all: $(ALL) - - -proc_mod.o: $(_ALL) - $(Q)$(LD) -r $^ -o $@ - @echo " LD $@" - - -proc_label.s: $(PROC_LAB_DEPS) - $(Q)$(CXX) $(CXXFLAGS) $(PROC_LAB_INC_DIRS) -S $< -o $@ - @echo " CXX $@" -proc_label.o: proc_label.s $(PROC_LAB_DEPS) - $(Q)$(AS) $< -o $@ - @echo " AS $@" - -proc_lighters.s: $(PROC_LGHT_DEPS) - $(Q)$(CXX) $(CXXFLAGS) $(PROC_LGHT_INC_DIRS) -S $< -o $@ - @echo " CXX $@" -proc_lighters.o: proc_lighters.s $(PROC_LGHT_DEPS) - $(Q)$(AS) $< -o $@ - @echo " AS $@" - -proc_objects.s: $(PROC_OBJS_DEPS) - $(Q)$(CXX) $(CXXFLAGS) $(PROC_OBJS_INC_DIRS) -S $< -o $@ - @echo " CXX $@" -proc_objects.o: proc_objects.s $(PROC_OBJS_DEPS) - $(Q)$(AS) $< -o $@ - @echo " AS $@" - -proc_coins.s: $(PROC_COIN_DEPS) - $(Q)$(CXX) $(CXXFLAGS) $(PROC_COIN_INC_DIRS) -S $< -o $@ - @echo " CXX $@" -proc_coins.o: proc_coins.s $(PROC_COIN_DEPS) - $(Q)$(AS) $< -o $@ - @echo " AS $@" - -proc_resistor.s: $(PROC_RES_DEPS) - $(Q)$(CXX) $(CXXFLAGS) $(PROC_RES_INC_DIRS) -S $< -o $@ - @echo " CXX $@" -proc_resistor.o: proc_resistor.s $(PROC_RES_DEPS) - $(Q)$(AS) $< -o $@ - @echo " AS $@" - -proc_common.s: $(PROC_CMN_DEPS) - $(Q)$(CXX) $(CXXFLAGS) $(PROC_CMN_INC_DIRS) -S $< -o $@ - @echo " CXX $@" -proc_common.o: proc_common.s $(PROC_CMN_DEPS) - $(Q)$(AS) $< -o $@ - @echo " AS $@" - -proc_iface.s: $(PROC_IFACE_DEPS) - $(Q)$(CC) $(CFLAGS) $(PROC_IFACE_INC_DIRS) -S $< -o $@ - @echo " CC $@" -proc_iface.o: proc_iface.s $(PROC_IFACE_DEPS) - $(Q)$(AS) $< -o $@ - @echo " AS $@" - - -clean: - $(Q)rm -f *.o *.s diff --git a/modules/save/Makefile b/modules/save/Makefile deleted file mode 100644 index 614a58c..0000000 --- a/modules/save/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -TMP_DIR = $(SAVE_DIR)/tmp/ - -# target: dependencies -# action - -all: - $(Q)cd $(TMP_DIR) && $(MAKE) && cd .. - -clean: - $(Q)cd $(TMP_DIR) && $(MAKE) clean && cd .. - -################################################################################ -######## End of file ########################################################### -################################################################################ -######## End of file ########################################################### -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/modules/save/inc/save.h b/modules/save/inc/save.h deleted file mode 100644 index 4ab65ab..0000000 --- a/modules/save/inc/save.h +++ /dev/null @@ -1,79 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_SAVE_H - # define VA_SAVE_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* FILENAME_MAX */ - #include <stdio.h> - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define ENV_HOME "HOME" - - # define USER_PROG_DIR "vision-artificial/" - # define USER_SAVED_DIR "vision-artificial/saved/" - # define USER_LABELS_DIR "vision-artificial/labels/" - # define USER_LABELS_FAIL_DIR "vision-artificial/labels/fail" - # define USER_LIGHTERS_DIR "vision-artificial/lighters/" - # define USER_LIGHTERS_FAIL_DIR "vision-artificial/lighters/fail" - # define USER_OBJECTS_DIR "vision-artificial/objects/" - # define USER_OBJECTS_FAIL_DIR "vision-artificial/objects/fail" - # define USER_COINS_DIR "vision-artificial/coins/" - # define USER_COINS_FAIL_DIR "vision-artificial/coins/fail" - # define USER_RESISTORS_DIR "vision-artificial/resistors/" - # define USER_RESISTORS_FAIL_DIR "vision-artificial/resistors/fail" - # define SAVED_NAME_DEFAULT "saved" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern char home_path [FILENAME_MAX]; -extern char user_prog_path [FILENAME_MAX]; -extern char saved_path [FILENAME_MAX]; -extern char labels_path [FILENAME_MAX]; -extern char labels_fail_path [FILENAME_MAX]; -extern char lighters_path [FILENAME_MAX]; -extern char lighters_fail_path [FILENAME_MAX]; -extern char objects_path [FILENAME_MAX]; -extern char objects_fail_path [FILENAME_MAX]; -extern char coins_path [FILENAME_MAX]; -extern char coins_fail_path [FILENAME_MAX]; -extern char resistors_path [FILENAME_MAX]; -extern char resistors_fail_path [FILENAME_MAX]; -extern char saved_name [FILENAME_MAX]; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void save_init (void); -void save_cleanup (void); -void save_clr (void); -void load_image_file (const char *fpath, const char *fname); -void save_image_file (const char *fpath, const char *save_as); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* save.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/save/inc/save.hpp b/modules/save/inc/save.hpp deleted file mode 100644 index bf60bca..0000000 --- a/modules/save/inc/save.hpp +++ /dev/null @@ -1,96 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_SAVE_HPP - # define VA_SAVE_HPP - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* FILENAME_MAX */ - #include <cstdio> - -/* Project -------------------------------------------------------------------*/ - /* opencv */ - #include <opencv2/opencv.hpp> - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define ENV_HOME "HOME" - - # define USER_PROG_DIR "vision-artificial/" - # define USER_SAVED_DIR "vision-artificial/saved/" - # define USER_LABELS_DIR "vision-artificial/labels/" - # define USER_LABELS_FAIL_DIR "vision-artificial/labels/fail" - # define USER_LIGHTERS_DIR "vision-artificial/lighters/" - # define USER_LIGHTERS_FAIL_DIR "vision-artificial/lighters/fail" - # define USER_OBJECTS_DIR "vision-artificial/objects/" - # define USER_OBJECTS_FAIL_DIR "vision-artificial/objects/fail" - # define USER_COINS_DIR "vision-artificial/coins/" - # define USER_COINS_FAIL_DIR "vision-artificial/coins/fail" - # define USER_RESISTORS_DIR "vision-artificial/resistors/" - # define USER_RESISTORS_FAIL_DIR "vision-artificial/resistors/fail" - # define SAVED_NAME_DEFAULT "saved" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern class cv::Mat image; -extern char home_path [FILENAME_MAX]; -extern char user_prog_path [FILENAME_MAX]; -extern char saved_path [FILENAME_MAX]; -extern char labels_path [FILENAME_MAX]; -extern char labels_fail_path [FILENAME_MAX]; -extern char lighters_path [FILENAME_MAX]; -extern char lighters_fail_path [FILENAME_MAX]; -extern char objects_path [FILENAME_MAX]; -extern char objects_fail_path [FILENAME_MAX]; -extern char coins_path [FILENAME_MAX]; -extern char coins_fail_path [FILENAME_MAX]; -extern char resistors_path [FILENAME_MAX]; -extern char resistors_fail_path [FILENAME_MAX]; -extern char saved_name [FILENAME_MAX]; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void save_init (void); -void save_cleanup (void); -void save_clr (void); -void load_image_file (const char *fpath, const char *fname); -void save_image_file (const char *fpath, const char *save_as); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* save.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/save/src/save.cpp b/modules/save/src/save.cpp deleted file mode 100644 index 30d3376..0000000 --- a/modules/save/src/save.cpp +++ /dev/null @@ -1,289 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <cerrno> - #include <cstdio> - #include <cstdlib> -/* Linux ---------------------------------------------------------------------*/ - /* mkdir */ - #include <sys/stat.h> -/* Packages ------------------------------------------------------------------*/ - #include <opencv2/opencv.hpp> -/* Project -------------------------------------------------------------------*/ - #include "user_iface.hpp" -/* Module --------------------------------------------------------------------*/ - #include "save.hpp" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - class cv::Mat image; - char home_path [FILENAME_MAX]; - char user_prog_path [FILENAME_MAX]; - char saved_path [FILENAME_MAX]; - char labels_path [FILENAME_MAX]; - char labels_fail_path [FILENAME_MAX]; - char lighters_path [FILENAME_MAX]; - char lighters_fail_path [FILENAME_MAX]; - char objects_path [FILENAME_MAX]; - char objects_fail_path [FILENAME_MAX]; - char coins_path [FILENAME_MAX]; - char coins_fail_path [FILENAME_MAX]; - char resistors_path [FILENAME_MAX]; - char resistors_fail_path [FILENAME_MAX]; - char saved_name [FILENAME_MAX]; - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -void save_init (void) -{ - int err; - - if (snprintf(home_path, FILENAME_MAX, "%s/", - getenv(ENV_HOME)) >= FILENAME_MAX) { - goto err_path; - } - if (snprintf(user_prog_path, FILENAME_MAX, "%s/%s/", - home_path, - USER_PROG_DIR) >= FILENAME_MAX) { - goto err_path; - } - if (snprintf(saved_path, FILENAME_MAX, "%s/%s/", - home_path, - USER_SAVED_DIR) >= FILENAME_MAX) { - goto err_path; - } - if (snprintf(labels_path, FILENAME_MAX, "%s/%s/", - home_path, - USER_LABELS_DIR) >= FILENAME_MAX) { - goto err_path; - } - if (snprintf(labels_fail_path, FILENAME_MAX, "%s/%s/", - home_path, - USER_LABELS_FAIL_DIR) >= FILENAME_MAX) { - goto err_path; - } - if (snprintf(lighters_path, FILENAME_MAX, "%s/%s/", - home_path, - USER_LIGHTERS_DIR) >= FILENAME_MAX) { - goto err_path; - } - if (snprintf(lighters_fail_path, FILENAME_MAX, "%s/%s/", - home_path, - USER_LIGHTERS_FAIL_DIR) >= FILENAME_MAX) { - goto err_path; - } - if (snprintf(objects_path, FILENAME_MAX, "%s/%s/", - home_path, - USER_OBJECTS_DIR) >= FILENAME_MAX) { - goto err_path; - } - if (snprintf(objects_fail_path, FILENAME_MAX, "%s/%s/", - home_path, - USER_OBJECTS_FAIL_DIR) >= FILENAME_MAX) { - goto err_path; - } - if (snprintf(coins_path, FILENAME_MAX, "%s/%s/", - home_path, - USER_COINS_DIR) >= FILENAME_MAX) { - goto err_path; - } - if (snprintf(coins_fail_path, FILENAME_MAX, "%s/%s/", - home_path, - USER_COINS_FAIL_DIR) >= FILENAME_MAX) { - goto err_path; - } - if (snprintf(resistors_path, FILENAME_MAX, "%s/%s/", - home_path, - USER_RESISTORS_DIR) >= FILENAME_MAX) { - goto err_path; - } - if (snprintf(resistors_fail_path, FILENAME_MAX, "%s/%s/", - home_path, - USER_RESISTORS_FAIL_DIR) >= FILENAME_MAX) { - goto err_path; - } - saved_name[0] = '\0'; - - err = mkdir(user_prog_path, 0700); - - if (!err) { - ; - } else { - - switch (errno) { - case EACCES: - printf("err = EACCES"); -// exit(EXIT_FAILURE); - break; - - case EEXIST: - /* OK */ - break; - - default: - printf("WTF?!"); -// exit(EXIT_FAILURE); - } - } - - mkdir(saved_path, 0700); - mkdir(labels_path, 0700); - mkdir(labels_fail_path, 0700); - - return; - - -err_path: - printf("Path is too large and has been truncated\n"); - exit(EXIT_FAILURE); -} - -void save_clr (void) -{ - - if (snprintf(saved_path, FILENAME_MAX, "%s/%s/", - home_path, - USER_SAVED_DIR) >= FILENAME_MAX) { - goto err_path; - } - - return; - - -err_path: - printf("Path is too large and has been truncated\n"); - exit(EXIT_FAILURE); -} - -void load_image_file (const char *fpath, const char *fname) -{ - char file_path [FILENAME_MAX]; - char file_name [FILENAME_MAX]; - - /* Free old image */ - image.release(); - - /* Set file_path */ - if (!fpath) { - /* Default path */ - save_clr(); - snprintf(file_path, FILENAME_MAX, "%s", saved_path); - } else { - snprintf(file_path, FILENAME_MAX, "%s", fpath); - } - - /* Set file_name */ - if (!fname) { - /* Request file name */ - user_iface_fname(file_path, saved_name); - } else { - snprintf(saved_name, FILENAME_MAX, "%s", fname); - } - - /* File name */ - if (snprintf(file_name, FILENAME_MAX, "%s/%s", - file_path, - saved_name) >= FILENAME_MAX) { - goto err_path; - } - - /* Load image */ - image = cv::imread(file_name, CV_LOAD_IMAGE_COLOR); - - /* Manage load error */ - if (image.empty()) { - printf("Could not load file: %s\n", file_name); -// exit(0); - } - - return; - - -err_path: - printf("Path is too large and has been truncated\n"); - exit(EXIT_FAILURE); -} - -void save_cleanup (void) -{ - - image.release(); -} - -void save_image_file (const char *fpath, const char *save_as) -{ - char file_path [FILENAME_MAX]; - char file_name [FILENAME_MAX]; - FILE *fp; - - /* Set file_path */ - if (!fpath) { - /* Default path */ - save_clr(); - snprintf(file_path, FILENAME_MAX, "%s", saved_path); - } else { - snprintf(file_path, FILENAME_MAX, "%s", fpath); - } - - /* Set file_name */ - if (!save_as) { - /* Default name */ - snprintf(saved_name, FILENAME_MAX, "%s", SAVED_NAME_DEFAULT); - /* Request file name */ - user_iface_fname(saved_path, saved_name); - } else { - snprintf(saved_name, FILENAME_MAX, "%s", save_as); - } - - /* Prepend the path */ - if (snprintf(file_name, FILENAME_MAX, "%s/%s", - file_path, - saved_name) >= FILENAME_MAX) { - goto err_path; - } - - fp = fopen(file_name, "r"); - if (fp) { - /* Name in use; ask once more */ - fclose(fp); - user_iface_fname(saved_path, saved_name); - if (snprintf(file_name, FILENAME_MAX, "%s/%s", - file_path, - saved_name) >= FILENAME_MAX) { - goto err_path; - } - } - - /* Write into log */ - (void)snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "%s", saved_name); - user_iface_log.lvl[user_iface_log.len] = 2; - (user_iface_log.len)++; - - - /* Write to a new file */ - cv::imwrite(file_name, image); - - return; - - -err_path: - printf("Path is too large and has been truncated\n"); - exit(EXIT_FAILURE); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/save/tmp/Makefile b/modules/save/tmp/Makefile deleted file mode 100644 index 4f2abf9..0000000 --- a/modules/save/tmp/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -USR_INC_DIR = $(USR_DIR)/inc/ - -INC_DIR = $(SAVE_DIR)/inc/ -SRC_DIR = $(SAVE_DIR)/src/ - -# dependencies - -_ALL = save.o -ALL = $(_ALL) save_mod.o - -SAVE_INC_VIEW = user_iface.hpp -SAVE_INC = save.hpp -SAVE_DEPS = $(SRC_DIR)/save.cpp \ - $(patsubst %,$(INC_DIR)/%,$(SAVE_INC)) \ - $(patsubst %,$(USR_INC_DIR)/%,$(SAVE_INC_USR)) -SAVE_INC_DIRS = -I $(INC_DIR) \ - -I $(USR_INC_DIR) - -# target: dependencies -# action - -all: $(ALL) - - -save_mod.o: $(_ALL) - $(Q)$(LD) -r $^ -o $@ - @echo " LD $@" - - -save.s: $(SAVE_DEPS) - $(Q)$(CXX) $(CXXFLAGS) $(SAVE_INC_DIRS) -S $< -o $@ - @echo " CXX $@" -save.o: save.s - $(Q)$(AS) $< -o $@ - @echo " AS $@" - - -clean: - $(Q)rm -f *.o *.s diff --git a/modules/tmp/Makefile b/modules/tmp/Makefile deleted file mode 100644 index 93693cc..0000000 --- a/modules/tmp/Makefile +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/make -f - -# MACRO = substitute with this - -# directories - -ABOUT_TMP_DIR = $(ABOUT_DIR)/tmp/ -CTRL_TMP_DIR = $(CTRL_DIR)/tmp/ -IMG_TMP_DIR = $(IMG_DIR)/tmp/ -MENU_TMP_DIR = $(MENU_DIR)/tmp/ -PROC_TMP_DIR = $(PROC_DIR)/tmp/ -SAVE_TMP_DIR = $(SAVE_DIR)/tmp/ -USR_TMP_DIR = $(USR_DIR)/tmp/ - -# dependencies - -ALL = modules.o - -MODS_OBJ_ABOUT = about_mod.o -MODS_OBJ_CTRL = ctrl_mod.o -MODS_OBJ_IMG = img_mod.o -MODS_OBJ_MENU = menu_mod.o -MODS_OBJ_PROC = proc_mod.o -MODS_OBJ_SAVE = save_mod.o -MODS_OBJ_USR = user_mod.o -MODS_OBJS = $(patsubst %,$(ABOUT_TMP_DIR)/%,$(MODS_OBJ_ABOUT)) \ - $(patsubst %,$(CTRL_TMP_DIR)/%,$(MODS_OBJ_CTRL)) \ - $(patsubst %,$(IMG_TMP_DIR)/%,$(MODS_OBJ_IMG)) \ - $(patsubst %,$(MENU_TMP_DIR)/%,$(MODS_OBJ_MENU)) \ - $(patsubst %,$(PROC_TMP_DIR)/%,$(MODS_OBJ_PROC)) \ - $(patsubst %,$(SAVE_TMP_DIR)/%,$(MODS_OBJ_SAVE)) \ - $(patsubst %,$(USR_TMP_DIR)/%,$(MODS_OBJ_USR)) - -# target: dependencies -# action - -all: $(ALL) - - -modules.o: $(MODS_OBJS) - $(Q)$(LD) -r $^ -o $@ - @echo " LD $@" - - -clean: - $(Q)rm -f *.o diff --git a/modules/user/Makefile b/modules/user/Makefile deleted file mode 100644 index 82df218..0000000 --- a/modules/user/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -TMP_DIR = $(USR_DIR)/tmp/ - -# target: dependencies -# action - -all: - $(Q)cd $(TMP_DIR) && $(MAKE) && cd .. - -clean: - $(Q)cd $(TMP_DIR) && $(MAKE) clean && cd .. - -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/modules/user/inc/user_clui.h b/modules/user/inc/user_clui.h deleted file mode 100644 index 807c508..0000000 --- a/modules/user/inc/user_clui.h +++ /dev/null @@ -1,31 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_USER_CLUI_H - # define VA_USER_CLUI_H - - -/****************************************************************************** - ******* 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); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* user_clui.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/user/inc/user_iface.h b/modules/user/inc/user_iface.h deleted file mode 100644 index a994ae1..0000000 --- a/modules/user/inc/user_iface.h +++ /dev/null @@ -1,166 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_USER_IFACE_H - # define VA_USER_IFACE_H - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define LOG_LEN (1048576) - # define LOG_LINE_LEN (80) - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* intX_t */ - #include <stdint.h> - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Player_Iface_Mode { - USER_IFACE_FOO, - USER_IFACE_CLUI, - USER_IFACE_TUI - }; - - enum Player_Iface_Action { - USER_IFACE_ACT_FOO = 0x000000u, - - USER_IFACE_ACT_ALX = 0x000010u, - USER_IFACE_ACT_LOCAL_MAX, - USER_IFACE_ACT_SKELETON, - USER_IFACE_ACT_LINES_HORIZONTAL, - USER_IFACE_ACT_LINES_VERTICAL, - USER_IFACE_ACT_MEAN_HORIZONTAL, - USER_IFACE_ACT_MEAN_VERTICAL, - USER_IFACE_ACT_MEDIAN_HORIZONTAL, - USER_IFACE_ACT_MEDIAN_VERTICAL, - - USER_IFACE_ACT_CV = 0x000100u, - USER_IFACE_ACT_PIXEL_GET, - USER_IFACE_ACT_PIXEL_SET, - USER_IFACE_ACT_SET_ROI, - USER_IFACE_ACT_SET_ROI_2RECT, - USER_IFACE_ACT_AND_2REF, - USER_IFACE_ACT_NOT, - USER_IFACE_ACT_OR_2REF, - USER_IFACE_ACT_COMPONENT, - USER_IFACE_ACT_DILATE, - USER_IFACE_ACT_ERODE, - USER_IFACE_ACT_DILATE_ERODE, - USER_IFACE_ACT_ERODE_DILATE, - USER_IFACE_ACT_SMOOTH, - USER_IFACE_ACT_SOBEL, - USER_IFACE_ACT_BORDER, - USER_IFACE_ACT_MIRROR, - USER_IFACE_ACT_ROTATE_ORTO, - USER_IFACE_ACT_ROTATE, - USER_IFACE_ACT_ROTATE_2RECT, - USER_IFACE_ACT_ADAPTIVE_THRESHOLD, - USER_IFACE_ACT_CVT_COLOR, - USER_IFACE_ACT_DISTANCE_TRANSFORM, - USER_IFACE_ACT_THRESHOLD, - USER_IFACE_ACT_HISTOGRAM, - USER_IFACE_ACT_HISTOGRAM_C3, - USER_IFACE_ACT_CONTOURS, - USER_IFACE_ACT_CONTOURS_SIZE, - USER_IFACE_ACT_BOUNDING_RECT, - USER_IFACE_ACT_FIT_ELLIPSE, - USER_IFACE_ACT_MIN_AREA_RECT, - USER_IFACE_ACT_HOUGH_CIRCLES, - - USER_IFACE_ACT_ORB = 0x000200u, - USER_IFACE_ACT_ALIGN, - - USER_IFACE_ACT_CALIB3D = 0x000400u, - USER_IFACE_ACT_CALIBRATE, - USER_IFACE_ACT_UNDISTORT, - - USER_IFACE_ACT_ZB = 0x000800u, - USER_IFACE_ACT_DECODE, - - USER_IFACE_ACT_OCR = 0x001000u, - USER_IFACE_ACT_READ, - - USER_IFACE_ACT_IMGI = 0x002000u, - USER_IFACE_ACT_APPLY, - USER_IFACE_ACT_DISCARD, - USER_IFACE_ACT_SAVE_MEM, - USER_IFACE_ACT_LOAD_MEM, - USER_IFACE_ACT_SAVE_REF, - - USER_IFACE_ACT_SAVE = 0x004000u, - USER_IFACE_ACT_SAVE_FILE, - USER_IFACE_ACT_SAVE_UPDT, - - USER_IFACE_ACT_PROC = 0x008000u, - USER_IFACE_ACT_PROC_LABEL_SERIES, - USER_IFACE_ACT_PROC_LABEL_CALIB, - USER_IFACE_ACT_PROC_OBJECTS_SERIES, - USER_IFACE_ACT_PROC_OBJECTS_CALIB, - USER_IFACE_ACT_PROC_COINS_SERIES, - USER_IFACE_ACT_PROC_COINS_CALIB, - USER_IFACE_ACT_PROC_RESISTOR_SERIES, - USER_IFACE_ACT_PROC_RESISTOR_CALIB, - USER_IFACE_ACT_PROC_LIGHTERS_SERIES, - USER_IFACE_ACT_PROC_LIGHTERS_CALIB, - - USER_IFACE_ACT_USRI = 0x010000u, - USER_IFACE_ACT_SHOW_OCR, - USER_IFACE_ACT_QUIT - }; - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ - struct User_Iface_Log { - int len; - char line [LOG_LEN] [LOG_LINE_LEN]; - int lvl [LOG_LEN]; - int visible; - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern int user_iface_mode; -extern struct User_Iface_Log user_iface_log; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void user_iface_init (void); -void user_iface_cleanup (void); -void user_iface (void); -void user_iface_show_log (const char *title, const char *subtitle); -void user_iface_fname (const char *filepath, char *filename); -double user_iface_getdbl (double m, double def, double M, - const char *title, const char *help); -int64_t user_iface_getint (double m, int64_t def, double M, - const char *title, const char *help); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* user_iface.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/user/inc/user_iface.hpp b/modules/user/inc/user_iface.hpp deleted file mode 100644 index 26fadfb..0000000 --- a/modules/user/inc/user_iface.hpp +++ /dev/null @@ -1,178 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_USER_IFACE_HPP - # define VA_USER_IFACE_HPP - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define LOG_LEN (1048576) - # define LOG_LINE_LEN (80) - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* intX_t */ - #include <cstdint> - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Player_Iface_Mode { - USER_IFACE_FOO, - USER_IFACE_CLUI, - USER_IFACE_TUI - }; - - enum Player_Iface_Action { - USER_IFACE_ACT_FOO = 0x000000u, - - USER_IFACE_ACT_ALX = 0x000010u, - USER_IFACE_ACT_LOCAL_MAX, - USER_IFACE_ACT_SKELETON, - USER_IFACE_ACT_LINES_HORIZONTAL, - USER_IFACE_ACT_LINES_VERTICAL, - USER_IFACE_ACT_MEAN_HORIZONTAL, - USER_IFACE_ACT_MEAN_VERTICAL, - USER_IFACE_ACT_MEDIAN_HORIZONTAL, - USER_IFACE_ACT_MEDIAN_VERTICAL, - - USER_IFACE_ACT_CV = 0x000100u, - USER_IFACE_ACT_PIXEL_GET, - USER_IFACE_ACT_PIXEL_SET, - USER_IFACE_ACT_SET_ROI, - USER_IFACE_ACT_SET_ROI_2RECT, - USER_IFACE_ACT_AND_2REF, - USER_IFACE_ACT_NOT, - USER_IFACE_ACT_OR_2REF, - USER_IFACE_ACT_COMPONENT, - USER_IFACE_ACT_DILATE, - USER_IFACE_ACT_ERODE, - USER_IFACE_ACT_DILATE_ERODE, - USER_IFACE_ACT_ERODE_DILATE, - USER_IFACE_ACT_SMOOTH, - USER_IFACE_ACT_SOBEL, - USER_IFACE_ACT_BORDER, - USER_IFACE_ACT_MIRROR, - USER_IFACE_ACT_ROTATE_ORTO, - USER_IFACE_ACT_ROTATE, - USER_IFACE_ACT_ROTATE_2RECT, - USER_IFACE_ACT_ADAPTIVE_THRESHOLD, - USER_IFACE_ACT_CVT_COLOR, - USER_IFACE_ACT_DISTANCE_TRANSFORM, - USER_IFACE_ACT_THRESHOLD, - USER_IFACE_ACT_HISTOGRAM, - USER_IFACE_ACT_HISTOGRAM_C3, - USER_IFACE_ACT_CONTOURS, - USER_IFACE_ACT_CONTOURS_SIZE, - USER_IFACE_ACT_BOUNDING_RECT, - USER_IFACE_ACT_FIT_ELLIPSE, - USER_IFACE_ACT_MIN_AREA_RECT, - USER_IFACE_ACT_HOUGH_CIRCLES, - - USER_IFACE_ACT_ORB = 0x000200u, - USER_IFACE_ACT_ALIGN, - - USER_IFACE_ACT_CALIB3D = 0x000400u, - USER_IFACE_ACT_CALIBRATE, - USER_IFACE_ACT_UNDISTORT, - - USER_IFACE_ACT_ZB = 0x000800u, - USER_IFACE_ACT_DECODE, - - USER_IFACE_ACT_OCR = 0x001000u, - USER_IFACE_ACT_READ, - - USER_IFACE_ACT_IMGI = 0x002000u, - USER_IFACE_ACT_APPLY, - USER_IFACE_ACT_DISCARD, - USER_IFACE_ACT_SAVE_MEM, - USER_IFACE_ACT_LOAD_MEM, - USER_IFACE_ACT_SAVE_REF, - - USER_IFACE_ACT_SAVE = 0x004000u, - USER_IFACE_ACT_SAVE_FILE, - USER_IFACE_ACT_SAVE_UPDT, - - USER_IFACE_ACT_PROC = 0x008000u, - USER_IFACE_ACT_PROC_LABEL_SERIES, - USER_IFACE_ACT_PROC_LABEL_CALIB, - USER_IFACE_ACT_PROC_OBJECTS_SERIES, - USER_IFACE_ACT_PROC_OBJECTS_CALIB, - USER_IFACE_ACT_PROC_COINS_SERIES, - USER_IFACE_ACT_PROC_COINS_CALIB, - USER_IFACE_ACT_PROC_RESISTOR_SERIES, - USER_IFACE_ACT_PROC_RESISTOR_CALIB, - USER_IFACE_ACT_PROC_LIGHTERS_SERIES, - USER_IFACE_ACT_PROC_LIGHTERS_CALIB, - - USER_IFACE_ACT_USRI = 0x010000u, - USER_IFACE_ACT_SHOW_OCR, - USER_IFACE_ACT_QUIT - }; - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ - struct User_Iface_Log { - int len; - char line [LOG_LEN] [LOG_LINE_LEN]; - int lvl [LOG_LEN]; - int visible; - }; - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern int user_iface_mode; -extern struct User_Iface_Log user_iface_log; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void user_iface_init (void); -void user_iface_cleanup (void); -void user_iface (void); -void user_iface_show_log (const char *title, const char *subtitle); -void user_iface_fname (const char *filepath, char *filename); -double user_iface_getdbl (double m, double def, double M, - const char *title, const char *help); -int64_t user_iface_getint (double m, int64_t def, double M, - const char *title, const char *help); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* user_iface.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/user/inc/user_tui.h b/modules/user/inc/user_tui.h deleted file mode 100644 index 64dd880..0000000 --- a/modules/user/inc/user_tui.h +++ /dev/null @@ -1,37 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_USER_TUI_H - # define VA_USER_TUI_H - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void user_tui_init (void); -void user_tui_cleanup (void); -int user_tui (const char *title, const char *subtitle); -void user_tui_show_log (const char *title, const char *subtitle); -void user_tui_fname (const char *filepath, char *filename); -double user_tui_getdbl (double m, double def, double M, - const char *title, const char *help); -int64_t user_tui_getint (double m, int64_t def, double M, - const char *title, const char *help); -void user_tui_show_ocr (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* user_tui.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/user/src/user_clui.c b/modules/user/src/user_clui.c deleted file mode 100644 index bcd44c8..0000000 --- a/modules/user/src/user_clui.c +++ /dev/null @@ -1,537 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - #include <stdio.h> - - #include "libalx/io/alx_input.h" - - #include "img_iface.h" - #include "user_iface.h" - - #include "user_clui.h" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define BUFF_SIZE (1024) - - -/****************************************************************************** - ******* static variables ***************************************************** - ******************************************************************************/ -static int log_pos; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ - /* Log */ -static void log_loop (void); - /* Input */ -static int usr_input (void); - /* Help */ -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; - - /* User action */ - show_help(); - user_clui_show_log(title, subtitle); - action = usr_input(); - - return action; -} - -void user_clui_fname (const char *filepath, char *filename) -{ - - printf("File name:\n"); - printf("Valid extensions: .bmp .dib .jpeg .png .pbm .pgm .ppm .tiff\n"); - fgets(filename, FILENAME_MAX, stdin); - alx_sscan_fname(filepath, filename, false, filename); -} - -void user_clui_show_log (const char *title, const char *subtitle) -{ - - printf("________________________________________________________________________________\n"); - log_loop(); - printf("%s - %s\n", subtitle, title); - printf("--------------------------------------------------------------------------------\n"); - -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -/* Log -----------------------------------------------------------------------*/ -static void log_loop (void) -{ - int lvl; - - putchar('\n'); - 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[log_pos]); - } - } - putchar('\n'); -} - -/* Input ---------------------------------------------------------------------*/ -static int usr_input (void) -{ - int action; - char buff [BUFF_SIZE]; - char ch [10]; - int i; - - for (i = 0; i < 10; i++) - ch[i] = '\0'; - buff[0] = '\0'; - action = USER_IFACE_ACT_FOO; - - if (!fgets(buff, BUFF_SIZE, stdin)) - goto err_fgets; - if (sscanf(buff, " %5c", ch) <= 0) - goto err_sscanf; - - switch (ch[0]) { - case '+': - action = USER_IFACE_ACT_APPLY; - break; - - case '-': - action = USER_IFACE_ACT_DISCARD; - break; - - case 'e': - /* Exercises from class */ - switch (ch[1]) { - case '1': - /* Label */ - switch (ch[2]) { - case '1': - action = USER_IFACE_ACT_PROC_LABEL_SERIES; - break; - } - break; - case '2': - /* Objects */ - switch (ch[2]) { - case '0': - action = USER_IFACE_ACT_PROC_OBJECTS_CALIB; - break; - case '1': - action = USER_IFACE_ACT_PROC_OBJECTS_SERIES; - break; - } - break; - case '3': - /* Coins */ - switch (ch[2]) { - case '1': - action = USER_IFACE_ACT_PROC_COINS_SERIES; - break; - } - break; - case '4': - /* Resistor */ - switch (ch[2]) { - case '1': - action = USER_IFACE_ACT_PROC_RESISTOR_SERIES; - break; - } - break; - case '5': - /* Lighters */ - switch (ch[2]) { - case '1': - action = USER_IFACE_ACT_PROC_LIGHTERS_SERIES; - break; - } - break; - } - break; - - case 'f': - /* Use simple funtions */ - switch (ch[1]) { - case '0': - /* img_alx */ - switch (ch[2]) { - case '0': - /* Distance transform postprocessing */ - switch (ch[3]) { - case '0': - action = USER_IFACE_ACT_LOCAL_MAX; - break; - case '1': - action = USER_IFACE_ACT_SKELETON; - break; - } - break; - case '1': - /* Lines */ - switch (ch[3]) { - case '0': - action = USER_IFACE_ACT_LINES_HORIZONTAL; - break; - case '1': - action = USER_IFACE_ACT_LINES_VERTICAL; - break; - } - break; - case '2': - /* Smooth */ - switch (ch[3]) { - case '0': - action = USER_IFACE_ACT_MEAN_HORIZONTAL; - break; - case '1': - action = USER_IFACE_ACT_MEAN_VERTICAL; - break; - case '2': - action = USER_IFACE_ACT_MEDIAN_HORIZONTAL; - break; - case '3': - action = USER_IFACE_ACT_MEDIAN_VERTICAL; - break; - } - break; - } - break; - case '1': - /* img_cv */ - switch (ch[2]) { - case '0': - /* Core: The core functionality */ - switch (ch[3]) { - case '0': - /* Pixel */ - switch (ch[4]) { - case '0': - action = USER_IFACE_ACT_PIXEL_GET; - break; - case '1': - action = USER_IFACE_ACT_PIXEL_SET; - break; - } - break; - case '1': - /* ROI */ - switch (ch[4]) { - case '0': - action = USER_IFACE_ACT_SET_ROI; - break; - case '1': - action = USER_IFACE_ACT_SET_ROI_2RECT; - break; - } - break; - case '2': - /* Operations on Arrays */ - switch (ch[4]) { - case '0': - action = USER_IFACE_ACT_AND_2REF; - break; - case '1': - action = USER_IFACE_ACT_NOT; - break; - case '2': - action = USER_IFACE_ACT_OR_2REF; - break; - case '3': - action = USER_IFACE_ACT_COMPONENT; - break; - } - break; - } - break; - case '1': - /* Imgproc: Image processing */ - switch (ch[3]) { - case '0': - /* Image filtering */ - switch (ch[4]) { - case '0': - action = USER_IFACE_ACT_DILATE; - break; - case '1': - action = USER_IFACE_ACT_ERODE; - break; - case '2': - action = USER_IFACE_ACT_DILATE_ERODE; - break; - case '3': - action = USER_IFACE_ACT_ERODE_DILATE; - break; - case '4': - action = USER_IFACE_ACT_SMOOTH; - break; - case '5': - action = USER_IFACE_ACT_SOBEL; - break; - case '6': - action = USER_IFACE_ACT_BORDER; - break; - } - break; - case '1': - /* Geometric image transformations */ - switch (ch[4]) { - case '0': - action = USER_IFACE_ACT_MIRROR; - break; - case '1': - action = USER_IFACE_ACT_ROTATE_ORTO; - break; - case '2': - action = USER_IFACE_ACT_ROTATE; - break; - case '3': - action = USER_IFACE_ACT_ROTATE_2RECT; - break; - } - break; - case '2': - /* Miscellaneous image transformations */ - switch (ch[4]) { - case '0': - action = USER_IFACE_ACT_ADAPTIVE_THRESHOLD; - break; - case '1': - action = USER_IFACE_ACT_CVT_COLOR; - break; - case '2': - action = USER_IFACE_ACT_DISTANCE_TRANSFORM; - break; - case '3': - action = USER_IFACE_ACT_THRESHOLD; - break; - } - break; - case '3': - /* Histograms */ - switch (ch[4]) { - case '0': - action = USER_IFACE_ACT_HISTOGRAM; - break; - case '1': - action = USER_IFACE_ACT_HISTOGRAM_C3; - break; - } - break; - case '4': - /* Structural analysis and shape descriptors */ - switch (ch[4]) { - case '0': - action = USER_IFACE_ACT_CONTOURS; - break; - case '1': - action = USER_IFACE_ACT_CONTOURS_SIZE; - break; - case '2': - action = USER_IFACE_ACT_BOUNDING_RECT; - break; - case '3': - action = USER_IFACE_ACT_FIT_ELLIPSE; - break; - case '4': - action = USER_IFACE_ACT_MIN_AREA_RECT; - break; - } - break; - case '5': - /* Feature detection */ - switch (ch[4]) { - case '0': - action = USER_IFACE_ACT_HOUGH_CIRCLES; - break; - } - break; - } - break; - } - break; - case '2': - /* img_orb */ - switch (ch[2]) { - case '0': - action = USER_IFACE_ACT_ALIGN; - break; - } - break; - case '3': - /* img_calib3d */ - switch (ch[2]) { - case '0': - action = USER_IFACE_ACT_CALIBRATE; - break; - case '1': - action = USER_IFACE_ACT_UNDISTORT; - break; - } - break; - case '4': - /* img_zbar */ - switch (ch[2]) { - case '0': - action = USER_IFACE_ACT_DECODE; - break; - } - break; - case '5': - /* img_ocr */ - switch (ch[2]) { - case '0': - action = USER_IFACE_ACT_READ; - break; - } - break; - } - break; - - case 'l': - action = USER_IFACE_ACT_LOAD_MEM; - break; - - case 'm': - action = USER_IFACE_ACT_SAVE_MEM; - break; - - case 'q': - action = USER_IFACE_ACT_QUIT; - break; - - case 'r': - action = USER_IFACE_ACT_SAVE_REF; - break; - - case 's': - action = USER_IFACE_ACT_SAVE_FILE; - break; - - case 'u': - /* User iface actions */ - switch (ch[1]) { - case '1': - action = USER_IFACE_ACT_SHOW_OCR; - break; - } - break; - - case 'x': - /* Special sequence "xyzzy" */ - if (ch[1] == 'y') { - if (ch[2] == 'z') { - if (ch[3] == 'z') { - if (ch[4] == 'y') { - action = USER_IFACE_ACT_FOO; - } - } - } - } - break; - } - -err_fgets: -err_sscanf: - return action; -} - -/* * * * * * * * * * - * * * Help * * * * * * * - * * * * * * * * * */ -static void show_help (void) -{ - - printf("Apply: %s\n", "Space"); - printf("Discard: %s\n", "Backspace"); - printf("Save to mem: %c\n", 'm'); - printf("Load from mem: %c\n", 'l'); - printf("Save to ref: %c\n", 'r'); - printf("Save to file: %c\n", 's'); - printf("Functions:\n"); - printf(" - Local maxima: %s\n", "f000"); - printf(" - Skeleton: %s\n", "f001"); - printf(" - Horizontal lines: %s\n", "f010"); - printf(" - Vertical lines: %s\n", "f011"); - printf(" - Horizontal mean: %s\n", "f020"); - printf(" - Vertical mean: %s\n", "f021"); - printf(" - Horizontal median: %s\n", "f022"); - printf(" - Vertical median: %s\n", "f023"); - printf(" - Pixel get: %s\n", "f1000"); - printf(" - Pixel set: %s\n", "f1001"); - printf(" - Set ROI: %s\n", "f1010"); - printf(" - Set ROI 2rect: %s\n", "f1011"); - printf(" - Bitwise AND 2ref: %s\n", "f1020"); - printf(" - Bitwise NOT: %s\n", "f1021"); - printf(" - Bitwise OR 2ref: %s\n", "f1022"); - printf(" - Component: %s\n", "f1023"); - printf(" - Dilate: %s\n", "f1100"); - printf(" - Erode: %s\n", "f1101"); - printf(" - D-E: %s\n", "f1102"); - printf(" - E-D: %s\n", "f1103"); - printf(" - Smooth: %s\n", "f1104"); - printf(" - Sobel: %s\n", "f1105"); - printf(" - Border: %s\n", "f1106"); - printf(" - Mirror: %s\n", "f1110"); - printf(" - Rotate ortogonally: %s\n", "f1111"); - printf(" - Rotate: %s\n", "f1112"); - printf(" - Rotate 2rect_rot: %s\n", "f1113"); - printf(" - Adaptive threshold: %s\n", "f1120"); - printf(" - Cvt color: %s\n", "f1121"); - printf(" - Distance transform: %s\n", "f1122"); - printf(" - Threshold: %s\n", "f1123"); - printf(" - Histogram: %s\n", "f1130"); - printf(" - Histogram (3 chan): %s\n", "f1131"); - printf(" - Contours: %s\n", "f1140"); - printf(" - Contours size: %s\n", "f1141"); - printf(" - Bounding rectangle: %s\n", "f1142"); - printf(" - Fit ellipse: %s\n", "f1143"); - printf(" - Min. area rectangle: %s\n", "f1144"); - printf(" - Hough circles: %s\n", "f1150"); - printf(" - Align 2ref (ORB): %s\n", "f20"); - printf(" - Calibrate (Calib3d): %s\n", "f30"); - printf(" - Undistort (Calib3d): %s\n", "f31"); - printf(" - Scan codes (ZBAR): %s\n", "f40"); - printf(" - Scan text (OCR): %s\n", "f50"); - printf("Exercises:\n"); - printf(" - Label: %s\n", "e11"); - printf(" - Objects (calib): %s\n", "e20"); - printf(" - Objects: %s\n", "e21"); - printf(" - Coins: %s\n", "e31"); - printf(" - Resistor: %s\n", "e41"); - printf(" - Lighters: %s\n", "e51"); - printf("Other:\n"); - printf(" - Show OCR text: %s\n", "u1"); - printf("Quit: %c\n", 'q'); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/user/src/user_iface.c b/modules/user/src/user_iface.c deleted file mode 100644 index 84aedfb..0000000 --- a/modules/user/src/user_iface.c +++ /dev/null @@ -1,220 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <stdint.h> - #include <stdio.h> -/* Project -------------------------------------------------------------------*/ - #include "img_iface.h" - #include "proc_iface.h" -/* Module --------------------------------------------------------------------*/ - #include "user_clui.h" - #include "user_tui.h" - - #include "user_iface.h" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define TITLE_SIZE (20) - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -int user_iface_mode; -struct User_Iface_Log user_iface_log; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void user_iface_act (int action); -static void user_iface_show_ocr (void); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void user_iface_init (void) -{ - user_iface_log.len = 0; - - switch (user_iface_mode) { - case USER_IFACE_CLUI: - user_clui_init(); - break; - - case USER_IFACE_TUI: - user_tui_init(); - break; - } -} - -void user_iface_cleanup (void) -{ - switch (user_iface_mode) { - case USER_IFACE_CLUI: - break; - - case USER_IFACE_TUI: - user_tui_cleanup(); - break; - } - - fflush(stdout); -} - -void user_iface (void) -{ - char title[TITLE_SIZE]; - char subtitle[TITLE_SIZE]; - int user_action; - - snprintf(title, TITLE_SIZE, "Title"); - snprintf(subtitle, TITLE_SIZE, "Subtitle"); - - do { - /* Display image */ - img_iface_show_img(); - - /* Request user action */ - switch (user_iface_mode) { - case USER_IFACE_CLUI: - user_action = user_clui(title, subtitle); - break; - - case USER_IFACE_TUI: - user_action = user_tui(title, subtitle); - break; - - default: - user_action = USER_IFACE_ACT_FOO; - break; - } - - /* Do action */ - user_iface_act(user_action); - } while (user_action != USER_IFACE_ACT_QUIT); -} - -void user_iface_show_log (const char *title, const char *subtitle) -{ - switch (user_iface_mode) { - case USER_IFACE_CLUI: - user_clui_show_log(title, subtitle); - break; - - case USER_IFACE_TUI: - user_tui_show_log(title, subtitle); - break; - } -} - -void user_iface_fname (const char *filepath, char *filename) -{ - switch (user_iface_mode) { - case USER_IFACE_CLUI: - user_clui_fname(filepath, filename); - break; - - case USER_IFACE_TUI: - user_tui_fname(filepath, filename); - break; - } -} - -int64_t user_iface_getint (double m, int64_t def, double M, - const char *title, const char *help) -{ - int64_t i; - - switch (user_iface_mode) { - case USER_IFACE_CLUI: - // FIXME - i = 1; - break; - - case USER_IFACE_TUI: - i = user_tui_getint(m, def, M, title, help); - break; - - default: - i = 1; - break; - } - - return i; -} - -double user_iface_getdbl (double m, double def, double M, - const char *title, const char *help) -{ - int64_t i; - - switch (user_iface_mode) { - case USER_IFACE_CLUI: - // FIXME - i = 1; - break; - - case USER_IFACE_TUI: - i = user_tui_getdbl(m, def, M, title, help); - break; - - default: - i = 1; - break; - } - - return i; -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void user_iface_act (int action) -{ - if (action & USER_IFACE_ACT_USRI) { - switch (action) { - case USER_IFACE_ACT_SHOW_OCR: - user_iface_show_ocr(); - break; - case USER_IFACE_ACT_QUIT: - /* do nothing */ - break; - } - - } else if (action & USER_IFACE_ACT_PROC) { - proc_iface_single(action); - - } else { - img_iface_act_nodata(action); - } -} - -static void user_iface_show_ocr (void) -{ - switch (user_iface_mode) { - case USER_IFACE_CLUI: - // FIXME - break; - - case USER_IFACE_TUI: - user_tui_show_ocr(); - break; - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/user/src/user_tui.c b/modules/user/src/user_tui.c deleted file mode 100644 index 9b0285b..0000000 --- a/modules/user/src/user_tui.c +++ /dev/null @@ -1,705 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - #include <inttypes.h> - #include <ncurses.h> - - #include "libalx/curses/alx_ncur.h" - - #include "img_iface.h" - #include "user_iface.h" - - #include "user_tui.h" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -static WINDOW *win_log; -static WINDOW *win_help; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ - /* Log */ -static void log_loop (void); - /* Input */ -static int usr_input (void); - /* Help */ -static void show_help (void); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void user_tui_init (void) -{ - int h1; - int w1; - int r1; - int c1; - int h2; - int w2; - int r2; - int c2; - - /* Use curses mode */ - alx_resume_curses(); - - /* Dimensions: log */ - h1 = 54; - w1 = 40; - r1 = 0; - c1 = 30; - win_log = newwin(h1, w1, r1, c1); - - /* Dimensions: help */ - h2 = 54; - w2 = 40; - r2 = 0; - c2 = 0; - win_help = newwin(h2, w2, r2, c2); - - /* Activate keypad, don't echo input */ - keypad(win_log, true); - noecho(); -} - -void user_tui_cleanup (void) -{ - - /* Del wins & return to terminal mode */ - alx_win_del(win_log); - alx_win_del(win_help); - alx_pause_curses(); -} - -int user_tui (const char *title, const char *subtitle) -{ - int action; - - show_help(); - user_tui_show_log(title, subtitle); - action = usr_input(); - - return action; -} - -void user_tui_fname (const char *filepath, char *filename) -{ - int w; - int r; - - /* Input box */ - w = 75; - r = 10; - - /* Request name */ - alx_w_getfname(filepath, filename, false, w, r, "File name:", - "Valid extensions: .bmp .dib .jpeg .png .pbm .pgm .ppm .tiff"); -} - -void user_tui_show_log (const char *title, const char *subtitle) -{ - - /* Clear & box */ - werase(win_log); - box(win_log, 0, 0); - - /* Title */ - alx_ncur_prn_title(win_log, title); - /* Subtitle */ - alx_ncur_prn_subtitle(win_log, subtitle); - - /* Log */ - log_loop(); - - /* Refresh */ - wrefresh(win_log); -} - -double user_tui_getdbl (double m, double def, double M, - const char *title, const char *help) -{ - int w; - int r; - double R; - - /* Input box */ - w = 75; - r = 10; - - /* Request int */ - R = alx_w_getdbl(w, r, title, m, def, M, help); - - return R; -} - -int64_t user_tui_getint (double m, int64_t def, double M, - const char *title, const char *help) -{ - /* Input box */ - int w; - int r; - int64_t i; - - w = 75; - r = 10; - - /* Request int */ - i = alx_w_getint(w, r, title, m, def, M, help); - - return i; -} - -void user_tui_show_ocr (void) -{ - - alx_pause_curses(); - - printf("%s", img_ocr_text); - getchar(); - - alx_resume_curses(); -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -/* Log -----------------------------------------------------------------------*/ -static void log_loop (void) -{ - int i; - int i_0; - int l; - int l_0; - - if (user_iface_log.len > 51) { - i_0 = user_iface_log.len - 51; - l_0 = 1; - mvwprintw(win_log, 1, 10, "..."); - } else { - i_0 = 0; - l_0 = 0; - } - - l = l_0; - for (i = i_0; i < user_iface_log.len; i++) { - if (user_iface_log.lvl[i] <= user_iface_log.visible) { - mvwprintw(win_log, (1 + l), - (1 + 4 * user_iface_log.lvl[i]), - "%.*s", - 40 - 2 - 4 * user_iface_log.lvl[i], - user_iface_log.line[i]); - l++; - } - } -} - -/* Input ---------------------------------------------------------------------*/ -static int usr_input (void) -{ - int action; - wchar_t ch; - - action = USER_IFACE_ACT_FOO; - ch = wgetch(win_log); - switch (ch) { - case ' ': - action = USER_IFACE_ACT_APPLY; - break; - - /* ASCII 0x08 is BS */ - case KEY_BACKSPACE: - case 0x08: - action = USER_IFACE_ACT_DISCARD; - break; - - case 'e': - /* Exercises from class */ - ch = wgetch(win_log); - - switch (ch) { - case '1': - /* Label */ - ch = wgetch(win_log); - - switch (ch) { - case '1': - action = USER_IFACE_ACT_PROC_LABEL_SERIES; - break; - } - break; - case '2': - /* Objects */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_PROC_OBJECTS_CALIB; - break; - case '1': - action = USER_IFACE_ACT_PROC_OBJECTS_SERIES; - break; - } - break; - case '3': - /* Coins */ - ch = wgetch(win_log); - - switch (ch) { - case '1': - action = USER_IFACE_ACT_PROC_COINS_SERIES; - break; - } - break; - case '4': - /* Resistor */ - ch = wgetch(win_log); - - switch (ch) { - case '1': - action = USER_IFACE_ACT_PROC_RESISTOR_SERIES; - break; - } - break; - case '5': - /* Lighters */ - ch = wgetch(win_log); - - switch (ch) { - case '1': - action = USER_IFACE_ACT_PROC_LIGHTERS_SERIES; - break; - } - break; - } - break; - - case 'f': - /* Use simple funtions */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - /* img_alx */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - /* Distance transform postprocessing */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_LOCAL_MAX; - break; - case '1': - action = USER_IFACE_ACT_SKELETON; - break; - } - break; - case '1': - /* Lines */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_LINES_HORIZONTAL; - break; - case '1': - action = USER_IFACE_ACT_LINES_VERTICAL; - break; - } - break; - case '2': - /* Smooth */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_MEAN_HORIZONTAL; - break; - case '1': - action = USER_IFACE_ACT_MEAN_VERTICAL; - break; - case '2': - action = USER_IFACE_ACT_MEDIAN_HORIZONTAL; - break; - case '3': - action = USER_IFACE_ACT_MEDIAN_VERTICAL; - break; - } - break; - } - break; - case '1': - /* img_cv */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - /* Core: The core functionality */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - /* Pixel */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_PIXEL_GET; - break; - case '1': - action = USER_IFACE_ACT_PIXEL_SET; - break; - } - break; - case '1': - /* ROI */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_SET_ROI; - break; - case '1': - action = USER_IFACE_ACT_SET_ROI_2RECT; - break; - } - break; - case '2': - /* Operations on Arrays */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_AND_2REF; - break; - case '1': - action = USER_IFACE_ACT_NOT; - break; - case '2': - action = USER_IFACE_ACT_OR_2REF; - break; - case '3': - action = USER_IFACE_ACT_COMPONENT; - break; - } - break; - } - break; - case '1': - /* Imgproc: Image processing */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - /* Image filtering */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_DILATE; - break; - case '1': - action = USER_IFACE_ACT_ERODE; - break; - case '2': - action = USER_IFACE_ACT_DILATE_ERODE; - break; - case '3': - action = USER_IFACE_ACT_ERODE_DILATE; - break; - case '4': - action = USER_IFACE_ACT_SMOOTH; - break; - case '5': - action = USER_IFACE_ACT_SOBEL; - break; - case '6': - action = USER_IFACE_ACT_BORDER; - break; - } - break; - case '1': - /* Geometric image transformations */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_MIRROR; - break; - case '1': - action = USER_IFACE_ACT_ROTATE_ORTO; - break; - case '2': - action = USER_IFACE_ACT_ROTATE; - break; - case '3': - action = USER_IFACE_ACT_ROTATE_2RECT; - break; - } - break; - case '2': - /* Miscellaneous image transformations */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_ADAPTIVE_THRESHOLD; - break; - case '1': - action = USER_IFACE_ACT_CVT_COLOR; - break; - case '2': - action = USER_IFACE_ACT_DISTANCE_TRANSFORM; - break; - case '3': - action = USER_IFACE_ACT_THRESHOLD; - break; - } - break; - case '3': - /* Histograms */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_HISTOGRAM; - break; - case '1': - action = USER_IFACE_ACT_HISTOGRAM_C3; - break; - } - break; - case '4': - /* Structural analysis and shape descriptors */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_CONTOURS; - break; - case '1': - action = USER_IFACE_ACT_CONTOURS_SIZE; - break; - case '2': - action = USER_IFACE_ACT_BOUNDING_RECT; - break; - case '3': - action = USER_IFACE_ACT_FIT_ELLIPSE; - break; - case '4': - action = USER_IFACE_ACT_MIN_AREA_RECT; - break; - } - break; - case '5': - /* Feature detection */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_HOUGH_CIRCLES; - break; - } - break; - } - break; - } - break; - case '2': - /* img_orb */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_ALIGN; - break; - } - break; - case '3': - /* img_calib3d */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_CALIBRATE; - break; - case '1': - action = USER_IFACE_ACT_UNDISTORT; - break; - } - break; - case '4': - /* img_zbar */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_DECODE; - break; - } - break; - case '5': - /* img_ocr */ - ch = wgetch(win_log); - - switch (ch) { - case '0': - action = USER_IFACE_ACT_READ; - break; - } - break; - } - break; - - case 'l': - action = USER_IFACE_ACT_LOAD_MEM; - break; - - case 'm': - action = USER_IFACE_ACT_SAVE_MEM; - break; - - case 'q': - action = USER_IFACE_ACT_QUIT; - break; - - case 'r': - action = USER_IFACE_ACT_SAVE_REF; - break; - - case 's': - action = USER_IFACE_ACT_SAVE_FILE; - break; - - case 'u': - /* User iface actions */ - ch = wgetch(win_log); - - switch (ch) { - case '1': - action = USER_IFACE_ACT_SHOW_OCR; - break; - } - break; - - case 'x': - action = USER_IFACE_ACT_FOO; - - /* Special sequence "xyzzy" */ - ch = wgetch(win_log); - if (ch == 'y') { - ch = wgetch(win_log); - if (ch == 'z') { - - ch = wgetch(win_log); - if (ch == 'z') { - - ch = wgetch(win_log); - if (ch == 'y') { - action = USER_IFACE_ACT_FOO; - } - } - } - } - break; - } - - return action; -} - -/* * * * * * * * * * - * * * Help * * * * * * * - * * * * * * * * * */ -static void show_help (void) -{ - int r; - int c; - - /* Clear */ - werase(win_help); - - r = 0; - c = 0; - mvwprintw(win_help, r++, c, "Apply: %s", "Space"); - mvwprintw(win_help, r++, c, "Discard: %s", "BS"); - mvwprintw(win_help, r++, c, "Save to mem: %c", 'm'); - mvwprintw(win_help, r++, c, "Load from mem: %c", 'l'); - 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, " - Local maxima: %s", "f000"); - mvwprintw(win_help, r++, c, " - Skeleton: %s", "f001"); - mvwprintw(win_help, r++, c, " - Horizontal lines: %s", "f010"); - mvwprintw(win_help, r++, c, " - Vertical lines: %s", "f011"); - mvwprintw(win_help, r++, c, " - Horizontal mean: %s", "f020"); - mvwprintw(win_help, r++, c, " - Vertical mean: %s", "f021"); - mvwprintw(win_help, r++, c, " - Horizontal median: %s", "f022"); - mvwprintw(win_help, r++, c, " - Vertical median: %s", "f023"); - mvwprintw(win_help, r++, c, " - Pixel get: %s", "f1000"); - mvwprintw(win_help, r++, c, " - Pixel set: %s", "f1001"); - mvwprintw(win_help, r++, c, " - Set ROI: %s", "f1010"); - mvwprintw(win_help, r++, c, " - Set ROI 2rect: %s", "f1011"); - mvwprintw(win_help, r++, c, " - Bitwise AND 2ref: %s", "f1020"); - mvwprintw(win_help, r++, c, " - Bitwise NOT: %s", "f1021"); - mvwprintw(win_help, r++, c, " - Bitwise OR 2ref: %s", "f1022"); - mvwprintw(win_help, r++, c, " - Component: %s", "f1023"); - mvwprintw(win_help, r++, c, " - Dilate: %s", "f1100"); - mvwprintw(win_help, r++, c, " - Erode: %s", "f1101"); - mvwprintw(win_help, r++, c, " - D-E: %s", "f1102"); - mvwprintw(win_help, r++, c, " - E-D: %s", "f1103"); - mvwprintw(win_help, r++, c, " - Smooth: %s", "f1104"); - mvwprintw(win_help, r++, c, " - Sobel: %s", "f1105"); - mvwprintw(win_help, r++, c, " - Border: %s", "f1106"); - mvwprintw(win_help, r++, c, " - Mirror: %s", "f1110"); - mvwprintw(win_help, r++, c, " - Rotate ortogonally: %s", "f1111"); - mvwprintw(win_help, r++, c, " - Rotate: %s", "f1112"); - mvwprintw(win_help, r++, c, " - Rotate 2rect_rot: %s", "f1113"); - mvwprintw(win_help, r++, c, " - Adaptive threshold: %s", "f1120"); - mvwprintw(win_help, r++, c, " - Cvt color: %s", "f1121"); - mvwprintw(win_help, r++, c, " - Distance transform: %s", "f1122"); - mvwprintw(win_help, r++, c, " - Threshold: %s", "f1123"); - mvwprintw(win_help, r++, c, " - Histogram: %s", "f1130"); - mvwprintw(win_help, r++, c, " - Histogram (3 chan): %s", "f1131"); - mvwprintw(win_help, r++, c, " - Contours: %s", "f1140"); - mvwprintw(win_help, r++, c, " - Contours size: %s", "f1141"); - mvwprintw(win_help, r++, c, " - Bounding rectangle: %s", "f1142"); - mvwprintw(win_help, r++, c, " - Fit ellipse: %s", "f1143"); - mvwprintw(win_help, r++, c, " - Min. area rectangle: %s", "f1144"); - mvwprintw(win_help, r++, c, " - Hough circles: %s", "f1150"); - mvwprintw(win_help, r++, c, " - Align 2ref (ORB): %s", "f20"); - mvwprintw(win_help, r++, c, " - Calibrate (Calib3d): %s", "f30"); - mvwprintw(win_help, r++, c, " - Undistort (Calib3d): %s", "f31"); - mvwprintw(win_help, r++, c, " - Scan codes (ZBAR): %s", "f40"); - mvwprintw(win_help, r++, c, " - Scan text (OCR): %s", "f50"); - mvwprintw(win_help, r++, c, "Exercises:"); - mvwprintw(win_help, r++, c, " - Label: %s", "e11"); - mvwprintw(win_help, r++, c, " - Objects (calib): %s", "e20"); - mvwprintw(win_help, r++, c, " - Objects: %s", "e21"); - mvwprintw(win_help, r++, c, " - Coins: %s", "e31"); - mvwprintw(win_help, r++, c, " - Resistor: %s", "e41"); - mvwprintw(win_help, r++, c, " - Lighters: %s", "e51"); - mvwprintw(win_help, r++, c, "Other:"); - mvwprintw(win_help, r++, c, " - Show OCR: %s", "u1"); - mvwprintw(win_help, r++, c, "Quit: %c", 'q'); - - /* Refresh */ - wrefresh(win_help); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/user/tmp/Makefile b/modules/user/tmp/Makefile deleted file mode 100644 index bc4f607..0000000 --- a/modules/user/tmp/Makefile +++ /dev/null @@ -1,89 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -LIBALX_INC_DIR = $(LIBALX_DIR)/inc/ -IMG_INC_DIR = $(IMG_DIR)/inc/ - -IMG_INC_DIR = $(IMG_DIR)/inc/ -MENU_INC_DIR = $(MENU_DIR)/inc/ -PROC_INC_DIR = $(PROC_DIR)/inc/ - -INC_DIR = $(USR_DIR)/inc/ -SRC_DIR = $(USR_DIR)/src/ - -# dependencies - -_ALL = user_iface.o user_clui.o user_tui.o -ALL = $(_ALL) user_mod.o - -UI_INC_IMG = img_iface.h -UI_INC_PROC = proc_iface.h -UI_INC = user_iface.h user_clui.h user_tui.h -UI_DEPS = $(SRC_DIR)/user_iface.c \ - $(patsubst %,$(INC_DIR)/%,$(UI_INC)) \ - $(patsubst %,$(IMG_INC_DIR)/%,$(UI_INC_IMG)) \ - $(patsubst %,$(PROC_INC_DIR)/%,$(UI_INC_PROC)) -UI_INC_DIRS = -I $(INC_DIR) \ - -I $(IMG_INC_DIR) \ - -I $(PROC_INC_DIR) - -UCLUI_INC_LIBALX = libalx/curses/alx_ncur.h -UCLUI_INC_IMG = img_iface.h -UCLUI_INC = user_clui.h user_iface.h -UCLUI_DEPS = $(SRC_DIR)/user_clui.c \ - $(patsubst %,$(INC_DIR)/%,$(UCLUI_INC)) \ - $(patsubst %,$(IMG_INC_DIR)/%,$(UCLUI_INC_IMG)) \ - $(patsubst %,$(LIBALX_INC_DIR)/%,$(UCLUI_INC_LIBALX)) -UCLUI_INC_DIRS = -I $(INC_DIR) \ - -I $(LIBALX_INC_DIR) \ - -I $(IMG_INC_DIR) - -UTUI_INC_LIBALX = libalx/curses/alx_ncur.h -UTUI_INC_IMG = img_iface.h -UTUI_INC = user_tui.h user_iface.h -UTUI_DEPS = $(SRC_DIR)/user_tui.c \ - $(patsubst %,$(INC_DIR)/%,$(UTUI_INC)) \ - $(patsubst %,$(IMG_INC_DIR)/%,$(UTUI_INC_IMG)) \ - $(patsubst %,$(LIBALX_INC_DIR)/%,$(UTUI_INC_LIBALX)) -UTUI_INC_DIRS = -I $(INC_DIR) \ - -I $(LIBALX_INC_DIR) \ - -I $(IMG_INC_DIR) - -# target: dependencies -# action - -all: $(ALL) - - -user_mod.o: $(_ALL) - $(Q)$(LD) -r $^ -o $@ - @echo " LD $@" - - -user_iface.s: $(UI_DEPS) - $(Q)$(CC) $(CFLAGS) $(UI_INC_DIRS) -S $< -o $@ - @echo " CC $@" -user_iface.o: user_iface.s - $(Q)$(AS) $< -o $@ - @echo " AS $@" - -user_clui.s: $(UCLUI_DEPS) - $(Q)$(CC) $(CFLAGS) $(UCLUI_INC_DIRS) -S $< -o $@ - @echo " CC $@" -user_clui.o: user_clui.s - $(Q)$(AS) $< -o $@ - @echo " AS $@" - -user_tui.s: $(UTUI_DEPS) - $(Q)$(CC) $(CFLAGS) $(UTUI_INC_DIRS) -S $< -o $@ - @echo " CC $@" -user_tui.o: user_tui.s - $(Q)$(AS) $< -o $@ - @echo " AS $@" - - -clean: - $(Q)rm -f *.o *.s diff --git a/share/COPYRIGHT.txt b/share/COPYRIGHT.txt deleted file mode 100644 index 64ca5ad..0000000 --- a/share/COPYRIGHT.txt +++ /dev/null @@ -1,8 +0,0 @@ - - - vision-artificial Copyright (C) 2018 Alejandro COLOMAR ANDRES - - This program comes with ABSOLUTELY NO WARRANTY. - This is free software, and you are welcome to redistribute it - under certain conditions; see the file COPYING.txt for details. - diff --git a/share/DISCLAIMER.txt b/share/DISCLAIMER.txt deleted file mode 100644 index 291440a..0000000 --- a/share/DISCLAIMER.txt +++ /dev/null @@ -1,16 +0,0 @@ -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - - Disclaimer of Warranty. - -THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. - -THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OFANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - -THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. - -SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY -SERVICING, REPAIR OR CORRECTION. - -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! diff --git a/share/HELP.txt b/share/HELP.txt deleted file mode 100644 index 000f7ef..0000000 --- a/share/HELP.txt +++ /dev/null @@ -1,25 +0,0 @@ -Usage: $ vision-artificial [OPTION...] - - -f, --file=FILE set image file - -i, --iface=IFACE set program interface - - Other: - -L, --license display license - -h, --help give this help list - -u, --usage give a short usage message - -v, --version print program version - -MANDATORY or [OPTIONAL] arguments to long options are also mandatory or optional -for any corresponding short options. - - - Examples: - $ vision-artificial - $ vision-artificial --version - $ vision-artificial --license - $ vision-artificial -i 1 - $ vision-artificial -f <file> - - -Report bugs to: 1903716@gmail.com -vision-artificial home page: <https://github.com/AlejandroColomar/vision-artificial/> diff --git a/share/LICENSE.txt b/share/LICENSE.txt deleted file mode 100644 index 0776f74..0000000 --- a/share/LICENSE.txt +++ /dev/null @@ -1,352 +0,0 @@ - NOTE! The GPL below is copyrighted by the Free Software - Foundation, but the instance of code that it refers to (vision-artificial) - is copyrighted by me who actually wrote it. - - Also note that the only valid version of the GPL is _this_ particular - version of the license (ie v2, not v2.2 or v3.x or whatever), unless - explicitly otherwise stated. - - Alejandro Colomar - ----------------------------------------- - - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. -51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - <one line to give the program's name and a brief idea of what it does.> - Copyright (C) <year> <name of author> - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - <signature of Ty Coon>, 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. diff --git a/share/README.txt b/share/README.txt deleted file mode 100644 index b523695..0000000 --- a/share/README.txt +++ /dev/null @@ -1,84 +0,0 @@ -/****************************************************************************** - * vision-artificial Copyright (C) 2018 Alejandro Colomar Andrés * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, version 2. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, see the file COPYING, or write * - * to the Free Software Foundation, Inc. * - ****************************************************************************** - * Disclaimer of Warranty. * - * * - * THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY * - * APPLICABLE LAW. * - * * - * EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER * - * PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER * - * EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * - * * - * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH * - * YOU. * - * * - * SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY * - * SERVICING, REPAIR OR CORRECTION. * - ******************************************************************************/ - - If you make a version, please tell me. - I would like to see it. Thank you. - -site: - https://github.com/AlejandroColomar/vision-artificial - - -COMPILE: - $ make - -INSTALL: - # make install - -RUN: - $ vision-artificial - if it doesn't work: - $ /usr/local/games/vision-artificial - -UNINSTALL: - # make uninstall - - -The program creates a folder '.vision-artificial/' at $HOME. It -is used by the program to store saved images. If you remove the program, you -should delete that folder manually. - - -THE PROGRAM DOES: - // FIXME - - -MENU: - When you run the program, it starts in a menu that has these branches: - - /* - * + Menu: - * + Continue: - * - Start - * - Change file name (File: "<file_name>") - * - .. - * - Disclaimer of warranty - * - Terms and conditions - * - Exit program - */ - - -SYSTEM REQUIREMENTS: - - * ¿? - -To be continued... diff --git a/share/USAGE.txt b/share/USAGE.txt deleted file mode 100644 index fcbbfc7..0000000 --- a/share/USAGE.txt +++ /dev/null @@ -1,5 +0,0 @@ - Usage: $ vision-artificial [--help] [--license] [--usage] [--version] - [--file=FILE] [--iface=IFACE] - - - Type '$ vision-artificial --help' for a full description. diff --git a/share/price b/share/price deleted file mode 100644 index c2b89cc..0000000 --- a/share/price +++ /dev/null @@ -1 +0,0 @@ -tessedit_char_whitelist 0123456789.€ diff --git a/share/vision-artificial/COPYRIGHT.txt b/share/vision-artificial/COPYRIGHT.txt new file mode 100644 index 0000000..64ca5ad --- /dev/null +++ b/share/vision-artificial/COPYRIGHT.txt @@ -0,0 +1,8 @@ + + + vision-artificial Copyright (C) 2018 Alejandro COLOMAR ANDRES + + This program comes with ABSOLUTELY NO WARRANTY. + This is free software, and you are welcome to redistribute it + under certain conditions; see the file COPYING.txt for details. + diff --git a/share/vision-artificial/DISCLAIMER.txt b/share/vision-artificial/DISCLAIMER.txt new file mode 100644 index 0000000..291440a --- /dev/null +++ b/share/vision-artificial/DISCLAIMER.txt @@ -0,0 +1,16 @@ +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + + Disclaimer of Warranty. + +THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. + +THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OFANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + +THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. + +SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY +SERVICING, REPAIR OR CORRECTION. + +!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! diff --git a/share/vision-artificial/HELP.txt b/share/vision-artificial/HELP.txt new file mode 100644 index 0000000..000f7ef --- /dev/null +++ b/share/vision-artificial/HELP.txt @@ -0,0 +1,25 @@ +Usage: $ vision-artificial [OPTION...] + + -f, --file=FILE set image file + -i, --iface=IFACE set program interface + + Other: + -L, --license display license + -h, --help give this help list + -u, --usage give a short usage message + -v, --version print program version + +MANDATORY or [OPTIONAL] arguments to long options are also mandatory or optional +for any corresponding short options. + + + Examples: + $ vision-artificial + $ vision-artificial --version + $ vision-artificial --license + $ vision-artificial -i 1 + $ vision-artificial -f <file> + + +Report bugs to: 1903716@gmail.com +vision-artificial home page: <https://github.com/AlejandroColomar/vision-artificial/> diff --git a/share/vision-artificial/LICENSE.txt b/share/vision-artificial/LICENSE.txt new file mode 100644 index 0000000..0776f74 --- /dev/null +++ b/share/vision-artificial/LICENSE.txt @@ -0,0 +1,352 @@ + NOTE! The GPL below is copyrighted by the Free Software + Foundation, but the instance of code that it refers to (vision-artificial) + is copyrighted by me who actually wrote it. + + Also note that the only valid version of the GPL is _this_ particular + version of the license (ie v2, not v2.2 or v3.x or whatever), unless + explicitly otherwise stated. + + Alejandro Colomar + +---------------------------------------- + + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc. +51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Library General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + <one line to give the program's name and a brief idea of what it does.> + Copyright (C) <year> <name of author> + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + <signature of Ty Coon>, 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Library General +Public License instead of this License. diff --git a/share/vision-artificial/README.txt b/share/vision-artificial/README.txt new file mode 100644 index 0000000..b523695 --- /dev/null +++ b/share/vision-artificial/README.txt @@ -0,0 +1,84 @@ +/****************************************************************************** + * vision-artificial Copyright (C) 2018 Alejandro Colomar Andrés * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, version 2. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, see the file COPYING, or write * + * to the Free Software Foundation, Inc. * + ****************************************************************************** + * Disclaimer of Warranty. * + * * + * THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY * + * APPLICABLE LAW. * + * * + * EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER * + * PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER * + * EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * + * * + * THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH * + * YOU. * + * * + * SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY * + * SERVICING, REPAIR OR CORRECTION. * + ******************************************************************************/ + + If you make a version, please tell me. + I would like to see it. Thank you. + +site: + https://github.com/AlejandroColomar/vision-artificial + + +COMPILE: + $ make + +INSTALL: + # make install + +RUN: + $ vision-artificial + if it doesn't work: + $ /usr/local/games/vision-artificial + +UNINSTALL: + # make uninstall + + +The program creates a folder '.vision-artificial/' at $HOME. It +is used by the program to store saved images. If you remove the program, you +should delete that folder manually. + + +THE PROGRAM DOES: + // FIXME + + +MENU: + When you run the program, it starts in a menu that has these branches: + + /* + * + Menu: + * + Continue: + * - Start + * - Change file name (File: "<file_name>") + * - .. + * - Disclaimer of warranty + * - Terms and conditions + * - Exit program + */ + + +SYSTEM REQUIREMENTS: + + * ¿? + +To be continued... diff --git a/share/vision-artificial/USAGE.txt b/share/vision-artificial/USAGE.txt new file mode 100644 index 0000000..fcbbfc7 --- /dev/null +++ b/share/vision-artificial/USAGE.txt @@ -0,0 +1,5 @@ + Usage: $ vision-artificial [--help] [--license] [--usage] [--version] + [--file=FILE] [--iface=IFACE] + + + Type '$ vision-artificial --help' for a full description. diff --git a/share/vision-artificial/price b/share/vision-artificial/price new file mode 100644 index 0000000..c2b89cc --- /dev/null +++ b/share/vision-artificial/price @@ -0,0 +1 @@ +tessedit_char_whitelist 0123456789.€ diff --git a/src/about/about.c b/src/about/about.c new file mode 100644 index 0000000..60f5104 --- /dev/null +++ b/src/about/about.c @@ -0,0 +1,144 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "vision-artificial/about/about.h" + +#include <errno.h> +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> + +#include "libalx/base/errno/errno_str.h" +#include "libalx/base/stdio/sprint_file.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +#define BUFF_SIZE_TEXT (0xFFFF) /* 64 KiB */ +#define BEGINNING "\n┌──────────────────────────────────────────────────────────────────────────────┐\n" +#define ENDING "└──────────────────────────────────────────────────────────────────────────────┘\n\n" + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +char share_path [FILENAME_MAX]; + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void about_init (void) +{ + + if (snprintf(share_path, FILENAME_MAX, "%s/estadistica/", + INSTALL_SHARE_DIR) >= FILENAME_MAX) { + goto err; + } + return; +err: + printf("Path is too large and has been truncated\n"); + exit(EXIT_FAILURE); +} + +void snprint_share_file (ptrdiff_t size, char buff[restrict size], + int file) +{ + char fname [FILENAME_MAX]; + + switch (file) { + case SHARE_COPYRIGHT: + if (snprintf(fname, FILENAME_MAX, "%s/%s", + share_path, + "COPYRIGHT.txt") >= FILENAME_MAX) { + goto err; + } + break; + case SHARE_DISCLAIMER: + if (snprintf(fname, FILENAME_MAX, "%s/%s", + share_path, + "DISCLAIMER.txt") >= FILENAME_MAX) { + goto err; + } + break; + case SHARE_HELP: + if (snprintf(fname, FILENAME_MAX, "%s/%s", + share_path, + "HELP.txt") >= FILENAME_MAX) { + goto err; + } + break; + case SHARE_LICENSE: + if (snprintf(fname, FILENAME_MAX, "%s/%s", + share_path, + "LICENSE.txt") >= FILENAME_MAX) { + goto err; + } + break; + case SHARE_USAGE: + if (snprintf(fname, FILENAME_MAX, "%s/%s", + share_path, + "USAGE.txt") >= FILENAME_MAX) { + goto err; + } + break; + } + + if (alx_snprint_file(size, buff, fname) < 0) + printf("%s: %s\n", errno_str[errno][0], errno_str[errno][1]); + + return; + +err: + printf("Path is too large and has been truncated\n"); + printf("File could not be shown!\n"); +} + +void print_share_file (int file) +{ + char str [BUFF_SIZE_TEXT]; + + snprint_share_file(BUFF_SIZE_TEXT, str, file); + + printf(BEGINNING); + printf("%s", str); + printf(ENDING); +} + +void print_version (void) +{ + + printf(""PROG_NAME" "PROG_VERSION"\n\n"); +} + + +/****************************************************************************** + ******* static functions (definitions) *************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/ctrl/start.c b/src/ctrl/start.c new file mode 100644 index 0000000..5562503 --- /dev/null +++ b/src/ctrl/start.c @@ -0,0 +1,100 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "vision-artificial/ctrl/start.h" + +#include <errno.h> +#include <stddef.h> +#include <stdio.h> + +#include "vision-artificial/image/iface.h" +#include "vision-artificial/proc/iface.h" +#include "vision-artificial/save/save.h" +#include "vision-artificial/user/iface.h" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +int start_mode; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void start_foo (void); +static void start_single (void); +static void start_series (void); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void start_switch (void) +{ + + switch (start_mode) { + case START_FOO: + start_foo(); + break; + + case START_SINGLE: + start_single(); + break; + + case START_SERIES: + start_series(); + break; + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void start_foo (void) +{ +} + +static void start_single (void) +{ + + img_iface_init(); + errno = 0; + img_iface_load(NULL, saved_name); + + if (!errno) { + user_iface_init(); + user_iface(); + user_iface_cleanup(); + } else { + printf("errno:%i\n", errno); + } + + img_iface_cleanup(); +} + +static void start_series (void) +{ + int tmp; + + tmp = user_iface_mode; + user_iface_mode = USER_IFACE_CLUI; + + user_iface_init(); + proc_iface_series(); + user_iface_cleanup(); + + user_iface_mode = tmp; +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/image/alx.cpp b/src/image/alx.cpp new file mode 100644 index 0000000..a0a6ae2 --- /dev/null +++ b/src/image/alx.cpp @@ -0,0 +1,430 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: (GPL-2.0-only OR LGPL-3.0-only) * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "vision-artificial/image/alx.hpp" + +#include <cstdbool> +#include <cstddef> +#include <cstdlib> +#include <cstdio> + +#include <opencv2/opencv.hpp> + +#include "libalx/base/math/arithmetic_mean.hpp" +#include "libalx/base/math/median.hpp" + +#include "vision-artificial/image/iface.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Cell { + NOT_LOCAL_MAX, + MAYBE_LOCAL_MAX, + LOCAL_MAX +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ +static void img_alx_local_max (class cv::Mat *imgptr); +static void img_alx_skeleton (class cv::Mat *imgptr); +static void img_alx_lines_horizontal (class cv::Mat *imgptr); +static void img_alx_lines_vertical (class cv::Mat *imgptr); +static void img_alx_mean_horizontal (class cv::Mat *imgptr); +static void img_alx_mean_vertical (class cv::Mat *imgptr); +static void img_alx_median_horizontal (class cv::Mat *imgptr); +static void img_alx_median_vertical (class cv::Mat *imgptr); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void img_alx_act (class cv::Mat *imgptr, int action, const void *data) +{ + + switch (action) { + case IMG_ALX_ACT_LOCAL_MAX: + img_alx_local_max(imgptr); + break; + case IMG_ALX_ACT_SKELETON: + img_alx_skeleton(imgptr); + break; + + case IMG_ALX_ACT_LINES_HORIZONTAL: + img_alx_lines_horizontal(imgptr); + break; + case IMG_ALX_ACT_LINES_VERTICAL: + img_alx_lines_vertical(imgptr); + break; + + case IMG_ALX_ACT_MEAN_HORIZONTAL: + img_alx_mean_horizontal(imgptr); + break; + case IMG_ALX_ACT_MEAN_VERTICAL: + img_alx_mean_vertical(imgptr); + break; + case IMG_ALX_ACT_MEDIAN_HORIZONTAL: + img_alx_median_horizontal(imgptr); + break; + case IMG_ALX_ACT_MEDIAN_VERTICAL: + img_alx_median_vertical(imgptr); + break; + } +} + + +/****************************************************************************** + ******* static functions (definitions) *************************************** + ******************************************************************************/ +static void img_alx_local_max (class cv::Mat *imgptr) +{ + const ptrdiff_t rows = imgptr->rows; + const ptrdiff_t cols = imgptr->cols; + const ptrdiff_t step = imgptr->step; + /* Minimum distance between local maxima */ + const int dist = 4; + /* Minimum value of local maxima */ + const uint8_t val_min = 16; + class cv::Mat imgtmp; + int arr_tmp[rows][cols]; + bool wh; + /* pointer to a pixel (in imgptr) */ + const uint8_t *img_pix; + /* pointer to a pixel near img_pix (in imgptr) */ + const uint8_t *near_pix; + /* pointer to a pixel (same position as img_pix, but in imgtmp) */ + uint8_t *tmp_pix; + + /* Tmp image copy */ + imgptr->copyTo(imgtmp); + + memset(arr_tmp, 0, sizeof(arr_tmp)); + + for (ptrdiff_t i = 0; i < rows; i++) { + for (ptrdiff_t j = 0; j < cols; j++) { + img_pix = imgptr->data + i*step + j; + if (*img_pix < val_min) + continue; + + for (ptrdiff_t k = (i + dist + 1); k >= (i - dist - 1); k--) { + for (ptrdiff_t l = (j + dist + 1); l >= (j - dist - 1); l--) { + if ((k > 0) && (k < rows)) { + if ((l > 0) && (l < cols)) { + near_pix = imgptr->data + k*step + l; + if (*near_pix > *img_pix) + goto not_maxima; + if (*near_pix == *img_pix) + arr_tmp[i][j] = MAYBE_LOCAL_MAX; + } + } + } + } + if (!arr_tmp[i][j]) + arr_tmp[i][j] = LOCAL_MAX; + continue; +not_maxima: + ; + } + } + + do { + wh = false; + for (ptrdiff_t i = 0; i < rows; i++) { + for (ptrdiff_t j = 0; j < cols; j++) { + img_pix = imgptr->data + i*step + j; + if (arr_tmp[i][j] != MAYBE_LOCAL_MAX) + continue; + for (ptrdiff_t k = (i+dist+1); k >= (i-dist-1); k--) { + for (ptrdiff_t l = (j+dist+1); l >= (j-dist-1); l--) { + if ((k > 0) && (k < rows)) { + if ((l > 0) && (l < cols)) { + near_pix = imgptr->data + k*step + l; + if (*near_pix == *img_pix) { + if (!arr_tmp[k][l]) + goto not_maxima_2; + } + } + } + } + } + continue; +not_maxima_2: + wh = true; + arr_tmp[i][j] = 0; + } + } + } while (wh); + + for (ptrdiff_t i = 0; i < rows; i++) { + for (ptrdiff_t j = 0; j < cols; j++) { + if (!arr_tmp[i][j]) { + tmp_pix = imgtmp.data + i * step + j; + *tmp_pix = 0; + } + } + } + + /* Cleanup */ + imgtmp.copyTo(*imgptr); + imgtmp.release(); +} + +static void img_alx_skeleton (class cv::Mat *imgptr) +{ + const ptrdiff_t rows = imgptr->rows; + const ptrdiff_t cols = imgptr->cols; + const ptrdiff_t step = imgptr->step; + /* (Half of the) width of the skeleton */ + const ptrdiff_t width = 5; + ptrdiff_t dist_x; + ptrdiff_t dist_y; + bool skeleton; + int_fast16_t cnt_lo [width]; + int_fast16_t cnt_hi_or_eq [width]; + class cv::Mat imgtmp; + /* pointer to a pixel (in imgptr) */ + const uint8_t *img_pix; + /* pointer to a pixel near img_pix (in imgptr) */ + const uint8_t *near_pix; + /* pointer to a pixel (same position as img_pix, but in imgtmp) */ + uint8_t *tmp_pix; + + /* Tmp image copy */ + imgptr->copyTo(imgtmp); + + for (ptrdiff_t i = 0; i < rows; i++) { + for (ptrdiff_t j = 0; j < cols; j++) { + img_pix = imgptr->data + i * step + j; + tmp_pix = imgtmp.data + i * step + j; + + if (!(*img_pix)) { + *tmp_pix = 0; + continue; + } + + for (ptrdiff_t r = 0; r < width; r++) { + cnt_lo[r] = 0; + cnt_hi_or_eq[r] = 0; + } + + for (ptrdiff_t k = (i + width); k >= (i - width); k--) { + for (ptrdiff_t l = (j + width); l >= (j - width); l--) { + near_pix = imgptr->data + k * step + l; + + dist_x = abs(k - i); + dist_y = abs(l - j); + + if ((k >= 0) && (k < rows)) { + if ((l >= 0) && (l < cols)) { + if (dist_x || dist_y) { + if (*near_pix < *img_pix) + cnt_lo[std::max(dist_x, dist_y)]++; + else + cnt_hi_or_eq[std::max(dist_x, dist_y)]++; + } + } + } + + } + } + + skeleton = false; + for (ptrdiff_t r = 0; r < width; r++) { + if (cnt_lo[r] > (cnt_hi_or_eq[r] + (1.6) * (r + 1))) + skeleton = true; + } + + if (skeleton) + *tmp_pix = *img_pix; + else + *tmp_pix = 0; + } + } + + /* Cleanup */ + imgtmp.copyTo(*imgptr); + imgtmp.release(); +} + +static void img_alx_lines_horizontal (class cv::Mat *imgptr) +{ + const ptrdiff_t rows = imgptr->rows; + const ptrdiff_t cols = imgptr->cols; + const ptrdiff_t step = imgptr->step; + bool white; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + + for (ptrdiff_t i = 0; i < rows; i++) { + white = false; + + for (ptrdiff_t j = 0; j < cols; j++) { + img_pix = imgptr->data + i * step + j; + if (*img_pix) { + white = true; + break; + } + } + + if (white) { + for (ptrdiff_t j = 0; j < cols; j++) { + img_pix = imgptr->data + i * step + j; + *img_pix = 255; + } + } + } +} + +static void img_alx_lines_vertical (class cv::Mat *imgptr) +{ + const ptrdiff_t rows = imgptr->rows; + const ptrdiff_t cols = imgptr->cols; + const ptrdiff_t step = imgptr->step; + bool white; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + + for (ptrdiff_t i = 0; i < cols; i++) { + white = false; + + for (ptrdiff_t j = 0; j < rows; j++) { + img_pix = imgptr->data + j * step + i; + if (*img_pix) { + white = true; + break; + } + } + + if (white) { + for (ptrdiff_t j = 0; j < rows; j++) { + img_pix = imgptr->data + j * step + i; + *img_pix = 255; + } + } + } +} + +static void img_alx_mean_horizontal (class cv::Mat *imgptr) +{ + const ptrdiff_t rows = imgptr->rows; + const ptrdiff_t cols = imgptr->cols; + const ptrdiff_t step = imgptr->step; + uint8_t row [cols]; + uint8_t mean; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + + for (ptrdiff_t i = 0; i < rows; i++) { + for (ptrdiff_t j = 0; j < cols; j++) { + img_pix = imgptr->data + i * step + j; + row[j] = *img_pix; + } + mean = alx_arithmetic_mean_u8(cols, row); + + for (ptrdiff_t j = 0; j < cols; j++) { + img_pix = imgptr->data + i * step + j; + *img_pix = mean; + } + } +} + +static void img_alx_mean_vertical (class cv::Mat *imgptr) +{ + const ptrdiff_t rows = imgptr->rows; + const ptrdiff_t cols = imgptr->cols; + const ptrdiff_t step = imgptr->step; + uint8_t col [rows]; + uint8_t mean; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + + for (ptrdiff_t i = 0; i < cols; i++) { + for (ptrdiff_t j = 0; j < rows; j++) { + img_pix = imgptr->data + j * step + i; + col[j] = *img_pix; + } + mean = alx_arithmetic_mean_u8(rows, col); + + for (ptrdiff_t j = 0; j < rows; j++) { + img_pix = imgptr->data + j * step + i; + *img_pix = mean; + } + } +} + +static void img_alx_median_horizontal (class cv::Mat *imgptr) +{ + const ptrdiff_t rows = imgptr->rows; + const ptrdiff_t cols = imgptr->cols; + const ptrdiff_t step = imgptr->step; + uint8_t row [cols]; + uint8_t median; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + + for (ptrdiff_t i = 0; i < rows; i++) { + for (ptrdiff_t j = 0; j < cols; j++) { + img_pix = imgptr->data + i * step + j; + row[j] = *img_pix; + } + median = alx_median_u8(cols, row); + + for (ptrdiff_t j = 0; j < cols; j++) { + img_pix = imgptr->data + i * step + j; + *img_pix = median; + } + } +} + +static void img_alx_median_vertical (class cv::Mat *imgptr) +{ + const ptrdiff_t rows = imgptr->rows; + const ptrdiff_t cols = imgptr->cols; + const ptrdiff_t step = imgptr->step; + uint8_t col [rows]; + uint8_t median; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + + for (ptrdiff_t i = 0; i < cols; i++) { + for (ptrdiff_t j = 0; j < rows; j++) { + img_pix = imgptr->data + j * step + i; + col[j] = *img_pix; + } + median = alx_median_u8(rows, col); + + for (ptrdiff_t j = 0; j < rows; j++) { + img_pix = imgptr->data + j * step + i; + *img_pix = median; + } + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/image/calib3d.cpp b/src/image/calib3d.cpp new file mode 100644 index 0000000..43fa360 --- /dev/null +++ b/src/image/calib3d.cpp @@ -0,0 +1,125 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "vision-artificial/image/calib3d.hpp" + +#include <cstddef> +#include <cstdio> + +#include <vector> + +#include <opencv2/opencv.hpp> +#include <opencv2/calib3d/calib3d.hpp> + +#include "vision-artificial/image/iface.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +#define CORNERS_HOR (16) +#define CORNERS_VER (13) + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void img_calib3d_calibrate(class cv::Mat *imgptr, const void *data); +static void img_calib3d_undistort(class cv::Mat *imgptr, const void *data); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void img_calib3d_act(class cv::Mat *imgptr, int action, const void *data) +{ + switch (action) { + case IMG_CALIB3D_ACT_CALIBRATE: + img_calib3d_calibrate(imgptr, data); + break; + + case IMG_CALIB3D_ACT_UNDISTORT: + img_calib3d_undistort(imgptr, data); + break; + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void img_calib3d_calibrate(class cv::Mat *imgptr, const void *data) +{ + const struct Img_Iface_Data_Calibrate *data_cast; + class cv::Mat *intrinsic_mat; + class cv::Mat *dist_coefs; + class std::vector <class cv::Mat> *rvecs; + class std::vector <class cv::Mat> *tvecs; + + class cv::Size_ <int> pattern_size; + class std::vector <class std::vector <class cv::Point3_ <float>>> object_points; + class std::vector <class std::vector <class cv::Point_ <float>>> image_points; + class std::vector <class cv::Point_ <float>> corners; + class std::vector <class cv::Point3_ <float>> obj; + bool found; + + data_cast = (const struct Img_Iface_Data_Calibrate *)data; + intrinsic_mat = data_cast->intrinsic_mat; + dist_coefs = data_cast->dist_coefs; + rvecs = data_cast->rvecs; + tvecs = data_cast->tvecs; + + pattern_size = cv::Size(CORNERS_HOR, CORNERS_VER); + *intrinsic_mat = cv::Mat(3, 3, CV_32FC1); + (*intrinsic_mat).ptr<float>(0)[0] = 1; + (*intrinsic_mat).ptr<float>(1)[1] = 1; + + for (ptrdiff_t i = 0; i < CORNERS_HOR; i++) { + for (ptrdiff_t j = 0; j < CORNERS_VER; j++) + obj.push_back(cv::Point3f(i, j * 10.0, 0.0)); + } + + found = cv::findChessboardCorners(*imgptr, pattern_size, corners, + CV_CALIB_CB_ADAPTIVE_THRESH | + CV_CALIB_CB_FILTER_QUADS); + + cv::cornerSubPix(*imgptr, corners, cv::Size(11, 11), + cv::Size(-1, -1), + cv::TermCriteria(CV_TERMCRIT_EPS | + CV_TERMCRIT_ITER, 30, 0.1)); + cv::drawChessboardCorners(*imgptr, pattern_size, corners, found); + + image_points.push_back(corners); + object_points.push_back(obj); + + cv::calibrateCamera(object_points, image_points, imgptr->size(), + *intrinsic_mat, *dist_coefs, *rvecs, *tvecs); +} + +static void img_calib3d_undistort(class cv::Mat *imgptr, const void *data) +{ + class cv::Mat imgtmp; + const struct Img_Iface_Data_Undistort *data_cast; + const class cv::Mat *intrinsic_mat; + const class cv::Mat *dist_coefs; + + data_cast = (const struct Img_Iface_Data_Undistort *)data; + intrinsic_mat = data_cast->intrinsic_mat; + dist_coefs = data_cast->dist_coefs; + + cv::undistort(*imgptr, imgtmp, *intrinsic_mat, *dist_coefs); + + imgptr->release(); + imgtmp.copyTo(*imgptr); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/image/cv.cpp b/src/image/cv.cpp new file mode 100644 index 0000000..b5d4877 --- /dev/null +++ b/src/image/cv.cpp @@ -0,0 +1,802 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "vision-artificial/image/cv.hpp" + +#include <cmath> +#include <cstdbool> +#include <cstddef> +#include <cstdint> +#include <cstdio> + +#include <vector> + +#include <opencv2/opencv.hpp> + +#include "vision-artificial/image/iface.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ + /* Core: The core functionality */ + /* Pixel */ +static void img_cv_pixel_get (const class cv::Mat *imgptr, const void *data); +static void img_cv_pixel_set (class cv::Mat *imgptr, const void *data); + /* ROI */ +static void img_cv_set_ROI (class cv::Mat *imgptr, const void *data); + /* Operations on Arrays */ +static void img_cv_and_2ref (class cv::Mat *imgptr, const void *data); +static void img_cv_not (class cv::Mat *imgptr); +static void img_cv_or_2ref (class cv::Mat *imgptr, const void *data); +static void img_cv_component (class cv::Mat *imgptr, const void *data); + /* Imgproc: Image processing */ + /* Image filtering */ +static void img_cv_dilate (class cv::Mat *imgptr, const void *data); +static void img_cv_erode (class cv::Mat *imgptr, const void *data); +static void img_cv_smooth (class cv::Mat *imgptr, const void *data); +static void img_cv_sobel (class cv::Mat *imgptr, const void *data); +static void img_cv_border (class cv::Mat *imgptr, const void *data); + /* Geometric image transformations */ +static void img_cv_mirror (class cv::Mat *imgptr, const void *data); +static void img_cv_rotate_orto (class cv::Mat *imgptr, const void *data); +static void img_cv_rotate (class cv::Mat *imgptr, const void *data); + /* Miscellaneous image transformations */ +static void img_cv_adaptive_thr (class cv::Mat *imgptr, const void *data); +static void img_cv_cvt_color (class cv::Mat *imgptr, const void *data); +static void img_cv_distance_transform(class cv::Mat *imgptr); +static void img_cv_threshold (class cv::Mat *imgptr, const void *data); + /* Histograms */ +static void img_cv_histogram (class cv::Mat *imgptr, const void *data); +static void img_cv_histogram_c3 (class cv::Mat *imgptr, const void *data); + /* Structural analysis and shape descriptors */ +static void img_cv_contours (class cv::Mat *imgptr, const void *data); +static void img_cv_contours_size (const void *data); +static void img_cv_bounding_rect (class cv::Mat *imgptr, const void *data); +static void img_cv_fit_ellipse (class cv::Mat *imgptr, const void *data); +static void img_cv_min_area_rect (class cv::Mat *imgptr, const void *data); + /* Feature detection */ +static void img_cv_hough_circles (class cv::Mat *imgptr, const void *data); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void img_cv_act (class cv::Mat *imgptr, int action, const void *data) +{ + switch (action) { + case IMG_CV_ACT_PIXEL_GET: + img_cv_pixel_get(imgptr, data); + break; + case IMG_CV_ACT_PIXEL_SET: + img_cv_pixel_set(imgptr, data); + break; + + case IMG_CV_ACT_SET_ROI: + img_cv_set_ROI(imgptr, data); + break; + + case IMG_CV_ACT_AND_2REF: + img_cv_and_2ref(imgptr, data); + break; + 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_COMPONENT: + img_cv_component(imgptr, data); + break; + + case IMG_CV_ACT_DILATE: + img_cv_dilate(imgptr, data); + break; + case IMG_CV_ACT_ERODE: + img_cv_erode(imgptr, data); + break; + case IMG_CV_ACT_SMOOTH: + img_cv_smooth(imgptr, data); + break; + case IMG_CV_ACT_SOBEL: + img_cv_sobel(imgptr, data); + break; + case IMG_CV_ACT_BORDER: + img_cv_border(imgptr, data); + break; + + case IMG_CV_ACT_MIRROR: + img_cv_mirror(imgptr, data); + break; + case IMG_CV_ACT_ROTATE_ORTO: + img_cv_rotate_orto(imgptr, data); + break; + case IMG_CV_ACT_ROTATE: + img_cv_rotate(imgptr, data); + break; + + case IMG_CV_ACT_ADAPTIVE_THRESHOLD: + img_cv_adaptive_thr(imgptr, data); + break; + case IMG_CV_ACT_CVT_COLOR: + img_cv_cvt_color(imgptr, data); + break; + case IMG_CV_ACT_DISTANCE_TRANSFORM: + img_cv_distance_transform(imgptr); + break; + case IMG_CV_ACT_THRESHOLD: + img_cv_threshold(imgptr, data); + break; + + case IMG_CV_ACT_HISTOGRAM: + img_cv_histogram(imgptr, data); + break; + case IMG_CV_ACT_HISTOGRAM_C3: + img_cv_histogram_c3(imgptr, data); + break; + + case IMG_CV_ACT_CONTOURS: + img_cv_contours(imgptr, data); + break; + case IMG_CV_ACT_CONTOURS_SIZE: + img_cv_contours_size(data); + break; + case IMG_CV_ACT_BOUNDING_RECT: + img_cv_bounding_rect(imgptr, data); + break; + case IMG_CV_ACT_FIT_ELLIPSE: + img_cv_fit_ellipse(imgptr, data); + break; + case IMG_CV_ACT_MIN_AREA_RECT: + img_cv_min_area_rect(imgptr, data); + break; + + case IMG_CV_ACT_HOUGH_CIRCLES: + img_cv_hough_circles(imgptr, data); + break; + } +} + + +/****************************************************************************** + ******* static functions (definitions) *************************************** + ******************************************************************************/ +/* Core: The core functionality */ +/* ----- Pixel */ +static void img_cv_pixel_get (const class cv::Mat *imgptr, const void *data) +{ + const struct Img_Iface_Data_Pixel_Get *data_cast; + unsigned char *val; + ptrdiff_t x; + ptrdiff_t y; + + data_cast = (const struct Img_Iface_Data_Pixel_Get *)data; + val = data_cast->val; + x = data_cast->x; + y = data_cast->y; + + *val = imgptr->at<unsigned char>(y, x); +} + +static void img_cv_pixel_set (class cv::Mat *imgptr, const void *data) +{ + const struct Img_Iface_Data_Pixel_Set *data_cast; + unsigned char val; + ptrdiff_t x; + ptrdiff_t y; + + data_cast = (const struct Img_Iface_Data_Pixel_Set *)data; + val = data_cast->val; + x = data_cast->x; + y = data_cast->y; + + imgptr->at<unsigned char>(y, x) = val; +} + +/* ----- ROI */ +static void img_cv_set_ROI (class cv::Mat *imgptr, const void *data) +{ + const struct Img_Iface_Data_SetROI *data_cast; + const class cv::Rect_ <int> *rect; + class cv::Mat imgtmp; + + data_cast = (const struct Img_Iface_Data_SetROI *)data; + rect = &(data_cast->rect); + + (*imgptr)(*rect).copyTo(imgtmp); + imgtmp.copyTo(*imgptr); + + imgptr->release(); + imgtmp.copyTo(*imgptr); + + imgtmp.release(); +} + +/* ----- Operations on arrays */ +static void img_cv_and_2ref (class cv::Mat *imgptr, const void *data) +{ + const class cv::Mat *img_ref; + + img_ref = (const class cv::Mat *)data; + + cv::bitwise_and(*imgptr, *img_ref, *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, const void *data) +{ + const class cv::Mat *img_ref; + + img_ref = (const class cv::Mat *)data; + + cv::bitwise_or(*imgptr, *img_ref, *imgptr); +} + +static void img_cv_component (class cv::Mat *imgptr, const void *data) +{ + const struct Img_Iface_Data_Component *data_cast; + class cv::Mat cmp_img[3]; + int cmp; + + data_cast = (const struct Img_Iface_Data_Component *)data; + cmp = data_cast->cmp; + + cv::split(*imgptr, cmp_img); + + imgptr->release(); + cmp_img[cmp].copyTo(*imgptr); + + cmp_img[0].release(); + cmp_img[1].release(); + cmp_img[2].release(); +} + +/* Imgproc: Image processing */ +/* ----- Image filtering */ +static void img_cv_dilate (class cv::Mat *imgptr, const void *data) +{ + const struct Img_Iface_Data_Dilate_Erode *data_cast; + int i; + + data_cast = (const struct Img_Iface_Data_Dilate_Erode *)data; + i = data_cast->i; + + cv::dilate(*imgptr, *imgptr, cv::Mat(), cv::Point(-1,-1), i, + cv::BORDER_CONSTANT, cv::Scalar(0)); +} + +static void img_cv_erode (class cv::Mat *imgptr, const void *data) +{ + const struct Img_Iface_Data_Dilate_Erode *data_cast; + int i; + + data_cast = (const struct Img_Iface_Data_Dilate_Erode *)data; + i = data_cast->i; + + cv::erode(*imgptr, *imgptr, cv::Mat(), cv::Point(-1,-1), i, + cv::BORDER_CONSTANT, cv::Scalar(0)); +} + +static void img_cv_smooth (class cv::Mat *imgptr, const void *data) +{ + const struct Img_Iface_Data_Smooth *data_cast; + int method; + int ksize; + + data_cast = (const struct Img_Iface_Data_Smooth *)data; + method = data_cast->method; + ksize = data_cast->ksize; + if (!(ksize % 2)) + ksize++; + + switch (method) { + case IMGI_SMOOTH_MEAN: + cv::blur(*imgptr, *imgptr, cv::Size(ksize, ksize), + cv::Point(-1,-1), cv::BORDER_DEFAULT); + break; + case IMGI_SMOOTH_GAUSS: + cv::GaussianBlur(*imgptr, *imgptr, cv::Size(ksize, ksize), + 0, 0, cv::BORDER_DEFAULT); + break; + case IMGI_SMOOTH_MEDIAN: + cv::medianBlur(*imgptr, *imgptr, ksize); + break; + } +} + +static void img_cv_sobel (class cv::Mat *imgptr, const void *data) +{ + const struct Img_Iface_Data_Sobel *data_cast; + int dx; + int dy; + int ksize; + + data_cast = (const struct Img_Iface_Data_Sobel *)data; + dx = data_cast->dx; + dy = data_cast->dy; + ksize = data_cast->ksize; + if (!(ksize % 2)) + ksize++; + + cv::Sobel(*imgptr, *imgptr, -1, dx, dy, ksize, 1, 0, + cv::BORDER_DEFAULT); +} + +static void img_cv_border (class cv::Mat *imgptr, const void *data) +{ + const struct Img_Iface_Data_Border *data_cast; + class cv::Mat imgtmp; + ptrdiff_t size; + ptrdiff_t rows; + ptrdiff_t cols; + + /* Data */ + data_cast = (struct Img_Iface_Data_Border *)data; + size = data_cast->size; + rows = imgptr->rows; + cols = imgptr->cols; + + imgtmp = cv::Mat(cv::Size(cols + size, rows + size), CV_8U); + + cv::copyMakeBorder(*imgptr, imgtmp, size, size, size, size, + cv::BORDER_CONSTANT, cv::Scalar(0)); + + imgtmp.copyTo(*imgptr); + + imgtmp.release(); +} + +/* ----- Geometric image transformations */ +static void img_cv_mirror (class cv::Mat *imgptr, const void *data) +{ + const struct Img_Iface_Data_Mirror *data_cast; + int axis; + + data_cast = (const struct Img_Iface_Data_Mirror *)data; + axis = data_cast->axis; + + cv::flip(*imgptr, *imgptr, axis); +} + +static void img_cv_rotate_orto (class cv::Mat *imgptr, const void *data) +{ + const struct Img_Iface_Data_Rotate_Orto *data_cast; + int n; + + data_cast = (struct Img_Iface_Data_Rotate_Orto *)data; + n = data_cast->n; + + switch (n) { + case 1: + /* Rotate: transpose and flip around horizontal axis: flip_mode=0 */ + cv::transpose(*imgptr, *imgptr); + cv::flip(*imgptr, *imgptr, 0); + break; + + case 2: + /* Rotate: Flip both axises: flip_mode=-1 */ + cv::flip(*imgptr, *imgptr, -1); + break; + + case 3: + /* Rotate: transpose and flip around vertical axis: flip_mode=1 */ + cv::transpose(*imgptr, *imgptr); + cv::flip(*imgptr, *imgptr, 1); + break; + } +} + +static void img_cv_rotate (class cv::Mat *imgptr, const void *data) +{ + const struct Img_Iface_Data_Rotate *data_cast; + const class cv::Point_ <float> *center; + class cv::Mat map_matrix; + double angle; + class cv::Size_ <int> size; + + data_cast = (const struct Img_Iface_Data_Rotate *)data; + center = &(data_cast->center); + angle = data_cast->angle; + size = imgptr->size(); + + map_matrix = cv::getRotationMatrix2D(*center, angle, 1); + cv::warpAffine(*imgptr, *imgptr, map_matrix, size, cv::INTER_LINEAR, + cv::BORDER_CONSTANT, cv::Scalar(0, 0, 0)); + + map_matrix.release(); +} + +/* ----- Miscellaneous image transformations */ +static void img_cv_adaptive_thr (class cv::Mat *imgptr, const void *data) +{ + const struct Img_Iface_Data_Adaptive_Thr *data_cast; + int method; + int thr_typ; + int ksize; + + data_cast = (const struct Img_Iface_Data_Adaptive_Thr *)data; + method = data_cast->method; + thr_typ = data_cast->thr_typ; + ksize = data_cast->ksize; + if (!(ksize % 2)) + ksize++; + + cv::adaptiveThreshold(*imgptr, *imgptr, UINT8_MAX, method, thr_typ, + ksize, 0); +} + +static void img_cv_cvt_color (class cv::Mat *imgptr, const void *data) +{ + const struct Img_Iface_Data_Cvt_Color *data_cast; + int method; + + data_cast = (const struct Img_Iface_Data_Cvt_Color *)data; + method = data_cast->method; + + cv::cvtColor(*imgptr, *imgptr, method, 0); +} + +static void img_cv_distance_transform(class cv::Mat *imgptr) +{ + class cv::Mat imgtmp; + + cv::distanceTransform(*imgptr,imgtmp, CV_DIST_L2, CV_DIST_MASK_PRECISE); + + /* DistanceTransform gives CV_32F image */ + imgtmp.convertTo(*imgptr, CV_8U); + + imgtmp.release(); +} + +static void img_cv_threshold (class cv::Mat *imgptr, const void *data) +{ + const struct Img_Iface_Data_Threshold *data_cast; + int thr_typ; + int thr_val; + + data_cast = (const struct Img_Iface_Data_Threshold *)data; + thr_typ = data_cast->thr_typ; + thr_val = data_cast->thr_val; + if (thr_val == -1) + thr_typ |= cv::THRESH_OTSU; + + cv::threshold(*imgptr, *imgptr, thr_val, UINT8_MAX, thr_typ); +} + +/* ----- Histograms */ +static void img_cv_histogram (class cv::Mat *imgptr, const void *data) +{ + const struct Img_Iface_Data_Histogram *data_cast; + const int h_size = 256; + const float h_range_arr[] = {0.0, 256.0}; + const float *h_range = {h_range_arr}; + class cv::Mat *hist; + class cv::Mat *hist_img; + ptrdiff_t rows; + + data_cast = (const struct Img_Iface_Data_Histogram *)data; + hist = data_cast->hist_c0; + hist_img = data_cast->hist_img; + rows = hist_img->rows; + + /* Write components into cmp_img[] */ + cv::calcHist(imgptr, 1, 0, cv::Mat(), *hist, 1, &h_size, &h_range, + true, false); + + /* Init */ + hist_img->setTo(cv::Scalar(0)); + + /* Normalize the result to [0, rows - 1] */ + cv::normalize(*hist, *hist, 0, rows-1, cv::NORM_MINMAX, -1, cv::Mat()); + + /* Draw hist into hist_img */ + for (ptrdiff_t i = 0; i < h_size; i++) { + cv::line(*hist_img, cv::Point(i, rows - 0), + cv::Point(i, rows - hist->at<float>(i)), + cv::Scalar(UINT8_MAX, 0, 0), 1, 8, 0); + } + + /* Show histogram */ + img_iface_show_hist_c1(); +} + +static void img_cv_histogram_c3 (class cv::Mat *imgptr, const void *data) +{ + const struct Img_Iface_Data_Histogram *data_cast; + const int h_size = 256; + const float h_range_arr[] = {0.0, 256.0}; + const float *h_range = {h_range_arr}; + class cv::Mat cmp_img[3]; + class cv::Mat *hist_c0; + class cv::Mat *hist_c1; + class cv::Mat *hist_c2; + class cv::Mat *hist_img; + ptrdiff_t rows; + + data_cast = (const struct Img_Iface_Data_Histogram *)data; + hist_c0 = data_cast->hist_c0; + hist_c1 = data_cast->hist_c1; + hist_c2 = data_cast->hist_c2; + hist_img = data_cast->hist_img; + rows = hist_img->rows; + + /* Write components into cmp_img[] */ + cv::split(*imgptr, cmp_img); + + /* Write components into cmp_img[] */ + cv::calcHist(&cmp_img[0], 1, 0, cv::Mat(), *hist_c0, 1, &h_size, + &h_range, true, false); + cv::calcHist(&cmp_img[1], 1, 0, cv::Mat(), *hist_c1, 1, &h_size, + &h_range, true, false); + cv::calcHist(&cmp_img[2], 1, 0, cv::Mat(), *hist_c2, 1, &h_size, + &h_range, true, false); + + /* Init */ + hist_img->setTo(cv::Scalar(0)); + + /* Normalize the result to [0, hist_img->rows - 1] */ + cv::normalize(*hist_c0, *hist_c0, 0, rows - 1, cv::NORM_MINMAX, -1, + cv::Mat()); + cv::normalize(*hist_c1, *hist_c1, 0, rows - 1, cv::NORM_MINMAX, -1, + cv::Mat()); + cv::normalize(*hist_c2, *hist_c2, 0, rows - 1, cv::NORM_MINMAX, -1, + cv::Mat()); + + /* Draw hist into hist_img */ + for (ptrdiff_t i = 0; i < h_size; i++) + cv::line(*hist_img, cv::Point(3 * i, rows - 0), + cv::Point(3 * i, rows - hist_c0->at<float>(i)), + cv::Scalar(UINT8_MAX, 0, 0), 1, 8, 0); + for (ptrdiff_t i = 0; i < h_size; i++) + cv::line(*hist_img, cv::Point(3 * i + 1, rows - 0), + cv::Point(3*i+1, rows - hist_c1->at<float>(i)), + cv::Scalar(0, UINT8_MAX, 0), 1, 8, 0); + for (ptrdiff_t i = 0; i < h_size; i++) + cv::line(*hist_img, cv::Point(3 * i + 2, rows - 0), + cv::Point(3*i+2, rows - hist_c2->at<float>(i)), + cv::Scalar(0, 0, UINT8_MAX), 1, 8, 0); + + /* Show histogram */ + img_iface_show_hist_c3(); + + cmp_img[0].release(); + cmp_img[1].release(); + cmp_img[2].release(); +} + +/* ----- Structural analysis and shape descriptors */ +static void img_cv_contours (class cv::Mat *imgptr, const void *data) +{ + const struct Img_Iface_Data_Contours *data_cast; + class std::vector<class std::vector<class cv::Point_<int>>> *contours; + class cv::Mat *hierarchy; + + data_cast = (const struct Img_Iface_Data_Contours *)data; + contours = data_cast->contours; + hierarchy = data_cast->hierarchy; + + cv::findContours(*imgptr, *contours, *hierarchy, CV_RETR_EXTERNAL, + CV_CHAIN_APPROX_SIMPLE); + + /* Set image to black */ + imgptr->setTo(cv::Scalar(0)); + /* Draw contours in color */ + cv::drawContours(*imgptr, *contours, -1, cv::Scalar(UINT8_MAX), 1, 8, + *hierarchy, 1, cvPoint(0, 0)); +} + +static void img_cv_contours_size (const void *data) +{ + const struct Img_Iface_Data_Contours_Size *data_cast; + const class std::vector<class std::vector<class cv::Point_<int>>> *contours; + ptrdiff_t size; + + data_cast = (const struct Img_Iface_Data_Contours_Size *)data; + contours = data_cast->contours; + size = contours->size(); + + if (data_cast->area) { + for (ptrdiff_t i = 0; i < size; i++) + data_cast->area[i] = cv::contourArea((*contours)[i], + false); + } + if (data_cast->perimeter) { + for (ptrdiff_t i = 0; i < size; i++) + data_cast->perimeter[i] = cv::arcLength((*contours)[i], + true); + } +} + +static void img_cv_bounding_rect (class cv::Mat *imgptr, const void *data) +{ + const struct Img_Iface_Data_Bounding_Rect *data_cast; + const class std::vector <class cv::Point_ <int>> *contour; + class cv::Point_ <float> vertices[4]; + class cv::Rect_ <int> *rect; + bool show; + ptrdiff_t x; + ptrdiff_t y; + ptrdiff_t width; + ptrdiff_t height; + + data_cast = (const struct Img_Iface_Data_Bounding_Rect *)data; + contour = data_cast->contour; + rect = data_cast->rect; + show = data_cast->show; + + *rect = cv::boundingRect(*contour); + x = rect->x; + y = rect->y; + width = rect->width; + height = rect->height; + + if (!show) + return; + /* Draw rectangle */ + vertices[0].x = x; + vertices[0].y = y; + vertices[1].x = x + width; + vertices[1].y = y; + vertices[2].x = x + width; + vertices[2].y = y + height; + vertices[3].x = x; + vertices[3].y = y + height; + cv::line(*imgptr, cv::Point(vertices[0].x, vertices[0].y), + cv::Point(vertices[1].x, vertices[1].y), + CV_RGB(0, 0, UINT8_MAX), 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, UINT8_MAX), 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, UINT8_MAX), 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, UINT8_MAX), 1, 8, 0); +} + +static void img_cv_fit_ellipse (class cv::Mat *imgptr, const void *data) +{ + const struct Img_Iface_Data_MinARect *data_cast; + const class std::vector <class cv::Point_ <int>> *contour; + class cv::Point_ <float> vertices[4]; + class cv::RotatedRect *rect; + bool show; + + data_cast = (const struct Img_Iface_Data_MinARect *)data; + contour = data_cast->contour; + rect = data_cast->rect; + show = data_cast->show; + + *rect = cv::fitEllipse(*contour); + + if (!show) + return; + /* Draw rectangle */ + 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, UINT8_MAX), 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, UINT8_MAX), 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, UINT8_MAX), 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, UINT8_MAX), 1, 8, 0); +} + +static void img_cv_min_area_rect (class cv::Mat *imgptr, const void *data) +{ + const struct Img_Iface_Data_MinARect *data_cast; + const class std::vector <class cv::Point_ <int>> *contour; + class cv::Point_ <float> vertices[4]; + class cv::RotatedRect *rect; + bool show; + + data_cast = (const struct Img_Iface_Data_MinARect *)data; + contour = data_cast->contour; + rect = data_cast->rect; + show = data_cast->show; + + *rect = cv::minAreaRect(*contour); + + if (!show) + return; + /* Draw rectangle */ + 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, UINT8_MAX), 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, UINT8_MAX), 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, UINT8_MAX), 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, UINT8_MAX), 1, 8, 0); +} + +/* ----- Feature detection */ +static void img_cv_hough_circles (class cv::Mat *imgptr, const void *data) +{ + const struct Img_Iface_Data_Hough_Circles *data_cast; + class std::vector <class cv::Vec <float, 3>> *circles; + class cv::Point_ <int> center; + int radius; + double dist_min; + double param_1; + double param_2; + int radius_min; + int radius_max; + ptrdiff_t size; + + data_cast = (const struct Img_Iface_Data_Hough_Circles *)data; + circles = data_cast->circles; + dist_min = data_cast->dist_min; + param_1 = data_cast->param_1; + param_2 = data_cast->param_2; + radius_min = data_cast->radius_min; + radius_max = data_cast->radius_max; + + /* Get circles */ + cv::HoughCircles(*imgptr, *circles, CV_HOUGH_GRADIENT, 1, dist_min, + param_1, param_2, radius_min, radius_max); + + /* Set image to black */ + imgptr->setTo(cv::Scalar(0)); + + /* Draw circles */ + size = circles->size(); + for (ptrdiff_t i = 0; i < size; i++) { + center.x = cvRound((*circles)[i][0]); + center.y = cvRound((*circles)[i][1]); + radius = cvRound((*circles)[i][2]); + + /* Draw the circle center */ +/* cv::circle(*imgptr, center, 3, cv::Scalar(0, 255, 0), -1, 8, 0);*/ + + /* Draw the circle outline */ + cv::circle(*imgptr, center, radius, cv::Scalar(250), 1, 8, 0); + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/image/iface.cpp b/src/image/iface.cpp new file mode 100644 index 0000000..8759bf4 --- /dev/null +++ b/src/image/iface.cpp @@ -0,0 +1,1489 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "vision-artificial/image/iface.hpp" + +#include <cerrno> +#include <cmath> +#include <cstddef> +#include <cstdio> + +#include <vector> + +#include <opencv2/opencv.hpp> + +#include "vision-artificial/image/alx.hpp" +#include "vision-artificial/image/calib3d.hpp" +#include "vision-artificial/image/cv.hpp" +#include "vision-artificial/image/ocr.hpp" +#include "vision-artificial/image/orb.hpp" +#include "vision-artificial/image/zbar.hpp" +#include "vision-artificial/save/save.hpp" +#include "vision-artificial/user/iface.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +#define IMG_MEM_SIZE (20) + +#define WIN_NAME_IMG "Image" +#define WIN_NAME_HIST "Hist" +#define WIN_TIMEOUT (500) + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ + char img_ocr_text [OCR_TEXT_MAX]; + struct Img_Iface_ZB_Codes zb_codes; +/* Static --------------------------------------------------------------------*/ +static class cv::Mat image_copy_old; +static class cv::Mat image_copy_tmp; +static class cv::Mat image_mem[IMG_MEM_SIZE]; +static class cv::Mat image_ref; +static class cv::Mat histogram_c0; +static class cv::Mat histogram_c1; +static class cv::Mat histogram_c2; +static class cv::Mat hist_img_c1; +static class cv::Mat hist_img_c3; +static class std::vector <class std::vector <cv::Point_ <int>>> contours; +static double area[CONTOURS_MAX]; +static double perimeter[CONTOURS_MAX]; +static class cv::Mat hierarchy; +static class cv::Rect_ <int> rectangle; +static class cv::RotatedRect rectangle_rot; +static class std::vector <class cv::Vec <float, 3>> circles; +static class cv::Mat intrinsic_mat; +static class cv::Mat dist_coefs; +static class std::vector <class cv::Mat> rvecs; +static class std::vector <class cv::Mat> tvecs; + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ + /* alx */ +static void img_iface_local_max (void); +static void img_iface_skeleton (void); +static void img_iface_lines_horizontal (void); +static void img_iface_lines_vertical (void); +static void img_iface_mean_horizontal (void); +static void img_iface_mean_vertical (void); +static void img_iface_median_horizontal (void); +static void img_iface_median_vertical (void); + /* cv */ + /* Core: The core functionality */ + /* Pixel */ +static void img_iface_pixel_get (const void *data); +static void img_iface_pixel_set (const void *data); + /* ROI */ +static void img_iface_set_ROI (const void *data); +static void img_iface_set_ROI_2rect (const void *data); + /* Operations on Arrays */ +static void img_iface_and_2ref (void); +static void img_iface_not (void); +static void img_iface_or_2ref (void); +static void img_iface_component (const void *data); + /* Imgproc: Image processing */ + /* Image filtering */ +static void img_iface_dilate (const void *data); +static void img_iface_erode (const void *data); +static void img_iface_dilate_erode (const void *data); +static void img_iface_erode_dilate (const void *data); +static void img_iface_smooth (const void *data); +static void img_iface_sobel (const void *data); +static void img_iface_border (const void *data); + /* Geometric image transformations */ +static void img_iface_mirror (const void *data); +static void img_iface_rotate_orto (const void *data); +static void img_iface_rotate (const void *data); +static void img_iface_rotate_2rect (const void *data); + /* Miscellaneous image transformations */ +static void img_iface_adaptive_thr (const void *data); +static void img_iface_cvt_color (const void *data); +static void img_iface_distance_transform (void); +static void img_iface_threshold (const void *data); + /* Histograms */ +static void img_iface_histogram (const void *data); +static void img_iface_histogram_c3 (const void *data); + /* Structural analysis and shape descriptors */ +static void img_iface_contours (const void *data); +static void img_iface_contours_size (const void *data); +static void img_iface_bounding_rect (const void *data); +static void img_iface_fit_ellipse (const void *data); +static void img_iface_min_area_rect (const void *data); + /* Feature detection */ +static void img_iface_hough_circles (const void *data); + /* orb */ +static void img_iface_align (void); + /* calib3d */ +static void img_iface_calibrate (const void *data); +static void img_iface_undistort (const void *data); + /* zbar */ +static void img_iface_decode (const void *data); + /* ocr */ +static void img_iface_read (const void *data); + /* iface */ +static void img_iface_apply (void); +static void img_iface_discard (void); +static void img_iface_save_mem (const void *data); +static void img_iface_load_mem (const void *data); +static void img_iface_save_ref (void); + /* save/save */ +static void img_iface_save_file (void); +static void img_iface_save_update (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void img_iface_init (void) +{ + + 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); + hist_img_c3.release(); + hist_img_c3 = cv::Mat::zeros(cv::Size(256 * 3, 100), CV_8UC3); +} + +void img_iface_deinit (void) +{ + + for (ptrdiff_t i = 0; i < IMG_MEM_SIZE; i++) + image_mem[i].release(); + image_ref.release(); + + cv::destroyAllWindows(); +} + +void img_iface_load (const char *fpath, const char *fname) +{ + const char *path; + char file_name[FILENAME_MAX]; + + if (!fpath) + path = saved_path; + else + path = fpath; + + if (!fname) + user_iface_fname(fpath, file_name); + else + snprintf(file_name, FILENAME_MAX, "%s", fname); + + errno = 0; + load_image_file(path, file_name); + if (errno) + return; + + image.copyTo(image_copy_old); + image.copyTo(image_copy_tmp); +} + +void img_iface_cleanup (void) +{ + + image_copy_old.release(); + image_copy_tmp.release(); + histogram_c0.release(); + histogram_c1.release(); + histogram_c2.release(); + hist_img_c1.release(); + hist_img_c3.release(); +} + +void img_iface_act (int action, const void *data) +{ + + switch (action) { + /* img_alx */ + case IMG_IFACE_ACT_LOCAL_MAX: + img_iface_local_max(); + break; + case IMG_IFACE_ACT_SKELETON: + img_iface_skeleton(); + break; + case IMG_IFACE_ACT_LINES_HORIZONTAL: + img_iface_lines_horizontal(); + break; + case IMG_IFACE_ACT_LINES_VERTICAL: + img_iface_lines_vertical(); + break; + case IMG_IFACE_ACT_MEAN_HORIZONTAL: + img_iface_mean_horizontal(); + break; + case IMG_IFACE_ACT_MEAN_VERTICAL: + img_iface_mean_vertical(); + break; + case IMG_IFACE_ACT_MEDIAN_HORIZONTAL: + img_iface_median_horizontal(); + break; + case IMG_IFACE_ACT_MEDIAN_VERTICAL: + img_iface_median_vertical(); + break; + /* img_cv */ + /* Core: The core functionality */ + /* Pixel */ + case IMG_IFACE_ACT_PIXEL_GET: + img_iface_pixel_get(data); + break; + case IMG_IFACE_ACT_PIXEL_SET: + img_iface_pixel_set(data); + break; + /* ROI */ + case IMG_IFACE_ACT_SET_ROI: + img_iface_set_ROI(data); + break; + case IMG_IFACE_ACT_SET_ROI_2RECT: + img_iface_set_ROI_2rect(data); + break; + /* Operations on Arrays */ + case IMG_IFACE_ACT_AND_2REF: + img_iface_and_2ref(); + break; + case IMG_IFACE_ACT_NOT: + img_iface_not(); + break; + case IMG_IFACE_ACT_OR_2REF: + img_iface_or_2ref(); + break; + case IMG_IFACE_ACT_COMPONENT: + img_iface_component(data); + break; + /* Imgproc: Image processing */ + /* Image filtering */ + case IMG_IFACE_ACT_DILATE: + img_iface_dilate(data); + break; + case IMG_IFACE_ACT_ERODE: + img_iface_erode(data); + break; + case IMG_IFACE_ACT_DILATE_ERODE: + img_iface_dilate_erode(data); + break; + case IMG_IFACE_ACT_ERODE_DILATE: + img_iface_erode_dilate(data); + break; + case IMG_IFACE_ACT_SMOOTH: + img_iface_smooth(data); + break; + case IMG_IFACE_ACT_SOBEL: + img_iface_sobel(data); + break; + case IMG_IFACE_ACT_BORDER: + img_iface_border(data); + break; + /* Geometric image transformations */ + case IMG_IFACE_ACT_MIRROR: + img_iface_mirror(data); + break; + case IMG_IFACE_ACT_ROTATE_ORTO: + img_iface_rotate_orto(data); + break; + case IMG_IFACE_ACT_ROTATE: + img_iface_rotate(data); + break; + case IMG_IFACE_ACT_ROTATE_2RECT: + img_iface_rotate_2rect(data); + break; + /* Miscellaneous image transformations */ + case IMG_IFACE_ACT_ADAPTIVE_THRESHOLD: + img_iface_adaptive_thr(data); + break; + case IMG_IFACE_ACT_CVT_COLOR: + img_iface_cvt_color(data); + break; + case IMG_IFACE_ACT_DISTANCE_TRANSFORM: + img_iface_distance_transform(); + break; + case IMG_IFACE_ACT_THRESHOLD: + img_iface_threshold(data); + break; + /* Histograms */ + case IMG_IFACE_ACT_HISTOGRAM: + img_iface_histogram(data); + break; + case IMG_IFACE_ACT_HISTOGRAM_C3: + img_iface_histogram_c3(data); + break; + /* Structural analysis and shape descriptors */ + case IMG_IFACE_ACT_CONTOURS: + img_iface_contours(data); + break; + case IMG_IFACE_ACT_CONTOURS_SIZE: + img_iface_contours_size(data); + break; + case IMG_IFACE_ACT_BOUNDING_RECT: + img_iface_bounding_rect(data); + break; + case IMG_IFACE_ACT_FIT_ELLIPSE: + img_iface_fit_ellipse(data); + break; + case IMG_IFACE_ACT_MIN_AREA_RECT: + img_iface_min_area_rect(data); + break; + /* Feature detection */ + case IMG_IFACE_ACT_HOUGH_CIRCLES: + img_iface_hough_circles(data); + break; + /* img_orb */ + case IMG_IFACE_ACT_ALIGN: + img_iface_align(); + break; + /* img_calib3d */ + case IMG_IFACE_ACT_CALIBRATE: + img_iface_calibrate(data); + break; + case IMG_IFACE_ACT_UNDISTORT: + img_iface_undistort(data); + break; + /* img_zbar */ + case IMG_IFACE_ACT_DECODE: + img_iface_decode(data); + break; + /* img_ocr */ + case IMG_IFACE_ACT_READ: + img_iface_read(data); + break; + /* img_iface */ + case IMG_IFACE_ACT_APPLY: + img_iface_apply(); + break; + case IMG_IFACE_ACT_DISCARD: + img_iface_discard(); + break; + case IMG_IFACE_ACT_SAVE_MEM: + img_iface_save_mem(data); + break; + case IMG_IFACE_ACT_LOAD_MEM: + img_iface_load_mem(data); + break; + case IMG_IFACE_ACT_SAVE_REF: + img_iface_save_ref(); + break; + /* save */ + case IMG_IFACE_ACT_SAVE_FILE: + img_iface_save_file(); + break; + case IMG_IFACE_ACT_SAVE_UPDT: + img_iface_save_update(); + break; + default: + /* Invalid action */ + break; + } +} + +void img_iface_show_img (void) +{ + + cv::imshow(WIN_NAME_IMG, image_copy_tmp); + cv::waitKey(WIN_TIMEOUT); +} + +void img_iface_show_hist_c1 (void) +{ + + cv::imshow(WIN_NAME_HIST, hist_img_c1); + cv::waitKey(WIN_TIMEOUT); +} + +void img_iface_show_hist_c3 (void) +{ + + cv::imshow(WIN_NAME_HIST, hist_img_c3); + cv::waitKey(WIN_TIMEOUT); +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +/* alx -----------------------------------------------------------------------*/ +static void img_iface_local_max (void) +{ + + if (image_copy_tmp.channels() != 1) + goto err; + + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_LOCAL_MAX, NULL); + + user_iface_log_write(1, "Local maxima"); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +static void img_iface_skeleton (void) +{ + + if (image_copy_tmp.channels() != 1) + goto err; + + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_SKELETON, NULL); + + user_iface_log_write(1, "Skeleton"); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +static void img_iface_lines_horizontal (void) +{ + + if (image_copy_tmp.channels() != 1) + goto err; + + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_LINES_HORIZONTAL, NULL); + + user_iface_log_write(1, "Horizontal lines"); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +static void img_iface_lines_vertical (void) +{ + + if (image_copy_tmp.channels() != 1) + goto err; + + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_LINES_VERTICAL, NULL); + + user_iface_log_write(1, "Vertical lines"); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +static void img_iface_mean_horizontal (void) +{ + + if (image_copy_tmp.channels() != 1) + goto err; + + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEAN_HORIZONTAL, NULL); + + user_iface_log_write(1, "Horizontal mean"); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +static void img_iface_mean_vertical (void) +{ + if (image_copy_tmp.channels() != 1) + goto err; + + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEAN_VERTICAL, NULL); + + user_iface_log_write(1, "Vertical mean"); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +static void img_iface_median_horizontal (void) +{ + + if (image_copy_tmp.channels() != 1) + goto err; + + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEDIAN_HORIZONTAL, NULL); + + user_iface_log_write(1, "Horizontal median"); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +static void img_iface_median_vertical (void) +{ + + if (image_copy_tmp.channels() != 1) + goto err; + + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEDIAN_VERTICAL, NULL); + + user_iface_log_write(1, "Vertical median"); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +/* cv ------------------------------------------------------------------------*/ +/* ----- Core: The core functionality */ +/* ----- ------- Pixel */ +static void img_iface_pixel_get (const void *data) +{ + const struct Img_Iface_Data_Pixel_Get *data_cast; + struct Img_Iface_Data_Pixel_Get data_tmp; + unsigned char val; + ptrdiff_t tmp; + char txt[LOG_LINE_LEN]; + + if (image_copy_tmp.channels() != 1) + goto err; + + if (!data) { + data_tmp.val = &val; + tmp = image_copy_tmp.cols; + data_tmp.x = user_iface_getint(0, 0, tmp, "x:", NULL); + tmp = image_copy_tmp.rows; + data_tmp.y = user_iface_getint(0, 0, tmp, "y:", NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_PIXEL_GET, data); + + /* Write into user_iface_log_write */ + data_cast = (const struct Img_Iface_Data_Pixel_Get *)data; + snprintf(txt, LOG_LINE_LEN, "Pixel get: (%ti, %ti): %i", + data_cast->x, data_cast->y, *data_cast->val); + user_iface_log_write(1, txt); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +static void img_iface_pixel_set (const void *data) +{ + const struct Img_Iface_Data_Pixel_Set *data_cast; + struct Img_Iface_Data_Pixel_Set data_tmp; + ptrdiff_t tmp; + char txt[LOG_LINE_LEN]; + + if (image_copy_tmp.channels() != 1) + goto err; + + if (!data) { + tmp = image_copy_tmp.cols; + data_tmp.x = user_iface_getint(0, 0, tmp, "x:", NULL); + tmp = image_copy_tmp.rows; + data_tmp.y = user_iface_getint(0, 0, tmp, "y:", NULL); + data_tmp.val = user_iface_getint(0, 0, UINT8_MAX, "val:", NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_PIXEL_SET, data); + + data_cast = (const struct Img_Iface_Data_Pixel_Set *)data; + snprintf(txt, LOG_LINE_LEN, "Pixel get: (%ti, %ti): %i", + data_cast->x, data_cast->y, data_cast->val); + user_iface_log_write(1, txt); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +/* ----- ------- ROI */ +static void img_iface_set_ROI (const void *data) +{ + const struct Img_Iface_Data_SetROI *data_cast; + struct Img_Iface_Data_SetROI data_tmp; + ptrdiff_t tmp; + char txt[LOG_LINE_LEN]; + + if (!data) { + tmp = image_copy_tmp.cols; + data_tmp.rect.x = user_iface_getint(0, 0, tmp, "Origin: x:", + NULL); + tmp = image_copy_tmp.rows; + data_tmp.rect.y = user_iface_getint(0, 0, tmp, "Origin: y:", + NULL); + tmp = image_copy_tmp.cols - data_tmp.rect.x; + data_tmp.rect.width = user_iface_getint(1, tmp, tmp, "Width:", + NULL); + tmp = image_copy_tmp.rows - data_tmp.rect.y; + data_tmp.rect.height = user_iface_getint(1, tmp, tmp,"Height:", + NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_SET_ROI, data); + + data_cast = (const struct Img_Iface_Data_SetROI *)data; + snprintf(txt, LOG_LINE_LEN, "ROI: (%i,%i) w=%i,h=%i", + data_cast->rect.x, data_cast->rect.y, + data_cast->rect.width, data_cast->rect.height); + user_iface_log_write(1, txt); +} + +static void img_iface_set_ROI_2rect (const void *data) +{ + const struct Img_Iface_Data_SetROI *data_cast; + struct Img_Iface_Data_SetROI data_tmp; + char txt[LOG_LINE_LEN]; + + if (!data) { + data_tmp.rect.x = rectangle.x; + data_tmp.rect.y = rectangle.y; + data_tmp.rect.width = rectangle.width; + data_tmp.rect.height = rectangle.height; + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_SET_ROI, data); + + data_cast = (const struct Img_Iface_Data_SetROI *)data; + snprintf(txt, LOG_LINE_LEN, "ROI: (%i,%i) w=%i,h=%i", + data_cast->rect.x, data_cast->rect.y, + data_cast->rect.width, data_cast->rect.height); + user_iface_log_write(1, txt); +} + +/* ----- ------- Operations on arrays */ +static void img_iface_and_2ref (void) +{ + + if (image_copy_tmp.channels() != image_ref.channels()) + goto err; + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_AND_2REF, + (const void *)&image_ref); + + user_iface_log_write(1, "Bitwise AND"); + return; +err: + user_iface_log_write(1, "! Invalid input (Channels do not match ref)"); +} + +static void img_iface_not (void) +{ + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_NOT, NULL); + + user_iface_log_write(1, "Invert color"); +} + +static void img_iface_or_2ref (void) +{ + + if (image_copy_tmp.channels() != image_ref.channels()) + goto err; + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_OR_2REF, + (const void *)&image_ref); + + user_iface_log_write(1, "Bitwise OR"); + return; +err: + user_iface_log_write(1, "! Invalid input (Channels do not match ref)"); +} + +static void img_iface_component (const void *data) +{ + const struct Img_Iface_Data_Component *data_cast; + struct Img_Iface_Data_Component data_tmp; + ptrdiff_t tmp; + char txt[LOG_LINE_LEN]; + + if (image_copy_tmp.channels() < 2) + goto err; + + if (!data) { + tmp = image_copy_tmp.channels() - 1; + data_tmp.cmp = user_iface_getint(0, 0, tmp, "Component:", NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_COMPONENT, data); + + data_cast = (const struct Img_Iface_Data_Component *)data; + snprintf(txt, LOG_LINE_LEN, "Component %ti", data_cast->cmp); + user_iface_log_write(1, txt); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be >= 2 channels)"); +} + +/* ----- Imgproc: Image processing */ +/* ----- ------- Image filtering */ +static void img_iface_dilate (const void *data) +{ + const struct Img_Iface_Data_Dilate_Erode *data_cast; + struct Img_Iface_Data_Dilate_Erode data_tmp; + char txt[LOG_LINE_LEN]; + + if (!data) { + data_tmp.i = user_iface_getint(1, 1, INFINITY, "Iterations:", + NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data); + + data_cast = (const struct Img_Iface_Data_Dilate_Erode *)data; + snprintf(txt, LOG_LINE_LEN, "Dilate i = %i", data_cast->i); + user_iface_log_write(1, txt); +} + +static void img_iface_erode (const void *data) +{ + const struct Img_Iface_Data_Dilate_Erode *data_cast; + struct Img_Iface_Data_Dilate_Erode data_tmp; + char txt[LOG_LINE_LEN]; + + if (!data) { + data_tmp.i = user_iface_getint(1, 1, INFINITY, "Iterations:", + NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data); + + data_cast = (const struct Img_Iface_Data_Dilate_Erode *)data; + snprintf(txt, LOG_LINE_LEN, "Erode i = %i", data_cast->i); + user_iface_log_write(1, txt); +} + +static void img_iface_dilate_erode (const void *data) +{ + const struct Img_Iface_Data_Dilate_Erode *data_cast; + struct Img_Iface_Data_Dilate_Erode data_tmp; + char txt[LOG_LINE_LEN]; + + if (!data) { + data_tmp.i = user_iface_getint(1, 1, INFINITY, "Iterations:", + NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data); + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data); + + data_cast = (const struct Img_Iface_Data_Dilate_Erode *)data; + snprintf(txt, LOG_LINE_LEN, "Dilate-erode i = %i", data_cast->i); + user_iface_log_write(1, txt); +} + +static void img_iface_erode_dilate (const void *data) +{ + const struct Img_Iface_Data_Dilate_Erode *data_cast; + struct Img_Iface_Data_Dilate_Erode data_tmp; + char txt[LOG_LINE_LEN]; + + if (!data) { + data_tmp.i = user_iface_getint(1, 1, INFINITY, "Iterations:", + NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data); + img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data); + + data_cast = (const struct Img_Iface_Data_Dilate_Erode *)data; + snprintf(txt, LOG_LINE_LEN, "Erode-dilate i = %i", data_cast->i); + user_iface_log_write(1, txt); +} + +static void img_iface_smooth (const void *data) +{ + const struct Img_Iface_Data_Smooth *data_cast; + struct Img_Iface_Data_Smooth data_tmp; + char txt[LOG_LINE_LEN]; + + if (!data) { + data_tmp.method = user_iface_getint(1, 3, 3, + "Method: MEAN=1, GAUSS=2, MEDIAN=3", NULL); + data_tmp.ksize = user_iface_getint(3, 3, INFINITY, + "Kernel size: 3, 5, 7, ...", NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_SMOOTH, data); + + data_cast = (const struct Img_Iface_Data_Smooth *)data; + snprintf(txt, LOG_LINE_LEN, "Smooth mth = %i [%i x %i]", + data_cast->method, data_cast->ksize, data_cast->ksize); + user_iface_log_write(1, txt); +} + +static void img_iface_sobel (const void *data) +{ + const struct Img_Iface_Data_Sobel *data_cast; + struct Img_Iface_Data_Sobel data_tmp; + char txt[LOG_LINE_LEN]; + + if (image_copy_tmp.channels() != 1) + goto err; + + if (!data) { + data_tmp.dx = user_iface_getint(0, 1, 10, + "Order of the derivative x", NULL); + data_tmp.dy = user_iface_getint(0, 1, 10, + "Order of the derivative y", NULL); + data_tmp.ksize = user_iface_getint(-1, 3, 7, + "Size of the extended Sobel kernel (Scharr: -1)", + NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_SOBEL, data); + + data_cast = (const struct Img_Iface_Data_Sobel *)data; + snprintf(txt, LOG_LINE_LEN, "Sobel dx = %i; dy = %i [ks = %i]", + data_cast->dx, data_cast->dy, data_cast->ksize); + user_iface_log_write(1, txt); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +static void img_iface_border (const void *data) +{ + const struct Img_Iface_Data_Border *data_cast; + struct Img_Iface_Data_Border data_tmp; + char txt[LOG_LINE_LEN]; + + if (image_copy_tmp.channels() != 1) + goto err; + + if (!data) { + data_tmp.size = user_iface_getint(1, 1, INT16_MAX, "Size",NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_BORDER, data); + + data_cast = (const struct Img_Iface_Data_Border *)data; + snprintf(txt, LOG_LINE_LEN, "Border size = %ti", data_cast->size); + user_iface_log_write(1, txt); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +/* ----- ------- Geometric image transformations */ +static void img_iface_mirror (const void *data) +{ + const struct Img_Iface_Data_Mirror *data_cast; + struct Img_Iface_Data_Mirror data_tmp; + char txt[LOG_LINE_LEN]; + + if (!data) { + data_tmp.axis = user_iface_getint(0, 1, 1, "Axis: 0=x; 1=y", + NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_MIRROR, data); + + data_cast = (const struct Img_Iface_Data_Mirror *)data; + snprintf(txt, LOG_LINE_LEN, "Mirror axis: %i", data_cast->axis); + user_iface_log_write(1, txt); +} + +static void img_iface_rotate_orto (const void *data) +{ + const struct Img_Iface_Data_Rotate_Orto *data_cast; + struct Img_Iface_Data_Rotate_Orto data_tmp; + char txt[LOG_LINE_LEN]; + + if (!data) { + data_tmp.n = user_iface_getint(1, 1, 3, + "Rotate (counterclockwise) n * pi/2 rad; n:", + NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE_ORTO, data); + + data_cast = (const struct Img_Iface_Data_Rotate_Orto *)data; + snprintf(txt, LOG_LINE_LEN, "Rotate %i * pi/2 rad", data_cast->n); + user_iface_log_write(1, txt); +} + +static void img_iface_rotate (const void *data) +{ + const struct Img_Iface_Data_Rotate *data_cast; + struct Img_Iface_Data_Rotate data_tmp; + char txt[LOG_LINE_LEN]; + + if (!data) { + data_tmp.center.x = user_iface_getdbl(0, 0, INFINITY, + "Center: x:", NULL); + data_tmp.center.y = user_iface_getdbl(0, 0, INFINITY, + "Center: y:", NULL); + data_tmp.angle = user_iface_getdbl(-INFINITY, 0, INFINITY, + "Angle: (deg)", NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE, data); + + data_cast = (const struct Img_Iface_Data_Rotate *)data; + snprintf(txt, LOG_LINE_LEN, "Rotate (%.2f,%.2f) %lfº", + data_cast->center.x, data_cast->center.y, + data_cast->angle); + user_iface_log_write(1, txt); +} + +static void img_iface_rotate_2rect (const void *data) +{ + struct Img_Iface_Data_Rotate data_tmp; + + if (!data) { + data_tmp.center.x = rectangle_rot.center.x; + data_tmp.center.y = rectangle_rot.center.y; + data_tmp.angle = rectangle_rot.angle; + /* If angle is < -45º, + * it is taking into acount the incorrect side */ + if (data_tmp.angle < -45.0) + data_tmp.angle += 90.0; + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE, data); + + user_iface_log_write(1, "Rotate to rectangle"); +} + +/* ----- ------- Miscellaneous image transformations */ +static void img_iface_adaptive_thr (const void *data) +{ + const struct Img_Iface_Data_Adaptive_Thr *data_cast; + struct Img_Iface_Data_Adaptive_Thr data_tmp; + char txt[LOG_LINE_LEN]; + + if (image_copy_tmp.channels() != 1) + goto err; + + if (!data) { + data_tmp.method = user_iface_getint(0, 1, 1, + "Method: MEAN=0, GAUSS=1", NULL); + data_tmp.thr_typ = user_iface_getint(0, 0, 1, + "Type: BIN=0, BIN_INV=1", NULL); + data_tmp.ksize = user_iface_getint(3, 3, INFINITY, + "Kernel size: 3, 5, 7, ...", NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ADAPTIVE_THRESHOLD, data); + + data_cast = (const struct Img_Iface_Data_Adaptive_Thr *)data; + snprintf(txt, LOG_LINE_LEN, "Threshold mth=%i, typ=%i, ks=%i", + data_cast->method, data_cast->thr_typ, + data_cast->ksize); + user_iface_log_write(1, txt); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +static void img_iface_cvt_color (const void *data) +{ + const struct Img_Iface_Data_Cvt_Color *data_cast; + struct Img_Iface_Data_Cvt_Color data_tmp; + char txt[LOG_LINE_LEN]; + + if (image_copy_tmp.channels() != 3) + goto err; + + if (!data) { + data_tmp.method =user_iface_getint(0, 0, cv::COLOR_COLORCVT_MAX, + "Method: BGR2GRAY = 6, BGR2HSV = 40", NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_CVT_COLOR, data); + + data_cast = (const struct Img_Iface_Data_Cvt_Color *)data; + snprintf(txt, LOG_LINE_LEN, "Convert color %i", data_cast->method); + user_iface_log_write(1, txt); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 3 channels)"); +} + +static void img_iface_distance_transform (void) +{ + + if (image_copy_tmp.channels() != 1) + goto err; + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_DISTANCE_TRANSFORM, NULL); + + user_iface_log_write(1, "Distance transform"); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +static void img_iface_threshold (const void *data) +{ + const struct Img_Iface_Data_Threshold *data_cast; + struct Img_Iface_Data_Threshold data_tmp; + char txt[LOG_LINE_LEN]; + + if (image_copy_tmp.channels() != 1) + goto err; + + if (!data) { + data_tmp.thr_typ = user_iface_getint(0, 0, 4, + "Type: BIN=0, BIN_INV=1, TRUNC=2, TOZ=3, TOZ_INV=4", + NULL); + data_tmp.thr_val = user_iface_getint(-1, 0, UINT8_MAX, + "Value: 0 to 255 (or -1 for Otsu's algorithm)", + NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_THRESHOLD, data); + + data_cast = (const struct Img_Iface_Data_Threshold *)data; + snprintf(txt, LOG_LINE_LEN, "Threshold typ = %i, val = %i", + data_cast->thr_typ, data_cast->thr_val); + user_iface_log_write(1, txt); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +/* ----- ------- Histograms */ +static void img_iface_histogram (const void *data) +{ + struct Img_Iface_Data_Histogram data_tmp; + + if (image_copy_tmp.channels() != 1) + goto err; + + if (!data) { + data_tmp.hist_c0 = &histogram_c0; + data_tmp.hist_img = &hist_img_c1; + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_HISTOGRAM, data); + + user_iface_log_write(1, "Histogram"); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +static void img_iface_histogram_c3 (const void *data) +{ + struct Img_Iface_Data_Histogram data_tmp; + + if (image_copy_tmp.channels() != 3) + goto err; + + if (!data) { + data_tmp.hist_c0 = &histogram_c0; + data_tmp.hist_c1 = &histogram_c1; + data_tmp.hist_c2 = &histogram_c2; + data_tmp.hist_img = &hist_img_c3; + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_HISTOGRAM_C3, data); + + user_iface_log_write(1, "Histogram (3 channels)"); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 3 channels)"); +} + +/* ----- ------- Structural analysis and shape descriptors */ +static void img_iface_contours (const void *data) +{ + const struct Img_Iface_Data_Contours *data_cast; + struct Img_Iface_Data_Contours data_tmp; + ptrdiff_t tmp; + char txt[LOG_LINE_LEN]; + + if (image_copy_tmp.channels() != 1) + goto err; + + if (!data) { + data_tmp.contours = &contours; + data_tmp.hierarchy = &hierarchy; + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_CONTOURS, data); + + data_cast = (const struct Img_Iface_Data_Contours *)data; + tmp = data_cast->contours->size(); + snprintf(txt, LOG_LINE_LEN, "Contours n = %ti", tmp); + user_iface_log_write(1, txt); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +static void img_iface_contours_size (const void *data) +{ + const struct Img_Iface_Data_Contours_Size *data_cast; + struct Img_Iface_Data_Contours_Size data_tmp; + ptrdiff_t tmp; + char txt[LOG_LINE_LEN]; + + if (!data) { + data_tmp.contours = &contours; + data_tmp.area = area; + data_tmp.perimeter = perimeter; + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_CONTOURS_SIZE, data); + + data_cast = (const struct Img_Iface_Data_Contours_Size *)data; + user_iface_log_write(1, "Contours size:"); + tmp = data_cast->contours->size(); + for (ptrdiff_t i = 0; i < tmp; i++) { + snprintf(txt, LOG_LINE_LEN, "cnt[%ti]: A = %lf; P = %lf;", + i, data_cast->area[i], data_cast->perimeter[i]); + user_iface_log_write(2, txt); + } +} + +static void img_iface_bounding_rect (const void *data) +{ + struct Img_Iface_Data_Bounding_Rect data_tmp; + + if (!data) { + if(!contours.size()) + goto err; + data_tmp.contour = &(contours[0]); + data_tmp.rect = &rectangle; + data_tmp.show = true; + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_BOUNDING_RECT, data); + + user_iface_log_write(1, "Bounding rectangle"); + return; +err: + user_iface_log_write(1, "! Invalid input (No contours saved)"); +} + +static void img_iface_fit_ellipse (const void *data) +{ + struct Img_Iface_Data_MinARect data_tmp; + + if (!data) { + if(!contours.size()) + goto err; + data_tmp.contour = &(contours[0]); + data_tmp.rect = &rectangle_rot; + data_tmp.show = true; + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_FIT_ELLIPSE, data); + + user_iface_log_write(1, "Fit ellipse"); + return; +err: + user_iface_log_write(1, "! Invalid input (No contours saved)"); +} + +static void img_iface_min_area_rect (const void *data) +{ + struct Img_Iface_Data_MinARect data_tmp; + + if (!data) { + if(!contours.size()) + goto err; + data_tmp.contour = &(contours[0]); + data_tmp.rect = &rectangle_rot; + data_tmp.show = true; + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_MIN_AREA_RECT, data); + + user_iface_log_write(1, "Min area rectangle"); + return; +err: + user_iface_log_write(1, "! Invalid input (No contours saved)"); +} + +/* ----- ------- Feature detection */ +static void img_iface_hough_circles (const void *data) +{ + const struct Img_Iface_Data_Hough_Circles *data_cast; + struct Img_Iface_Data_Hough_Circles data_tmp; + ptrdiff_t tmp; + char txt[LOG_LINE_LEN]; + + if (image_copy_tmp.channels() != 1) + goto err; + + if (!data) { + data_tmp.circles = &circles; + data_tmp.dist_min = user_iface_getdbl(0, 5, INFINITY, + "Minimum distance:", NULL); + data_tmp.param_1 = user_iface_getdbl(0, 200, INFINITY, + "param 1:", NULL); + data_tmp.param_2 = user_iface_getdbl(0, 100, INFINITY, + "param 2:", NULL); + data_tmp.radius_min = user_iface_getint(0, 10, INFINITY, + "Minimum radius", NULL); + data_tmp.radius_max = user_iface_getint(0, 0, INFINITY, + "Maximum radius", NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_HOUGH_CIRCLES, data); + + data_cast = (const struct Img_Iface_Data_Hough_Circles *)data; + tmp = data_cast->circles->size(); + snprintf(txt, LOG_LINE_LEN, "Circles n = %ti", tmp); + user_iface_log_write(1, txt); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +/* orb -----------------------------------------------------------------------*/ +static void img_iface_align (void) +{ + + if (image_ref.empty()) + goto err; + + img_orb_act(&image_ref, &image_copy_tmp, IMG_ORB_ACT_ALIGN); + + user_iface_log_write(1, "Align to reference"); + return; +err: + user_iface_log_write(1, "! Reference is NULL"); +} + +/* calib3d -------------------------------------------------------------------*/ +static void img_iface_calibrate (const void *data) +{ + struct Img_Iface_Data_Calibrate data_tmp; + + if (image_copy_tmp.channels() != 1) + goto err; + + if (!data) { + data_tmp.intrinsic_mat = &intrinsic_mat; + data_tmp.dist_coefs = &dist_coefs; + data_tmp.rvecs = &rvecs; + data_tmp.tvecs = &tvecs; + data = (const void *)&data_tmp; + } + + img_calib3d_act(&image_copy_tmp, IMG_CALIB3D_ACT_CALIBRATE, data); + + user_iface_log_write(1, "Calibrate"); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +static void img_iface_undistort (const void *data) +{ + struct Img_Iface_Data_Undistort data_tmp; + + if (!data) { + data_tmp.intrinsic_mat = &intrinsic_mat; + data_tmp.dist_coefs = &dist_coefs; + data = (const void *)&data_tmp; + } + + img_calib3d_act(&image_copy_tmp, IMG_CALIB3D_ACT_UNDISTORT, data); + + user_iface_log_write(1, "Undistort"); +} + +/* zbar ----------------------------------------------------------------------*/ +static void img_iface_decode (const void *data) +{ + struct Img_Iface_Data_Decode data_tmp; + const struct Img_Iface_Data_Decode *data_cast; + char txt[LOG_LINE_LEN]; + + if (image_copy_tmp.channels() != 1) + goto err_chan; + + if (!data) { + data_tmp.code_type = user_iface_getint(0, 0, INT_MAX, + "Type of code: (0 for all)", NULL); + data = (const void *)&data_tmp; + } + + img_zb_act(&image_copy_tmp, IMG_ZB_ACT_DECODE, data); + + data_cast = (const struct Img_Iface_Data_Decode *)data; + snprintf(txt, LOG_LINE_LEN, "Detect codes c = %i",data_cast->code_type); + user_iface_log_write(1, txt); + + if (!zb_codes.n) + goto err_zb; + for (ptrdiff_t i = 0; i < zb_codes.n; i++) { + snprintf(txt, LOG_LINE_LEN, "%s -- '%s'", + zb_codes.arr[i].sym_name, zb_codes.arr[i].data); + user_iface_log_write(2, txt); + } + return; +err_zb: + user_iface_log_write(2, "! No code detected"); + return; +err_chan: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +/* ocr -----------------------------------------------------------------------*/ +static void img_iface_read (const void *data) +{ + struct Img_Iface_Data_Read data_tmp; + const struct Img_Iface_Data_Read *data_cast; + char txt[LOG_LINE_LEN]; + + if (image_copy_tmp.channels() != 1) + goto err_chan; + + data_cast = (const struct Img_Iface_Data_Read *)data; + + if (!data) { + data_tmp.lang = user_iface_getint(0, 1, 2, + "Language: ENG = 0, SPA = 1, CAT = 2", NULL); + data_tmp.conf = user_iface_getint(0, 1, 2, + "Config: none = 0, Price = 1", NULL); + } else { + data_tmp.lang = data_cast->lang; + data_tmp.conf = data_cast->conf; + } + /* Adapt image data */ + data_tmp.img.data = image_copy_tmp.data; + data_tmp.img.width = image_copy_tmp.size().width; + data_tmp.img.height = image_copy_tmp.size().height; + data_tmp.img.B_per_pix = image_copy_tmp.channels(); + data_tmp.img.B_per_line = image_copy_tmp.step1(); + data = (const void *)&data_tmp; + + img_ocr_act(IMG_OCR_ACT_READ, data); + + snprintf(txt, LOG_LINE_LEN, "OCR (lang = %i) [c = %i]", + data_cast->lang, data_cast->conf); + user_iface_log_write(1, txt); + if (img_ocr_text[0] == '\0') + goto err_ocr; + return; +err_ocr: + user_iface_log_write(2, "! No text detected"); + return; +err_chan: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +/* iface ---------------------------------------------------------------------*/ +static void img_iface_apply (void) +{ + + image_copy_old.release(); + image_copy_tmp.copyTo(image_copy_old); + + user_iface_log_write(1, "Apply changes"); +} + +static void img_iface_discard (void) +{ + + image_copy_tmp.release(); + image_copy_old.copyTo(image_copy_tmp); + + user_iface_log_write(1, "Discard changes"); +} + +static void img_iface_save_mem (const void *data) +{ + ptrdiff_t m; + char txt[LOG_LINE_LEN]; + + if (!data) + m = user_iface_getint(0, 0, IMG_MEM_SIZE -1,"mem[m]; m:",NULL); + else + m = *(const ptrdiff_t *)data; + + image_mem[m].release(); + image_copy_tmp.copyTo(image_mem[m]); + + snprintf(txt, LOG_LINE_LEN, "Save to mem[%ti]", m); + user_iface_log_write(1, txt); +} + +static void img_iface_load_mem (const void *data) +{ + ptrdiff_t m; + char txt[LOG_LINE_LEN]; + + if (!data) + m = user_iface_getint(0, 0, IMG_MEM_SIZE -1,"mem[m]; m:",NULL); + else + m = *(const ptrdiff_t *)data; + + if (image_mem[m].empty()) + goto err; + + image_copy_tmp.release(); + image_mem[m].copyTo(image_copy_tmp); + + snprintf(txt, LOG_LINE_LEN, "Load from mem[%ti]", m); + user_iface_log_write(1, txt); + return; +err: + user_iface_log_write(1, "! Empty memory"); +} + +static void img_iface_save_ref (void) +{ + + image_ref.release(); + image_copy_tmp.copyTo(image_ref); + + user_iface_log_write(1, "Save to reference"); +} + +/* save/save -----------------------------------------------------------------*/ +static void img_iface_save_file (void) +{ + + user_iface_log_write(1, "Save as..."); + + image.release(); + image_copy_tmp.copyTo(image); + save_image_file(NULL, NULL); +} + +static void img_iface_save_update (void) +{ + + image.release(); + image_copy_tmp.copyTo(image); + + user_iface_log_write(1, "Save: update img"); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/image/ocr.c b/src/image/ocr.c new file mode 100644 index 0000000..4f6d3de --- /dev/null +++ b/src/image/ocr.c @@ -0,0 +1,145 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "vision-artificial/image/ocr.h" + +#include <limits.h> +#include <stddef.h> +#include <stdio.h> + +#include <tesseract/capi.h> + +#include "vision-artificial/about/about.h" +#include "vision-artificial/image/iface.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ +static void img_ocr_read (const void *data); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void img_ocr_act (int action, const void *data) +{ + + switch (action) { + case IMG_OCR_ACT_READ: + img_ocr_read(data); + break; + } +} + + +/****************************************************************************** + ******* static functions (definitions) *************************************** + ******************************************************************************/ +static void img_ocr_read (const void *data) +{ + const struct Img_Iface_Data_Read *data_cast; + struct TessBaseAPI *handle_ocr; + int lang; + char lang_str[FILENAME_MAX]; + int conf; + char conf_str[FILENAME_MAX]; + char *txt; + + /* Data */ + data_cast = (const struct Img_Iface_Data_Read *)data; + + /* Language */ + lang = data_cast->lang; + switch (lang) { + case IMG_IFACE_OCR_LANG_ENG: + sprintf(lang_str, "eng"); + break; + case IMG_IFACE_OCR_LANG_SPA: + sprintf(lang_str, "spa"); + break; + case IMG_IFACE_OCR_LANG_CAT: + sprintf(lang_str, "cat"); + break; + case IMG_IFACE_OCR_LANG_DIGITS: + sprintf(lang_str, "digits"); + break; + case IMG_IFACE_OCR_LANG_DIGITS_COMMA: + sprintf(lang_str, "digits_comma"); + break; + } + + /* Config file */ + conf = data_cast->conf; + switch (conf) { + case IMG_IFACE_OCR_CONF_PRICE: + if (snprintf(conf_str, FILENAME_MAX, "%s/%s", + share_path, + "price") >= FILENAME_MAX) { + printf("Path is too large and has been truncated\n"); + printf("Price configuration was not possible!\n"); + conf = IMG_IFACE_OCR_CONF_NONE; + } + break; + } + + /* init OCR */ + handle_ocr = TessBaseAPICreate(); +#if defined(OEM_LSTM_ONLY) + TessBaseAPIInit2(handle_ocr, NULL, lang_str, OEM_LSTM_ONLY); +#else + TessBaseAPIInit2(handle_ocr, NULL, lang_str, OEM_DEFAULT); +#endif +/* TessBaseAPIInit2(handle_ocr, NULL, lang_str, OEM_TESSERACT_LSTM_COMBINED);*/ + + /* Configure OCR (whitelist chars) */ + if (conf) + TessBaseAPIReadConfigFile(handle_ocr, conf_str); + + /* scan image for text */ + TessBaseAPISetImage(handle_ocr, data_cast->img.data, + data_cast->img.width, data_cast->img.height, + data_cast->img.B_per_pix, + data_cast->img.B_per_line); + TessBaseAPIRecognize(handle_ocr, NULL); + txt = TessBaseAPIGetUTF8Text(handle_ocr); + + /* Copy text to global variable */ + snprintf(img_ocr_text, OCR_TEXT_MAX, "%s", txt); + + /* cleanup */ + TessDeleteText(txt); + TessBaseAPIEnd(handle_ocr); + TessBaseAPIDelete(handle_ocr); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/image/orb.cpp b/src/image/orb.cpp new file mode 100644 index 0000000..708eb3c --- /dev/null +++ b/src/image/orb.cpp @@ -0,0 +1,136 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "vision-artificial/image/orb.hpp" + +#include <cstddef> +#include <cstdio> + +#include <vector> + +#include <opencv2/opencv.hpp> +#include <opencv2/features2d/features2d.hpp> + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +#define MAX_FEATURES (50000) +#define GOOD_MATCH_P (0.25) + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ +static void img_orb_align (const class cv::Mat *img_0, + class cv::Mat *img_1); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void img_orb_act (const class cv::Mat *img_ref, + class cv::Mat *imgptr, int action) +{ + switch (action) { + case IMG_ORB_ACT_ALIGN: + img_orb_align(img_ref, imgptr); + break; + } +} + + +/****************************************************************************** + ******* static functions (definitions) *************************************** + ******************************************************************************/ +static void img_orb_align (const class cv::Mat *img_0, + class cv::Mat *img_1) +{ + class std::vector <class cv::KeyPoint> keypoints_0; + class std::vector <class cv::KeyPoint> keypoints_1; + class cv::Mat descriptors_0; + class cv::Mat descriptors_1; +#if (CV_VERSION_EPOCH == 2) + class cv::ORB orb; +#elif (CV_VERSION_EPOCH == 3) + class cv::Ptr <class cv::Feature2D> orb; +#endif + class std::vector <struct cv::DMatch> matches; + class cv::Ptr <class cv::DescriptorMatcher> matcher; + ptrdiff_t good_matches; + class cv::Mat img_matches; + class std::vector <class cv::Point_ <float>> points_0; + class std::vector <class cv::Point_ <float>> points_1; + ptrdiff_t size; + class cv::Mat img_hg; + class cv::Mat img_align; + + /* Detect ORB features & compute descriptors */ +#if (CV_VERSION_EPOCH == 2) + orb(*img_0, cv::Mat(), keypoints_0, descriptors_0); + orb(*img_1, cv::Mat(), keypoints_1, descriptors_1); +#elif (CV_VERSION_EPOCH == 3) + orb = cv::ORB::create(MAX_FEATURES); + orb->detectAndCompute(*img_0, cv::Mat(), keypoints_0, descriptors_0); + orb->detectAndCompute(*img_1, cv::Mat(), keypoints_1, descriptors_1); +#endif + + /* Match structures */ + matcher = cv::DescriptorMatcher::create("BruteForce-Hamming"); + matcher->match(descriptors_1, descriptors_0, matches, cv::Mat()); + + /* Sort matches by score */ + std::sort(matches.begin(), matches.end()); + + /* Remove not so good matches */ + good_matches = GOOD_MATCH_P * matches.size(); + matches.erase(matches.begin() + good_matches, matches.end()); + + /* Draw top matches */ + cv::drawMatches(*img_1, keypoints_1, *img_0, keypoints_0, matches, + img_matches); + cv::imwrite("matches.jpg", img_matches); + + /* Extract location of good matches */ + size = matches.size(); + for (ptrdiff_t i = 0; i < size; i++) { + points_1.push_back(keypoints_1[matches[i].queryIdx].pt); + points_0.push_back(keypoints_0[matches[i].trainIdx].pt); + } + + /* Find homography */ + img_hg = cv::findHomography(points_1, points_0, CV_RANSAC); + + /* Use homography to warp image */ + cv::warpPerspective(*img_1, img_align, img_hg, img_0->size()); + + /* Write img_align into img_1 */ + *img_1 = img_align; + img_align.release(); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/image/zbar.cpp b/src/image/zbar.cpp new file mode 100644 index 0000000..f11e751 --- /dev/null +++ b/src/image/zbar.cpp @@ -0,0 +1,122 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "vision-artificial/image/zbar.hpp" + +#include <climits> +#include <cstddef> +#include <cstdio> + +#include <opencv2/opencv.hpp> +#include <zbar.h> + +#include "vision-artificial/image/iface.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ +static void img_zb_decode (class cv::Mat *imgptr, const void *data); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void img_zb_act (class cv::Mat *imgptr, int action, const void *data) +{ + + switch (action) { + case IMG_ZB_ACT_DECODE: + img_zb_decode(imgptr, data); + break; + } +} + + +/****************************************************************************** + ******* static functions (definitions) *************************************** + ******************************************************************************/ +static void img_zb_decode (class cv::Mat *imgptr, const void *data) +{ + const struct zbar::zbar_symbol_s *symbol; + struct zbar::zbar_image_scanner_s *scanner; + struct zbar::zbar_image_s *image_zb; + enum zbar::zbar_symbol_type_e code_type; + void *imgdata; + ptrdiff_t rows; + ptrdiff_t cols; + + imgdata = (void *)imgptr->data; + rows = imgptr->rows; + cols = imgptr->cols; + + /* Type of code to scan */ + code_type = (enum zbar::zbar_symbol_type_e) + ((const struct Img_Iface_Data_Decode *)data)->code_type; + + /* create & configure a reader */ + scanner = zbar::zbar_image_scanner_create(); + zbar::zbar_image_scanner_set_config(scanner, code_type, + zbar::ZBAR_CFG_ENABLE, 1); + + /* wrap image data */ + image_zb = zbar::zbar_image_create(); + zbar::zbar_image_set_format(image_zb, *(int*)"GREY"); + zbar::zbar_image_set_size(image_zb, cols, rows); + zbar::zbar_image_set_data(image_zb, imgdata, cols * rows, NULL); + + /* scan the image for barcodes */ + zb_codes.n = zbar::zbar_scan_image(scanner, image_zb); + if (!zb_codes.n) + goto not_found; + + /* extract results */ + symbol = zbar::zbar_image_first_symbol(image_zb); + for (ptrdiff_t i = 0; i < ZB_CODES_MAX && symbol; i++) { + zb_codes.arr[i].type = zbar::zbar_symbol_get_type(symbol); + code_type = (enum zbar::zbar_symbol_type_e)zb_codes.arr[i].type; + snprintf(zb_codes.arr[i].sym_name, 80, "%s", + zbar::zbar_get_symbol_name(code_type)); + snprintf(zb_codes.arr[i].data, ZBAR_LEN_MAX, "%s", + zbar::zbar_symbol_get_data(symbol)); + + /* Load next symbol */ + symbol = zbar::zbar_symbol_next(symbol); + } + +not_found: + /* clean up */ + zbar::zbar_image_destroy(image_zb); + zbar::zbar_image_scanner_destroy(scanner); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/main.cpp b/src/main.cpp index b1bc046..1a8f5de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,24 +7,24 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <cstdio> -/* libalx --------------------------------------------------------------------*/ - #include "libalx/curses/alx_ncur.hpp" -/* Project -------------------------------------------------------------------*/ - #include "about.hpp" - #include "img_iface.hpp" - #include "menu_iface.hpp" - #include "user_iface.hpp" - #include "parser.hpp" - #include "save.hpp" +#include <cstdio> + +#include "libalx/base/stdio/wait.hpp" +#include "libalx/extra/ncurses/common.hpp" + +#include "vision-artificial/about/about.hpp" +#include "vision-artificial/image/iface.hpp" +#include "vision-artificial/menu/iface.hpp" +#include "vision-artificial/menu/parse.hpp" +#include "vision-artificial/save/save.hpp" +#include "vision-artificial/user/iface.hpp" /****************************************************************************** ******* static functions ***************************************************** ******************************************************************************/ -static void init_all (int *argc, char *(*argv[])); -static void cleanup (void); +static void init (int *argc, char *(*argv[])); +static void deinit (void); /****************************************************************************** @@ -33,14 +33,14 @@ static void cleanup (void); int main (int argc, char *argv[]) { - init_all(&argc, &argv); + init(&argc, &argv); print_share_file(SHARE_COPYRIGHT); - getchar(); + alx_wait4enter(); menu_iface(); - cleanup(); + deinit(); return 0; } @@ -49,11 +49,11 @@ int main (int argc, char *argv[]) /****************************************************************************** ******* static functions ***************************************************** ******************************************************************************/ -static void init_all (int *argc, char *(*argv[])) +static void init (int *argc, char *(*argv[])) { - alx_start_curses(); - alx_pause_curses(); + alx_ncurses_init(); + alx_ncurses_pause(); about_init(); save_init(); @@ -62,16 +62,16 @@ static void init_all (int *argc, char *(*argv[])) user_iface_mode = USER_IFACE_TUI; user_iface_log.visible = 2; - parser(*argc, *argv); + parse(*argc, *argv); } -static void cleanup (void) +static void deinit (void) { - img_iface_cleanup_main(); + img_iface_deinit(); - alx_resume_curses(); - alx_end_curses(); + alx_ncurses_resume(); + alx_ncurses_deinit(); } diff --git a/src/menu/clui.c b/src/menu/clui.c new file mode 100644 index 0000000..5e947b7 --- /dev/null +++ b/src/menu/clui.c @@ -0,0 +1,125 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "vision-artificial/menu/clui.h" + +#include <ctype.h> +#include <stdlib.h> + +#include "libalx/base/stdio/get.h" + +#include "vision-artificial/about/about.h" +#include "vision-artificial/ctrl/start.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ +//static void menu_clui_rand (void); +//static void menu_clui_custom (void); +static void menu_clui_load (void); +static void menu_clui_start (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void menu_clui (void) +{ + unsigned char c; + + c = alx_get_ch("ny", true, true, "Read 'Disclaimer of warranty'? (yes/NO): ", + NULL, 1); + if (tolower(c) == 'y') { + printf(" >yes\n"); + print_share_file(SHARE_DISCLAIMER); + } else { + printf(" >NO\n"); + } + + c = alx_get_ch("ny", true, true, "Read 'License'? (yes/NO): ", NULL, 1); + if (tolower(c) == 'y') { + printf(" >yes\n"); + print_share_file(SHARE_LICENSE); + } else { + printf(" >NO\n"); + } +#if 0 + c = alx_get_ch("nt", true, true, "Game interface? (NCURSES/text): ", + NULL, 1); + if (tolower(c) == 't') { + printf(" >text\n"); + // FIXME + } else { + printf(" >NCURSES\n"); + // FIXME + } +#endif + menu_clui_load(); +} + + +/****************************************************************************** + ******* static functions (definitions) *************************************** + ******************************************************************************/ +static void menu_clui_load (void) +{ + +#if 0 + /* File name */ /* FIXME */ + alx_w_getfname(USER_SAVED_DIR, saved_name, "File name:", saved_name, NULL); +#endif + menu_clui_start(); +} + +static void menu_clui_start (void) +{ + unsigned char c; + + printf(" >>START:\n"); + start_switch(); + + c = alx_get_ch("mle", true, true, "Load again? (MENU/load/exit): ", + NULL, 1); + if (tolower(c) == 'l') { + printf(" >load\n"); + menu_clui_start(); + } else if (tolower(c) == 'e') { + printf(" >exit!\n"); + exit(EXIT_SUCCESS); + } else { + printf(" >MENU\n"); + menu_clui(); + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/menu/iface.c b/src/menu/iface.c new file mode 100644 index 0000000..4b8bbd7 --- /dev/null +++ b/src/menu/iface.c @@ -0,0 +1,68 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "vision-artificial/menu/iface.h" + +#include "vision-artificial/menu/clui.h" +#include "vision-artificial/menu/tui.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +int menu_iface_mode; + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void menu_iface (void) +{ + + switch (menu_iface_mode) { + case MENU_IFACE_FOO: + break; + case MENU_IFACE_CLUI: + menu_clui(); + break; + case MENU_IFACE_TUI: + menu_tui(); + break; + } +} + + +/****************************************************************************** + ******* static functions (definitions) *************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/menu/parse.c b/src/menu/parse.c new file mode 100644 index 0000000..959ec5f --- /dev/null +++ b/src/menu/parse.c @@ -0,0 +1,152 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "vision-artificial/menu/parse.h" + +#include <stdio.h> +#include <stdlib.h> + +#include <getopt.h> + +#include "libalx/base/stdio/sscan.h" + +#include "vision-artificial/about/about.h" +#include "vision-artificial/menu/iface.h" +#include "vision-artificial/save/save.h" +#include "vision-artificial/user/iface.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +#define OPT_LIST "hLuv""f:i:" + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ +static void parse_file (char *arg); +static void parse_iface (char *arg); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void parse (int argc, char *argv[]) +{ + int opt = 0; + int opt_index = 0; + + const struct option long_options[] = { + /* Standard */ + {"help", no_argument, 0, 'h'}, + {"license", no_argument, 0, 'L'}, + {"usage", no_argument, 0, 'u'}, + {"version", no_argument, 0, 'v'}, + /* Non-standard */ + {"file", required_argument, 0, 'f'}, + {"iface", required_argument, 0, 'i'}, + /* Null */ + {0, 0, 0, 0} + }; + + while ((opt = getopt_long(argc, argv, OPT_LIST, long_options, + &opt_index)) != -1) { + + switch (opt) { + /* Standard */ + case 'h': + print_share_file(SHARE_HELP); + exit(EXIT_SUCCESS); + case 'L': + print_share_file(SHARE_LICENSE); + exit(EXIT_SUCCESS); + case 'u': + print_share_file(SHARE_USAGE); + exit(EXIT_SUCCESS); + case 'v': + print_version(); + exit(EXIT_SUCCESS); + /* Non-standard */ + case 'f': + parse_file(optarg); + break; + case 'i': + parse_iface(optarg); + break; + + case '?': + /* getopt_long already printed an error message. */ + default: + print_share_file(SHARE_USAGE); + exit(EXIT_FAILURE); + } + } +} + + +/****************************************************************************** + ******* static functions (definitions) *************************************** + ******************************************************************************/ +static void parse_file (char *arg) +{ + FILE *fp; + + /* FIXME */ + fp = fopen(arg, "r"); + if (!fp) + goto err; + fclose(fp); + + saved_path[0] = '\0'; + snprintf(saved_name, FILENAME_MAX, "%s", arg); + + return; +err: + printf("--file argument not valid\n"); + printf("It must be a valid file name (relative to saved dir)\n"); + exit(EXIT_FAILURE); +} + +static void parse_iface (char *arg) +{ + + if (alx_sscan_int(&menu_iface_mode, MENU_IFACE_CLUI, 0, MENU_IFACE_TUI, + arg)) { + goto err; + } + user_iface_mode = menu_iface_mode; + + return; +err: + printf("--iface argument not valid\n"); + printf("It must be an integer [%i U %i]\n", MENU_IFACE_CLUI, + MENU_IFACE_TUI); + exit(EXIT_FAILURE); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/menu/tui.c b/src/menu/tui.c new file mode 100644 index 0000000..6c0620e --- /dev/null +++ b/src/menu/tui.c @@ -0,0 +1,315 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "vision-artificial/menu/tui.h" + +#include <stdbool.h> +#include <stddef.h> +#include <stdint.h> + +#include <ncurses.h> + +#include "libalx/base/stddef/size.h" +#include "libalx/base/stdio/wait.h" +#include "libalx/extra/ncurses/common.h" +#include "libalx/extra/ncurses/get.h" +#include "libalx/extra/ncurses/menu.h" + +#include "vision-artificial/about/about.h" +#include "vision-artificial/ctrl/start.h" +#include "vision-artificial/proc/iface.h" +#include "vision-artificial/save/save.h" +#include "vision-artificial/user/iface.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ +static void menu_continue (void); +static void menu_select (void); +static void menu_series (void); +static void menu_devel (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void menu_tui (void) +{ + int_fast8_t h, w; + bool wh; + int_fast8_t sw; + + alx_ncurses_resume(); + + h = 23; + w = 80; + + static const struct Alx_Ncurses_Menu mnu[] = { + {7, 4, "[0] Exit program"}, + {2, 4, "[1] Continue"}, + {4, 4, "[2] Disclaimer of warranty"}, + {5, 4, "[3] Terms and conditions"} + }; + + wh = true; + while (wh) { + sw = alx_ncurses_menu(h, w, ARRAY_SIZE(mnu), mnu, "MENU:"); + + switch (sw) { + case 0: + wh = false; + break; + case 1: + menu_continue(); + break; + case 2: + alx_ncurses_pause(); + print_share_file(SHARE_DISCLAIMER); + printf("Press ENTER to continue"); + alx_wait4enter(); + alx_ncurses_resume(); + break; + case 3: + alx_ncurses_pause(); + print_share_file(SHARE_LICENSE); + printf("Press ENTER to continue"); + alx_wait4enter(); + alx_ncurses_resume(); + break; + } + } + + alx_ncurses_pause(); +} + + +/****************************************************************************** + ******* static functions (definitions) *************************************** + ******************************************************************************/ +static void menu_continue (void) +{ + WINDOW *win; + int_fast8_t h, w; + int_fast8_t r, c; + int_fast8_t w2, r2; + bool wh; + int_fast8_t sw; + + h = 23; + w = 80; + r = 1; + c = (80 - w) / 2; + + static const struct Alx_Ncurses_Menu mnu[] = { + {8, 4, "[0] Back"}, + {2, 4, "[1] Start"}, + {3, 4, "[2] Select"}, + {4, 4, "[3] Series"}, + {5, 4, "[4] Change file name"}, + {6, 4, "[5] DEVEL"} + }; + + /* Input box */ + w2 = w - 8; + r2 = r + h - 5; + static const char *const txt[] = {"File name:"}; + + wh = true; + while (wh) { + win = newwin(h, w, r, c); + mvwprintw(win, mnu[1].r, mnu[1].c, "%s (File: \"%s\")", + mnu[1].t, saved_name); + sw = alx_ncurses_w_menu(win, ARRAY_SIZE(mnu), mnu, + "CONTINUE:"); + + switch (sw) { + case 0: + wh = false; + break; + case 1: + alx_ncurses_delwin(win); + alx_ncurses_pause(); + start_switch(); + alx_ncurses_resume(); + break; + case 2: + alx_ncurses_delwin(win); + menu_select(); + break; + case 3: + alx_ncurses_delwin(win); + menu_series(); + break; + case 4: + save_reset_fpath(); + alx_w_get_fname(saved_path, saved_name, true, w2, r2, + txt[0], NULL, 2); + alx_ncurses_delwin(win); + break; + case 5: + alx_ncurses_delwin(win); + menu_devel(); + break; + } + } + + alx_ncurses_delwin(win); +} + +static void menu_select (void) +{ + int_fast8_t h, w; + int_fast8_t sw; + + h = 23; + w = 80; + + static const struct Alx_Ncurses_Menu mnu[] = { + {6, 4, "[0] Back"}, + {2, 4, "[1] Single image"}, + {4, 4, "[2] Series"} + }; + + sw = alx_ncurses_menu(h, w, ARRAY_SIZE(mnu), mnu, "SELECT MODE:"); + + switch (sw) { + case 1: + start_mode = START_SINGLE; + break; + + case 2: + start_mode = START_SERIES; + break; + } + +} + +static void menu_series (void) +{ + int_fast8_t h, w; + int_fast8_t sw; + + h = 23; + w = 80; + + static const struct Alx_Ncurses_Menu mnu[] = { + {8, 4, "[0] Back"}, + {2, 4, "[1] Label"}, + {3, 4, "[2] Objects"}, + {4, 4, "[3] Coins"}, + {5, 4, "[4] Resistor"}, + {6, 4, "[5] Lighters"} + }; + + sw = alx_ncurses_menu(h, w, ARRAY_SIZE(mnu), mnu, "SELECT LEVEL:"); + + switch (sw) { + case 1: + proc_mode = PROC_MODE_LABEL_SERIES; + break; + case 2: + proc_mode = PROC_MODE_OBJECTS_SERIES; + break; + case 3: + proc_mode = PROC_MODE_COINS_SERIES; + break; + case 4: + proc_mode = PROC_MODE_RESISTOR_SERIES; + break; + case 5: + proc_mode = PROC_MODE_LIGHTERS_SERIES; + break; + } + +} + +static void menu_devel (void) +{ + WINDOW *win; + int_fast8_t h, w; + int_fast8_t r, c; + int_fast8_t w2, r2; + bool wh; + int_fast8_t sw; + + h = 23; + w = 80; + r = 1; + c = (80 - w) / 2; + + static const struct Alx_Ncurses_Menu mnu[] = { + {6, 4, "[0] Back"}, + {2, 4, "[1] Change process mode"}, + {3, 4, "[2] Change log mode"}, + {4, 4, "[3] Change user iface mode"} + }; + + /* Input box */ + w2 = w - 8; + r2 = r + h - 5; + static const char *const txt[] = { + "Modes: 0=Auto; 1=Stop@prod; 2=Delay@step; 3=Stop@step", + "Modes: 0=Results; 1=Operations; 2=All", + "Modes: 1=CLUI; 2=TUI" + }; + + win = newwin(h, w, r, c); + + wh = true; + while (wh) { + sw = alx_ncurses_w_menu(win, ARRAY_SIZE(mnu), mnu, + "DEVELOPER OPTIONS:"); + switch (sw) { + case 0: + wh = false; + break; + case 1: + proc_debug = alx_w_get_int(PROC_DBG_NO, 0, + PROC_DBG_STOP_STEP, + w2, r2, txt[0], NULL, 2); + break; + case 2: + user_iface_log.visible = alx_w_get_u8(0, 2, 2, + w2, r2, txt[1], NULL, 2); + break; + case 3: + user_iface_mode = alx_w_get_int(1, 2, 2, + w2, r2, txt[2], NULL, 2); + break; + } + } + + alx_ncurses_delwin(win); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/proc/coins.cpp b/src/proc/coins.cpp new file mode 100644 index 0000000..76d9640 --- /dev/null +++ b/src/proc/coins.cpp @@ -0,0 +1,291 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "vision-artificial/proc/coins.hpp" + +#include <cstdio> + +#include <opencv2/opencv.hpp> + +#include "libalx/base/math/arithmetic_mean.hpp" +#include "libalx/base/stddef/size.hpp" +#include "libalx/base/stdlib/maximum.hpp" + +#include "vision-artificial/image/iface.hpp" +#include "vision-artificial/user/iface.hpp" +#include "vision-artificial/proc/common.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +#define COINS_MAX (0xFFF) + +#define COIN_DIAMETER_2E (25.75) +#define COIN_DIAMETER_50c (24.25) +#define COIN_DIAMETER_1E (23.25) +#define COIN_DIAMETER_20c (22.25) +#define COIN_DIAMETER_5c (21.25) +#define COIN_DIAMETER_10c (19.75) +#define COIN_DIAMETER_2c (18.75) +#define COIN_DIAMETER_1c (16.25) + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ +struct Coins_Properties { + ptrdiff_t x; + ptrdiff_t y; + uint8_t diameter_pix; + double diameter_mm; + double value; +}; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ +/* Static --------------------------------------------------------------------*/ +static class std::vector <class std::vector <class cv::Point_ <int>>> contours; +static class cv::Mat hierarchy; +static class cv::Rect_ <int> rectangle[COINS_MAX]; +static ptrdiff_t coins_n; +static struct Coins_Properties coins[COINS_MAX]; +static double ratio_mm_per_pix; +static double value_total; + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ +static void result_coins (int status); + +static void coins_segmentate (void); +static int coins_positions (void); +static void coins_diameters_pix (void); +static void calibrate_mm_per_pix (void); +static void coins_diameters_mm (void); +static int coins_values (void); +static double coin_value (double diameter_mm); +static void coins_total_value (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +int proc_coins (void) +{ + int status; + + proc_save_mem(0); + + /* Segmentate coins */ + clock_start(); + coins_segmentate(); + clock_stop("Segmentate coins"); + + /* Find coins positions */ + clock_start(); + status = coins_positions(); + if (status) { + result_coins(status); + return status; + } + clock_stop("Find coins positions"); + + /* Get coin diameters in pixels */ + clock_start(); + coins_diameters_pix(); + clock_stop("Coins diameters in pixels"); + + /* Calibrate with the biggest coin; every img should have a 2 € coin */ + clock_start(); + calibrate_mm_per_pix(); + clock_stop("Calibrate (mm per pix)"); + + /* Get coins diameters in mm */ + clock_start(); + coins_diameters_mm(); + clock_stop("Coins diameters in mm"); + + /* Get coins values (by their sizes) */ + clock_start(); + status = coins_values(); + if (status) { + result_coins(status); + return status; + } + clock_stop("Coins values"); + + /* Add total value */ + clock_start(); + coins_total_value(); + clock_stop("Total value"); + + result_coins(COINS_OK); + return 0; +} + + +/****************************************************************************** + ******* static functions (definitions) *************************************** + ******************************************************************************/ +static void result_coins (int status) +{ + + switch (status) { + case COINS_OK: + user_iface_log_write(0, "Coin: OK"); + break; + case COINS_NOK_COINS: + user_iface_log_write(0, "Coin: NOK_COINS"); + break; +#if 0 + case COINS_NOK_OVERLAP: + user_iface_log_write(0, "Coin: NOK_OVERLAP"); + break; +#endif + case COINS_NOK_SIZE: + user_iface_log_write(0, "Coin: NOK_SIZE"); + break; + default: + user_iface_log_write(0, "Coin: NOK"); + break; + } +} + +static void coins_segmentate (void) +{ + proc_load_mem(0); + + proc_cmp(IMG_IFACE_CMP_BLUE); + proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU); + proc_distance_transform(); + proc_local_max(); + proc_dilate(6); + proc_save_mem(1); +} + +static int coins_positions (void) +{ + + proc_load_mem(1); + + proc_contours(&contours, &hierarchy); + coins_n = contours.size(); + if (!coins_n) + return COINS_NOK_COINS; + for (ptrdiff_t i = 0; i < coins_n; i++) { + proc_bounding_rect(&contours[i], &rectangle[i], true); + coins[i].x = rectangle[i].x + rectangle[i].width / 2.0; + coins[i].y = rectangle[i].y + rectangle[i].height / 2.0; + } + + return 0; +} + +static void coins_diameters_pix (void) +{ + + proc_load_mem(1); + for (ptrdiff_t i = 0; i < coins_n; i++) { + proc_pixel_get(coins[i].x, coins[i].y, &coins[i].diameter_pix); + coins[i].diameter_pix *= 2; + } +} + +static void calibrate_mm_per_pix (void) +{ + uint8_t coins_size_pix[coins_n]; + int max_pos; + int max_size; + + for (ptrdiff_t i = 0; i < coins_n; i++) + coins_size_pix[i] = coins[i].diameter_pix; + + max_pos = alx_maximum_u8(ARRAY_SIZE(coins_size_pix), coins_size_pix); + max_size = coins_size_pix[max_pos]; + ratio_mm_per_pix = 25.75 / max_size; +} + +static void coins_diameters_mm (void) +{ + char txt[LOG_LINE_LEN]; + + for (ptrdiff_t i = 0; i < coins_n; i++) { + coins[i].diameter_mm = ratio_mm_per_pix * coins[i].diameter_pix; + snprintf(txt, LOG_LINE_LEN, "Coin[%ti]: %.2lf mm", + i, coins[i].diameter_mm); + user_iface_log_write(0, txt); + } +} + +static int coins_values (void) +{ + char txt[LOG_LINE_LEN]; + + for (ptrdiff_t i = 0; i < coins_n; i++) { + coins[i].value = coin_value(coins[i].diameter_mm); + if (coins[i].value < 0) + return COINS_NOK_SIZE; + snprintf(txt, LOG_LINE_LEN, "Coin[%ti]: %.2lf EUR", + i, coins[i].value); + user_iface_log_write(0, txt); + } + + return 0; +} + +static double coin_value (double diameter_mm) +{ + + if (diameter_mm > (COIN_DIAMETER_2E + 1.5)) + return -1; + if (diameter_mm > AVGfast(COIN_DIAMETER_2E, COIN_DIAMETER_50c,double_t)) + return 2.00; + if (diameter_mm > AVGfast(COIN_DIAMETER_50c, COIN_DIAMETER_1E,double_t)) + return 0.50; + if (diameter_mm > AVGfast(COIN_DIAMETER_1E, COIN_DIAMETER_20c,double_t)) + return 1.00; + if (diameter_mm > AVGfast(COIN_DIAMETER_20c, COIN_DIAMETER_5c,double_t)) + return 0.20; + if (diameter_mm > AVGfast(COIN_DIAMETER_5c, COIN_DIAMETER_10c,double_t)) + return 0.05; + if (diameter_mm > AVGfast(COIN_DIAMETER_10c, COIN_DIAMETER_2c,double_t)) + return 0.10; + if (diameter_mm > AVGfast(COIN_DIAMETER_2c, COIN_DIAMETER_1c, double_t)) + return 0.02; + if (diameter_mm > (COIN_DIAMETER_1c - 1.5)) + return 0.01; + return -1; +} + +static void coins_total_value (void) +{ + char txt[LOG_LINE_LEN]; + + value_total = 0.00; + for (ptrdiff_t i = 0; i < coins_n; i++) + value_total += coins[i].value; + + snprintf(txt, LOG_LINE_LEN, "Total value: %.2lf EUR",value_total); + user_iface_log_write(0, txt); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/proc/common.cpp b/src/proc/common.cpp new file mode 100644 index 0000000..82cb6eb --- /dev/null +++ b/src/proc/common.cpp @@ -0,0 +1,461 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "vision-artificial/proc/common.hpp" + +#include <cstddef> +#include <cstdio> +#include <ctime> + +#include <opencv2/opencv.hpp> + +#include "libalx/base/stdio/wait.hpp" + +#include "vision-artificial/image/iface.hpp" +#include "vision-artificial/proc/iface.hpp" +#include "vision-artificial/user/iface.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ +/* Static --------------------------------------------------------------------*/ +static clock_t clock_0; +static clock_t clock_1; + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void proc_apply (void) +{ + img_iface_act(IMG_IFACE_ACT_APPLY, NULL); +} + +void proc_save_mem (ptrdiff_t n) +{ + img_iface_act(IMG_IFACE_ACT_SAVE_MEM, (const void *)&n); +} + +void proc_load_mem (ptrdiff_t n) +{ + + img_iface_act(IMG_IFACE_ACT_LOAD_MEM, (const 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_skeleton (void) +{ + + img_iface_act(IMG_IFACE_ACT_SKELETON, 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_get (ptrdiff_t x, ptrdiff_t y, unsigned char *val) +{ + struct Img_Iface_Data_Pixel_Get data; + + data = (struct Img_Iface_Data_Pixel_Get){ + .val = val, + .x = x, + .y = y, + }; + img_iface_act(IMG_IFACE_ACT_PIXEL_GET, (const void *)&data); +} + +void proc_pixel_set (ptrdiff_t x, ptrdiff_t y, unsigned char val) +{ + struct Img_Iface_Data_Pixel_Set data; + + data = (struct Img_Iface_Data_Pixel_Set){ + .val = val, + .x = x, + .y = y, + }; + img_iface_act(IMG_IFACE_ACT_PIXEL_SET, (const void *)&data); + proc_show_img(); +} + +void proc_ROI (int x, int y, int w, int h) +{ + struct Img_Iface_Data_SetROI data; + + data = (struct Img_Iface_Data_SetROI){ + .rect = { + .x = x, + .y = y, + .width = w, + .height = h, + }, + }; + img_iface_act(IMG_IFACE_ACT_SET_ROI, (const 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 = (struct Img_Iface_Data_Component){ + .cmp = cmp, + }; + img_iface_act(IMG_IFACE_ACT_COMPONENT, (const void *)&data); + proc_show_img(); +} + +void proc_dilate (int size) +{ + struct Img_Iface_Data_Dilate_Erode data; + + data = (struct Img_Iface_Data_Dilate_Erode){ + .i = size, + }; + img_iface_act(IMG_IFACE_ACT_DILATE, (const void *)&data); + proc_show_img(); +} + +void proc_erode (int size) +{ + struct Img_Iface_Data_Dilate_Erode data; + + data = (struct Img_Iface_Data_Dilate_Erode){ + .i = size, + }; + img_iface_act(IMG_IFACE_ACT_ERODE, (const void *)&data); + proc_show_img(); +} + +void proc_dilate_erode (int size) +{ + struct Img_Iface_Data_Dilate_Erode data; + + data = (struct Img_Iface_Data_Dilate_Erode){ + .i = size, + }; + img_iface_act(IMG_IFACE_ACT_DILATE_ERODE, (const void *)&data); + proc_show_img(); +} + +void proc_erode_dilate (int size) +{ + struct Img_Iface_Data_Dilate_Erode data; + + data = (struct Img_Iface_Data_Dilate_Erode){ + .i = size, + }; + img_iface_act(IMG_IFACE_ACT_ERODE_DILATE, (const void *)&data); + proc_show_img(); +} + +void proc_smooth (int method, int ksize) +{ + struct Img_Iface_Data_Smooth data; + + data = (struct Img_Iface_Data_Smooth){ + .method = method, + .ksize = ksize, + }; + img_iface_act(IMG_IFACE_ACT_SMOOTH, (const void *)&data); + proc_show_img(); +} + +void proc_border (int size) +{ + struct Img_Iface_Data_Border data; + + data = (struct Img_Iface_Data_Border){ + .size = size, + }; + img_iface_act(IMG_IFACE_ACT_BORDER, (const void *)&data); + proc_show_img(); +} + +void proc_rotate (float center_x, float center_y, double angle) +{ + struct Img_Iface_Data_Rotate data; + + data = (struct Img_Iface_Data_Rotate){ + .center = { + .x = center_x, + .y = center_y, + }, + .angle = angle, + }; + img_iface_act(IMG_IFACE_ACT_ROTATE, (const void *)&data); + proc_show_img(); +} + +void proc_adaptive_threshold (int method, int type, int ksize) +{ + struct Img_Iface_Data_Adaptive_Thr data; + + data = (struct Img_Iface_Data_Adaptive_Thr){ + .method = method, + .thr_typ = type, + .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 = (struct Img_Iface_Data_Cvt_Color){ + .method = method, + }; + img_iface_act(IMG_IFACE_ACT_CVT_COLOR, (const void *)&data); + proc_show_img(); +} + +void proc_threshold (int type, int size) +{ + struct Img_Iface_Data_Threshold data; + + data = (struct Img_Iface_Data_Threshold){ + .thr_typ = type, + .thr_val = size, + }; + img_iface_act(IMG_IFACE_ACT_THRESHOLD, (const 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( + class std::vector <class std::vector <class cv::Point_<int>>> *contours, + class cv::Mat *hierarchy) +{ + struct Img_Iface_Data_Contours data; + + data = (struct Img_Iface_Data_Contours){ + .contours = contours, + .hierarchy = hierarchy, + }; + img_iface_act(IMG_IFACE_ACT_CONTOURS, (const void *)&data); + proc_show_img(); +} + +void proc_contours_size( + const class std::vector <class std::vector <class cv::Point_ <int>>> *contours, + double *area, + double *perimeter) +{ + struct Img_Iface_Data_Contours_Size data; + + data = (struct Img_Iface_Data_Contours_Size){ + .contours = contours, + .area = area, + .perimeter = perimeter, + }; + img_iface_act(IMG_IFACE_ACT_CONTOURS_SIZE, (const void *)&data); +} + +void proc_bounding_rect( + const class std::vector <class cv::Point_ <int>> *contour, + class cv::Rect_ <int> *rect, + bool show) +{ + struct Img_Iface_Data_Bounding_Rect data; + + data = (struct Img_Iface_Data_Bounding_Rect){ + .contour = contour, + .rect = rect, + .show = show, + }; + img_iface_act(IMG_IFACE_ACT_BOUNDING_RECT, (const void *)&data); + if (show) + proc_show_img(); +} + +void proc_fit_ellipse ( + const class std::vector <class cv::Point_ <int>> *contour, + class cv::RotatedRect *rect, + bool show +) +{ + struct Img_Iface_Data_MinARect data; + + data = (struct Img_Iface_Data_MinARect){ + .contour = contour, + .rect = rect, + .show = show, + }; + img_iface_act(IMG_IFACE_ACT_FIT_ELLIPSE, (const void *)&data); + if (show) + proc_show_img(); +} + +void proc_min_area_rect ( + const class std::vector <class cv::Point_ <int>> *contour, + class cv::RotatedRect *rect, + bool show +) +{ + struct Img_Iface_Data_MinARect data; + + data = (struct Img_Iface_Data_MinARect){ + .contour = contour, + .rect = rect, + .show = show, + }; + img_iface_act(IMG_IFACE_ACT_MIN_AREA_RECT, (const 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, (const void *)&data); +} + +void proc_zbar (int type) +{ + struct Img_Iface_Data_Decode data; + + data = (struct Img_Iface_Data_Decode){ + .code_type = type, + }; + img_iface_act(IMG_IFACE_ACT_DECODE, (const void *)&data); +} + +void proc_show_img (void) +{ + + if (proc_debug < PROC_DBG_DELAY_STEP) + return; + img_iface_show_img(); + if (proc_debug >= PROC_DBG_STOP_STEP) + alx_wait4enter(); +} + +void clock_start (void) +{ + clock_0 = clock(); +} + +void clock_stop (const char *txt) +{ + clock_t clock_diff; + double time_diff; + char tmp[LOG_LINE_LEN]; + + clock_1 = clock(); + clock_diff = clock_1 - clock_0; + time_diff = (double)clock_diff / (double)CLOCKS_PER_SEC; + + snprintf(tmp, LOG_LINE_LEN, "Time: %.3lf (%s)", time_diff, txt); + user_iface_log_write(0, tmp); +} + + +/****************************************************************************** + ******* static functions (definitions) *************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/proc/iface.c b/src/proc/iface.c new file mode 100644 index 0000000..9790e1c --- /dev/null +++ b/src/proc/iface.c @@ -0,0 +1,224 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "vision-artificial/proc/iface.h" + +#include <errno.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> + +#include "libalx/base/stddef/size.h" +#include "libalx/base/stdio/sscan.h" +#include "libalx/base/stdio/wait.h" + +#include "vision-artificial/image/iface.h" +#include "vision-artificial/proc/coins.h" +#include "vision-artificial/proc/common.h" +#include "vision-artificial/proc/label.h" +#include "vision-artificial/proc/lighters.h" +#include "vision-artificial/proc/objects.h" +#include "vision-artificial/proc/resistor.h" +#include "vision-artificial/save/save.h" +#include "vision-artificial/user/iface.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ + int proc_debug; + int proc_mode; +/* Static --------------------------------------------------------------------*/ +static char proc_path [FILENAME_MAX]; +static char proc_fail_path [FILENAME_MAX]; + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +int proc_iface_single (int action) +{ + int error; + clock_t time_0; + clock_t time_1; + double time_tot; + char txt[LOG_LINE_LEN]; + + time_0 = clock(); + + switch (action) { + case PROC_MODE_LABEL_SERIES: + error = proc_label(); + break; + case PROC_MODE_OBJECTS_CALIB: + error = proc_objects_calibrate(); + break; + case PROC_MODE_OBJECTS_SERIES: + error = proc_objects(); + break; + case PROC_MODE_COINS_SERIES: + error = proc_coins(); + break; + case PROC_MODE_RESISTOR_SERIES: + error = proc_resistor(); + break; + case PROC_MODE_LIGHTERS_SERIES: + error = proc_lighter(); + break; + default: + error = -1; + } + + time_1 = clock(); + time_tot = ((double) time_1 - time_0) / CLOCKS_PER_SEC; + snprintf(txt, LOG_LINE_LEN, "Item total time: %.3lf", time_tot); + user_iface_log_write(0, txt); + + return error; +} + +void proc_iface_series (void) +{ + int num_len; + char file_basename[FILENAME_MAX]; + char file_ext[FILENAME_MAX]; + char file_name[FILENAME_MAX]; + char save_error_as[FILENAME_MAX]; + /* if i starts being 0, the camera needs calibration */ + int i; + char txt[LOG_LINE_LEN]; + char tmp[FILENAME_MAX]; + + switch (proc_mode) { + case PROC_MODE_LABEL_SERIES: + snprintf(proc_path, FILENAME_MAX, "%s", labels_path); + snprintf(proc_fail_path, FILENAME_MAX, "%s", labels_fail_path); + snprintf(file_basename, FILENAME_MAX, "b"); + num_len = 4; + snprintf(file_ext, FILENAME_MAX, ".BMP"); + i = 1; + break; + case PROC_MODE_OBJECTS_SERIES: + snprintf(proc_path, FILENAME_MAX, "%s", objects_path); + snprintf(proc_fail_path, FILENAME_MAX, "%s", objects_fail_path); + snprintf(file_basename, FILENAME_MAX, "o"); + num_len = 4; + snprintf(file_ext, FILENAME_MAX, ".jpeg"); + i = 0; + proc_mode++; + break; + case PROC_MODE_COINS_SERIES: + snprintf(proc_path, FILENAME_MAX, "%s", coins_path); + snprintf(proc_fail_path, FILENAME_MAX, "%s", coins_fail_path); + snprintf(file_basename, FILENAME_MAX, "c"); + num_len = 4; + snprintf(file_ext, FILENAME_MAX, ".jpeg"); + i = 1; + break; + case PROC_MODE_RESISTOR_SERIES: + snprintf(proc_path, FILENAME_MAX, "%s", resistors_path); + snprintf(proc_fail_path, FILENAME_MAX,"%s",resistors_fail_path); + snprintf(file_basename, FILENAME_MAX, "r"); + num_len = 4; + snprintf(file_ext, FILENAME_MAX, ".png"); + i = 1; + break; + case PROC_MODE_LIGHTERS_SERIES: + snprintf(proc_path, FILENAME_MAX, "%s", lighters_path); + snprintf(proc_fail_path, FILENAME_MAX, "%s",lighters_fail_path); + snprintf(file_basename, FILENAME_MAX, "lighters"); + num_len = 4; + snprintf(file_ext, FILENAME_MAX, ".png"); + i = 1; + break; + default: + return; + } + + for (;; i++) { + if (snprintf(file_name, FILENAME_MAX, "%s%04i%s", + file_basename, + i, file_ext) >= FILENAME_MAX) { + goto err_path; + } + + memcpy(tmp, file_name, ARRAY_SIZE(file_name)); + if (alx_sscan_fname(proc_path, file_name, true, tmp)) + break; + + errno = 0; + img_iface_load(proc_path, file_name); + + if (errno) { + printf("errno:%i\n", errno); + goto err_load; + } + + /* Process */ + if (proc_iface_single(proc_mode)) { + /* Save failed image into file */ + proc_show_img(); + if (snprintf(save_error_as, FILENAME_MAX,"%s%0*i_err%s", + file_basename, num_len, i, + file_ext) >= FILENAME_MAX) { + goto err_path; + } + save_image_file(proc_fail_path, save_error_as); + } + + /* Show log */ + snprintf(txt, LOG_LINE_LEN, "%04i", i); + user_iface_show_log(txt, "Item"); + + if (proc_debug >= PROC_DBG_STOP_ITEM) + alx_wait4enter(); +err_load: + if (!i) + proc_mode--; + } + + return; + +err_path: + printf("Path is too large and has been truncated\n"); + exit(EXIT_FAILURE); +} + + +/****************************************************************************** + ******* static functions (definitions) *************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/proc/label.cpp b/src/proc/label.cpp new file mode 100644 index 0000000..5b5a3c7 --- /dev/null +++ b/src/proc/label.cpp @@ -0,0 +1,295 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "vision-artificial/proc/label.hpp" + +#include <cstdio> +#include <cstring> + +#include <opencv2/opencv.hpp> +#include <zbar.h> + +#include "libalx/base/stdlib/swap.hpp" + +#include "vision-artificial/image/iface.hpp" +#include "vision-artificial/proc/common.hpp" +#include "vision-artificial/user/iface.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ +/* Static --------------------------------------------------------------------*/ +static class std::vector <class std::vector <class cv::Point_ <int>>> contours; +static class cv::Mat hierarchy; +static class cv::RotatedRect rect; + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ +static void result_label (int status); + +static int label_find (void); +static void label_align (void); +static int find_cerdo (void); +static int barcode_read (void); +static int barcode_chk_prod(void); +static void price_read (void); +static int price_chk (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +int proc_label (void) +{ + int status; + + proc_save_mem(0); + + /* Find label (position and angle) */ + clock_start(); + status = label_find(); + if (status) { + result_label(status); + return status; + } + clock_stop("Find label"); + + /* Align label and extract green component */ + clock_start(); + label_align(); + clock_stop("Align label"); + + /* Find "Cerdo" in aligned image */ + clock_start(); + status = find_cerdo(); + if (status) { + result_label(status); + return status; + } + clock_stop("Find cerdo (OCR)"); + + /* Read barcode in original image */ + clock_start(); + status = barcode_read(); + if (status) { + result_label(status); + return status; + } + clock_stop("Read barcode (zbar)"); + + /* Check product code in barcode */ + clock_start(); + status = barcode_chk_prod(); + if (status) { + result_label(status); + return status; + } + clock_stop("Chk product code"); + + /* Read price in aligned image (green component) */ + clock_start(); + price_read(); + clock_stop("Read price (OCR)"); + + /* Check label price with barcode price */ + clock_start(); + status = price_chk(); + if (status) { + result_label(status); + return status; + } + clock_stop("Check price"); + + result_label(LABEL_OK); + return 0; +} + + +/****************************************************************************** + ******* static functions (definitions) *************************************** + ******************************************************************************/ +static void result_label (int status) +{ + + switch (status) { + case LABEL_OK: + user_iface_log_write(0, "Label: OK"); + break; + case LABEL_NOK_LABEL: + user_iface_log_write(0, "Label: NOK_LABEL"); + break; + case LABEL_NOK_CERDO: + user_iface_log_write(0, "Label: NOK_CERDO"); + break; + case LABEL_NOK_BCODE: + user_iface_log_write(0, "Label: NOK_BCODE"); + break; + case LABEL_NOK_PRODUCT: + user_iface_log_write(0, "Label: NOK_PRODUCT"); + break; + case LABEL_NOK_PRICE: + user_iface_log_write(0, "Label: NOK_PRICE"); + break; + default: + user_iface_log_write(0, "Label: NOK"); + break; + } +} + +static int label_find (void) +{ + + proc_load_mem(0); + + 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_not(); +#endif + proc_smooth(IMGI_SMOOTH_MEAN, 21); + proc_threshold(cv::THRESH_BINARY_INV, 2); + proc_dilate_erode(100); + proc_contours(&contours, &hierarchy); + + if (!contours.size()) + return LABEL_NOK_LABEL; + + 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) { + rect.angle += 90.0; + ALX_SWAP(&rect.size.width, &rect.size.height); + } + + return 0; +} + +static void label_align (void) +{ + proc_load_mem(0); + + proc_rotate(rect.center.x, rect.center.y, rect.angle); + proc_cmp(IMG_IFACE_CMP_GREEN); + proc_save_mem(1); +} + +static int find_cerdo (void) +{ + int x, y; + int w, h; + + proc_load_mem(1); + + x = rect.center.x - (1.05 * rect.size.width / 2); + if (x < 0) + x = 0; + y = rect.center.y - (1.47 * rect.size.height / 2); + if (y < 0) + y = 0; + w = rect.size.width / 2; + h = rect.size.height * 0.20; + proc_ROI(x, y, w, h); + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_erode(1); + proc_OCR(IMG_IFACE_OCR_LANG_ENG, IMG_IFACE_OCR_CONF_NONE); + + if (strncmp(img_ocr_text, "Cerdo", strlen("Cerdo"))) + return LABEL_NOK_CERDO; + return 0; +} + +static int barcode_read (void) +{ + + proc_load_mem(0); + + proc_cmp(IMG_IFACE_CMP_GREEN); + proc_zbar(zbar::ZBAR_EAN13); + if (zb_codes.n != 1) + return LABEL_NOK_BCODE; + return 0; +} + +static int barcode_chk_prod(void) +{ + + if (strncmp(zb_codes.arr[0].data, "2301703", strlen("2301703"))) + return LABEL_NOK_PRODUCT; + return LABEL_OK; +} + +static void price_read (void) +{ + int x, y; + int w, h; + + proc_load_mem(1); + + x = rect.center.x + (0.33 * rect.size.width / 2); + y = rect.center.y + (0.64 * rect.size.height / 2); + w = rect.size.width * 0.225; + h = rect.size.height * 0.15; + proc_ROI(x, y, w, h); + proc_smooth(IMGI_SMOOTH_MEAN, 3); + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_dilate_erode(1); + proc_threshold(cv::THRESH_BINARY, 1); + proc_OCR(IMG_IFACE_OCR_LANG_DIGITS, IMG_IFACE_OCR_CONF_PRICE); +} + +static int price_chk (void) +{ + char price[80]; + + /* Extract price from barcode */ + if (zb_codes.arr[0].data[8] != '0') { + snprintf(price, 80, "%c%c.%c%c", + zb_codes.arr[0].data[8], + zb_codes.arr[0].data[9], + zb_codes.arr[0].data[10], + zb_codes.arr[0].data[11]); + } else { + snprintf(price, 80, "%c.%c%c", + zb_codes.arr[0].data[9], + zb_codes.arr[0].data[10], + zb_codes.arr[0].data[11]); + } + + /* Compare price from barcode and from text */ + if (strncmp(img_ocr_text, price, strlen(price))) + return LABEL_NOK_PRICE; + return 0; +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/proc/lighters.cpp b/src/proc/lighters.cpp new file mode 100644 index 0000000..6eb9441 --- /dev/null +++ b/src/proc/lighters.cpp @@ -0,0 +1,426 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "vision-artificial/proc/lighters.hpp" + +#include <cstddef> +#include <cstdio> + +#include <opencv2/opencv.hpp> + +#include "libalx/base/stdlib/swap.hpp" + +#include "vision-artificial/image/iface.hpp" +#include "vision-artificial/proc/common.hpp" +#include "vision-artificial/user/iface.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Lighter_Hood { + HOOD_OK, + HOOD_NOT_PRESENT, + HOOD_NOT_OK +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ +struct Point { + uint16_t x; + uint16_t y; +}; + +struct Size { + uint16_t h; + uint16_t w; +}; + +struct Lighter_Properties { + struct Point pos; + struct Size size; + double angle; + + bool fork; + bool valve; + int hood_; + bool hood; + bool wheel; + + bool ok; +}; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ +/* Static --------------------------------------------------------------------*/ +static class std::vector <class std::vector <class cv::Point_ <int>>> contours_all; +static class std::vector <class std::vector <class cv::Point_ <int>>> contours_one; +static class cv::Mat hierarchy; +static class cv::RotatedRect rect_rot[CONTOURS_MAX]; +static class cv::Rect_ <int> rect; +static struct Lighter_Properties lighter[CONTOURS_MAX]; +static ptrdiff_t lighters_n; + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ +static void result_lighter (int status); + +static void lighters_bgr2gray (void); +static void lighters_segment_full (void); +static int lighters_find (void); +static void lighter_segment_body (int i); +static void lighter_rm_body (int i); +static void lighter_crop_head (int i); +static void lighter_chk_hood (int i); +static void lighter_rm_hood (void); +static void lighter_chk_fork (int i); +static void lighter_chk_wheel (int i); +static void lighter_chk_valve (int i); +static void lighters_log (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +int proc_lighter (void) +{ + + proc_save_mem(0); + /* Segment lighters */ + clock_start(); + lighters_bgr2gray(); + lighters_segment_full(); + lighters_find(); + clock_stop("Segment lighters"); + + /* Check each lighter */ + for (ptrdiff_t i = 0; i < lighters_n; i++) { + clock_start(); + lighter[i].ok = true; + lighter_segment_body(i); + lighter_rm_body(i); + lighter_crop_head(i); + lighter_chk_hood(i); + if (lighter[i].hood_ != HOOD_NOT_PRESENT) { + lighter_rm_hood(); + } else { + proc_load_mem(7); + proc_save_mem(8); + } + lighter_chk_fork(i); + lighter_chk_wheel(i); + lighter_chk_valve(i); + clock_stop("Check parts"); + } + + /* Print results of lighters into log */ + clock_start(); + lighters_log(); + clock_stop("Lighters properties (log)"); + + result_lighter(LIGHTER_OK); + return 0; +} + + +/****************************************************************************** + ******* static functions (definitions) *************************************** + ******************************************************************************/ +static void result_lighter (int status) +{ + + switch (status) { + case LIGHTER_OK: + user_iface_log_write(0, "Coin: OK"); + break; + case LIGHTER_NOK_LIGHTER: + user_iface_log_write(0, "Coin: NOK_LIGHTER"); + break; + + case LIGHTER_NOK_SIZE: + user_iface_log_write(0, "Coin: NOK_SIZE"); + break; + default: + user_iface_log_write(0, "Coin: NOK"); + } +} + +/* process -------------------------------------------------------------------*/ +static void lighters_bgr2gray (void) +{ + + proc_load_mem(0); + + proc_cvt_color(cv::COLOR_BGR2GRAY); + proc_not(); + proc_save_mem(1); + + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_border(100); + proc_save_mem(3); + + proc_load_mem(1); + proc_border(100); + proc_save_mem(2); +} + +static void lighters_segment_full (void) +{ + + proc_load_mem(3); + proc_erode_dilate(1); + proc_dilate_erode(2); + proc_save_mem(4); +} + +static int lighters_find (void) +{ + + proc_load_mem(4); + proc_contours(&contours_all, &hierarchy); + lighters_n = contours_all.size(); + if (!lighters_n) + return LIGHTER_NOK_LIGHTER; + + for (ptrdiff_t i = 0; i < lighters_n; i++) { + proc_min_area_rect(&contours_all[i], &rect_rot[i], true); + /* If width > height, + * it is taking into acount the incorrect side */ + if (rect_rot[i].size.width > rect_rot[i].size.height) { + rect_rot[i].angle += 90.0; + ALX_SWAP(&rect_rot[i].size.width, + &rect_rot[i].size.height); + } + lighter[i].pos.x = rect_rot[i].center.x; + lighter[i].pos.y = rect_rot[i].center.y; + lighter[i].angle = -rect_rot[i].angle; + lighter[i].size.h = rect_rot[i].size.height; + lighter[i].size.w = rect_rot[i].size.width; + } + + return 0; +} + +static void lighter_segment_body (int i) +{ + int x, y; + int w, h; + + proc_load_mem(2); + + proc_rotate(lighter[i].pos.x, lighter[i].pos.y, -lighter[i].angle); + w = lighter[i].size.w * 1.25; + h = lighter[i].size.h * 1.25; + x = lighter[i].pos.x - (w / 2.0); + y = lighter[i].pos.y - (h / 2.0); + proc_ROI(x, y, w, h); + proc_threshold(cv::THRESH_BINARY, UINT8_MAX - 165); + + proc_erode_dilate(1); + proc_dilate_erode(1); + proc_erode_dilate(lighter[i].size.w * 0.43); + proc_save_mem(5); + + proc_contours(&contours_one, &hierarchy); + proc_bounding_rect(&contours_one[0], &rect, true); +} + +static void lighter_rm_body (int i) +{ + int x, y; + int w, h; + + proc_load_mem(5); + proc_not(); + proc_erode(5); + proc_save_ref(); + + proc_load_mem(3); + proc_rotate(lighter[i].pos.x, lighter[i].pos.y, -lighter[i].angle); + w = lighter[i].size.w * 1.25; + h = lighter[i].size.h * 1.25; + x = lighter[i].pos.x - (w / 2.0); + y = lighter[i].pos.y - (h / 2.0); + proc_ROI(x, y, w, h); + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_and_2ref(); + proc_save_mem(6); +} + +static void lighter_crop_head (int i) +{ + int x, y; + int w, h; + + proc_load_mem(6); + + w = rect.width * 1.15; + h = rect.width * 0.65; + x = rect.x - rect.width * 0.075; + y = rect.y - rect.width * 0.65; + proc_ROI(x, y, w, h); + rect.x = x; + rect.y = y; + rect.width = w; + rect.height = h; + lighter[i].size.w = w; + lighter[i].size.h = h; + proc_save_mem(7); +} + +static void lighter_chk_hood (int i) +{ + uint8_t val1; + uint8_t val2; + proc_load_mem(7); + + proc_pixel_get(rect.width * 0.2, rect.height * 0.3, &val1); + proc_pixel_set(rect.width * 0.2, rect.height * 0.3, UINT8_MAX / 2); + proc_save_mem(9); + + if (val1) { + proc_pixel_get(rect.width *0.2, rect.height *0.8, &val2); + proc_pixel_set(rect.width *0.2, rect.height *0.8, UINT8_MAX /2); + if (val2) { + lighter[i].hood_ = HOOD_OK; + lighter[i].hood = true; + } else { + lighter[i].hood_ = HOOD_NOT_OK; + lighter[i].hood = false; + lighter[i].ok = false; + } + } else { + lighter[i].hood_ = HOOD_NOT_PRESENT; + lighter[i].hood = false; + lighter[i].ok = false; + } +} + +static void lighter_rm_hood (void) +{ + + proc_load_mem(7); + proc_border(2); + proc_save_ref(); + + proc_dilate_erode(2); + proc_erode_dilate(rect.height * 0.25); + proc_dilate(2); + proc_not(); + proc_and_2ref(); + proc_save_mem(8); +} + +static void lighter_chk_fork (int i) +{ + uint8_t val; + + proc_load_mem(8); + + proc_dilate_erode(2); + proc_pixel_get(rect.width * 0.8, rect.height * 0.8, &val); + proc_pixel_set(rect.width * 0.8, rect.height * 0.8, UINT8_MAX / 2); + proc_save_mem(10); + + if (val) { + lighter[i].fork = true; + } else { + lighter[i].fork = false; + lighter[i].ok = false; + } +} + +static void lighter_chk_wheel (int i) +{ + uint8_t val; + + proc_load_mem(8); + + proc_dilate(5); + proc_pixel_get(rect.width * 0.58, rect.height * 0.19, &val); + proc_pixel_set(rect.width * 0.58, rect.height * 0.19, UINT8_MAX / 2); + proc_save_mem(11); + + if (val) { + lighter[i].wheel = true; + } else { + lighter[i].wheel = false; + lighter[i].ok = false; + } +} + +static void lighter_chk_valve (int i) +{ + uint8_t val; + + proc_load_mem(8); + + if (lighter[i].hood_ == HOOD_NOT_PRESENT) + proc_dilate(5); + else + proc_dilate(10); + proc_pixel_get(rect.width * 0.07, rect.height * 0.92, &val); + proc_pixel_set(rect.width * 0.07, rect.height * 0.92, UINT8_MAX / 2); + proc_save_mem(12); + + if (val) { + lighter[i].valve = true; + } else { + lighter[i].valve = false; + lighter[i].ok = false; + } +} + +static void lighters_log (void) +{ + char txt[LOG_LINE_LEN]; + + for (ptrdiff_t i = 0; i < lighters_n; i++) { + snprintf(txt, LOG_LINE_LEN, "Lighter[%ti]:", i); + user_iface_log_write(0, txt); + snprintf(txt, LOG_LINE_LEN, " pos: (%i, %i) pix", + lighter[i].pos.x, lighter[i].pos.y); + user_iface_log_write(0, txt); + snprintf(txt, LOG_LINE_LEN, " ang = %.1lf DEG", + lighter[i].angle); + user_iface_log_write(0, txt); + snprintf(txt, LOG_LINE_LEN, " hood = %s", + lighter[i].hood ? "ok" : "nok"); + user_iface_log_write(0, txt); + snprintf(txt, LOG_LINE_LEN, " fork = %s", + lighter[i].fork ? "ok" : "nok"); + user_iface_log_write(0, txt); + snprintf(txt, LOG_LINE_LEN, " wheel = %s", + lighter[i].wheel ? "ok" : "nok"); + user_iface_log_write(0, txt); + snprintf(txt, LOG_LINE_LEN, " valve = %s", + lighter[i].valve ? "ok" : "nok"); + user_iface_log_write(0, txt); + snprintf(txt, LOG_LINE_LEN, " RESULT = %s", + lighter[i].ok ? "OK" : "NOK"); + user_iface_log_write(0, txt); + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/proc/objects.cpp b/src/proc/objects.cpp new file mode 100644 index 0000000..dd00820 --- /dev/null +++ b/src/proc/objects.cpp @@ -0,0 +1,550 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "vision-artificial/proc/objects.hpp" + +#include <cstddef> +#include <cstdio> + +#include <opencv2/opencv.hpp> + +#include "libalx/base/math/median.hpp" + +#include "vision-artificial/image/iface.hpp" +#include "vision-artificial/proc/common.hpp" +#include "vision-artificial/user/iface.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +#define OBJECTS_MAX (0xFFF) +#define PATTERN_SQUARE_LEN_MM (10.0) + +#define PATTERN_DILATE (2) + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ +struct Point { + uint16_t x_pix; + uint16_t y_pix; + + double x_mm; + double y_mm; +}; + +struct Pattern_Square { + struct Point pos; + uint8_t len; +}; + +struct Pattern_Properties { + struct Point center; + struct Point origin; + + double angle; + + uint16_t height; + uint16_t width; + + /* Squares (distance calibration) */ + struct Pattern_Square square[OBJECTS_MAX]; +}; + +struct Objects_Properties { + struct Point pos; + + double angle; + + double area_pix2; + double area_mm2; + double perimeter_pix; + double perimeter_mm; + + double ratio_p2_a; + double area_rect; + double ratio_a_arect; + double perimeter_rect; + double ratio_p_prect; +}; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ +/* Static --------------------------------------------------------------------*/ +static class std::vector <class std::vector <class cv::Point_ <int>>> contours; +static class cv::Mat hierarchy; +static class cv::RotatedRect rect_rot[OBJECTS_MAX]; +static class cv::Rect_ <int> rect[OBJECTS_MAX]; +static struct Pattern_Properties pattern; +static ptrdiff_t squares_n; +static double ratio_mm_pix; +static ptrdiff_t objects_n; +static struct Objects_Properties objects[OBJECTS_MAX]; + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ +static void result_objects (int status); + +static void pattern_bgr2gray (void); +static int pattern_find (void); +static void pattern_rotation_get (void); +static void pattern_rotation_fix (void); +static void pattern_dimensions_get (void); +static void pattern_dimensions_fix (void); +static void pattern_squares_find (void); +static void pattern_squares_pos_get (void); +static void pattern_squares_len_get (void); +static void pattern_calib_mm_pix (void); + +static void objects_bgr2gray (void); +static void objects_rotation_fix (void); +static void objects_dimensions_fix (void); +static void objects_segment (void); +static int objects_contours (void); +static void objects_position_pix (void); +static void objects_size_pix (void); +static void objects_shape (void); +static void objects_position_mm (void); +static void objects_size_mm (void); +static void objects_log (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +int proc_objects_calibrate (void) +{ + int status; + + proc_save_mem(0); + /* Calibrate angle with the whole pattern */ + clock_start(); + pattern_bgr2gray(); + status = pattern_find(); + if (status) { + result_objects(status); + return status; + } + pattern_rotation_get(); + pattern_rotation_fix(); + clock_stop("Calibrate: rotation"); + + /* Segmentate pattern squares */ + clock_start(); + pattern_dimensions_get(); + pattern_dimensions_fix(); + clock_stop("Calibrate: dimensions"); + + /* Find squares */ + clock_start(); + pattern_squares_find(); + pattern_squares_pos_get(); + pattern_squares_len_get(); + pattern_calib_mm_pix(); + clock_stop("Calibrate (mm per pix)"); + + result_objects(OBJECTS_OK); + return 0; +} + +int proc_objects (void) +{ + int status; + + proc_save_mem(0); + /* Align image */ + clock_start(); + objects_bgr2gray(); + objects_rotation_fix(); + objects_dimensions_fix(); + clock_stop("Align image to pattern"); + + /* Segment objects */ + clock_start(); + objects_segment(); + clock_stop("Segment objects"); + + /* Find objects positions */ + clock_start(); + status = objects_contours(); + if (status) { + result_objects(status); + return status; + } + clock_stop("Find objects"); + + /* Get objects properties in pixels */ + clock_start(); + objects_position_pix(); + objects_position_mm(); + clock_stop("Objects positions"); + + /* Get objects properties in mm */ + clock_start(); + objects_size_pix(); + objects_size_mm(); + clock_stop("Objects sizes"); + + /* Get objects properties in mm */ + clock_start(); + objects_shape(); + clock_stop("Objects shapes"); + + /* Print properties of objects into log */ + clock_start(); + objects_log(); + clock_stop("Objects properties (log)"); + + result_objects(OBJECTS_OK); + return 0; +} + + +/****************************************************************************** + ******* static functions (definitions) *************************************** + ******************************************************************************/ +static void result_objects (int status) +{ + + switch (status) { + case OBJECTS_OK: + user_iface_log_write(0, "Coin: OK"); + break; + case OBJECTS_NOK_OBJECTS: + user_iface_log_write(0, "Coin: NOK_OBJECTS"); + break; + + case OBJECTS_NOK_SIZE: + user_iface_log_write(0, "Coin: NOK_SIZE"); + break; + default: + user_iface_log_write(0, "Coin: NOK"); + } +} + +/* calibration ---------------------------------------------------------------*/ +static void pattern_bgr2gray (void) +{ + + proc_load_mem(0); + + proc_cvt_color(cv::COLOR_BGR2GRAY); + proc_save_mem(1); +} + +static int pattern_find (void) +{ + + proc_load_mem(1); + + proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU); + proc_erode_dilate(16); + proc_dilate(2); + proc_contours(&contours, &hierarchy); + if (contours.size() != 1) + return OBJECTS_NOK_PATTERN; + + return 0; +} + +static void pattern_rotation_get (void) +{ + char txt[LOG_LINE_LEN]; + + proc_min_area_rect(&(contours[0]), &(rect_rot[0]), true); + + /* If angle is < -45º, it is taking into account the incorrect side */ + if (rect_rot[0].angle < -45.0) + rect_rot[0].angle += 90.0; + pattern.angle = rect_rot[0].angle; + pattern.center.x_pix = rect_rot[0].center.x; + pattern.center.y_pix = rect_rot[0].center.y; + + snprintf(txt, LOG_LINE_LEN, "pattern angle = %lf DEG", + -pattern.angle); + user_iface_log_write(0, txt); + snprintf(txt, LOG_LINE_LEN, "pattern center (x) = %i pix", + pattern.center.x_pix); + user_iface_log_write(0, txt); + snprintf(txt, LOG_LINE_LEN, "pattern center (y) = %i pix", + pattern.center.y_pix); + user_iface_log_write(0, txt); +} + +static void pattern_rotation_fix (void) +{ + + proc_load_mem(1); + + /* invert image before rotation to avoid black bands */ + proc_not(); + proc_rotate(pattern.center.x_pix, pattern.center.y_pix, pattern.angle); + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_save_mem(2); +} + +static void pattern_dimensions_get (void) +{ + + proc_load_mem(2); + + proc_erode_dilate(16); + proc_dilate(PATTERN_DILATE); + proc_contours(&contours, &hierarchy); + proc_bounding_rect(&(contours[0]), &(rect[0]), true); +} + +static void pattern_dimensions_fix (void) +{ + + /* Need to correct also pattern dilatation (pattern_dimensions_get()) */ + pattern.origin.x_pix = rect[0].x; + pattern.origin.y_pix = rect[0].y; + pattern.width = rect[0].width; + pattern.height = rect[0].height; + + proc_load_mem(2); + proc_ROI(pattern.origin.x_pix, pattern.origin.y_pix, + pattern.width, pattern.height); + proc_save_mem(3); +} + +static void pattern_squares_find (void) +{ + + proc_load_mem(3); + + proc_distance_transform(); + proc_local_max(); + proc_dilate(6); + proc_save_mem(4); + + proc_contours(&contours, &hierarchy); + squares_n = contours.size(); +} + +static void pattern_squares_pos_get (void) +{ + + for (ptrdiff_t i = 0; i < squares_n; i++) { + proc_bounding_rect(&(contours[i]), &(rect[i]), true); + pattern.square[i].pos.x_pix = rect[i].x + rect[i].width/2.0; + pattern.square[i].pos.y_pix = rect[i].y + rect[i].height/2.0; + } +} + +static void pattern_squares_len_get (void) +{ + + proc_load_mem(4); + for (ptrdiff_t i = 0; i < squares_n; i++) { + proc_pixel_get(pattern.square[i].pos.x_pix, + pattern.square[i].pos.y_pix, + &(pattern.square[i].len)); + pattern.square[i].len *= 2; + } +} + +static void pattern_calib_mm_pix (void) +{ + uint8_t pattern_len[OBJECTS_MAX]; + uint8_t median_size; + char txt[LOG_LINE_LEN]; + + for (ptrdiff_t i = 0; i < squares_n; i++) + pattern_len[i] = pattern.square[i].len; + median_size = alx_median_u8(squares_n, pattern_len); + ratio_mm_pix = PATTERN_SQUARE_LEN_MM / median_size; + + snprintf(txt, LOG_LINE_LEN, "mm/pix = %lf", ratio_mm_pix); + user_iface_log_write(0, txt); +} + +/* process -------------------------------------------------------------------*/ +static void objects_bgr2gray (void) +{ + + proc_load_mem(0); + + proc_cvt_color(cv::COLOR_BGR2GRAY); + proc_save_mem(1); +} + +static void objects_rotation_fix (void) +{ + + proc_load_mem(1); + + /* invert image before rotation to avoid black bands */ + proc_not(); + proc_rotate(pattern.center.x_pix, pattern.center.y_pix, pattern.angle); + proc_save_mem(2); +} + +static void objects_dimensions_fix (void) +{ + + /* Need to correct also pattern dilatation (pattern_dimensions_get()) */ + proc_load_mem(2); + + proc_ROI(pattern.origin.x_pix, pattern.origin.y_pix, + pattern.width, pattern.height); + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_save_mem(3); +} + +static void objects_segment (void) +{ + + proc_load_mem(3); + + proc_dilate_erode(3); + proc_erode_dilate(3); + proc_save_mem(4); + + proc_distance_transform(); + proc_threshold(cv::THRESH_BINARY_INV, 30); + proc_distance_transform(); + proc_skeleton(); + proc_threshold(cv::THRESH_BINARY_INV, 10); + proc_save_ref(); + proc_save_mem(5); + + proc_load_mem(3); + proc_and_2ref(); + proc_distance_transform(); + proc_threshold(cv::THRESH_BINARY, 10); + proc_save_mem(6); +} + +static int objects_contours (void) +{ + + proc_load_mem(6); + + proc_contours(&contours, &hierarchy); + objects_n = contours.size(); + if (!objects_n) + return OBJECTS_NOK_OBJECTS; + + return 0; +} + +static void objects_position_pix (void) +{ + + for (ptrdiff_t i = 0; i < objects_n; i++) { + proc_fit_ellipse(&(contours[i]), &(rect_rot[i]), true); + objects[i].pos.x_pix = rect_rot[i].center.x; + objects[i].pos.y_pix = rect_rot[i].center.y; + objects[i].angle = -rect_rot[i].angle + 90.0; + if (objects[i].angle < 0) + objects[i].angle += 180.0; + } +} + +static void objects_position_mm (void) +{ + + for (ptrdiff_t i = 0; i < objects_n; i++) { + objects[i].pos.x_mm = ratio_mm_pix * objects[i].pos.x_pix; + objects[i].pos.y_mm = ratio_mm_pix * objects[i].pos.y_pix; + } +} + +static void objects_size_pix (void) +{ + double area[OBJECTS_MAX]; + double perimeter[OBJECTS_MAX]; + + proc_contours_size(&contours, area, perimeter); + for (ptrdiff_t i = 0; i < objects_n; i++) { + objects[i].area_pix2 = area[i]; + objects[i].perimeter_pix = perimeter[i]; + } +} + +static void objects_size_mm (void) +{ + + for (ptrdiff_t i = 0; i < objects_n; i++) { + objects[i].area_mm2 = pow(ratio_mm_pix, 2) * + objects[i].area_pix2; + objects[i].perimeter_mm = ratio_mm_pix * + objects[i].perimeter_pix; + } +} + +static void objects_shape (void) +{ + + for (ptrdiff_t i = 0; i < objects_n; i++) { + proc_min_area_rect(&(contours[i]), &(rect_rot[i]), true); + + objects[i].ratio_p2_a = pow(objects[i].perimeter_pix, 2) / + objects[i].area_pix2; + objects[i].area_rect = rect_rot[i].size.width * + rect_rot[i].size.height; + objects[i].perimeter_rect = 2.0 * (rect_rot[i].size.width + + rect_rot[i].size.height); + objects[i].ratio_p_prect = objects[i].perimeter_pix / + objects[i].perimeter_rect; + objects[i].ratio_a_arect = objects[i].area_pix2 / + objects[i].area_rect; + } +} + +static void objects_log (void) +{ + char txt[LOG_LINE_LEN]; + + for (ptrdiff_t i = 0; i < objects_n; i++) { + snprintf(txt, LOG_LINE_LEN, "Object[%ti]:", i); + user_iface_log_write(0, txt); + snprintf(txt, LOG_LINE_LEN, " pos: (%.1lf, %.1lf) mm", + objects[i].pos.x_mm, + objects[i].pos.y_mm); + user_iface_log_write(0, txt); + snprintf(txt, LOG_LINE_LEN, " ang = %.1lf DEG", + objects[i].angle); + user_iface_log_write(0, txt); + snprintf(txt, LOG_LINE_LEN, " A = %.1lf mm2", + objects[i].area_mm2); + user_iface_log_write(0, txt); + snprintf(txt, LOG_LINE_LEN, " P = %.1lf mm", + objects[i].perimeter_mm); + user_iface_log_write(0, txt); + snprintf(txt, LOG_LINE_LEN, " p2/A = %.2lf", + objects[i].ratio_p2_a); + user_iface_log_write(0, txt); + snprintf(txt, LOG_LINE_LEN, " p/p_r = %.2lf", + objects[i].ratio_p_prect); + user_iface_log_write(0, txt); + snprintf(txt, LOG_LINE_LEN, " A/A_r = %.2lf", + objects[i].ratio_a_arect); + user_iface_log_write(0, txt); + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/proc/resistor.cpp b/src/proc/resistor.cpp new file mode 100644 index 0000000..5c370e7 --- /dev/null +++ b/src/proc/resistor.cpp @@ -0,0 +1,1279 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "vision-artificial/proc/resistor.hpp" + +#include <cmath> +#include <cstdio> +#include <cstring> + +#include <opencv2/opencv.hpp> + +#include "libalx/base/stddef/size.hpp" + +#include "vision-artificial/image/iface.hpp" +#include "vision-artificial/proc/common.hpp" +#include "vision-artificial/user/iface.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ +struct Resistor_Bands { + int x; + int y; + + unsigned char h; + unsigned char s; + unsigned char v; +}; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ +/* Static --------------------------------------------------------------------*/ +static class std::vector <class std::vector <class cv::Point_ <int>>> contours; +static class cv::Mat hierarchy; +static class cv::RotatedRect rect_rot; +static class cv::Rect_ <int> rect; +static int bkgd; +static int bands_n; +static struct Resistor_Bands bands[5]; +static char code[6]; +static int base; +static float resistance; +static int tolerance; + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ +static void result_resistor (int status); + +static int resistor_find (void); +static void resistor_align (void); +static void resistor_dimensions_0 (void); +static void resistor_crop_0 (void); +static void resistor_bkgd (void); +static void resistor_dimensions_1 (void); +static void resistor_crop_1 (void); +static void separate_bkgd_bands_h (void); +static void separate_bkgd_bands_s (void); +static void separate_bkgd_bands_v (void); +static void bkgd_find (void); +static int bands_find (void); +static void bands_colors (void); +static void bands_code (void); +static char band_hsv2code (struct Resistor_Bands *band); +static void bands_code_deduce_0 (void); +static void bands_code_deduce_1 (void); +static int bands_code_deduce_no (void); +static void resistor_value (void); +static int resistor_tolerance (void); +static void log_resistance (void); +static int chk_std_value (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +int proc_resistor (void) +{ + int status; + + proc_save_mem(0); + /* Find resistor (position and angle) */ + clock_start(); + status = resistor_find(); + if (status) { + result_resistor(status); + return status; + } + clock_stop("Find resistor"); + + /* Align resistor, find its dimensions, and crop */ + clock_start(); + resistor_align(); + resistor_dimensions_0(); + resistor_crop_0(); + clock_stop("Align, dimensions, & crop"); + + /* Find backgroung color */ + clock_start(); + resistor_bkgd(); + clock_stop("Background color"); + + /* Crop more */ + clock_start(); + resistor_dimensions_1(); + resistor_crop_1(); + clock_stop("Crop more"); + + /* Separate background (BK) and lines (WH) */ + clock_start(); + separate_bkgd_bands_h(); + separate_bkgd_bands_s(); + separate_bkgd_bands_v(); + bkgd_find(); + clock_stop("Separate bkgd from bands"); + + /* Find bands: contours -> rectangles */ + clock_start(); + status = bands_find(); + if (status) { + result_resistor(status); + return status; + } + clock_stop("Find bands"); + + /* Read values on the center of each band */ + clock_start(); + bands_colors(); + clock_stop("Bands' colors"); + + /* Interpret colors */ + clock_start(); + bands_code(); + bands_code_deduce_0(); + bands_code_deduce_1(); + status = bands_code_deduce_no(); + if (status) { + result_resistor(status); + return status; + } + clock_stop("Interpret colors"); + + /* Calculate resistor value & tolerance */ + clock_start(); + resistor_value(); + status = resistor_tolerance(); + if (status) { + result_resistor(status); + return status; + } + log_resistance(); + clock_stop("Calculate resistance & tolerance"); + + /* Check STD value */ + clock_start(); + status = chk_std_value(); + if (status) { + result_resistor(status); + return status; + } + clock_stop("Chk STD values"); + + result_resistor(status); + return 0; +} + + +/****************************************************************************** + ******* static functions (definitions) *************************************** + ******************************************************************************/ +static void result_resistor (int status) +{ + + switch (status) { + case RESISTOR_OK: + user_iface_log_write(0, "Resistor: OK"); + break; + case RESISTOR_NOK_RESISTOR: + user_iface_log_write(0, "Resistor: NOK_RESISTOR"); + break; + case RESISTOR_NOK_BANDS: + user_iface_log_write(0, "Resistor: NOK_BANDS"); + break; + case RESISTOR_NOK_COLOR: + user_iface_log_write(0, "Resistor: NOK_COLOR"); + break; + case RESISTOR_NOK_STD_VALUE: + user_iface_log_write(0, "Resistor: NOK_STD_VALUE"); + break; + case RESISTOR_NOK_TOLERANCE: + user_iface_log_write(0, "Resistor: NOK_TOLERANCE"); + break; + default: + user_iface_log_write(0, "Resistor: NOK"); + break; + } +} + +static int resistor_find (void) +{ + + proc_load_mem(0); + + /* BGR -> HSV */ + proc_cvt_color(cv::COLOR_BGR2HSV); + proc_save_mem(19); + + proc_cmp(IMG_IFACE_CMP_SATURATION); + proc_smooth(IMGI_SMOOTH_MEDIAN, 7); + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_save_mem(1); + proc_dilate_erode(10); + proc_contours(&contours, &hierarchy); + if (!contours.size()) + return RESISTOR_NOK_RESISTOR; + + proc_min_area_rect(&contours[0], &rect_rot, true); + /* If angle is < -45º, it is taking into acount the incorrect side */ + if (rect_rot.angle < -45.0) + rect_rot.angle += 90.0; + + return 0; +} + +static void resistor_align (void) +{ + + proc_load_mem(19); + proc_rotate(rect_rot.center.x, rect_rot.center.y, rect_rot.angle); + proc_save_mem(2); + proc_load_mem(1); + proc_rotate(rect_rot.center.x, rect_rot.center.y, rect_rot.angle); + proc_save_mem(3); +} + +static void resistor_dimensions_0 (void) +{ + + proc_load_mem(3); + + proc_dilate_erode(10); + proc_contours(&contours, &hierarchy); + proc_bounding_rect(&(contours[0]), &rect, true); +} + +static void resistor_crop_0 (void) +{ + int x, y; + int w, h; + + proc_load_mem(2); + + w = rect.width; + h = rect.height; + x = rect.x; + y = rect.y; + proc_ROI(x, y, w, h); + proc_save_mem(4); +} + +static void resistor_bkgd (void) +{ + uint8_t bkgd_hue; + uint8_t bkgd_sat; + + /* hue */ + proc_load_mem(4); + proc_cmp(IMG_IFACE_CMP_HUE); + proc_median_vertical(); + proc_median_horizontal(); + proc_pixel_get(0, 0, &bkgd_hue); + + /* saturation */ + proc_load_mem(4); + proc_cmp(IMG_IFACE_CMP_SATURATION); + proc_median_vertical(); + proc_median_horizontal(); + proc_pixel_get(0, 0, &bkgd_sat); + + if (bkgd_hue < 50) { + /* Beige */ + bkgd = 0; + } else { + /* Blue */ + if ((bkgd_hue < 90) || (bkgd_sat < 100)) + bkgd = 1; /* Teal blue */ + else if (bkgd_hue >= 105) + bkgd = 2; /* Dark blue */ + else + bkgd = 3; /* Normal blue */ + } +} + +static void resistor_dimensions_1 (void) +{ + + proc_load_mem(3); + + proc_dilate_erode(10); + proc_erode_dilate((rect.height * 0.67) / 2); + proc_contours(&contours, &hierarchy); + proc_bounding_rect(&contours[0], &rect, true); +} + +static void resistor_crop_1 (void) +{ + int x; + int y; + int w; + int h; + + proc_load_mem(2); + + w = rect.width * 0.95; + h = rect.height * 0.8; + x = rect.x + w * (1.0 - 0.95) / 2.0; + y = rect.y + h * (1.0 - 0.8) / 2.0; + proc_ROI(x, y, w, h); + proc_save_mem(4); +} + +static void separate_bkgd_bands_h (void) +{ + + proc_load_mem(4); + + proc_cmp(IMG_IFACE_CMP_HUE); + proc_median_vertical(); + proc_save_mem(9); + + switch (bkgd) { + case 0: + proc_threshold(cv::THRESH_TOZERO_INV, 20); + proc_threshold(cv::THRESH_TOZERO, 5); + break; + case 1: + proc_threshold(cv::THRESH_TOZERO_INV, 100); + proc_threshold(cv::THRESH_TOZERO, 70); + break; + case 2: + proc_threshold(cv::THRESH_TOZERO_INV, 115); + proc_threshold(cv::THRESH_TOZERO, 100); + break; + case 3: + proc_threshold(cv::THRESH_TOZERO_INV, 110); + proc_threshold(cv::THRESH_TOZERO, 90); + break; + } + proc_threshold(cv::THRESH_BINARY_INV, 1); + proc_save_mem(5); +} + +static void separate_bkgd_bands_s (void) +{ + + proc_load_mem(4); + + proc_cmp(IMG_IFACE_CMP_SATURATION); + proc_median_vertical(); + proc_save_mem(10); + + switch (bkgd) { + case 0: + proc_threshold(cv::THRESH_TOZERO_INV, 160); + proc_threshold(cv::THRESH_TOZERO, 110); + break; + case 1: + proc_threshold(cv::THRESH_TOZERO_INV, 180); + proc_threshold(cv::THRESH_TOZERO, 30); + break; + case 2: + proc_threshold(cv::THRESH_TOZERO_INV, 190); + proc_threshold(cv::THRESH_TOZERO, 170); + break; + case 3: + proc_threshold(cv::THRESH_TOZERO_INV, 210); + proc_threshold(cv::THRESH_TOZERO, 120); + break; + } + proc_threshold(cv::THRESH_BINARY_INV, 1); + proc_save_mem(6); +} + +static void separate_bkgd_bands_v (void) +{ + + proc_load_mem(4); + + proc_cmp(IMG_IFACE_CMP_VALUE); + proc_median_vertical(); + proc_save_mem(11); + + switch (bkgd) { + case 0: + proc_threshold(cv::THRESH_TOZERO_INV, 170); + proc_threshold(cv::THRESH_TOZERO, 100); + break; + + case 1: + proc_threshold(cv::THRESH_TOZERO_INV, 180); + proc_threshold(cv::THRESH_TOZERO, 100); + break; + case 2: + proc_threshold(cv::THRESH_TOZERO_INV, 180); + proc_threshold(cv::THRESH_TOZERO, 150); + break; + case 3: + proc_threshold(cv::THRESH_TOZERO_INV, 190); + proc_threshold(cv::THRESH_TOZERO, 90); + break; + } + proc_threshold(cv::THRESH_BINARY_INV, 1); + proc_save_mem(7); +} + +static void bkgd_find (void) +{ + + /* Merge the components: H | S | V */ + proc_load_mem(7); + proc_save_ref(); + proc_load_mem(6); + proc_or_2ref(); + proc_save_ref(); + proc_load_mem(5); + proc_or_2ref(); + if (rect.width * 0.95 > 80) { + proc_dilate_erode(1); + } + proc_save_mem(8); +} + +static int bands_find (void) +{ + + proc_load_mem(8); + + proc_contours(&contours, &hierarchy); + bands_n = contours.size(); + if (bands_n > 5) { + proc_load_mem(8); + proc_dilate_erode(1); + proc_contours(&contours, &hierarchy); + bands_n = contours.size(); + } + if ((bands_n == 0) || (bands_n == 2) || (bands_n > 5)) + return RESISTOR_NOK_BANDS; + + /* Band 0 (hundreds) */ + if (bands_n == 5) { + proc_bounding_rect(&contours[4], &rect, true); + bands[0].x = rect.x + rect.width / 2.0; + bands[0].y = rect.y + rect.height / 2.0; + } + + /* Band 1 (tens) */ + if (bands_n >= 3) { + if (bands_n > 3) + proc_bounding_rect(&contours[3], &rect, true); + else + proc_bounding_rect(&contours[2], &rect, true); + bands[1].x = rect.x + rect.width / 2.0; + bands[1].y = rect.y + rect.height / 2.0; + } + + /* Band 2 (units) */ + if (bands_n > 3) + proc_bounding_rect(&contours[2], &rect, true); + else if (bands_n == 3) + proc_bounding_rect(&contours[1], &rect, true); + else /* bands_n == 1 */ + proc_bounding_rect(&contours[0], &rect, true); + bands[2].x = rect.x + rect.width / 2.0; + bands[2].y = rect.y + rect.height / 2.0; + + /* Band 3 (multiplier) */ + if (bands_n >= 3) { + if (bands_n > 3) + proc_bounding_rect(&contours[1], &rect, true); + else + proc_bounding_rect(&contours[0], &rect, true); + bands[3].x = rect.x + rect.width / 2.0; + bands[3].y = rect.y + rect.height / 2.0; + } + + /* Band 4 (tolerance) */ + if (bands_n > 3) { + proc_bounding_rect(&contours[0], &rect, true); + bands[4].x = rect.x + rect.width / 2.0; + bands[4].y = rect.y + rect.height / 2.0; + } + + return 0; +} + +static void bands_colors (void) +{ + + /* Hue */ + proc_load_mem(9); + if (bands_n == 5) + proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].h)); + if (bands_n >= 3) + proc_pixel_get(bands[1].x, bands[1].y, &(bands[1].h)); + proc_pixel_get(bands[2].x, bands[2].y, &(bands[2].h)); + if (bands_n >= 3) + proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].h)); + if (bands_n > 3) + proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].h)); + + /* Saturation */ + proc_load_mem(10); + if (bands_n == 5) + proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].s)); + if (bands_n >= 3) + proc_pixel_get(bands[1].x, bands[1].y, &(bands[1].s)); + proc_pixel_get(bands[2].x, bands[2].y, &(bands[2].s)); + if (bands_n >= 3) + proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].s)); + if (bands_n > 3) + proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].s)); + + /* Value */ + proc_load_mem(11); + if (bands_n == 5) + proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].v)); + if (bands_n >= 3) + proc_pixel_get(bands[1].x, bands[1].y, &(bands[1].v)); + proc_pixel_get(bands[2].x, bands[2].y, &(bands[2].v)); + if (bands_n >= 3) + proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].v)); + if (bands_n > 3) + proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].v)); +} + +static void bands_code (void) +{ + char txt[LOG_LINE_LEN]; + + memset(code, 0, ARRAY_SIZE(code)); + + /* Band 0 (hundreds) */ + if (bands_n == 5) + code[0] = band_hsv2code(&bands[0]); + else + code[0] = 'n'; + + /* Band 1 (tens) */ + if (bands_n != 1) + code[1] = band_hsv2code(&bands[1]); + else + code[1] = 'n'; + + /* Band 2 (units) */ + code[2] = band_hsv2code(&bands[2]); + + /* Band 3 (multiplier) */ + if (bands_n != 1) + code[3] = band_hsv2code(&bands[3]); + else + code[3] = 'n'; + + /* Band 4 (tolerance) */ + if (bands_n > 3) + code[4] = band_hsv2code(&bands[4]); + else + code[4] = 'n'; + + snprintf(txt, LOG_LINE_LEN, "Code: \"%s\"", code); + user_iface_log_write(0, txt); +} + +static char band_hsv2code (struct Resistor_Bands *band) +{ + char c; + + /* + * Not able to segmentate: + * q = 1 2 + * w = 2 3 + * e = 3 g + * r = 3 4 + * t = 1 8 + * y = 0 1 + * u = 0 1 8 + */ + + if (band->h < 10) { + // 1 2 3 + if (band->s < 90) { + // 1 3 + if (band->v < 85) + c = '1'; + else + c = '3'; + } else if (band->s < 140) { + // 1 2 3 + if (band->v < 60) + c = '1'; + else if (band->v < 85) + c = 'q'; // 1 2 + else if (band->v < 90) + c = '2'; + else if (band->v < 150) + c = 'w'; // 2 3 + else + c = '3'; + } else if (band->s < 210) { + // 2 3 + if (band->v < 90) + c = '2'; + else if (band->v < 150) + c = 'w'; // 2 3 + else + c = '3'; + } else { + c = '3'; + } + } else if (band->h < 35) { + // 1 3 g + if (band->s < 130) { + // 1 3 + if (band->v < 85) + c = '1'; + else + c = '3'; + } else if (band->s < 140) { + // 1 3 g + if (band->v < 85) + c = '1'; + else if (band->v < 120) + c = '3'; + else + c = 'e'; // 3 g + } else if (band->s < 180) { + // 3 g + if (band->v < 120) + c = '3'; + else + c = 'e'; // 3 g + } else { + c = '3'; + } + } else if (band->h < 50) { + // 1 3 + if (band->s < 140) { + // 1 3 + if (band->v < 85) + c = '1'; + else + c = '3'; + } else { + c = '3'; + } + } else if (band->h < 60) { + // 1 3 4 + if (band->s < 140) { + // 1 3 + if (band->v < 85) + c = '1'; + else + c = '3'; + } else if (band->s < 160) { + c = '3'; + } else if (band->s < 180) { + // 3 4 + if (band->v < 110) + c = 'r'; // 3 4 + else + c = '3'; + } else { + c = '3'; + } + } else if (band->h < 80) { + // 1 5 + if (band->s < 165) + c = '1'; + else + c = '5'; + } else if (band->h < 90) { + c = '1'; + } else if (band->h < 100) { + // 0 1 8 9 + if (band->s < 40) { + // 1 8 9 + if (band->v < 55) + c = '1'; + else if (band->v < 80) + c = 't'; // 1 8 + else if (band->v < 125) + c = '1'; + else + c = '9'; + } else if (band->s < 70) { + // 0 1 8 9 + if (band->v < 45) + c = '0'; + else if (band->v < 55) + c = 'y'; // 0 1 + else if (band->v < 75) + c = 'u'; // 0 1 8 + else if (band->v < 80) + c = 't'; // 1 8 + else if (band->v < 125) + c = '1'; + else + c = '9'; + } else if (band->s < 100) { + // 0 1 8 + if (band->v < 45) + c = '0'; + else if (band->v < 55) + c = 'y'; // 0 1 + else if (band->v < 75) + c = 'u'; // 0 1 8 + else if (band->v < 80) + c = 't'; // 1 8 + else + c = '1'; + } else if (band->s < 140) { + // 0 1 + if (band->v < 45) + c = '0'; + else if (band->v < 75) + c = 'y'; // 0 1 + else + c = '1'; + } else { + c = '0'; + } + } else if (band->h < 110) { + // 0 1 6 8 + if (band->s < 40) { + // 1 8 + if (band->v < 55) + c = '1'; + else if (band->v < 80) + c = 't'; // 1 8 + else + c = '1'; + } else if (band->s < 100) { + // 0 1 8 + if (band->v < 45) + c = '0'; + else if (band->v < 55) + c = 'y'; // 0 1 + else if (band->v < 75) + c = 'u'; // 0 1 8 + else if (band->v < 80) + c = 't'; // 1 8 + else + c = '1'; + } else if (band->s < 140) { + // 0 1 + if (band->v < 45) + c = '0'; + else if (band->v < 75) + c = 'y'; // 0 1 + else + c = '1'; + } else if (band->s < 200) { + c = '0'; + } else { + c = '6'; + } + } else if (band->h < 120) { + // 0 1 6 7 + if (band->s < 40) { + c = '1'; + } else if (band->s < 90) { + // 0 1 + if (band->v < 45) + c = '0'; + else if (band->v < 75) + c = 'y'; // 0 1 + else + c = '1'; + } else if (band->s < 110) { + // 0 1 7 + if (band->v < 45) + c = '0'; + else if (band->v < 75) + c = 'y'; // 0 1 + else if (band->v < 120) + c = '1'; + else + c = '7'; + } else if (band->s < 140) { + // 0 1 + if (band->v < 45) + c = '0'; + else if (band->v < 75) + c = 'y'; // 0 1 + else + c = '1'; + } else if (band->s < 200) { + c = '0'; + } else { + c = '6'; + } + } else if (band->h < 130) { + // 0 1 7 + if (band->s < 40) { + c = '1'; + } else if (band->s < 90) { + // 0 1 + if (band->v < 45) + c = '0'; + else if (band->v < 75) + c = 'y'; // 0 1 + else + c = '1'; + } else if (band->s < 110) { + // 0 1 7 + if (band->v < 45) + c = '0'; + else if (band->v < 75) + c = 'y'; // 0 1 + else if (band->v < 120) + c = '1'; + else + c = '7'; + } else if (band->s < 140) { + // 0 1 + if (band->v < 45) + c = '0'; + else if (band->v < 75) + c = 'y'; // 0 1 + else + c = '1'; + } else { + c = '0'; + } + } else if (band->h < 140) { + // 0 1 + if (band->s < 40) { + c = '1'; + } else if (band->s < 140) { + // 0 1 + if (band->v < 45) + c = '0'; + else if (band->v < 75) + c = 'y'; // 0 1 + else + c = '1'; + } else { + c = '0'; + } + } else if (band->h < 150) { + c = '0'; + } else { + c = '2'; + } + + return c; +} + +static void bands_code_deduce_0 (void) +{ + char txt[LOG_LINE_LEN]; + + /* + * Not able to segmentate: + * q = 1 2 + * w = 2 3 + * e = 3 g + * r = 3 4 + * t = 1 8 + * y = 0 1 + * u = 0 1 8 + */ + + /* Band 0 (hundreds) */ + switch (code[0]) { + case 'e': + code[0] = '3'; + break; + case 'y': + code[0] = '1'; + break; + case 'u': + code[0] = 't'; + break; + } + + /* Band 2 (units) */ + switch (code[2]) { + case 'e': + code[2] = '3'; + break; + } + + /* Band 3 (multiplier) */ + switch (code[3]) { + case 't': + code[3] = '1'; + break; + case 'u': + code[3] = 'y'; + break; + } + + /* Band 4 (tolerance) */ + switch (code[4]) { + case 'w': + code[4] = '2'; + break; + case 'e': + code[4] = 'g'; + break; + case 't': + code[4] = '1'; + break; + case 'y': + code[4] = '1'; + break; + case 'u': + code[4] = '1'; + break; + } + + snprintf(txt, LOG_LINE_LEN, "Code: \"%s\"", code); + user_iface_log_write(0, txt); +} + +static void bands_code_deduce_1 (void) +{ + char txt[LOG_LINE_LEN]; + + /* + * Not able to segmentate: + * q = 1 2 + * w = 2 3 + * e = 3 g + * r = 3 4 + * t = 1 8 + * y = 0 1 + * u = 0 1 8 + */ + + /* Band 0 (hundreds) */ + switch (code[0]) { + case 'q': + switch (code[1]) { + case '1': + case '3': + case '5': + case '6': + case '8': + code[0] = '1'; + break; + case '2': + case '4': + case '7': + code[0] = '2'; + break; + case '0': + // q + break; + } + break; + case 'w': + switch (code[1]) { + case '2': + case '4': + case '7': + code[0] = '2'; + break; + case '3': + case '6': + case '9': + code[0] = '3'; + break; + case '0': + // w + break; + } + break; + case 'r': + switch (code[1]) { + case '0': + case '6': + case '9': + code[0] = '3'; + break; + case '7': + code[0] = '4'; + break; + case '3': + // r + break; + } + break; + case 't': + switch (code[1]) { + case '0': + case '1': + case '3': + case '5': + case '6': + case '8': + code[0] = '1'; + break; + case '2': + // t + break; + } + break; + } + + /* Band 1 (tens) */ + switch (code[1]) { + case 'q': + switch (code[0]) { + case '5': + case '9': + code[1] = '1'; + break; + case '2': + case '6': + case '8': + code[1] = '2'; + break; + case '1': + // q + break; + } + break; + case 'w': + switch (code[0]) { + case '2': + case '6': + case '8': + code[1] = '2'; + break; + case '3': + case '4': + code[1] = '3'; + break; + case '1': + // w + break; + } + break; + case 't': + switch (code[0]) { + case '5': + case '9': + code[1] = '1'; + break; + case '6': + code[1] = '8'; + break; + case '1': + // t + break; + } + break; + case 'y': + switch (code[0]) { + case '2': + case '3': + code[1] = '0'; + break; + case '5': + case '9': + code[1] = '1'; + break; + case '1': + // y + break; + } + break; + case 'u': + switch (code[0]) { + case '2': + case '3': + code[1] = '0'; + break; + case '5': + case '9': + code[1] = '1'; + break; + case '6': + code[1] = '8'; + break; + case '1': + // u + break; + } + break; + } + + /* Band 2 (units) */ + switch (code[2]) { + case 'y': + code[2] = '0'; + break; + case 'u': + code[2] = '0'; + break; + } + + /* Band 3 (multiplier) */ + switch (code[3]) { + case 'y': + code[3] = '0'; + break; + } + + /* Band 4 (tolerance) */ + switch (code[4]) { + case 'q': + code[4] = '2'; + break; + } + + snprintf(txt, LOG_LINE_LEN, "Code: \"%s\"", code); + user_iface_log_write(0, txt); +} + +static int bands_code_deduce_no (void) +{ + char txt[LOG_LINE_LEN]; + + /* + * Not able to segmentate: + * q = 1 2 + * w = 2 3 + * e = 3 g + * r = 3 4 + * t = 1 8 + * y = 0 1 + * u = 0 1 8 + */ + + for (ptrdiff_t i = 0; i < 5; i++) { + switch (code[i]) { + case 'q': + case 'w': + case 'e': + case 'r': + case 't': + case 'y': + case 'u': + code[i] = '?'; + } + } + + for (ptrdiff_t i = 0; i < 5; i++) { + if (code[i] == '?') + return RESISTOR_NOK_COLOR; + } + + snprintf(txt, LOG_LINE_LEN, "Code: \"%s\"", code); + user_iface_log_write(0, txt); + + return 0; +} + +static void resistor_value (void) +{ + int power; + + /* Base value */ + base = code[2] - '0'; + if (code[1] != 'n') + base += (code[1] - '0') * 10; + if (code[0] != 'n') + base += (code[0] - '0') * 100; + + /* Calculate resistance */ + if ((code[3] > '0') && (code[3] < '9')) + power = code[3] - '0'; + else if (code[3] == 'g') + power = -1; + else if (code[3] == 's') + power = -2; + else + return; + + resistance = base * pow(10, power); +} + +static int resistor_tolerance (void) +{ + + if (bands_n != 1) { + switch (code[4]) { + case '1': + tolerance = 1; + break; + case '2': + tolerance = 2; + break; + case '4': + case 'g': + case 'n': + tolerance = 5; + break; + case '8': + tolerance = 10; + break; + default: + return RESISTOR_NOK_TOLERANCE; + } + } + + return 0; +} + +static void log_resistance (void) +{ + char txt[LOG_LINE_LEN]; + + if (bands_n != 1) { + snprintf(txt, LOG_LINE_LEN,"Resistance: %.2E ± %i%% Ohm", + resistance, tolerance); + user_iface_log_write(0, txt); + } else { + user_iface_log_write(0, "Resistance: 0 Ohm"); + } +} + +static int chk_std_value (void) +{ + /* Check that base value is a standard value */ + int std_values_10 [12] = {10,12,15,18,22,27,33,39,47,56,68,82}; + int std_values_5 [12] = {11,13,16,20,24,30,36,43,51,62,75,91}; + + if (bands_n == 1) { + if (base) + return RESISTOR_NOK_STD_VALUE; + return 0; + } + + for (ptrdiff_t i = 0; i < 12; i++) { + if (base == std_values_10[i]) + return 0; + if (base == (std_values_10[i] * 10)) + return 0; + } + if (tolerance <= 5) { + for (ptrdiff_t i = 0; i < 12; i++) { + if (base == std_values_5[i]) + return 0; + if (base == (std_values_5[i] * 10)) + return 0; + } + } + + return RESISTOR_NOK_STD_VALUE; +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/save/save.cpp b/src/save/save.cpp new file mode 100644 index 0000000..cbe039d --- /dev/null +++ b/src/save/save.cpp @@ -0,0 +1,280 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "vision-artificial/save/save.hpp" + +#include <cerrno> +#include <cstdio> +#include <cstdlib> + +#include <sys/stat.h> + +#include <opencv2/opencv.hpp> + +#include "libalx/base/errno/errno_str.hpp" +#include "libalx/base/stddef/restrict.hpp" + +#include "vision-artificial/user/iface.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + class cv::Mat image; + char home_path[FILENAME_MAX]; + char user_prog_path[FILENAME_MAX]; + char saved_path[FILENAME_MAX]; + char labels_path[FILENAME_MAX]; + char labels_fail_path[FILENAME_MAX]; + char lighters_path[FILENAME_MAX]; + char lighters_fail_path[FILENAME_MAX]; + char objects_path[FILENAME_MAX]; + char objects_fail_path[FILENAME_MAX]; + char coins_path[FILENAME_MAX]; + char coins_fail_path[FILENAME_MAX]; + char resistors_path[FILENAME_MAX]; + char resistors_fail_path[FILENAME_MAX]; + char saved_name[FILENAME_MAX]; + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void save_init (void) +{ + + if (snprintf(home_path, FILENAME_MAX, "%s/", + getenv(ENV_HOME)) >= FILENAME_MAX) { + goto err; + } + if (snprintf(user_prog_path, FILENAME_MAX, "%s/%s/", + home_path, + USER_PROG_DIR) >= FILENAME_MAX) { + goto err; + } + if (snprintf(saved_path, FILENAME_MAX, "%s/%s/", + home_path, + USER_SAVED_DIR) >= FILENAME_MAX) { + goto err; + } + if (snprintf(labels_path, FILENAME_MAX, "%s/%s/", + home_path, + USER_LABELS_DIR) >= FILENAME_MAX) { + goto err; + } + if (snprintf(labels_fail_path, FILENAME_MAX, "%s/%s/", + home_path, + USER_LABELS_FAIL_DIR) >= FILENAME_MAX) { + goto err; + } + if (snprintf(lighters_path, FILENAME_MAX, "%s/%s/", + home_path, + USER_LIGHTERS_DIR) >= FILENAME_MAX) { + goto err; + } + if (snprintf(lighters_fail_path, FILENAME_MAX, "%s/%s/", + home_path, + USER_LIGHTERS_FAIL_DIR) >= FILENAME_MAX) { + goto err; + } + if (snprintf(objects_path, FILENAME_MAX, "%s/%s/", + home_path, + USER_OBJECTS_DIR) >= FILENAME_MAX) { + goto err; + } + if (snprintf(objects_fail_path, FILENAME_MAX, "%s/%s/", + home_path, + USER_OBJECTS_FAIL_DIR) >= FILENAME_MAX) { + goto err; + } + if (snprintf(coins_path, FILENAME_MAX, "%s/%s/", + home_path, + USER_COINS_DIR) >= FILENAME_MAX) { + goto err; + } + if (snprintf(coins_fail_path, FILENAME_MAX, "%s/%s/", + home_path, + USER_COINS_FAIL_DIR) >= FILENAME_MAX) { + goto err; + } + if (snprintf(resistors_path, FILENAME_MAX, "%s/%s/", + home_path, + USER_RESISTORS_DIR) >= FILENAME_MAX) { + goto err; + } + if (snprintf(resistors_fail_path, FILENAME_MAX, "%s/%s/", + home_path, + USER_RESISTORS_FAIL_DIR) >= FILENAME_MAX) { + goto err; + } + saved_name[0] = '\0'; + + if (mkdir(user_prog_path, 0700)) { + switch (errno) { + case EEXIST: + /* OK */ + break; + default: + printf("%s: %s\n", errno_str[errno][0], + errno_str[errno][1]); + } + } + + mkdir(saved_path, 0700); + mkdir(labels_path, 0700); + mkdir(labels_fail_path, 0700); + + return; +err: + printf("Path is too large and has been truncated\n"); +} + +void save_reset_fpath(void) +{ + + if (snprintf(saved_path, FILENAME_MAX, "%s/%s/", + home_path, + USER_SAVED_DIR) >= FILENAME_MAX) { + goto err; + } + + return; +err: + printf("Path is too large and has been truncated\n"); +} + +void load_image_file (const char *restrict fpath, + const char *restrict fname) +{ + char file_path[FILENAME_MAX]; + char file_name[FILENAME_MAX]; + + image.release(); + + /* Set file_path */ + if (!fpath) { + /* Default path */ + save_reset_fpath(); + snprintf(file_path, FILENAME_MAX, "%s", saved_path); + } else { + snprintf(file_path, FILENAME_MAX, "%s", fpath); + } + + /* Set file_name */ + if (!fname) + user_iface_fname(file_path, saved_name); + else + snprintf(saved_name, FILENAME_MAX, "%s", fname); + + /* File name */ + if (snprintf(file_name, FILENAME_MAX, "%s/%s", + file_path, + saved_name) >= FILENAME_MAX) { + goto err_path; + } + + image = cv::imread(file_name, CV_LOAD_IMAGE_COLOR); + if (image.empty()) + goto err_img; + + return; +err_img: + printf("Could not load file: %s\n", file_name); + return; +err_path: + printf("Path is too large and has been truncated\n"); +} + +void save_cleanup (void) +{ + + image.release(); +} + +void save_image_file (const char *restrict fpath, + const char *restrict save_as) +{ + char file_path[FILENAME_MAX]; + char file_name[FILENAME_MAX]; + FILE *fp; + + /* Set file_path */ + if (!fpath) { + /* Default path */ + save_reset_fpath(); + snprintf(file_path, FILENAME_MAX, "%s", saved_path); + } else { + snprintf(file_path, FILENAME_MAX, "%s", fpath); + } + + /* Set file_name */ + if (!save_as) { + snprintf(saved_name, FILENAME_MAX, "%s", SAVED_NAME_DEFAULT); + user_iface_fname(saved_path, saved_name); + } else { + snprintf(saved_name, FILENAME_MAX, "%s", save_as); + } + + /* Prepend the path */ + if (snprintf(file_name, FILENAME_MAX, "%s/%s", + file_path, + saved_name) >= FILENAME_MAX) { + goto err_path; + } + + fp = fopen(file_name, "r"); + if (fp) { + /* Name in use; ask once more */ + fclose(fp); + user_iface_fname(saved_path, saved_name); + if (snprintf(file_name, FILENAME_MAX, "%s/%s", + file_path, + saved_name) >= FILENAME_MAX) { + goto err_path; + } + } + + user_iface_log_write(2, saved_name); + + cv::imwrite(file_name, image); + + return; +err_path: + printf("Path is too large and has been truncated\n"); +} + + +/****************************************************************************** + ******* static functions (definitions) *************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/user/clui.c b/src/user/clui.c new file mode 100644 index 0000000..8c3c7ec --- /dev/null +++ b/src/user/clui.c @@ -0,0 +1,471 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "vision-artificial/user/clui.h" + +#include <stdio.h> +#include <string.h> + +#include "libalx/base/stddef/size.h" +#include "libalx/base/stdio/get.h" +#include "libalx/base/stdio/wait.h" + +#include "vision-artificial/image/iface.h" +#include "vision-artificial/user/iface.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +#define BUFF_SIZE (0xFFF) + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ +/* Static --------------------------------------------------------------------*/ + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ +static void log_loop (void); +static int usr_input (void); +static void show_help (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +int user_clui (const char *restrict title, + const char *restrict subtitle) +{ + + show_help(); + user_clui_show_log(title, subtitle); + return usr_input(); +} + +void user_clui_fname (const char *restrict fpath, + char *restrict fname) +{ + + alx_get_fname(fpath, fname, false, "File name:", "Valid extensions: .bmp .dib .jpeg .png .pbm .pgm .ppm .tiff", + 2); +} + +void user_clui_show_log (const char *restrict title, + const char *restrict subtitle) +{ + + printf("________________________________________________________________________________\n"); + log_loop(); + printf("%s - %s\n", subtitle, title); + printf("--------------------------------------------------------------------------------\n"); + +} + +void user_clui_show_ocr (void) +{ + + printf("%s", img_ocr_text); + alx_wait4enter(); +} + + +/****************************************************************************** + ******* static functions (definitions) *************************************** + ******************************************************************************/ +static void log_loop (void) +{ + const char *txt; + + putchar('\n'); + for (;;) { + txt = user_iface_log_read(); + if (!txt) + break; + for (int i = 0; i < user_iface_log.lvl[user_iface_log.pos]; i++) + printf("\t"); + printf("%s\n", txt); + } + printf("\n"); +} + +static int usr_input (void) +{ + char buff[BUFF_SIZE]; + char ch [10]; + + memset(ch, 0, ARRAY_SIZE(ch)); + buff[0] = '\0'; + + if (!fgets(buff, BUFF_SIZE, stdin)) + goto err_fgets; + if (sscanf(buff, " %5c", ch) <= 0) + goto err_sscanf; + + switch (ch[0]) { + case '+': + return USER_IFACE_ACT_APPLY; + case '-': + return USER_IFACE_ACT_DISCARD; + case 'e': + /* Exercises from class */ + switch (ch[1]) { + case '1': + /* Label */ + switch (ch[2]) { + case '1': + return USER_IFACE_ACT_PROC_LABEL_SERIES; + } + break; + case '2': + /* Objects */ + switch (ch[2]) { + case '0': + return USER_IFACE_ACT_PROC_OBJECTS_CALIB; + case '1': + return USER_IFACE_ACT_PROC_OBJECTS_SERIES; + } + break; + case '3': + /* Coins */ + switch (ch[2]) { + case '1': + return USER_IFACE_ACT_PROC_COINS_SERIES; + } + break; + case '4': + /* Resistor */ + switch (ch[2]) { + case '1': + return USER_IFACE_ACT_PROC_RESISTOR_SERIES; + } + break; + case '5': + /* Lighters */ + switch (ch[2]) { + case '1': + return USER_IFACE_ACT_PROC_LIGHTERS_SERIES; + } + break; + } + break; + + case 'f': + /* Use simple funtions */ + switch (ch[1]) { + case '0': + /* img_alx */ + switch (ch[2]) { + case '0': + /* Distance transform postprocessing */ + switch (ch[3]) { + case '0': + return USER_IFACE_ACT_LOCAL_MAX; + case '1': + return USER_IFACE_ACT_SKELETON; + } + break; + case '1': + /* Lines */ + switch (ch[3]) { + case '0': + return USER_IFACE_ACT_LINES_HORIZONTAL; + case '1': + return USER_IFACE_ACT_LINES_VERTICAL; + } + break; + case '2': + /* Smooth */ + switch (ch[3]) { + case '0': + return USER_IFACE_ACT_MEAN_HORIZONTAL; + case '1': + return USER_IFACE_ACT_MEAN_VERTICAL; + case '2': + return USER_IFACE_ACT_MEDIAN_HORIZONTAL; + case '3': + return USER_IFACE_ACT_MEDIAN_VERTICAL; + } + break; + } + break; + case '1': + /* img_cv */ + switch (ch[2]) { + case '0': + /* Core: The core functionality */ + switch (ch[3]) { + case '0': + /* Pixel */ + switch (ch[4]) { + case '0': + return USER_IFACE_ACT_PIXEL_GET; + case '1': + return USER_IFACE_ACT_PIXEL_SET; + } + break; + case '1': + /* ROI */ + switch (ch[4]) { + case '0': + return USER_IFACE_ACT_SET_ROI; + case '1': + return USER_IFACE_ACT_SET_ROI_2RECT; + } + break; + case '2': + /* Operations on Arrays */ + switch (ch[4]) { + case '0': + return USER_IFACE_ACT_AND_2REF; + case '1': + return USER_IFACE_ACT_NOT; + case '2': + return USER_IFACE_ACT_OR_2REF; + case '3': + return USER_IFACE_ACT_COMPONENT; + } + break; + } + break; + case '1': + /* Imgproc: Image processing */ + switch (ch[3]) { + case '0': + /* Image filtering */ + switch (ch[4]) { + case '0': + return USER_IFACE_ACT_DILATE; + case '1': + return USER_IFACE_ACT_ERODE; + case '2': + return USER_IFACE_ACT_DILATE_ERODE; + case '3': + return USER_IFACE_ACT_ERODE_DILATE; + case '4': + return USER_IFACE_ACT_SMOOTH; + case '5': + return USER_IFACE_ACT_SOBEL; + case '6': + return USER_IFACE_ACT_BORDER; + } + break; + case '1': + /* Geometric image transformations */ + switch (ch[4]) { + case '0': + return USER_IFACE_ACT_MIRROR; + case '1': + return USER_IFACE_ACT_ROTATE_ORTO; + case '2': + return USER_IFACE_ACT_ROTATE; + case '3': + return USER_IFACE_ACT_ROTATE_2RECT; + } + break; + case '2': + /* Miscellaneous image transformations */ + switch (ch[4]) { + case '0': + return USER_IFACE_ACT_ADAPTIVE_THRESHOLD; + case '1': + return USER_IFACE_ACT_CVT_COLOR; + case '2': + return USER_IFACE_ACT_DISTANCE_TRANSFORM; + case '3': + return USER_IFACE_ACT_THRESHOLD; + } + break; + case '3': + /* Histograms */ + switch (ch[4]) { + case '0': + return USER_IFACE_ACT_HISTOGRAM; + case '1': + return USER_IFACE_ACT_HISTOGRAM_C3; + } + break; + case '4': + /* Structural analysis and shape descriptors */ + switch (ch[4]) { + case '0': + return USER_IFACE_ACT_CONTOURS; + case '1': + return USER_IFACE_ACT_CONTOURS_SIZE; + case '2': + return USER_IFACE_ACT_BOUNDING_RECT; + case '3': + return USER_IFACE_ACT_FIT_ELLIPSE; + case '4': + return USER_IFACE_ACT_MIN_AREA_RECT; + } + break; + case '5': + /* Feature detection */ + switch (ch[4]) { + case '0': + return USER_IFACE_ACT_HOUGH_CIRCLES; + } + break; + } + break; + } + break; + case '2': + /* img_orb */ + switch (ch[2]) { + case '0': + return USER_IFACE_ACT_ALIGN; + } + break; + case '3': + /* img_calib3d */ + switch (ch[2]) { + case '0': + return USER_IFACE_ACT_CALIBRATE; + case '1': + return USER_IFACE_ACT_UNDISTORT; + } + break; + case '4': + /* img_zbar */ + switch (ch[2]) { + case '0': + return USER_IFACE_ACT_DECODE; + } + break; + case '5': + /* img_ocr */ + switch (ch[2]) { + case '0': + return USER_IFACE_ACT_READ; + } + break; + } + break; + case 'l': + return USER_IFACE_ACT_LOAD_MEM; + case 'm': + return USER_IFACE_ACT_SAVE_MEM; + case 'q': + return USER_IFACE_ACT_QUIT; + case 'r': + return USER_IFACE_ACT_SAVE_REF; + case 's': + return USER_IFACE_ACT_SAVE_FILE; + case 'u': + /* User iface actions */ + switch (ch[1]) { + case '1': + return USER_IFACE_ACT_SHOW_OCR; + } + break; + case 'x': + /* Special sequence "xyzzy" */ + if (ch[1] == 'y') { + if (ch[2] == 'z') { + if (ch[3] == 'z') { + if (ch[4] == 'y') { + return USER_IFACE_ACT_FOO; + } + } + } + } + break; + } + +err_fgets: +err_sscanf: + return USER_IFACE_ACT_FOO; +} + +static void show_help (void) +{ + + printf("Apply: %s\n", "Space"); + printf("Discard: %s\n", "Backspace"); + printf("Save to mem: %c\n", 'm'); + printf("Load from mem: %c\n", 'l'); + printf("Save to ref: %c\n", 'r'); + printf("Save to file: %c\n", 's'); + printf("Functions:\n"); + printf(" - Local maxima: %s\n", "f000"); + printf(" - Skeleton: %s\n", "f001"); + printf(" - Horizontal lines: %s\n", "f010"); + printf(" - Vertical lines: %s\n", "f011"); + printf(" - Horizontal mean: %s\n", "f020"); + printf(" - Vertical mean: %s\n", "f021"); + printf(" - Horizontal median: %s\n", "f022"); + printf(" - Vertical median: %s\n", "f023"); + printf(" - Pixel get: %s\n", "f1000"); + printf(" - Pixel set: %s\n", "f1001"); + printf(" - Set ROI: %s\n", "f1010"); + printf(" - Set ROI 2rect: %s\n", "f1011"); + printf(" - Bitwise AND 2ref: %s\n", "f1020"); + printf(" - Bitwise NOT: %s\n", "f1021"); + printf(" - Bitwise OR 2ref: %s\n", "f1022"); + printf(" - Component: %s\n", "f1023"); + printf(" - Dilate: %s\n", "f1100"); + printf(" - Erode: %s\n", "f1101"); + printf(" - D-E: %s\n", "f1102"); + printf(" - E-D: %s\n", "f1103"); + printf(" - Smooth: %s\n", "f1104"); + printf(" - Sobel: %s\n", "f1105"); + printf(" - Border: %s\n", "f1106"); + printf(" - Mirror: %s\n", "f1110"); + printf(" - Rotate ortogonally: %s\n", "f1111"); + printf(" - Rotate: %s\n", "f1112"); + printf(" - Rotate 2rect_rot: %s\n", "f1113"); + printf(" - Adaptive threshold: %s\n", "f1120"); + printf(" - Cvt color: %s\n", "f1121"); + printf(" - Distance transform: %s\n", "f1122"); + printf(" - Threshold: %s\n", "f1123"); + printf(" - Histogram: %s\n", "f1130"); + printf(" - Histogram (3 chan): %s\n", "f1131"); + printf(" - Contours: %s\n", "f1140"); + printf(" - Contours size: %s\n", "f1141"); + printf(" - Bounding rectangle: %s\n", "f1142"); + printf(" - Fit ellipse: %s\n", "f1143"); + printf(" - Min. area rectangle: %s\n", "f1144"); + printf(" - Hough circles: %s\n", "f1150"); + printf(" - Align 2ref (ORB): %s\n", "f20"); + printf(" - Calibrate (Calib3d): %s\n", "f30"); + printf(" - Undistort (Calib3d): %s\n", "f31"); + printf(" - Scan codes (ZBAR): %s\n", "f40"); + printf(" - Scan text (OCR): %s\n", "f50"); + printf("Exercises:\n"); + printf(" - Label: %s\n", "e11"); + printf(" - Objects (calib): %s\n", "e20"); + printf(" - Objects: %s\n", "e21"); + printf(" - Coins: %s\n", "e31"); + printf(" - Resistor: %s\n", "e41"); + printf(" - Lighters: %s\n", "e51"); + printf("Other:\n"); + printf(" - Show OCR text: %s\n", "u1"); + printf("Quit: %c\n", 'q'); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/user/iface.c b/src/user/iface.c new file mode 100644 index 0000000..75da415 --- /dev/null +++ b/src/user/iface.c @@ -0,0 +1,234 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "vision-artificial/user/iface.h" + +#include <stddef.h> +#include <stdint.h> +#include <stdio.h> + +#include "libalx/base/stdio/get.h" + +#include "vision-artificial/image/iface.h" +#include "vision-artificial/proc/iface.h" +#include "vision-artificial/user/clui.h" +#include "vision-artificial/user/tui.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +#define TITLE_SIZE (80) + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ + int user_iface_mode; + struct User_Iface_Log user_iface_log; +/* Static --------------------------------------------------------------------*/ + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ +static void user_iface_act (int action); +static void user_iface_show_ocr (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void user_iface_init (void) +{ + + user_iface_log.len = 0; + user_iface_log.pos = -1; + + switch (user_iface_mode) { + case USER_IFACE_CLUI: + break; + case USER_IFACE_TUI: + user_tui_init(); + break; + } +} + +void user_iface_cleanup (void) +{ + + switch (user_iface_mode) { + case USER_IFACE_CLUI: + break; + case USER_IFACE_TUI: + user_tui_cleanup(); + break; + } + fflush(stdout); +} + +void user_iface (void) +{ + char title[TITLE_SIZE]; + char subtitle[TITLE_SIZE]; + int user_action; + + snprintf(title, TITLE_SIZE, "Title"); + snprintf(subtitle, TITLE_SIZE, "Subtitle"); + + do { + img_iface_show_img(); + + switch (user_iface_mode) { + case USER_IFACE_CLUI: + user_action = user_clui(title, subtitle); + break; + case USER_IFACE_TUI: + user_action = user_tui(title, subtitle); + break; + default: + user_action = USER_IFACE_ACT_FOO; + } + user_iface_act(user_action); + } while (user_action != USER_IFACE_ACT_QUIT); +} + +void user_iface_show_log (const char *restrict title, + const char *restrict subtitle) +{ + + switch (user_iface_mode) { + case USER_IFACE_CLUI: + user_clui_show_log(title, subtitle); + break; + case USER_IFACE_TUI: + user_tui_show_log(title, subtitle); + break; + } +} + +void user_iface_fname (const char *restrict filepath, + char *restrict filename) +{ + + switch (user_iface_mode) { + case USER_IFACE_CLUI: + user_clui_fname(filepath, filename); + break; + case USER_IFACE_TUI: + user_tui_fname(filepath, filename); + break; + } +} + +double user_iface_getdbl (double m, double def, double M, + const char *restrict title, + const char *restrict help) +{ + + switch (user_iface_mode) { + case USER_IFACE_CLUI: + return alx_get_int(m, def, M, title, help, 2); + case USER_IFACE_TUI: + return user_tui_getint(m, def, M, title, help); + default: + return 1; + } +} + +int user_iface_getint (double m, int64_t def, double M, + const char *restrict title, + const char *restrict help) +{ + + switch (user_iface_mode) { + case USER_IFACE_CLUI: + return alx_get_dbl(m, def, M, title, help, 2); + case USER_IFACE_TUI: + return user_tui_getdbl(m, def, M, title, help); + default: + return 1.0; + } +} + +void user_iface_log_write (ptrdiff_t lvl, const char *restrict msg) +{ + + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "%s", + msg); + user_iface_log.lvl[user_iface_log.len] = lvl; + user_iface_log.len++; +} + +const char *user_iface_log_read (void) +{ + + user_iface_log.pos++; + for (; user_iface_log.pos < user_iface_log.len; user_iface_log.pos++) { + if (user_iface_log.lvl[user_iface_log.pos] <= + user_iface_log.visible) { + break; + } + } + if (user_iface_log.pos == user_iface_log.len) + return NULL; + return &user_iface_log.line[user_iface_log.pos][0]; +} + + +/****************************************************************************** + ******* static functions (definitions) *************************************** + ******************************************************************************/ +static void user_iface_act (int action) +{ + + if (action & USER_IFACE_ACT_USRI) { + switch (action) { + case USER_IFACE_ACT_SHOW_OCR: + user_iface_show_ocr(); + break; + case USER_IFACE_ACT_QUIT: + /* do nothing */ + break; + } + } else if (action & USER_IFACE_ACT_PROC) { + proc_iface_single(action); + } else { + img_iface_act(action, NULL); + } +} + +static void user_iface_show_ocr (void) +{ + + switch (user_iface_mode) { + case USER_IFACE_CLUI: + user_clui_show_ocr(); + break; + case USER_IFACE_TUI: + user_tui_show_ocr(); + break; + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/user/tui.c b/src/user/tui.c new file mode 100644 index 0000000..bad2574 --- /dev/null +++ b/src/user/tui.c @@ -0,0 +1,611 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "vision-artificial/user/tui.h" + +#include <inttypes.h> +#include <ncurses.h> + +#include "libalx/base/stdio/wait.h" +#include "libalx/extra/ncurses/common.h" +#include "libalx/extra/ncurses/get.h" + +#include "vision-artificial/image/iface.h" +#include "vision-artificial/user/iface.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +static WINDOW *win_log; +static WINDOW *win_help; + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ +static void log_loop (void); +static int usr_input (void); +static void show_help (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void user_tui_init (void) +{ + int_fast8_t h1, w1, r1, c1; + int_fast8_t h2, w2, r2, c2; + + alx_ncurses_resume(); + + /* Dimensions: log */ + h1 = 54; + w1 = 40; + r1 = 0; + c1 = 30; + win_log = newwin(h1, w1, r1, c1); + + /* Dimensions: help */ + h2 = 54; + w2 = 40; + r2 = 0; + c2 = 0; + win_help = newwin(h2, w2, r2, c2); + + /* Activate keypad, don't echo input */ + keypad(win_log, true); + noecho(); +} + +void user_tui_cleanup (void) +{ + + /* Del wins & return to terminal mode */ + alx_ncurses_delwin(win_log); + alx_ncurses_delwin(win_help); + alx_ncurses_pause(); +} + +int user_tui (const char *restrict title, + const char *restrict subtitle) +{ + + show_help(); + user_tui_show_log(title, subtitle); + return usr_input(); +} + +void user_tui_fname (const char *restrict fpath, + char *restrict fname) +{ + int w, r; + + w = 75; + r = 10; + + alx_w_get_fname(fpath, fname, false, w, r, "File name:", "Valid extensions: .bmp .dib .jpeg .png .pbm .pgm .ppm .tiff", + 2); +} + +void user_tui_show_log (const char *restrict title, + const char *restrict subtitle) +{ + + werase(win_log); + box(win_log, 0, 0); + + alx_ncurses_title(win_log, title); + alx_ncurses_subtitle(win_log, subtitle); + + log_loop(); + wrefresh(win_log); +} + +double user_tui_getdbl (double m, double def, double M, + const char *restrict title, + const char *restrict help) +{ + int w, r; + + w = 75; + r = 10; + + return alx_w_get_dbl(m, def, M, w, r, title, help, 2); +} + +int user_tui_getint (int m, int def, int M, + const char *restrict title, + const char *restrict help) +{ + int w, r; + + w = 75; + r = 10; + + return alx_w_get_int(m, def, M, w, r, title, help, 2); +} + +void user_tui_show_ocr (void) +{ + + alx_ncurses_pause(); + + printf("%s", img_ocr_text); + alx_wait4enter(); + + alx_ncurses_resume(); +} + + +/****************************************************************************** + ******* static functions (definitions) *************************************** + ******************************************************************************/ +static void log_loop (void) +{ + ptrdiff_t i_0; + int_fast8_t l_0; + int_fast8_t l; + + if (user_iface_log.len > 51) { + i_0 = user_iface_log.len - 51; + l_0 = 1; + mvwprintw(win_log, 1, 10, "..."); + } else { + i_0 = 0; + l_0 = 0; + } + + l = l_0 + 1; + for (ptrdiff_t i = i_0; i < user_iface_log.len; i++) { + if (user_iface_log.lvl[i] <= user_iface_log.visible) { + mvwprintw(win_log, l, (1 + 4 * user_iface_log.lvl[i]), + "%.*s", + 40 - 2 - 4 * user_iface_log.lvl[i], + user_iface_log.line[i]); + l++; + } + } +} + +static int usr_input (void) +{ + int c; + + c = wgetch(win_log); + switch (c) { + case ' ': + return USER_IFACE_ACT_APPLY; + case KEY_BACKSPACE: + /* ASCII 0x08 is BS */ + case 0x08: + return USER_IFACE_ACT_DISCARD; + case 'e': + /* Exercises from class */ + c = wgetch(win_log); + + switch (c) { + case '1': + /* Label */ + c = wgetch(win_log); + + switch (c) { + case '1': + return USER_IFACE_ACT_PROC_LABEL_SERIES; + } + break; + case '2': + /* Objects */ + c = wgetch(win_log); + + switch (c) { + case '0': + return USER_IFACE_ACT_PROC_OBJECTS_CALIB; + case '1': + return USER_IFACE_ACT_PROC_OBJECTS_SERIES; + } + break; + case '3': + /* Coins */ + c = wgetch(win_log); + + switch (c) { + case '1': + return USER_IFACE_ACT_PROC_COINS_SERIES; + } + break; + case '4': + /* Resistor */ + c = wgetch(win_log); + + switch (c) { + case '1': + return USER_IFACE_ACT_PROC_RESISTOR_SERIES; + } + break; + case '5': + /* Lighters */ + c = wgetch(win_log); + + switch (c) { + case '1': + return USER_IFACE_ACT_PROC_LIGHTERS_SERIES; + } + break; + } + break; + case 'f': + /* Use simple funtions */ + c = wgetch(win_log); + + switch (c) { + case '0': + /* img_alx */ + c = wgetch(win_log); + + switch (c) { + case '0': + /* Distance transform postprocessing */ + c = wgetch(win_log); + + switch (c) { + case '0': + return USER_IFACE_ACT_LOCAL_MAX; + case '1': + return USER_IFACE_ACT_SKELETON; + } + break; + case '1': + /* Lines */ + c = wgetch(win_log); + + switch (c) { + case '0': + return USER_IFACE_ACT_LINES_HORIZONTAL; + case '1': + return USER_IFACE_ACT_LINES_VERTICAL; + } + break; + case '2': + /* Smooth */ + c = wgetch(win_log); + + switch (c) { + case '0': + return USER_IFACE_ACT_MEAN_HORIZONTAL; + case '1': + return USER_IFACE_ACT_MEAN_VERTICAL; + case '2': + return USER_IFACE_ACT_MEDIAN_HORIZONTAL; + case '3': + return USER_IFACE_ACT_MEDIAN_VERTICAL; + } + break; + } + break; + case '1': + /* img_cv */ + c = wgetch(win_log); + + switch (c) { + case '0': + /* Core: The core functionality */ + c = wgetch(win_log); + + switch (c) { + case '0': + /* Pixel */ + c = wgetch(win_log); + + switch (c) { + case '0': + return USER_IFACE_ACT_PIXEL_GET; + case '1': + return USER_IFACE_ACT_PIXEL_SET; + } + break; + case '1': + /* ROI */ + c = wgetch(win_log); + + switch (c) { + case '0': + return USER_IFACE_ACT_SET_ROI; + case '1': + return USER_IFACE_ACT_SET_ROI_2RECT; + } + break; + case '2': + /* Operations on Arrays */ + c = wgetch(win_log); + + switch (c) { + case '0': + return USER_IFACE_ACT_AND_2REF; + case '1': + return USER_IFACE_ACT_NOT; + case '2': + return USER_IFACE_ACT_OR_2REF; + case '3': + return USER_IFACE_ACT_COMPONENT; + } + break; + } + break; + case '1': + /* Imgproc: Image processing */ + c = wgetch(win_log); + + switch (c) { + case '0': + /* Image filtering */ + c = wgetch(win_log); + + switch (c) { + case '0': + return USER_IFACE_ACT_DILATE; + case '1': + return USER_IFACE_ACT_ERODE; + case '2': + return USER_IFACE_ACT_DILATE_ERODE; + case '3': + return USER_IFACE_ACT_ERODE_DILATE; + case '4': + return USER_IFACE_ACT_SMOOTH; + case '5': + return USER_IFACE_ACT_SOBEL; + case '6': + return USER_IFACE_ACT_BORDER; + } + break; + case '1': + /* Geometric image transformations */ + c = wgetch(win_log); + + switch (c) { + case '0': + return USER_IFACE_ACT_MIRROR; + case '1': + return USER_IFACE_ACT_ROTATE_ORTO; + case '2': + return USER_IFACE_ACT_ROTATE; + case '3': + return USER_IFACE_ACT_ROTATE_2RECT; + } + break; + case '2': + /* Miscellaneous image transformations */ + c = wgetch(win_log); + + switch (c) { + case '0': + return USER_IFACE_ACT_ADAPTIVE_THRESHOLD; + case '1': + return USER_IFACE_ACT_CVT_COLOR; + case '2': + return USER_IFACE_ACT_DISTANCE_TRANSFORM; + case '3': + return USER_IFACE_ACT_THRESHOLD; + } + break; + case '3': + /* Histograms */ + c = wgetch(win_log); + + switch (c) { + case '0': + return USER_IFACE_ACT_HISTOGRAM; + case '1': + return USER_IFACE_ACT_HISTOGRAM_C3; + } + break; + case '4': + /* Structural analysis and shape descriptors */ + c = wgetch(win_log); + + switch (c) { + case '0': + return USER_IFACE_ACT_CONTOURS; + case '1': + return USER_IFACE_ACT_CONTOURS_SIZE; + case '2': + return USER_IFACE_ACT_BOUNDING_RECT; + case '3': + return USER_IFACE_ACT_FIT_ELLIPSE; + case '4': + return USER_IFACE_ACT_MIN_AREA_RECT; + } + break; + case '5': + /* Feature detection */ + c = wgetch(win_log); + + switch (c) { + case '0': + return USER_IFACE_ACT_HOUGH_CIRCLES; + } + break; + } + break; + } + break; + case '2': + /* img_orb */ + c = wgetch(win_log); + + switch (c) { + case '0': + return USER_IFACE_ACT_ALIGN; + } + break; + case '3': + /* img_calib3d */ + c = wgetch(win_log); + + switch (c) { + case '0': + return USER_IFACE_ACT_CALIBRATE; + case '1': + return USER_IFACE_ACT_UNDISTORT; + } + break; + case '4': + /* img_zbar */ + c = wgetch(win_log); + + switch (c) { + case '0': + return USER_IFACE_ACT_DECODE; + } + break; + case '5': + /* img_ocr */ + c = wgetch(win_log); + + switch (c) { + case '0': + return USER_IFACE_ACT_READ; + } + break; + } + break; + case 'l': + return USER_IFACE_ACT_LOAD_MEM; + case 'm': + return USER_IFACE_ACT_SAVE_MEM; + case 'q': + return USER_IFACE_ACT_QUIT; + case 'r': + return USER_IFACE_ACT_SAVE_REF; + case 's': + return USER_IFACE_ACT_SAVE_FILE; + case 'u': + /* User iface actions */ + c = wgetch(win_log); + + switch (c) { + case '1': + return USER_IFACE_ACT_SHOW_OCR; + } + break; + + case 'x': + + /* Special sequence "xyzzy" */ + c = wgetch(win_log); + if (c == 'y') { + c = wgetch(win_log); + if (c == 'z') { + + c = wgetch(win_log); + if (c == 'z') { + + c = wgetch(win_log); + if (c == 'y') { + return USER_IFACE_ACT_FOO; + } + } + } + } + break; + } + + return USER_IFACE_ACT_FOO; +} + +static void show_help (void) +{ + int r, c; + + werase(win_help); + r = 0; + c = 0; + mvwprintw(win_help, r++, c, "Apply: %s", "Space"); + mvwprintw(win_help, r++, c, "Discard: %s", "BS"); + mvwprintw(win_help, r++, c, "Save to mem: %c", 'm'); + mvwprintw(win_help, r++, c, "Load from mem: %c", 'l'); + 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, " - Local maxima: %s", "f000"); + mvwprintw(win_help, r++, c, " - Skeleton: %s", "f001"); + mvwprintw(win_help, r++, c, " - Horizontal lines: %s", "f010"); + mvwprintw(win_help, r++, c, " - Vertical lines: %s", "f011"); + mvwprintw(win_help, r++, c, " - Horizontal mean: %s", "f020"); + mvwprintw(win_help, r++, c, " - Vertical mean: %s", "f021"); + mvwprintw(win_help, r++, c, " - Horizontal median: %s", "f022"); + mvwprintw(win_help, r++, c, " - Vertical median: %s", "f023"); + mvwprintw(win_help, r++, c, " - Pixel get: %s", "f1000"); + mvwprintw(win_help, r++, c, " - Pixel set: %s", "f1001"); + mvwprintw(win_help, r++, c, " - Set ROI: %s", "f1010"); + mvwprintw(win_help, r++, c, " - Set ROI 2rect: %s", "f1011"); + mvwprintw(win_help, r++, c, " - Bitwise AND 2ref: %s", "f1020"); + mvwprintw(win_help, r++, c, " - Bitwise NOT: %s", "f1021"); + mvwprintw(win_help, r++, c, " - Bitwise OR 2ref: %s", "f1022"); + mvwprintw(win_help, r++, c, " - Component: %s", "f1023"); + mvwprintw(win_help, r++, c, " - Dilate: %s", "f1100"); + mvwprintw(win_help, r++, c, " - Erode: %s", "f1101"); + mvwprintw(win_help, r++, c, " - D-E: %s", "f1102"); + mvwprintw(win_help, r++, c, " - E-D: %s", "f1103"); + mvwprintw(win_help, r++, c, " - Smooth: %s", "f1104"); + mvwprintw(win_help, r++, c, " - Sobel: %s", "f1105"); + mvwprintw(win_help, r++, c, " - Border: %s", "f1106"); + mvwprintw(win_help, r++, c, " - Mirror: %s", "f1110"); + mvwprintw(win_help, r++, c, " - Rotate ortogonally: %s", "f1111"); + mvwprintw(win_help, r++, c, " - Rotate: %s", "f1112"); + mvwprintw(win_help, r++, c, " - Rotate 2rect_rot: %s", "f1113"); + mvwprintw(win_help, r++, c, " - Adaptive threshold: %s", "f1120"); + mvwprintw(win_help, r++, c, " - Cvt color: %s", "f1121"); + mvwprintw(win_help, r++, c, " - Distance transform: %s", "f1122"); + mvwprintw(win_help, r++, c, " - Threshold: %s", "f1123"); + mvwprintw(win_help, r++, c, " - Histogram: %s", "f1130"); + mvwprintw(win_help, r++, c, " - Histogram (3 chan): %s", "f1131"); + mvwprintw(win_help, r++, c, " - Contours: %s", "f1140"); + mvwprintw(win_help, r++, c, " - Contours size: %s", "f1141"); + mvwprintw(win_help, r++, c, " - Bounding rectangle: %s", "f1142"); + mvwprintw(win_help, r++, c, " - Fit ellipse: %s", "f1143"); + mvwprintw(win_help, r++, c, " - Min. area rectangle: %s", "f1144"); + mvwprintw(win_help, r++, c, " - Hough circles: %s", "f1150"); + mvwprintw(win_help, r++, c, " - Align 2ref (ORB): %s", "f20"); + mvwprintw(win_help, r++, c, " - Calibrate (Calib3d): %s", "f30"); + mvwprintw(win_help, r++, c, " - Undistort (Calib3d): %s", "f31"); + mvwprintw(win_help, r++, c, " - Scan codes (ZBAR): %s", "f40"); + mvwprintw(win_help, r++, c, " - Scan text (OCR): %s", "f50"); + mvwprintw(win_help, r++, c, "Exercises:"); + mvwprintw(win_help, r++, c, " - Label: %s", "e11"); + mvwprintw(win_help, r++, c, " - Objects (calib): %s", "e20"); + mvwprintw(win_help, r++, c, " - Objects: %s", "e21"); + mvwprintw(win_help, r++, c, " - Coins: %s", "e31"); + mvwprintw(win_help, r++, c, " - Resistor: %s", "e41"); + mvwprintw(win_help, r++, c, " - Lighters: %s", "e51"); + mvwprintw(win_help, r++, c, "Other:"); + mvwprintw(win_help, r++, c, " - Show OCR: %s", "u1"); + mvwprintw(win_help, r++, c, "Quit: %c", 'q'); + wrefresh(win_help); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/tmp/Makefile b/tmp/Makefile index a49f078..cd48349 100644 --- a/tmp/Makefile +++ b/tmp/Makefile @@ -1,74 +1,88 @@ -# -*- MakeFile -*- +#! /usr/bin/make -f -# MACRO = substitute with this +################################################################################ +# Copyright (C) 2019 Alejandro Colomar Andrés +# SPDX-License-Identifier: GPL-2.0-only +################################################################################ +# *AUTHOR* +# FULL NAME "Alejandro Colomar Andrés" +# EMAIL "1903716@gmail.com" +################################################################################ -# directories +################################################################################ +# dependencies -LIBALX_INC_DIR = $(LIBALX_DIR)/inc/ +OBJ = \ + main.o -ABOUT_DIR = $(MODULES_DIR)/about/ -ABOUT_INC_DIR = $(ABOUT_DIR)/inc/ +MAIN_INC = \ + $(LIBALX_INC_DIR)/libalx/base/stdio/wait.hpp \ + $(LIBALX_INC_DIR)/libalx/extra/ncurses/common.hpp \ + $(INC_DIR)/vision-artificial/about/about.hpp \ + $(INC_DIR)/vision-artificial/image/iface.h \ + $(INC_DIR)/vision-artificial/menu/iface.h \ + $(INC_DIR)/vision-artificial/menu/parse.h \ + $(INC_DIR)/vision-artificial/user/iface.h \ + $(INC_DIR)/vision-artificial/save/save.h +MAIN_SRC = \ + $(SRC_DIR)/main.cpp -CTRL_DIR = $(MODULES_DIR)/ctrl/ -CTRL_INC_DIR = $(CTRL_DIR)/inc/ -IMG_DIR = $(MODULES_DIR)/image/ -IMG_INC_DIR = $(IMG_DIR)/inc/ +# target: dependencies +# action -MENU_DIR = $(MODULES_DIR)/menu/ -MENU_INC_DIR = $(MENU_DIR)/inc/ +PHONY := all +all: $(OBJ) about ctrl image menu proc save user -SAVE_DIR = $(MODULES_DIR)/save/ -SAVE_INC_DIR = $(SAVE_DIR)/inc/ -USR_DIR = $(MODULES_DIR)/user/ -USR_INC_DIR = $(USR_DIR)/inc/ +PHONY += about +about: + @echo " MAKE tmp/about" + $(Q)$(MAKE) -C $(TMP_DIR)/about/ -SRC_DIR = $(MAIN_DIR)/src/ +PHONY += ctrl +ctrl: + @echo " MAKE tmp/ctrl" + $(Q)$(MAKE) -C $(TMP_DIR)/ctrl/ -# dependencies +PHONY += image +image: + @echo " MAKE tmp/image" + $(Q)$(MAKE) -C $(TMP_DIR)/image/ -ALL = main.o - -MAIN_INC_LIBALX = libalx/curses/alx_ncur.hpp -MAIN_INC_ABOUT = about.hpp -MAIN_INC_IMG = img_iface.hpp -MAIN_INC_MENU = parser.hpp menu_iface.hpp -MAIN_INC_SAVE = save.hpp -MAIN_INC_USR = user_iface.hpp -MAIN_DEPS = $(SRC_DIR)/main.cpp \ - $(patsubst %,$(LIBALX_INC_DIR)/%,$(MAIN_INC_LIBALX)) \ - $(patsubst %,$(ABOUT_INC_DIR)/%,$(MAIN_INC_ABOUT)) \ - $(patsubst %,$(IMG_INC_DIR)/%,$(MAIN_INC_IMG)) \ - $(patsubst %,$(MENU_INC_DIR)/%,$(MAIN_INC_MENU)) \ - $(patsubst %,$(SAVE_INC_DIR)/%,$(MAIN_INC_SAVE)) \ - $(patsubst %,$(USR_INC_DIR)/%,$(MAIN_INC_USR)) -MAIN_INC_DIRS = -I $(LIBALX_INC_DIR) \ - -I $(ABOUT_INC_DIR) \ - -I $(IMG_INC_DIR) \ - -I $(MENU_INC_DIR) \ - -I $(SAVE_INC_DIR) \ - -I $(USR_INC_DIR) +PHONY += menu +menu: + @echo " MAKE tmp/menu" + $(Q)$(MAKE) -C $(TMP_DIR)/menu/ +PHONY += proc +proc: + @echo " MAKE tmp/proc" + $(Q)$(MAKE) -C $(TMP_DIR)/proc/ -# target: dependencies -# action +PHONY += save +save: + @echo " MAKE tmp/save" + $(Q)$(MAKE) -C $(TMP_DIR)/save/ + +PHONY += user +user: + @echo " MAKE tmp/user" + $(Q)$(MAKE) -C $(TMP_DIR)/user/ -PHONY := all -all: $(ALL) -main.s: $(MAIN_DEPS) - @echo " CXX $@" - $(Q)$(CXX) $(CXXFLAGS) $(MAIN_INC_DIRS) -S $< -o $@ +main.s: $(MAIN_SRC) $(MAIN_INC) + @echo " CXX vision-artificial/tmp/$@" + $(Q)$(CXX) $(CXXFLAGS) -I $(INC_DIR) -S $< -o $@ main.o: main.s - @echo " AS $@" + @echo " AS vision-artificial/tmp/$@" $(Q)$(AS) $< -o $@ PHONY += clean clean: @echo " RM *.o *.s" - $(Q)rm -f *.o *.s + $(Q)rm -f *.o *.s ################################################################################ # Declare the contents of the .PHONY variable as phony. diff --git a/tmp/about/Makefile b/tmp/about/Makefile new file mode 100644 index 0000000..36f47a2 --- /dev/null +++ b/tmp/about/Makefile @@ -0,0 +1,53 @@ +#! /usr/bin/make -f + +################################################################################ +# Copyright (C) 2019 Alejandro Colomar Andrés +# SPDX-License-Identifier: GPL-2.0-only +################################################################################ +# *AUTHOR* +# FULL NAME "Alejandro Colomar Andrés" +# EMAIL "1903716@gmail.com" +################################################################################ + +################################################################################ +# dependencies + +OBJ = \ + about.o + +ABOUT_INC = \ + $(INC_DIR)/vision-artificial/about/about.h \ + $(LIBALX_INC_DIR)/libalx/base/errno/errno_str.h \ + $(LIBALX_INC_DIR)/libalx/base/stdio/sprint_file.h +ABOUT_SRC = \ + $(SRC_DIR)/about/about.c + +################################################################################ +# target: dependencies +# action + +PHONY := all +all: $(OBJ) + + +about.s: $(ABOUT_SRC) $(ABOUT_INC) + @echo " CC vision-artificial/about/$@" + $(Q)$(CC) $(CFLAGS) -I $(INC_DIR) -S $< -o $@ +about.o: about.s + @echo " AS vision-artificial/about/$@" + $(Q)$(AS) $< -o $@ + + +PHONY += clean +clean: + @echo " RM *.o *.s" + $(Q)rm -f *.o *.s + +################################################################################ +# Declare the contents of the .PHONY variable as phony. +.PHONY: $(PHONY) + + +################################################################################ +######## End of file ########################################################### +################################################################################ diff --git a/tmp/ctrl/Makefile b/tmp/ctrl/Makefile new file mode 100644 index 0000000..da57c66 --- /dev/null +++ b/tmp/ctrl/Makefile @@ -0,0 +1,54 @@ +#! /usr/bin/make -f + +################################################################################ +# Copyright (C) 2019 Alejandro Colomar Andrés +# SPDX-License-Identifier: GPL-2.0-only +################################################################################ +# *AUTHOR* +# FULL NAME "Alejandro Colomar Andrés" +# EMAIL "1903716@gmail.com" +################################################################################ + +################################################################################ +# dependencies + +OBJ = \ + start.o + +START_INC = \ + $(INC_DIR)/vision-artificial/ctrl/start.h \ + $(INC_DIR)/vision-artificial/proc/iface.h \ + $(INC_DIR)/vision-artificial/save/save.h \ + $(INC_DIR)/vision-artificial/user/iface.h +START_SRC = \ + $(SRC_DIR)/ctrl/start.c + +################################################################################ +# target: dependencies +# action + +PHONY := all +all: $(OBJ) + + +start.s: $(START_SRC) $(START_INC) + @echo " CC vision-artificial/ctrl/$@" + $(Q)$(CC) $(CFLAGS) -I $(INC_DIR) -S $< -o $@ +start.o: start.s + @echo " AS vision-artificial/ctrl/$@" + $(Q)$(AS) $< -o $@ + + +PHONY += clean +clean: + @echo " RM *.o *.s" + $(Q)rm -f *.o *.s + +################################################################################ +# Declare the contents of the .PHONY variable as phony. +.PHONY: $(PHONY) + + +################################################################################ +######## End of file ########################################################### +################################################################################ diff --git a/tmp/image/Makefile b/tmp/image/Makefile new file mode 100644 index 0000000..951f7db --- /dev/null +++ b/tmp/image/Makefile @@ -0,0 +1,145 @@ +#! /usr/bin/make -f + +################################################################################ +# Copyright (C) 2019 Alejandro Colomar Andrés +# SPDX-License-Identifier: GPL-2.0-only +################################################################################ +# *AUTHOR* +# FULL NAME "Alejandro Colomar Andrés" +# EMAIL "1903716@gmail.com" +################################################################################ + +################################################################################ +# dependencies + +OBJ = \ + alx.o \ + calib3d.o \ + cv.o \ + iface.o \ + ocr.o \ + orb.o \ + zbar.o + +ALX_INC = \ + $(INC_DIR)/vision-artificial/image/alx.hpp \ + $(LIBALX_INC_DIR)/libalx/base/math/arithmetic_mean.hpp \ + $(LIBALX_INC_DIR)/libalx/base/math/median.hpp \ + $(INC_DIR)/vision-artificial/image/iface.hpp +ALX_SRC = \ + $(SRC_DIR)/image/alx.cpp + +CALIB3D_INC = \ + $(INC_DIR)/vision-artificial/image/calib3d.hpp \ + $(INC_DIR)/vision-artificial/image/iface.hpp +CALIB3D_SRC = \ + $(SRC_DIR)/image/calib3d.cpp + +CV_INC = \ + $(INC_DIR)/vision-artificial/image/cv.hpp \ + $(INC_DIR)/vision-artificial/image/iface.hpp +CV_SRC = \ + $(SRC_DIR)/image/cv.cpp + +IFACE_INC = \ + $(INC_DIR)/vision-artificial/image/iface.hpp \ + $(INC_DIR)/vision-artificial/image/alx.hpp \ + $(INC_DIR)/vision-artificial/image/calib3d.hpp \ + $(INC_DIR)/vision-artificial/image/cv.hpp \ + $(INC_DIR)/vision-artificial/image/ocr.hpp \ + $(INC_DIR)/vision-artificial/image/orb.hpp \ + $(INC_DIR)/vision-artificial/image/zbar.hpp \ + $(INC_DIR)/vision-artificial/save/save.hpp \ + $(INC_DIR)/vision-artificial/user/iface.hpp +IFACE_SRC = \ + $(SRC_DIR)/image/iface.cpp + +OCR_INC = \ + $(INC_DIR)/vision-artificial/image/ocr.h \ + $(INC_DIR)/vision-artificial/about/about.h \ + $(INC_DIR)/vision-artificial/image/iface.h +OCR_SRC = \ + $(SRC_DIR)/image/ocr.c + +ORB_INC = \ + $(INC_DIR)/vision-artificial/image/orb.hpp +ORB_SRC = \ + $(SRC_DIR)/image/orb.cpp + +ZBAR_INC = \ + $(INC_DIR)/vision-artificial/image/zbar.hpp \ + $(INC_DIR)/vision-artificial/image/iface.hpp +ZBAR_SRC = \ + $(SRC_DIR)/image/zbar.cpp + +################################################################################ +# target: dependencies +# action + +PHONY := all +all: $(OBJ) + + +alx.s: $(ALX_SRC) $(ALX_INC) + @echo " CXX vision-artificial/image/$@" + $(Q)$(CXX) $(CXXFLAGS) -I $(INC_DIR) -S $< -o $@ +alx.o: alx.s + @echo " AS vision-artificial/image/$@" + $(Q)$(AS) $< -o $@ + +calib3d.s: $(CALIB3D_SRC) $(CALIB3D_INC) + @echo " CXX vision-artificial/image/$@" + $(Q)$(CXX) $(CXXFLAGS) -I $(INC_DIR) -S $< -o $@ +calib3d.o: calib3d.s + @echo " AS vision-artificial/image/$@" + $(Q)$(AS) $< -o $@ + +cv.s: $(CV_SRC) $(CV_INC) + @echo " CXX vision-artificial/image/$@" + $(Q)$(CXX) $(CXXFLAGS) -I $(INC_DIR) -S $< -o $@ +cv.o: cv.s + @echo " AS vision-artificial/image/$@" + $(Q)$(AS) $< -o $@ + +iface.s: $(IFACE_SRC) $(IFACE_INC) + @echo " CXX vision-artificial/image/$@" + $(Q)$(CXX) $(CXXFLAGS) -I $(INC_DIR) -S $< -o $@ +iface.o: iface.s + @echo " AS vision-artificial/image/$@" + $(Q)$(AS) $< -o $@ + +ocr.s: $(OCR_SRC) $(OCR_INC) + @echo " CC vision-artificial/image/$@" + $(Q)$(CC) $(CFLAGS) -I $(INC_DIR) -S $< -o $@ +ocr.o: ocr.s + @echo " AS vision-artificial/image/$@" + $(Q)$(AS) $< -o $@ + +orb.s: $(ORB_SRC) $(ORB_INC) + @echo " CXX vision-artificial/image/$@" + $(Q)$(CXX) $(CXXFLAGS) -I $(INC_DIR) -S $< -o $@ +orb.o: orb.s + @echo " AS vision-artificial/image/$@" + $(Q)$(AS) $< -o $@ + +zbar.s: $(ZBAR_SRC) $(ZBAR_INC) + @echo " CXX vision-artificial/image/$@" + $(Q)$(CXX) $(CXXFLAGS) -I $(INC_DIR) -S $< -o $@ +zbar.o: zbar.s + @echo " AS vision-artificial/image/$@" + $(Q)$(AS) $< -o $@ + + +PHONY += clean +clean: + @echo " RM *.o *.s" + $(Q)rm -f *.o *.s + +################################################################################ +# Declare the contents of the .PHONY variable as phony. +.PHONY: $(PHONY) + + +################################################################################ +######## End of file ########################################################### +################################################################################ diff --git a/tmp/menu/Makefile b/tmp/menu/Makefile new file mode 100644 index 0000000..31849bb --- /dev/null +++ b/tmp/menu/Makefile @@ -0,0 +1,110 @@ +#! /usr/bin/make -f + +################################################################################ +# Copyright (C) 2019 Alejandro Colomar Andrés +# SPDX-License-Identifier: GPL-2.0-only +################################################################################ +# *AUTHOR* +# FULL NAME "Alejandro Colomar Andrés" +# EMAIL "1903716@gmail.com" +################################################################################ + +################################################################################ +# dependencies + +OBJ = \ + clui.o \ + iface.o \ + parse.o \ + tui.o + +CLUI_INC = \ + $(INC_DIR)/vision-artificial/menu/clui.h \ + $(LIBALX_INC_DIR)/libalx/base/stdio/get.h \ + $(INC_DIR)/vision-artificial/about/about.h \ + $(INC_DIR)/vision-artificial/ctrl/start.h +CLUI_SRC = \ + $(SRC_DIR)/menu/clui.c + +IFACE_INC = \ + $(INC_DIR)/vision-artificial/menu/iface.h \ + $(INC_DIR)/vision-artificial/menu/clui.h \ + $(INC_DIR)/vision-artificial/menu/tui.h +IFACE_SRC = \ + $(SRC_DIR)/menu/iface.c + +PARSE_INC = \ + $(INC_DIR)/vision-artificial/menu/parse.h \ + $(LIBALX_INC_DIR)/libalx/base/stdio/sscan.h \ + $(INC_DIR)/vision-artificial/about/about.h \ + $(INC_DIR)/vision-artificial/menu/iface.h \ + $(INC_DIR)/vision-artificial/save/save.h \ + $(INC_DIR)/vision-artificial/user/iface.h +PARSE_SRC = \ + $(SRC_DIR)/menu/parse.c + +TUI_INC = \ + $(INC_DIR)/vision-artificial/menu/tui.h \ + $(LIBALX_INC_DIR)/libalx/base/stddef/size.h \ + $(LIBALX_INC_DIR)/libalx/base/stdio/wait.h \ + $(LIBALX_INC_DIR)/libalx/extra/ncurses/common.h \ + $(LIBALX_INC_DIR)/libalx/extra/ncurses/get.h \ + $(LIBALX_INC_DIR)/libalx/extra/ncurses/menu.h \ + $(INC_DIR)/vision-artificial/about/about.h \ + $(INC_DIR)/vision-artificial/ctrl/start.h \ + $(INC_DIR)/vision-artificial/proc/iface.h \ + $(INC_DIR)/vision-artificial/save/save.h \ + $(INC_DIR)/vision-artificial/user/iface.h +TUI_SRC = \ + $(SRC_DIR)/menu/tui.c + +################################################################################ +# target: dependencies +# action + +PHONY := all +all: $(OBJ) + + +clui.s: $(CLUI_SRC) $(CLUI_INC) + @echo " CC vision-artificial/menu/$@" + $(Q)$(CC) $(CFLAGS) -I $(INC_DIR) -S $< -o $@ +clui.o: clui.s + @echo " AS vision-artificial/menu/$@" + $(Q)$(AS) $< -o $@ + +iface.s: $(IFACE_SRC) $(IFACE_INC) + @echo " CXX vision-artificial/menu/$@" + $(Q)$(CC) $(CFLAGS) -I $(INC_DIR) -S $< -o $@ +iface.o: iface.s + @echo " AS vision-artificial/menu/$@" + $(Q)$(AS) $< -o $@ + +parse.s: $(PARSE_SRC) $(PARSE_INC) + @echo " CC vision-artificial/menu/$@" + $(Q)$(CC) $(CFLAGS) -I $(INC_DIR) -S $< -o $@ +parse.o: parse.s + @echo " AS vision-artificial/menu/$@" + $(Q)$(AS) $< -o $@ + +tui.s: $(TUI_SRC) $(TUI_INC) + @echo " CC vision-artificial/menu/$@" + $(Q)$(CC) $(CFLAGS) -I $(INC_DIR) -S $< -o $@ +tui.o: tui.s + @echo " AS vision-artificial/menu/$@" + $(Q)$(AS) $< -o $@ + + +PHONY += clean +clean: + @echo " RM *.o *.s" + $(Q)rm -f *.o *.s + +################################################################################ +# Declare the contents of the .PHONY variable as phony. +.PHONY: $(PHONY) + + +################################################################################ +######## End of file ########################################################### +################################################################################ diff --git a/tmp/proc/Makefile b/tmp/proc/Makefile new file mode 100644 index 0000000..b5e9577 --- /dev/null +++ b/tmp/proc/Makefile @@ -0,0 +1,167 @@ +#! /usr/bin/make -f + +################################################################################ +# Copyright (C) 2019 Alejandro Colomar Andrés +# SPDX-License-Identifier: GPL-2.0-only +################################################################################ +# *AUTHOR* +# FULL NAME "Alejandro Colomar Andrés" +# EMAIL "1903716@gmail.com" +################################################################################ + +################################################################################ +# dependencies + +OBJ = \ + coins.o \ + common.o \ + iface.o \ + label.o \ + lighters.o \ + objects.o \ + resistor.o + +COINS_INC = \ + $(INC_DIR)/vision-artificial/proc/coins.hpp \ + $(LIBALX_INC_DIR)/libalx/base/math/arithmetic_mean.hpp \ + $(LIBALX_INC_DIR)/libalx/base/stddef/size.hpp \ + $(LIBALX_INC_DIR)/libalx/base/stdlib/maximum.hpp \ + $(INC_DIR)/vision-artificial/image/iface.hpp \ + $(INC_DIR)/vision-artificial/proc/common.hpp \ + $(INC_DIR)/vision-artificial/user/iface.hpp +COINS_SRC = \ + $(SRC_DIR)/proc/coins.cpp + +COMMON_INC = \ + $(INC_DIR)/vision-artificial/proc/common.hpp \ + $(LIBALX_INC_DIR)/libalx/base/stdio/wait.hpp \ + $(INC_DIR)/vision-artificial/image/iface.hpp \ + $(INC_DIR)/vision-artificial/proc/iface.hpp \ + $(INC_DIR)/vision-artificial/user/iface.hpp +COMMON_SRC = \ + $(SRC_DIR)/proc/common.cpp + +IFACE_INC = \ + $(INC_DIR)/vision-artificial/proc/iface.h \ + $(LIBALX_INC_DIR)/libalx/base/stddef/size.h \ + $(LIBALX_INC_DIR)/libalx/base/stdio/sscan.h \ + $(LIBALX_INC_DIR)/libalx/base/stdio/wait.h \ + $(INC_DIR)/vision-artificial/image/iface.h \ + $(INC_DIR)/vision-artificial/proc/coins.h \ + $(INC_DIR)/vision-artificial/proc/common.h \ + $(INC_DIR)/vision-artificial/proc/label.h \ + $(INC_DIR)/vision-artificial/proc/lighters.h \ + $(INC_DIR)/vision-artificial/proc/objects.h \ + $(INC_DIR)/vision-artificial/proc/resistor.h \ + $(INC_DIR)/vision-artificial/save/save.h \ + $(INC_DIR)/vision-artificial/user/iface.h +IFACE_SRC = \ + $(SRC_DIR)/proc/iface.c + +LABEL_INC = \ + $(INC_DIR)/vision-artificial/proc/label.hpp \ + $(LIBALX_INC_DIR)/libalx/base/stdlib/swap.hpp \ + $(INC_DIR)/vision-artificial/image/iface.hpp \ + $(INC_DIR)/vision-artificial/proc/common.hpp \ + $(INC_DIR)/vision-artificial/user/iface.hpp +LABEL_SRC = \ + $(SRC_DIR)/proc/label.cpp + +LIGHTERS_INC = \ + $(INC_DIR)/vision-artificial/proc/lighters.hpp \ + $(LIBALX_INC_DIR)/libalx/base/stdlib/swap.hpp \ + $(INC_DIR)/vision-artificial/image/iface.hpp \ + $(INC_DIR)/vision-artificial/proc/common.hpp \ + $(INC_DIR)/vision-artificial/user/iface.hpp +LIGHTERS_SRC = \ + $(SRC_DIR)/proc/lighters.cpp + +OBJECTS_INC = \ + $(INC_DIR)/vision-artificial/proc/objects.hpp \ + $(LIBALX_INC_DIR)/libalx/base/math/median.hpp \ + $(INC_DIR)/vision-artificial/image/iface.hpp \ + $(INC_DIR)/vision-artificial/proc/common.hpp \ + $(INC_DIR)/vision-artificial/user/iface.hpp +OBJECTS_SRC = \ + $(SRC_DIR)/proc/objects.cpp + +RESISTOR_INC = \ + $(INC_DIR)/vision-artificial/proc/resistor.hpp \ + $(LIBALX_INC_DIR)/libalx/base/stddef/size.hpp \ + $(INC_DIR)/vision-artificial/image/iface.hpp \ + $(INC_DIR)/vision-artificial/proc/common.hpp \ + $(INC_DIR)/vision-artificial/user/iface.hpp +RESISTOR_SRC = \ + $(SRC_DIR)/proc/resistor.cpp + +################################################################################ +# target: dependencies +# action + +PHONY := all +all: $(OBJ) + + +coins.s: $(COINS_SRC) $(COINS_INC) + @echo " CXX vision-artificial/proc/$@" + $(Q)$(CXX) $(CXXFLAGS) -I $(INC_DIR) -S $< -o $@ +coins.o: coins.s + @echo " AS vision-artificial/proc/$@" + $(Q)$(AS) $< -o $@ + +common.s: $(COMMON_SRC) $(COMMON_INC) + @echo " CXX vision-artificial/proc/$@" + $(Q)$(CXX) $(CXXFLAGS) -I $(INC_DIR) -S $< -o $@ +common.o: common.s + @echo " AS vision-artificial/proc/$@" + $(Q)$(AS) $< -o $@ + +iface.s: $(IFACE_SRC) $(IFACE_INC) + @echo " CC vision-artificial/proc/$@" + $(Q)$(CC) $(CFLAGS) -I $(INC_DIR) -S $< -o $@ +iface.o: iface.s + @echo " AS vision-artificial/proc/$@" + $(Q)$(AS) $< -o $@ + +label.s: $(LABEL_SRC) $(LABEL_INC) + @echo " CXX vision-artificial/proc/$@" + $(Q)$(CXX) $(CXXFLAGS) -I $(INC_DIR) -S $< -o $@ +label.o: label.s + @echo " AS vision-artificial/proc/$@" + $(Q)$(AS) $< -o $@ + +lighters.s: $(LIGHTERS_SRC) $(LIGHTERS_INC) + @echo " CXX vision-artificial/proc/$@" + $(Q)$(CXX) $(CXXFLAGS) -I $(INC_DIR) -S $< -o $@ +lighters.o: lighters.s + @echo " AS vision-artificial/proc/$@" + $(Q)$(AS) $< -o $@ + +objects.s: $(OBJECTS_SRC) $(OBJECTS_INC) + @echo " CXX vision-artificial/proc/$@" + $(Q)$(CXX) $(CXXFLAGS) -I $(INC_DIR) -S $< -o $@ +objects.o: objects.s + @echo " AS vision-artificial/proc/$@" + $(Q)$(AS) $< -o $@ + +resistor.s: $(RESISTOR_SRC) $(RESISTOR_INC) + @echo " CXX vision-artificial/proc/$@" + $(Q)$(CXX) $(CXXFLAGS) -I $(INC_DIR) -S $< -o $@ +resistor.o: resistor.s + @echo " AS vision-artificial/proc/$@" + $(Q)$(AS) $< -o $@ + + +PHONY += clean +clean: + @echo " RM *.o *.s" + $(Q)rm -f *.o *.s + +################################################################################ +# Declare the contents of the .PHONY variable as phony. +.PHONY: $(PHONY) + + +################################################################################ +######## End of file ########################################################### +################################################################################ diff --git a/tmp/save/Makefile b/tmp/save/Makefile new file mode 100644 index 0000000..50546a5 --- /dev/null +++ b/tmp/save/Makefile @@ -0,0 +1,54 @@ +#! /usr/bin/make -f + +################################################################################ +# Copyright (C) 2019 Alejandro Colomar Andrés +# SPDX-License-Identifier: GPL-2.0-only +################################################################################ +# *AUTHOR* +# FULL NAME "Alejandro Colomar Andrés" +# EMAIL "1903716@gmail.com" +################################################################################ + +################################################################################ +# dependencies + +OBJ = \ + save.o + +SAVE_INC = \ + $(INC_DIR)/vision-artificial/save/save.hpp \ + $(LIBALX_INC_DIR)/libalx/base/errno/errno_str.hpp \ + $(LIBALX_INC_DIR)/libalx/base/stddef/restrict.hpp \ + $(INC_DIR)/vision-artificial/user/iface.hpp +SAVE_SRC = \ + $(SRC_DIR)/save/save.cpp + +################################################################################ +# target: dependencies +# action + +PHONY := all +all: $(OBJ) + + +save.s: $(SAVE_SRC) $(SAVE_INC) + @echo " CC vision-artificial/save/$@" + $(Q)$(CXX) $(CXXFLAGS) -I $(INC_DIR) -S $< -o $@ +save.o: save.s + @echo " AS vision-artificial/save/$@" + $(Q)$(AS) $< -o $@ + + +PHONY += clean +clean: + @echo " RM *.o *.s" + $(Q)rm -f *.o *.s + +################################################################################ +# Declare the contents of the .PHONY variable as phony. +.PHONY: $(PHONY) + + +################################################################################ +######## End of file ########################################################### +################################################################################ diff --git a/tmp/user/Makefile b/tmp/user/Makefile new file mode 100644 index 0000000..e06b3db --- /dev/null +++ b/tmp/user/Makefile @@ -0,0 +1,92 @@ +#! /usr/bin/make -f + +################################################################################ +# Copyright (C) 2019 Alejandro Colomar Andrés +# SPDX-License-Identifier: GPL-2.0-only +################################################################################ +# *AUTHOR* +# FULL NAME "Alejandro Colomar Andrés" +# EMAIL "1903716@gmail.com" +################################################################################ + +################################################################################ +# dependencies + +OBJ = \ + clui.o \ + iface.o \ + tui.o + +CLUI_INC = \ + $(INC_DIR)/vision-artificial/user/clui.h \ + $(LIBALX_INC_DIR)/libalx/base/stdlib/swap.h \ + $(LIBALX_INC_DIR)/libalx/base/stdio/get.h \ + $(LIBALX_INC_DIR)/libalx/base/stdio/wait.h \ + $(INC_DIR)/vision-artificial/image/iface.h \ + $(INC_DIR)/vision-artificial/user/iface.h +CLUI_SRC = \ + $(SRC_DIR)/user/clui.c + +IFACE_INC = \ + $(INC_DIR)/vision-artificial/user/iface.h \ + $(LIBALX_INC_DIR)/libalx/base/stdio/get.h \ + $(INC_DIR)/vision-artificial/image/iface.h \ + $(INC_DIR)/vision-artificial/proc/iface.h \ + $(INC_DIR)/vision-artificial/user/clui.h \ + $(INC_DIR)/vision-artificial/user/tui.h +IFACE_SRC = \ + $(SRC_DIR)/user/iface.c + +TUI_INC = \ + $(INC_DIR)/vision-artificial/user/tui.h \ + $(LIBALX_INC_DIR)/libalx/base/stdio/wait.h \ + $(LIBALX_INC_DIR)/libalx/extra/ncurses/common.h \ + $(LIBALX_INC_DIR)/libalx/extra/ncurses/get.h \ + $(INC_DIR)/vision-artificial/image/iface.h \ + $(INC_DIR)/vision-artificial/user/iface.h +TUI_SRC = \ + $(SRC_DIR)/user/tui.c + +################################################################################ +# target: dependencies +# action + +PHONY := all +all: $(OBJ) + + +clui.s: $(CLUI_SRC) $(CLUI_INC) + @echo " CC vision-artificial/user/$@" + $(Q)$(CC) $(CFLAGS) -I $(INC_DIR) -S $< -o $@ +clui.o: clui.s + @echo " AS vision-artificial/user/$@" + $(Q)$(AS) $< -o $@ + +iface.s: $(IFACE_SRC) $(IFACE_INC) + @echo " CC vision-artificial/user/$@" + $(Q)$(CC) $(CFLAGS) -I $(INC_DIR) -S $< -o $@ +iface.o: iface.s + @echo " AS vision-artificial/user/$@" + $(Q)$(AS) $< -o $@ + +tui.s: $(TUI_SRC) $(TUI_INC) + @echo " CC vision-artificial/user/$@" + $(Q)$(CC) $(CFLAGS) -I $(INC_DIR) -S $< -o $@ +tui.o: tui.s + @echo " AS vision-artificial/user/$@" + $(Q)$(AS) $< -o $@ + + +PHONY += clean +clean: + @echo " RM *.o *.s" + $(Q)rm -f *.o *.s + +################################################################################ +# Declare the contents of the .PHONY variable as phony. +.PHONY: $(PHONY) + + +################################################################################ +######## End of file ########################################################### +################################################################################ -- cgit v1.2.3