summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralex <alex@ASUS>2018-10-19 13:14:43 +0200
committeralex <alex@ASUS>2018-10-19 13:14:43 +0200
commit0663633d85d8c100b5284906c108e3fa878ff57d (patch)
treed97cdf08be568102d5e9671fb3f880991164f2ec
parent8d4fa231c1d13a281b61018f3d34f755bcf0129c (diff)
Fix bug misusing printf; Stop using varargs; Add log visibility modes; Add process debug modes
-rw-r--r--libalx/inc/alx_ncur.h12
-rw-r--r--libalx/inc/alx_ncur.hpp12
-rw-r--r--libalx/src/alx_input.c2
-rw-r--r--libalx/src/alx_ncur.c55
-rw-r--r--modules/ctrl/src/start.c15
-rw-r--r--modules/image/inc/img_iface.hpp2
-rw-r--r--modules/image/src/img_iface.c88
-rw-r--r--modules/image/src/img_orb.cpp9
-rw-r--r--modules/menu/src/menu_tui.c99
-rw-r--r--modules/menu/src/parser.c2
-rw-r--r--modules/menu/tmp/Makefile11
-rw-r--r--modules/proc/inc/proc.h21
-rw-r--r--modules/proc/src/proc.c63
-rw-r--r--modules/save/src/save.c31
-rw-r--r--modules/user/inc/user_iface.h3
-rw-r--r--modules/user/inc/user_iface.hpp3
-rw-r--r--modules/user/src/user_iface.c18
-rw-r--r--modules/user/src/user_tui.c12
18 files changed, 249 insertions, 209 deletions
diff --git a/libalx/inc/alx_ncur.h b/libalx/inc/alx_ncur.h
index f1a774f..b3f2860 100644
--- a/libalx/inc/alx_ncur.h
+++ b/libalx/inc/alx_ncur.h
@@ -53,8 +53,7 @@
double m,
double def,
double M,
- const char *format,
- ...);
+ const char *help);
int64_t alx_w_getint (int w,
int r,
@@ -62,16 +61,14 @@
double m,
int64_t def,
double M,
- const char *format,
- ...);
+ const char *help);
void alx_w_getstr (char *dest,
int destsize,
int w,
int r,
const char *title,
- const char *format,
- ...);
+ const char *help);
void alx_w_getfname (const char *fpath,
char *fname,
@@ -79,8 +76,7 @@
int w,
int r,
const char *title,
- const char *format,
- ...);
+ const char *help);
void alx_ncur_prn_title (WINDOW *win,
const char *title);
diff --git a/libalx/inc/alx_ncur.hpp b/libalx/inc/alx_ncur.hpp
index 36cc822..676b64b 100644
--- a/libalx/inc/alx_ncur.hpp
+++ b/libalx/inc/alx_ncur.hpp
@@ -64,8 +64,7 @@ extern "C" {
double m,
double def,
double M,
- const char *format,
- ...);
+ const char *help);
int64_t alx_w_getint (int w,
int r,
@@ -73,16 +72,14 @@ extern "C" {
double m,
int64_t def,
double M,
- const char *format,
- ...);
+ const char *help);
void alx_w_getstr (char *dest,
int destsize,
int w,
int r,
const char *title,
- const char *format,
- ...);
+ const char *help);
void alx_w_getfname (const char *fpath,
char *fname,
@@ -90,8 +87,7 @@ extern "C" {
int w,
int r,
const char *title,
- const char *format,
- ...);
+ const char *help);
void alx_ncur_prn_title (WINDOW *win,
const char *title);
diff --git a/libalx/src/alx_input.c b/libalx/src/alx_input.c
index 0c52cb9..214e145 100644
--- a/libalx/src/alx_input.c
+++ b/libalx/src/alx_input.c
@@ -134,7 +134,7 @@ int alx_sscan_fname (const char *fpath, char *fname, bool exist, const char *str
}
if (!err) {
- snprintf(fname, FILENAME_MAX, buff);
+ snprintf(fname, FILENAME_MAX, "%s", buff);
}
return err;
diff --git a/libalx/src/alx_ncur.c b/libalx/src/alx_ncur.c
index c059488..cdb683d 100644
--- a/libalx/src/alx_ncur.c
+++ b/libalx/src/alx_ncur.c
@@ -11,7 +11,6 @@
* * * * * * * * * */
#include <ncurses.h>
#include <inttypes.h>
- #include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
/* strlen() */
@@ -153,12 +152,8 @@ int alx_menu_2 (WINDOW *win,
double alx_w_getdbl (int w, int r, const char *title,
double m, double def, double M,
- const char *format, ...)
+ const char *help)
{
- /* Varargs */
- va_list args;
- va_start(args, format);
-
/* Dimensions */
WINDOW *win1;
int h1;
@@ -197,10 +192,10 @@ double alx_w_getdbl (int w, int r, const char *title,
/* Help */
win2 = newwin(h2, w2, r2, c2);
- if (format == NULL) {
+ if (help == NULL) {
wprintw(win2, "Introduce a real number [%lf U %lf] (default %lf)", m, M, def);
} else {
- vw_printw(win2, format, args);
+ wprintw(win2, "%s", help);
}
wrefresh(win2);
@@ -216,20 +211,13 @@ double alx_w_getdbl (int w, int r, const char *title,
alx_win_del(win2);
alx_win_del(win1);
- /* End varargs */
- va_end(args);
-
return R;
}
int64_t alx_w_getint (int w, int r, const char *title,
double m, int64_t def, double M,
- const char *format, ...)
+ const char *help)
{
- /* Varargs */
- va_list args;
- va_start(args, format);
-
/* Dimensions */
WINDOW *win1;
int h1;
@@ -268,10 +256,10 @@ int64_t alx_w_getint (int w, int r, const char *title,
/* Help */
win2 = newwin(h2, w2, r2, c2);
- if (format == NULL) {
+ if (help == NULL) {
wprintw(win2, "Introduce an integer number [%lf U %lf] (default %"PRIi64")", m, M, def);
} else {
- vw_printw(win2, format, args);
+ wprintw(win2, "%s", help);
}
wrefresh(win2);
@@ -287,20 +275,13 @@ int64_t alx_w_getint (int w, int r, const char *title,
alx_win_del(win2);
alx_win_del(win1);
- /* End varargs */
- va_end(args);
-
return Z;
}
void alx_w_getstr (char *dest, int destsize,
int w, int r, const char *title,
- const char *format, ...)
+ const char *help)
{
- /* Varargs */
- va_list args;
- va_start(args, format);
-
/* Dimensions */
WINDOW *win1;
int h1;
@@ -339,10 +320,10 @@ void alx_w_getstr (char *dest, int destsize,
/* Help */
win2 = newwin(h2, w2, r2, c2);
- if (format == NULL) {
+ if (help == NULL) {
waddstr(win2, "Introduce a string");
} else {
- vw_printw(win2, format, args);
+ wprintw(win2, "%s", help);
}
wrefresh(win2);
@@ -356,19 +337,12 @@ void alx_w_getstr (char *dest, int destsize,
alx_win_del(win3);
alx_win_del(win2);
alx_win_del(win1);
-
- /* End varargs */
- va_end(args);
}
void alx_w_getfname (const char *fpath, char *fname, bool exist,
int w, int r, const char *title,
- const char *format, ...)
+ const char *help)
{
- /* Varargs */
- va_list args;
- va_start(args, format);
-
/* Dimensions */
WINDOW *win1;
int h1;
@@ -407,10 +381,10 @@ void alx_w_getfname (const char *fpath, char *fname, bool exist,
/* Help */
win2 = newwin(h2, w2, r2, c2);
- if (format == NULL) {
+ if (help == NULL) {
waddstr(win2, "Introduce a file name");
} else {
- vw_printw(win2, format, args);
+ wprintw(win2, "%s", help);
}
wrefresh(win2);
@@ -424,9 +398,6 @@ void alx_w_getfname (const char *fpath, char *fname, bool exist,
alx_win_del(win3);
alx_win_del(win2);
alx_win_del(win1);
-
- /* End varargs */
- va_end(args);
}
void alx_ncur_prn_title (WINDOW *win, const char *title)
@@ -641,7 +612,7 @@ static void loop_w_getstr (char *dest, int destsize, WINDOW *win)
}
if (!err) {
- snprintf(dest, destsize, buff);
+ snprintf(dest, destsize, "%s", buff);
}
}
diff --git a/modules/ctrl/src/start.c b/modules/ctrl/src/start.c
index 976dc00..8302323 100644
--- a/modules/ctrl/src/start.c
+++ b/modules/ctrl/src/start.c
@@ -6,22 +6,21 @@
/******************************************************************************
******* headers **************************************************************
******************************************************************************/
-/* * * * * * * * * *
- * * * Standard * * * * * *
- * * * * * * * * * */
- /* opencv */
- #include <cv.h>
+/* Standard C ----------------------------------------------------------------*/
/* errno */
#include <errno.h>
-/* * * * * * * * * *
- * * * Other * * * * * * *
- * * * * * * * * * */
+/* Packages ------------------------------------------------------------------*/
+ /* opencv */
+ #include <cv.h>
+
+/* Project -------------------------------------------------------------------*/
/* img_iface_load() */
#include "img_iface.h"
/* user_iface() */
#include "user_iface.h"
+/* Module --------------------------------------------------------------------*/
#include "start.h"
diff --git a/modules/image/inc/img_iface.hpp b/modules/image/inc/img_iface.hpp
index 7b98327..a19f351 100644
--- a/modules/image/inc/img_iface.hpp
+++ b/modules/image/inc/img_iface.hpp
@@ -14,7 +14,7 @@
******* headers **************************************************************
******************************************************************************/
/* Packages ------------------------------------------------------------------*/
- /* struct _IplImage */
+ /* opencv */
#include <opencv2/opencv.hpp>
diff --git a/modules/image/src/img_iface.c b/modules/image/src/img_iface.c
index d432aea..f2c939e 100644
--- a/modules/image/src/img_iface.c
+++ b/modules/image/src/img_iface.c
@@ -7,6 +7,8 @@
******* headers **************************************************************
******************************************************************************/
/* Standard C ----------------------------------------------------------------*/
+ /* errno */
+ #include <errno.h>
/* INFINITY */
#include <math.h>
/* snprintf() */
@@ -127,16 +129,20 @@ struct _IplImage *img_iface_load (void)
/* Load file */
load_image_file();
- /* Make a static copy of image */
- cvReleaseImage(&image_copy_old);
- image_copy_old = cvCloneImage(image);
- cvReleaseImage(&image_copy_tmp);
- image_copy_tmp = cvCloneImage(image);
+ if (!errno) {
+ /* Make a static copy of image */
+ cvReleaseImage(&image_copy_old);
+ image_copy_old = cvCloneImage(image);
+ cvReleaseImage(&image_copy_tmp);
+ image_copy_tmp = cvCloneImage(image);
- /* Make a copy of the image so that it isn't modified by the user */
- cvReleaseImage(&image_copy_usr);
- image_copy_usr = cvCloneImage(image_copy_tmp);
- return image_copy_tmp;
+ /* Make a copy of the image so that it isn't modified by the user */
+ cvReleaseImage(&image_copy_usr);
+ image_copy_usr = cvCloneImage(image_copy_tmp);
+ return image_copy_tmp;
+ } else {
+ return NULL;
+ }
}
void img_iface_cleanup (void)
@@ -285,7 +291,7 @@ static void img_iface_bgr2gray (void)
/* 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] = 0;
+ user_iface_log.lvl[user_iface_log.len] = 1;
(user_iface_log.len)++;
return;
@@ -308,7 +314,7 @@ static void img_iface_component (void *data)
/* 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] = 0;
+ user_iface_log.lvl[user_iface_log.len] = 1;
(user_iface_log.len)++;
return;
@@ -345,7 +351,7 @@ static void img_iface_smooth (void *data)
/* 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] = 0;
+ user_iface_log.lvl[user_iface_log.len] = 1;
(user_iface_log.len)++;
return;
@@ -387,7 +393,7 @@ static void img_iface_threshold (void *data)
/* 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] = 0;
+ user_iface_log.lvl[user_iface_log.len] = 1;
(user_iface_log.len)++;
return;
@@ -428,7 +434,7 @@ static void img_iface_adaptive_thr (void *data)
/* 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] = 0;
+ user_iface_log.lvl[user_iface_log.len] = 1;
(user_iface_log.len)++;
return;
@@ -525,7 +531,7 @@ static void img_iface_contours (void *data)
/* 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] = 0;
+ user_iface_log.lvl[user_iface_log.len] = 1;
(user_iface_log.len)++;
return;
@@ -577,8 +583,7 @@ static void img_iface_contours_size (void *data)
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:",
- data_cast->n);
+ "Contours size:");
user_iface_log.lvl[user_iface_log.len] = 1;
(user_iface_log.len)++;
int i;
@@ -664,7 +669,7 @@ static void img_iface_rotate (void *data)
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) angle=%lfº",
+ "Rotate (%.2f,%.2f) %lfº",
data_cast->center.x,
data_cast->center.y,
data_cast->angle);
@@ -831,7 +836,7 @@ static void img_iface_decode (void *data)
/* 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] = 0;
+ user_iface_log.lvl[user_iface_log.len] = 1;
(user_iface_log.len)++;
return;
@@ -875,7 +880,7 @@ static void img_iface_decode (void *data)
"%s -- '%s'",
zb_codes.arr[i].sym_name,
zb_codes.arr[i].data);
- user_iface_log.lvl[user_iface_log.len] = 1;
+ user_iface_log.lvl[user_iface_log.len] = 2;
(user_iface_log.len)++;
}
}
@@ -916,7 +921,7 @@ static void img_iface_read (void *data)
/* 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] = 1;
+ user_iface_log.lvl[user_iface_log.len] = 2;
(user_iface_log.len)++;
}
}
@@ -929,7 +934,7 @@ static void img_iface_align (void)
/* 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] = 0;
+ user_iface_log.lvl[user_iface_log.len] = 1;
(user_iface_log.len)++;
return;
@@ -951,7 +956,7 @@ 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] = 0;
+ user_iface_log.lvl[user_iface_log.len] = 1;
(user_iface_log.len)++;
/* Write tmp into old */
@@ -964,7 +969,7 @@ 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] = 0;
+ user_iface_log.lvl[user_iface_log.len] = 1;
(user_iface_log.len)++;
/* Discard tmp image copy */
@@ -974,15 +979,6 @@ static void img_iface_discard (void)
static void img_iface_save_mem (void *data)
{
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Save to memory");
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-
- /* Apply changes before saving */
- img_iface_apply();
-
/* Which memory to use */
int x;
if (!data) {
@@ -1002,17 +998,11 @@ static void img_iface_save_mem (void *data)
/* Write into mem */
cvReleaseImage(&image_mem[x]);
- image_mem[x] = cvCloneImage(image_copy_old);
+ image_mem[x] = cvCloneImage(image_copy_tmp);
}
static void img_iface_load_mem (void *data)
{
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Load from memory");
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-
/* Which memory to use */
int x;
if (!data) {
@@ -1044,15 +1034,12 @@ 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] = 0;
+ user_iface_log.lvl[user_iface_log.len] = 1;
(user_iface_log.len)++;
- /* Apply changes before saving */
- img_iface_apply();
-
/* Write into ref */
cvReleaseImage(&image_ref);
- image_ref = cvCloneImage(image_copy_old);
+ image_ref = cvCloneImage(image_copy_tmp);
}
/* save ----------------------------------------------------------------------*/
@@ -1060,22 +1047,13 @@ static void img_iface_save_file (void)
{
/* Write into log */
snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Save to file");
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-
- /* Apply changes before saving */
- img_iface_apply();
-
- /* 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) */
cvReleaseImage(&image);
- image = cvCloneImage(image_copy_old);
+ image = cvCloneImage(image_copy_tmp);
/* Save into file */
save_image_file();
diff --git a/modules/image/src/img_orb.cpp b/modules/image/src/img_orb.cpp
index 8efe136..2b2612a 100644
--- a/modules/image/src/img_orb.cpp
+++ b/modules/image/src/img_orb.cpp
@@ -74,14 +74,19 @@ static void img_orb_align (struct _IplImage *img_ref,
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);
-/* class cv::Ptr <class cv::Feature2D> orb;
+#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 */
std::vector <struct cv::DMatch> matches;
diff --git a/modules/menu/src/menu_tui.c b/modules/menu/src/menu_tui.c
index 327ea11..c3186d8 100644
--- a/modules/menu/src/menu_tui.c
+++ b/modules/menu/src/menu_tui.c
@@ -6,24 +6,26 @@
/******************************************************************************
******* headers **************************************************************
******************************************************************************/
-/* * * * * * * * * *
- * * * Standard * * * * * *
- * * * * * * * * * */
+/* Standard C ----------------------------------------------------------------*/
#include <ncurses.h>
#include <stdbool.h>
-/* * * * * * * * * *
- * * * Other * * * * * * *
- * * * * * * * * * */
+/* libalx --------------------------------------------------------------------*/
#include "alx_ncur.h"
+/* Project -------------------------------------------------------------------*/
/* printf_share_file() */
#include "about.h"
+ /* proc_debug */
+ #include "proc.h"
/* saved_name */
#include "save.h"
/* start_switch() */
#include "start.h"
+ /* user_iface_log */
+ #include "user_iface.h"
+/* Module --------------------------------------------------------------------*/
#include "menu_tui.h"
@@ -32,6 +34,7 @@
******************************************************************************/
static void menu_tui_continue (void);
static void menu_tui_select (void);
+static void menu_tui_devel (void);
/******************************************************************************
@@ -44,8 +47,8 @@ void menu_tui (void)
/* Menu dimensions & options */
int h;
int w;
- h = 10;
- w = 34;
+ h = 24;
+ w = 80;
int N;
N = 4;
struct Alx_Menu mnu[4] = {
@@ -104,16 +107,17 @@ static void menu_tui_continue (void)
int w;
int r;
int c;
- h = 12;
- w = 50;
+ h = 24;
+ w = 80;
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] = {
+ {7, 4, "[0] Back"},
{2, 4, "[1] Start"},
- {3, 4, "[2] Change file name"}
+ {3, 4, "[2] Change file name"},
+ {5, 4, "[3] DEVEL"}
};
/* Input box */
@@ -155,10 +159,77 @@ static void menu_tui_continue (void)
txt[0], NULL);
alx_win_del(win);
break;
+
+ case 3:
+ alx_win_del(win);
+ menu_tui_devel();
+ break;
}
}
}
+static void menu_tui_devel (void)
+{
+ WINDOW *win;
+ int h;
+ int w;
+ int r;
+ int c;
+ h = 24;
+ w = 80;
+ r = 1;
+ c = (80 - w) / 2;
+ int N;
+ N = 3;
+ struct Alx_Menu mnu[3] = {
+ {5, 4, "[0] Back"},
+ {2, 4, "[1] Change process mode"},
+ {3, 4, "[2] Change log 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"
+ };
+
+ /* 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;
+ }
+ }
+
+ /* Cleanup */
+ alx_win_del(win);
+}
+
/******************************************************************************
******* end of file **********************************************************
diff --git a/modules/menu/src/parser.c b/modules/menu/src/parser.c
index 1ee2d5d..1dfd64d 100644
--- a/modules/menu/src/parser.c
+++ b/modules/menu/src/parser.c
@@ -122,7 +122,7 @@ static void parse_file (char* argument)
fclose(fp);
sprintf(saved_path, "");
- snprintf(saved_name, FILENAME_MAX, argument);
+ snprintf(saved_name, FILENAME_MAX, "%s", argument);
}
}
diff --git a/modules/menu/tmp/Makefile b/modules/menu/tmp/Makefile
index 8165d6a..e017159 100644
--- a/modules/menu/tmp/Makefile
+++ b/modules/menu/tmp/Makefile
@@ -8,6 +8,7 @@ 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/
@@ -58,19 +59,25 @@ MENUCLUI_INC_DIRS = -I $(INC_DIR) \
MENUTUI_INC_LIBALX = alx_ncur.h
MENUTUI_INC_ABOUT = about.h
MENUTUI_INC_CTRL = start.h
+MENUTUI_INC_PROC = proc.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 %,$(SAVE_INC_DIR)/%,$(MENUTUI_INC_SAVE))
+ $(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 $(SAVE_INC_DIR)
+ -I $(PROC_INC_DIR) \
+ -I $(SAVE_INC_DIR) \
+ -I $(USR_INC_DIR)
# target: dependencies
# action
diff --git a/modules/proc/inc/proc.h b/modules/proc/inc/proc.h
index 132df3e..3b1b9e9 100644
--- a/modules/proc/inc/proc.h
+++ b/modules/proc/inc/proc.h
@@ -26,10 +26,26 @@
******* enums ****************************************************************
******************************************************************************/
enum Proc_Mode {
- PROC_FOO,
+ PROC_MODE_FOO,
PROC_MODE = 0x4000,
- PROC_MODE_ETIQUETA
+ PROC_MODE_LABEL
+ };
+
+ enum Proc_DBG {
+ PROC_DBG_NO,
+ PROC_DBG_STOP_PROD,
+ PROC_DBG_DELAY_STEP,
+ PROC_DBG_STOP_STEP
+ };
+
+ enum Proc_Label {
+ LABEL_OK,
+ LABEL_NOK_LABEL,
+ LABEL_NOK_CERDO,
+ LABEL_NOK_BCODE,
+ LABEL_NOK_PRODUCT,
+ LABEL_NOK_PRICE
};
@@ -41,6 +57,7 @@
/******************************************************************************
******* variables ************************************************************
******************************************************************************/
+extern int proc_debug;
/******************************************************************************
diff --git a/modules/proc/src/proc.c b/modules/proc/src/proc.c
index ea065b6..fa263b7 100644
--- a/modules/proc/src/proc.c
+++ b/modules/proc/src/proc.c
@@ -34,22 +34,12 @@
/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
- # define OK (0)
- # define NOK_LABEL (1)
- # define NOK_CERDO (2)
- # define NOK_BCODE (3)
- # define NOK_PRODUCT (4)
- # define NOK_PRICE (5)
-
- # define show (false)
- # define pause (false)
-
-
-/******************************************************************************
******* variables ************************************************************
******************************************************************************/
+/* Global --------------------------------------------------------------------*/
+ int proc_debug;
+
+/* Static --------------------------------------------------------------------*/
static struct _IplImage *imgptr;
static struct CvMemStorage *proc_storage;
@@ -95,7 +85,7 @@ int proc_iface (int proc_mode)
/* Process */
switch (proc_mode) {
- case PROC_MODE_ETIQUETA:
+ case PROC_MODE_LABEL:
error = proc_etiqueta();
break;
}
@@ -109,7 +99,7 @@ int proc_iface (int proc_mode)
/* Write time into log */
snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
"Time: %.3lf", time_tot);
- user_iface_log.lvl[user_iface_log.len] = 2;
+ user_iface_log.lvl[user_iface_log.len] = 0;
(user_iface_log.len)++;
return error;
@@ -123,7 +113,7 @@ static int proc_etiqueta (void)
{
int status;
- char price [6];
+ char price [80];
struct CvSeq *et_contours;
int et_contours_n;
@@ -153,7 +143,7 @@ static int proc_etiqueta (void)
/* If no contour is found, error: NOK_LABEL */
if (!et_contours) {
- status = NOK_LABEL;
+ status = LABEL_NOK_LABEL;
result_etiqueta(status);
return status;
}
@@ -193,7 +183,7 @@ static int proc_etiqueta (void)
cerdo_nok = strncmp(img_ocr_text, "Cerdo",
strlen("Cerdo"));
if (cerdo_nok) {
- status = NOK_CERDO;
+ status = LABEL_NOK_CERDO;
result_etiqueta(status);
return status;
}
@@ -206,7 +196,7 @@ static int proc_etiqueta (void)
/* Check that 1 and only 1 bcode is read. */
if (zb_codes.n != 1) {
- status = NOK_BCODE;
+ status = LABEL_NOK_BCODE;
result_etiqueta(status);
return status;
}
@@ -217,7 +207,7 @@ static int proc_etiqueta (void)
prod_nok = strncmp(zb_codes.arr[0].data, "2301703",
strlen("2301703"));
if (prod_nok) {
- status = NOK_PRODUCT;
+ status = LABEL_NOK_PRODUCT;
result_etiqueta(status);
return status;
}
@@ -241,13 +231,13 @@ static int proc_etiqueta (void)
/* Extract price from barcode */
{
if (zb_codes.arr[0].data[8] != '0') {
- snprintf(price, 6, "%c%c.%c%c€",
+ 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, 6, "%c.%c%c€",
+ snprintf(price, 80, "%c.%c%c€",
zb_codes.arr[0].data[9],
zb_codes.arr[0].data[10],
zb_codes.arr[0].data[11]);
@@ -258,13 +248,13 @@ static int proc_etiqueta (void)
bool price_nok;
price_nok = strncmp(img_ocr_text, price, strlen(price));
if (price_nok) {
- status = NOK_PRICE;
+ status = LABEL_NOK_PRICE;
result_etiqueta(status);
return status;
}
}
- status = OK;
+ status = LABEL_OK;
result_etiqueta(status);
return status;
}
@@ -277,27 +267,27 @@ static void result_etiqueta (int status)
/* Write result into log */
char result [LOG_LINE_LEN];
switch (status) {
- case OK:
+ case LABEL_OK:
snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
"Label: OK");
break;
- case NOK_LABEL:
+ case LABEL_NOK_LABEL:
snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
"Label: NOK_LABEL");
break;
- case NOK_CERDO:
+ case LABEL_NOK_CERDO:
snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
"Label: NOK_CERDO");
break;
- case NOK_BCODE:
+ case LABEL_NOK_BCODE:
snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
"Label: NOK_BCODE");
break;
- case NOK_PRODUCT:
+ case LABEL_NOK_PRODUCT:
snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
"Label: NOK_PRODUCT");
break;
- case NOK_PRICE:
+ case LABEL_NOK_PRICE:
snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
"Label: NOK_PRICE");
break;
@@ -306,7 +296,7 @@ static void result_etiqueta (int status)
"Label: NOK");
break;
}
- user_iface_log.lvl[user_iface_log.len] = 1;
+ user_iface_log.lvl[user_iface_log.len] = 0;
(user_iface_log.len)++;
}
@@ -445,14 +435,15 @@ static void proc_zbar (int type)
static void proc_show_img (void)
{
- if (show) {
+ if (proc_debug >= PROC_DBG_DELAY_STEP) {
imgptr = img_iface_show();
/* Display image and do NOT wait for any key to continue */
cvShowImage(WIN_NAME, imgptr);
cvWaitKey(WIN_TIMEOUT);
- }
- if (pause) {
- getchar();
+
+ if (proc_debug >= PROC_DBG_STOP_STEP) {
+ getchar();
+ }
}
}
diff --git a/modules/save/src/save.c b/modules/save/src/save.c
index 88f4898..71529ad 100644
--- a/modules/save/src/save.c
+++ b/modules/save/src/save.c
@@ -6,28 +6,30 @@
/******************************************************************************
******* headers **************************************************************
******************************************************************************/
-/* * * * * * * * * *
- * * * Standard * * * * * *
- * * * * * * * * * */
- /* opencv */
- #include <cv.h>
- /* cvLoadImage & cvSaveImage */
- #include <highgui.h>
+/* Standard C ----------------------------------------------------------------*/
/* errno */
#include <errno.h>
/* fscanf() & fprintf() & FILE & FILENAME_MAX & snprintf() */
#include <stdio.h>
/* getenv() */
#include <stdlib.h>
+
+/* Linux ---------------------------------------------------------------------*/
/* mkdir */
#include <sys/stat.h>
-/* * * * * * * * * *
- * * * Other * * * * * * *
- * * * * * * * * * */
+/* Packages ------------------------------------------------------------------*/
+ /* opencv */
+ #include <opencv/cv.h>
+ /* cvLoadImage & cvSaveImage */
+ #include <opencv/highgui.h>
+// #include <opencv2/imgcodecs/imgcodecs_c.h>
+
+/* Project -------------------------------------------------------------------*/
/* user_iface_save_name() */
#include "user_iface.h"
+/* Module --------------------------------------------------------------------*/
#include "save.h"
@@ -61,7 +63,7 @@ void save_init (void)
switch (errno) {
case EACCES:
printf("err = EACCES");
- exit(EXIT_FAILURE);
+// exit(EXIT_FAILURE);
break;
case EEXIST:
@@ -70,7 +72,7 @@ void save_init (void)
default:
printf("WTF?!");
- exit(EXIT_FAILURE);
+// exit(EXIT_FAILURE);
}
}
}
@@ -91,12 +93,13 @@ void load_image_file (void)
snprintf(file_name, FILENAME_MAX, "%s/%s", saved_path, saved_name);
/* Load image */
- image = cvLoadImage(file_name, CV_LOAD_IMAGE_COLOR);
+// image = cvLoadImage(file_name, CV_LOAD_IMAGE_COLOR);
+ image = cvvLoadImage(file_name);
/* Manage load error */
if (!image) {
printf("Could not load file: %s\n", file_name);
- exit(0);
+// exit(0);
}
}
diff --git a/modules/user/inc/user_iface.h b/modules/user/inc/user_iface.h
index 5b26705..a1d1b79 100644
--- a/modules/user/inc/user_iface.h
+++ b/modules/user/inc/user_iface.h
@@ -80,7 +80,7 @@
USER_IFACE_ACT_SAVE_FILE,
USER_IFACE_ACT_PROC = 0x4000,
- USER_IFACE_ACT_PROC_ETIQUETA,
+ USER_IFACE_ACT_PROC_LABEL,
USER_IFACE_ACT_USRI = 0x8000,
USER_IFACE_ACT_SHOW_OCR,
@@ -95,6 +95,7 @@
int len;
char line [LOG_LEN] [LOG_LINE_LEN];
int lvl [LOG_LEN];
+ int visible;
};
diff --git a/modules/user/inc/user_iface.hpp b/modules/user/inc/user_iface.hpp
index 6d290d6..33a2349 100644
--- a/modules/user/inc/user_iface.hpp
+++ b/modules/user/inc/user_iface.hpp
@@ -87,7 +87,7 @@ extern "C" {
USER_IFACE_ACT_SAVE_FILE,
USER_IFACE_ACT_PROC = 0x4000,
- USER_IFACE_ACT_PROC_ETIQUETA,
+ USER_IFACE_ACT_PROC_LABEL,
USER_IFACE_ACT_USRI = 0x8000,
USER_IFACE_ACT_SHOW_OCR,
@@ -102,6 +102,7 @@ extern "C" {
int len;
char line [LOG_LEN] [LOG_LINE_LEN];
int lvl [LOG_LEN];
+ int visible;
};
diff --git a/modules/user/src/user_iface.c b/modules/user/src/user_iface.c
index da8fe98..d1cc4ff 100644
--- a/modules/user/src/user_iface.c
+++ b/modules/user/src/user_iface.c
@@ -6,24 +6,22 @@
/******************************************************************************
******* headers **************************************************************
******************************************************************************/
-/* * * * * * * * * *
- * * * Standard * * * * * *
- * * * * * * * * * */
+/* Standard C ----------------------------------------------------------------*/
+ /* snprintf() & fflush() */
+ #include <stdio.h>
+
+/* Packages ------------------------------------------------------------------*/
/* opencv */
#include <cv.h>
- /* opencv gui */
#include <highgui.h>
- /* snprintf() & fflush() */
- #include <stdio.h>
-/* * * * * * * * * *
- * * * Other * * * * * * *
- * * * * * * * * * */
+/* Project -------------------------------------------------------------------*/
/* img_iface_act() */
#include "img_iface.h"
/* proc_iface() */
#include "proc.h"
+/* Module --------------------------------------------------------------------*/
/* user_clui() & ...save_name() */
#include "user_clui.h"
/* user_tui() & ...init() & ...cleanup() & ...save_name() */
@@ -48,7 +46,7 @@ struct User_Iface_Log user_iface_log;
/******************************************************************************
******* static functions *****************************************************
******************************************************************************/
-struct _IplImage *user_iface_act (int action);
+struct _IplImage *user_iface_act (int action);
void user_iface_show_ocr (void);
diff --git a/modules/user/src/user_tui.c b/modules/user/src/user_tui.c
index 9321da1..c127b77 100644
--- a/modules/user/src/user_tui.c
+++ b/modules/user/src/user_tui.c
@@ -185,8 +185,14 @@ static void log_loop (void)
l_0 = 0;
}
- for (i = i_0, l = l_0; i < user_iface_log.len; i++, l++) {
- mvwprintw(win_log, (1 + l), (1 + 4 * user_iface_log.lvl[i]), user_iface_log.line[i]);
+ 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]),
+ user_iface_log.line[i]);
+ l++;
+ }
}
}
@@ -222,7 +228,7 @@ static int usr_input (void)
switch (ch) {
case '0':
- action = USER_IFACE_ACT_PROC_ETIQUETA;
+ action = USER_IFACE_ACT_PROC_LABEL;
break;
}
break;