summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralex <alex@ASUS>2018-10-20 15:45:43 +0200
committeralex <alex@ASUS>2018-10-20 15:45:43 +0200
commite9ea8b1725a2deac000c03aa596851c9f3a28d74 (patch)
treeecb7f2d58a37d1f7938160aa2d9dc570b733a60d
parent8d4fa231c1d13a281b61018f3d34f755bcf0129c (diff)
Use C++ API of openCV instead of the deprecated C API
-rw-r--r--.gitignore2
-rw-r--r--Makefile19
-rw-r--r--bin/Makefile4
-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.c17
-rw-r--r--modules/image/inc/img_cv.hpp (renamed from modules/image/inc/img_cv.h)10
-rw-r--r--modules/image/inc/img_iface.h109
-rw-r--r--modules/image/inc/img_iface.hpp71
-rw-r--r--modules/image/inc/img_ocr.h9
-rw-r--r--modules/image/inc/img_ocr.hpp (renamed from modules/image/inc/img_orb.h)35
-rw-r--r--modules/image/inc/img_orb.hpp6
-rw-r--r--modules/image/inc/img_zbar.hpp (renamed from modules/image/inc/img_zbar.h)6
-rw-r--r--modules/image/src/img_cv.c518
-rw-r--r--modules/image/src/img_cv.cpp400
-rw-r--r--modules/image/src/img_iface.cpp (renamed from modules/image/src/img_iface.c)279
-rw-r--r--modules/image/src/img_ocr.c32
-rw-r--r--modules/image/src/img_ocr.cpp111
-rw-r--r--modules/image/src/img_orb.cpp60
-rw-r--r--modules/image/src/img_zbar.cpp (renamed from modules/image/src/img_zbar.c)64
-rw-r--r--modules/image/tmp/Makefile36
-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.h29
-rw-r--r--modules/proc/inc/proc.hpp77
-rw-r--r--modules/proc/src/proc.cpp (renamed from modules/proc/src/proc.c)221
-rw-r--r--modules/proc/tmp/Makefile12
-rw-r--r--modules/save/inc/save.h22
-rw-r--r--modules/save/inc/save.hpp14
-rw-r--r--modules/save/src/save.cpp (renamed from modules/save/src/save.c)55
-rw-r--r--modules/save/tmp/Makefile10
-rw-r--r--modules/user/inc/user_iface.h41
-rw-r--r--modules/user/inc/user_iface.hpp37
-rw-r--r--modules/user/src/user_iface.c47
-rw-r--r--modules/user/src/user_tui.c20
38 files changed, 1266 insertions, 1300 deletions
diff --git a/.gitignore b/.gitignore
index bd81bcb..cbfb8fe 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,3 @@
*.o
*.s
-bin/vision-artificial
+bin/vision-artificial2
diff --git a/Makefile b/Makefile
index 7bb03eb..b1b95b0 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
#!/usr/bin/make -f
-VERSION = 0
-PATCHLEVEL = .6
+VERSION = 2
+PATCHLEVEL = ~a1
SUBLEVEL =
EXTRAVERSION =
NAME =
@@ -101,7 +101,7 @@ export SHARE_DIR
################################################################################
# executables
-BIN_NAME = vision-artificial
+BIN_NAME = vision-artificial2
export BIN_NAME
@@ -120,10 +120,14 @@ export LD
# cflags
CFLAGS_STD = -std=c11
+CFLAGS_W = -Wno-format-truncation
+CFLAGS_W += -Wno-format-zero-length
+
CFLAGS_PKG = `pkg-config --cflags ncurses`
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_D = -D 'PROG_VERSION="$(PROGRAMVERSION)"'
CFLAGS_D += -D 'INSTALL_SHARE_DIR="$(INSTALL_SHARE_DIR)"'
@@ -131,7 +135,7 @@ 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_PKG) $(CFLAGS_D)
+CFLAGS = $(CFLAGS_STD) $(CFLAGS_W) $(CFLAGS_PKG) $(CFLAGS_D)
export CFLAGS
@@ -139,10 +143,14 @@ export CFLAGS
# c++flags
CXXFLAGS_STD = -std=c++17
+CXXFLAGS_W = -Wno-format-truncation
+CXXFLAGS_W += -Wno-format-zero-length
+
CXXFLAGS_PKG = `pkg-config --cflags ncurses`
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_D = -D 'PROG_VERSION="$(PROGRAMVERSION)"'
CXXFLAGS_D += -D 'INSTALL_SHARE_DIR="$(INSTALL_SHARE_DIR)"'
@@ -150,7 +158,7 @@ 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_PKG) $(CXXFLAGS_D)
+CXXFLAGS = $(CXXFLAGS_STD) $(CXXFLAGS_W) $(CXXFLAGS_PKG) $(CXXFLAGS_D)
export CXXFLAGS
@@ -160,6 +168,7 @@ LIBS_PKG = `pkg-config --libs ncurses`
LIBS_PKG += `pkg-config --libs opencv`
LIBS_PKG += `pkg-config --libs zbar`
LIBS_PKG += `pkg-config --libs tesseract`
+LIBS_PKG += `pkg-config --libs lept`
LIBS = $(LIBS_PKG)
diff --git a/bin/Makefile b/bin/Makefile
index f2b10ca..5965246 100644
--- a/bin/Makefile
+++ b/bin/Makefile
@@ -8,8 +8,6 @@ MODULES_TMP_DIR = $(MODULES_DIR)/tmp/
TMP_DIR = $(MAIN_DIR)/tmp/
# dependencies
-_ALL = vision-artificial
-
ALL = $(BIN_NAME)
MAIN_OBJ_LIBALX = alx_lib.o
@@ -33,7 +31,7 @@ $(BIN_NAME): $(MAIN_OBJS)
clean:
- $(Q)rm -f $(_ALL)
+ $(Q)rm -f $(ALL)
@echo "Clean binaries"
################################################################################
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..12be0df 100644
--- a/modules/ctrl/src/start.c
+++ b/modules/ctrl/src/start.c
@@ -6,22 +6,17 @@
/******************************************************************************
******* headers **************************************************************
******************************************************************************/
-/* * * * * * * * * *
- * * * Standard * * * * * *
- * * * * * * * * * */
- /* opencv */
- #include <cv.h>
+/* Standard C ----------------------------------------------------------------*/
/* errno */
#include <errno.h>
-/* * * * * * * * * *
- * * * Other * * * * * * *
- * * * * * * * * * */
+/* Project -------------------------------------------------------------------*/
/* img_iface_load() */
#include "img_iface.h"
/* user_iface() */
#include "user_iface.h"
+/* Module --------------------------------------------------------------------*/
#include "start.h"
@@ -30,14 +25,12 @@
******************************************************************************/
void start_switch (void)
{
- struct _IplImage *imgptr;
-
errno = 0;
- imgptr = img_iface_load();
+ img_iface_load();
if (!errno) {
user_iface_init();
- user_iface(imgptr);
+ user_iface();
user_iface_cleanup();
}
diff --git a/modules/image/inc/img_cv.h b/modules/image/inc/img_cv.hpp
index ee2adb7..9d850ca 100644
--- a/modules/image/inc/img_cv.h
+++ b/modules/image/inc/img_cv.hpp
@@ -13,8 +13,8 @@
/******************************************************************************
******* headers **************************************************************
******************************************************************************/
- /* struct IplImage */
- #include <cv.h>
+ /* openCV */
+ #include <opencv2/opencv.hpp>
/******************************************************************************
@@ -37,16 +37,14 @@
IMG_CV_ACT_MIN_AREA_RECT,
IMG_CV_ACT_ROTATE_ORTO,
IMG_CV_ACT_ROTATE,
- IMG_CV_ACT_SET_ROI,
- IMG_CV_ACT_RESET_ROI,
- IMG_CV_ACT_CROP
+ IMG_CV_ACT_SET_ROI
};
/******************************************************************************
******* functions ************************************************************
******************************************************************************/
-void img_cv_act (struct _IplImage **imgptr2, int action, void *data);
+void img_cv_act (class cv::Mat *imgptr, int action, void *data);
/******************************************************************************
diff --git a/modules/image/inc/img_iface.h b/modules/image/inc/img_iface.h
index 2ff4802..6b1311d 100644
--- a/modules/image/inc/img_iface.h
+++ b/modules/image/inc/img_iface.h
@@ -11,16 +11,9 @@
/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Packages ------------------------------------------------------------------*/
- /* struct _IplImage */
- #include <cv.h>
-
-
-/******************************************************************************
******* macros ***************************************************************
******************************************************************************/
+/* Constants -----------------------------------------------------------------*/
# define CONTOURS_MAX (65536)
# define OCR_TEXT_MAX (1048576)
# define ZB_CODES_MAX (10)
@@ -28,6 +21,9 @@
# define IMG_IFACE_THR_OTSU (-1)
+/* Functions -----------------------------------------------------------------*/
+ # define img_iface_act_nodata(x) img_iface_act(x, NULL);
+
/******************************************************************************
******* enums ****************************************************************
@@ -50,8 +46,6 @@
IMG_IFACE_ACT_ROTATE_ORTO,
IMG_IFACE_ACT_ROTATE,
IMG_IFACE_ACT_SET_ROI,
- IMG_IFACE_ACT_RESET_ROI,
- IMG_IFACE_ACT_CROP,
IMG_IFACE_ACT_DILATE_ERODE,
IMG_IFACE_ACT_ERODE_DILATE,
@@ -83,6 +77,12 @@
IMG_IFACE_CMP_RED
};
+ 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,
@@ -98,80 +98,16 @@
/******************************************************************************
******* structs **************************************************************
******************************************************************************/
-/* img_cv --------------------------------------------------------------------*/
- struct Img_Iface_Data_Component {
- int cmp;
- };
-
- struct Img_Iface_Data_Smooth {
- int method;
- int msk_siz;
- };
-
- struct Img_Iface_Data_Threshold {
- int thr_typ;
- int thr_val;
- };
-
- struct Img_Iface_Data_Adaptive_Thr {
- int method;
- int thr_typ;
- int nbh_val;
- };
-
- struct Img_Iface_Data_Dilate_Erode {
- int i;
- };
-
- struct Img_Iface_Data_Contours {
- struct CvMemStorage **storage;
- struct CvSeq **contours;
- int *n;
- };
-
- struct Img_Iface_Data_Contours_Size {
- struct CvSeq *contours;
- int n;
- double area [CONTOURS_MAX];
- double perimeter [CONTOURS_MAX];
- };
-
- struct Img_Iface_Data_MinARect {
- struct CvSeq *contours;
- struct CvBox2D *rect;
- };
-
- struct Img_Iface_Data_Rotate_Orto {
- int n;
- };
-
- struct Img_Iface_Data_Rotate {
- struct CvPoint2D32f center;
- double angle;
- };
-
- struct Img_Iface_Data_SetROI {
- struct CvRect rect;
- };
-
-/* img_zbar -------------------------------------------------------------------*/
- struct Img_Iface_Data_Decode {
- int code_type;
- };
-
- struct Img_Iface_ZB_Codes {
- int n;
- struct {
- int 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;
};
@@ -185,11 +121,12 @@
/******************************************************************************
******* functions ************************************************************
******************************************************************************/
- void img_iface_cleanup_main (void);
- struct _IplImage *img_iface_load (void);
- void img_iface_cleanup (void);
- void img_iface_act (int action, void *data);
- struct _IplImage *img_iface_show (void);
+ void img_iface_cleanup_main (void);
+ void img_iface_load (void);
+ void img_iface_cleanup (void);
+ /* data should *always* be NULL */
+ void img_iface_act (int action, void *data);
+ void img_iface_show (void);
/******************************************************************************
diff --git a/modules/image/inc/img_iface.hpp b/modules/image/inc/img_iface.hpp
index 7b98327..5379d5e 100644
--- a/modules/image/inc/img_iface.hpp
+++ b/modules/image/inc/img_iface.hpp
@@ -14,14 +14,10 @@
******* headers **************************************************************
******************************************************************************/
/* Packages ------------------------------------------------------------------*/
- /* struct _IplImage */
+ /* opencv */
#include <opencv2/opencv.hpp>
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-extern "C" {
+ /* zbar */
+ #include <zbar.h>
/******************************************************************************
@@ -56,8 +52,6 @@ extern "C" {
IMG_IFACE_ACT_ROTATE_ORTO,
IMG_IFACE_ACT_ROTATE,
IMG_IFACE_ACT_SET_ROI,
- IMG_IFACE_ACT_RESET_ROI,
- IMG_IFACE_ACT_CROP,
IMG_IFACE_ACT_DILATE_ERODE,
IMG_IFACE_ACT_ERODE_DILATE,
@@ -89,6 +83,12 @@ extern "C" {
IMG_IFACE_CMP_RED
};
+ 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,
@@ -130,21 +130,19 @@ extern "C" {
};
struct Img_Iface_Data_Contours {
- struct CvMemStorage **storage;
- struct CvSeq **contours;
- int *n;
+ std::vector <std::vector <class cv::Point_ <int>>> *contours;
+ class cv::Mat *hierarchy;
};
struct Img_Iface_Data_Contours_Size {
- struct CvSeq *contours;
- int n;
- double area [CONTOURS_MAX];
- double perimeter [CONTOURS_MAX];
+ std::vector <std::vector <class cv::Point_ <int>>> *contours;
+ double area [CONTOURS_MAX];
+ double perimeter [CONTOURS_MAX];
};
struct Img_Iface_Data_MinARect {
- struct CvSeq *contours;
- struct CvBox2D *rect;
+ std::vector <class cv::Point_ <int>> *contour;
+ class cv::RotatedRect *rect;
};
struct Img_Iface_Data_Rotate_Orto {
@@ -152,25 +150,25 @@ extern "C" {
};
struct Img_Iface_Data_Rotate {
- struct CvPoint2D32f center;
- double angle;
+ class cv::Point_ <float> center;
+ double angle;
};
struct Img_Iface_Data_SetROI {
- struct CvRect rect;
+ class cv::Rect_ <int> rect;
};
/* img_zbar -------------------------------------------------------------------*/
struct Img_Iface_Data_Decode {
- int code_type;
+ enum zbar::zbar_symbol_type_e code_type;
};
struct Img_Iface_ZB_Codes {
int n;
struct {
- int type;
- char sym_name [80];
- char data [ZBAR_LEN_MAX];
+ enum zbar::zbar_symbol_type_e type;
+ char sym_name [80];
+ char data [ZBAR_LEN_MAX];
} arr [ZB_CODES_MAX];
};
@@ -178,10 +176,23 @@ extern "C" {
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];
@@ -191,11 +202,11 @@ extern "C" {
/******************************************************************************
******* functions ************************************************************
******************************************************************************/
- void img_iface_cleanup_main (void);
- struct _IplImage *img_iface_load (void);
- void img_iface_cleanup (void);
- void img_iface_act (int action, void *data);
- struct _IplImage *img_iface_show (void);
+ void img_iface_cleanup_main (void);
+ void img_iface_load (void);
+ void img_iface_cleanup (void);
+ void img_iface_act (int action, void *data);
+ void img_iface_show (void);
/******************************************************************************
diff --git a/modules/image/inc/img_ocr.h b/modules/image/inc/img_ocr.h
index fc9ed93..2c216ad 100644
--- a/modules/image/inc/img_ocr.h
+++ b/modules/image/inc/img_ocr.h
@@ -11,13 +11,6 @@
/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
- /* struct IplImage */
- #include <cv.h>
-
-
-/******************************************************************************
******* enums ****************************************************************
******************************************************************************/
enum Img_OCR_Action {
@@ -31,7 +24,7 @@
/******************************************************************************
******* functions ************************************************************
******************************************************************************/
-void img_ocr_act (struct _IplImage **imgptr2, int action, void *data);
+void img_ocr_act (int action, void *data);
/******************************************************************************
diff --git a/modules/image/inc/img_orb.h b/modules/image/inc/img_ocr.hpp
index 51bce1e..723588e 100644
--- a/modules/image/inc/img_orb.h
+++ b/modules/image/inc/img_ocr.hpp
@@ -6,40 +6,43 @@
/******************************************************************************
******* include guard ********************************************************
******************************************************************************/
-# ifndef VA_IMG_ORB_H
- # define VA_IMG_ORB_H
+# ifndef VA_IMG_OCR_HPP
+ # define VA_IMG_OCR_HPP
/******************************************************************************
- ******* headers **************************************************************
+ ******* enums ****************************************************************
******************************************************************************/
-/* Packages ------------------------------------------------------------------*/
- /* struct _IplImage */
- #include <cv.h>
+ enum Img_OCR_Action {
+ IMG_OCR_ACT_FOO = 0,
+
+ IMG_OCR_ACT_OCR = 0x0400,
+ IMG_OCR_ACT_READ
+ };
/******************************************************************************
- ******* enums ****************************************************************
+ ******* C wrapper ************************************************************
******************************************************************************/
- enum Img_ORB_Action {
- IMG_ORB_ACT_FOO = 0,
-
- IMG_ORB_ACT_ORB = 0x0800,
- IMG_ORB_ACT_ALIGN
- };
+extern "C" {
/******************************************************************************
******* functions ************************************************************
******************************************************************************/
- void img_orb_act (struct _IplImage *pattern,
- struct _IplImage **imgptr2, int action);
+ void img_ocr_act (int action, void *data);
+
+
+/******************************************************************************
+ ******* C wrapper ************************************************************
+ ******************************************************************************/
+} /* extern "C" */
/******************************************************************************
******* include guard ********************************************************
******************************************************************************/
-# endif /* img_orb.h */
+# endif /* img_ocr.hpp */
/******************************************************************************
diff --git a/modules/image/inc/img_orb.hpp b/modules/image/inc/img_orb.hpp
index f4f0e0c..6138a04 100644
--- a/modules/image/inc/img_orb.hpp
+++ b/modules/image/inc/img_orb.hpp
@@ -13,7 +13,7 @@
/******************************************************************************
******* headers **************************************************************
******************************************************************************/
- /* struct IplImage */
+ /* openCV */
#include <opencv2/opencv.hpp>
@@ -37,8 +37,8 @@ extern "C" {
/******************************************************************************
******* functions ************************************************************
******************************************************************************/
-void img_orb_act (struct _IplImage *pattern,
- struct _IplImage **imgptr2, int action);
+ void img_orb_act (class cv::Mat *pattern,
+ class cv::Mat *imgptr, int action);
/******************************************************************************
diff --git a/modules/image/inc/img_zbar.h b/modules/image/inc/img_zbar.hpp
index 8ffe717..3132175 100644
--- a/modules/image/inc/img_zbar.h
+++ b/modules/image/inc/img_zbar.hpp
@@ -14,8 +14,8 @@
******* headers **************************************************************
******************************************************************************/
/* Packages ------------------------------------------------------------------*/
- /* struct _IplImage */
- #include <cv.h>
+ /* openCV */
+ #include <opencv2/opencv.hpp>
/******************************************************************************
@@ -32,7 +32,7 @@
/******************************************************************************
******* functions ************************************************************
******************************************************************************/
-void img_zb_act (struct _IplImage **imgptr2, int action, void *data);
+void img_zb_act (class cv::Mat *imgptr, int action, void *data);
/******************************************************************************
diff --git a/modules/image/src/img_cv.c b/modules/image/src/img_cv.c
deleted file mode 100644
index 6632bed..0000000
--- a/modules/image/src/img_cv.c
+++ /dev/null
@@ -1,518 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* true & false */
- #include <stdbool.h>
- /* snprintf() */
- #include <stdio.h>
-
-/* Packages ------------------------------------------------------------------*/
- /* opencv */
- #include <cv.h>
-
-/* Project -------------------------------------------------------------------*/
- /* user_iface_log */
- #include "user_iface.h"
-
-/* Module --------------------------------------------------------------------*/
- /* data */
- #include "img_iface.h"
-
- #include "img_cv.h"
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
- /* Filters */
-static void img_cv_invert (struct _IplImage *imgptr);
-static void img_cv_bgr2gray (struct _IplImage **imgptr2);
-static void img_cv_component (struct _IplImage **imgptr2, void *data);
-static void img_cv_smooth (struct _IplImage *imgptr, void *data);
-static void img_cv_threshold (struct _IplImage *imgptr, void *data);
-static void img_cv_adaptive_thr (struct _IplImage *imgptr, void *data);
-static void img_cv_dilate (struct _IplImage *imgptr, void *data);
-static void img_cv_erode (struct _IplImage *imgptr, void *data);
-static void img_cv_contours (struct _IplImage **imgptr2, void *data);
-static void img_cv_contours_size (void *data);
-static void img_cv_min_area_rect (struct _IplImage *imgptr, void *data);
-static void img_cv_rotate_orto (struct _IplImage **imgptr2, void *data);
-static void img_cv_rotate (struct _IplImage *imgptr, void *data);
-static void img_cv_set_ROI (struct _IplImage *imgptr, void *data);
-static void img_cv_reset_ROI (struct _IplImage *imgptr);
-static void img_cv_crop (struct _IplImage **imgptr2);
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void img_cv_act (struct _IplImage **imgptr2, int action, void *data)
-{
- switch (action) {
- case IMG_CV_ACT_INVERT:
- img_cv_invert(*imgptr2);
- break;
-
- case IMG_CV_ACT_BGR2GRAY:
- img_cv_bgr2gray(imgptr2);
- break;
- case IMG_CV_ACT_COMPONENT:
- img_cv_component(imgptr2, data);
- break;
-
- case IMG_CV_ACT_SMOOTH:
- img_cv_smooth(*imgptr2, data);
- break;
-
- case IMG_CV_ACT_THRESHOLD:
- img_cv_threshold(*imgptr2, data);
- break;
- case IMG_CV_ACT_ADAPTIVE_THRESHOLD:
- img_cv_adaptive_thr(*imgptr2, data);
- break;
-
- case IMG_CV_ACT_DILATE:
- img_cv_dilate(*imgptr2, data);
- break;
- case IMG_CV_ACT_ERODE:
- img_cv_erode(*imgptr2, data);
- break;
-
- case IMG_CV_ACT_CONTOURS:
- img_cv_contours(imgptr2, data);
- break;
- case IMG_CV_ACT_CONTOURS_SIZE:
- img_cv_contours_size(data);
- break;
- case IMG_CV_ACT_MIN_AREA_RECT:
- img_cv_min_area_rect(*imgptr2, data);
- break;
-
- case IMG_CV_ACT_ROTATE_ORTO:
- img_cv_rotate_orto(imgptr2, data);
- break;
- case IMG_CV_ACT_ROTATE:
- img_cv_rotate(*imgptr2, data);
- break;
-
- case IMG_CV_ACT_SET_ROI:
- img_cv_set_ROI(*imgptr2, data);
- break;
- case IMG_CV_ACT_RESET_ROI:
- img_cv_reset_ROI(*imgptr2);
- break;
- case IMG_CV_ACT_CROP:
- img_cv_crop(imgptr2);
- break;
- }
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-/* * * * * * * * * *
- * * * Filters * * * * * *
- * * * * * * * * * */
-static void img_cv_invert (struct _IplImage *imgptr)
-{
- int step;
- int chan;
- char *data;
-
- step = imgptr->widthStep;
- chan = imgptr->nChannels;
- data = imgptr->imageData;
-
- int i;
- int j;
- int k;
-
- for (i = 0; i < imgptr->height; i++) {
- for (j = 0; j < imgptr->width; j++) {
- for (k = 0; k < imgptr->nChannels; k++) {
- data[i*step + j*chan + k] =
- ~data[i*step + j*chan + k];
- }
- }
- }
-}
-
-static void img_cv_bgr2gray (struct _IplImage **imgptr2)
-{
- struct _IplImage *gray;
-
- /* Create structure for tmp */
- gray = cvCreateImage(cvGetSize(*imgptr2), (*imgptr2)->depth, 1);
-
- /* Write gray img into gray */
- cvCvtColor(*imgptr2, gray, CV_BGR2GRAY);
-
- /* Write gray into imgptr2 */
- cvReleaseImage(imgptr2);
- *imgptr2 = cvCloneImage(gray);
-
- /* clean up */
- cvReleaseImage(&gray);
-}
-
-static void img_cv_component (struct _IplImage **imgptr2, void *data)
-{
- struct _IplImage *cmp_B;
- struct _IplImage *cmp_G;
- struct _IplImage *cmp_R;
-
- /* Data */
- struct Img_Iface_Data_Component *data_cast;
- data_cast = (struct Img_Iface_Data_Component *)data;
-
- /* Color component */
- int cmp;
- cmp = data_cast->cmp;
-
- /* Create structure for tmp */
- cmp_B = cvCreateImage(cvGetSize(*imgptr2), (*imgptr2)->depth, 1);
- cmp_G = cvCreateImage(cvGetSize(*imgptr2), (*imgptr2)->depth, 1);
- cmp_R = cvCreateImage(cvGetSize(*imgptr2), (*imgptr2)->depth, 1);
-
- /* Write gray img into tmp */
- cvSplit(*imgptr2, cmp_B, cmp_G, cmp_R, NULL);
-
- /* Write tmp into imgptr2 */
- cvReleaseImage(imgptr2);
- switch (cmp) {
- case 0:
- *imgptr2 = cvCloneImage(cmp_B);
- break;
- case 1:
- *imgptr2 = cvCloneImage(cmp_G);
- break;
- case 2:
- *imgptr2 = cvCloneImage(cmp_R);
- break;
- }
-
- /* clean up */
- cvReleaseImage(&cmp_B);
- cvReleaseImage(&cmp_G);
- cvReleaseImage(&cmp_R);
-}
-
-static void img_cv_smooth (struct _IplImage *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;
- /* Mask size */
- int msk_siz;
- msk_siz = data_cast->msk_siz;
- if (!(msk_siz % 2)) {
- msk_siz++;
- }
-
- /* Write smooth img into img_smth */
- cvSmooth(imgptr, imgptr, method, msk_siz, msk_siz, 0, 0);
-}
-
-static void img_cv_threshold (struct _IplImage *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;
- }
-
- /* Write thr img into img_thr */
- cvThreshold(imgptr, imgptr, thr_val, 0xFF, thr_typ);
-}
-
-static void img_cv_adaptive_thr (struct _IplImage *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 nbh_val;
- nbh_val = data_cast->nbh_val;
- if (!(nbh_val % 2)) {
- nbh_val++;
- }
-
- /* Apply adaptive threshold */
- cvAdaptiveThreshold(imgptr, imgptr, 255, method, thr_typ, nbh_val, 0);
-}
-
-static void img_cv_dilate (struct _IplImage *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 */
- cvDilate(imgptr, imgptr, NULL, i);
-}
-
-static void img_cv_erode (struct _IplImage *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 */
- cvErode(imgptr, imgptr, NULL, i);
-}
-
-static void img_cv_contours (struct _IplImage **imgptr2, void *data)
-{
- /* 3 channels; Set to black */
- struct _IplImage *imgtmp;
- imgtmp = cvCreateImage(cvGetSize(*imgptr2), (*imgptr2)->depth, 3);
- cvSet(imgtmp, CV_RGB(0, 0, 0), NULL);
-
- /* Data */
- struct Img_Iface_Data_Contours *data_cast;
- data_cast = (struct Img_Iface_Data_Contours *)data;
-
- /* Contours */
- struct CvMemStorage **storage;
- storage = data_cast->storage;
- struct CvSeq **contours;
- contours = data_cast->contours;
- int *n;
- n = data_cast->n;
-
- /* Get contours */
- *n = cvFindContours(*imgptr2, *storage, contours, sizeof(CvContour),
- CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, cvPoint(0, 0));
-
- /* Limit n */
- if (*n > CONTOURS_MAX) {
- *n = CONTOURS_MAX;
- }
-
- /* Draw contours in color */
- cvDrawContours(imgtmp, *contours, CV_RGB(255, 0, 0), CV_RGB(0, 255, 0),
- 1, 1, 8, cvPoint(0, 0));
-
- /* imgptr2 was modified by cvFindContours */
- cvReleaseImage(imgptr2);
- *imgptr2 = cvCloneImage(imgtmp);
-
- /* clean up */
- cvReleaseImage(&imgtmp);
-}
-
-static void img_cv_contours_size (void *data)
-{
- /* Data */
- struct Img_Iface_Data_Contours_Size *data_cast;
- data_cast = (struct Img_Iface_Data_Contours_Size *)data;
-
- /* Contours */
- struct CvSeq *contours;
- contours = data_cast->contours;
- int n;
- n = data_cast->n;
-
- /* Get area and perimeter */
- int i;
- for (i = 0; i < n; i++) {
- if (!contours) {
- break;
- }
-
- data_cast->area[i] = cvContourArea(contours,
- CV_WHOLE_SEQ, false);
- data_cast->perimeter[i] = cvArcLength(contours,
- CV_WHOLE_SEQ, -1);
- contours = contours->h_next;
- }
-}
-
-static void img_cv_min_area_rect (struct _IplImage *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_MinARect *data_cast;
- data_cast = (struct Img_Iface_Data_MinARect *)data;
-
- /* Contours */
- struct CvSeq *contours;
- contours = data_cast->contours;
- /* Rotated rectangle */
- struct CvBox2D *rect;
- rect = data_cast->rect;
-
- /* Get rectangle */
- *rect = cvMinAreaRect2(contours, NULL);
-
- /* Draw rectangle */
- struct CvPoint2D32f points[4];
- cvBoxPoints(*rect, points);
- cvLine(imgptr, cvPoint(points[0].x, points[0].y),
- cvPoint(points[1].x, points[1].y), CV_RGB(0, 0, 255),
- 1, 8, 0);
- cvLine(imgptr, cvPoint(points[1].x, points[1].y),
- cvPoint(points[2].x, points[2].y), CV_RGB(0, 0, 255),
- 1, 8, 0);
- cvLine(imgptr, cvPoint(points[2].x, points[2].y),
- cvPoint(points[3].x, points[3].y), CV_RGB(0, 0, 255),
- 1, 8, 0);
- cvLine(imgptr, cvPoint(points[3].x, points[3].y),
- cvPoint(points[0].x, points[0].y), CV_RGB(0, 0, 255),
- 1, 8, 0);
-}
-
-static void img_cv_rotate_orto (struct _IplImage **imgptr2, void *data)
-{
- struct _IplImage *rotated;
-
- /* 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:
- /* Init structures */
- rotated = cvCreateImage(cvSize((*imgptr2)->height, (*imgptr2)->width),
- (*imgptr2)->depth, (*imgptr2)->nChannels);
-
- /* Rotate: transpose and flip around horizontal axis: flip_mode=0 */
- cvTranspose(*imgptr2, rotated);
- cvFlip(rotated, rotated, 0);
- break;
-
- case 2:
- /* Init structures */
- rotated = cvCreateImage(cvGetSize(*imgptr2),
- (*imgptr2)->depth, (*imgptr2)->nChannels);
-
- /* Rotate: Flip both axises: flip_mode=-1 */
- cvFlip(*imgptr2, rotated, -1);
- break;
-
- case 3:
- /* Init structures */
- rotated = cvCreateImage(cvSize((*imgptr2)->height, (*imgptr2)->width),
- (*imgptr2)->depth, (*imgptr2)->nChannels);
-
- /* Rotate: transpose and flip around vertical axis: flip_mode=1 */
- cvTranspose(*imgptr2, rotated);
- cvFlip(rotated, rotated, 1);
- break;
- }
-
- /* Write rotated into imgptr2 */
- cvReleaseImage(imgptr2);
- *imgptr2 = cvCloneImage(rotated);
-
- /* clean up */
- cvReleaseImage(&rotated);
-}
-
-static void img_cv_rotate (struct _IplImage *imgptr, void *data)
-{
- struct CvMat *map_matrix;
-
- /* Data */
- struct Img_Iface_Data_Rotate *data_cast;
- data_cast = (struct Img_Iface_Data_Rotate *)data;
-
- /* Angle of rotation */
- struct CvPoint2D32f center;
- center = data_cast->center;
- double angle;
- angle = data_cast->angle;
-
- /* Init map_matrix */
- map_matrix = cvCreateMat(2, 3, CV_32F);
-
- /* Get map_matrix */
- cv2DRotationMatrix(center, angle, 1, map_matrix);
-
- /* Rotate */
- cvWarpAffine(imgptr, imgptr, map_matrix,
- CV_INTER_LINEAR + CV_WARP_FILL_OUTLIERS, cvScalarAll(0));
-
- /* clean up */
- cvReleaseMat(&map_matrix);
-}
-
-static void img_cv_set_ROI (struct _IplImage *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_SetROI *data_cast;
- data_cast = (struct Img_Iface_Data_SetROI *)data;
-
- /* Set ROI */
- cvSetImageROI(imgptr, data_cast->rect);
-}
-
-static void img_cv_reset_ROI (struct _IplImage *imgptr)
-{
- /* Reset ROI */
- cvResetImageROI(imgptr);
-}
-
-static void img_cv_crop (struct _IplImage **imgptr2)
-{
- struct _IplImage *cropped;
-
- /* Create structure for cropped */
- cropped = cvCreateImage(cvGetSize(*imgptr2), (*imgptr2)->depth,
- (*imgptr2)->nChannels);
-
- /* Copy data */
- cvCopy(*imgptr2, cropped, NULL);
-
- /* Reset ROI */
- cvResetImageROI(cropped);
-
- /* Write cropped into imgptr2 */
- cvReleaseImage(imgptr2);
- *imgptr2 = cvCloneImage(cropped);
-
- /* clean up */
- cvReleaseImage(&cropped);
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/image/src/img_cv.cpp b/modules/image/src/img_cv.cpp
new file mode 100644
index 0000000..c653748
--- /dev/null
+++ b/modules/image/src/img_cv.cpp
@@ -0,0 +1,400 @@
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+/* Standard C ----------------------------------------------------------------*/
+ /* true & false */
+ #include <cstdbool>
+ /* snprintf() */
+ #include <cstdio>
+
+/* Packages ------------------------------------------------------------------*/
+ /* opencv */
+ #include <opencv2/opencv.hpp>
+
+/* Project -------------------------------------------------------------------*/
+ /* user_iface_log */
+ #include "user_iface.hpp"
+
+/* Module --------------------------------------------------------------------*/
+ /* data */
+ #include "img_iface.hpp"
+
+ #include "img_cv.hpp"
+
+
+/******************************************************************************
+ ******* static functions *****************************************************
+ ******************************************************************************/
+ /* Filters */
+static void img_cv_invert (class cv::Mat *imgptr);
+static void img_cv_bgr2gray (class cv::Mat *imgptr);
+static void img_cv_component (class cv::Mat *imgptr, void *data);
+static void img_cv_smooth (class cv::Mat *imgptr, void *data);
+static void img_cv_threshold (class cv::Mat *imgptr, void *data);
+static void img_cv_adaptive_thr (class cv::Mat *imgptr, void *data);
+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_contours (class cv::Mat *imgptr, void *data);
+static void img_cv_contours_size (void *data);
+static void img_cv_min_area_rect (class cv::Mat *imgptr, void *data);
+static void img_cv_rotate_orto (class cv::Mat *imgptr, void *data);
+static void img_cv_rotate (class cv::Mat *imgptr, void *data);
+static void img_cv_set_ROI (class cv::Mat *imgptr, void *data);
+
+
+/******************************************************************************
+ ******* main *****************************************************************
+ ******************************************************************************/
+void img_cv_act (class cv::Mat *imgptr, int action, void *data)
+{
+ switch (action) {
+ case IMG_CV_ACT_INVERT:
+ img_cv_invert(imgptr);
+ break;
+
+ case IMG_CV_ACT_BGR2GRAY:
+ img_cv_bgr2gray(imgptr);
+ break;
+ case IMG_CV_ACT_COMPONENT:
+ img_cv_component(imgptr, data);
+ break;
+
+ case IMG_CV_ACT_SMOOTH:
+ img_cv_smooth(imgptr, data);
+ break;
+
+ case IMG_CV_ACT_THRESHOLD:
+ img_cv_threshold(imgptr, data);
+ break;
+ case IMG_CV_ACT_ADAPTIVE_THRESHOLD:
+ img_cv_adaptive_thr(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_CONTOURS:
+ img_cv_contours(imgptr, data);
+ break;
+ case IMG_CV_ACT_CONTOURS_SIZE:
+ img_cv_contours_size(data);
+ break;
+ case IMG_CV_ACT_MIN_AREA_RECT:
+ img_cv_min_area_rect(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_SET_ROI:
+ img_cv_set_ROI(imgptr, data);
+ break;
+ }
+}
+
+
+/******************************************************************************
+ ******* static functions *****************************************************
+ ******************************************************************************/
+/* * * * * * * * * *
+ * * * Filters * * * * * *
+ * * * * * * * * * */
+static void img_cv_invert (class cv::Mat *imgptr)
+{
+ cv::bitwise_not(*imgptr, *imgptr);
+}
+
+static void img_cv_bgr2gray (class cv::Mat *imgptr)
+{
+ cv::cvtColor(*imgptr, *imgptr, cv::COLOR_BGR2GRAY, 0);
+}
+
+static void img_cv_component (class cv::Mat *imgptr, void *data)
+{
+ class cv::Mat cmp_img[3];
+
+ /* 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[] */
+ 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();
+}
+
+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;
+ /* Mask size */
+ int msk_siz;
+ msk_siz = data_cast->msk_siz;
+ if (!(msk_siz % 2)) {
+ msk_siz++;
+ }
+
+ switch (method) {
+ case IMGI_SMOOTH_MEAN:
+ cv::blur(*imgptr, *imgptr, cv::Size(msk_siz, msk_siz),
+ cv::Point(-1,-1), cv::BORDER_DEFAULT);
+ break;
+ case IMGI_SMOOTH_GAUSS:
+ cv::GaussianBlur(*imgptr, *imgptr, cv::Size(msk_siz, msk_siz),
+ 0, 0, cv::BORDER_DEFAULT);
+ break;
+ case IMGI_SMOOTH_MEDIAN:
+ cv::medianBlur(*imgptr, *imgptr, msk_siz);
+ break;
+ }
+}
+
+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);
+}
+
+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 nbh_val;
+ nbh_val = data_cast->nbh_val;
+ if (!(nbh_val % 2)) {
+ nbh_val++;
+ }
+
+ /* Apply adaptive threshold */
+ cv::adaptiveThreshold(*imgptr, *imgptr, 255, method, thr_typ, nbh_val,
+ 0);
+}
+
+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, 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, 0);
+}
+
+static void img_cv_contours (class cv::Mat *imgptr, void *data)
+{
+ /* Data */
+ struct Img_Iface_Data_Contours *data_cast;
+ data_cast = (struct Img_Iface_Data_Contours *)data;
+
+ /* Contours */
+ std::vector <std::vector <class cv::Point_ <int>>> *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);
+
+ /* Draw contours in color */
+ cv::drawContours(*imgptr, *contours, -1, cv::Scalar(255, 0, 0), 1, 8,
+ *hierarchy, 1, cvPoint(0, 0));
+}
+
+static void img_cv_contours_size (void *data)
+{
+ /* Data */
+ struct Img_Iface_Data_Contours_Size *data_cast;
+ data_cast = (struct Img_Iface_Data_Contours_Size *)data;
+
+ /* Contours */
+ std::vector <std::vector <class cv::Point_ <int>>> *contours;
+ contours = data_cast->contours;
+
+ /* Get area and perimeter */
+ int i;
+ for (i = 0; i < contours->size(); i++) {
+ data_cast->area[i] = cv::contourArea((*contours)[i], false);
+ data_cast->perimeter[i] = cv::arcLength((*contours)[i], true);
+ }
+}
+
+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 */
+ std::vector <class cv::Point_ <int>> *contour;
+ contour = data_cast->contour;
+ /* Rotated rectangle */
+ class cv::RotatedRect *rect;
+ rect = data_cast->rect;
+
+ /* Get rectangle */
+ *rect = cv::minAreaRect(*contour);
+
+ /* Draw rectangle */
+ class cv::Point_<float> vertices[4];
+ rect->points(vertices);
+ cv::line(*imgptr, cv::Point(vertices[0].x, vertices[0].y),
+ cv::Point(vertices[1].x, vertices[1].y),
+ CV_RGB(0, 0, 255), 1, 8, 0);
+ cv::line(*imgptr, cv::Point(vertices[1].x, vertices[1].y),
+ cv::Point(vertices[2].x, vertices[2].y),
+ CV_RGB(0, 0, 255), 1, 8, 0);
+ cv::line(*imgptr, cv::Point(vertices[2].x, vertices[2].y),
+ cv::Point(vertices[3].x, vertices[3].y),
+ CV_RGB(0, 0, 255), 1, 8, 0);
+ cv::line(*imgptr, cv::Point(vertices[3].x, vertices[3].y),
+ cv::Point(vertices[0].x, vertices[0].y),
+ CV_RGB(0, 0, 255), 1, 8, 0);
+}
+
+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_ <float> *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();
+}
+
+static void img_cv_set_ROI (class cv::Mat *imgptr, void *data)
+{
+ /* Data */
+ struct Img_Iface_Data_SetROI *data_cast;
+ data_cast = (struct Img_Iface_Data_SetROI *)data;
+
+ /* Rectangle */
+ class cv::Rect_ <int> *rect;
+ rect = &(data_cast->rect);
+
+ /* Set ROI */
+ *imgptr = (*imgptr)(*rect);
+}
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/modules/image/src/img_iface.c b/modules/image/src/img_iface.cpp
index d432aea..fca3191 100644
--- a/modules/image/src/img_iface.c
+++ b/modules/image/src/img_iface.cpp
@@ -7,38 +7,42 @@
******* headers **************************************************************
******************************************************************************/
/* Standard C ----------------------------------------------------------------*/
+ /* errno */
+ #include <cerrno>
/* INFINITY */
- #include <math.h>
+ #include <cmath>
/* snprintf() */
- #include <stdio.h>
+ #include <cstdio>
/* Packages ------------------------------------------------------------------*/
- /* opencv */
- #include <cv.h>
+ /* openCV */
+ #include <opencv2/opencv.hpp>
/* Project -------------------------------------------------------------------*/
/* load_image_file() */
- #include "save.h"
+ #include "save.hpp"
/* user_iface_log */
- #include "user_iface.h"
+ #include "user_iface.hpp"
/* Module --------------------------------------------------------------------*/
/* img_cv_act() */
- #include "img_cv.h"
+ #include "img_cv.hpp"
/* img_zb_act() */
- #include "img_zbar.h"
+ #include "img_zbar.hpp"
/* OCR */
- #include "img_ocr.h"
+ #include "img_ocr.hpp"
/* ORB */
- #include "img_orb.h"
+ #include "img_orb.hpp"
- #include "img_iface.h"
+ #include "img_iface.hpp"
/******************************************************************************
******* macros ***************************************************************
******************************************************************************/
# define IMG_MEM_SIZE (10)
+ # define WIN_NAME "Image"
+ # define WIN_TIMEOUT (500)
/******************************************************************************
@@ -49,15 +53,13 @@
struct Img_Iface_ZB_Codes zb_codes;
/* Static --------------------------------------------------------------------*/
-static struct _IplImage *image_copy_old;
-static struct _IplImage *image_copy_tmp;
-static struct _IplImage *image_copy_usr;
-static struct _IplImage *image_mem [IMG_MEM_SIZE];
-static struct _IplImage *image_ref;
-static struct CvMemStorage *storage;
-static struct CvSeq *contours;
-static int contours_n;
-static struct CvBox2D rectangle;
+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 std::vector <std::vector <cv::Point_ <int>>> contours;
+static class cv::Mat hierarchy;
+static class cv::RotatedRect rectangle;
/******************************************************************************
@@ -78,8 +80,6 @@ static void img_iface_min_area_rect (void *data);
static void img_iface_rotate_orto (void *data);
static void img_iface_rotate (void *data);
static void img_iface_set_ROI (void *data);
-static void img_iface_reset_ROI (void);
-static void img_iface_crop (void);
static void img_iface_dilate_erode (void *data);
static void img_iface_erode_dilate (void *data);
@@ -103,50 +103,46 @@ static void img_iface_save_file (void);
/******************************************************************************
******* main *****************************************************************
******************************************************************************/
-void img_iface_init (void)
+void img_iface_init (void)
{
- storage = cvCreateMemStorage(0);
+ cv::namedWindow(WIN_NAME, cv::WINDOW_NORMAL);
}
-void img_iface_cleanup_main (void)
+void img_iface_cleanup_main (void)
{
int i;
for (i = 0; i < IMG_MEM_SIZE; i++) {
- cvReleaseImage(&image_mem[i]);
+ image_mem[i].release();
}
- cvReleaseImage(&image_ref);
- cvReleaseMemStorage(&storage);
+ image_ref.release();
+
+ cv::destroyAllWindows();
}
-struct _IplImage *img_iface_load (void)
+void img_iface_load (void)
{
/* Init */
img_iface_init();
/* Load file */
+ errno = 0;
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);
-
- /* 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;
+ if (!errno) {
+ /* Make a static copy of image */
+ image.copyTo(image_copy_old);
+ image.copyTo(image_copy_tmp);
+ }
}
-void img_iface_cleanup (void)
+void img_iface_cleanup (void)
{
- cvReleaseImage(&image_copy_old);
- cvReleaseImage(&image_copy_tmp);
- cvReleaseImage(&image_copy_usr);
+ image_copy_old.release();
+ image_copy_tmp.release();
}
-void img_iface_act (int action, void *data)
+void img_iface_act (int action, void *data)
{
switch (action) {
/* img_cv */
@@ -192,12 +188,6 @@ void img_iface_act (int action, void *data)
case IMG_IFACE_ACT_SET_ROI:
img_iface_set_ROI(data);
break;
- case IMG_IFACE_ACT_RESET_ROI:
- img_iface_reset_ROI();
- break;
- case IMG_IFACE_ACT_CROP:
- img_iface_crop();
- break;
case IMG_IFACE_ACT_DILATE_ERODE:
img_iface_dilate_erode(data);
@@ -252,13 +242,10 @@ void img_iface_act (int action, void *data)
}
}
-struct _IplImage *img_iface_show (void)
+void img_iface_show (void)
{
- /* Make a static copy of tmp so that it isn't modified by the user */
- cvReleaseImage(&image_copy_usr);
- image_copy_usr = cvCloneImage(image_copy_tmp);
-
- return image_copy_usr;
+ cv::imshow(WIN_NAME, image_copy_tmp);
+ cv::waitKey(WIN_TIMEOUT);
}
@@ -281,11 +268,11 @@ static void img_iface_invert (void)
static void img_iface_bgr2gray (void)
{
/* Must have 3 channels */
- if (image_copy_tmp->nChannels != 3) {
+ 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] = 0;
+ user_iface_log.lvl[user_iface_log.len] = 1;
(user_iface_log.len)++;
return;
@@ -304,11 +291,11 @@ static void img_iface_bgr2gray (void)
static void img_iface_component (void *data)
{
/* Must have 3 channels */
- if (image_copy_tmp->nChannels != 3) {
+ 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] = 0;
+ user_iface_log.lvl[user_iface_log.len] = 1;
(user_iface_log.len)++;
return;
@@ -341,11 +328,11 @@ static void img_iface_component (void *data)
static void img_iface_smooth (void *data)
{
/* Must have 1 channel */
- if (image_copy_tmp->nChannels != 1) {
+ 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] = 0;
+ user_iface_log.lvl[user_iface_log.len] = 1;
(user_iface_log.len)++;
return;
@@ -357,7 +344,7 @@ static void img_iface_smooth (void *data)
/* Ask user */
char title [80];
snprintf(title, 80, "Method: MEAN=1, GAUSS=2, MEDIAN=3");
- data_tmp.method = user_iface_getint(0, 3, 4, title, NULL);
+ data_tmp.method = user_iface_getint(1, 3, 3, title, NULL);
snprintf(title, 80, "Mask size: 3, 5, 7, ...");
data_tmp.msk_siz = user_iface_getint(3, 3, INFINITY, title, NULL);
@@ -383,11 +370,11 @@ static void img_iface_smooth (void *data)
static void img_iface_threshold (void *data)
{
/* Must have 1 channel */
- if (image_copy_tmp->nChannels != 1) {
+ 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] = 0;
+ user_iface_log.lvl[user_iface_log.len] = 1;
(user_iface_log.len)++;
return;
@@ -424,11 +411,11 @@ static void img_iface_threshold (void *data)
static void img_iface_adaptive_thr (void *data)
{
/* Must have 1 channel */
- if (image_copy_tmp->nChannels != 1) {
+ 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] = 0;
+ user_iface_log.lvl[user_iface_log.len] = 1;
(user_iface_log.len)++;
return;
@@ -521,11 +508,11 @@ static void img_iface_erode (void *data)
static void img_iface_contours (void *data)
{
/* Must have 1 channel */
- if (image_copy_tmp->nChannels != 1) {
+ 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] = 0;
+ user_iface_log.lvl[user_iface_log.len] = 1;
(user_iface_log.len)++;
return;
@@ -534,13 +521,8 @@ static void img_iface_contours (void *data)
/* Data */
struct Img_Iface_Data_Contours data_tmp;
if (!data) {
- data_tmp.storage = &storage;
- cvClearMemStorage(*(data_tmp.storage));
-
data_tmp.contours = &contours;
- *(data_tmp.contours) = NULL;
-
- data_tmp.n = &contours_n;
+ data_tmp.hierarchy = &hierarchy;
data = (void *)&data_tmp;
}
@@ -552,8 +534,8 @@ static void img_iface_contours (void *data)
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",
- *(data_cast->n));
+ "Contours n=%i",
+ (int)data_cast->contours->size());
user_iface_log.lvl[user_iface_log.len] = 1;
(user_iface_log.len)++;
}
@@ -563,9 +545,7 @@ 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.n = contours_n;
+ data_tmp.contours = &contours;
data = (void *)&data_tmp;
}
@@ -577,12 +557,11 @@ 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;
- for (i = 0; i < data_cast->n; 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,
@@ -598,7 +577,7 @@ static void img_iface_min_area_rect (void *data)
/* Data */
struct Img_Iface_Data_MinARect data_tmp;
if (!data) {
- data_tmp.contours = contours;
+ data_tmp.contour = &(contours[0]);
data_tmp.rect = &rectangle;
@@ -664,7 +643,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);
@@ -684,22 +663,22 @@ static void img_iface_set_ROI (void *data)
char title [80];
snprintf(title, 80, "Origin: x:");
data_tmp.rect.x = user_iface_getint(0, 0,
- image_copy_tmp->width,
+ image_copy_tmp.cols,
title, NULL);
snprintf(title, 80, "Origin: y:");
data_tmp.rect.y = user_iface_getint(0, 0,
- image_copy_tmp->height,
+ image_copy_tmp.rows,
title, NULL);
snprintf(title, 80, "Width:");
data_tmp.rect.width = user_iface_getint(1, 1,
- image_copy_tmp->width - 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, 1,
- image_copy_tmp->height - data_tmp.rect.y,
+ image_copy_tmp.rows - data_tmp.rect.y,
title, NULL);
data = (void *)&data_tmp;
@@ -721,30 +700,6 @@ static void img_iface_set_ROI (void *data)
img_cv_act(&image_copy_tmp, IMG_CV_ACT_SET_ROI, data);
}
-static void img_iface_reset_ROI (void)
-{
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Reset ROI");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Set ROI */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_RESET_ROI, NULL);
-}
-
-static void img_iface_crop (void)
-{
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Crop");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Set ROI */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_CROP, NULL);
-}
-
static void img_iface_dilate_erode (void *data)
{
/* Data */
@@ -827,11 +782,11 @@ static void img_iface_rotate_2rect (void *data)
static void img_iface_decode (void *data)
{
/* Must have 1 channel */
- if (image_copy_tmp->nChannels != 1) {
+ 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] = 0;
+ user_iface_log.lvl[user_iface_log.len] = 1;
(user_iface_log.len)++;
return;
@@ -843,7 +798,9 @@ static void img_iface_decode (void *data)
/* Ask user */
char title [80];
snprintf(title, 80, "Type of code: (0 for all)");
- data_tmp.code_type = user_iface_getint(0, 0, INT_MAX, title, NULL);
+ data_tmp.code_type = (enum zbar::zbar_symbol_type_e)
+ user_iface_getint(0, 0, INT_MAX,
+ title, NULL);
data = (void *)&data_tmp;
}
@@ -875,7 +832,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)++;
}
}
@@ -884,6 +841,17 @@ static void img_iface_decode (void *data)
/* 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) {
@@ -908,15 +876,22 @@ 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(&image_copy_tmp, IMG_OCR_ACT_READ, data);
+ 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] = 1;
+ user_iface_log.lvl[user_iface_log.len] = 2;
(user_iface_log.len)++;
}
}
@@ -925,11 +900,11 @@ static void img_iface_read (void *data)
static void img_iface_align (void)
{
/* Must have defined a reference */
- if (!image_ref) {
+ 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] = 0;
+ user_iface_log.lvl[user_iface_log.len] = 1;
(user_iface_log.len)++;
return;
@@ -942,7 +917,7 @@ static void img_iface_align (void)
(user_iface_log.len)++;
/* Align to reference image_ref */
- img_orb_act(image_ref, &image_copy_tmp, IMG_ORB_ACT_ALIGN);
+ img_orb_act(&image_ref, &image_copy_tmp, IMG_ORB_ACT_ALIGN);
}
/* img_iface -----------------------------------------------------------------*/
@@ -951,12 +926,12 @@ 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 */
- cvReleaseImage(&image_copy_old);
- image_copy_old = cvCloneImage(image_copy_tmp);
+ image_copy_old.release();
+ image_copy_tmp.copyTo(image_copy_old);
}
static void img_iface_discard (void)
@@ -964,25 +939,16 @@ 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 */
- cvReleaseImage(&image_copy_tmp);
- image_copy_tmp = cvCloneImage(image_copy_old);
+ image_copy_tmp.release();
+ image_copy_old.copyTo(image_copy_tmp);
}
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) {
@@ -1001,18 +967,12 @@ static void img_iface_save_mem (void *data)
(user_iface_log.len)++;
/* Write into mem */
- cvReleaseImage(&image_mem[x]);
- image_mem[x] = cvCloneImage(image_copy_old);
+ image_mem[x].release();
+ image_copy_tmp.copyTo(image_mem[x]);
}
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) {
@@ -1030,12 +990,12 @@ static void img_iface_load_mem (void *data)
user_iface_log.lvl[user_iface_log.len] = 1;
(user_iface_log.len)++;
- if (image_mem[x]) {
+ if (!image_mem[x].empty()) {
/* Discard tmp image copy */
- cvReleaseImage(&image_copy_tmp);
+ image_copy_tmp.release();
/* Load from mem */
- image_copy_tmp = cvCloneImage(image_mem[x]);
+ image_mem[x].copyTo(image_copy_tmp);
}
}
@@ -1044,15 +1004,13 @@ 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.release();
+ image_copy_tmp.copyTo(image_ref);
+ image_ref = image_copy_tmp;
}
/* save ----------------------------------------------------------------------*/
@@ -1060,22 +1018,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.release();
+ image_copy_tmp.copyTo(image);
/* Save into file */
save_image_file();
diff --git a/modules/image/src/img_ocr.c b/modules/image/src/img_ocr.c
index 61dae92..b6e679a 100644
--- a/modules/image/src/img_ocr.c
+++ b/modules/image/src/img_ocr.c
@@ -13,8 +13,6 @@
#include <stdio.h>
/* Packages ------------------------------------------------------------------*/
- /* opencv */
- #include <cv.h>
/* OCR Tesseract */
#include <tesseract/capi.h>
@@ -34,17 +32,17 @@
/******************************************************************************
******* static functions *****************************************************
******************************************************************************/
-static void img_ocr_read (struct _IplImage *imgptr, void *data);
+static void img_ocr_read (void *data);
/******************************************************************************
******* main *****************************************************************
******************************************************************************/
-void img_ocr_act (struct _IplImage **imgptr2, int action, void *data)
+void img_ocr_act (int action, void *data)
{
switch (action) {
case IMG_OCR_ACT_READ:
- img_ocr_read(*imgptr2, data);
+ img_ocr_read(data);
break;
}
}
@@ -53,17 +51,18 @@ void img_ocr_act (struct _IplImage **imgptr2, int action, void *data)
/******************************************************************************
******* static functions *****************************************************
******************************************************************************/
-static void img_ocr_read (struct _IplImage *imgptr, void *data)
+static void img_ocr_read (void *data)
{
- struct _IplImage *imgtmp;
struct TessBaseAPI *handle_ocr;
- /* Make a copy of imgptr so that it isn't modified by tesseract */
- imgtmp = cvCloneImage(imgptr);
+ /* Data */
+ struct Img_Iface_Data_Read *data_cast;
+ data_cast = (struct Img_Iface_Data_Read *)data;
+
/* Language */
int lang;
char lang_str [3 + 1];
- lang = ((struct Img_Iface_Data_Read *)data)->lang;
+ lang = data_cast->lang;
switch (lang) {
case 0:
sprintf(lang_str, "eng");
@@ -79,7 +78,7 @@ static void img_ocr_read (struct _IplImage *imgptr, void *data)
/* Config file */
int conf;
char conf_str [FILENAME_MAX];
- conf = ((struct Img_Iface_Data_Read *)data)->conf;
+ conf = data_cast->conf;
switch (conf) {
case 1:
sprintf(conf_str, "%s/%s", share_path, "price");
@@ -88,16 +87,18 @@ static void img_ocr_read (struct _IplImage *imgptr, void *data)
/* init OCR */
handle_ocr = TessBaseAPICreate();
- TessBaseAPIInit3(handle_ocr, NULL, lang_str);
+ TessBaseAPIInit2(handle_ocr, NULL, lang_str,
+ OEM_CUBE_ONLY);
if (conf) {
/* Configure OCR (whitelist chars) */
TessBaseAPIReadConfigFile(handle_ocr, conf_str);
}
/* scan image for text */
- TessBaseAPISetImage(handle_ocr, imgtmp->imageData,
- imgtmp->width, imgtmp->height,
- imgtmp->depth / 8, imgtmp->widthStep);
+ 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);
@@ -109,7 +110,6 @@ static void img_ocr_read (struct _IplImage *imgptr, void *data)
TessDeleteText(txt);
TessBaseAPIEnd(handle_ocr);
TessBaseAPIDelete(handle_ocr);
- cvReleaseImage(&imgtmp);
}
diff --git a/modules/image/src/img_ocr.cpp b/modules/image/src/img_ocr.cpp
new file mode 100644
index 0000000..565c29a
--- /dev/null
+++ b/modules/image/src/img_ocr.cpp
@@ -0,0 +1,111 @@
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+/* Standard C ----------------------------------------------------------------*/
+ /* snprintf() & FILENAME_MAX */
+ #include <cstdio>
+
+/* Packages ------------------------------------------------------------------*/
+ /* opencv */
+ #include <opencv2/opencv.hpp>
+ /* OCR Tesseract */
+ #include <tesseract/baseapi.h>
+ #include <leptonica/allheaders.h>
+
+/* Project -------------------------------------------------------------------*/
+ /* user_iface_log */
+ #include "user_iface.hpp"
+ /* share_path */
+ #include "about.hpp"
+
+/* Module --------------------------------------------------------------------*/
+ /* data & img_ocr_text & OCR_TEXT_MAX */
+ #include "img_iface.hpp"
+
+ #include "img_ocr.hpp"
+
+
+/******************************************************************************
+ ******* static functions *****************************************************
+ ******************************************************************************/
+static void img_ocr_read (class cv::Mat *imgptr, void *data);
+
+
+/******************************************************************************
+ ******* main *****************************************************************
+ ******************************************************************************/
+void img_ocr_act (class cv::Mat *imgptr, int action, void *data)
+{
+ switch (action) {
+ case IMG_OCR_ACT_READ:
+ img_ocr_read(imgptr, data);
+ break;
+ }
+}
+
+
+/******************************************************************************
+ ******* static functions *****************************************************
+ ******************************************************************************/
+static void img_ocr_read (class cv::Mat *imgptr, void *data)
+{
+ class tesseract::TessBaseAPI *handle_ocr;
+
+ /* Language */
+ int lang;
+ char lang_str [3 + 1];
+ lang = ((struct Img_Iface_Data_Read *)data)->lang;
+ switch (lang) {
+ case 0:
+ sprintf(lang_str, "eng");
+ break;
+ case 1:
+ sprintf(lang_str, "spa");
+ break;
+ case 2:
+ sprintf(lang_str, "cat");
+ break;
+ }
+
+ /* Config file */
+ int conf;
+ char conf_str [FILENAME_MAX];
+ conf = ((struct Img_Iface_Data_Read *)data)->conf;
+ switch (conf) {
+ case 1:
+ sprintf(conf_str, "%s/%s", share_path, "price");
+ break;
+ }
+
+ /* init OCR */
+ handle_ocr = new tesseract::TessBaseApi();
+ handle_ocr->Init(NULL, lang_str, tesseract::OEM_TESSERACT_CUBE_COMBINED);
+ if (conf) {
+ /* Configure OCR (whitelist chars) */
+ handle_ocr->ReadConfigFile(conf_str);
+ }
+
+ /* scan image for text */
+ handle_ocr->SetImage(imgptr->data, imgptr->cols, imgptr->rows,
+ imgptr->depth() / 8, imgptr->step);
+ char *txt;
+ txt = handle_ocr->GetUTF8Text();
+
+ /* Copy text to global variable */
+ snprintf(img_ocr_text, OCR_TEXT_MAX, "%s", txt);
+
+ /* cleanup */
+ delete [] txt;
+ handle_ocr->Clear();
+ handle_ocr->End();
+}
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/modules/image/src/img_orb.cpp b/modules/image/src/img_orb.cpp
index 8efe136..c4f7526 100644
--- a/modules/image/src/img_orb.cpp
+++ b/modules/image/src/img_orb.cpp
@@ -36,19 +36,19 @@
/******************************************************************************
******* static functions *****************************************************
******************************************************************************/
-static void img_orb_align (struct _IplImage *img_ref,
- struct _IplImage **imgptr2);
+static void img_orb_align (class cv::Mat *img_0,
+ class cv::Mat *img_1);
/******************************************************************************
******* main *****************************************************************
******************************************************************************/
-void img_orb_act (struct _IplImage *img_ref,
- struct _IplImage **imgptr2, int action)
+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, imgptr2);
+ img_orb_align(img_ref, imgptr);
break;
}
}
@@ -57,16 +57,9 @@ void img_orb_act (struct _IplImage *img_ref,
/******************************************************************************
******* static functions *****************************************************
******************************************************************************/
-static void img_orb_align (struct _IplImage *img_ref,
- struct _IplImage **imgptr2)
+static void img_orb_align (class cv::Mat *img_0,
+ class cv::Mat *img_1)
{
- /* Transform (struct _IplImage *) to (class cv::Mat) */
- /* Make a copy so that they aren't modified */
- class cv::Mat img_0;
- class cv::Mat img_1;
- img_0 = cv::cvarrToMat(img_ref, true);
- img_1 = cv::cvarrToMat(*imgptr2, true);
-
/* Variables to store keypoints & descriptors */
std::vector <class cv::KeyPoint> keypoints_0;
std::vector <class cv::KeyPoint> keypoints_1;
@@ -74,14 +67,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;
+ 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);
-*/
+ 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;
@@ -99,7 +97,7 @@ static void img_orb_align (struct _IplImage *img_ref,
/* Draw top matches */
class cv::Mat img_matches;
- cv::drawMatches(img_1, keypoints_1, img_0, keypoints_0, matches,
+ cv::drawMatches(*img_1, keypoints_1, *img_0, keypoints_0, matches,
img_matches);
cv::imwrite("matches.jpg", img_matches);
@@ -118,22 +116,10 @@ static void img_orb_align (struct _IplImage *img_ref,
/* 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 imgptr (need a tmp img; don't know why) */
- struct _IplImage imgtmp;
- int cols;
- int rows;
- int depth;
- int chan;
- cols = img_align.cols;
- rows = img_align.rows;
- depth = (*imgptr2)->depth;
- chan = (*imgptr2)->nChannels;
- cvReleaseImage(imgptr2);
- *imgptr2 = cvCreateImage(cvSize(cols, rows), depth, chan);
- imgtmp = img_align;
- cvCopy(&imgtmp, *imgptr2);
+ cv::warpPerspective(*img_1, img_align, img_hg, img_0->size());
+
+ /* Write img_align into img_1 */
+ *img_1 = img_align;
img_align.release();
}
diff --git a/modules/image/src/img_zbar.c b/modules/image/src/img_zbar.cpp
index 00f82c8..a195054 100644
--- a/modules/image/src/img_zbar.c
+++ b/modules/image/src/img_zbar.cpp
@@ -8,41 +8,41 @@
******************************************************************************/
/* Standard C ----------------------------------------------------------------*/
/* INT_MAX */
- #include <limits.h>
+ #include <climits>
/* snprintf() */
- #include <stdio.h>
+ #include <cstdio>
/* Packages ------------------------------------------------------------------*/
/* opencv */
- #include <cv.h>
+ #include <opencv2/opencv.hpp>
/* zbar */
#include <zbar.h>
/* Project -------------------------------------------------------------------*/
/* user_iface_log */
- #include "user_iface.h"
+ #include "user_iface.hpp"
/* Module --------------------------------------------------------------------*/
/* data & zb_codes */
- #include "img_iface.h"
+ #include "img_iface.hpp"
- #include "img_zbar.h"
+ #include "img_zbar.hpp"
/******************************************************************************
******* static functions *****************************************************
******************************************************************************/
-static void img_zb_decode (struct _IplImage *imgptr, void *data);
+static void img_zb_decode (class cv::Mat *imgptr, void *data);
/******************************************************************************
******* main *****************************************************************
******************************************************************************/
-void img_zb_act (struct _IplImage **imgptr2, int action, void *data)
+void img_zb_act (class cv::Mat *imgptr, int action, void *data)
{
switch (action) {
case IMG_ZB_ACT_DECODE:
- img_zb_decode(*imgptr2, data);
+ img_zb_decode(imgptr, data);
break;
}
}
@@ -51,56 +51,52 @@ void img_zb_act (struct _IplImage **imgptr2, int action, void *data)
/******************************************************************************
******* static functions *****************************************************
******************************************************************************/
-static void img_zb_decode (struct _IplImage *imgptr, void *data)
+static void img_zb_decode (class cv::Mat *imgptr, void *data)
{
- struct _IplImage *imgtmp;
- struct zbar_image_scanner_s *scanner;
- struct zbar_image_s *image_zb;
- const struct zbar_symbol_s *symbol;
-
- /* Make a copy of imgptr so that it isn't modified by zbar */
- imgtmp = cvCloneImage(imgptr);
+ 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 */
- int code_type;
+ enum zbar::zbar_symbol_type_e code_type;
code_type = ((struct Img_Iface_Data_Decode *)data)->code_type;
/* create & configure a reader */
- scanner = zbar_image_scanner_create();
- zbar_image_scanner_set_config(scanner, code_type, ZBAR_CFG_ENABLE, 1);
+ 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_image_create();
- zbar_image_set_format(image_zb, *(int*)"GREY");
- zbar_image_set_size(image_zb, imgtmp->width, imgtmp->height);
- zbar_image_set_data(image_zb, (void *)(imgtmp->imageData),
- (imgtmp->width * imgtmp->height),
+ 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_scan_image(scanner, image_zb);
+ zb_codes.n = zbar::zbar_scan_image(scanner, image_zb);
if (zb_codes.n) {
/* extract results */
- symbol = 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_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_get_symbol_name(
+ zbar::zbar_get_symbol_name(
zb_codes.arr[i].type));
snprintf(zb_codes.arr[i].data, ZBAR_LEN_MAX, "%s",
- zbar_symbol_get_data(symbol));
+ zbar::zbar_symbol_get_data(symbol));
/* Load next symbol */
- symbol = zbar_symbol_next(symbol);
+ symbol = zbar::zbar_symbol_next(symbol);
}
}
/* clean up */
- zbar_image_destroy(image_zb);
- zbar_image_scanner_destroy(scanner);
- cvReleaseImage(&imgtmp);
+ zbar::zbar_image_destroy(image_zb);
+ zbar::zbar_image_scanner_destroy(scanner);
}
diff --git a/modules/image/tmp/Makefile b/modules/image/tmp/Makefile
index d9abdc0..b513765 100644
--- a/modules/image/tmp/Makefile
+++ b/modules/image/tmp/Makefile
@@ -18,18 +18,18 @@ SRC_DIR = $(IMG_DIR)/src/
_ALL = img_cv.o img_zbar.o img_ocr.o img_orb.o img_iface.o
ALL = $(_ALL) img_mod.o
-IMGCV_INC_USR = user_iface.h
-IMGCV_INC = img_cv.h img_iface.h
-IMGCV_DEPS = $(SRC_DIR)/img_cv.c \
+IMGCV_INC_USR = user_iface.hpp
+IMGCV_INC = img_cv.hpp img_iface.hpp
+IMGCV_DEPS = $(SRC_DIR)/img_cv.cpp \
$(patsubst %,$(INC_DIR)/%,$(IMGCV_INC)) \
$(patsubst %,$(USR_INC_DIR)/%,$(IMGCV_INC_USR))
IMGCV_INC_DIRS = -I $(INC_DIR) \
-I $(USR_INC_DIR) \
-I $(LIBALX_INC_DIR)
-IMGZB_INC_USR = user_iface.h
-IMGZB_INC = img_zbar.h img_iface.h
-IMGZB_DEPS = $(SRC_DIR)/img_zbar.c \
+IMGZB_INC_USR = user_iface.hpp
+IMGZB_INC = img_zbar.hpp img_iface.hpp
+IMGZB_DEPS = $(SRC_DIR)/img_zbar.cpp \
$(patsubst %,$(INC_DIR)/%,$(IMGZB_INC)) \
$(patsubst %,$(USR_INC_DIR)/%,$(IMGZB_INC_USR))
IMGZB_INC_DIRS = -I $(INC_DIR) \
@@ -49,7 +49,7 @@ IMGOCR_INC_DIRS = -I $(INC_DIR) \
-I $(LIBALX_INC_DIR)
IMGORB_INC_USR = user_iface.hpp
-IMGORB_INC = img_orb.hpp img_iface.h
+IMGORB_INC = img_orb.hpp img_iface.hpp
IMGORB_DEPS = $(SRC_DIR)/img_orb.cpp \
$(patsubst %,$(INC_DIR)/%,$(IMGORB_INC)) \
$(patsubst %,$(USR_INC_DIR)/%,$(IMGORB_INC_USR))
@@ -57,10 +57,10 @@ IMGORB_INC_DIRS = -I $(INC_DIR) \
-I $(USR_INC_DIR) \
-I $(LIBALX_INC_DIR)
-IMGI_INC_SAVE = save.h
-IMGI_INC_USR = user_iface.h
-IMGI_INC = img_iface.h img_cv.h img_zbar.h img_ocr.h img_orb.h
-IMGI_DEPS = $(SRC_DIR)/img_iface.c \
+IMGI_INC_SAVE = save.hpp
+IMGI_INC_USR = user_iface.hpp
+IMGI_INC = img_iface.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))
@@ -81,21 +81,21 @@ img_mod.o: $(_ALL)
img_cv.s: $(IMGCV_DEPS)
- $(Q)$(CC) $(CFLAGS) $(IMGCV_INC_DIRS) -S $< -o $@
- @echo " CC $@"
+ $(Q)$(CXX) $(CXXFLAGS) $(IMGCV_INC_DIRS) -S $< -o $@
+ @echo " CXX $@"
img_cv.o: img_cv.s
$(Q)$(AS) $< -o $@
@echo " AS $@"
img_zbar.s: $(IMGZB_DEPS)
- $(Q)$(CC) $(CFLAGS) $(IMGZB_INC_DIRS) -S $< -o $@
- @echo " CC $@"
+ $(Q)$(CXX) $(CXXFLAGS) $(IMGZB_INC_DIRS) -S $< -o $@
+ @echo " CXX $@"
img_zbar.o: img_zbar.s
$(Q)$(AS) $< -o $@
@echo " AS $@"
img_ocr.s: $(IMGOCR_DEPS)
- $(Q)$(CC) $(CFLAGS) $(IMGOCR_INC_DIRS) -S $< -o $@
+ $(Q)$(CC) $(CCFLAGS) $(IMGOCR_INC_DIRS) -S $< -o $@
@echo " CC $@"
img_ocr.o: img_ocr.s
$(Q)$(AS) $< -o $@
@@ -109,8 +109,8 @@ img_orb.o: img_orb.s
@echo " AS $@"
img_iface.s: $(IMGI_DEPS)
- $(Q)$(CC) $(CFLAGS) $(IMGI_INC_DIRS) -S $< -o $@
- @echo " CC $@"
+ $(Q)$(CXX) $(CXXFLAGS) $(IMGI_INC_DIRS) -S $< -o $@
+ @echo " CXX $@"
img_iface.o: img_iface.s
$(Q)$(AS) $< -o $@
@echo " AS $@"
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..2b40698 100644
--- a/modules/proc/inc/proc.h
+++ b/modules/proc/inc/proc.h
@@ -11,13 +11,6 @@
/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
- /* bool */
- #include <stdbool.h>
-
-
-/******************************************************************************
******* macros ***************************************************************
******************************************************************************/
@@ -26,21 +19,33 @@
******* 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
+ };
-/******************************************************************************
- ******* structs **************************************************************
- ******************************************************************************/
+ enum Proc_Label {
+ LABEL_OK,
+ LABEL_NOK_LABEL,
+ LABEL_NOK_CERDO,
+ LABEL_NOK_BCODE,
+ LABEL_NOK_PRODUCT,
+ LABEL_NOK_PRICE
+ };
/******************************************************************************
******* variables ************************************************************
******************************************************************************/
+extern int proc_debug;
/******************************************************************************
diff --git a/modules/proc/inc/proc.hpp b/modules/proc/inc/proc.hpp
new file mode 100644
index 0000000..97641a0
--- /dev/null
+++ b/modules/proc/inc/proc.hpp
@@ -0,0 +1,77 @@
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# ifndef VA_PROC_HPP
+ # define VA_PROC_HPP
+
+
+/******************************************************************************
+ ******* macros ***************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+ enum Proc_Mode {
+ PROC_MODE_FOO,
+
+ PROC_MODE = 0x4000,
+ 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
+ };
+
+
+/******************************************************************************
+ ******* C wrapper ************************************************************
+ ******************************************************************************/
+extern "C" {
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+ extern int proc_debug;
+
+
+/******************************************************************************
+ ******* functions ************************************************************
+ ******************************************************************************/
+ int proc_iface (int proc_mode);
+
+
+/******************************************************************************
+ ******* C wrapper ************************************************************
+ ******************************************************************************/
+} /* extern "C" */
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# endif /* proc.hpp */
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/modules/proc/src/proc.c b/modules/proc/src/proc.cpp
index ea065b6..184ec6d 100644
--- a/modules/proc/src/proc.c
+++ b/modules/proc/src/proc.cpp
@@ -8,50 +8,33 @@
******************************************************************************/
/* Standard C ----------------------------------------------------------------*/
/* snprintf() & fflush() */
- #include <stdio.h>
- /* bool */
- #include <stdbool.h>
+ #include <cstdio>
/* strcmp() */
- #include <string.h>
+ #include <cstring>
/* clock_t & clock() & CLOCKS_PER_SEC */
- #include <time.h>
+ #include <ctime>
/* Packages ------------------------------------------------------------------*/
- /* opencv */
- #include <cv.h>
- #include <highgui.h>
- /* ZBAR_EAN13 */
+ /* openCV */
+ #include <opencv2/opencv.hpp>
+ /* zbar::ZBAR_EAN13 */
#include <zbar.h>
/* Project -------------------------------------------------------------------*/
/* img_iface_act() */
- #include "img_iface.h"
- /* WIN_NAME */
- #include "user_iface.h"
+ #include "img_iface.hpp"
+ /* user_iface_log */
+ #include "user_iface.hpp"
/* Module --------------------------------------------------------------------*/
- #include "proc.h"
-
-
-/******************************************************************************
- ******* 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)
+ #include "proc.hpp"
/******************************************************************************
******* variables ************************************************************
******************************************************************************/
-static struct _IplImage *imgptr;
-static struct CvMemStorage *proc_storage;
+/* Global --------------------------------------------------------------------*/
+ int proc_debug;
/******************************************************************************
@@ -67,13 +50,21 @@ static void proc_smooth (int method, int mask_size);
static void proc_adaptive_threshold (int method, int type, int size);
static void proc_threshold (int type, int size);
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 (struct CvSeq **cont, int *n);
-static void proc_min_area_rect (struct CvSeq *cont,
- struct CvBox2D *rect);
-static void proc_rotate (struct CvBox2D *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_crop (void);
static void proc_OCR (int lang, int conf);
static void proc_zbar (int type);
@@ -95,7 +86,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 +100,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,77 +114,75 @@ static int proc_etiqueta (void)
{
int status;
- char price [6];
+ char price [80];
- struct CvSeq *et_contours;
- int et_contours_n;
- struct CvBox2D et_rect;
+ std::vector <std::vector <cv::Point_ <int>>> contours;
+ class cv::Mat hierarchy;
+ class cv::RotatedRect rect;
int x;
int y;
int w;
int h;
- proc_storage = cvCreateMemStorage(0);
-
proc_save_mem(0);
/* Find label (position and angle) */
{
proc_cmp(IMG_IFACE_CMP_BLUE);
- proc_smooth(CV_MEDIAN, 7);
+ proc_smooth(IMGI_SMOOTH_MEDIAN, 7);
#if 0
proc_adaptive_threshold(CV_ADAPTIVE_THRESH_MEAN_C,
CV_THRESH_BINARY, 5);
#else
proc_invert();
#endif
- proc_smooth(CV_BLUR, 21);
- proc_threshold(CV_THRESH_BINARY_INV, 2);
+ proc_smooth(IMGI_SMOOTH_MEAN, 21);
+ proc_threshold(cv::THRESH_BINARY_INV, 2);
proc_dilate_erode(100);
- proc_contours(&et_contours, &et_contours_n);
+ proc_contours(&contours, &hierarchy);
/* If no contour is found, error: NOK_LABEL */
- if (!et_contours) {
- status = NOK_LABEL;
+ if (!contours.size()) {
+ status = LABEL_NOK_LABEL;
result_etiqueta(status);
return status;
}
- proc_min_area_rect(et_contours, &et_rect);
+ proc_min_area_rect(&(contours[0]), &rect);
/* If angle is < -45º, it is taking into acount the incorrect side */
- if (et_rect.angle < -45.0) {
+ if (rect.angle < -45.0) {
int tmp;
- et_rect.angle = et_rect.angle + 90.0;
- tmp = et_rect.size.width;
- et_rect.size.width = et_rect.size.height;
- et_rect.size.height = tmp;
+ rect.angle = rect.angle + 90.0;
+ tmp = rect.size.width;
+ rect.size.width = rect.size.height;
+ rect.size.height = tmp;
}
}
/* Align label and extract green component */
{
proc_load_mem(0);
- proc_rotate(&et_rect);
+ proc_rotate(&rect);
proc_cmp(IMG_IFACE_CMP_GREEN);
proc_save_mem(1);
}
/* Find "Cerdo" in aligned image */
{
- x = et_rect.center.x - (1.05 * et_rect.size.width / 2);
- y = et_rect.center.y - (1.47 * et_rect.size.height / 2);
- w = et_rect.size.width / 2;
- h = et_rect.size.height * 0.20;
+ x = rect.center.x - (1.05 * rect.size.width / 2);
+ y = rect.center.y - (1.47 * rect.size.height / 2);
+ w = rect.size.width / 2;
+ h = rect.size.height * 0.20;
proc_ROI(x, y, w, h);
- proc_crop();
- proc_threshold(CV_THRESH_BINARY, IMG_IFACE_THR_OTSU);
- proc_OCR(IMG_IFACE_OCR_LANG_SPA, IMG_IFACE_OCR_CONF_NONE);
+ 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". */
bool cerdo_nok;
cerdo_nok = strncmp(img_ocr_text, "Cerdo",
strlen("Cerdo"));
if (cerdo_nok) {
- status = NOK_CERDO;
+ status = LABEL_NOK_CERDO;
result_etiqueta(status);
return status;
}
@@ -202,11 +191,11 @@ static int proc_etiqueta (void)
{
proc_load_mem(0);
proc_cmp(IMG_IFACE_CMP_GREEN);
- proc_zbar(ZBAR_EAN13);
+ proc_zbar(zbar::ZBAR_EAN13);
/* 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 +206,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;
}
@@ -226,28 +215,28 @@ static int proc_etiqueta (void)
{
proc_load_mem(1);
- x = et_rect.center.x + (0.33 * et_rect.size.width / 2);
- y = et_rect.center.y + (0.64 * et_rect.size.height / 2);
- w = et_rect.size.width * 0.33;
- h = et_rect.size.height * 0.15;
+ 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.33;
+ h = rect.size.height * 0.15;
proc_ROI(x, y, w, h);
- proc_crop();
- proc_smooth(CV_BLUR, 3);
- proc_threshold(CV_THRESH_BINARY, IMG_IFACE_THR_OTSU);
+ proc_smooth(IMGI_SMOOTH_MEAN, 3);
+ proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU);
// proc_threshold(CV_THRESH_BINARY, 100);
// proc_smooth(CV_BLUR, 3);
+// proc_dilate(1);
proc_OCR(IMG_IFACE_OCR_LANG_ENG, IMG_IFACE_OCR_CONF_PRICE);
}
/* 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 +247,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;
}
@@ -272,32 +261,31 @@ static int proc_etiqueta (void)
static void result_etiqueta (int status)
{
/* Cleanup */
- cvReleaseMemStorage(&proc_storage);
/* 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 +294,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)++;
}
@@ -369,6 +357,24 @@ static void proc_invert (void)
proc_show_img();
}
+static 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();
+}
+
+static 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();
+}
+
static void proc_dilate_erode (int size)
{
struct Img_Iface_Data_Dilate_Erode data;
@@ -378,29 +384,35 @@ static void proc_dilate_erode (int size)
proc_show_img();
}
-static void proc_contours (struct CvSeq **cont, int *n)
+static void proc_contours (std::vector <
+ std::vector <
+ class cv::Point_ <int>
+ >
+ > *contours,
+ class cv::Mat *hierarchy)
{
struct Img_Iface_Data_Contours data;
- data.storage = &proc_storage;
- data.contours = cont;
- data.n = n;
+ data.contours = contours;
+ data.hierarchy = hierarchy;
img_iface_act(IMG_IFACE_ACT_CONTOURS, (void *)&data);
proc_show_img();
}
-static void proc_min_area_rect (struct CvSeq *cont,
- struct CvBox2D *rect)
+static void proc_min_area_rect (std::vector <
+ class cv::Point_ <int>
+ > *contour,
+ class cv::RotatedRect *rect)
{
struct Img_Iface_Data_MinARect data;
- data.contours = cont;
+ data.contour = contour;
data.rect = rect;
img_iface_act(IMG_IFACE_ACT_MIN_AREA_RECT, (void *)&data);
proc_show_img();
}
-static void proc_rotate (struct CvBox2D *rect)
+static void proc_rotate (class cv::RotatedRect *rect)
{
struct Img_Iface_Data_Rotate data;
data.center.x = rect->center.x;
@@ -421,13 +433,6 @@ static void proc_ROI (int x, int y, int w, int h)
img_iface_act(IMG_IFACE_ACT_SET_ROI, (void *)&data);
}
-static void proc_crop (void)
-{
- img_iface_act(IMG_IFACE_ACT_CROP, NULL);
-
- proc_show_img();
-}
-
static void proc_OCR (int lang, int conf)
{
struct Img_Iface_Data_Read data;
@@ -439,20 +444,18 @@ static void proc_OCR (int lang, int conf)
static void proc_zbar (int type)
{
struct Img_Iface_Data_Decode data;
- data.code_type = type;
+ data.code_type = (enum zbar::zbar_symbol_type_e)type;
img_iface_act(IMG_IFACE_ACT_DECODE, (void *)&data);
}
static void proc_show_img (void)
{
- if (show) {
- 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_DELAY_STEP) {
+ img_iface_show();
+
+ if (proc_debug >= PROC_DBG_STOP_STEP) {
+ getchar();
+ }
}
}
diff --git a/modules/proc/tmp/Makefile b/modules/proc/tmp/Makefile
index 52c710b..e2693a1 100644
--- a/modules/proc/tmp/Makefile
+++ b/modules/proc/tmp/Makefile
@@ -15,10 +15,10 @@ SRC_DIR = $(PROC_DIR)/src/
_ALL = proc.o
ALL = $(_ALL) proc_mod.o
-PROC_INC_IMG = img_iface.h
-PROC_INC_USER = user_iface.h
-PROC_INC = proc.h
-PROC_DEPS = $(SRC_DIR)/proc.c \
+PROC_INC_IMG = img_iface.hpp
+PROC_INC_USER = user_iface.hpp
+PROC_INC = proc.hpp
+PROC_DEPS = $(SRC_DIR)/proc.cpp \
$(patsubst %,$(INC_DIR)/%,$(PROC_INC)) \
$(patsubst %,$(IMG_INC_DIR)/%,$(PROC_INC_IMG)) \
$(patsubst %,$(USR_INC_DIR)/%,$(PROC_INC_USR))
@@ -39,8 +39,8 @@ proc_mod.o: $(_ALL)
proc.s: $(PROC_DEPS)
- $(Q)$(CC) $(CFLAGS) $(PROC_INC_DIRS) -S $< -o $@
- @echo " CC $@"
+ $(Q)$(CXX) $(CXXFLAGS) $(PROC_INC_DIRS) -S $< -o $@
+ @echo " CXX $@"
proc.o: proc.s
$(Q)$(AS) $< -o $@
@echo " AS $@"
diff --git a/modules/save/inc/save.h b/modules/save/inc/save.h
index 125e774..9582b7b 100644
--- a/modules/save/inc/save.h
+++ b/modules/save/inc/save.h
@@ -13,8 +13,7 @@
/******************************************************************************
******* headers **************************************************************
******************************************************************************/
- /* opencv */
- #include <cv.h>
+/* Standard C ----------------------------------------------------------------*/
/* FILENAME_MAX */
#include <stdio.h>
@@ -32,21 +31,20 @@
/******************************************************************************
******* variables ************************************************************
******************************************************************************/
-extern struct _IplImage *image;
-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 saved_name [FILENAME_MAX];
/******************************************************************************
******* functions ************************************************************
******************************************************************************/
-void save_init (void);
-void save_cleanup (void);
-void save_clr (void);
-void load_image_file (void);
-void save_image_file (void);
+ void save_init (void);
+ void save_cleanup (void);
+ void save_clr (void);
+ void load_image_file (void);
+ void save_image_file (void);
/******************************************************************************
diff --git a/modules/save/inc/save.hpp b/modules/save/inc/save.hpp
index 47c9cc8..274a450 100644
--- a/modules/save/inc/save.hpp
+++ b/modules/save/inc/save.hpp
@@ -18,7 +18,7 @@
#include <cstdio>
/* Project -------------------------------------------------------------------*/
- /* struct _IplImage */
+ /* opencv */
#include <opencv2/opencv.hpp>
@@ -41,11 +41,11 @@ extern "C" {
/******************************************************************************
******* variables ************************************************************
******************************************************************************/
- extern struct _IplImage *image;
- 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 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 saved_name [FILENAME_MAX];
/******************************************************************************
@@ -67,7 +67,7 @@ extern "C" {
/******************************************************************************
******* include guard ********************************************************
******************************************************************************/
-# endif /* save.h */
+# endif /* save.hpp */
/******************************************************************************
diff --git a/modules/save/src/save.c b/modules/save/src/save.cpp
index 88f4898..26a6626 100644
--- a/modules/save/src/save.c
+++ b/modules/save/src/save.cpp
@@ -6,39 +6,38 @@
/******************************************************************************
******* headers **************************************************************
******************************************************************************/
-/* * * * * * * * * *
- * * * Standard * * * * * *
- * * * * * * * * * */
- /* opencv */
- #include <cv.h>
- /* cvLoadImage & cvSaveImage */
- #include <highgui.h>
+/* Standard C ----------------------------------------------------------------*/
/* errno */
- #include <errno.h>
+ #include <cerrno>
/* fscanf() & fprintf() & FILE & FILENAME_MAX & snprintf() */
- #include <stdio.h>
+ #include <cstdio>
/* getenv() */
- #include <stdlib.h>
+ #include <cstdlib>
+
+/* Linux ---------------------------------------------------------------------*/
/* mkdir */
#include <sys/stat.h>
-/* * * * * * * * * *
- * * * Other * * * * * * *
- * * * * * * * * * */
+/* Packages ------------------------------------------------------------------*/
+ /* opencv */
+ #include <opencv2/opencv.hpp>
+
+/* Project -------------------------------------------------------------------*/
/* user_iface_save_name() */
- #include "user_iface.h"
+ #include "user_iface.hpp"
- #include "save.h"
+/* Module --------------------------------------------------------------------*/
+ #include "save.hpp"
/******************************************************************************
******* variables ************************************************************
******************************************************************************/
-struct _IplImage *image;
-char home_path [FILENAME_MAX];
-char user_prog_path [FILENAME_MAX];
-char saved_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 saved_name [FILENAME_MAX];
/******************************************************************************
@@ -61,7 +60,7 @@ void save_init (void)
switch (errno) {
case EACCES:
printf("err = EACCES");
- exit(EXIT_FAILURE);
+// exit(EXIT_FAILURE);
break;
case EEXIST:
@@ -70,7 +69,7 @@ void save_init (void)
default:
printf("WTF?!");
- exit(EXIT_FAILURE);
+// exit(EXIT_FAILURE);
}
}
}
@@ -85,25 +84,25 @@ void load_image_file (void)
char file_name [FILENAME_MAX];
/* Free old image */
- cvReleaseImage(&image);
+ image.release();
/* File name */
snprintf(file_name, FILENAME_MAX, "%s/%s", saved_path, saved_name);
/* Load image */
- image = cvLoadImage(file_name, CV_LOAD_IMAGE_COLOR);
+ image = cv::imread(file_name, CV_LOAD_IMAGE_COLOR);
/* Manage load error */
- if (!image) {
+ if (image.empty()) {
printf("Could not load file: %s\n", file_name);
- exit(0);
+// exit(0);
}
}
void save_cleanup (void)
{
/* Free old image */
- cvReleaseImage(&image);
+ image.release();
}
void save_image_file (void)
@@ -137,7 +136,7 @@ void save_image_file (void)
/* Write to a new file */
- cvSaveImage(file_name, image, NULL);
+ cv::imwrite(file_name, image);
}
diff --git a/modules/save/tmp/Makefile b/modules/save/tmp/Makefile
index c504b21..e33755e 100644
--- a/modules/save/tmp/Makefile
+++ b/modules/save/tmp/Makefile
@@ -14,9 +14,9 @@ SRC_DIR = $(SAVE_DIR)/src/
_ALL = save.o
ALL = $(_ALL) save_mod.o
-SAVE_INC_VIEW = user_iface.h
-SAVE_INC = save.h
-SAVE_DEPS = $(SRC_DIR)/save.c \
+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) \
@@ -35,8 +35,8 @@ save_mod.o: $(_ALL)
save.s: $(SAVE_DEPS)
- $(Q)$(CC) $(CFLAGS) $(SAVE_INC_DIRS) -S $< -o $@
- @echo " CC $@"
+ $(Q)$(CXX) $(CXXFLAGS) $(SAVE_INC_DIRS) -S $< -o $@
+ @echo " CXX $@"
save.o: save.s
$(Q)$(AS) $< -o $@
@echo " AS $@"
diff --git a/modules/user/inc/user_iface.h b/modules/user/inc/user_iface.h
index 5b26705..02e0c39 100644
--- a/modules/user/inc/user_iface.h
+++ b/modules/user/inc/user_iface.h
@@ -11,19 +11,18 @@
/******************************************************************************
- ******* headers **************************************************************
+ ******* macros ***************************************************************
******************************************************************************/
- /* struct IplImage */
- #include <cv.h>
+ # define LOG_LEN (1024)
+ # define LOG_LINE_LEN (35)
/******************************************************************************
- ******* macros ***************************************************************
+ ******* headers **************************************************************
******************************************************************************/
- # define LOG_LEN (1024)
- # define LOG_LINE_LEN (35)
- # define WIN_NAME "Image"
- # define WIN_TIMEOUT (500)
+/* Standard C ----------------------------------------------------------------*/
+ /* intX_t */
+ #include <stdint.h>
/******************************************************************************
@@ -53,8 +52,6 @@
USER_IFACE_ACT_ROTATE_ORTO,
USER_IFACE_ACT_ROTATE,
USER_IFACE_ACT_SET_ROI,
- USER_IFACE_ACT_RESET_ROI,
- USER_IFACE_ACT_CROP,
USER_IFACE_ACT_DILATE_ERODE,
USER_IFACE_ACT_ERODE_DILATE,
@@ -80,7 +77,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,27 +92,29 @@
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;
+ 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 (struct _IplImage *imgptr);
-void user_iface_save_name (const char *filepath, char *filename, int destsize);
-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_save_name (const char *filepath, char *filename,
+ int destsize);
+ 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 6d290d6..e1e6837 100644
--- a/modules/user/inc/user_iface.hpp
+++ b/modules/user/inc/user_iface.hpp
@@ -11,26 +11,18 @@
/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Project -------------------------------------------------------------------*/
- /* struct _IplImage */
- #include <opencv2/opencv.hpp>
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
+ ******* macros ***************************************************************
******************************************************************************/
-extern "C" {
+ # define LOG_LEN (1024)
+ # define LOG_LINE_LEN (35)
/******************************************************************************
- ******* macros ***************************************************************
+ ******* headers **************************************************************
******************************************************************************/
- # define LOG_LEN (1024)
- # define LOG_LINE_LEN (35)
- # define WIN_NAME "Image"
- # define WIN_TIMEOUT (500)
+/* Standard C ----------------------------------------------------------------*/
+ /* intX_t */
+ #include <cstdint>
/******************************************************************************
@@ -60,8 +52,6 @@ extern "C" {
USER_IFACE_ACT_ROTATE_ORTO,
USER_IFACE_ACT_ROTATE,
USER_IFACE_ACT_SET_ROI,
- USER_IFACE_ACT_RESET_ROI,
- USER_IFACE_ACT_CROP,
USER_IFACE_ACT_DILATE_ERODE,
USER_IFACE_ACT_ERODE_DILATE,
@@ -87,7 +77,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,10 +92,17 @@ extern "C" {
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;
@@ -117,7 +114,7 @@ extern "C" {
******************************************************************************/
void user_iface_init (void);
void user_iface_cleanup (void);
- void user_iface (struct _IplImage *imgptr);
+ void user_iface (void);
void user_iface_save_name (const char *filepath, char *filename,
int destsize);
double user_iface_getdbl (double m, double def, double M,
@@ -135,7 +132,7 @@ extern "C" {
/******************************************************************************
******* include guard ********************************************************
******************************************************************************/
-# endif /* user_iface.hpp */
+# endif /* user_iface.h */
/******************************************************************************
diff --git a/modules/user/src/user_iface.c b/modules/user/src/user_iface.c
index da8fe98..56aa3ad 100644
--- a/modules/user/src/user_iface.c
+++ b/modules/user/src/user_iface.c
@@ -6,24 +6,19 @@
/******************************************************************************
******* headers **************************************************************
******************************************************************************/
-/* * * * * * * * * *
- * * * Standard * * * * * *
- * * * * * * * * * */
- /* opencv */
- #include <cv.h>
- /* opencv gui */
- #include <highgui.h>
+/* Standard C ----------------------------------------------------------------*/
+ /* intX_t */
+ #include <stdint.h>
/* snprintf() & fflush() */
#include <stdio.h>
-/* * * * * * * * * *
- * * * Other * * * * * * *
- * * * * * * * * * */
- /* img_iface_act() */
+/* Project -------------------------------------------------------------------*/
+ /* img_iface_act_nodata() */
#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,8 +43,8 @@ struct User_Iface_Log user_iface_log;
/******************************************************************************
******* static functions *****************************************************
******************************************************************************/
-struct _IplImage *user_iface_act (int action);
-void user_iface_show_ocr (void);
+void user_iface_act (int action);
+void user_iface_show_ocr (void);
/******************************************************************************
@@ -58,8 +53,7 @@ void user_iface_show_ocr (void);
void user_iface_init (void)
{
user_iface_log.len = 0;
-
- cvNamedWindow(WIN_NAME, CV_WINDOW_NORMAL);
+ user_iface_log.visible = 2;
switch (user_iface_mode) {
case USER_IFACE_CLUI:
@@ -82,12 +76,10 @@ void user_iface_cleanup (void)
break;
}
- cvDestroyWindow(WIN_NAME);
-
fflush(stdout);
}
-void user_iface (struct _IplImage *imgptr)
+void user_iface (void)
{
char title[TITLE_SIZE];
char subtitle[TITLE_SIZE];
@@ -97,9 +89,8 @@ void user_iface (struct _IplImage *imgptr)
snprintf(subtitle, TITLE_SIZE, "Subtitle");
do {
- /* Display image and do NOT wait for any key to continue */
- cvShowImage(WIN_NAME, imgptr);
- cvWaitKey(WIN_TIMEOUT);
+ /* Display image */
+ img_iface_show();
/* Request user action */
switch (user_iface_mode) {
@@ -121,8 +112,6 @@ void user_iface (struct _IplImage *imgptr)
user_iface_act(user_action);
break;
}
-
- imgptr = img_iface_show();
} while (user_action != USER_IFACE_ACT_QUIT);
}
@@ -181,13 +170,9 @@ double user_iface_getdbl (double m, double def, double M,
/******************************************************************************
******* static functions *****************************************************
******************************************************************************/
-struct _IplImage *user_iface_act (int action)
+void user_iface_act (int action)
{
- struct _IplImage *imgptr;
-
if (action & USER_IFACE_ACT_USRI) {
- imgptr = NULL;
-
switch (action) {
case USER_IFACE_ACT_SHOW_OCR:
user_iface_show_ocr();
@@ -197,13 +182,11 @@ struct _IplImage *user_iface_act (int action)
break;
}
} else {
- img_iface_act(action, NULL);
+ img_iface_act_nodata(action);
}
-
- return imgptr;
}
-void user_iface_show_ocr (void)
+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 9321da1..a3ddeea 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;
@@ -348,12 +354,6 @@ static int usr_input (void)
case '0':
action = USER_IFACE_ACT_SET_ROI;
break;
- case '1':
- action = USER_IFACE_ACT_RESET_ROI;
- break;
- case '2':
- action = USER_IFACE_ACT_CROP;
- break;
default:
action = USER_IFACE_ACT_FOO;
break;
@@ -507,8 +507,6 @@ static void show_help (void)
mvwprintw(win_help, r++, c, " - Rotate: %s", "f141");
mvwprintw(win_help, r++, c, " - Rotate 2rect:%s", "f142");
mvwprintw(win_help, r++, c, " - Set ROI: %s", "f150");
- mvwprintw(win_help, r++, c, " - Reset ROI: %s", "f151");
- mvwprintw(win_help, r++, c, " - Crop: %s", "f152");
mvwprintw(win_help, r++, c, " - Scan codes: %s", "f20");
mvwprintw(win_help, r++, c, " - Scan text: %s", "f30");
mvwprintw(win_help, r++, c, " - Align: %s", "f40");