diff options
author | Alex <colomar.6.4.3@gmail.com> | 2018-10-22 13:10:48 +0200 |
---|---|---|
committer | Alex <colomar.6.4.3@gmail.com> | 2018-10-22 13:10:48 +0200 |
commit | 7b9a8f3fa83bc774785ab092f5149cf1b53c5d7e (patch) | |
tree | 84f11a7b3c9802a664b4edf2856ce55d94c57d11 | |
parent | e4721f5b38e840386ada995232e74bc703b7bab3 (diff) |
Measure time of each step; Update user CLUI; Add directories for processes
-rw-r--r-- | modules/ctrl/src/start.c | 4 | ||||
-rw-r--r-- | modules/ctrl/tmp/Makefile | 4 | ||||
-rw-r--r-- | modules/image/inc/img_iface.h | 2 | ||||
-rw-r--r-- | modules/image/inc/img_iface.hpp | 2 | ||||
-rw-r--r-- | modules/image/src/img_iface.cpp | 24 | ||||
-rw-r--r-- | modules/image/src/img_ocr.c | 16 | ||||
-rw-r--r-- | modules/menu/src/menu_tui.c | 21 | ||||
-rw-r--r-- | modules/proc/inc/proc.h | 2 | ||||
-rw-r--r-- | modules/proc/inc/proc.hpp | 2 | ||||
-rw-r--r-- | modules/proc/src/proc.cpp | 143 | ||||
-rw-r--r-- | modules/save/inc/save.h | 16 | ||||
-rw-r--r-- | modules/save/inc/save.hpp | 8 | ||||
-rw-r--r-- | modules/save/src/save.cpp | 61 | ||||
-rw-r--r-- | modules/user/inc/user_clui.h | 2 | ||||
-rw-r--r-- | modules/user/inc/user_iface.h | 5 | ||||
-rw-r--r-- | modules/user/inc/user_iface.hpp | 5 | ||||
-rw-r--r-- | modules/user/inc/user_tui.h | 2 | ||||
-rw-r--r-- | modules/user/src/user_clui.c | 232 | ||||
-rw-r--r-- | modules/user/src/user_iface.c | 8 | ||||
-rw-r--r-- | modules/user/src/user_tui.c | 34 | ||||
-rw-r--r-- | modules/user/tmp/Makefile | 11 |
21 files changed, 478 insertions, 126 deletions
diff --git a/modules/ctrl/src/start.c b/modules/ctrl/src/start.c index 71f7e59..52ee14b 100644 --- a/modules/ctrl/src/start.c +++ b/modules/ctrl/src/start.c @@ -17,6 +17,8 @@ #include "img_iface.h"
/* proc_iface_series() */
#include "proc.h"
+ /* saved_name*/
+ #include "save.h"
/* user_iface() */
#include "user_iface.h"
@@ -70,7 +72,7 @@ static void start_foo (void) static void start_single (void)
{
errno = 0;
- img_iface_load();
+ img_iface_load(NULL, saved_name);
if (!errno) {
user_iface_init();
diff --git a/modules/ctrl/tmp/Makefile b/modules/ctrl/tmp/Makefile index f6f0ed4..8413864 100644 --- a/modules/ctrl/tmp/Makefile +++ b/modules/ctrl/tmp/Makefile @@ -6,6 +6,7 @@ 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/ @@ -18,16 +19,19 @@ ALL = $(_ALL) ctrl_mod.o STRT_INC_IMG = img_iface.h STRT_INC_PROC = proc.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 diff --git a/modules/image/inc/img_iface.h b/modules/image/inc/img_iface.h index d8a9796..08029df 100644 --- a/modules/image/inc/img_iface.h +++ b/modules/image/inc/img_iface.h @@ -124,7 +124,7 @@ ******* functions ************************************************************
******************************************************************************/
void img_iface_cleanup_main (void);
- void img_iface_load (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);
diff --git a/modules/image/inc/img_iface.hpp b/modules/image/inc/img_iface.hpp index 3522bc4..fcaa3da 100644 --- a/modules/image/inc/img_iface.hpp +++ b/modules/image/inc/img_iface.hpp @@ -205,7 +205,7 @@ extern "C" { ******* functions ************************************************************
******************************************************************************/
void img_iface_cleanup_main (void);
- void img_iface_load (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 (void);
diff --git a/modules/image/src/img_iface.cpp b/modules/image/src/img_iface.cpp index 61583b0..7d720fe 100644 --- a/modules/image/src/img_iface.cpp +++ b/modules/image/src/img_iface.cpp @@ -120,14 +120,32 @@ void img_iface_cleanup_main (void) cv::destroyAllWindows();
}
-void img_iface_load (void)
+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();
+ load_image_file(file_path, file_name);
if (!errno) {
/* Make a static copy of image */
@@ -1037,7 +1055,7 @@ static void img_iface_save_file (void) image_copy_tmp.copyTo(image);
/* Save into file */
- save_image_file(NULL);
+ save_image_file(NULL, NULL);
}
diff --git a/modules/image/src/img_ocr.c b/modules/image/src/img_ocr.c index 26b6282..1f2f74d 100644 --- a/modules/image/src/img_ocr.c +++ b/modules/image/src/img_ocr.c @@ -64,19 +64,19 @@ static void img_ocr_read (void *data) char lang_str [20 + 1];
lang = data_cast->lang;
switch (lang) {
- case 0:
+ case IMG_IFACE_OCR_LANG_ENG:
sprintf(lang_str, "eng");
break;
- case 1:
+ case IMG_IFACE_OCR_LANG_SPA:
sprintf(lang_str, "spa");
break;
- case 2:
+ case IMG_IFACE_OCR_LANG_CAT:
sprintf(lang_str, "cat");
break;
- case 3:
+ case IMG_IFACE_OCR_LANG_DIGITS:
sprintf(lang_str, "digits");
break;
- case 4:
+ case IMG_IFACE_OCR_LANG_DIGITS_COMMA:
sprintf(lang_str, "digits_comma");
break;
}
@@ -86,7 +86,7 @@ static void img_ocr_read (void *data) char conf_str [FILENAME_MAX];
conf = data_cast->conf;
switch (conf) {
- case 1:
+ case IMG_IFACE_OCR_CONF_PRICE:
sprintf(conf_str, "%s/%s", share_path, "price");
break;
}
@@ -94,8 +94,8 @@ static void img_ocr_read (void *data) /* init OCR */
handle_ocr = TessBaseAPICreate();
TessBaseAPIInit2(handle_ocr, NULL, lang_str,
- OEM_DEFAULT);
-// OEM_LSTM_ONLY);
+// OEM_DEFAULT);
+ OEM_LSTM_ONLY);
// OEM_TESSERACT_LSTM_COMBINED);
if (conf) {
/* Configure OCR (whitelist chars) */
diff --git a/modules/menu/src/menu_tui.c b/modules/menu/src/menu_tui.c index f34e495..6112b4e 100644 --- a/modules/menu/src/menu_tui.c +++ b/modules/menu/src/menu_tui.c @@ -258,11 +258,12 @@ static void menu_tui_devel (void) r = 1;
c = (80 - w) / 2;
int N;
- N = 3;
- struct Alx_Menu mnu[3] = {
- {5, 4, "[0] Back"},
+ N = 4;
+ struct Alx_Menu mnu[4] = {
+ {6, 4, "[0] Back"},
{2, 4, "[1] Change process mode"},
- {3, 4, "[2] Change log mode"}
+ {3, 4, "[2] Change log mode"},
+ {4, 4, "[3] Change user iface mode"}
};
/* Input box */
@@ -272,7 +273,8 @@ static void menu_tui_devel (void) 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: 0=Results; 1=Operations; 2=All",
+ "Modes: 1=CLUI; 2=TUI"
};
/* Menu */
@@ -292,8 +294,8 @@ static void menu_tui_devel (void) break;
case 1:
- proc_debug = alx_w_getint(w2, r2, txt[0],
- PROC_DBG_NO, 0, PROC_DBG_STOP_STEP,
+ proc_debug = alx_w_getint(w2, r2, txt[0],
+ PROC_DBG_NO, 0, PROC_DBG_STOP_STEP,
NULL);
break;
@@ -301,6 +303,11 @@ static void menu_tui_devel (void) 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;
}
}
diff --git a/modules/proc/inc/proc.h b/modules/proc/inc/proc.h index 0c3b98c..0b5c74e 100644 --- a/modules/proc/inc/proc.h +++ b/modules/proc/inc/proc.h @@ -52,7 +52,7 @@ /******************************************************************************
******* functions ************************************************************
******************************************************************************/
- int proc_iface_single (void);
+ int proc_iface_single (int action);
void proc_iface_series (void);
diff --git a/modules/proc/inc/proc.hpp b/modules/proc/inc/proc.hpp index 4d1f529..bd716f2 100644 --- a/modules/proc/inc/proc.hpp +++ b/modules/proc/inc/proc.hpp @@ -58,7 +58,7 @@ extern "C" { /******************************************************************************
******* functions ************************************************************
******************************************************************************/
- int proc_iface_single (void);
+ int proc_iface_single (int action);
void proc_iface_series (void);
diff --git a/modules/proc/src/proc.cpp b/modules/proc/src/proc.cpp index 3b99017..43cbb17 100644 --- a/modules/proc/src/proc.cpp +++ b/modules/proc/src/proc.cpp @@ -60,16 +60,12 @@ static void proc_invert (void); static void proc_dilate (int size);
static void proc_erode (int size);
static void proc_dilate_erode (int size);
-static void proc_contours (std::vector <
- std::vector <
- class cv::Point_ <int>
- >
- > *contours,
- class cv::Mat *hierarchy);
-static void proc_min_area_rect (std::vector <
- class cv::Point_ <int>
- > *contour,
- class cv::RotatedRect *rect);
+static void proc_contours (
+ std::vector <std::vector <class cv::Point_ <int>>> *contours,
+ class cv::Mat *hierarchy);
+static void proc_min_area_rect (
+ std::vector <class cv::Point_ <int>> *contour,
+ class cv::RotatedRect *rect);
static void proc_rotate (class cv::RotatedRect *rect);
static void proc_ROI (int x, int y, int w, int h);
static void proc_OCR (int lang, int conf);
@@ -81,7 +77,7 @@ static void proc_show_img (void); /******************************************************************************
******* main *****************************************************************
******************************************************************************/
-int proc_iface_single (void)
+int proc_iface_single (int action)
{
int error;
clock_t time_0;
@@ -92,7 +88,7 @@ int proc_iface_single (void) time_0 = clock();
/* Process */
- switch (proc_mode) {
+ switch (action) {
case PROC_MODE_LABEL:
error = proc_label();
break;
@@ -138,28 +134,34 @@ void proc_iface_series (void) snprintf(file_name, FILENAME_MAX, "%s%04i%s",
file_basename, i, file_ext);
- file_error = alx_sscan_fname(saved_path, saved_name,
+ file_error = alx_sscan_fname(labels_path, file_name,
true, file_name);
if (file_error) {
wh = false;
} else {
errno = 0;
- img_iface_load();
+ img_iface_load(labels_path, file_name);
if (!errno) {
/* Process */
- proc_error = proc_iface_single();
- /* Show log */
- user_iface_show_log(saved_name, NULL);
+ proc_error = proc_iface_single(proc_mode);
if (proc_error) {
+ /* Save failed image into file */
img_iface_show();
snprintf(save_error_as, FILENAME_MAX,
- "%s%04i_err%s",
- file_basename, i, file_ext);
- save_image_file(save_error_as);
+ "%s%04i_err%s",
+ file_basename, i,
+ file_ext);
+ save_image_file(labels_fail_path,
+ save_error_as);
}
+
+ /* Show log */
+ char txt_tmp [80];
+ snprintf(txt_tmp, 80, "%04i", i);
+ user_iface_show_log(txt_tmp, "Label");
} else {
printf("errno:%i\n", errno);
}
@@ -175,7 +177,9 @@ static int proc_label (void) {
int status;
- char price [80];
+ double times;
+ clock_t time_0;
+ clock_t time_1;
std::vector <std::vector <cv::Point_ <int>>> contours;
class cv::Mat hierarchy;
@@ -185,9 +189,14 @@ static int proc_label (void) int w;
int h;
+ char price [80];
+
proc_save_mem(0);
/* Find label (position and angle) */
{
+ /* Measure time */
+ time_0 = clock();
+
proc_cmp(IMG_IFACE_CMP_BLUE);
proc_smooth(IMGI_SMOOTH_MEDIAN, 7);
#if 0
@@ -218,16 +227,39 @@ static int proc_label (void) rect.size.width = rect.size.height;
rect.size.height = tmp;
}
+
+ /* Measure time */
+ time_1 = clock();
+ times = ((double) time_1 - time_0) / CLOCKS_PER_SEC;
+ /* Write time into log */
+ snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
+ "Time0: %.3lf", times);
+ user_iface_log.lvl[user_iface_log.len] = 0;
+ (user_iface_log.len)++;
}
/* Align label and extract green component */
{
+ /* Measure time */
+ time_0 = clock();
+
proc_load_mem(0);
proc_rotate(&rect);
proc_cmp(IMG_IFACE_CMP_GREEN);
proc_save_mem(1);
+
+ /* Measure time */
+ time_1 = clock();
+ times = ((double) time_1 - time_0) / CLOCKS_PER_SEC;
+ /* Write time into log */
+ snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
+ "Time1: %.3lf", times);
+ user_iface_log.lvl[user_iface_log.len] = 0;
+ (user_iface_log.len)++;
}
/* Find "Cerdo" in aligned image */
{
+ /* Measure time */
+ time_0 = clock();
x = rect.center.x - (1.05 * rect.size.width / 2);
if (x < 0) {
@@ -253,9 +285,21 @@ static int proc_label (void) result_label(status);
return status;
}
+
+ /* Measure time */
+ time_1 = clock();
+ times = ((double) time_1 - time_0) / CLOCKS_PER_SEC;
+ /* Write time into log */
+ snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
+ "Time2: %.3lf", times);
+ user_iface_log.lvl[user_iface_log.len] = 0;
+ (user_iface_log.len)++;
}
/* Read barcode in original image */
{
+ /* Measure time */
+ time_0 = clock();
+
proc_load_mem(0);
proc_cmp(IMG_IFACE_CMP_GREEN);
proc_zbar(zbar::ZBAR_EAN13);
@@ -266,9 +310,21 @@ static int proc_label (void) result_label(status);
return status;
}
+
+ /* Measure time */
+ time_1 = clock();
+ times = ((double) time_1 - time_0) / CLOCKS_PER_SEC;
+ /* Write time into log */
+ snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
+ "Time3: %.3lf", times);
+ user_iface_log.lvl[user_iface_log.len] = 0;
+ (user_iface_log.len)++;
}
/* Check product code in barcode */
{
+ /* Measure time */
+ time_0 = clock();
+
bool prod_nok;
prod_nok = strncmp(zb_codes.arr[0].data, "2301703",
strlen("2301703"));
@@ -277,9 +333,21 @@ static int proc_label (void) result_label(status);
return status;
}
+
+ /* Measure time */
+ time_1 = clock();
+ times = ((double) time_1 - time_0) / CLOCKS_PER_SEC;
+ /* Write time into log */
+ snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
+ "Time4: %.3lf", times);
+ user_iface_log.lvl[user_iface_log.len] = 0;
+ (user_iface_log.len)++;
}
/* Read price in aligned image (green component) */
{
+ /* Measure time */
+ time_0 = clock();
+
proc_load_mem(1);
x = rect.center.x + (0.33 * rect.size.width / 2);
@@ -292,9 +360,21 @@ static int proc_label (void) proc_dilate_erode(1);
proc_threshold(cv::THRESH_BINARY, 1);
proc_OCR(IMG_IFACE_OCR_LANG_DIGITS, IMG_IFACE_OCR_CONF_PRICE);
+
+ /* Measure time */
+ time_1 = clock();
+ times = ((double) time_1 - time_0) / CLOCKS_PER_SEC;
+ /* Write time into log */
+ snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
+ "Time5: %.3lf", times);
+ user_iface_log.lvl[user_iface_log.len] = 0;
+ (user_iface_log.len)++;
}
/* Extract price from barcode */
{
+ /* Measure time */
+ time_0 = clock();
+
if (zb_codes.arr[0].data[8] != '0') {
snprintf(price, 80, "%c%c.%c%c",
zb_codes.arr[0].data[8],
@@ -307,9 +387,21 @@ static int proc_label (void) zb_codes.arr[0].data[10],
zb_codes.arr[0].data[11]);
}
+
+ /* Measure time */
+ time_1 = clock();
+ times = ((double) time_1 - time_0) / CLOCKS_PER_SEC;
+ /* Write time into log */
+ snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
+ "Time6: %.3lf", times);
+ user_iface_log.lvl[user_iface_log.len] = 0;
+ (user_iface_log.len)++;
}
/* Check label price with barcode price */
{
+ /* Measure time */
+ time_0 = clock();
+
bool price_nok;
price_nok = strncmp(img_ocr_text, price, strlen(price));
if (price_nok) {
@@ -317,6 +409,15 @@ static int proc_label (void) result_label(status);
return status;
}
+
+ /* Measure time */
+ time_1 = clock();
+ times = ((double) time_1 - time_0) / CLOCKS_PER_SEC;
+ /* Write time into log */
+ snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
+ "Time7: %.3lf", times);
+ user_iface_log.lvl[user_iface_log.len] = 0;
+ (user_iface_log.len)++;
}
status = LABEL_OK;
diff --git a/modules/save/inc/save.h b/modules/save/inc/save.h index c4c61b7..e34786e 100644 --- a/modules/save/inc/save.h +++ b/modules/save/inc/save.h @@ -25,16 +25,20 @@ # 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 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 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 saved_name [FILENAME_MAX];
/******************************************************************************
@@ -43,8 +47,8 @@ void save_init (void);
void save_cleanup (void);
void save_clr (void);
- void load_image_file (void);
- void save_image_file (const char *save_as);
+ 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 6937d7b..c849500 100644 --- a/modules/save/inc/save.hpp +++ b/modules/save/inc/save.hpp @@ -35,6 +35,8 @@ extern "C" { # 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 SAVED_NAME_DEFAULT "saved"
@@ -45,6 +47,8 @@ extern "C" { 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 saved_name [FILENAME_MAX];
@@ -54,8 +58,8 @@ extern "C" { void save_init (void);
void save_cleanup (void);
void save_clr (void);
- void load_image_file (void);
- void save_image_file (const char *save_as);
+ 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 951a034..240b532 100644 --- a/modules/save/src/save.cpp +++ b/modules/save/src/save.cpp @@ -37,6 +37,8 @@ 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 saved_name [FILENAME_MAX];
@@ -48,13 +50,14 @@ 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);
sprintf(saved_name, "");
int err;
err = mkdir(user_prog_path, 0700);
if (!err) {
- mkdir(saved_path, 0700);
} else {
switch (errno) {
@@ -72,6 +75,10 @@ void save_init (void) // exit(EXIT_FAILURE);
}
}
+
+ mkdir(saved_path, 0700);
+ mkdir(labels_path, 0700);
+ mkdir(labels_fail_path, 0700);
}
void save_clr (void)
@@ -79,15 +86,33 @@ void save_clr (void) snprintf(saved_path, FILENAME_MAX, "%s/%s/", home_path, USER_SAVED_DIR);
}
-void load_image_file (void)
+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", saved_path, saved_name);
+ snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name);
/* Load image */
image = cv::imread(file_name, CV_LOAD_IMAGE_COLOR);
@@ -105,32 +130,40 @@ void save_cleanup (void) image.release();
}
-void save_image_file (const char *save_as)
+void save_image_file (const char *fpath, const char *save_as)
{
+ char file_path [FILENAME_MAX];
char file_name [FILENAME_MAX];
FILE *fp;
- /* Default path & name */
- save_clr();
- snprintf(saved_name, FILENAME_MAX, "%s", SAVED_NAME_DEFAULT);
+ /* 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);
+ }
- /* Request file name */
+ /* Set file_name */
if (!save_as) {
- user_iface_save_name(saved_path, saved_name, FILENAME_MAX);
+ /* 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", saved_path, saved_name);
+ snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name);
fp = fopen(file_name, "r");
if (fp) {
- fclose(fp);
/* Name in use; ask once more */
- user_iface_save_name(saved_path, saved_name, FILENAME_MAX);
- /* Prepend the path */
- snprintf(file_name, FILENAME_MAX, "%s/%s", saved_path, saved_name);
+ fclose(fp);
+ user_iface_fname(saved_path, saved_name);
+ snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name);
}
/* Write into log */
diff --git a/modules/user/inc/user_clui.h b/modules/user/inc/user_clui.h index 5d45d18..07ff866 100644 --- a/modules/user/inc/user_clui.h +++ b/modules/user/inc/user_clui.h @@ -14,7 +14,7 @@ ******* functions ************************************************************
******************************************************************************/
int user_clui (const char *title, const char *subtitle);
-void user_clui_save_name (const char *filepath, char *filename, int destsize);
+void user_clui_fname (const char *filepath, char *filename);
void user_clui_show_log (const char *title, const char *subtitle);
diff --git a/modules/user/inc/user_iface.h b/modules/user/inc/user_iface.h index ad1852b..0a959b3 100644 --- a/modules/user/inc/user_iface.h +++ b/modules/user/inc/user_iface.h @@ -13,7 +13,7 @@ /******************************************************************************
******* macros ***************************************************************
******************************************************************************/
- # define LOG_LEN (1024)
+ # define LOG_LEN (1048576)
# define LOG_LINE_LEN (35)
@@ -110,8 +110,7 @@ void user_iface_cleanup (void);
void user_iface (void);
void user_iface_show_log (const char *title, const char *subtitle);
- void user_iface_save_name (const char *filepath, char *filename,
- int destsize);
+ 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,
diff --git a/modules/user/inc/user_iface.hpp b/modules/user/inc/user_iface.hpp index f507ac5..3008441 100644 --- a/modules/user/inc/user_iface.hpp +++ b/modules/user/inc/user_iface.hpp @@ -13,7 +13,7 @@ /******************************************************************************
******* macros ***************************************************************
******************************************************************************/
- # define LOG_LEN (1024)
+ # define LOG_LEN (1048576)
# define LOG_LINE_LEN (35)
@@ -116,8 +116,7 @@ extern "C" { void user_iface_cleanup (void);
void user_iface (void);
void user_iface_show_log (const char *title, const char *subtitle);
- void user_iface_save_name (const char *filepath, char *filename,
- int destsize);
+ 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,
diff --git a/modules/user/inc/user_tui.h b/modules/user/inc/user_tui.h index 2241879..d8f9a3c 100644 --- a/modules/user/inc/user_tui.h +++ b/modules/user/inc/user_tui.h @@ -17,7 +17,7 @@ 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_save_name (const char *filepath, char *filename, int destsize);
+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,
diff --git a/modules/user/src/user_clui.c b/modules/user/src/user_clui.c index f662d96..ad4e6ef 100644 --- a/modules/user/src/user_clui.c +++ b/modules/user/src/user_clui.c @@ -6,15 +6,15 @@ /******************************************************************************
******* headers **************************************************************
******************************************************************************/
-/* * * * * * * * * *
- * * * Standard * * * * * *
- * * * * * * * * * */
+/* Standard C ----------------------------------------------------------------*/
/* printf() & fgets() & sscanf() */
#include <stdio.h>
-/* * * * * * * * * *
- * * * Other * * * * * * *
- * * * * * * * * * */
+/* Project -------------------------------------------------------------------*/
+ /*img_ocr_text */
+ #include "img_iface.h"
+
+/* Module --------------------------------------------------------------------*/
/* user_iface_log */
#include "user_iface.h"
@@ -30,7 +30,7 @@ /******************************************************************************
******* static functions *****************************************************
******************************************************************************/
- /* Play */
+ /* Log */
static void log_loop (void);
/* Input */
static int usr_input (void);
@@ -53,11 +53,11 @@ int user_clui (const char *title, const char *subtitle) return action;
}
-void user_clui_save_name (const char *filepath, char *filename, int destsize)
+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, destsize, stdin);
+ fgets(filename, FILENAME_MAX, stdin);
}
void user_clui_show_log (const char *title, const char *subtitle)
@@ -77,10 +77,7 @@ void user_clui_show_log (const char *title, const char *subtitle) /******************************************************************************
******* static functions *****************************************************
******************************************************************************/
-/* * * * * * * * * *
- * * * Log * * * * * * *
- * * * * * * * * * */
-
+/* Log -----------------------------------------------------------------------*/
static void log_loop (void)
{
static int i = 0;
@@ -98,9 +95,7 @@ static void log_loop (void) putchar('\n');
}
-/* * * * * * * * * *
- * * * Input * * * * * * *
- * * * * * * * * * */
+/* Input ---------------------------------------------------------------------*/
static int usr_input (void)
{
int action;
@@ -119,19 +114,24 @@ static int usr_input (void) /* Interpret input */
sscanf(buff, " %c%c%c%c%c", &ch[0], &ch[1], &ch[2], &ch[3], &ch[4]);
switch (ch[0]) {
- case ' ':
+ case '+':
action = USER_IFACE_ACT_APPLY;
break;
- /* ASCII 0x08 is BS */
- case 0x7F:
- case 0x08:
+ case '-':
action = USER_IFACE_ACT_DISCARD;
break;
case 'e':
/* Exercises from class */
switch (ch[1]) {
+ case '1':
+ switch (ch[2]) {
+ case '0':
+ action = USER_IFACE_ACT_PROC_LABEL;
+ break;
+ }
+ break;
default:
action = USER_IFACE_ACT_FOO;
break;
@@ -141,11 +141,145 @@ static int usr_input (void) case 'f':
/* Use simple funtions */
switch (ch[1]) {
- case '0':
- action = USER_IFACE_ACT_INVERT;
- break;
case '1':
- action = USER_IFACE_ACT_BGR2GRAY;
+ /* img_cv */
+ switch (ch[2]) {
+ case '0':
+ /* color manipulation */
+ switch (ch[3]) {
+ case '0':
+ action = USER_IFACE_ACT_INVERT;
+ break;
+ case '1':
+ action = USER_IFACE_ACT_BGR2GRAY;
+ break;
+ case '2':
+ action = USER_IFACE_ACT_COMPONENT;
+ break;
+ default:
+ action = USER_IFACE_ACT_FOO;
+ break;
+ }
+ break;
+ case '1':
+ /* grayscale filters */
+ switch (ch[3]) {
+ case '0':
+ action = USER_IFACE_ACT_SMOOTH;
+ break;
+ case '1':
+ action = USER_IFACE_ACT_THRESHOLD;
+ break;
+ case '2':
+ action = USER_IFACE_ACT_ADAPTIVE_THRESHOLD;
+ break;
+ default:
+ action = USER_IFACE_ACT_FOO;
+ break;
+ }
+ break;
+ case '2':
+ /* black & white filters */
+ switch (ch[3]) {
+ 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;
+ default:
+ action = USER_IFACE_ACT_FOO;
+ break;
+ }
+ break;
+ case '3':
+ /* contour */
+ switch (ch[3]) {
+ case '0':
+ action = USER_IFACE_ACT_CONTOURS;
+ break;
+ case '1':
+ action = USER_IFACE_ACT_CONTOURS_SIZE;
+ break;
+ case '2':
+ action = USER_IFACE_ACT_MIN_AREA_RECT;
+ break;
+ default:
+ action = USER_IFACE_ACT_FOO;
+ break;
+ }
+ break;
+ case '4':
+ /* contour */
+ switch (ch[3]) {
+ case '0':
+ action = USER_IFACE_ACT_ROTATE_ORTO;
+ break;
+ case '1':
+ action = USER_IFACE_ACT_ROTATE;
+ break;
+ case '2':
+ action = USER_IFACE_ACT_ROTATE_2RECT;
+ break;
+ default:
+ action = USER_IFACE_ACT_FOO;
+ break;
+ }
+ break;
+ case '5':
+ /* ROI */
+ switch (ch[3]) {
+ case '0':
+ action = USER_IFACE_ACT_SET_ROI;
+ break;
+ default:
+ action = USER_IFACE_ACT_FOO;
+ break;
+ }
+ break;
+ default:
+ action = USER_IFACE_ACT_FOO;
+ break;
+ }
+ break;
+ case '2':
+ /* img_zbar */
+ switch (ch[2]) {
+ case '0':
+ action = USER_IFACE_ACT_DECODE;
+ break;
+ default:
+ action = USER_IFACE_ACT_FOO;
+ break;
+ }
+ break;
+ case '3':
+ /* img_ocr */
+ switch (ch[2]) {
+ case '0':
+ action = USER_IFACE_ACT_READ;
+ break;
+ default:
+ action = USER_IFACE_ACT_FOO;
+ break;
+ }
+ break;
+ case '4':
+ /* img_ocr */
+ switch (ch[2]) {
+ case '0':
+ action = USER_IFACE_ACT_ALIGN;
+ break;
+ default:
+ action = USER_IFACE_ACT_FOO;
+ break;
+ }
break;
default:
action = USER_IFACE_ACT_FOO;
@@ -165,17 +299,33 @@ static int usr_input (void) 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;
+ action = USER_IFACE_ACT_FOO;
}
}
}
@@ -196,6 +346,38 @@ 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');
+ 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(" - Invert: %s\n", "f100");
+ printf(" - BGR -> Gray: %s\n", "f101");
+ printf(" - Component: %s\n", "f102");
+ printf(" - Smooth: %s\n", "f110");
+ printf(" - Threshold: %s\n", "f111");
+ printf(" - Adaptive Thr:%s\n", "f112");
+ printf(" - Dilate: %s\n", "f120");
+ printf(" - Erode: %s\n", "f121");
+ printf(" - D-E: %s\n", "f122");
+ printf(" - E-D: %s\n", "f123");
+ printf(" - Contours: %s\n", "f130");
+ printf(" - Contours siz:%s\n", "f131");
+ printf(" - Min. A rect.:%s\n", "f132");
+ printf(" - Rotate orto.:%s\n", "f140");
+ printf(" - Rotate: %s\n", "f141");
+ printf(" - Rotate 2rect:%s\n", "f142");
+ printf(" - Set ROI: %s\n", "f150");
+ printf(" - Scan codes: %s\n", "f20");
+ printf(" - Scan text: %s\n", "f30");
+ printf(" - Align: %s\n", "f40");
+ printf("Exercises:\n");
+ printf(" - Etiqueta: %s\n", "e10");
+ printf("Other:\n");
+ printf(" - Show OCR: %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 a7804e5..4d6aec9 100644 --- a/modules/user/src/user_iface.c +++ b/modules/user/src/user_iface.c @@ -105,7 +105,7 @@ void user_iface (void) /* Do action */
switch (user_action & 0xF000) {
case USER_IFACE_ACT_PROC:
- proc_iface_single();
+ proc_iface_single(user_action);
break;
default:
user_iface_act(user_action);
@@ -127,15 +127,15 @@ void user_iface_show_log (const char *title, const char *subtitle) }
}
-void user_iface_save_name (const char *filepath, char *filename, int destsize)
+void user_iface_fname (const char *filepath, char *filename)
{
switch (user_iface_mode) {
case USER_IFACE_CLUI:
- user_clui_save_name(filepath, filename, destsize);
+ user_clui_fname(filepath, filename);
break;
case USER_IFACE_TUI:
- user_tui_save_name(filepath, filename, destsize);
+ user_tui_fname(filepath, filename);
break;
}
}
diff --git a/modules/user/src/user_tui.c b/modules/user/src/user_tui.c index 997acc7..4a1877d 100644 --- a/modules/user/src/user_tui.c +++ b/modules/user/src/user_tui.c @@ -90,6 +90,19 @@ int user_tui (const char *title, const char *subtitle) 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 */
@@ -108,19 +121,6 @@ void user_tui_show_log (const char *title, const char *subtitle) wrefresh(win_log);
}
-void user_tui_save_name (const char *filepath, char *filename, int destsize)
-{
- /* 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");
-}
-
double user_tui_getdbl (double m, double def, double M,
const char *title, const char *help)
{
@@ -165,9 +165,7 @@ void user_tui_show_ocr (void) /******************************************************************************
******* static functions *****************************************************
******************************************************************************/
-/* * * * * * * * * *
- * * * Log * * * * * * *
- * * * * * * * * * */
+/* Log -----------------------------------------------------------------------*/
static void log_loop (void)
{
int i;
@@ -195,9 +193,7 @@ static void log_loop (void) }
}
-/* * * * * * * * * *
- * * * Input * * * * * * *
- * * * * * * * * * */
+/* Input ---------------------------------------------------------------------*/
static int usr_input (void)
{
int action;
diff --git a/modules/user/tmp/Makefile b/modules/user/tmp/Makefile index 0248e77..ae99ed7 100644 --- a/modules/user/tmp/Makefile +++ b/modules/user/tmp/Makefile @@ -30,18 +30,21 @@ UI_INC_DIRS = -I $(INC_DIR) \ -I $(IMG_INC_DIR) \ -I $(PROC_INC_DIR) +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)) -UCLUI_INC_DIRS = -I $(INC_DIR) + $(patsubst %,$(INC_DIR)/%,$(UCLUI_INC)) \ + $(patsubst %,$(IMG_INC_DIR)/%,$(UCLUI_INC_IMG)) +UCLUI_INC_DIRS = -I $(INC_DIR) \ + -I $(IMG_INC_DIR) UTUI_INC_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 \ $(patsubst %,$(INC_DIR)/%,$(UTUI_INC)) \ - $(patsubst %,$(LIBALX_INC_DIR)/%,$(UTUI_INC_LIBALX)) \ - $(patsubst %,$(IMG_INC_DIR)/%,$(UTUI_INC_IMG)) + $(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) |