diff options
author | alex <alex@ASUS> | 2018-10-10 23:49:53 +0200 |
---|---|---|
committer | alex <alex@ASUS> | 2018-10-10 23:49:53 +0200 |
commit | ecaa3da92fa6b2154a95b52dd8985fa82d0a3236 (patch) | |
tree | 2e794c7f471c4844416f755ddff2b24ed8f36c03 | |
parent | fc8deff811d1f303750e1db406da248a0df41485 (diff) |
Use C++ & C (main needs to be C++); Use ORB feature from openCV (needs C++);
26 files changed, 1300 insertions, 158 deletions
@@ -108,6 +108,7 @@ export BIN_NAME ################################################################################ # Make variables (CC, etc...) CC = gcc + CXX = g++ AS = as LD = ld @@ -118,9 +119,11 @@ export LD ################################################################################ # cflags CFLAGS_STD = -std=c11 -CFLAGS_CV = `pkg-config --cflags opencv` -CFLAGS_ZBAR = `pkg-config --cflags zbar` -CFLAGS_TESS = `pkg-config --cflags tesseract` + +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_D = -D 'PROG_VERSION="$(PROGRAMVERSION)"' CFLAGS_D += -D 'INSTALL_SHARE_DIR="$(INSTALL_SHARE_DIR)"' @@ -128,18 +131,37 @@ 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_D) $(CFLAGS_CV) $(CFLAGS_ZBAR) $(CFLAGS_TESS) +CFLAGS = $(CFLAGS_STD) $(CFLAGS_PKG) $(CFLAGS_D) export CFLAGS ################################################################################ +# c++flags +CXXFLAGS_STD = -std=c++17 + +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_D = -D 'PROG_VERSION="$(PROGRAMVERSION)"' +CXXFLAGS_D += -D 'INSTALL_SHARE_DIR="$(INSTALL_SHARE_DIR)"' +CXXFLAGS_D += -D 'SHARE_DIR="$(SHARE_DIR)"' +CXXFLAGS_D += -D 'INSTALL_VAR_DIR="$(INSTALL_VAR_DIR)"' +CXXFLAGS_D += -D 'VAR_DIR="$(VAR_DIR)"' + +CXXFLAGS = $(CXXFLAGS_STD) $(CXXFLAGS_PKG) $(CXXFLAGS_D) + +export CXXFLAGS + +################################################################################ # libs -LIBS_CURSES = -l ncurses -LIBS_CV = `pkg-config --libs opencv` -LIBS_ZBAR = `pkg-config --libs zbar` -LIBS_TESS = `pkg-config --libs tesseract` +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 = $(LIBS_CURSES) $(LIBS_CV) $(LIBS_ZBAR) $(LIBS_TESS) +LIBS = $(LIBS_PKG) export LIBS diff --git a/bin/Makefile b/bin/Makefile index 75d3bea..16ca3b0 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -16,8 +16,8 @@ MAIN_OBJ_LIBALX = alx_lib.o MAIN_OBJ_MODULES = modules.o MAIN_OBJS = $(TMP_DIR)/main.o \ - $(patsubst %,$(LIBALX_TMP_DIR)/%,$(MAIN_OBJ_LIBALX)) \ - $(patsubst %,$(MODULES_TMP_DIR)/%,$(MAIN_OBJ_MODULES)) + $(patsubst %,$(MODULES_TMP_DIR)/%,$(MAIN_OBJ_MODULES)) \ + $(patsubst %,$(LIBALX_TMP_DIR)/%,$(MAIN_OBJ_LIBALX)) # target: dependencies @@ -27,7 +27,7 @@ all: $(ALL) $(BIN_NAME): $(MAIN_OBJS) - $(Q)$(CC) $^ -o $@ $(LIBS) + $(Q)$(CXX) $^ -o $@ $(LIBS) @echo " CC $@" @echo "" diff --git a/libalx/inc/alx_ncur.hpp b/libalx/inc/alx_ncur.hpp new file mode 100644 index 0000000..36cc822 --- /dev/null +++ b/libalx/inc/alx_ncur.hpp @@ -0,0 +1,117 @@ +/******************************************************************************
+ * Copyright (C) 2017 Alejandro Colomar Andrés *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# ifndef ALX_NCUR_HPP
+ # define ALX_NCUR_HPP
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+/* Standard C ----------------------------------------------------------------*/
+ /* int64_t */
+ #include <cstdint>
+
+/* Packages ------------------------------------------------------------------*/
+ /* WINDOW */
+ #include <ncurses.h>
+
+
+/******************************************************************************
+ ******* C wrapper ************************************************************
+ ******************************************************************************/
+extern "C" {
+
+
+/******************************************************************************
+ ******* structs **************************************************************
+ ******************************************************************************/
+ struct Alx_Menu {
+ int r;
+ int c;
+ char *t;
+ };
+
+
+/******************************************************************************
+ ******* functions ************************************************************
+ ******************************************************************************/
+ void alx_start_curses (void);
+ void alx_pause_curses (void);
+ void alx_resume_curses (void);
+ void alx_end_curses (void);
+ void alx_win_del (WINDOW *win);
+
+ int alx_menu (int h,
+ int w,
+ int N,
+ struct Alx_Menu mnu[],
+ const char *str);
+
+ int alx_menu_2 (WINDOW *win,
+ int N,
+ struct Alx_Menu mnu[],
+ const char *str);
+
+ double alx_w_getdbl (int w,
+ int r,
+ const char *title,
+ double m,
+ double def,
+ double M,
+ const char *format,
+ ...);
+
+ int64_t alx_w_getint (int w,
+ int r,
+ const char *title,
+ double m,
+ int64_t def,
+ double M,
+ const char *format,
+ ...);
+
+ void alx_w_getstr (char *dest,
+ int destsize,
+ int w,
+ int r,
+ const char *title,
+ const char *format,
+ ...);
+
+ void alx_w_getfname (const char *fpath,
+ char *fname,
+ bool exist,
+ int w,
+ int r,
+ const char *title,
+ const char *format,
+ ...);
+
+ void alx_ncur_prn_title (WINDOW *win,
+ const char *title);
+
+ void alx_ncur_prn_subtitle (WINDOW *win,
+ const char *subtitle);
+
+
+/******************************************************************************
+ ******* C wrapper ************************************************************
+ ******************************************************************************/
+} /* extern "C" */
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# endif /* alx_ncur.hpp */
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/matches.jpg b/matches.jpg Binary files differnew file mode 100644 index 0000000..dbbfcb4 --- /dev/null +++ b/matches.jpg diff --git a/modules/about/inc/about.h b/modules/about/inc/about.h index a2cd214..5122d14 100644 --- a/modules/about/inc/about.h +++ b/modules/about/inc/about.h @@ -13,6 +13,7 @@ /******************************************************************************
******* headers **************************************************************
******************************************************************************/
+/* Standard C ----------------------------------------------------------------*/
/* FILENAME_MAX */
#include <stdio.h>
diff --git a/modules/about/inc/about.hpp b/modules/about/inc/about.hpp new file mode 100644 index 0000000..50180ba --- /dev/null +++ b/modules/about/inc/about.hpp @@ -0,0 +1,75 @@ +/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# ifndef VA_ABOUT_HPP
+ # define VA_ABOUT_HPP
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+/* Standard C ----------------------------------------------------------------*/
+ /* FILENAME_MAX */
+ #include <cstdio>
+
+
+/******************************************************************************
+ ******* C wrapper ************************************************************
+ ******************************************************************************/
+extern "C" {
+
+
+/******************************************************************************
+ ******* macros ***************************************************************
+ ******************************************************************************/
+ # define PROG_NAME "vision-artificial"
+ # define PROG_YEAR "2018"
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+ enum Share_File {
+ SHARE_COPYRIGHT,
+ SHARE_DISCLAIMER,
+ SHARE_HELP,
+ SHARE_LICENSE,
+ SHARE_USAGE
+ };
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+ extern char share_path [FILENAME_MAX];
+
+
+/******************************************************************************
+ ******* functions ************************************************************
+ ******************************************************************************/
+ void about_init (void);
+ void snprint_share_file (char *dest, int destsize, int share_file);
+ void print_share_file (int share_file);
+ void print_version (void);
+
+
+/******************************************************************************
+ ******* C wrapper ************************************************************
+ ******************************************************************************/
+} /* extern "C" */
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# endif /* about.hpp */
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/modules/ctrl/src/start.c b/modules/ctrl/src/start.c index 499edd7..976dc00 100644 --- a/modules/ctrl/src/start.c +++ b/modules/ctrl/src/start.c @@ -40,6 +40,8 @@ void start_switch (void) user_iface(imgptr);
user_iface_cleanup();
}
+
+ img_iface_cleanup();
}
diff --git a/modules/image/inc/img_cv.h b/modules/image/inc/img_cv.h index 6fde4bf..4781114 100644 --- a/modules/image/inc/img_cv.h +++ b/modules/image/inc/img_cv.h @@ -14,7 +14,7 @@ ******* headers **************************************************************
******************************************************************************/
/* struct IplImage */
- #include "cv.h"
+ #include <cv.h>
/******************************************************************************
@@ -25,9 +25,10 @@ IMG_CV_ACT_CV = 0x0100,
IMG_CV_ACT_INVERT,
- IMG_CV_ACT_ROTATE,
IMG_CV_ACT_BGR2GRAY,
- IMG_CV_ACT_COMPONENT
+ IMG_CV_ACT_COMPONENT,
+ IMG_CV_ACT_THRESHOLD,
+ IMG_CV_ACT_ROTATE
};
diff --git a/modules/image/inc/img_iface.h b/modules/image/inc/img_iface.h index 191b6a3..2e14bee 100644 --- a/modules/image/inc/img_iface.h +++ b/modules/image/inc/img_iface.h @@ -13,8 +13,9 @@ /******************************************************************************
******* headers **************************************************************
******************************************************************************/
- /* struct IplImage */
- #include "cv.h"
+/* Packages ------------------------------------------------------------------*/
+ /* struct IplImage */
+ #include <cv.h>
/******************************************************************************
@@ -25,9 +26,10 @@ IMG_IFACE_ACT_CV = 0x0100,
IMG_IFACE_ACT_INVERT,
- IMG_IFACE_ACT_ROTATE,
IMG_IFACE_ACT_BGR2GRAY,
IMG_IFACE_ACT_COMPONENT,
+ IMG_IFACE_ACT_THRESHOLD,
+ IMG_IFACE_ACT_ROTATE,
IMG_IFACE_ACT_ZB = 0x0200,
IMG_IFACE_ACT_DECODE,
@@ -35,11 +37,17 @@ IMG_IFACE_ACT_OCR = 0x0400,
IMG_IFACE_ACT_READ,
- IMG_IFACE_ACT_IMGI = 0x0800,
+ IMG_IFACE_ACT_ORB = 0x0800,
+ IMG_IFACE_ACT_ALIGN,
+
+ IMG_IFACE_ACT_IMGI = 0x1000,
IMG_IFACE_ACT_APPLY,
IMG_IFACE_ACT_DISCARD,
IMG_IFACE_ACT_SAVE_MEM,
IMG_IFACE_ACT_LOAD_MEM,
+ IMG_IFACE_ACT_SAVE_REF,
+
+ IMG_IFACE_ACT_SAVE = 0x2000,
IMG_IFACE_ACT_SAVE_FILE
};
diff --git a/modules/image/inc/img_iface.hpp b/modules/image/inc/img_iface.hpp new file mode 100644 index 0000000..652c6eb --- /dev/null +++ b/modules/image/inc/img_iface.hpp @@ -0,0 +1,84 @@ +/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# ifndef VA_IMG_IFACE_HPP
+ # define VA_IMG_IFACE_HPP
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+/* Packages ------------------------------------------------------------------*/
+ /* struct _IplImage */
+ #include <opencv2/opencv.hpp>
+
+
+/******************************************************************************
+ ******* C wrapper ************************************************************
+ ******************************************************************************/
+extern "C" {
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+ enum Img_Iface_Action {
+ IMG_IFACE_ACT_FOO = 0,
+
+ IMG_IFACE_ACT_CV = 0x0100,
+ IMG_IFACE_ACT_INVERT,
+ IMG_IFACE_ACT_BGR2GRAY,
+ IMG_IFACE_ACT_COMPONENT,
+ IMG_IFACE_ACT_THRESHOLD,
+ IMG_IFACE_ACT_ROTATE,
+
+ IMG_IFACE_ACT_ZB = 0x0200,
+ IMG_IFACE_ACT_DECODE,
+
+ IMG_IFACE_ACT_OCR = 0x0400,
+ IMG_IFACE_ACT_READ,
+
+ IMG_IFACE_ACT_ORB = 0x0800,
+ IMG_IFACE_ACT_ALIGN,
+
+ IMG_IFACE_ACT_IMGI = 0x1000,
+ IMG_IFACE_ACT_APPLY,
+ IMG_IFACE_ACT_DISCARD,
+ IMG_IFACE_ACT_SAVE_MEM,
+ IMG_IFACE_ACT_LOAD_MEM,
+ IMG_IFACE_ACT_SAVE_REF,
+
+ IMG_IFACE_ACT_SAVE = 0x2000,
+ IMG_IFACE_ACT_SAVE_FILE
+ };
+
+
+/******************************************************************************
+ ******* functions ************************************************************
+ ******************************************************************************/
+ void img_iface_cleanup_main (void);
+ struct _IplImage *img_iface_load (void);
+ void img_iface_cleanup (void);
+ struct _IplImage *img_iface_act (int action);
+
+
+/******************************************************************************
+ ******* C wrapper ************************************************************
+ ******************************************************************************/
+} /* extern "C" */
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# endif /* img_iface.hpp */
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/modules/image/inc/img_ocr.h b/modules/image/inc/img_ocr.h index 9f6a273..ae74f49 100644 --- a/modules/image/inc/img_ocr.h +++ b/modules/image/inc/img_ocr.h @@ -14,7 +14,7 @@ ******* headers **************************************************************
******************************************************************************/
/* struct IplImage */
- #include "cv.h"
+ #include <cv.h>
/******************************************************************************
diff --git a/modules/image/inc/img_orb.h b/modules/image/inc/img_orb.h new file mode 100644 index 0000000..51bce1e --- /dev/null +++ b/modules/image/inc/img_orb.h @@ -0,0 +1,47 @@ +/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# ifndef VA_IMG_ORB_H
+ # define VA_IMG_ORB_H
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+/* Packages ------------------------------------------------------------------*/
+ /* struct _IplImage */
+ #include <cv.h>
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+ enum Img_ORB_Action {
+ IMG_ORB_ACT_FOO = 0,
+
+ IMG_ORB_ACT_ORB = 0x0800,
+ IMG_ORB_ACT_ALIGN
+ };
+
+
+/******************************************************************************
+ ******* functions ************************************************************
+ ******************************************************************************/
+ void img_orb_act (struct _IplImage *pattern,
+ struct _IplImage **imgptr2, int action);
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# endif /* img_orb.h */
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/modules/image/inc/img_orb.hpp b/modules/image/inc/img_orb.hpp new file mode 100644 index 0000000..f4f0e0c --- /dev/null +++ b/modules/image/inc/img_orb.hpp @@ -0,0 +1,58 @@ +/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# ifndef VA_IMG_ORB_HPP
+ # define VA_IMG_ORB_HPP
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+ /* struct IplImage */
+ #include <opencv2/opencv.hpp>
+
+
+/******************************************************************************
+ ******* C wrapper ************************************************************
+ ******************************************************************************/
+extern "C" {
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+ enum Img_ORB_Action {
+ IMG_ORB_ACT_FOO = 0,
+
+ IMG_ORB_ACT_ORB = 0x0800,
+ IMG_ORB_ACT_ALIGN
+ };
+
+
+/******************************************************************************
+ ******* functions ************************************************************
+ ******************************************************************************/
+void img_orb_act (struct _IplImage *pattern,
+ struct _IplImage **imgptr2, int action);
+
+
+/******************************************************************************
+ ******* C wrapper ************************************************************
+ ******************************************************************************/
+} /* extern "C" */
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# endif /* img_orb.hpp */
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/modules/image/src/img_cv.c b/modules/image/src/img_cv.c index 726ae30..cd5b13d 100644 --- a/modules/image/src/img_cv.c +++ b/modules/image/src/img_cv.c @@ -28,9 +28,10 @@ ******************************************************************************/
/* Filters */
static void img_cv_invert (struct _IplImage *imgptr);
-static void img_cv_rotate (struct _IplImage **imgptr2);
static void img_cv_bgr2gray (struct _IplImage **imgptr2);
static void img_cv_component (struct _IplImage **imgptr2);
+static void img_cv_threshold (struct _IplImage **imgptr2);
+static void img_cv_rotate (struct _IplImage **imgptr2);
/******************************************************************************
@@ -43,10 +44,6 @@ void img_cv_act (struct _IplImage **imgptr2, int action) img_cv_invert(*imgptr2);
break;
- case IMG_CV_ACT_ROTATE:
- img_cv_rotate(imgptr2);
- break;
-
case IMG_CV_ACT_BGR2GRAY:
img_cv_bgr2gray(imgptr2);
break;
@@ -54,6 +51,14 @@ void img_cv_act (struct _IplImage **imgptr2, int action) case IMG_CV_ACT_COMPONENT:
img_cv_component(imgptr2);
break;
+
+ case IMG_CV_ACT_THRESHOLD:
+ img_cv_threshold(imgptr2);
+ break;
+
+ case IMG_CV_ACT_ROTATE:
+ img_cv_rotate(imgptr2);
+ break;
}
}
@@ -93,68 +98,6 @@ static void img_cv_invert (struct _IplImage *imgptr) }
}
-static void img_cv_rotate (struct _IplImage **imgptr2)
-{
- struct _IplImage *rotated;
- struct _IplImage *imgtmp;
-
- /* Ask user how to rotate */
- char title [80];
- int rot;
- snprintf(title, 80, "Rotate (counterclockwise) n * pi/2 rad; n:");
- rot = user_iface_getint(1, 1, 3, title, NULL);
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Rotate %i * pi/2 rad", rot);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- switch (rot) {
- case 1:
- /* Init structures */
- imgtmp = cvCreateImage(cvSize((*imgptr2)->height, (*imgptr2)->width),
- (*imgptr2)->depth, (*imgptr2)->nChannels);
- rotated = cvCreateImage(cvSize((*imgptr2)->height, (*imgptr2)->width),
- (*imgptr2)->depth, (*imgptr2)->nChannels);
-
- /* Rotate: transpose and flip around horizontal axis: flip_mode=0 */
- cvTranspose(*imgptr2, imgtmp);
- cvFlip(imgtmp, rotated, 0);
- break;
-
- case 2:
- /* Init structures */
- imgtmp = NULL;
- rotated = cvCreateImage(cvGetSize(*imgptr2),
- (*imgptr2)->depth, (*imgptr2)->nChannels);
-
- /* Rotate: Flip both axises: flip_mode=-1 */
- cvFlip(*imgptr2, rotated, -1);
- break;
-
- case 3:
- /* Init structures */
- imgtmp = cvCreateImage(cvSize((*imgptr2)->height, (*imgptr2)->width),
- (*imgptr2)->depth, (*imgptr2)->nChannels);
- rotated = cvCreateImage(cvSize((*imgptr2)->height, (*imgptr2)->width),
- (*imgptr2)->depth, (*imgptr2)->nChannels);
-
- /* Rotate: transpose and flip around vertical axis: flip_mode=1 */
- cvTranspose(*imgptr2, imgtmp);
- cvFlip(imgtmp, rotated, 1);
- break;
- }
-
- /* Write rotated into imgptr2 */
- cvReleaseImage(imgptr2);
- *imgptr2 = cvCloneImage(rotated);
-
- /* clean up */
- cvReleaseImage(&imgtmp);
- cvReleaseImage(&rotated);
-}
-
static void img_cv_bgr2gray (struct _IplImage **imgptr2)
{
struct _IplImage *gray;
@@ -175,8 +118,7 @@ static void img_cv_bgr2gray (struct _IplImage **imgptr2) *imgptr2 = cvCloneImage(gray);
/* clean up */
- cvReleaseImage(&gray);
-
+ cvReleaseImage(&gray);
}
static void img_cv_component (struct _IplImage **imgptr2)
@@ -222,8 +164,108 @@ static void img_cv_component (struct _IplImage **imgptr2) /* clean up */
cvReleaseImage(&cmp_B);
cvReleaseImage(&cmp_G);
- cvReleaseImage(&cmp_R);
-
+ cvReleaseImage(&cmp_R);
+}
+
+static void img_cv_threshold (struct _IplImage **imgptr2)
+{
+ struct _IplImage *img_thr;
+
+ /* Ask user which threshold type to apply */
+ char title [80];
+ int thr_typ;
+ snprintf(title, 80, "Type: BIN=0, BIN_INV=1, TRUNC=2, TOZ=3, TOZ_INV=4");
+ thr_typ = user_iface_getint(0, 0, 4, title, NULL);
+
+ /* Ask user which threshold value to apply */
+ int thr_val;
+ snprintf(title, 80, "Value: 0 to 255 (or -1 for Otsu's algorithm)");
+ thr_val = user_iface_getint(-1, 0, 255, title, NULL);
+ if (thr_val == -1) {
+ thr_typ |= CV_THRESH_OTSU;
+ }
+
+ /* Write into log */
+ snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
+ "Threshold typ=%i, val=%i",
+ thr_typ, thr_val);
+ user_iface_log.lvl[user_iface_log.len] = 1;
+ (user_iface_log.len)++;
+
+ /* Create structure for tmp */
+ img_thr = cvCreateImage(cvGetSize(*imgptr2), (*imgptr2)->depth, 1);
+
+ /* Write gray img into gray */
+ cvThreshold(*imgptr2, img_thr, thr_val, 0xFF, thr_typ);
+
+ /* Write B & W img into imgptr2 */
+ cvReleaseImage(imgptr2);
+ *imgptr2 = cvCloneImage(img_thr);
+
+ /* clean up */
+ cvReleaseImage(&img_thr);
+}
+
+static void img_cv_rotate (struct _IplImage **imgptr2)
+{
+ struct _IplImage *rotated;
+ struct _IplImage *imgtmp;
+
+ /* Ask user how to rotate */
+ char title [80];
+ int rot;
+ snprintf(title, 80, "Rotate (counterclockwise) n * pi/2 rad; n:");
+ rot = user_iface_getint(1, 1, 3, title, NULL);
+
+ /* Write into log */
+ snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
+ "Rotate %i * pi/2 rad", rot);
+ user_iface_log.lvl[user_iface_log.len] = 1;
+ (user_iface_log.len)++;
+
+ switch (rot) {
+ case 1:
+ /* Init structures */
+ imgtmp = cvCreateImage(cvSize((*imgptr2)->height, (*imgptr2)->width),
+ (*imgptr2)->depth, (*imgptr2)->nChannels);
+ rotated = cvCreateImage(cvSize((*imgptr2)->height, (*imgptr2)->width),
+ (*imgptr2)->depth, (*imgptr2)->nChannels);
+
+ /* Rotate: transpose and flip around horizontal axis: flip_mode=0 */
+ cvTranspose(*imgptr2, imgtmp);
+ cvFlip(imgtmp, rotated, 0);
+ break;
+
+ case 2:
+ /* Init structures */
+ imgtmp = NULL;
+ rotated = cvCreateImage(cvGetSize(*imgptr2),
+ (*imgptr2)->depth, (*imgptr2)->nChannels);
+
+ /* Rotate: Flip both axises: flip_mode=-1 */
+ cvFlip(*imgptr2, rotated, -1);
+ break;
+
+ case 3:
+ /* Init structures */
+ imgtmp = cvCreateImage(cvSize((*imgptr2)->height, (*imgptr2)->width),
+ (*imgptr2)->depth, (*imgptr2)->nChannels);
+ rotated = cvCreateImage(cvSize((*imgptr2)->height, (*imgptr2)->width),
+ (*imgptr2)->depth, (*imgptr2)->nChannels);
+
+ /* Rotate: transpose and flip around vertical axis: flip_mode=1 */
+ cvTranspose(*imgptr2, imgtmp);
+ cvFlip(imgtmp, rotated, 1);
+ break;
+ }
+
+ /* Write rotated into imgptr2 */
+ cvReleaseImage(imgptr2);
+ *imgptr2 = cvCloneImage(rotated);
+
+ /* clean up */
+ cvReleaseImage(&imgtmp);
+ cvReleaseImage(&rotated);
}
diff --git a/modules/image/src/img_iface.c b/modules/image/src/img_iface.c index 3230481..6f9772f 100644 --- a/modules/image/src/img_iface.c +++ b/modules/image/src/img_iface.c @@ -6,17 +6,15 @@ /******************************************************************************
******* headers **************************************************************
******************************************************************************/
-/* * * * * * * * * *
- * * * Standard * * * * * *
- * * * * * * * * * */
- /* opencv */
- #include <cv.h>
+/* Standard C ----------------------------------------------------------------*/
/* snprintf() */
#include <stdio.h>
-/* * * * * * * * * *
- * * * Other * * * * * * *
- * * * * * * * * * */
+/* Packages ------------------------------------------------------------------*/
+ /* opencv */
+ #include <cv.h>
+
+/* Project -------------------------------------------------------------------*/
/* load_image_file() */
#include "save.h"
/* user_iface_log */
@@ -28,6 +26,8 @@ #include "img_zbar.h"
/* OCR */
#include "img_ocr.h"
+ /* ORB */
+ #include "img_orb.h"
#include "img_iface.h"
@@ -45,6 +45,7 @@ static struct _IplImage *image_copy_old; static struct _IplImage *image_copy_tmp;
static struct _IplImage *image_copy_usr;
static struct _IplImage *image_mem [10];
+static struct _IplImage *image_ref;
/******************************************************************************
@@ -52,16 +53,25 @@ static struct _IplImage *image_mem [10]; ******************************************************************************/
/* Actions */
static void img_iface_action (int action);
+ /* img_cv */
static void img_iface_invert (void);
-static void img_iface_rotate (void);
static void img_iface_bgr2gray (void);
static void img_iface_component (void);
+static void img_iface_threshold (void);
+static void img_iface_rotate (void);
+ /* img_zbar */
static void img_iface_decode (void);
+ /* img_ocr */
static void img_iface_read (void);
+ /* img_orb */
+static void img_iface_align (void);
+ /* img_iface */
static void img_iface_apply (void);
static void img_iface_discard (void);
static void img_iface_save_mem (void);
static void img_iface_load_mem (void);
+static void img_iface_save_ref (void);
+ /* save */
static void img_iface_save_file (void);
@@ -75,6 +85,7 @@ void img_iface_cleanup_main (void) for (i = 0; i < IMG_MEM_SIZE; i++) {
cvReleaseImage(&image_mem[i]);
}
+ cvReleaseImage(&image_ref);
}
struct _IplImage *img_iface_load (void)
@@ -115,9 +126,7 @@ struct _IplImage *img_iface_act (int action) /******************************************************************************
******* static functions *****************************************************
******************************************************************************/
-/* * * * * * * * * *
- * * * Actions * * * * * *
- * * * * * * * * * */
+/* Actions -------------------------------------------------------------------*/
static void img_iface_action (int action)
{
switch (action) {
@@ -125,15 +134,18 @@ static void img_iface_action (int action) case IMG_IFACE_ACT_INVERT:
img_iface_invert();
break;
- case IMG_IFACE_ACT_ROTATE:
- img_iface_rotate();
- break;
case IMG_IFACE_ACT_BGR2GRAY:
img_iface_bgr2gray();
break;
case IMG_IFACE_ACT_COMPONENT:
img_iface_component();
break;
+ case IMG_IFACE_ACT_THRESHOLD:
+ img_iface_threshold();
+ break;
+ case IMG_IFACE_ACT_ROTATE:
+ img_iface_rotate();
+ break;
/* img_zbar */
case IMG_IFACE_ACT_DECODE:
@@ -145,6 +157,11 @@ static void img_iface_action (int action) img_iface_read();
break;
+ /* img_orb */
+ case IMG_IFACE_ACT_ALIGN:
+ img_iface_align();
+ break;
+
/* img_iface */
case IMG_IFACE_ACT_APPLY:
img_iface_apply();
@@ -158,6 +175,11 @@ static void img_iface_action (int action) case IMG_IFACE_ACT_LOAD_MEM:
img_iface_load_mem();
break;
+ case IMG_IFACE_ACT_SAVE_REF:
+ img_iface_save_ref();
+ break;
+
+ /* save */
case IMG_IFACE_ACT_SAVE_FILE:
img_iface_save_file();
break;
@@ -168,23 +190,24 @@ static void img_iface_action (int action) }
}
+/* img_cv --------------------------------------------------------------------*/
static void img_iface_invert (void)
{
/* Filter: invert color */
img_cv_act(&image_copy_tmp, IMG_CV_ACT_INVERT);
}
-static void img_iface_rotate (void)
-{
- /* Rotate */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE);
-}
-
static void img_iface_bgr2gray (void)
{
/* Filter: invert color */
if (image_copy_tmp->nChannels == 3) {
img_cv_act(&image_copy_tmp, IMG_CV_ACT_BGR2GRAY);
+ } else {
+ /* 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.len)++;
}
}
@@ -193,9 +216,36 @@ static void img_iface_component (void) /* Filter: extract component */
if (image_copy_tmp->nChannels == 3) {
img_cv_act(&image_copy_tmp, IMG_CV_ACT_COMPONENT);
+ } else {
+ /* 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.len)++;
}
}
+static void img_iface_threshold (void)
+{
+ /* Filter: threshold */
+ if (image_copy_tmp->nChannels == 1) {
+ img_cv_act(&image_copy_tmp, IMG_CV_ACT_THRESHOLD);
+ } else {
+ /* 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.len)++;
+ }
+}
+
+static void img_iface_rotate (void)
+{
+ /* Rotate */
+ img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE);
+}
+
+/* img_zbar ------------------------------------------------------------------*/
static void img_iface_decode (void)
{
/* Decode */
@@ -204,6 +254,7 @@ static void img_iface_decode (void) // }
}
+/* img_ocr -------------------------------------------------------------------*/
static void img_iface_read (void)
{
/* OCR */
@@ -212,10 +263,19 @@ static void img_iface_read (void) // }
}
+/* img_orb -------------------------------------------------------------------*/
+static void img_iface_align (void)
+{
+ /* Align to reference image_ref */
+ img_orb_act(image_ref, &image_copy_tmp, IMG_ORB_ACT_ALIGN);
+}
+
+/* img_iface -----------------------------------------------------------------*/
static void img_iface_apply (void)
{
/* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Apply changes");
+ 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.len)++;
@@ -227,7 +287,8 @@ static void img_iface_apply (void) static void img_iface_discard (void)
{
/* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Discard changes");
+ 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.len)++;
@@ -239,7 +300,8 @@ static void img_iface_discard (void) static void img_iface_save_mem (void)
{
/* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Save to memory");
+ 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)++;
@@ -247,7 +309,8 @@ static void img_iface_save_mem (void) img_iface_apply();
/* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Save to mem_%i", 0);
+ snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
+ "Save to mem_%i", 0);
user_iface_log.lvl[user_iface_log.len] = 1;
(user_iface_log.len)++;
@@ -259,7 +322,8 @@ static void img_iface_save_mem (void) static void img_iface_load_mem (void)
{
/* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Load from memory");
+ 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)++;
@@ -267,7 +331,8 @@ static void img_iface_load_mem (void) cvReleaseImage(&image_copy_tmp);
/* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Load from mem_%i", 0);
+ snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
+ "Load from mem_%i", 0);
user_iface_log.lvl[user_iface_log.len] = 1;
(user_iface_log.len)++;
@@ -275,10 +340,28 @@ static void img_iface_load_mem (void) image_copy_tmp = cvCloneImage(image_mem[0]);
}
+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.len)++;
+
+ /* Apply changes before saving */
+ img_iface_apply();
+
+ /* Write into ref */
+ cvReleaseImage(&image_ref);
+ image_ref = cvCloneImage(image_copy_old);
+}
+
+/* save ----------------------------------------------------------------------*/
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");
+ 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)++;
@@ -286,7 +369,8 @@ static void img_iface_save_file (void) img_iface_apply();
/* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "Save as...");
+ 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)++;
diff --git a/modules/image/src/img_orb (copy).cpp b/modules/image/src/img_orb (copy).cpp new file mode 100644 index 0000000..384120d --- /dev/null +++ b/modules/image/src/img_orb (copy).cpp @@ -0,0 +1,128 @@ +/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+/* Standard (C++) ------------------------------------------------------------*/
+ /* INT_MAX */
+ #include <limits>
+ /* std::vector */
+ #include <vector>
+
+/* Standard (C) --------------------------------------------------------------*/
+ /* snprintf() */
+ #include <stdio.h>
+
+/* Packages ------------------------------------------------------------------*/
+ /* opencv */
+ #include <opencv2/opencv.hpp>
+ #include <opencv2/features2d/features2d.hpp>
+
+/* Project -------------------------------------------------------------------*/
+ /* user_iface_log */
+ #include "user_iface.hpp"
+
+ #include "img_orb.hpp"
+
+
+/******************************************************************************
+ ******* macros ***************************************************************
+ ******************************************************************************/
+ # define MAX_FEATURES (500)
+ # define GOOD_MATCH_P (0.15)
+
+
+/******************************************************************************
+ ******* static functions *****************************************************
+ ******************************************************************************/
+static void img_orb_align (struct _IplImage *pattern,
+ struct _IplImage *imgptr);
+
+
+/******************************************************************************
+ ******* main *****************************************************************
+ ******************************************************************************/
+void img_orb_act (struct _IplImage *pattern,
+ struct _IplImage **imgptr2, int action)
+{
+ switch (action) {
+ case IMG_ORB_ACT_ALIGN:
+ img_orb_align(pattern, *imgptr2);
+ break;
+ }
+}
+
+
+/******************************************************************************
+ ******* static functions *****************************************************
+ ******************************************************************************/
+static void img_orb_align (struct _IplImage *pattern,
+ struct _IplImage *imgptr)
+{
+ /* 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(pattern, true);
+ img_1 = cv::cvarrToMat(imgptr, true);
+
+ /* Variables to store keypoints & descriptors */
+ std::vector <class cv::KeyPoint> keypoints_0;
+ std::vector <class cv::KeyPoint> keypoints_1;
+ class cv::Mat descriptors_0;
+ class cv::Mat descriptors_1;
+
+ /* Detect ORB features & compute descriptors */
+ class cv::Ptr <class cv::Feature2D> orb;
+ orb = cv::ORB::create(MAX_FEATURES);
+ orb->detectAndCompute(img_0, cv::Mat::Mat(), keypoints_0, descriptors_0);
+ orb->detectAndCompute(img_1, cv::Mat::Mat(), keypoints_1, descriptors_1);
+
+ /* Match structures */
+ std::vector <struct cv::DMatch> matches;
+ cv::Ptr <class cv::DescriptorMatcher> matcher;
+ matcher = cv::DescriptorMatcher::create("BruteForce-Hamming");
+ matcher->match(descriptors_1, descriptors_0, matches, cv::Mat::Mat());
+
+ /* Sort matches by score */
+ std::sort(matches.begin(), matches.end());
+
+ /* Remove not so good matches */
+ int good_matches;
+ good_matches = GOOD_MATCH_P * matches.size();
+ matches.erase(matches.begin() + good_matches, matches.end());
+
+ /* Draw top matches */
+ class cv::Mat img_matches;
+ cv::drawMatches(img_1, keypoints_1, img_0, keypoints_0, matches,
+ img_matches);
+ cv::imwrite("matches.jpg", img_matches);
+
+ /* Extract location of good matches */
+ std::vector <class cv::Point_ <float>> points_0;
+ std::vector <class cv::Point_ <float>> points_1;
+ int i;
+ for (i = 0; i < matches.size(); i++) {
+ points_1.push_back(keypoints_1[matches[i].queryIdx].pt);
+ points_0.push_back(keypoints_0[matches[i].trainIdx].pt);
+ }
+
+ /* Find homography */
+ class cv::Mat img_hg;
+ img_hg = cv::findHomography(points_1, points_0, CV_RANSAC);
+
+ /* Use homography to warp image */
+ class cv::Mat img_align;
+ cv::warpPerspective(img_1, img_align, img_hg, img_0.size());
+
+ /* Write img_align into imgptr */
+ *imgptr = img_align;
+}
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/modules/image/src/img_orb.cpp b/modules/image/src/img_orb.cpp new file mode 100644 index 0000000..0409387 --- /dev/null +++ b/modules/image/src/img_orb.cpp @@ -0,0 +1,143 @@ +/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+/* Standard C++ --------------------------------------------------------------*/
+ /* std::vector */
+ #include <vector>
+
+/* Standard C ----------------------------------------------------------------*/
+ /* snprintf() */
+ #include <cstdio>
+
+/* Packages ------------------------------------------------------------------*/
+ /* opencv */
+ #include <opencv2/opencv.hpp>
+ #include <opencv2/features2d/features2d.hpp>
+
+/* Project -------------------------------------------------------------------*/
+ /* user_iface_log */
+ #include "user_iface.hpp"
+
+ #include "img_orb.hpp"
+
+
+/******************************************************************************
+ ******* macros ***************************************************************
+ ******************************************************************************/
+ # define MAX_FEATURES (500)
+ # define GOOD_MATCH_P (0.15)
+
+
+/******************************************************************************
+ ******* static functions *****************************************************
+ ******************************************************************************/
+static void img_orb_align (struct _IplImage *img_ref,
+ struct _IplImage **imgptr2);
+
+
+/******************************************************************************
+ ******* main *****************************************************************
+ ******************************************************************************/
+void img_orb_act (struct _IplImage *img_ref,
+ struct _IplImage **imgptr2, int action)
+{
+ switch (action) {
+ case IMG_ORB_ACT_ALIGN:
+ img_orb_align(img_ref, imgptr2);
+ break;
+ }
+}
+
+
+/******************************************************************************
+ ******* static functions *****************************************************
+ ******************************************************************************/
+static void img_orb_align (struct _IplImage *img_ref,
+ struct _IplImage **imgptr2)
+{
+ /* 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;
+ class cv::Mat descriptors_0;
+ class cv::Mat descriptors_1;
+
+ /* Detect ORB features & compute descriptors */
+ 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 = 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);
+*/
+
+ /* Match structures */
+ std::vector <struct cv::DMatch> matches;
+ cv::Ptr <class cv::DescriptorMatcher> matcher;
+ matcher = cv::DescriptorMatcher::create("BruteForce-Hamming");
+ matcher->match(descriptors_1, descriptors_0, matches, cv::Mat());
+
+ /* Sort matches by score */
+ std::sort(matches.begin(), matches.end());
+
+ /* Remove not so good matches */
+ int good_matches;
+ good_matches = GOOD_MATCH_P * matches.size();
+ matches.erase(matches.begin() + good_matches, matches.end());
+
+ /* Draw top matches */
+ class cv::Mat img_matches;
+ cv::drawMatches(img_1, keypoints_1, img_0, keypoints_0, matches,
+ img_matches);
+ cv::imwrite("matches.jpg", img_matches);
+
+ /* Extract location of good matches */
+ std::vector <class cv::Point_ <float>> points_0;
+ std::vector <class cv::Point_ <float>> points_1;
+ int i;
+ for (i = 0; i < matches.size(); i++) {
+ points_1.push_back(keypoints_1[matches[i].queryIdx].pt);
+ points_0.push_back(keypoints_0[matches[i].trainIdx].pt);
+ }
+
+ /* Find homography */
+ class cv::Mat img_hg;
+ img_hg = cv::findHomography(points_1, points_0, CV_RANSAC);
+
+ /* Use homography to warp image */
+ class cv::Mat img_align;
+ cv::warpPerspective(img_1, img_align, img_hg, img_0.size());
+
+ /* Write img_align into 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);
+ img_align.release();
+}
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/modules/image/tmp/Makefile b/modules/image/tmp/Makefile index 09adfe2..8fb21ab 100644 --- a/modules/image/tmp/Makefile +++ b/modules/image/tmp/Makefile @@ -14,7 +14,7 @@ SRC_DIR = $(IMG_DIR)/src/ # dependencies -_ALL = img_cv.o img_zbar.o img_ocr.o img_iface.o +_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 @@ -44,9 +44,18 @@ IMGOCR_INC_DIRS = -I $(INC_DIR) \ -I $(USR_INC_DIR) \ -I $(LIBALX_INC_DIR) +IMGORB_INC_USR = user_iface.hpp +IMGORB_INC = img_orb.hpp +IMGORB_DEPS = $(SRC_DIR)/img_orb.cpp \ + $(patsubst %,$(INC_DIR)/%,$(IMGORB_INC)) \ + $(patsubst %,$(USR_INC_DIR)/%,$(IMGORB_INC_USR)) +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 +IMGI_INC = img_iface.h img_cv.h img_zbar.h img_ocr.h img_orb.h IMGI_DEPS = $(SRC_DIR)/img_iface.c \ $(patsubst %,$(INC_DIR)/%,$(IMGI_INC)) \ $(patsubst %,$(SAVE_INC_DIR)/%,$(IMGI_INC_SAVE)) \ @@ -88,6 +97,13 @@ img_ocr.o: img_ocr.s $(Q)$(AS) $< -o $@ @echo " AS $@" +img_orb.s: $(IMGORB_DEPS) + $(Q)$(CXX) $(CXXFLAGS) $(IMGORB_INC_DIRS) -S $< -o $@ + @echo " CXX $@" +img_orb.o: img_orb.s + $(Q)$(AS) $< -o $@ + @echo " AS $@" + img_iface.s: $(IMGI_DEPS) $(Q)$(CC) $(CFLAGS) $(IMGI_INC_DIRS) -S $< -o $@ @echo " CC $@" diff --git a/modules/menu/inc/menu_iface.hpp b/modules/menu/inc/menu_iface.hpp new file mode 100644 index 0000000..a1fbb25 --- /dev/null +++ b/modules/menu/inc/menu_iface.hpp @@ -0,0 +1,55 @@ +/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# ifndef VA_MENU_IFACE_HPP
+ # define VA_MENU_IFACE_HPP
+
+
+/******************************************************************************
+ ******* C wrapper ************************************************************
+ ******************************************************************************/
+extern "C" {
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+ enum Menu_Iface_Mode {
+ MENU_IFACE_FOO = 0,
+ MENU_IFACE_CLUI,
+ MENU_IFACE_TUI
+ };
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+ extern int menu_iface_mode;
+
+
+/******************************************************************************
+ ******* functions ************************************************************
+ ******************************************************************************/
+ void menu_iface (void);
+
+
+/******************************************************************************
+ ******* C wrapper ************************************************************
+ ******************************************************************************/
+} /* extern "C" */
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# endif /* menu_iface.hpp */
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/modules/menu/inc/parser.hpp b/modules/menu/inc/parser.hpp new file mode 100644 index 0000000..ff40d1f --- /dev/null +++ b/modules/menu/inc/parser.hpp @@ -0,0 +1,39 @@ +/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# ifndef VA_PARSER_HPP
+ # define VA_PARSER_HPP
+
+
+/******************************************************************************
+ ******* C wrapper ************************************************************
+ ******************************************************************************/
+extern "C" {
+
+
+/******************************************************************************
+ ******* functions ************************************************************
+ ******************************************************************************/
+ void parser (int argc, char *argv[]);
+
+
+/******************************************************************************
+ ******* C wrapper ************************************************************
+ ******************************************************************************/
+} /* extern "C" */
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# endif /* parser.hpp */
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/modules/save/inc/save.hpp b/modules/save/inc/save.hpp new file mode 100644 index 0000000..23084b0 --- /dev/null +++ b/modules/save/inc/save.hpp @@ -0,0 +1,75 @@ +/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# ifndef VA_SAVE_HPP
+ # define VA_SAVE_HPP
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+/* Standard C ----------------------------------------------------------------*/
+ /* FILENAME_MAX */
+ #include <cstdio>
+
+/* Project -------------------------------------------------------------------*/
+ /* struct _IplImage */
+ #include <opencv2/opencv.hpp>
+
+
+/******************************************************************************
+ ******* C wrapper ************************************************************
+ ******************************************************************************/
+extern "C" {
+
+
+/******************************************************************************
+ ******* macros ***************************************************************
+ ******************************************************************************/
+ # define ENV_HOME "HOME"
+
+ # define USER_PROG_DIR ".vision-artificial/"
+ # define USER_SAVED_DIR ".vision-artificial/saved/"
+ # define SAVED_NAME_DEFAULT "saved"
+
+
+/******************************************************************************
+ ******* 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];
+
+
+/******************************************************************************
+ ******* functions ************************************************************
+ ******************************************************************************/
+ void save_init (void);
+ void save_cleanup (void);
+ void save_clr (void);
+ void load_image_file (void);
+ void save_image_file (void);
+
+
+/******************************************************************************
+ ******* C wrapper ************************************************************
+ ******************************************************************************/
+} /* extern "C" */
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# endif /* save.h */
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/modules/user/inc/user_iface.h b/modules/user/inc/user_iface.h index 9885653..b5d5208 100644 --- a/modules/user/inc/user_iface.h +++ b/modules/user/inc/user_iface.h @@ -14,7 +14,7 @@ ******* headers **************************************************************
******************************************************************************/
/* struct IplImage */
- #include "cv.h"
+ #include <cv.h>
/******************************************************************************
@@ -38,9 +38,10 @@ USER_IFACE_ACT_CV = 0x0100,
USER_IFACE_ACT_INVERT,
- USER_IFACE_ACT_ROTATE,
USER_IFACE_ACT_BGR2GRAY,
USER_IFACE_ACT_COMPONENT,
+ USER_IFACE_ACT_THRESHOLD,
+ USER_IFACE_ACT_ROTATE,
USER_IFACE_ACT_ZB = 0x0200,
USER_IFACE_ACT_DECODE,
@@ -48,14 +49,20 @@ USER_IFACE_ACT_OCR = 0x0400,
USER_IFACE_ACT_READ,
- USER_IFACE_ACT_IMGI = 0x0800,
+ USER_IFACE_ACT_ORB = 0x0800,
+ USER_IFACE_ACT_ALIGN,
+
+ USER_IFACE_ACT_IMGI = 0x1000,
USER_IFACE_ACT_APPLY,
USER_IFACE_ACT_DISCARD,
USER_IFACE_ACT_SAVE_MEM,
USER_IFACE_ACT_LOAD_MEM,
+ USER_IFACE_ACT_SAVE_REF,
+
+ USER_IFACE_ACT_SAVE = 0x2000,
USER_IFACE_ACT_SAVE_FILE,
- USER_IFACE_ACT_USRI = 0x1000,
+ USER_IFACE_ACT_USRI = 0x4000,
USER_IFACE_ACT_SHOW_OCR,
USER_IFACE_ACT_QUIT
};
diff --git a/modules/user/inc/user_iface.hpp b/modules/user/inc/user_iface.hpp new file mode 100644 index 0000000..8d5a8f3 --- /dev/null +++ b/modules/user/inc/user_iface.hpp @@ -0,0 +1,121 @@ +/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# ifndef VA_USER_IFACE_HPP
+ # define VA_USER_IFACE_HPP
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+/* Project -------------------------------------------------------------------*/
+ /* struct _IplImage */
+ #include <opencv2/opencv.hpp>
+
+
+/******************************************************************************
+ ******* C wrapper ************************************************************
+ ******************************************************************************/
+extern "C" {
+
+
+/******************************************************************************
+ ******* macros ***************************************************************
+ ******************************************************************************/
+ # define LOG_LEN (1024)
+ # define LOG_LINE_LEN (35)
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+ enum Player_Iface_Mode {
+ USER_IFACE_FOO,
+ USER_IFACE_CLUI,
+ USER_IFACE_TUI
+ };
+
+ enum Player_Iface_Action {
+ USER_IFACE_ACT_FOO = 0,
+
+ USER_IFACE_ACT_CV = 0x0100,
+ USER_IFACE_ACT_INVERT,
+ USER_IFACE_ACT_BGR2GRAY,
+ USER_IFACE_ACT_COMPONENT,
+ USER_IFACE_ACT_THRESHOLD,
+ USER_IFACE_ACT_ROTATE,
+
+ USER_IFACE_ACT_ZB = 0x0200,
+ USER_IFACE_ACT_DECODE,
+
+ USER_IFACE_ACT_OCR = 0x0400,
+ USER_IFACE_ACT_READ,
+
+ USER_IFACE_ACT_ORB = 0x0800,
+ USER_IFACE_ACT_ALIGN,
+
+ USER_IFACE_ACT_IMGI = 0x1000,
+ USER_IFACE_ACT_APPLY,
+ USER_IFACE_ACT_DISCARD,
+ USER_IFACE_ACT_SAVE_MEM,
+ USER_IFACE_ACT_LOAD_MEM,
+ USER_IFACE_ACT_SAVE_REF,
+
+ USER_IFACE_ACT_SAVE = 0x2000,
+ USER_IFACE_ACT_SAVE_FILE,
+
+ USER_IFACE_ACT_USRI = 0x4000,
+ USER_IFACE_ACT_SHOW_OCR,
+ USER_IFACE_ACT_QUIT
+ };
+
+
+/******************************************************************************
+ ******* structs **************************************************************
+ ******************************************************************************/
+ struct User_Iface_Log {
+ int len;
+ char line [LOG_LEN] [LOG_LINE_LEN];
+ int lvl [LOG_LEN];
+ };
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+ extern int user_iface_mode;
+ extern struct User_Iface_Log user_iface_log;
+
+
+/******************************************************************************
+ ******* functions ************************************************************
+ ******************************************************************************/
+ void user_iface_init (void);
+ void user_iface_cleanup (void);
+ void user_iface (struct _IplImage *imgptr);
+ void user_iface_save_name (const char *filepath, char *filename,
+ int destsize);
+ int64_t user_iface_getint (double m, int64_t def, double M,
+ const char *title, const char *help);
+
+
+/******************************************************************************
+ ******* C wrapper ************************************************************
+ ******************************************************************************/
+} /* extern "C" */
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+# endif /* user_iface.hpp */
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/modules/user/src/user_tui.c b/modules/user/src/user_tui.c index 046072f..ac786bf 100644 --- a/modules/user/src/user_tui.c +++ b/modules/user/src/user_tui.c @@ -223,13 +223,16 @@ static int usr_input (void) action = USER_IFACE_ACT_INVERT;
break;
case '1':
- action = USER_IFACE_ACT_ROTATE;
+ action = USER_IFACE_ACT_BGR2GRAY;
break;
case '2':
- action = USER_IFACE_ACT_BGR2GRAY;
+ action = USER_IFACE_ACT_COMPONENT;
break;
case '3':
- action = USER_IFACE_ACT_COMPONENT;
+ action = USER_IFACE_ACT_THRESHOLD;
+ break;
+ case '4':
+ action = USER_IFACE_ACT_ROTATE;
break;
default:
action = USER_IFACE_ACT_FOO;
@@ -262,6 +265,19 @@ static int usr_input (void) break;
}
break;
+ case '4':
+ /* img_orb */
+ ch = wgetch(win_log);
+
+ switch (ch) {
+ case '0':
+ action = USER_IFACE_ACT_ALIGN;
+ break;
+ default:
+ action = USER_IFACE_ACT_FOO;
+ break;
+ }
+ break;
default:
action = USER_IFACE_ACT_FOO;
break;
@@ -280,6 +296,10 @@ static int usr_input (void) action = USER_IFACE_ACT_QUIT;
break;
+ case 'r':
+ action = USER_IFACE_ACT_SAVE_REF;
+ break;
+
case 's':
action = USER_IFACE_ACT_SAVE_FILE;
break;
@@ -342,14 +362,17 @@ static void show_help (void) mvwprintw(win_help, r++, c, "Discard: %s", "Backspace");
mvwprintw(win_help, r++, c, "Save to mem: %c", 'm');
mvwprintw(win_help, r++, c, "Load from mem: %c", 'l');
+ mvwprintw(win_help, r++, c, "Save to ref: %c", 'r');
mvwprintw(win_help, r++, c, "Save to file: %c", 's');
mvwprintw(win_help, r++, c, "Functions:");
mvwprintw(win_help, r++, c, " - Invert: %s", "f10");
- mvwprintw(win_help, r++, c, " - Rotate: %s", "f11");
- mvwprintw(win_help, r++, c, " - BGR -> Gray: %s", "f12");
- mvwprintw(win_help, r++, c, " - Component: %s", "f13");
+ mvwprintw(win_help, r++, c, " - BGR -> Gray: %s", "f11");
+ mvwprintw(win_help, r++, c, " - Component: %s", "f12");
+ mvwprintw(win_help, r++, c, " - Threshold: %s", "f13");
+ mvwprintw(win_help, r++, c, " - Rotate: %s", "f14");
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");
mvwprintw(win_help, r++, c, "Exercises:");
mvwprintw(win_help, r++, c, "Other:");
mvwprintw(win_help, r++, c, " - Show OCR: %s", "u1");
diff --git a/src/main.c b/src/main.cpp index cd26f9a..bb9a6ce 100644 --- a/src/main.c +++ b/src/main.cpp @@ -6,24 +6,21 @@ /******************************************************************************
******* headers **************************************************************
******************************************************************************/
-/* * * * * * * * * *
- * * * Standard * * * * * *
- * * * * * * * * * */
+/* Standard C ----------------------------------------------------------------*/
/* getchar() */
- #include <stdio.h>
+ #include <cstdio>
-/* * * * * * * * * *
- * * * Other * * * * * * *
- * * * * * * * * * */
- #include "alx_ncur.h"
+/* libalx --------------------------------------------------------------------*/
+ #include "alx_ncur.hpp"
+/* Project -------------------------------------------------------------------*/
/* about_init() & print_cpright() */
- #include "about.h"
- #include "img_iface.h"
- #include "menu_iface.h"
- #include "user_iface.h"
- #include "parser.h"
- #include "save.h"
+ #include "about.hpp"
+ #include "img_iface.hpp"
+ #include "menu_iface.hpp"
+ #include "user_iface.hpp"
+ #include "parser.hpp"
+ #include "save.hpp"
/******************************************************************************
diff --git a/tmp/Makefile b/tmp/Makefile index 2b7b448..5cfe99e 100644 --- a/tmp/Makefile +++ b/tmp/Makefile @@ -30,24 +30,21 @@ SRC_DIR = $(MAIN_DIR)/src/ ALL = main.o -MAIN_INC_LIBALX = alx_ncur.h -MAIN_INC_ABOUT = about.h -MAIN_INC_CTRL = start.h -MAIN_INC_IMG = img_iface.h -MAIN_INC_MENU = parser.h menu_iface.h -MAIN_INC_SAVE = save.h -MAIN_INC_USR = user_iface.h -MAIN_DEPS = $(SRC_DIR)/main.c \ +MAIN_INC_LIBALX = alx_ncur.hpp +MAIN_INC_ABOUT = about.hpp +MAIN_INC_IMG = img_iface.hpp +MAIN_INC_MENU = parser.hpp menu_iface.hpp +MAIN_INC_SAVE = save.hpp +MAIN_INC_USR = user_iface.hpp +MAIN_DEPS = $(SRC_DIR)/main.cpp \ $(patsubst %,$(LIBALX_INC_DIR)/%,$(MAIN_INC_LIBALX)) \ $(patsubst %,$(ABOUT_INC_DIR)/%,$(MAIN_INC_ABOUT)) \ - $(patsubst %,$(CTRL_INC_DIR)/%,$(MAIN_INC_CTRL)) \ $(patsubst %,$(IMG_INC_DIR)/%,$(MAIN_INC_IMG)) \ $(patsubst %,$(MENU_INC_DIR)/%,$(MAIN_INC_MENU)) \ $(patsubst %,$(SAVE_INC_DIR)/%,$(MAIN_INC_SAVE)) \ $(patsubst %,$(USR_INC_DIR)/%,$(MAIN_INC_USR)) MAIN_INC_DIRS = -I $(LIBALX_INC_DIR) \ -I $(ABOUT_INC_DIR) \ - -I $(CTRL_INC_DIR) \ -I $(IMG_INC_DIR) \ -I $(MENU_INC_DIR) \ -I $(SAVE_INC_DIR) \ @@ -60,8 +57,8 @@ MAIN_INC_DIRS = -I $(LIBALX_INC_DIR) \ all: $(ALL) main.s: $(MAIN_DEPS) - $(Q)$(CC) $(CFLAGS) $(MAIN_INC_DIRS) -S $< -o $@ - @echo " CC $@" + $(Q)$(CXX) $(CXXFLAGS) $(MAIN_INC_DIRS) -S $< -o $@ + @echo " CXX $@" main.o: main.s $(Q)$(AS) $< -o $@ @echo " AS $@" |