diff options
author | AlejandroColomar <colomar.6.4.3@gmail.com> | 2019-01-04 16:46:45 +0100 |
---|---|---|
committer | AlejandroColomar <colomar.6.4.3@gmail.com> | 2019-01-04 16:46:45 +0100 |
commit | 4cd8237c148ffdc199e209454813b77bfacec4a6 (patch) | |
tree | cd4d00ca3a94d804a99c061972c0e6958e58d021 | |
parent | ddbe05a3b4bd4ec8b195f7526f886896ac0f9610 (diff) |
Unix new lines
60 files changed, 12658 insertions, 12658 deletions
diff --git a/modules/about/inc/about.h b/modules/about/inc/about.h index 5122d14..62a0963 100644 --- a/modules/about/inc/about.h +++ b/modules/about/inc/about.h @@ -1,63 +1,63 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_ABOUT_H
- # define VA_ABOUT_H
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* FILENAME_MAX */
- #include <stdio.h>
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
- # define PROG_NAME "vision-artificial"
- # define PROG_YEAR "2018"
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Share_File {
- SHARE_COPYRIGHT,
- SHARE_DISCLAIMER,
- SHARE_HELP,
- SHARE_LICENSE,
- SHARE_USAGE
- };
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
- extern char share_path [FILENAME_MAX];
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- void about_init (void);
- void snprint_share_file (char *dest, int destsize, int share_file);
- void print_share_file (int share_file);
- void print_version (void);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* about.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_ABOUT_H + # define VA_ABOUT_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* FILENAME_MAX */ + #include <stdio.h> + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define PROG_NAME "vision-artificial" + # define PROG_YEAR "2018" + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Share_File { + SHARE_COPYRIGHT, + SHARE_DISCLAIMER, + SHARE_HELP, + SHARE_LICENSE, + SHARE_USAGE + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern char share_path [FILENAME_MAX]; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void about_init (void); + void snprint_share_file (char *dest, int destsize, int share_file); + void print_share_file (int share_file); + void print_version (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* about.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/about/inc/about.hpp b/modules/about/inc/about.hpp index 50180ba..a1a9f2e 100644 --- a/modules/about/inc/about.hpp +++ b/modules/about/inc/about.hpp @@ -1,75 +1,75 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_ABOUT_HPP
- # define VA_ABOUT_HPP
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* FILENAME_MAX */
- #include <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 **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * 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/about/src/about.c b/modules/about/src/about.c index d443e1d..a9561e0 100644 --- a/modules/about/src/about.c +++ b/modules/about/src/about.c @@ -1,88 +1,88 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* printf() */
- #include <stdio.h>
-
-/* libalx --------------------------------------------------------------------*/
- /* alx_snprint_file() */
- #include "alx_file.h"
-
-/* Module --------------------------------------------------------------------*/
- #include "about.h"
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
- # define BUFF_SIZE_TEXT (1048576)
-
- # define BEGINNING "\n┌──────────────────────────────────────────────────────────────────────────────┐\n"
- # define ENDING "└──────────────────────────────────────────────────────────────────────────────┘\n\n"
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-char share_path [FILENAME_MAX];
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void about_init (void)
-{
- snprintf(share_path, FILENAME_MAX, "%s/%s/", INSTALL_SHARE_DIR, SHARE_DIR);
-}
-
-void snprint_share_file (char *dest, int destsize, int share_file)
-{
- char file_name [FILENAME_MAX];
-
- switch (share_file) {
- case SHARE_COPYRIGHT:
- snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "COPYRIGHT.txt");
- break;
- case SHARE_DISCLAIMER:
- snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "DISCLAIMER.txt");
- break;
- case SHARE_HELP:
- snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "HELP.txt");
- break;
- case SHARE_LICENSE:
- snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "LICENSE.txt");
- break;
- case SHARE_USAGE:
- snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "USAGE.txt");
- break;
- }
-
- alx_snprint_file(dest, destsize, file_name);
-}
-
-void print_share_file (int share_file)
-{
- char str [BUFF_SIZE_TEXT];
-
- snprint_share_file(str, BUFF_SIZE_TEXT, share_file);
-
- printf(BEGINNING);
- printf("%s", str);
- printf(ENDING);
-}
-
-void print_version (void)
-{
- printf("" PROG_NAME " " PROG_VERSION "\n\n");
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* printf() */ + #include <stdio.h> + +/* libalx --------------------------------------------------------------------*/ + /* alx_snprint_file() */ + #include "alx_file.h" + +/* Module --------------------------------------------------------------------*/ + #include "about.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define BUFF_SIZE_TEXT (1048576) + + # define BEGINNING "\n┌──────────────────────────────────────────────────────────────────────────────┐\n" + # define ENDING "└──────────────────────────────────────────────────────────────────────────────┘\n\n" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +char share_path [FILENAME_MAX]; + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void about_init (void) +{ + snprintf(share_path, FILENAME_MAX, "%s/%s/", INSTALL_SHARE_DIR, SHARE_DIR); +} + +void snprint_share_file (char *dest, int destsize, int share_file) +{ + char file_name [FILENAME_MAX]; + + switch (share_file) { + case SHARE_COPYRIGHT: + snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "COPYRIGHT.txt"); + break; + case SHARE_DISCLAIMER: + snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "DISCLAIMER.txt"); + break; + case SHARE_HELP: + snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "HELP.txt"); + break; + case SHARE_LICENSE: + snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "LICENSE.txt"); + break; + case SHARE_USAGE: + snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "USAGE.txt"); + break; + } + + alx_snprint_file(dest, destsize, file_name); +} + +void print_share_file (int share_file) +{ + char str [BUFF_SIZE_TEXT]; + + snprint_share_file(str, BUFF_SIZE_TEXT, share_file); + + printf(BEGINNING); + printf("%s", str); + printf(ENDING); +} + +void print_version (void) +{ + printf("" PROG_NAME " " PROG_VERSION "\n\n"); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/ctrl/inc/start.h b/modules/ctrl/inc/start.h index 9b79302..1ef2af6 100644 --- a/modules/ctrl/inc/start.h +++ b/modules/ctrl/inc/start.h @@ -1,43 +1,43 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_START_H
- # define VA_START_H
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Start_Mode {
- START_FOO = 0,
- START_SINGLE,
- START_SERIES
- };
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
- extern int start_mode;
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- void start_switch (void);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* start.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_START_H + # define VA_START_H + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Start_Mode { + START_FOO = 0, + START_SINGLE, + START_SERIES + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern int start_mode; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void start_switch (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* start.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/ctrl/src/start.c b/modules/ctrl/src/start.c index bd801c1..37ea1b4 100644 --- a/modules/ctrl/src/start.c +++ b/modules/ctrl/src/start.c @@ -1,105 +1,105 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* errno */
- #include <errno.h>
- #include <stddef.h>
- /* printf() */
- #include <stdio.h>
-
-/* Project -------------------------------------------------------------------*/
- /* img_iface_load() */
- #include "img_iface.h"
- /* proc_iface_series() */
- #include "proc_iface.h"
- /* saved_name*/
- #include "save.h"
- /* user_iface() */
- #include "user_iface.h"
-
-/* Module --------------------------------------------------------------------*/
- #include "start.h"
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-int start_mode;
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void start_foo (void);
-static void start_single (void);
-static void start_series (void);
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void start_switch (void)
-{
- switch (start_mode) {
- case START_FOO:
- start_foo();
- break;
-
- case START_SINGLE:
- start_single();
- break;
-
- case START_SERIES:
- start_series();
- break;
- }
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void start_foo (void)
-{
- /* empty */
-}
-
-static void start_single (void)
-{
- errno = 0;
- img_iface_load(NULL, saved_name);
-
- if (!errno) {
- user_iface_init();
- user_iface();
- user_iface_cleanup();
- } else {
- printf("errno:%i\n", errno);
- }
-
- img_iface_cleanup();
-}
-
-static void start_series (void)
-{
- int tmp;
- tmp = user_iface_mode;
- user_iface_mode = USER_IFACE_CLUI;
-
- user_iface_init();
- proc_iface_series();
- user_iface_cleanup();
-
- user_iface_mode = tmp;
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* errno */ + #include <errno.h> + #include <stddef.h> + /* printf() */ + #include <stdio.h> + +/* Project -------------------------------------------------------------------*/ + /* img_iface_load() */ + #include "img_iface.h" + /* proc_iface_series() */ + #include "proc_iface.h" + /* saved_name*/ + #include "save.h" + /* user_iface() */ + #include "user_iface.h" + +/* Module --------------------------------------------------------------------*/ + #include "start.h" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +int start_mode; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void start_foo (void); +static void start_single (void); +static void start_series (void); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void start_switch (void) +{ + switch (start_mode) { + case START_FOO: + start_foo(); + break; + + case START_SINGLE: + start_single(); + break; + + case START_SERIES: + start_series(); + break; + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void start_foo (void) +{ + /* empty */ +} + +static void start_single (void) +{ + errno = 0; + img_iface_load(NULL, saved_name); + + if (!errno) { + user_iface_init(); + user_iface(); + user_iface_cleanup(); + } else { + printf("errno:%i\n", errno); + } + + img_iface_cleanup(); +} + +static void start_series (void) +{ + int tmp; + tmp = user_iface_mode; + user_iface_mode = USER_IFACE_CLUI; + + user_iface_init(); + proc_iface_series(); + user_iface_cleanup(); + + user_iface_mode = tmp; +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/inc/img_alx.hpp b/modules/image/inc/img_alx.hpp index 9476ef8..d3867d6 100644 --- a/modules/image/inc/img_alx.hpp +++ b/modules/image/inc/img_alx.hpp @@ -1,52 +1,52 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_IMG_ALX_H
- # define VA_IMG_ALX_H
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
- /* openCV */
- #include <opencv2/opencv.hpp>
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Img_Alx_Action {
- IMG_ALX_ACT_FOO = 0x000000u,
-
- IMG_ALX_ACT_ALX = 0x000010u,
- IMG_ALX_ACT_LOCAL_MAX,
- IMG_ALX_ACT_SKELETON,
- IMG_ALX_ACT_LINES_HORIZONTAL,
- IMG_ALX_ACT_LINES_VERTICAL,
- IMG_ALX_ACT_MEAN_HORIZONTAL,
- IMG_ALX_ACT_MEAN_VERTICAL,
- IMG_ALX_ACT_MEDIAN_HORIZONTAL,
- IMG_ALX_ACT_MEDIAN_VERTICAL
- };
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
-void img_alx_act (class cv::Mat *imgptr, int action, void *data);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* img_alx.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_IMG_ALX_H + # define VA_IMG_ALX_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + /* openCV */ + #include <opencv2/opencv.hpp> + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Img_Alx_Action { + IMG_ALX_ACT_FOO = 0x000000u, + + IMG_ALX_ACT_ALX = 0x000010u, + IMG_ALX_ACT_LOCAL_MAX, + IMG_ALX_ACT_SKELETON, + IMG_ALX_ACT_LINES_HORIZONTAL, + IMG_ALX_ACT_LINES_VERTICAL, + IMG_ALX_ACT_MEAN_HORIZONTAL, + IMG_ALX_ACT_MEAN_VERTICAL, + IMG_ALX_ACT_MEDIAN_HORIZONTAL, + IMG_ALX_ACT_MEDIAN_VERTICAL + }; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void img_alx_act (class cv::Mat *imgptr, int action, void *data); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* img_alx.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/inc/img_calib3d.hpp b/modules/image/inc/img_calib3d.hpp index 777f33c..7079d68 100644 --- a/modules/image/inc/img_calib3d.hpp +++ b/modules/image/inc/img_calib3d.hpp @@ -1,46 +1,46 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_IMG_CALIB3D_HPP
- # define VA_IMG_CALIB3D_HPP
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
- /* openCV */
- #include <opencv2/opencv.hpp>
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Img_Calib3d_Action {
- IMG_CALIB3D_ACT_FOO = 0x000000u,
-
- IMG_CALIB3D_ACT_CALIB3D = 0x000400u,
- IMG_CALIB3D_ACT_CALIBRATE,
- IMG_CALIB3D_ACT_UNDISTORT
- };
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- void img_calib3d_act (class cv::Mat *imgptr, int action, void *data);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* img_calib3d.hpp */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_IMG_CALIB3D_HPP + # define VA_IMG_CALIB3D_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + /* openCV */ + #include <opencv2/opencv.hpp> + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Img_Calib3d_Action { + IMG_CALIB3D_ACT_FOO = 0x000000u, + + IMG_CALIB3D_ACT_CALIB3D = 0x000400u, + IMG_CALIB3D_ACT_CALIBRATE, + IMG_CALIB3D_ACT_UNDISTORT + }; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void img_calib3d_act (class cv::Mat *imgptr, int action, void *data); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* img_calib3d.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/inc/img_cv.hpp b/modules/image/inc/img_cv.hpp index 7412f46..61cb78a 100644 --- a/modules/image/inc/img_cv.hpp +++ b/modules/image/inc/img_cv.hpp @@ -1,71 +1,71 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_IMG_CV_H
- # define VA_IMG_CV_H
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* packages ------------------------------------------------------------------*/
- #include <opencv2/opencv.hpp>
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Img_Cv_Action {
- IMG_CV_ACT_FOO = 0x000000u,
-
- IMG_CV_ACT_CV = 0x000100u,
- IMG_CV_ACT_PIXEL_GET,
- IMG_CV_ACT_PIXEL_SET,
- IMG_CV_ACT_SET_ROI,
- IMG_CV_ACT_AND_2REF,
- IMG_CV_ACT_NOT,
- IMG_CV_ACT_OR_2REF,
- IMG_CV_ACT_COMPONENT,
- IMG_CV_ACT_DILATE,
- IMG_CV_ACT_ERODE,
- IMG_CV_ACT_SMOOTH,
- IMG_CV_ACT_SOBEL,
- IMG_CV_ACT_BORDER,
- IMG_CV_ACT_MIRROR,
- IMG_CV_ACT_ROTATE_ORTO,
- IMG_CV_ACT_ROTATE,
- IMG_CV_ACT_ADAPTIVE_THRESHOLD,
- IMG_CV_ACT_CVT_COLOR,
- IMG_CV_ACT_DISTANCE_TRANSFORM,
- IMG_CV_ACT_THRESHOLD,
- IMG_CV_ACT_HISTOGRAM,
- IMG_CV_ACT_HISTOGRAM_C3,
- IMG_CV_ACT_CONTOURS,
- IMG_CV_ACT_CONTOURS_SIZE,
- IMG_CV_ACT_BOUNDING_RECT,
- IMG_CV_ACT_FIT_ELLIPSE,
- IMG_CV_ACT_MIN_AREA_RECT,
- IMG_CV_ACT_HOUGH_CIRCLES
- };
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
-void img_cv_act (class cv::Mat *imgptr, int action, void *data);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* img_cv.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_IMG_CV_H + # define VA_IMG_CV_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* packages ------------------------------------------------------------------*/ + #include <opencv2/opencv.hpp> + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Img_Cv_Action { + IMG_CV_ACT_FOO = 0x000000u, + + IMG_CV_ACT_CV = 0x000100u, + IMG_CV_ACT_PIXEL_GET, + IMG_CV_ACT_PIXEL_SET, + IMG_CV_ACT_SET_ROI, + IMG_CV_ACT_AND_2REF, + IMG_CV_ACT_NOT, + IMG_CV_ACT_OR_2REF, + IMG_CV_ACT_COMPONENT, + IMG_CV_ACT_DILATE, + IMG_CV_ACT_ERODE, + IMG_CV_ACT_SMOOTH, + IMG_CV_ACT_SOBEL, + IMG_CV_ACT_BORDER, + IMG_CV_ACT_MIRROR, + IMG_CV_ACT_ROTATE_ORTO, + IMG_CV_ACT_ROTATE, + IMG_CV_ACT_ADAPTIVE_THRESHOLD, + IMG_CV_ACT_CVT_COLOR, + IMG_CV_ACT_DISTANCE_TRANSFORM, + IMG_CV_ACT_THRESHOLD, + IMG_CV_ACT_HISTOGRAM, + IMG_CV_ACT_HISTOGRAM_C3, + IMG_CV_ACT_CONTOURS, + IMG_CV_ACT_CONTOURS_SIZE, + IMG_CV_ACT_BOUNDING_RECT, + IMG_CV_ACT_FIT_ELLIPSE, + IMG_CV_ACT_MIN_AREA_RECT, + IMG_CV_ACT_HOUGH_CIRCLES + }; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void img_cv_act (class cv::Mat *imgptr, int action, void *data); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* img_cv.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/inc/img_iface.h b/modules/image/inc/img_iface.h index bfdbb70..460db47 100644 --- a/modules/image/inc/img_iface.h +++ b/modules/image/inc/img_iface.h @@ -1,187 +1,187 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_IMG_IFACE_H
- # define VA_IMG_IFACE_H
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- #include <stddef.h>
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
-/* Constants -----------------------------------------------------------------*/
- # define CONTOURS_MAX (65536)
- # define OCR_TEXT_MAX (1048576)
- # define ZB_CODES_MAX (10)
- # define ZBAR_LEN_MAX (1048576)
-
- # define IMG_IFACE_THR_OTSU (-1)
-
-/* Functions -----------------------------------------------------------------*/
- # define img_iface_act_nodata(x) \
- do { \
- img_iface_act(x, NULL); \
- } while (0)
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Img_Iface_Action {
- IMG_IFACE_ACT_FOO = 0x000000u,
-
- IMG_IFACE_ACT_ALX = 0x000010u,
- IMG_IFACE_ACT_LOCAL_MAX,
- IMG_IFACE_ACT_SKELETON,
- IMG_IFACE_ACT_LINES_HORIZONTAL,
- IMG_IFACE_ACT_LINES_VERTICAL,
- IMG_IFACE_ACT_MEAN_HORIZONTAL,
- IMG_IFACE_ACT_MEAN_VERTICAL,
- IMG_IFACE_ACT_MEDIAN_HORIZONTAL,
- IMG_IFACE_ACT_MEDIAN_VERTICAL,
-
- IMG_IFACE_ACT_CV = 0x000100u,
- IMG_IFACE_ACT_PIXEL_GET,
- IMG_IFACE_ACT_PIXEL_SET,
- IMG_IFACE_ACT_SET_ROI,
- IMG_IFACE_ACT_SET_ROI_2RECT,
- IMG_IFACE_ACT_AND_2REF,
- IMG_IFACE_ACT_NOT,
- IMG_IFACE_ACT_OR_2REF,
- IMG_IFACE_ACT_COMPONENT,
- IMG_IFACE_ACT_DILATE,
- IMG_IFACE_ACT_ERODE,
- IMG_IFACE_ACT_DILATE_ERODE,
- IMG_IFACE_ACT_ERODE_DILATE,
- IMG_IFACE_ACT_SMOOTH,
- IMG_IFACE_ACT_SOBEL,
- IMG_IFACE_ACT_BORDER,
- IMG_IFACE_ACT_MIRROR,
- IMG_IFACE_ACT_ROTATE_ORTO,
- IMG_IFACE_ACT_ROTATE,
- IMG_IFACE_ACT_ROTATE_2RECT,
- IMG_IFACE_ACT_ADAPTIVE_THRESHOLD,
- IMG_IFACE_ACT_CVT_COLOR,
- IMG_IFACE_ACT_DISTANCE_TRANSFORM,
- IMG_IFACE_ACT_THRESHOLD,
- IMG_IFACE_ACT_HISTOGRAM,
- IMG_IFACE_ACT_HISTOGRAM_C3,
- IMG_IFACE_ACT_CONTOURS,
- IMG_IFACE_ACT_CONTOURS_SIZE,
- IMG_IFACE_ACT_BOUNDING_RECT,
- IMG_IFACE_ACT_FIT_ELLIPSE,
- IMG_IFACE_ACT_MIN_AREA_RECT,
- IMG_IFACE_ACT_HOUGH_CIRCLES,
-
- IMG_IFACE_ACT_ORB = 0x000200u,
- IMG_IFACE_ACT_ALIGN,
-
- IMG_IFACE_ACT_CALIB3D = 0x000400u,
- IMG_IFACE_ACT_CALIBRATE,
- IMG_IFACE_ACT_UNDISTORT,
-
- IMG_IFACE_ACT_ZB = 0x000800u,
- IMG_IFACE_ACT_DECODE,
-
- IMG_IFACE_ACT_OCR = 0x001000u,
- IMG_IFACE_ACT_READ,
-
- IMG_IFACE_ACT_IMGI = 0x002000u,
- IMG_IFACE_ACT_APPLY,
- IMG_IFACE_ACT_DISCARD,
- IMG_IFACE_ACT_SAVE_MEM,
- IMG_IFACE_ACT_LOAD_MEM,
- IMG_IFACE_ACT_SAVE_REF,
-
- IMG_IFACE_ACT_SAVE = 0x004000u,
- IMG_IFACE_ACT_SAVE_FILE,
- IMG_IFACE_ACT_SAVE_UPDT
- };
-
- enum Img_Iface_Cmp_BGR {
- IMG_IFACE_CMP_BLUE = 0,
- IMG_IFACE_CMP_GREEN,
- IMG_IFACE_CMP_RED
- };
-
- enum Img_Iface_Cmp_HSV {
- IMG_IFACE_CMP_HUE = 0,
- IMG_IFACE_CMP_SATURATION,
- IMG_IFACE_CMP_VALUE
- };
-
- enum ImgI_Smooth {
- IMGI_SMOOTH_MEAN = 0,
- IMGI_SMOOTH_GAUSS,
- IMGI_SMOOTH_MEDIAN
- };
-
- enum Img_Iface_OCR_Lang {
- IMG_IFACE_OCR_LANG_ENG = 0,
- IMG_IFACE_OCR_LANG_SPA,
- IMG_IFACE_OCR_LANG_CAT,
- IMG_IFACE_OCR_LANG_DIGITS,
- IMG_IFACE_OCR_LANG_DIGITS_COMMA
- };
-
- enum Img_Iface_OCR_Conf {
- IMG_IFACE_OCR_CONF_NONE = 0,
- IMG_IFACE_OCR_CONF_PRICE
- };
-
-
-/******************************************************************************
- ******* structs **************************************************************
- ******************************************************************************/
- struct Img_Iface_Data_Read {
- int lang;
- int conf;
- struct {
- void *data;
- int width;
- int height;
- int B_per_pix;
- int B_per_line;
- } img;
- };
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
- extern char img_ocr_text [OCR_TEXT_MAX];
- extern struct Img_Iface_ZB_Codes zb_codes;
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- void img_iface_cleanup_main (void);
- void img_iface_load (const char *fpath, const char *fname);
- void img_iface_cleanup (void);
- void img_iface_act (int action, void *data);
- void img_iface_show_img (void);
- void img_iface_show_hist_c1 (void);
- void img_iface_show_hist_c3 (void);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* img_iface.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_IMG_IFACE_H + # define VA_IMG_IFACE_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + #include <stddef.h> + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +/* Constants -----------------------------------------------------------------*/ + # define CONTOURS_MAX (65536) + # define OCR_TEXT_MAX (1048576) + # define ZB_CODES_MAX (10) + # define ZBAR_LEN_MAX (1048576) + + # define IMG_IFACE_THR_OTSU (-1) + +/* Functions -----------------------------------------------------------------*/ + # define img_iface_act_nodata(x) \ + do { \ + img_iface_act(x, NULL); \ + } while (0) + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Img_Iface_Action { + IMG_IFACE_ACT_FOO = 0x000000u, + + IMG_IFACE_ACT_ALX = 0x000010u, + IMG_IFACE_ACT_LOCAL_MAX, + IMG_IFACE_ACT_SKELETON, + IMG_IFACE_ACT_LINES_HORIZONTAL, + IMG_IFACE_ACT_LINES_VERTICAL, + IMG_IFACE_ACT_MEAN_HORIZONTAL, + IMG_IFACE_ACT_MEAN_VERTICAL, + IMG_IFACE_ACT_MEDIAN_HORIZONTAL, + IMG_IFACE_ACT_MEDIAN_VERTICAL, + + IMG_IFACE_ACT_CV = 0x000100u, + IMG_IFACE_ACT_PIXEL_GET, + IMG_IFACE_ACT_PIXEL_SET, + IMG_IFACE_ACT_SET_ROI, + IMG_IFACE_ACT_SET_ROI_2RECT, + IMG_IFACE_ACT_AND_2REF, + IMG_IFACE_ACT_NOT, + IMG_IFACE_ACT_OR_2REF, + IMG_IFACE_ACT_COMPONENT, + IMG_IFACE_ACT_DILATE, + IMG_IFACE_ACT_ERODE, + IMG_IFACE_ACT_DILATE_ERODE, + IMG_IFACE_ACT_ERODE_DILATE, + IMG_IFACE_ACT_SMOOTH, + IMG_IFACE_ACT_SOBEL, + IMG_IFACE_ACT_BORDER, + IMG_IFACE_ACT_MIRROR, + IMG_IFACE_ACT_ROTATE_ORTO, + IMG_IFACE_ACT_ROTATE, + IMG_IFACE_ACT_ROTATE_2RECT, + IMG_IFACE_ACT_ADAPTIVE_THRESHOLD, + IMG_IFACE_ACT_CVT_COLOR, + IMG_IFACE_ACT_DISTANCE_TRANSFORM, + IMG_IFACE_ACT_THRESHOLD, + IMG_IFACE_ACT_HISTOGRAM, + IMG_IFACE_ACT_HISTOGRAM_C3, + IMG_IFACE_ACT_CONTOURS, + IMG_IFACE_ACT_CONTOURS_SIZE, + IMG_IFACE_ACT_BOUNDING_RECT, + IMG_IFACE_ACT_FIT_ELLIPSE, + IMG_IFACE_ACT_MIN_AREA_RECT, + IMG_IFACE_ACT_HOUGH_CIRCLES, + + IMG_IFACE_ACT_ORB = 0x000200u, + IMG_IFACE_ACT_ALIGN, + + IMG_IFACE_ACT_CALIB3D = 0x000400u, + IMG_IFACE_ACT_CALIBRATE, + IMG_IFACE_ACT_UNDISTORT, + + IMG_IFACE_ACT_ZB = 0x000800u, + IMG_IFACE_ACT_DECODE, + + IMG_IFACE_ACT_OCR = 0x001000u, + IMG_IFACE_ACT_READ, + + IMG_IFACE_ACT_IMGI = 0x002000u, + IMG_IFACE_ACT_APPLY, + IMG_IFACE_ACT_DISCARD, + IMG_IFACE_ACT_SAVE_MEM, + IMG_IFACE_ACT_LOAD_MEM, + IMG_IFACE_ACT_SAVE_REF, + + IMG_IFACE_ACT_SAVE = 0x004000u, + IMG_IFACE_ACT_SAVE_FILE, + IMG_IFACE_ACT_SAVE_UPDT + }; + + enum Img_Iface_Cmp_BGR { + IMG_IFACE_CMP_BLUE = 0, + IMG_IFACE_CMP_GREEN, + IMG_IFACE_CMP_RED + }; + + enum Img_Iface_Cmp_HSV { + IMG_IFACE_CMP_HUE = 0, + IMG_IFACE_CMP_SATURATION, + IMG_IFACE_CMP_VALUE + }; + + enum ImgI_Smooth { + IMGI_SMOOTH_MEAN = 0, + IMGI_SMOOTH_GAUSS, + IMGI_SMOOTH_MEDIAN + }; + + enum Img_Iface_OCR_Lang { + IMG_IFACE_OCR_LANG_ENG = 0, + IMG_IFACE_OCR_LANG_SPA, + IMG_IFACE_OCR_LANG_CAT, + IMG_IFACE_OCR_LANG_DIGITS, + IMG_IFACE_OCR_LANG_DIGITS_COMMA + }; + + enum Img_Iface_OCR_Conf { + IMG_IFACE_OCR_CONF_NONE = 0, + IMG_IFACE_OCR_CONF_PRICE + }; + + +/****************************************************************************** + ******* structs ************************************************************** + ******************************************************************************/ + struct Img_Iface_Data_Read { + int lang; + int conf; + struct { + void *data; + int width; + int height; + int B_per_pix; + int B_per_line; + } img; + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern char img_ocr_text [OCR_TEXT_MAX]; + extern struct Img_Iface_ZB_Codes zb_codes; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void img_iface_cleanup_main (void); + void img_iface_load (const char *fpath, const char *fname); + void img_iface_cleanup (void); + void img_iface_act (int action, void *data); + void img_iface_show_img (void); + void img_iface_show_hist_c1 (void); + void img_iface_show_hist_c3 (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* img_iface.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/inc/img_iface.hpp b/modules/image/inc/img_iface.hpp index c492537..6448578 100644 --- a/modules/image/inc/img_iface.hpp +++ b/modules/image/inc/img_iface.hpp @@ -1,343 +1,343 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_IMG_IFACE_HPP
- # define VA_IMG_IFACE_HPP
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- #include <cstddef>
-
-/* Standard C++ --------------------------------------------------------------*/
- /* class std::vector */
- #include <vector>
-
-/* Packages ------------------------------------------------------------------*/
- /* opencv */
- #include <opencv2/opencv.hpp>
- /* zbar */
- #include <zbar.h>
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
- # define CONTOURS_MAX (65536)
- # define OCR_TEXT_MAX (1048576)
- # define ZB_CODES_MAX (10)
- # define ZBAR_LEN_MAX (1048576)
-
- # define IMG_IFACE_THR_OTSU (-1)
-
-/* Functions -----------------------------------------------------------------*/
- # define img_iface_act_nodata(x) \
- do { \
- img_iface_act(x, NULL); \
- } while (0)
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Img_Iface_Action {
- IMG_IFACE_ACT_FOO = 0x000000u,
-
- IMG_IFACE_ACT_ALX = 0x000010u,
- IMG_IFACE_ACT_LOCAL_MAX,
- IMG_IFACE_ACT_SKELETON,
- IMG_IFACE_ACT_LINES_HORIZONTAL,
- IMG_IFACE_ACT_LINES_VERTICAL,
- IMG_IFACE_ACT_MEAN_HORIZONTAL,
- IMG_IFACE_ACT_MEAN_VERTICAL,
- IMG_IFACE_ACT_MEDIAN_HORIZONTAL,
- IMG_IFACE_ACT_MEDIAN_VERTICAL,
-
- IMG_IFACE_ACT_CV = 0x000100u,
- IMG_IFACE_ACT_PIXEL_GET,
- IMG_IFACE_ACT_PIXEL_SET,
- IMG_IFACE_ACT_SET_ROI,
- IMG_IFACE_ACT_SET_ROI_2RECT,
- IMG_IFACE_ACT_AND_2REF,
- IMG_IFACE_ACT_NOT,
- IMG_IFACE_ACT_OR_2REF,
- IMG_IFACE_ACT_COMPONENT,
- IMG_IFACE_ACT_DILATE,
- IMG_IFACE_ACT_ERODE,
- IMG_IFACE_ACT_DILATE_ERODE,
- IMG_IFACE_ACT_ERODE_DILATE,
- IMG_IFACE_ACT_SMOOTH,
- IMG_IFACE_ACT_SOBEL,
- IMG_IFACE_ACT_BORDER,
- IMG_IFACE_ACT_MIRROR,
- IMG_IFACE_ACT_ROTATE_ORTO,
- IMG_IFACE_ACT_ROTATE,
- IMG_IFACE_ACT_ROTATE_2RECT,
- IMG_IFACE_ACT_ADAPTIVE_THRESHOLD,
- IMG_IFACE_ACT_CVT_COLOR,
- IMG_IFACE_ACT_DISTANCE_TRANSFORM,
- IMG_IFACE_ACT_THRESHOLD,
- IMG_IFACE_ACT_HISTOGRAM,
- IMG_IFACE_ACT_HISTOGRAM_C3,
- IMG_IFACE_ACT_CONTOURS,
- IMG_IFACE_ACT_CONTOURS_SIZE,
- IMG_IFACE_ACT_BOUNDING_RECT,
- IMG_IFACE_ACT_FIT_ELLIPSE,
- IMG_IFACE_ACT_MIN_AREA_RECT,
- IMG_IFACE_ACT_HOUGH_CIRCLES,
-
- IMG_IFACE_ACT_ORB = 0x000200u,
- IMG_IFACE_ACT_ALIGN,
-
- IMG_IFACE_ACT_CALIB3D = 0x000400u,
- IMG_IFACE_ACT_CALIBRATE,
- IMG_IFACE_ACT_UNDISTORT,
-
- IMG_IFACE_ACT_ZB = 0x000800u,
- IMG_IFACE_ACT_DECODE,
-
- IMG_IFACE_ACT_OCR = 0x001000u,
- IMG_IFACE_ACT_READ,
-
- IMG_IFACE_ACT_IMGI = 0x002000u,
- IMG_IFACE_ACT_APPLY,
- IMG_IFACE_ACT_DISCARD,
- IMG_IFACE_ACT_SAVE_MEM,
- IMG_IFACE_ACT_LOAD_MEM,
- IMG_IFACE_ACT_SAVE_REF,
-
- IMG_IFACE_ACT_SAVE = 0x004000u,
- IMG_IFACE_ACT_SAVE_FILE,
- IMG_IFACE_ACT_SAVE_UPDT
- };
-
- enum Img_Iface_Cmp {
- IMG_IFACE_CMP_BLUE = 0,
- IMG_IFACE_CMP_GREEN,
- IMG_IFACE_CMP_RED
- };
-
- enum Img_Iface_Cmp_HSV {
- IMG_IFACE_CMP_HUE = 0,
- IMG_IFACE_CMP_SATURATION,
- IMG_IFACE_CMP_VALUE
- };
-
- enum ImgI_Smooth {
- IMGI_SMOOTH_MEAN = 1,
- IMGI_SMOOTH_GAUSS,
- IMGI_SMOOTH_MEDIAN
- };
-
- enum Img_Iface_OCR_Lang {
- IMG_IFACE_OCR_LANG_ENG = 0,
- IMG_IFACE_OCR_LANG_SPA,
- IMG_IFACE_OCR_LANG_CAT,
- IMG_IFACE_OCR_LANG_DIGITS,
- IMG_IFACE_OCR_LANG_DIGITS_COMMA
- };
-
- enum Img_Iface_OCR_Conf {
- IMG_IFACE_OCR_CONF_NONE = 0,
- IMG_IFACE_OCR_CONF_PRICE
- };
-
-
-/******************************************************************************
- ******* structs **************************************************************
- ******************************************************************************/
-/* img_cv --------------------------------------------------------------------*/
- struct Img_Iface_Data_Pixel_Get {
- unsigned char *val;
- int x;
- int y;
- };
-
- struct Img_Iface_Data_Pixel_Set {
- unsigned char val;
- int x;
- int y;
- };
-
- struct Img_Iface_Data_SetROI {
- class cv::Rect_ <int> rect;
- };
-
- struct Img_Iface_Data_Component {
- int cmp;
- };
-
- struct Img_Iface_Data_Dilate_Erode {
- int i;
- };
-
- struct Img_Iface_Data_Smooth {
- int method;
- int ksize;
- };
-
- struct Img_Iface_Data_Sobel {
- int dx;
- int dy;
- int ksize;
- };
-
- struct Img_Iface_Data_Border {
- int size;
- };
-
- struct Img_Iface_Data_Mirror {
- int axis;
- };
-
- struct Img_Iface_Data_Rotate_Orto {
- int n;
- };
-
- struct Img_Iface_Data_Rotate {
- class cv::Point_ <float> center;
- double angle;
- };
-
- struct Img_Iface_Data_Adaptive_Thr {
- int method;
- int thr_typ;
- int ksize;
- };
-
- struct Img_Iface_Data_Cvt_Color {
- int method;
- };
-
- struct Img_Iface_Data_Threshold {
- int thr_typ;
- int thr_val;
- };
-
- struct Img_Iface_Data_Histogram {
- class cv::Mat *hist_c0;
- class cv::Mat *hist_c1;
- class cv::Mat *hist_c2;
- class cv::Mat *hist_img;
- };
-
- struct Img_Iface_Data_Contours {
- class std::vector <class std::vector <class cv::Point_ <int>>> *contours;
- class cv::Mat *hierarchy;
- };
-
- struct Img_Iface_Data_Contours_Size {
- class std::vector <class std::vector <class cv::Point_ <int>>> *contours;
- double *area;
- double *perimeter;
- };
-
- struct Img_Iface_Data_Bounding_Rect {
- class std::vector <class cv::Point_ <int>> *contour;
- class cv::Rect_ <int> *rect;
- bool show;
- };
-
- struct Img_Iface_Data_MinARect {
- class std::vector <class cv::Point_ <int>> *contour;
- class cv::RotatedRect *rect;
- bool show;
- };
-
- struct Img_Iface_Data_Hough_Circles {
- class std::vector <class cv::Vec <float, 3>> *circles;
- double dist_min;
- double param_1;
- double param_2;
- int radius_min;
- int radius_max;
- };
-
-/* img_calib3d ---------------------------------------------------------------*/
- struct Img_Iface_Data_Calibrate {
- class cv::Mat *intrinsic_mat;
- class cv::Mat *dist_coefs;
- class std::vector <class cv::Mat> *rvecs;
- class std::vector <class cv::Mat> *tvecs;
- };
-
- struct Img_Iface_Data_Undistort {
- class cv::Mat *intrinsic_mat;
- class cv::Mat *dist_coefs;
- };
-
-/* img_zbar -------------------------------------------------------------------*/
- struct Img_Iface_Data_Decode {
- enum zbar::zbar_symbol_type_e code_type;
- };
-
- struct Img_Iface_ZB_Codes {
- int n;
- struct {
- enum zbar::zbar_symbol_type_e type;
- char sym_name [80];
- char data [ZBAR_LEN_MAX];
- } arr [ZB_CODES_MAX];
- };
-
-/* img_ocr -------------------------------------------------------------------*/
- struct Img_Iface_Data_Read {
- int lang;
- int conf;
- struct {
- void *data;
- int width;
- int height;
- int B_per_pix;
- int B_per_line;
- } img;
- };
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-extern "C" {
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
- extern char img_ocr_text [OCR_TEXT_MAX];
- extern struct Img_Iface_ZB_Codes zb_codes;
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- void img_iface_cleanup_main (void);
- void img_iface_load (const char *fpath, const char *fname);
- void img_iface_cleanup (void);
- void img_iface_act (int action, void *data);
- void img_iface_show_img (void);
- void img_iface_show_hist_c1 (void);
- void img_iface_show_hist_c3 (void);
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-} /* extern "C" */
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* img_iface.hpp */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_IMG_IFACE_HPP + # define VA_IMG_IFACE_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + #include <cstddef> + +/* Standard C++ --------------------------------------------------------------*/ + /* class std::vector */ + #include <vector> + +/* Packages ------------------------------------------------------------------*/ + /* opencv */ + #include <opencv2/opencv.hpp> + /* zbar */ + #include <zbar.h> + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define CONTOURS_MAX (65536) + # define OCR_TEXT_MAX (1048576) + # define ZB_CODES_MAX (10) + # define ZBAR_LEN_MAX (1048576) + + # define IMG_IFACE_THR_OTSU (-1) + +/* Functions -----------------------------------------------------------------*/ + # define img_iface_act_nodata(x) \ + do { \ + img_iface_act(x, NULL); \ + } while (0) + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Img_Iface_Action { + IMG_IFACE_ACT_FOO = 0x000000u, + + IMG_IFACE_ACT_ALX = 0x000010u, + IMG_IFACE_ACT_LOCAL_MAX, + IMG_IFACE_ACT_SKELETON, + IMG_IFACE_ACT_LINES_HORIZONTAL, + IMG_IFACE_ACT_LINES_VERTICAL, + IMG_IFACE_ACT_MEAN_HORIZONTAL, + IMG_IFACE_ACT_MEAN_VERTICAL, + IMG_IFACE_ACT_MEDIAN_HORIZONTAL, + IMG_IFACE_ACT_MEDIAN_VERTICAL, + + IMG_IFACE_ACT_CV = 0x000100u, + IMG_IFACE_ACT_PIXEL_GET, + IMG_IFACE_ACT_PIXEL_SET, + IMG_IFACE_ACT_SET_ROI, + IMG_IFACE_ACT_SET_ROI_2RECT, + IMG_IFACE_ACT_AND_2REF, + IMG_IFACE_ACT_NOT, + IMG_IFACE_ACT_OR_2REF, + IMG_IFACE_ACT_COMPONENT, + IMG_IFACE_ACT_DILATE, + IMG_IFACE_ACT_ERODE, + IMG_IFACE_ACT_DILATE_ERODE, + IMG_IFACE_ACT_ERODE_DILATE, + IMG_IFACE_ACT_SMOOTH, + IMG_IFACE_ACT_SOBEL, + IMG_IFACE_ACT_BORDER, + IMG_IFACE_ACT_MIRROR, + IMG_IFACE_ACT_ROTATE_ORTO, + IMG_IFACE_ACT_ROTATE, + IMG_IFACE_ACT_ROTATE_2RECT, + IMG_IFACE_ACT_ADAPTIVE_THRESHOLD, + IMG_IFACE_ACT_CVT_COLOR, + IMG_IFACE_ACT_DISTANCE_TRANSFORM, + IMG_IFACE_ACT_THRESHOLD, + IMG_IFACE_ACT_HISTOGRAM, + IMG_IFACE_ACT_HISTOGRAM_C3, + IMG_IFACE_ACT_CONTOURS, + IMG_IFACE_ACT_CONTOURS_SIZE, + IMG_IFACE_ACT_BOUNDING_RECT, + IMG_IFACE_ACT_FIT_ELLIPSE, + IMG_IFACE_ACT_MIN_AREA_RECT, + IMG_IFACE_ACT_HOUGH_CIRCLES, + + IMG_IFACE_ACT_ORB = 0x000200u, + IMG_IFACE_ACT_ALIGN, + + IMG_IFACE_ACT_CALIB3D = 0x000400u, + IMG_IFACE_ACT_CALIBRATE, + IMG_IFACE_ACT_UNDISTORT, + + IMG_IFACE_ACT_ZB = 0x000800u, + IMG_IFACE_ACT_DECODE, + + IMG_IFACE_ACT_OCR = 0x001000u, + IMG_IFACE_ACT_READ, + + IMG_IFACE_ACT_IMGI = 0x002000u, + IMG_IFACE_ACT_APPLY, + IMG_IFACE_ACT_DISCARD, + IMG_IFACE_ACT_SAVE_MEM, + IMG_IFACE_ACT_LOAD_MEM, + IMG_IFACE_ACT_SAVE_REF, + + IMG_IFACE_ACT_SAVE = 0x004000u, + IMG_IFACE_ACT_SAVE_FILE, + IMG_IFACE_ACT_SAVE_UPDT + }; + + enum Img_Iface_Cmp { + IMG_IFACE_CMP_BLUE = 0, + IMG_IFACE_CMP_GREEN, + IMG_IFACE_CMP_RED + }; + + enum Img_Iface_Cmp_HSV { + IMG_IFACE_CMP_HUE = 0, + IMG_IFACE_CMP_SATURATION, + IMG_IFACE_CMP_VALUE + }; + + enum ImgI_Smooth { + IMGI_SMOOTH_MEAN = 1, + IMGI_SMOOTH_GAUSS, + IMGI_SMOOTH_MEDIAN + }; + + enum Img_Iface_OCR_Lang { + IMG_IFACE_OCR_LANG_ENG = 0, + IMG_IFACE_OCR_LANG_SPA, + IMG_IFACE_OCR_LANG_CAT, + IMG_IFACE_OCR_LANG_DIGITS, + IMG_IFACE_OCR_LANG_DIGITS_COMMA + }; + + enum Img_Iface_OCR_Conf { + IMG_IFACE_OCR_CONF_NONE = 0, + IMG_IFACE_OCR_CONF_PRICE + }; + + +/****************************************************************************** + ******* structs ************************************************************** + ******************************************************************************/ +/* img_cv --------------------------------------------------------------------*/ + struct Img_Iface_Data_Pixel_Get { + unsigned char *val; + int x; + int y; + }; + + struct Img_Iface_Data_Pixel_Set { + unsigned char val; + int x; + int y; + }; + + struct Img_Iface_Data_SetROI { + class cv::Rect_ <int> rect; + }; + + struct Img_Iface_Data_Component { + int cmp; + }; + + struct Img_Iface_Data_Dilate_Erode { + int i; + }; + + struct Img_Iface_Data_Smooth { + int method; + int ksize; + }; + + struct Img_Iface_Data_Sobel { + int dx; + int dy; + int ksize; + }; + + struct Img_Iface_Data_Border { + int size; + }; + + struct Img_Iface_Data_Mirror { + int axis; + }; + + struct Img_Iface_Data_Rotate_Orto { + int n; + }; + + struct Img_Iface_Data_Rotate { + class cv::Point_ <float> center; + double angle; + }; + + struct Img_Iface_Data_Adaptive_Thr { + int method; + int thr_typ; + int ksize; + }; + + struct Img_Iface_Data_Cvt_Color { + int method; + }; + + struct Img_Iface_Data_Threshold { + int thr_typ; + int thr_val; + }; + + struct Img_Iface_Data_Histogram { + class cv::Mat *hist_c0; + class cv::Mat *hist_c1; + class cv::Mat *hist_c2; + class cv::Mat *hist_img; + }; + + struct Img_Iface_Data_Contours { + class std::vector <class std::vector <class cv::Point_ <int>>> *contours; + class cv::Mat *hierarchy; + }; + + struct Img_Iface_Data_Contours_Size { + class std::vector <class std::vector <class cv::Point_ <int>>> *contours; + double *area; + double *perimeter; + }; + + struct Img_Iface_Data_Bounding_Rect { + class std::vector <class cv::Point_ <int>> *contour; + class cv::Rect_ <int> *rect; + bool show; + }; + + struct Img_Iface_Data_MinARect { + class std::vector <class cv::Point_ <int>> *contour; + class cv::RotatedRect *rect; + bool show; + }; + + struct Img_Iface_Data_Hough_Circles { + class std::vector <class cv::Vec <float, 3>> *circles; + double dist_min; + double param_1; + double param_2; + int radius_min; + int radius_max; + }; + +/* img_calib3d ---------------------------------------------------------------*/ + struct Img_Iface_Data_Calibrate { + class cv::Mat *intrinsic_mat; + class cv::Mat *dist_coefs; + class std::vector <class cv::Mat> *rvecs; + class std::vector <class cv::Mat> *tvecs; + }; + + struct Img_Iface_Data_Undistort { + class cv::Mat *intrinsic_mat; + class cv::Mat *dist_coefs; + }; + +/* img_zbar -------------------------------------------------------------------*/ + struct Img_Iface_Data_Decode { + enum zbar::zbar_symbol_type_e code_type; + }; + + struct Img_Iface_ZB_Codes { + int n; + struct { + enum zbar::zbar_symbol_type_e type; + char sym_name [80]; + char data [ZBAR_LEN_MAX]; + } arr [ZB_CODES_MAX]; + }; + +/* img_ocr -------------------------------------------------------------------*/ + struct Img_Iface_Data_Read { + int lang; + int conf; + struct { + void *data; + int width; + int height; + int B_per_pix; + int B_per_line; + } img; + }; + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern char img_ocr_text [OCR_TEXT_MAX]; + extern struct Img_Iface_ZB_Codes zb_codes; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void img_iface_cleanup_main (void); + void img_iface_load (const char *fpath, const char *fname); + void img_iface_cleanup (void); + void img_iface_act (int action, void *data); + void img_iface_show_img (void); + void img_iface_show_hist_c1 (void); + void img_iface_show_hist_c3 (void); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* img_iface.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/inc/img_ocr.h b/modules/image/inc/img_ocr.h index f2e8742..62d248a 100644 --- a/modules/image/inc/img_ocr.h +++ b/modules/image/inc/img_ocr.h @@ -1,38 +1,38 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_IMG_OCR_H
- # define VA_IMG_OCR_H
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Img_OCR_Action {
- IMG_OCR_ACT_FOO = 0x000000u,
-
- IMG_OCR_ACT_OCR = 0x001000u,
- IMG_OCR_ACT_READ
- };
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
-void img_ocr_act (int action, void *data);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* img_ocr.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_IMG_OCR_H + # define VA_IMG_OCR_H + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Img_OCR_Action { + IMG_OCR_ACT_FOO = 0x000000u, + + IMG_OCR_ACT_OCR = 0x001000u, + IMG_OCR_ACT_READ + }; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void img_ocr_act (int action, void *data); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* img_ocr.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/inc/img_ocr.hpp b/modules/image/inc/img_ocr.hpp index 446f986..355a124 100644 --- a/modules/image/inc/img_ocr.hpp +++ b/modules/image/inc/img_ocr.hpp @@ -1,50 +1,50 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_IMG_OCR_HPP
- # define VA_IMG_OCR_HPP
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Img_OCR_Action {
- IMG_OCR_ACT_FOO = 0x000000u,
-
- IMG_OCR_ACT_OCR = 0x001000u,
- IMG_OCR_ACT_READ
- };
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-extern "C" {
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- void img_ocr_act (int action, void *data);
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-} /* extern "C" */
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* img_ocr.hpp */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_IMG_OCR_HPP + # define VA_IMG_OCR_HPP + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Img_OCR_Action { + IMG_OCR_ACT_FOO = 0x000000u, + + IMG_OCR_ACT_OCR = 0x001000u, + IMG_OCR_ACT_READ + }; + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void img_ocr_act (int action, void *data); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* img_ocr.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/inc/img_orb.hpp b/modules/image/inc/img_orb.hpp index b29fefa..ce5a914 100644 --- a/modules/image/inc/img_orb.hpp +++ b/modules/image/inc/img_orb.hpp @@ -1,46 +1,46 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_IMG_ORB_HPP
- # define VA_IMG_ORB_HPP
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
- /* openCV */
- #include <opencv2/opencv.hpp>
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Img_ORB_Action {
- IMG_ORB_ACT_FOO = 0x000000u,
-
- IMG_ORB_ACT_ORB = 0x000200u,
- IMG_ORB_ACT_ALIGN
- };
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- void img_orb_act (class cv::Mat *pattern,
- class cv::Mat *imgptr, int action);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* img_orb.hpp */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_IMG_ORB_HPP + # define VA_IMG_ORB_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + /* openCV */ + #include <opencv2/opencv.hpp> + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Img_ORB_Action { + IMG_ORB_ACT_FOO = 0x000000u, + + IMG_ORB_ACT_ORB = 0x000200u, + IMG_ORB_ACT_ALIGN + }; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void img_orb_act (class cv::Mat *pattern, + class cv::Mat *imgptr, int action); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* img_orb.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/inc/img_zbar.hpp b/modules/image/inc/img_zbar.hpp index 2019ae3..72f1020 100644 --- a/modules/image/inc/img_zbar.hpp +++ b/modules/image/inc/img_zbar.hpp @@ -1,46 +1,46 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_IMG_ZBAR_H
- # define VA_IMG_ZBAR_H
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Packages ------------------------------------------------------------------*/
- /* openCV */
- #include <opencv2/opencv.hpp>
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Img_ZB_Action {
- IMG_ZB_ACT_FOO = 0x000000u,
-
- IMG_ZB_ACT_ZB = 0x000800u,
- IMG_ZB_ACT_DECODE
- };
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
-void img_zb_act (class cv::Mat *imgptr, int action, void *data);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* img_zbar.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_IMG_ZBAR_H + # define VA_IMG_ZBAR_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Packages ------------------------------------------------------------------*/ + /* openCV */ + #include <opencv2/opencv.hpp> + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Img_ZB_Action { + IMG_ZB_ACT_FOO = 0x000000u, + + IMG_ZB_ACT_ZB = 0x000800u, + IMG_ZB_ACT_DECODE + }; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void img_zb_act (class cv::Mat *imgptr, int action, void *data); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* img_zbar.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/src/img_alx.cpp b/modules/image/src/img_alx.cpp index 093ff69..8a65084 100644 --- a/modules/image/src/img_alx.cpp +++ b/modules/image/src/img_alx.cpp @@ -1,380 +1,380 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- * SPDX-License-Identifier: (GPL-2.0-only OR LGPL-3.0-only) *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* true & false */
- #include <cstdbool>
- /* abs() */
- #include <cstdlib>
- /* snprintf() */
- #include <cstdio>
-
-/* Packages ------------------------------------------------------------------*/
- /* opencv */
- #include <opencv2/opencv.hpp>
-
-/* libalx --------------------------------------------------------------------*/
- /* alx_median_u8() */
- #include "alx_math.hpp"
-
-/* Module --------------------------------------------------------------------*/
- /* data */
- #include "img_iface.hpp"
-
- #include "img_alx.hpp"
-
-
-/******************************************************************************
- ******* static functions (prototypes) ****************************************
- ******************************************************************************/
-static void img_alx_local_max (class cv::Mat *imgptr);
-static void img_alx_skeleton (class cv::Mat *imgptr);
-static void img_alx_lines_horizontal (class cv::Mat *imgptr);
-static void img_alx_lines_vertical (class cv::Mat *imgptr);
-static void img_alx_mean_horizontal (class cv::Mat *imgptr);
-static void img_alx_mean_vertical (class cv::Mat *imgptr);
-static void img_alx_median_horizontal (class cv::Mat *imgptr);
-static void img_alx_median_vertical (class cv::Mat *imgptr);
-
-
-/******************************************************************************
- ******* global functions *****************************************************
- ******************************************************************************/
-void img_alx_act (class cv::Mat *imgptr, int action, void *data)
-{
-
- switch (action) {
- case IMG_ALX_ACT_LOCAL_MAX:
- img_alx_local_max(imgptr);
- break;
- case IMG_ALX_ACT_SKELETON:
- img_alx_skeleton(imgptr);
- break;
-
- case IMG_ALX_ACT_LINES_HORIZONTAL:
- img_alx_lines_horizontal(imgptr);
- break;
- case IMG_ALX_ACT_LINES_VERTICAL:
- img_alx_lines_vertical(imgptr);
- break;
-
- case IMG_ALX_ACT_MEAN_HORIZONTAL:
- img_alx_mean_horizontal(imgptr);
- break;
- case IMG_ALX_ACT_MEAN_VERTICAL:
- img_alx_mean_vertical(imgptr);
- break;
- case IMG_ALX_ACT_MEDIAN_HORIZONTAL:
- img_alx_median_horizontal(imgptr);
- break;
- case IMG_ALX_ACT_MEDIAN_VERTICAL:
- img_alx_median_vertical(imgptr);
- break;
- }
-}
-
-
-/******************************************************************************
- ******* static functions (definitions) ***************************************
- ******************************************************************************/
-static void img_alx_local_max (class cv::Mat *imgptr)
-{
- int i;
- int j;
- int k;
- int l;
- /* Minimum distance between local maxima */
- const int dist_min = 16;
- /* Minimum value of local maxima */
- const int val_min = 16;
- class cv::Mat imgtmp;
-
- /* pointer to a pixel (in imgptr) */
- uint8_t *img_pix;
- /* pointer to a pixel near img_pix (in imgptr) */
- uint8_t *near_pix;
- /* pointer to a pixel (same position as img_pix, but in imgtmp) */
- uint8_t *tmp_pix;
-
- /* Tmp image copy */
- imgptr->copyTo(imgtmp);
-
- for (i = 0; i < imgptr->rows; i++) {
- for (j = 0; j < imgptr->cols; j++) {
- img_pix = imgptr->data + i * imgptr->step + j;
- tmp_pix = imgtmp.data + i * imgptr->step + j;
- *tmp_pix = 0;
-
- if (*img_pix < val_min) {
- goto next_pixel;
- }
-
- for (k = (i - dist_min); k < (i + dist_min + 1); k++) {
- for (l = (j - dist_min); l < (j + dist_min + 1); l++) {
- near_pix = imgptr->data + k * imgptr->step + l;
- if ((k >= 0) && (k < imgptr->rows)) {
- if ((l >= 0) && (l < imgptr->cols)) {
- if (*img_pix < *near_pix) {
- goto next_pixel;
- }
- }
- }
- }
- }
-
- *tmp_pix = *img_pix;
- continue;
-
-next_pixel:
- *tmp_pix = 0;
- }
- }
-
- /* Cleanup */
- imgtmp.copyTo(*imgptr);
- imgtmp.release();
-}
-
-static void img_alx_skeleton (class cv::Mat *imgptr)
-{
- /* (Half of the) width of the skeleton */
- const int width = 5;
- int dist_x;
- int dist_y;
- bool skeleton;
- int cnt_lo [width];
- int cnt_hi_or_eq [width];
- class cv::Mat imgtmp;
- /* pointer to a pixel (in imgptr) */
- uint8_t *img_pix;
- /* pointer to a pixel near img_pix (in imgptr) */
- uint8_t *near_pix;
- /* pointer to a pixel (same position as img_pix, but in imgtmp) */
- uint8_t *tmp_pix;
-
- int i;
- int j;
- int k;
- int l;
- int r;
-
- /* Tmp image copy */
- imgptr->copyTo(imgtmp);
-
- for (i = 0; i < imgptr->rows; i++) {
- for (j = 0; j < imgptr->cols; j++) {
- img_pix = imgptr->data + i * imgptr->step + j;
- tmp_pix = imgtmp.data + i * imgptr->step + j;
-
- if (!(*img_pix)) {
- *tmp_pix = 0;
- continue;
- }
-
- for (r = 0; r < width; r++) {
- cnt_lo[r] = 0;
- cnt_hi_or_eq[r] = 0;
- }
-
- for (k = i - width; k <= i + width; k++) {
- for (l = j - width; l <= j + width; l++) {
- near_pix = imgptr->data + k * imgptr->step + l;
-
- dist_x = abs(k - i);
- dist_y = abs(l - j);
-
- if ((k >= 0) && (k < imgptr->rows)) {
- if ((l >= 0) && (l < imgptr->cols)) {
- if (dist_x || dist_y) {
- if (*near_pix < *img_pix) {
- cnt_lo[std::max(dist_x, dist_y)]++;
- } else {
- cnt_hi_or_eq[std::max(dist_x, dist_y)]++;
- }
- }
- }
- }
-
- }
- }
-
- skeleton = false;
- for (r = 0; r < width; r++) {
- if (cnt_lo[r] > (cnt_hi_or_eq[r] + (1.6) * (r + 1))) {
- skeleton = true;
- }
- }
-
- if (skeleton) {
- *tmp_pix = *img_pix;
- } else {
- *tmp_pix = 0;
- }
- }
- }
-
- /* Cleanup */
- imgtmp.copyTo(*imgptr);
- imgtmp.release();
-}
-
-static void img_alx_lines_horizontal (class cv::Mat *imgptr)
-{
- int i;
- int j;
- bool white;
- /* pointer to a pixel (in imgptr) */
- uint8_t *img_pix;
-
- for (i = 0; i < imgptr->rows; i++) {
- white = false;
-
- for (j = 0; j < imgptr->cols; j++) {
- img_pix = imgptr->data + i * imgptr->step + j;
- if (*img_pix) {
- white = true;
- break;
- }
- }
-
- if (white) {
- for (j = 0; j < imgptr->cols; j++) {
- img_pix = imgptr->data + i * imgptr->step + j;
- *img_pix = 255;
- }
- }
- }
-}
-
-static void img_alx_lines_vertical (class cv::Mat *imgptr)
-{
- int i;
- int j;
- bool white;
- /* pointer to a pixel (in imgptr) */
- uint8_t *img_pix;
-
- for (i = 0; i < imgptr->cols; i++) {
- white = false;
-
- for (j = 0; j < imgptr->rows; j++) {
- img_pix = imgptr->data + j * imgptr->step + i;
- if (*img_pix) {
- white = true;
- break;
- }
- }
-
- if (white) {
- for (j = 0; j < imgptr->rows; j++) {
- img_pix = imgptr->data + j * imgptr->step + i;
- *img_pix = 255;
- }
- }
- }
-}
-
-static void img_alx_mean_horizontal (class cv::Mat *imgptr)
-{
- int i;
- int j;
- uint32_t tmp;
- uint8_t mean;
- /* pointer to a pixel (in imgptr) */
- uint8_t *img_pix;
-
- for (i = 0; i < imgptr->rows; i++) {
- tmp = 0;
- for (j = 0; j < imgptr->cols; j++) {
- img_pix = imgptr->data + i * imgptr->step + j;
- tmp += *img_pix;
- }
- mean = tmp / imgptr->cols;
-
- for (j = 0; j < imgptr->cols; j++) {
- img_pix = imgptr->data + i * imgptr->step + j;
- *img_pix = mean;
- }
- }
-}
-
-static void img_alx_mean_vertical (class cv::Mat *imgptr)
-{
- int i;
- int j;
- uint32_t tmp;
- uint8_t mean;
- /* pointer to a pixel (in imgptr) */
- uint8_t *img_pix;
-
- for (i = 0; i < imgptr->cols; i++) {
- tmp = 0;
- for (j = 0; j < imgptr->rows; j++) {
- img_pix = imgptr->data + j * imgptr->step + i;
- tmp += *img_pix;
- }
- mean = tmp / imgptr->rows;
-
- for (j = 0; j < imgptr->rows; j++) {
- img_pix = imgptr->data + j * imgptr->step + i;
- *img_pix = mean;
- }
- }
-}
-
-static void img_alx_median_horizontal (class cv::Mat *imgptr)
-{
- int i;
- int j;
- uint8_t row [imgptr->cols];
- uint8_t median;
- /* pointer to a pixel (in imgptr) */
- uint8_t *img_pix;
-
- for (i = 0; i < imgptr->rows; i++) {
- for (j = 0; j < imgptr->cols; j++) {
- img_pix = imgptr->data + i * imgptr->step + j;
- row[j] = *img_pix;
- }
- median = alx_median_u8(imgptr->cols, row);
-
- for (j = 0; j < imgptr->cols; j++) {
- img_pix = imgptr->data + i * imgptr->step + j;
- *img_pix = median;
- }
- }
-}
-
-static void img_alx_median_vertical (class cv::Mat *imgptr)
-{
- int i;
- int j;
- uint8_t col [imgptr->rows];
- uint8_t median;
- /* pointer to a pixel (in imgptr) */
- uint8_t *img_pix;
-
- for (i = 0; i < imgptr->cols; i++) {
- for (j = 0; j < imgptr->rows; j++) {
- img_pix = imgptr->data + j * imgptr->step + i;
- col[j] = *img_pix;
- }
- median = alx_median_u8(imgptr->rows, col);
-
- for (j = 0; j < imgptr->rows; j++) {
- img_pix = imgptr->data + j * imgptr->step + i;
- *img_pix = median;
- }
- }
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: (GPL-2.0-only OR LGPL-3.0-only) * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* true & false */ + #include <cstdbool> + /* abs() */ + #include <cstdlib> + /* snprintf() */ + #include <cstdio> + +/* Packages ------------------------------------------------------------------*/ + /* opencv */ + #include <opencv2/opencv.hpp> + +/* libalx --------------------------------------------------------------------*/ + /* alx_median_u8() */ + #include "alx_math.hpp" + +/* Module --------------------------------------------------------------------*/ + /* data */ + #include "img_iface.hpp" + + #include "img_alx.hpp" + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ +static void img_alx_local_max (class cv::Mat *imgptr); +static void img_alx_skeleton (class cv::Mat *imgptr); +static void img_alx_lines_horizontal (class cv::Mat *imgptr); +static void img_alx_lines_vertical (class cv::Mat *imgptr); +static void img_alx_mean_horizontal (class cv::Mat *imgptr); +static void img_alx_mean_vertical (class cv::Mat *imgptr); +static void img_alx_median_horizontal (class cv::Mat *imgptr); +static void img_alx_median_vertical (class cv::Mat *imgptr); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void img_alx_act (class cv::Mat *imgptr, int action, void *data) +{ + + switch (action) { + case IMG_ALX_ACT_LOCAL_MAX: + img_alx_local_max(imgptr); + break; + case IMG_ALX_ACT_SKELETON: + img_alx_skeleton(imgptr); + break; + + case IMG_ALX_ACT_LINES_HORIZONTAL: + img_alx_lines_horizontal(imgptr); + break; + case IMG_ALX_ACT_LINES_VERTICAL: + img_alx_lines_vertical(imgptr); + break; + + case IMG_ALX_ACT_MEAN_HORIZONTAL: + img_alx_mean_horizontal(imgptr); + break; + case IMG_ALX_ACT_MEAN_VERTICAL: + img_alx_mean_vertical(imgptr); + break; + case IMG_ALX_ACT_MEDIAN_HORIZONTAL: + img_alx_median_horizontal(imgptr); + break; + case IMG_ALX_ACT_MEDIAN_VERTICAL: + img_alx_median_vertical(imgptr); + break; + } +} + + +/****************************************************************************** + ******* static functions (definitions) *************************************** + ******************************************************************************/ +static void img_alx_local_max (class cv::Mat *imgptr) +{ + int i; + int j; + int k; + int l; + /* Minimum distance between local maxima */ + const int dist_min = 16; + /* Minimum value of local maxima */ + const int val_min = 16; + class cv::Mat imgtmp; + + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + /* pointer to a pixel near img_pix (in imgptr) */ + uint8_t *near_pix; + /* pointer to a pixel (same position as img_pix, but in imgtmp) */ + uint8_t *tmp_pix; + + /* Tmp image copy */ + imgptr->copyTo(imgtmp); + + for (i = 0; i < imgptr->rows; i++) { + for (j = 0; j < imgptr->cols; j++) { + img_pix = imgptr->data + i * imgptr->step + j; + tmp_pix = imgtmp.data + i * imgptr->step + j; + *tmp_pix = 0; + + if (*img_pix < val_min) { + goto next_pixel; + } + + for (k = (i - dist_min); k < (i + dist_min + 1); k++) { + for (l = (j - dist_min); l < (j + dist_min + 1); l++) { + near_pix = imgptr->data + k * imgptr->step + l; + if ((k >= 0) && (k < imgptr->rows)) { + if ((l >= 0) && (l < imgptr->cols)) { + if (*img_pix < *near_pix) { + goto next_pixel; + } + } + } + } + } + + *tmp_pix = *img_pix; + continue; + +next_pixel: + *tmp_pix = 0; + } + } + + /* Cleanup */ + imgtmp.copyTo(*imgptr); + imgtmp.release(); +} + +static void img_alx_skeleton (class cv::Mat *imgptr) +{ + /* (Half of the) width of the skeleton */ + const int width = 5; + int dist_x; + int dist_y; + bool skeleton; + int cnt_lo [width]; + int cnt_hi_or_eq [width]; + class cv::Mat imgtmp; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + /* pointer to a pixel near img_pix (in imgptr) */ + uint8_t *near_pix; + /* pointer to a pixel (same position as img_pix, but in imgtmp) */ + uint8_t *tmp_pix; + + int i; + int j; + int k; + int l; + int r; + + /* Tmp image copy */ + imgptr->copyTo(imgtmp); + + for (i = 0; i < imgptr->rows; i++) { + for (j = 0; j < imgptr->cols; j++) { + img_pix = imgptr->data + i * imgptr->step + j; + tmp_pix = imgtmp.data + i * imgptr->step + j; + + if (!(*img_pix)) { + *tmp_pix = 0; + continue; + } + + for (r = 0; r < width; r++) { + cnt_lo[r] = 0; + cnt_hi_or_eq[r] = 0; + } + + for (k = i - width; k <= i + width; k++) { + for (l = j - width; l <= j + width; l++) { + near_pix = imgptr->data + k * imgptr->step + l; + + dist_x = abs(k - i); + dist_y = abs(l - j); + + if ((k >= 0) && (k < imgptr->rows)) { + if ((l >= 0) && (l < imgptr->cols)) { + if (dist_x || dist_y) { + if (*near_pix < *img_pix) { + cnt_lo[std::max(dist_x, dist_y)]++; + } else { + cnt_hi_or_eq[std::max(dist_x, dist_y)]++; + } + } + } + } + + } + } + + skeleton = false; + for (r = 0; r < width; r++) { + if (cnt_lo[r] > (cnt_hi_or_eq[r] + (1.6) * (r + 1))) { + skeleton = true; + } + } + + if (skeleton) { + *tmp_pix = *img_pix; + } else { + *tmp_pix = 0; + } + } + } + + /* Cleanup */ + imgtmp.copyTo(*imgptr); + imgtmp.release(); +} + +static void img_alx_lines_horizontal (class cv::Mat *imgptr) +{ + int i; + int j; + bool white; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + + for (i = 0; i < imgptr->rows; i++) { + white = false; + + for (j = 0; j < imgptr->cols; j++) { + img_pix = imgptr->data + i * imgptr->step + j; + if (*img_pix) { + white = true; + break; + } + } + + if (white) { + for (j = 0; j < imgptr->cols; j++) { + img_pix = imgptr->data + i * imgptr->step + j; + *img_pix = 255; + } + } + } +} + +static void img_alx_lines_vertical (class cv::Mat *imgptr) +{ + int i; + int j; + bool white; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + + for (i = 0; i < imgptr->cols; i++) { + white = false; + + for (j = 0; j < imgptr->rows; j++) { + img_pix = imgptr->data + j * imgptr->step + i; + if (*img_pix) { + white = true; + break; + } + } + + if (white) { + for (j = 0; j < imgptr->rows; j++) { + img_pix = imgptr->data + j * imgptr->step + i; + *img_pix = 255; + } + } + } +} + +static void img_alx_mean_horizontal (class cv::Mat *imgptr) +{ + int i; + int j; + uint32_t tmp; + uint8_t mean; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + + for (i = 0; i < imgptr->rows; i++) { + tmp = 0; + for (j = 0; j < imgptr->cols; j++) { + img_pix = imgptr->data + i * imgptr->step + j; + tmp += *img_pix; + } + mean = tmp / imgptr->cols; + + for (j = 0; j < imgptr->cols; j++) { + img_pix = imgptr->data + i * imgptr->step + j; + *img_pix = mean; + } + } +} + +static void img_alx_mean_vertical (class cv::Mat *imgptr) +{ + int i; + int j; + uint32_t tmp; + uint8_t mean; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + + for (i = 0; i < imgptr->cols; i++) { + tmp = 0; + for (j = 0; j < imgptr->rows; j++) { + img_pix = imgptr->data + j * imgptr->step + i; + tmp += *img_pix; + } + mean = tmp / imgptr->rows; + + for (j = 0; j < imgptr->rows; j++) { + img_pix = imgptr->data + j * imgptr->step + i; + *img_pix = mean; + } + } +} + +static void img_alx_median_horizontal (class cv::Mat *imgptr) +{ + int i; + int j; + uint8_t row [imgptr->cols]; + uint8_t median; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + + for (i = 0; i < imgptr->rows; i++) { + for (j = 0; j < imgptr->cols; j++) { + img_pix = imgptr->data + i * imgptr->step + j; + row[j] = *img_pix; + } + median = alx_median_u8(imgptr->cols, row); + + for (j = 0; j < imgptr->cols; j++) { + img_pix = imgptr->data + i * imgptr->step + j; + *img_pix = median; + } + } +} + +static void img_alx_median_vertical (class cv::Mat *imgptr) +{ + int i; + int j; + uint8_t col [imgptr->rows]; + uint8_t median; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + + for (i = 0; i < imgptr->cols; i++) { + for (j = 0; j < imgptr->rows; j++) { + img_pix = imgptr->data + j * imgptr->step + i; + col[j] = *img_pix; + } + median = alx_median_u8(imgptr->rows, col); + + for (j = 0; j < imgptr->rows; j++) { + img_pix = imgptr->data + j * imgptr->step + i; + *img_pix = median; + } + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/src/img_calib3d.cpp b/modules/image/src/img_calib3d.cpp index da6bb95..63a64f4 100644 --- a/modules/image/src/img_calib3d.cpp +++ b/modules/image/src/img_calib3d.cpp @@ -1,142 +1,142 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C++ --------------------------------------------------------------*/
- /* class std::vector */
- #include <vector>
-
-/* Standard C ----------------------------------------------------------------*/
- /* snprintf() */
- #include <cstdio>
-
-/* Packages ------------------------------------------------------------------*/
- /* opencv */
- #include <opencv2/opencv.hpp>
- #include <opencv2/calib3d/calib3d.hpp>
-
-/* Module -------------------------------------------------------------------*/
- /* data */
- #include "img_iface.hpp"
-
- #include "img_calib3d.hpp"
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
- # define CORNERS_HOR (16)
- # define CORNERS_VER (13)
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void img_calib3d_calibrate (class cv::Mat *imgptr, void *data);
-static void img_calib3d_undistort (class cv::Mat *imgptr, void *data);
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void img_calib3d_act (class cv::Mat *imgptr, int action, void *data)
-{
- switch (action) {
- case IMG_CALIB3D_ACT_CALIBRATE:
- img_calib3d_calibrate(imgptr, data);
- break;
-
- case IMG_CALIB3D_ACT_UNDISTORT:
- img_calib3d_undistort(imgptr, data);
- break;
- }
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void img_calib3d_calibrate (class cv::Mat *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_Calibrate *data_cast;
-
- class cv::Mat *intrinsic_mat;
- class cv::Mat *dist_coefs;
- class std::vector <class cv::Mat> *rvecs;
- class std::vector <class cv::Mat> *tvecs;
-
- class cv::Size_ <int> pattern_size;
- class std::vector <class std::vector <class cv::Point3_ <float>>> object_points;
- class std::vector <class std::vector <class cv::Point_ <float>>> image_points;
- class std::vector <class cv::Point_ <float>> corners;
- class std::vector <class cv::Point3_ <float>> obj;
-
- bool found;
- int i;
- int j;
-
- data_cast = (struct Img_Iface_Data_Calibrate *)data;
- intrinsic_mat = data_cast->intrinsic_mat;
- dist_coefs = data_cast->dist_coefs;
- rvecs = data_cast->rvecs;
- tvecs = data_cast->tvecs;
-
- pattern_size = cv::Size(CORNERS_HOR, CORNERS_VER);
- *intrinsic_mat = cv::Mat(3, 3, CV_32FC1);
- (*intrinsic_mat).ptr<float>(0)[0] = 1;
- (*intrinsic_mat).ptr<float>(1)[1] = 1;
-
- for (i = 0; i < CORNERS_HOR; i++) {
- for (j = 0; j < CORNERS_VER; j++) {
- obj.push_back(cv::Point3f(i, j * 10.0, 0.0));
- }
- }
-
- found = cv::findChessboardCorners(*imgptr, pattern_size, corners,
- CV_CALIB_CB_ADAPTIVE_THRESH |
- CV_CALIB_CB_FILTER_QUADS);
-
- cv::cornerSubPix(*imgptr, corners, cv::Size(11, 11),
- cv::Size(-1, -1),
- cv::TermCriteria(CV_TERMCRIT_EPS |
- CV_TERMCRIT_ITER, 30, 0.1));
- cv::drawChessboardCorners(*imgptr, pattern_size, corners, found);
-
- image_points.push_back(corners);
- object_points.push_back(obj);
-
- /* Calibrate */
- cv::calibrateCamera(object_points, image_points, imgptr->size(),
- *intrinsic_mat, *dist_coefs, *rvecs, *tvecs);
-}
-
-static void img_calib3d_undistort (class cv::Mat *imgptr, void *data)
-{
- class cv::Mat imgtmp;
-
- /* Data */
- struct Img_Iface_Data_Undistort *data_cast;
-
- class cv::Mat *intrinsic_mat;
- class cv::Mat *dist_coefs;
-
- data_cast = (struct Img_Iface_Data_Undistort *)data;
- intrinsic_mat = data_cast->intrinsic_mat;
- dist_coefs = data_cast->dist_coefs;
-
- cv::undistort(*imgptr, imgtmp, *intrinsic_mat, *dist_coefs);
-
- /* Write tmp into imgptr */
- imgptr->release();
- imgtmp.copyTo(*imgptr);
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C++ --------------------------------------------------------------*/ + /* class std::vector */ + #include <vector> + +/* Standard C ----------------------------------------------------------------*/ + /* snprintf() */ + #include <cstdio> + +/* Packages ------------------------------------------------------------------*/ + /* opencv */ + #include <opencv2/opencv.hpp> + #include <opencv2/calib3d/calib3d.hpp> + +/* Module -------------------------------------------------------------------*/ + /* data */ + #include "img_iface.hpp" + + #include "img_calib3d.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define CORNERS_HOR (16) + # define CORNERS_VER (13) + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void img_calib3d_calibrate (class cv::Mat *imgptr, void *data); +static void img_calib3d_undistort (class cv::Mat *imgptr, void *data); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void img_calib3d_act (class cv::Mat *imgptr, int action, void *data) +{ + switch (action) { + case IMG_CALIB3D_ACT_CALIBRATE: + img_calib3d_calibrate(imgptr, data); + break; + + case IMG_CALIB3D_ACT_UNDISTORT: + img_calib3d_undistort(imgptr, data); + break; + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void img_calib3d_calibrate (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Calibrate *data_cast; + + class cv::Mat *intrinsic_mat; + class cv::Mat *dist_coefs; + class std::vector <class cv::Mat> *rvecs; + class std::vector <class cv::Mat> *tvecs; + + class cv::Size_ <int> pattern_size; + class std::vector <class std::vector <class cv::Point3_ <float>>> object_points; + class std::vector <class std::vector <class cv::Point_ <float>>> image_points; + class std::vector <class cv::Point_ <float>> corners; + class std::vector <class cv::Point3_ <float>> obj; + + bool found; + int i; + int j; + + data_cast = (struct Img_Iface_Data_Calibrate *)data; + intrinsic_mat = data_cast->intrinsic_mat; + dist_coefs = data_cast->dist_coefs; + rvecs = data_cast->rvecs; + tvecs = data_cast->tvecs; + + pattern_size = cv::Size(CORNERS_HOR, CORNERS_VER); + *intrinsic_mat = cv::Mat(3, 3, CV_32FC1); + (*intrinsic_mat).ptr<float>(0)[0] = 1; + (*intrinsic_mat).ptr<float>(1)[1] = 1; + + for (i = 0; i < CORNERS_HOR; i++) { + for (j = 0; j < CORNERS_VER; j++) { + obj.push_back(cv::Point3f(i, j * 10.0, 0.0)); + } + } + + found = cv::findChessboardCorners(*imgptr, pattern_size, corners, + CV_CALIB_CB_ADAPTIVE_THRESH | + CV_CALIB_CB_FILTER_QUADS); + + cv::cornerSubPix(*imgptr, corners, cv::Size(11, 11), + cv::Size(-1, -1), + cv::TermCriteria(CV_TERMCRIT_EPS | + CV_TERMCRIT_ITER, 30, 0.1)); + cv::drawChessboardCorners(*imgptr, pattern_size, corners, found); + + image_points.push_back(corners); + object_points.push_back(obj); + + /* Calibrate */ + cv::calibrateCamera(object_points, image_points, imgptr->size(), + *intrinsic_mat, *dist_coefs, *rvecs, *tvecs); +} + +static void img_calib3d_undistort (class cv::Mat *imgptr, void *data) +{ + class cv::Mat imgtmp; + + /* Data */ + struct Img_Iface_Data_Undistort *data_cast; + + class cv::Mat *intrinsic_mat; + class cv::Mat *dist_coefs; + + data_cast = (struct Img_Iface_Data_Undistort *)data; + intrinsic_mat = data_cast->intrinsic_mat; + dist_coefs = data_cast->dist_coefs; + + cv::undistort(*imgptr, imgtmp, *intrinsic_mat, *dist_coefs); + + /* Write tmp into imgptr */ + imgptr->release(); + imgtmp.copyTo(*imgptr); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/src/img_cv.cpp b/modules/image/src/img_cv.cpp index 3a7c59b..0d76bb8 100644 --- a/modules/image/src/img_cv.cpp +++ b/modules/image/src/img_cv.cpp @@ -1,881 +1,881 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C++ --------------------------------------------------------------*/
- /* class std::vector */
- #include <vector>
-
-/* Standard C ----------------------------------------------------------------*/
- /* fabs */
- #include <cmath>
- /* true & false */
- #include <cstdbool>
- /* snprintf() */
- #include <cstdio>
-
-/* Packages ------------------------------------------------------------------*/
- /* opencv */
- #include <opencv2/opencv.hpp>
-
-/* Module --------------------------------------------------------------------*/
- /* data */
- #include "img_iface.hpp"
-
- #include "img_cv.hpp"
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
- /* Core: The core functionality */
- /* Pixel */
-static void img_cv_pixel_get (class cv::Mat *imgptr, void *data);
-static void img_cv_pixel_set (class cv::Mat *imgptr, void *data);
- /* ROI */
-static void img_cv_set_ROI (class cv::Mat *imgptr, void *data);
- /* Operations on Arrays */
-static void img_cv_and_2ref (class cv::Mat *imgptr, void *data);
-static void img_cv_not (class cv::Mat *imgptr);
-static void img_cv_or_2ref (class cv::Mat *imgptr, void *data);
-static void img_cv_component (class cv::Mat *imgptr, void *data);
- /* Imgproc: Image processing */
- /* Image filtering */
-static void img_cv_dilate (class cv::Mat *imgptr, void *data);
-static void img_cv_erode (class cv::Mat *imgptr, void *data);
-static void img_cv_smooth (class cv::Mat *imgptr, void *data);
-static void img_cv_sobel (class cv::Mat *imgptr, void *data);
-static void img_cv_border (class cv::Mat *imgptr, void *data);
- /* Geometric image transformations */
-static void img_cv_mirror (class cv::Mat *imgptr, void *data);
-static void img_cv_rotate_orto (class cv::Mat *imgptr, void *data);
-static void img_cv_rotate (class cv::Mat *imgptr, void *data);
- /* Miscellaneous image transformations */
-static void img_cv_adaptive_thr (class cv::Mat *imgptr, void *data);
-static void img_cv_cvt_color (class cv::Mat *imgptr, void *data);
-static void img_cv_distance_transform (class cv::Mat *imgptr);
-static void img_cv_threshold (class cv::Mat *imgptr, void *data);
- /* Histograms */
-static void img_cv_histogram (class cv::Mat *imgptr, void *data);
-static void img_cv_histogram_c3 (class cv::Mat *imgptr, void *data);
- /* Structural analysis and shape descriptors */
-static void img_cv_contours (class cv::Mat *imgptr, void *data);
-static void img_cv_contours_size (void *data);
-static void img_cv_bounding_rect (class cv::Mat *imgptr, void *data);
-static void img_cv_fit_ellipse (class cv::Mat *imgptr, void *data);
-static void img_cv_min_area_rect (class cv::Mat *imgptr, void *data);
- /* Feature detection */
-static void img_cv_hough_circles (class cv::Mat *imgptr, void *data);
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void img_cv_act (class cv::Mat *imgptr, int action, void *data)
-{
- switch (action) {
- case IMG_CV_ACT_PIXEL_GET:
- img_cv_pixel_get(imgptr, data);
- break;
- case IMG_CV_ACT_PIXEL_SET:
- img_cv_pixel_set(imgptr, data);
- break;
-
- case IMG_CV_ACT_SET_ROI:
- img_cv_set_ROI(imgptr, data);
- break;
-
- case IMG_CV_ACT_AND_2REF:
- img_cv_and_2ref(imgptr, data);
- break;
- case IMG_CV_ACT_NOT:
- img_cv_not(imgptr);
- break;
- case IMG_CV_ACT_OR_2REF:
- img_cv_or_2ref(imgptr, data);
- break;
- case IMG_CV_ACT_COMPONENT:
- img_cv_component(imgptr, data);
- break;
-
- case IMG_CV_ACT_DILATE:
- img_cv_dilate(imgptr, data);
- break;
- case IMG_CV_ACT_ERODE:
- img_cv_erode(imgptr, data);
- break;
- case IMG_CV_ACT_SMOOTH:
- img_cv_smooth(imgptr, data);
- break;
- case IMG_CV_ACT_SOBEL:
- img_cv_sobel(imgptr, data);
- break;
- case IMG_CV_ACT_BORDER:
- img_cv_border(imgptr, data);
- break;
-
- case IMG_CV_ACT_MIRROR:
- img_cv_mirror(imgptr, data);
- break;
- case IMG_CV_ACT_ROTATE_ORTO:
- img_cv_rotate_orto(imgptr, data);
- break;
- case IMG_CV_ACT_ROTATE:
- img_cv_rotate(imgptr, data);
- break;
-
- case IMG_CV_ACT_ADAPTIVE_THRESHOLD:
- img_cv_adaptive_thr(imgptr, data);
- break;
- case IMG_CV_ACT_CVT_COLOR:
- img_cv_cvt_color(imgptr, data);
- break;
- case IMG_CV_ACT_DISTANCE_TRANSFORM:
- img_cv_distance_transform(imgptr);
- break;
- case IMG_CV_ACT_THRESHOLD:
- img_cv_threshold(imgptr, data);
- break;
-
- case IMG_CV_ACT_HISTOGRAM:
- img_cv_histogram(imgptr, data);
- break;
- case IMG_CV_ACT_HISTOGRAM_C3:
- img_cv_histogram_c3(imgptr, data);
- break;
-
- case IMG_CV_ACT_CONTOURS:
- img_cv_contours(imgptr, data);
- break;
- case IMG_CV_ACT_CONTOURS_SIZE:
- img_cv_contours_size(data);
- break;
- case IMG_CV_ACT_BOUNDING_RECT:
- img_cv_bounding_rect(imgptr, data);
- break;
- case IMG_CV_ACT_FIT_ELLIPSE:
- img_cv_fit_ellipse(imgptr, data);
- break;
- case IMG_CV_ACT_MIN_AREA_RECT:
- img_cv_min_area_rect(imgptr, data);
- break;
-
- case IMG_CV_ACT_HOUGH_CIRCLES:
- img_cv_hough_circles(imgptr, data);
- break;
- }
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-/* Core: The core functionality */
-/* ----- Pixel */
-static void img_cv_pixel_get (class cv::Mat *imgptr, void *data)
-{
- struct Img_Iface_Data_Pixel_Get *data_cast;
- unsigned char *val;
- int x;
- int y;
- /* Data */
- data_cast = (struct Img_Iface_Data_Pixel_Get *)data;
-
- /* Value */
- val = data_cast->val;
- /* Position */
- x = data_cast->x;
- y = data_cast->y;
-
- /* Get value */
- *val = imgptr->at<unsigned char>(y, x);
-}
-
-static void img_cv_pixel_set (class cv::Mat *imgptr, void *data)
-{
- struct Img_Iface_Data_Pixel_Set *data_cast;
- unsigned char val;
- int x;
- int y;
-
- /* Data */
- data_cast = (struct Img_Iface_Data_Pixel_Set *)data;
-
- /* Value */
- val = data_cast->val;
- /* Position */
- x = data_cast->x;
- y = data_cast->y;
-
- /* Set value */
- imgptr->at<unsigned char>(y, x) = val;
-}
-
-/* ----- ROI */
-static void img_cv_set_ROI (class cv::Mat *imgptr, void *data)
-{
- class cv::Mat imgtmp;
- struct Img_Iface_Data_SetROI *data_cast;
- class cv::Rect_ <int> *rect;
-
- /* Data */
- data_cast = (struct Img_Iface_Data_SetROI *)data;
-
- /* Rectangle */
- rect = &(data_cast->rect);
-
- /* Set ROI */
- (*imgptr)(*rect).copyTo(imgtmp);
- imgtmp.copyTo(*imgptr);
-
- /* Write tmp into imgptr */
- imgptr->release();
- imgtmp.copyTo(*imgptr);
-
- /* clean up */
- imgtmp.release();
-}
-
-/* ----- Operations on arrays */
-static void img_cv_and_2ref (class cv::Mat *imgptr, void *data)
-{
- class cv::Mat *img_ref;
- img_ref = (class cv::Mat *)data;
-
- cv::bitwise_and(*imgptr, *img_ref, *imgptr);
-}
-
-static void img_cv_not (class cv::Mat *imgptr)
-{
- cv::bitwise_not(*imgptr, *imgptr);
-}
-
-static void img_cv_or_2ref (class cv::Mat *imgptr, void *data)
-{
- class cv::Mat *img_ref;
- img_ref = (class cv::Mat *)data;
-
- cv::bitwise_or(*imgptr, *img_ref, *imgptr);
-}
-
-static void img_cv_component (class cv::Mat *imgptr, void *data)
-{
- class cv::Mat cmp_img[3];
- struct Img_Iface_Data_Component *data_cast;
- int cmp;
-
- /* Data */
- data_cast = (struct Img_Iface_Data_Component *)data;
-
- /* Color component */
- cmp = data_cast->cmp;
-
- /* Write components into cmp_img[] */
- cv::split(*imgptr, cmp_img);
-
- /* Write tmp into imgptr */
- imgptr->release();
- cmp_img[cmp].copyTo(*imgptr);
-
- /* clean up */
- cmp_img[0].release();
- cmp_img[1].release();
- cmp_img[2].release();
-}
-
-/* Imgproc: Image processing */
-/* ----- Image filtering */
-static void img_cv_dilate (class cv::Mat *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_Dilate_Erode *data_cast;
- data_cast = (struct Img_Iface_Data_Dilate_Erode *)data;
-
- /* Iterations */
- int i;
- i = data_cast->i;
-
- /* Dilate */
- cv::dilate(*imgptr, *imgptr, cv::Mat(), cv::Point(-1,-1), i,
- cv::BORDER_CONSTANT, cv::Scalar(0));
-}
-
-static void img_cv_erode (class cv::Mat *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_Dilate_Erode *data_cast;
- data_cast = (struct Img_Iface_Data_Dilate_Erode *)data;
-
- /* Iterations */
- int i;
- i = data_cast->i;
-
- /* Erode */
- cv::erode(*imgptr, *imgptr, cv::Mat(), cv::Point(-1,-1), i,
- cv::BORDER_CONSTANT, cv::Scalar(0));
-}
-
-static void img_cv_smooth (class cv::Mat *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_Smooth *data_cast;
- data_cast = (struct Img_Iface_Data_Smooth *)data;
-
- /* Smoothing method */
- int method;
- method = data_cast->method;
- /* Kernel size */
- int ksize;
- ksize = data_cast->ksize;
- if (!(ksize % 2)) {
- ksize++;
- }
-
- switch (method) {
- case IMGI_SMOOTH_MEAN:
- cv::blur(*imgptr, *imgptr, cv::Size(ksize, ksize),
- cv::Point(-1,-1), cv::BORDER_DEFAULT);
- break;
- case IMGI_SMOOTH_GAUSS:
- cv::GaussianBlur(*imgptr, *imgptr, cv::Size(ksize, ksize),
- 0, 0, cv::BORDER_DEFAULT);
- break;
- case IMGI_SMOOTH_MEDIAN:
- cv::medianBlur(*imgptr, *imgptr, ksize);
- break;
- }
-}
-
-static void img_cv_sobel (class cv::Mat *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_Sobel *data_cast;
- data_cast = (struct Img_Iface_Data_Sobel *)data;
-
- /* Order of the derivative x */
- int dx;
- dx = data_cast->dx;
- /* Order of the derivative y */
- int dy;
- dy = data_cast->dy;
- /* Size of the extended Sobel kernel */
- int ksize;
- ksize = data_cast->ksize;
- if (!(ksize % 2)) {
- ksize++;
- }
-
- cv::Sobel(*imgptr, *imgptr, -1, dx, dy, ksize, 1, 0,
- cv::BORDER_DEFAULT);
-}
-
-static void img_cv_border (class cv::Mat *imgptr, void *data)
-{
- class cv::Mat imgtmp;
- struct Img_Iface_Data_Border *data_cast;
- int size;
-
- /* Data */
- data_cast = (struct Img_Iface_Data_Border *)data;
-
- size = data_cast->size;
-
- imgtmp = cv::Mat(cv::Size(imgptr->cols + size, imgptr->rows + size),
- CV_8U);
- /* Get transform */
- cv::copyMakeBorder(*imgptr, imgtmp, size, size, size, size,
- cv::BORDER_CONSTANT, cv::Scalar(0));
-
- imgtmp.copyTo(*imgptr);
-
- /* Cleanup */
- imgtmp.release();
-}
-
-/* ----- Geometric image transformations */
-static void img_cv_mirror (class cv::Mat *imgptr, void *data)
-{
- struct Img_Iface_Data_Mirror *data_cast;
- int axis;
-
- /* Data */
- data_cast = (struct Img_Iface_Data_Mirror *)data;
-
- /* Rotate n * pi/2 rad */
- axis = data_cast->axis;
-
- /* flip around axis */
- cv::flip(*imgptr, *imgptr, axis);
-}
-
-static void img_cv_rotate_orto (class cv::Mat *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_Rotate_Orto *data_cast;
- data_cast = (struct Img_Iface_Data_Rotate_Orto *)data;
-
- /* Rotate n * pi/2 rad */
- int n;
- n = data_cast->n;
-
- switch (n) {
- case 1:
- /* Rotate: transpose and flip around horizontal axis: flip_mode=0 */
- cv::transpose(*imgptr, *imgptr);
- cv::flip(*imgptr, *imgptr, 0);
- break;
-
- case 2:
- /* Rotate: Flip both axises: flip_mode=-1 */
- cv::flip(*imgptr, *imgptr, -1);
- break;
-
- case 3:
- /* Rotate: transpose and flip around vertical axis: flip_mode=1 */
- cv::transpose(*imgptr, *imgptr);
- cv::flip(*imgptr, *imgptr, 1);
- break;
- }
-}
-
-static void img_cv_rotate (class cv::Mat *imgptr, void *data)
-{
- class cv::Mat map_matrix;
-
- /* Data */
- struct Img_Iface_Data_Rotate *data_cast;
- data_cast = (struct Img_Iface_Data_Rotate *)data;
-
- /* Angle of rotation */
- class cv::Point_ <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();
-}
-
-/* ----- Miscellaneous image transformations */
-static void img_cv_adaptive_thr (class cv::Mat *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_Adaptive_Thr *data_cast;
- data_cast = (struct Img_Iface_Data_Adaptive_Thr *)data;
-
- /* Threshold method */
- int method;
- method = data_cast->method;
- /* Threshold type */
- int thr_typ;
- thr_typ = data_cast->thr_typ;
- /* Neighbourhood size */
- int ksize;
- ksize = data_cast->ksize;
- if (!(ksize % 2)) {
- ksize++;
- }
-
- /* Apply adaptive threshold */
- cv::adaptiveThreshold(*imgptr, *imgptr, 255, method, thr_typ, ksize,
- 0);
-}
-
-static void img_cv_cvt_color (class cv::Mat *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_Cvt_Color *data_cast;
- data_cast = (struct Img_Iface_Data_Cvt_Color *)data;
-
- /* Conversion method */
- int method;
- method = data_cast->method;
-
- cv::cvtColor(*imgptr, *imgptr, method, 0);
-}
-
-static void img_cv_distance_transform (class cv::Mat *imgptr)
-{
- class cv::Mat imgtmp;
-
- /* Get transform */
- cv::distanceTransform(*imgptr, imgtmp, CV_DIST_L2, CV_DIST_MASK_PRECISE);
-
- /* DistanceTransform gives CV_32F image */
- imgtmp.convertTo(*imgptr, CV_8U);
-
- /* Cleanup */
- imgtmp.release();
-}
-
-static void img_cv_threshold (class cv::Mat *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_Threshold *data_cast;
- data_cast = (struct Img_Iface_Data_Threshold *)data;
-
- /* Threshold type */
- int thr_typ;
- thr_typ = data_cast->thr_typ;
- /* Threshold value */
- int thr_val;
- thr_val = data_cast->thr_val;
- if (thr_val == -1) {
- thr_typ |= cv::THRESH_OTSU;
- }
-
- /* Threshold */
- cv::threshold(*imgptr, *imgptr, thr_val, 0xFF, thr_typ);
-}
-
-/* ----- Histograms */
-static void img_cv_histogram (class cv::Mat *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_Histogram *data_cast;
- data_cast = (struct Img_Iface_Data_Histogram *)data;
-
- /* Contours */
- class cv::Mat *hist;
- hist = data_cast->hist_c0;
- class cv::Mat *hist_img;
- hist_img = data_cast->hist_img;
-
- /* Write components into cmp_img[] */
- int h_size = 256;
- float h_range_arr[] = {0.0, 256.0};
- const float *h_range = {h_range_arr};
- cv::calcHist(imgptr, 1, 0, cv::Mat(), *hist, 1, &h_size, &h_range,
- true, false);
-
- /* Init */
- hist_img->setTo(cv::Scalar(0));
-
- /* Normalize the result to [0, hist_img->rows - 1] */
- cv::normalize(*hist, *hist, 0, hist_img->rows - 1, cv::NORM_MINMAX, -1,
- cv::Mat());
-
- /* Draw hist into hist_img */
- int i;
- for(i = 0; i < 256; i++ ) {
- cv::line(*hist_img, cv::Point(i, hist_img->rows - 0),
- cv::Point(i, hist_img->rows - hist->at<float>(i)),
- cv::Scalar(255, 0, 0), 1, 8, 0);
- }
-
- /* Show histogram */
- img_iface_show_hist_c1();
-}
-
-static void img_cv_histogram_c3 (class cv::Mat *imgptr, void *data)
-{
- class cv::Mat cmp_img[3];
-
- /* Write components into cmp_img[] */
- cv::split(*imgptr, cmp_img);
-
- /* Data */
- struct Img_Iface_Data_Histogram *data_cast;
- data_cast = (struct Img_Iface_Data_Histogram *)data;
-
- /* Contours */
- class cv::Mat *hist_c0;
- hist_c0 = data_cast->hist_c0;
- class cv::Mat *hist_c1;
- hist_c1 = data_cast->hist_c1;
- class cv::Mat *hist_c2;
- hist_c2 = data_cast->hist_c2;
- class cv::Mat *hist_img;
- hist_img = data_cast->hist_img;
-
- /* Write components into cmp_img[] */
- int h_size = 256;
- float h_range_arr[] = {0.0, 256.0};
- const float *h_range = {h_range_arr};
- cv::calcHist(&cmp_img[0], 1, 0, cv::Mat(), *hist_c0, 1, &h_size,
- &h_range, true, false);
- cv::calcHist(&cmp_img[1], 1, 0, cv::Mat(), *hist_c1, 1, &h_size,
- &h_range, true, false);
- cv::calcHist(&cmp_img[2], 1, 0, cv::Mat(), *hist_c2, 1, &h_size,
- &h_range, true, false);
-
- /* Init */
- hist_img->setTo(cv::Scalar(0));
-
- /* Normalize the result to [0, hist_img->rows - 1] */
- cv::normalize(*hist_c0, *hist_c0, 0, hist_img->rows - 1,
- cv::NORM_MINMAX, -1, cv::Mat());
- cv::normalize(*hist_c1, *hist_c1, 0, hist_img->rows - 1,
- cv::NORM_MINMAX, -1, cv::Mat());
- cv::normalize(*hist_c2, *hist_c2, 0, hist_img->rows - 1,
- cv::NORM_MINMAX, -1, cv::Mat());
-
- /* Draw hist into hist_img */
- int i;
- for(i = 0; i < 256; i++ ) {
- cv::line(*hist_img, cv::Point(3*i, hist_img->rows - 0),
- cv::Point(3*i,
- hist_img->rows - hist_c0->at<float>(i)),
- cv::Scalar(255, 0, 0), 1, 8, 0);
- }
- for(i = 0; i < 256; i++ ) {
- cv::line(*hist_img, cv::Point(3*i + 1, hist_img->rows - 0),
- cv::Point(3*i+1,
- hist_img->rows - hist_c1->at<float>(i)),
- cv::Scalar(0, 255, 0), 1, 8, 0);
- }
- for(i = 0; i < 256; i++ ) {
- cv::line(*hist_img, cv::Point(3*i + 2, hist_img->rows - 0),
- cv::Point(3*i + 2,
- hist_img->rows - hist_c2->at<float>(i)),
- cv::Scalar(0, 0, 255), 1, 8, 0);
- }
-
- /* Show histogram */
- img_iface_show_hist_c3();
-
- /* Cleanup */
- cmp_img[0].release();
- cmp_img[1].release();
- cmp_img[2].release();
-}
-
-/* ----- Structural analysis and shape descriptors */
-static void img_cv_contours (class cv::Mat *imgptr, void *data)
-{
- struct Img_Iface_Data_Contours *data_cast;
- class std::vector <class std::vector <class cv::Point_ <int>>> *contours;
- class cv::Mat *hierarchy;
-
- /* Data */
- data_cast = (struct Img_Iface_Data_Contours *)data;
-
- /* Contours */
- contours = data_cast->contours;
- hierarchy = data_cast->hierarchy;
-
- /* Get contours */
-
- cv::findContours(*imgptr, *contours, *hierarchy, CV_RETR_EXTERNAL,
- CV_CHAIN_APPROX_SIMPLE);
-
- /* Set image to black */
- imgptr->setTo(cv::Scalar(0));
-
- /* Draw contours in color */
- cv::drawContours(*imgptr, *contours, -1, cv::Scalar(255), 1, 8,
- *hierarchy, 1, cvPoint(0, 0));
-}
-
-static void img_cv_contours_size (void *data)
-{
- struct Img_Iface_Data_Contours_Size *data_cast;
- class std::vector <class std::vector <class cv::Point_ <int>>> *contours;
- int i;
-
- /* Data */
- data_cast = (struct Img_Iface_Data_Contours_Size *)data;
-
- /* Contours */
- contours = data_cast->contours;
-
- /* Get area and perimeter */
- if (data_cast->area) {
- for (i = 0; i < (int)contours->size(); i++) {
- data_cast->area[i] = cv::contourArea(
- (*contours)[i], false);
- }
- }
- if (data_cast->perimeter) {
- for (i = 0; i < (int)contours->size(); i++) {
- data_cast->perimeter[i] = cv::arcLength(
- (*contours)[i], true);
- }
- }
-}
-
-static void img_cv_bounding_rect (class cv::Mat *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_Bounding_Rect *data_cast;
- data_cast = (struct Img_Iface_Data_Bounding_Rect *)data;
-
- /* Contours */
- class std::vector <class cv::Point_ <int>> *contour;
- contour = data_cast->contour;
- /* Rotated rectangle */
- class cv::Rect_ <int> *rect;
- rect = data_cast->rect;
- /* Show rectangle ? */
- bool show;
- show = data_cast->show;
-
- /* Get rectangle */
- *rect = cv::boundingRect(*contour);
-
- /* Draw rectangle */
- class cv::Point_<float> vertices[4];
- if (show) {
- vertices[0].x = rect->x;
- vertices[0].y = rect->y;
- vertices[1].x = rect->x + rect->width;
- vertices[1].y = rect->y;
- vertices[2].x = rect->x + rect->width;
- vertices[2].y = rect->y + rect->height;
- vertices[3].x = rect->x;
- vertices[3].y = rect->y + rect->height;
- cv::line(*imgptr, cv::Point(vertices[0].x, vertices[0].y),
- cv::Point(vertices[1].x, vertices[1].y),
- CV_RGB(0, 0, 255), 1, 8, 0);
- cv::line(*imgptr, cv::Point(vertices[1].x, vertices[1].y),
- cv::Point(vertices[2].x, vertices[2].y),
- CV_RGB(0, 0, 255), 1, 8, 0);
- cv::line(*imgptr, cv::Point(vertices[2].x, vertices[2].y),
- cv::Point(vertices[3].x, vertices[3].y),
- CV_RGB(0, 0, 255), 1, 8, 0);
- cv::line(*imgptr, cv::Point(vertices[3].x, vertices[3].y),
- cv::Point(vertices[0].x, vertices[0].y),
- CV_RGB(0, 0, 255), 1, 8, 0);
- }
-}
-
-static void img_cv_fit_ellipse (class cv::Mat *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_MinARect *data_cast;
- data_cast = (struct Img_Iface_Data_MinARect *)data;
-
- /* Contours */
- class std::vector <class cv::Point_ <int>> *contour;
- contour = data_cast->contour;
- /* Rotated rectangle */
- class cv::RotatedRect *rect;
- rect = data_cast->rect;
- /* Show rectangle ? */
- bool show;
- show = data_cast->show;
-
- /* Get rectangle */
- *rect = cv::fitEllipse(*contour);
-
- /* Draw rectangle */
- class cv::Point_<float> vertices[4];
- if (show) {
- rect->points(vertices);
- cv::line(*imgptr, cv::Point(vertices[0].x, vertices[0].y),
- cv::Point(vertices[1].x, vertices[1].y),
- CV_RGB(0, 0, 255), 1, 8, 0);
- cv::line(*imgptr, cv::Point(vertices[1].x, vertices[1].y),
- cv::Point(vertices[2].x, vertices[2].y),
- CV_RGB(0, 0, 255), 1, 8, 0);
- cv::line(*imgptr, cv::Point(vertices[2].x, vertices[2].y),
- cv::Point(vertices[3].x, vertices[3].y),
- CV_RGB(0, 0, 255), 1, 8, 0);
- cv::line(*imgptr, cv::Point(vertices[3].x, vertices[3].y),
- cv::Point(vertices[0].x, vertices[0].y),
- CV_RGB(0, 0, 255), 1, 8, 0);
- }
-}
-
-static void img_cv_min_area_rect (class cv::Mat *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_MinARect *data_cast;
- data_cast = (struct Img_Iface_Data_MinARect *)data;
-
- /* Contours */
- class std::vector <class cv::Point_ <int>> *contour;
- contour = data_cast->contour;
- /* Rotated rectangle */
- class cv::RotatedRect *rect;
- rect = data_cast->rect;
- /* Show rectangle ? */
- bool show;
- show = data_cast->show;
-
- /* Get rectangle */
- *rect = cv::minAreaRect(*contour);
-
- /* Draw rectangle */
- class cv::Point_<float> vertices[4];
- if (show) {
- rect->points(vertices);
- cv::line(*imgptr, cv::Point(vertices[0].x, vertices[0].y),
- cv::Point(vertices[1].x, vertices[1].y),
- CV_RGB(0, 0, 255), 1, 8, 0);
- cv::line(*imgptr, cv::Point(vertices[1].x, vertices[1].y),
- cv::Point(vertices[2].x, vertices[2].y),
- CV_RGB(0, 0, 255), 1, 8, 0);
- cv::line(*imgptr, cv::Point(vertices[2].x, vertices[2].y),
- cv::Point(vertices[3].x, vertices[3].y),
- CV_RGB(0, 0, 255), 1, 8, 0);
- cv::line(*imgptr, cv::Point(vertices[3].x, vertices[3].y),
- cv::Point(vertices[0].x, vertices[0].y),
- CV_RGB(0, 0, 255), 1, 8, 0);
- }
-}
-
-/* ----- Feature detection */
-static void img_cv_hough_circles (class cv::Mat *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_Hough_Circles *data_cast;
- data_cast = (struct Img_Iface_Data_Hough_Circles *)data;
-
- /* Contours */
- class std::vector <class cv::Vec <float, 3>> *circles;
- circles = data_cast->circles;
- /* Parameters */
- double dist_min;
- double param_1;
- double param_2;
- int radius_min;
- int radius_max;
- dist_min = data_cast->dist_min;
- param_1 = data_cast->param_1;
- param_2 = data_cast->param_2;
- radius_min = data_cast->radius_min;
- radius_max = data_cast->radius_max;
-
- /* Get circles */
- cv::HoughCircles(*imgptr, *circles, CV_HOUGH_GRADIENT, 1, dist_min,
- param_1, param_2, radius_min, radius_max);
-
- /* Set image to black */
- imgptr->setTo(cv::Scalar(0));
-
- /* Draw circles */
- class cv::Point_ <int> center;
- int radius;
- int i;
- for (i = 0; i < (int)circles->size(); i++) {
- center.x = cvRound((*circles)[i][0]);
- center.y = cvRound((*circles)[i][1]);
- radius = cvRound((*circles)[i][2]);
-
- /* Draw the circle center */
-/* cv::circle(*imgptr, center, 3,
- cv::Scalar(0, 255, 0), -1, 8, 0);*/
-
- /* Draw the circle outline */
- cv::circle(*imgptr, center, radius,
- cv::Scalar(250), 1, 8, 0);
- }
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C++ --------------------------------------------------------------*/ + /* class std::vector */ + #include <vector> + +/* Standard C ----------------------------------------------------------------*/ + /* fabs */ + #include <cmath> + /* true & false */ + #include <cstdbool> + /* snprintf() */ + #include <cstdio> + +/* Packages ------------------------------------------------------------------*/ + /* opencv */ + #include <opencv2/opencv.hpp> + +/* Module --------------------------------------------------------------------*/ + /* data */ + #include "img_iface.hpp" + + #include "img_cv.hpp" + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ + /* Core: The core functionality */ + /* Pixel */ +static void img_cv_pixel_get (class cv::Mat *imgptr, void *data); +static void img_cv_pixel_set (class cv::Mat *imgptr, void *data); + /* ROI */ +static void img_cv_set_ROI (class cv::Mat *imgptr, void *data); + /* Operations on Arrays */ +static void img_cv_and_2ref (class cv::Mat *imgptr, void *data); +static void img_cv_not (class cv::Mat *imgptr); +static void img_cv_or_2ref (class cv::Mat *imgptr, void *data); +static void img_cv_component (class cv::Mat *imgptr, void *data); + /* Imgproc: Image processing */ + /* Image filtering */ +static void img_cv_dilate (class cv::Mat *imgptr, void *data); +static void img_cv_erode (class cv::Mat *imgptr, void *data); +static void img_cv_smooth (class cv::Mat *imgptr, void *data); +static void img_cv_sobel (class cv::Mat *imgptr, void *data); +static void img_cv_border (class cv::Mat *imgptr, void *data); + /* Geometric image transformations */ +static void img_cv_mirror (class cv::Mat *imgptr, void *data); +static void img_cv_rotate_orto (class cv::Mat *imgptr, void *data); +static void img_cv_rotate (class cv::Mat *imgptr, void *data); + /* Miscellaneous image transformations */ +static void img_cv_adaptive_thr (class cv::Mat *imgptr, void *data); +static void img_cv_cvt_color (class cv::Mat *imgptr, void *data); +static void img_cv_distance_transform (class cv::Mat *imgptr); +static void img_cv_threshold (class cv::Mat *imgptr, void *data); + /* Histograms */ +static void img_cv_histogram (class cv::Mat *imgptr, void *data); +static void img_cv_histogram_c3 (class cv::Mat *imgptr, void *data); + /* Structural analysis and shape descriptors */ +static void img_cv_contours (class cv::Mat *imgptr, void *data); +static void img_cv_contours_size (void *data); +static void img_cv_bounding_rect (class cv::Mat *imgptr, void *data); +static void img_cv_fit_ellipse (class cv::Mat *imgptr, void *data); +static void img_cv_min_area_rect (class cv::Mat *imgptr, void *data); + /* Feature detection */ +static void img_cv_hough_circles (class cv::Mat *imgptr, void *data); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void img_cv_act (class cv::Mat *imgptr, int action, void *data) +{ + switch (action) { + case IMG_CV_ACT_PIXEL_GET: + img_cv_pixel_get(imgptr, data); + break; + case IMG_CV_ACT_PIXEL_SET: + img_cv_pixel_set(imgptr, data); + break; + + case IMG_CV_ACT_SET_ROI: + img_cv_set_ROI(imgptr, data); + break; + + case IMG_CV_ACT_AND_2REF: + img_cv_and_2ref(imgptr, data); + break; + case IMG_CV_ACT_NOT: + img_cv_not(imgptr); + break; + case IMG_CV_ACT_OR_2REF: + img_cv_or_2ref(imgptr, data); + break; + case IMG_CV_ACT_COMPONENT: + img_cv_component(imgptr, data); + break; + + case IMG_CV_ACT_DILATE: + img_cv_dilate(imgptr, data); + break; + case IMG_CV_ACT_ERODE: + img_cv_erode(imgptr, data); + break; + case IMG_CV_ACT_SMOOTH: + img_cv_smooth(imgptr, data); + break; + case IMG_CV_ACT_SOBEL: + img_cv_sobel(imgptr, data); + break; + case IMG_CV_ACT_BORDER: + img_cv_border(imgptr, data); + break; + + case IMG_CV_ACT_MIRROR: + img_cv_mirror(imgptr, data); + break; + case IMG_CV_ACT_ROTATE_ORTO: + img_cv_rotate_orto(imgptr, data); + break; + case IMG_CV_ACT_ROTATE: + img_cv_rotate(imgptr, data); + break; + + case IMG_CV_ACT_ADAPTIVE_THRESHOLD: + img_cv_adaptive_thr(imgptr, data); + break; + case IMG_CV_ACT_CVT_COLOR: + img_cv_cvt_color(imgptr, data); + break; + case IMG_CV_ACT_DISTANCE_TRANSFORM: + img_cv_distance_transform(imgptr); + break; + case IMG_CV_ACT_THRESHOLD: + img_cv_threshold(imgptr, data); + break; + + case IMG_CV_ACT_HISTOGRAM: + img_cv_histogram(imgptr, data); + break; + case IMG_CV_ACT_HISTOGRAM_C3: + img_cv_histogram_c3(imgptr, data); + break; + + case IMG_CV_ACT_CONTOURS: + img_cv_contours(imgptr, data); + break; + case IMG_CV_ACT_CONTOURS_SIZE: + img_cv_contours_size(data); + break; + case IMG_CV_ACT_BOUNDING_RECT: + img_cv_bounding_rect(imgptr, data); + break; + case IMG_CV_ACT_FIT_ELLIPSE: + img_cv_fit_ellipse(imgptr, data); + break; + case IMG_CV_ACT_MIN_AREA_RECT: + img_cv_min_area_rect(imgptr, data); + break; + + case IMG_CV_ACT_HOUGH_CIRCLES: + img_cv_hough_circles(imgptr, data); + break; + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +/* Core: The core functionality */ +/* ----- Pixel */ +static void img_cv_pixel_get (class cv::Mat *imgptr, void *data) +{ + struct Img_Iface_Data_Pixel_Get *data_cast; + unsigned char *val; + int x; + int y; + /* Data */ + data_cast = (struct Img_Iface_Data_Pixel_Get *)data; + + /* Value */ + val = data_cast->val; + /* Position */ + x = data_cast->x; + y = data_cast->y; + + /* Get value */ + *val = imgptr->at<unsigned char>(y, x); +} + +static void img_cv_pixel_set (class cv::Mat *imgptr, void *data) +{ + struct Img_Iface_Data_Pixel_Set *data_cast; + unsigned char val; + int x; + int y; + + /* Data */ + data_cast = (struct Img_Iface_Data_Pixel_Set *)data; + + /* Value */ + val = data_cast->val; + /* Position */ + x = data_cast->x; + y = data_cast->y; + + /* Set value */ + imgptr->at<unsigned char>(y, x) = val; +} + +/* ----- ROI */ +static void img_cv_set_ROI (class cv::Mat *imgptr, void *data) +{ + class cv::Mat imgtmp; + struct Img_Iface_Data_SetROI *data_cast; + class cv::Rect_ <int> *rect; + + /* Data */ + data_cast = (struct Img_Iface_Data_SetROI *)data; + + /* Rectangle */ + rect = &(data_cast->rect); + + /* Set ROI */ + (*imgptr)(*rect).copyTo(imgtmp); + imgtmp.copyTo(*imgptr); + + /* Write tmp into imgptr */ + imgptr->release(); + imgtmp.copyTo(*imgptr); + + /* clean up */ + imgtmp.release(); +} + +/* ----- Operations on arrays */ +static void img_cv_and_2ref (class cv::Mat *imgptr, void *data) +{ + class cv::Mat *img_ref; + img_ref = (class cv::Mat *)data; + + cv::bitwise_and(*imgptr, *img_ref, *imgptr); +} + +static void img_cv_not (class cv::Mat *imgptr) +{ + cv::bitwise_not(*imgptr, *imgptr); +} + +static void img_cv_or_2ref (class cv::Mat *imgptr, void *data) +{ + class cv::Mat *img_ref; + img_ref = (class cv::Mat *)data; + + cv::bitwise_or(*imgptr, *img_ref, *imgptr); +} + +static void img_cv_component (class cv::Mat *imgptr, void *data) +{ + class cv::Mat cmp_img[3]; + struct Img_Iface_Data_Component *data_cast; + int cmp; + + /* Data */ + data_cast = (struct Img_Iface_Data_Component *)data; + + /* Color component */ + cmp = data_cast->cmp; + + /* Write components into cmp_img[] */ + cv::split(*imgptr, cmp_img); + + /* Write tmp into imgptr */ + imgptr->release(); + cmp_img[cmp].copyTo(*imgptr); + + /* clean up */ + cmp_img[0].release(); + cmp_img[1].release(); + cmp_img[2].release(); +} + +/* Imgproc: Image processing */ +/* ----- Image filtering */ +static void img_cv_dilate (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Dilate_Erode *data_cast; + data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; + + /* Iterations */ + int i; + i = data_cast->i; + + /* Dilate */ + cv::dilate(*imgptr, *imgptr, cv::Mat(), cv::Point(-1,-1), i, + cv::BORDER_CONSTANT, cv::Scalar(0)); +} + +static void img_cv_erode (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Dilate_Erode *data_cast; + data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; + + /* Iterations */ + int i; + i = data_cast->i; + + /* Erode */ + cv::erode(*imgptr, *imgptr, cv::Mat(), cv::Point(-1,-1), i, + cv::BORDER_CONSTANT, cv::Scalar(0)); +} + +static void img_cv_smooth (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Smooth *data_cast; + data_cast = (struct Img_Iface_Data_Smooth *)data; + + /* Smoothing method */ + int method; + method = data_cast->method; + /* Kernel size */ + int ksize; + ksize = data_cast->ksize; + if (!(ksize % 2)) { + ksize++; + } + + switch (method) { + case IMGI_SMOOTH_MEAN: + cv::blur(*imgptr, *imgptr, cv::Size(ksize, ksize), + cv::Point(-1,-1), cv::BORDER_DEFAULT); + break; + case IMGI_SMOOTH_GAUSS: + cv::GaussianBlur(*imgptr, *imgptr, cv::Size(ksize, ksize), + 0, 0, cv::BORDER_DEFAULT); + break; + case IMGI_SMOOTH_MEDIAN: + cv::medianBlur(*imgptr, *imgptr, ksize); + break; + } +} + +static void img_cv_sobel (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Sobel *data_cast; + data_cast = (struct Img_Iface_Data_Sobel *)data; + + /* Order of the derivative x */ + int dx; + dx = data_cast->dx; + /* Order of the derivative y */ + int dy; + dy = data_cast->dy; + /* Size of the extended Sobel kernel */ + int ksize; + ksize = data_cast->ksize; + if (!(ksize % 2)) { + ksize++; + } + + cv::Sobel(*imgptr, *imgptr, -1, dx, dy, ksize, 1, 0, + cv::BORDER_DEFAULT); +} + +static void img_cv_border (class cv::Mat *imgptr, void *data) +{ + class cv::Mat imgtmp; + struct Img_Iface_Data_Border *data_cast; + int size; + + /* Data */ + data_cast = (struct Img_Iface_Data_Border *)data; + + size = data_cast->size; + + imgtmp = cv::Mat(cv::Size(imgptr->cols + size, imgptr->rows + size), + CV_8U); + /* Get transform */ + cv::copyMakeBorder(*imgptr, imgtmp, size, size, size, size, + cv::BORDER_CONSTANT, cv::Scalar(0)); + + imgtmp.copyTo(*imgptr); + + /* Cleanup */ + imgtmp.release(); +} + +/* ----- Geometric image transformations */ +static void img_cv_mirror (class cv::Mat *imgptr, void *data) +{ + struct Img_Iface_Data_Mirror *data_cast; + int axis; + + /* Data */ + data_cast = (struct Img_Iface_Data_Mirror *)data; + + /* Rotate n * pi/2 rad */ + axis = data_cast->axis; + + /* flip around axis */ + cv::flip(*imgptr, *imgptr, axis); +} + +static void img_cv_rotate_orto (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Rotate_Orto *data_cast; + data_cast = (struct Img_Iface_Data_Rotate_Orto *)data; + + /* Rotate n * pi/2 rad */ + int n; + n = data_cast->n; + + switch (n) { + case 1: + /* Rotate: transpose and flip around horizontal axis: flip_mode=0 */ + cv::transpose(*imgptr, *imgptr); + cv::flip(*imgptr, *imgptr, 0); + break; + + case 2: + /* Rotate: Flip both axises: flip_mode=-1 */ + cv::flip(*imgptr, *imgptr, -1); + break; + + case 3: + /* Rotate: transpose and flip around vertical axis: flip_mode=1 */ + cv::transpose(*imgptr, *imgptr); + cv::flip(*imgptr, *imgptr, 1); + break; + } +} + +static void img_cv_rotate (class cv::Mat *imgptr, void *data) +{ + class cv::Mat map_matrix; + + /* Data */ + struct Img_Iface_Data_Rotate *data_cast; + data_cast = (struct Img_Iface_Data_Rotate *)data; + + /* Angle of rotation */ + class cv::Point_ <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(); +} + +/* ----- Miscellaneous image transformations */ +static void img_cv_adaptive_thr (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Adaptive_Thr *data_cast; + data_cast = (struct Img_Iface_Data_Adaptive_Thr *)data; + + /* Threshold method */ + int method; + method = data_cast->method; + /* Threshold type */ + int thr_typ; + thr_typ = data_cast->thr_typ; + /* Neighbourhood size */ + int ksize; + ksize = data_cast->ksize; + if (!(ksize % 2)) { + ksize++; + } + + /* Apply adaptive threshold */ + cv::adaptiveThreshold(*imgptr, *imgptr, 255, method, thr_typ, ksize, + 0); +} + +static void img_cv_cvt_color (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Cvt_Color *data_cast; + data_cast = (struct Img_Iface_Data_Cvt_Color *)data; + + /* Conversion method */ + int method; + method = data_cast->method; + + cv::cvtColor(*imgptr, *imgptr, method, 0); +} + +static void img_cv_distance_transform (class cv::Mat *imgptr) +{ + class cv::Mat imgtmp; + + /* Get transform */ + cv::distanceTransform(*imgptr, imgtmp, CV_DIST_L2, CV_DIST_MASK_PRECISE); + + /* DistanceTransform gives CV_32F image */ + imgtmp.convertTo(*imgptr, CV_8U); + + /* Cleanup */ + imgtmp.release(); +} + +static void img_cv_threshold (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Threshold *data_cast; + data_cast = (struct Img_Iface_Data_Threshold *)data; + + /* Threshold type */ + int thr_typ; + thr_typ = data_cast->thr_typ; + /* Threshold value */ + int thr_val; + thr_val = data_cast->thr_val; + if (thr_val == -1) { + thr_typ |= cv::THRESH_OTSU; + } + + /* Threshold */ + cv::threshold(*imgptr, *imgptr, thr_val, 0xFF, thr_typ); +} + +/* ----- Histograms */ +static void img_cv_histogram (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Histogram *data_cast; + data_cast = (struct Img_Iface_Data_Histogram *)data; + + /* Contours */ + class cv::Mat *hist; + hist = data_cast->hist_c0; + class cv::Mat *hist_img; + hist_img = data_cast->hist_img; + + /* Write components into cmp_img[] */ + int h_size = 256; + float h_range_arr[] = {0.0, 256.0}; + const float *h_range = {h_range_arr}; + cv::calcHist(imgptr, 1, 0, cv::Mat(), *hist, 1, &h_size, &h_range, + true, false); + + /* Init */ + hist_img->setTo(cv::Scalar(0)); + + /* Normalize the result to [0, hist_img->rows - 1] */ + cv::normalize(*hist, *hist, 0, hist_img->rows - 1, cv::NORM_MINMAX, -1, + cv::Mat()); + + /* Draw hist into hist_img */ + int i; + for(i = 0; i < 256; i++ ) { + cv::line(*hist_img, cv::Point(i, hist_img->rows - 0), + cv::Point(i, hist_img->rows - hist->at<float>(i)), + cv::Scalar(255, 0, 0), 1, 8, 0); + } + + /* Show histogram */ + img_iface_show_hist_c1(); +} + +static void img_cv_histogram_c3 (class cv::Mat *imgptr, void *data) +{ + class cv::Mat cmp_img[3]; + + /* Write components into cmp_img[] */ + cv::split(*imgptr, cmp_img); + + /* Data */ + struct Img_Iface_Data_Histogram *data_cast; + data_cast = (struct Img_Iface_Data_Histogram *)data; + + /* Contours */ + class cv::Mat *hist_c0; + hist_c0 = data_cast->hist_c0; + class cv::Mat *hist_c1; + hist_c1 = data_cast->hist_c1; + class cv::Mat *hist_c2; + hist_c2 = data_cast->hist_c2; + class cv::Mat *hist_img; + hist_img = data_cast->hist_img; + + /* Write components into cmp_img[] */ + int h_size = 256; + float h_range_arr[] = {0.0, 256.0}; + const float *h_range = {h_range_arr}; + cv::calcHist(&cmp_img[0], 1, 0, cv::Mat(), *hist_c0, 1, &h_size, + &h_range, true, false); + cv::calcHist(&cmp_img[1], 1, 0, cv::Mat(), *hist_c1, 1, &h_size, + &h_range, true, false); + cv::calcHist(&cmp_img[2], 1, 0, cv::Mat(), *hist_c2, 1, &h_size, + &h_range, true, false); + + /* Init */ + hist_img->setTo(cv::Scalar(0)); + + /* Normalize the result to [0, hist_img->rows - 1] */ + cv::normalize(*hist_c0, *hist_c0, 0, hist_img->rows - 1, + cv::NORM_MINMAX, -1, cv::Mat()); + cv::normalize(*hist_c1, *hist_c1, 0, hist_img->rows - 1, + cv::NORM_MINMAX, -1, cv::Mat()); + cv::normalize(*hist_c2, *hist_c2, 0, hist_img->rows - 1, + cv::NORM_MINMAX, -1, cv::Mat()); + + /* Draw hist into hist_img */ + int i; + for(i = 0; i < 256; i++ ) { + cv::line(*hist_img, cv::Point(3*i, hist_img->rows - 0), + cv::Point(3*i, + hist_img->rows - hist_c0->at<float>(i)), + cv::Scalar(255, 0, 0), 1, 8, 0); + } + for(i = 0; i < 256; i++ ) { + cv::line(*hist_img, cv::Point(3*i + 1, hist_img->rows - 0), + cv::Point(3*i+1, + hist_img->rows - hist_c1->at<float>(i)), + cv::Scalar(0, 255, 0), 1, 8, 0); + } + for(i = 0; i < 256; i++ ) { + cv::line(*hist_img, cv::Point(3*i + 2, hist_img->rows - 0), + cv::Point(3*i + 2, + hist_img->rows - hist_c2->at<float>(i)), + cv::Scalar(0, 0, 255), 1, 8, 0); + } + + /* Show histogram */ + img_iface_show_hist_c3(); + + /* Cleanup */ + cmp_img[0].release(); + cmp_img[1].release(); + cmp_img[2].release(); +} + +/* ----- Structural analysis and shape descriptors */ +static void img_cv_contours (class cv::Mat *imgptr, void *data) +{ + struct Img_Iface_Data_Contours *data_cast; + class std::vector <class std::vector <class cv::Point_ <int>>> *contours; + class cv::Mat *hierarchy; + + /* Data */ + data_cast = (struct Img_Iface_Data_Contours *)data; + + /* Contours */ + contours = data_cast->contours; + hierarchy = data_cast->hierarchy; + + /* Get contours */ + + cv::findContours(*imgptr, *contours, *hierarchy, CV_RETR_EXTERNAL, + CV_CHAIN_APPROX_SIMPLE); + + /* Set image to black */ + imgptr->setTo(cv::Scalar(0)); + + /* Draw contours in color */ + cv::drawContours(*imgptr, *contours, -1, cv::Scalar(255), 1, 8, + *hierarchy, 1, cvPoint(0, 0)); +} + +static void img_cv_contours_size (void *data) +{ + struct Img_Iface_Data_Contours_Size *data_cast; + class std::vector <class std::vector <class cv::Point_ <int>>> *contours; + int i; + + /* Data */ + data_cast = (struct Img_Iface_Data_Contours_Size *)data; + + /* Contours */ + contours = data_cast->contours; + + /* Get area and perimeter */ + if (data_cast->area) { + for (i = 0; i < (int)contours->size(); i++) { + data_cast->area[i] = cv::contourArea( + (*contours)[i], false); + } + } + if (data_cast->perimeter) { + for (i = 0; i < (int)contours->size(); i++) { + data_cast->perimeter[i] = cv::arcLength( + (*contours)[i], true); + } + } +} + +static void img_cv_bounding_rect (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Bounding_Rect *data_cast; + data_cast = (struct Img_Iface_Data_Bounding_Rect *)data; + + /* Contours */ + class std::vector <class cv::Point_ <int>> *contour; + contour = data_cast->contour; + /* Rotated rectangle */ + class cv::Rect_ <int> *rect; + rect = data_cast->rect; + /* Show rectangle ? */ + bool show; + show = data_cast->show; + + /* Get rectangle */ + *rect = cv::boundingRect(*contour); + + /* Draw rectangle */ + class cv::Point_<float> vertices[4]; + if (show) { + vertices[0].x = rect->x; + vertices[0].y = rect->y; + vertices[1].x = rect->x + rect->width; + vertices[1].y = rect->y; + vertices[2].x = rect->x + rect->width; + vertices[2].y = rect->y + rect->height; + vertices[3].x = rect->x; + vertices[3].y = rect->y + rect->height; + cv::line(*imgptr, cv::Point(vertices[0].x, vertices[0].y), + cv::Point(vertices[1].x, vertices[1].y), + CV_RGB(0, 0, 255), 1, 8, 0); + cv::line(*imgptr, cv::Point(vertices[1].x, vertices[1].y), + cv::Point(vertices[2].x, vertices[2].y), + CV_RGB(0, 0, 255), 1, 8, 0); + cv::line(*imgptr, cv::Point(vertices[2].x, vertices[2].y), + cv::Point(vertices[3].x, vertices[3].y), + CV_RGB(0, 0, 255), 1, 8, 0); + cv::line(*imgptr, cv::Point(vertices[3].x, vertices[3].y), + cv::Point(vertices[0].x, vertices[0].y), + CV_RGB(0, 0, 255), 1, 8, 0); + } +} + +static void img_cv_fit_ellipse (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_MinARect *data_cast; + data_cast = (struct Img_Iface_Data_MinARect *)data; + + /* Contours */ + class std::vector <class cv::Point_ <int>> *contour; + contour = data_cast->contour; + /* Rotated rectangle */ + class cv::RotatedRect *rect; + rect = data_cast->rect; + /* Show rectangle ? */ + bool show; + show = data_cast->show; + + /* Get rectangle */ + *rect = cv::fitEllipse(*contour); + + /* Draw rectangle */ + class cv::Point_<float> vertices[4]; + if (show) { + rect->points(vertices); + cv::line(*imgptr, cv::Point(vertices[0].x, vertices[0].y), + cv::Point(vertices[1].x, vertices[1].y), + CV_RGB(0, 0, 255), 1, 8, 0); + cv::line(*imgptr, cv::Point(vertices[1].x, vertices[1].y), + cv::Point(vertices[2].x, vertices[2].y), + CV_RGB(0, 0, 255), 1, 8, 0); + cv::line(*imgptr, cv::Point(vertices[2].x, vertices[2].y), + cv::Point(vertices[3].x, vertices[3].y), + CV_RGB(0, 0, 255), 1, 8, 0); + cv::line(*imgptr, cv::Point(vertices[3].x, vertices[3].y), + cv::Point(vertices[0].x, vertices[0].y), + CV_RGB(0, 0, 255), 1, 8, 0); + } +} + +static void img_cv_min_area_rect (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_MinARect *data_cast; + data_cast = (struct Img_Iface_Data_MinARect *)data; + + /* Contours */ + class std::vector <class cv::Point_ <int>> *contour; + contour = data_cast->contour; + /* Rotated rectangle */ + class cv::RotatedRect *rect; + rect = data_cast->rect; + /* Show rectangle ? */ + bool show; + show = data_cast->show; + + /* Get rectangle */ + *rect = cv::minAreaRect(*contour); + + /* Draw rectangle */ + class cv::Point_<float> vertices[4]; + if (show) { + rect->points(vertices); + cv::line(*imgptr, cv::Point(vertices[0].x, vertices[0].y), + cv::Point(vertices[1].x, vertices[1].y), + CV_RGB(0, 0, 255), 1, 8, 0); + cv::line(*imgptr, cv::Point(vertices[1].x, vertices[1].y), + cv::Point(vertices[2].x, vertices[2].y), + CV_RGB(0, 0, 255), 1, 8, 0); + cv::line(*imgptr, cv::Point(vertices[2].x, vertices[2].y), + cv::Point(vertices[3].x, vertices[3].y), + CV_RGB(0, 0, 255), 1, 8, 0); + cv::line(*imgptr, cv::Point(vertices[3].x, vertices[3].y), + cv::Point(vertices[0].x, vertices[0].y), + CV_RGB(0, 0, 255), 1, 8, 0); + } +} + +/* ----- Feature detection */ +static void img_cv_hough_circles (class cv::Mat *imgptr, void *data) +{ + /* Data */ + struct Img_Iface_Data_Hough_Circles *data_cast; + data_cast = (struct Img_Iface_Data_Hough_Circles *)data; + + /* Contours */ + class std::vector <class cv::Vec <float, 3>> *circles; + circles = data_cast->circles; + /* Parameters */ + double dist_min; + double param_1; + double param_2; + int radius_min; + int radius_max; + dist_min = data_cast->dist_min; + param_1 = data_cast->param_1; + param_2 = data_cast->param_2; + radius_min = data_cast->radius_min; + radius_max = data_cast->radius_max; + + /* Get circles */ + cv::HoughCircles(*imgptr, *circles, CV_HOUGH_GRADIENT, 1, dist_min, + param_1, param_2, radius_min, radius_max); + + /* Set image to black */ + imgptr->setTo(cv::Scalar(0)); + + /* Draw circles */ + class cv::Point_ <int> center; + int radius; + int i; + for (i = 0; i < (int)circles->size(); i++) { + center.x = cvRound((*circles)[i][0]); + center.y = cvRound((*circles)[i][1]); + radius = cvRound((*circles)[i][2]); + + /* Draw the circle center */ +/* cv::circle(*imgptr, center, 3, + cv::Scalar(0, 255, 0), -1, 8, 0);*/ + + /* Draw the circle outline */ + cv::circle(*imgptr, center, radius, + cv::Scalar(250), 1, 8, 0); + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/src/img_iface.cpp b/modules/image/src/img_iface.cpp index 3bdcf09..c252916 100644 --- a/modules/image/src/img_iface.cpp +++ b/modules/image/src/img_iface.cpp @@ -1,2010 +1,2010 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* errno */
- #include <cerrno>
- /* INFINITY */
- #include <cmath>
- #include <cstddef>
- /* snprintf() */
- #include <cstdio>
-
-/* Standard C++ --------------------------------------------------------------*/
- /* class std::vector */
- #include <vector>
-
-/* Packages ------------------------------------------------------------------*/
- /* openCV */
- #include <opencv2/opencv.hpp>
-
-/* Project -------------------------------------------------------------------*/
- /* load_image_file() */
- #include "save.hpp"
- /* user_iface_log */
- #include "user_iface.hpp"
-
-/* Module --------------------------------------------------------------------*/
- /* img_alx_act() */
- #include "img_alx.hpp"
- /* img_cv_act() */
- #include "img_cv.hpp"
- /* img_orb_act() */
- #include "img_orb.hpp"
- /* img_calib3d_act() */
- #include "img_calib3d.hpp"
- /* img_zb_act() */
- #include "img_zbar.hpp"
- /* img_ocr_act() */
- #include "img_ocr.hpp"
-
- #include "img_iface.hpp"
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
- # define IMG_MEM_SIZE (20)
-
- # define WIN_NAME_IMG "Image"
- # define WIN_NAME_HIST "Hist"
- # define WIN_TIMEOUT (500)
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-/* Global --------------------------------------------------------------------*/
- char img_ocr_text [OCR_TEXT_MAX];
- struct Img_Iface_ZB_Codes zb_codes;
-
-/* Static --------------------------------------------------------------------*/
-static class cv::Mat image_copy_old;
-static class cv::Mat image_copy_tmp;
-static class cv::Mat image_mem [IMG_MEM_SIZE];
-static class cv::Mat image_ref;
-static class cv::Mat histogram_c0;
-static class cv::Mat histogram_c1;
-static class cv::Mat histogram_c2;
-static class cv::Mat hist_img_c1;
-static class cv::Mat hist_img_c3;
-static class std::vector <class std::vector <cv::Point_ <int>>> contours;
-static double area [CONTOURS_MAX];
-static double perimeter [CONTOURS_MAX];
-static class cv::Mat hierarchy;
-static class cv::Rect_ <int> rectangle;
-static class cv::RotatedRect rectangle_rot;
-static class std::vector <class cv::Vec <float, 3>> circles;
-static class cv::Mat intrinsic_mat;
-static class cv::Mat dist_coefs;
-static class std::vector <class cv::Mat> rvecs;
-static class std::vector <class cv::Mat> tvecs;
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
- /* img_alx */
-static void img_iface_local_max (void);
-static void img_iface_skeleton (void);
-static void img_iface_lines_horizontal (void);
-static void img_iface_lines_vertical (void);
-static void img_iface_mean_horizontal (void);
-static void img_iface_mean_vertical (void);
-static void img_iface_median_horizontal (void);
-static void img_iface_median_vertical (void);
-
- /* img_cv */
- /* Core: The core functionality */
- /* Pixel */
-static void img_iface_pixel_get (void *data);
-static void img_iface_pixel_set (void *data);
- /* ROI */
-static void img_iface_set_ROI (void *data);
-static void img_iface_set_ROI_2rect (void *data);
- /* Operations on Arrays */
-static void img_iface_and_2ref (void);
-static void img_iface_not (void);
-static void img_iface_or_2ref (void);
-static void img_iface_component (void *data);
- /* Imgproc: Image processing */
- /* Image filtering */
-static void img_iface_dilate (void *data);
-static void img_iface_erode (void *data);
-static void img_iface_dilate_erode (void *data);
-static void img_iface_erode_dilate (void *data);
-static void img_iface_smooth (void *data);
-static void img_iface_sobel (void *data);
-static void img_iface_border (void *data);
- /* Geometric image transformations */
-static void img_iface_mirror (void *data);
-static void img_iface_rotate_orto (void *data);
-static void img_iface_rotate (void *data);
-static void img_iface_rotate_2rect (void *data);
- /* Miscellaneous image transformations */
-static void img_iface_adaptive_thr (void *data);
-static void img_iface_cvt_color (void *data);
-static void img_iface_distance_transform (void);
-static void img_iface_threshold (void *data);
- /* Histograms */
-static void img_iface_histogram (void *data);
-static void img_iface_histogram_c3 (void *data);
- /* Structural analysis and shape descriptors */
-static void img_iface_contours (void *data);
-static void img_iface_contours_size (void *data);
-static void img_iface_bounding_rect (void *data);
-static void img_iface_fit_ellipse (void *data);
-static void img_iface_min_area_rect (void *data);
- /* Feature detection */
-static void img_iface_hough_circles (void *data);
-
- /* img_orb */
-static void img_iface_align (void);
- /* img_calib3d */
-static void img_iface_calibrate (void *data);
-static void img_iface_undistort (void *data);
-
- /* img_zbar */
-static void img_iface_decode (void *data);
- /* img_ocr */
-static void img_iface_read (void *data);
-
- /* img_iface */
-static void img_iface_apply (void);
-static void img_iface_discard (void);
-static void img_iface_save_mem (void *data);
-static void img_iface_load_mem (void *data);
-static void img_iface_save_ref (void);
- /* save */
-static void img_iface_save_file (void);
-static void img_iface_save_update (void);
-
-
-/******************************************************************************
- ******* global functions *****************************************************
- ******************************************************************************/
-void img_iface_init (void)
-{
- cv::namedWindow(WIN_NAME_HIST, cv::WINDOW_NORMAL);
- cv::namedWindow(WIN_NAME_IMG, cv::WINDOW_NORMAL);
-
- hist_img_c1.release();
- hist_img_c1 = cv::Mat::zeros(cv::Size(256, 100), CV_8UC3);
- hist_img_c3.release();
- hist_img_c3 = cv::Mat::zeros(cv::Size(256 * 3, 100), CV_8UC3);
-}
-
-void img_iface_cleanup_main (void)
-{
- int i;
-
- for (i = 0; i < IMG_MEM_SIZE; i++) {
- image_mem[i].release();
- }
- image_ref.release();
-
- cv::destroyAllWindows();
-}
-
-void img_iface_load (const char *fpath, const char *fname)
-{
- char file_path [FILENAME_MAX];
- char file_name [FILENAME_MAX];
-
- /* Init */
- img_iface_init();
-
- /* Set file_path */
- if (!fpath) {
- snprintf(file_path, FILENAME_MAX, "%s", saved_path);
- } else {
- snprintf(file_path, FILENAME_MAX, "%s", fpath);
- }
-
- /* Set file_name */
- if (!fname) {
- /* Request file name */
- user_iface_fname(file_path, file_name);
- } else {
- snprintf(file_name, FILENAME_MAX, "%s", fname);
- }
-
- /* Load file */
- errno = 0;
- load_image_file(file_path, file_name);
-
- if (!errno) {
- /* Make a static copy of image */
- image.copyTo(image_copy_old);
- image.copyTo(image_copy_tmp);
- }
-}
-
-void img_iface_cleanup (void)
-{
- image_copy_old.release();
- image_copy_tmp.release();
- histogram_c0.release();
- histogram_c1.release();
- histogram_c2.release();
- hist_img_c1.release();
- hist_img_c3.release();
-}
-
-void img_iface_act (int action, void *data)
-{
- switch (action) {
- /* img_alx */
- case IMG_IFACE_ACT_LOCAL_MAX:
- img_iface_local_max();
- break;
- case IMG_IFACE_ACT_SKELETON:
- img_iface_skeleton();
- break;
- case IMG_IFACE_ACT_LINES_HORIZONTAL:
- img_iface_lines_horizontal();
- break;
- case IMG_IFACE_ACT_LINES_VERTICAL:
- img_iface_lines_vertical();
- break;
- case IMG_IFACE_ACT_MEAN_HORIZONTAL:
- img_iface_mean_horizontal();
- break;
- case IMG_IFACE_ACT_MEAN_VERTICAL:
- img_iface_mean_vertical();
- break;
- case IMG_IFACE_ACT_MEDIAN_HORIZONTAL:
- img_iface_median_horizontal();
- break;
- case IMG_IFACE_ACT_MEDIAN_VERTICAL:
- img_iface_median_vertical();
- break;
-
- /* img_cv */
- /* Core: The core functionality */
- /* Pixel */
- case IMG_IFACE_ACT_PIXEL_GET:
- img_iface_pixel_get(data);
- break;
- case IMG_IFACE_ACT_PIXEL_SET:
- img_iface_pixel_set(data);
- break;
- /* ROI */
- case IMG_IFACE_ACT_SET_ROI:
- img_iface_set_ROI(data);
- break;
- case IMG_IFACE_ACT_SET_ROI_2RECT:
- img_iface_set_ROI_2rect(data);
- break;
- /* Operations on Arrays */
- case IMG_IFACE_ACT_AND_2REF:
- img_iface_and_2ref();
- break;
- case IMG_IFACE_ACT_NOT:
- img_iface_not();
- break;
- case IMG_IFACE_ACT_OR_2REF:
- img_iface_or_2ref();
- break;
- case IMG_IFACE_ACT_COMPONENT:
- img_iface_component(data);
- break;
- /* Imgproc: Image processing */
- /* Image filtering */
- case IMG_IFACE_ACT_DILATE:
- img_iface_dilate(data);
- break;
- case IMG_IFACE_ACT_ERODE:
- img_iface_erode(data);
- break;
- case IMG_IFACE_ACT_DILATE_ERODE:
- img_iface_dilate_erode(data);
- break;
- case IMG_IFACE_ACT_ERODE_DILATE:
- img_iface_erode_dilate(data);
- break;
- case IMG_IFACE_ACT_SMOOTH:
- img_iface_smooth(data);
- break;
- case IMG_IFACE_ACT_SOBEL:
- img_iface_sobel(data);
- break;
- case IMG_IFACE_ACT_BORDER:
- img_iface_border(data);
- break;
- /* Geometric image transformations */
- case IMG_IFACE_ACT_MIRROR:
- img_iface_mirror(data);
- break;
- case IMG_IFACE_ACT_ROTATE_ORTO:
- img_iface_rotate_orto(data);
- break;
- case IMG_IFACE_ACT_ROTATE:
- img_iface_rotate(data);
- break;
- case IMG_IFACE_ACT_ROTATE_2RECT:
- img_iface_rotate_2rect(data);
- break;
- /* Miscellaneous image transformations */
- case IMG_IFACE_ACT_ADAPTIVE_THRESHOLD:
- img_iface_adaptive_thr(data);
- break;
- case IMG_IFACE_ACT_CVT_COLOR:
- img_iface_cvt_color(data);
- break;
- case IMG_IFACE_ACT_DISTANCE_TRANSFORM:
- img_iface_distance_transform();
- break;
- case IMG_IFACE_ACT_THRESHOLD:
- img_iface_threshold(data);
- break;
- /* Histograms */
- case IMG_IFACE_ACT_HISTOGRAM:
- img_iface_histogram(data);
- break;
- case IMG_IFACE_ACT_HISTOGRAM_C3:
- img_iface_histogram_c3(data);
- break;
- /* Structural analysis and shape descriptors */
- case IMG_IFACE_ACT_CONTOURS:
- img_iface_contours(data);
- break;
- case IMG_IFACE_ACT_CONTOURS_SIZE:
- img_iface_contours_size(data);
- break;
- case IMG_IFACE_ACT_BOUNDING_RECT:
- img_iface_bounding_rect(data);
- break;
- case IMG_IFACE_ACT_FIT_ELLIPSE:
- img_iface_fit_ellipse(data);
- break;
- case IMG_IFACE_ACT_MIN_AREA_RECT:
- img_iface_min_area_rect(data);
- break;
- /* Feature detection */
- case IMG_IFACE_ACT_HOUGH_CIRCLES:
- img_iface_hough_circles(data);
- break;
-
- /* img_orb */
- case IMG_IFACE_ACT_ALIGN:
- img_iface_align();
- break;
-
- /* img_calib3d */
- case IMG_IFACE_ACT_CALIBRATE:
- img_iface_calibrate(data);
- break;
- case IMG_IFACE_ACT_UNDISTORT:
- img_iface_undistort(data);
- break;
-
- /* img_zbar */
- case IMG_IFACE_ACT_DECODE:
- img_iface_decode(data);
- break;
-
- /* img_ocr */
- case IMG_IFACE_ACT_READ:
- img_iface_read(data);
- break;
-
- /* img_iface */
- case IMG_IFACE_ACT_APPLY:
- img_iface_apply();
- break;
- case IMG_IFACE_ACT_DISCARD:
- img_iface_discard();
- break;
- case IMG_IFACE_ACT_SAVE_MEM:
- img_iface_save_mem(data);
- break;
- case IMG_IFACE_ACT_LOAD_MEM:
- img_iface_load_mem(data);
- break;
- case IMG_IFACE_ACT_SAVE_REF:
- img_iface_save_ref();
- break;
-
- /* save */
- case IMG_IFACE_ACT_SAVE_FILE:
- img_iface_save_file();
- break;
- case IMG_IFACE_ACT_SAVE_UPDT:
- img_iface_save_update();
- break;
-
- default:
- /* Invalid action */
- break;
- }
-}
-
-void img_iface_show_img (void)
-{
- cv::imshow(WIN_NAME_IMG, image_copy_tmp);
- cv::waitKey(WIN_TIMEOUT);
-}
-
-void img_iface_show_hist_c1 (void)
-{
- cv::imshow(WIN_NAME_HIST, hist_img_c1);
- cv::waitKey(WIN_TIMEOUT);
-}
-
-void img_iface_show_hist_c3 (void)
-{
- cv::imshow(WIN_NAME_HIST, hist_img_c3);
- cv::waitKey(WIN_TIMEOUT);
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-/* img_alx --------------------------------------------------------------------*/
-static void img_iface_local_max (void)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Local maxima */
- img_alx_act(&image_copy_tmp, IMG_ALX_ACT_LOCAL_MAX, NULL);
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Local maxima");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-}
-
-static void img_iface_skeleton (void)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Skeleton */
- img_alx_act(&image_copy_tmp, IMG_ALX_ACT_SKELETON, NULL);
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Skeleton");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-}
-
-static void img_iface_lines_horizontal (void)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Horizontal lines */
- img_alx_act(&image_copy_tmp, IMG_ALX_ACT_LINES_HORIZONTAL, NULL);
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Horizontal lines");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-}
-
-static void img_iface_lines_vertical (void)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Vertical lines */
- img_alx_act(&image_copy_tmp, IMG_ALX_ACT_LINES_VERTICAL, NULL);
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Vertical lines");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-}
-
-static void img_iface_mean_horizontal (void)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Horizontal lines */
- img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEAN_HORIZONTAL, NULL);
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Horizontal mean");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-}
-
-static void img_iface_mean_vertical (void)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Horizontal lines */
- img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEAN_VERTICAL, NULL);
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Vertical mean");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-}
-
-static void img_iface_median_horizontal (void)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Horizontal lines */
- img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEDIAN_HORIZONTAL, NULL);
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Horizontal median");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-}
-
-static void img_iface_median_vertical (void)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Horizontal lines */
- img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEDIAN_VERTICAL, NULL);
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Vertical median");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-}
-
-/* img_cv --------------------------------------------------------------------*/
-/* ----- Core: The core functionality */
-/* ----- ------- Pixel */
-static void img_iface_pixel_get (void *data)
-{
- struct Img_Iface_Data_Pixel_Get data_tmp;
- struct Img_Iface_Data_Pixel_Get *data_cast;
- unsigned char val;
- char title [80];
-
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Data */
- if (!data) {
- data_tmp.val = &val;
-
- /* Ask user */
- snprintf(title, 80, "x:");
- data_tmp.x = user_iface_getint(0, 0,
- image_copy_tmp.cols,
- title, NULL);
-
- snprintf(title, 80, "y:");
- data_tmp.y = user_iface_getint(0, 0,
- image_copy_tmp.rows,
- title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Get pixel value */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_PIXEL_GET, data);
-
- /* Write into log */
- data_cast = (struct Img_Iface_Data_Pixel_Get *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Pixel get: (%i, %i): %i",
- data_cast->x,
- data_cast->y,
- *(data_cast->val));
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-}
-
-static void img_iface_pixel_set (void *data)
-{
- struct Img_Iface_Data_Pixel_Set data_tmp;
- struct Img_Iface_Data_Pixel_Set *data_cast;
- char title [80];
-
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Data */
- if (!data) {
- /* Ask user */
- snprintf(title, 80, "x:");
- data_tmp.x = user_iface_getint(0, 0,
- image_copy_tmp.cols,
- title, NULL);
-
- snprintf(title, 80, "y:");
- data_tmp.y = user_iface_getint(0, 0,
- image_copy_tmp.rows,
- title, NULL);
-
- snprintf(title, 80, "val:");
- data_tmp.val = user_iface_getint(0, 0, 255,
- title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Set pixel value */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_PIXEL_SET, data);
-
- /* Write into log */
- data_cast = (struct Img_Iface_Data_Pixel_Set *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Pixel get: (%i, %i): %i",
- data_cast->x,
- data_cast->y,
- data_cast->val);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-}
-
-/* ----- ------- ROI */
-static void img_iface_set_ROI (void *data)
-{
- struct Img_Iface_Data_SetROI data_tmp;
- struct Img_Iface_Data_SetROI *data_cast;
- char title [80];
-
- /* Data */
- if (!data) {
- /* Ask user */
- snprintf(title, 80, "Origin: x:");
- data_tmp.rect.x = user_iface_getint(0, 0,
- image_copy_tmp.cols,
- title, NULL);
-
- snprintf(title, 80, "Origin: y:");
- data_tmp.rect.y = user_iface_getint(0, 0,
- image_copy_tmp.rows,
- title, NULL);
-
- snprintf(title, 80, "Width:");
- data_tmp.rect.width = user_iface_getint(1,
- image_copy_tmp.cols - data_tmp.rect.x,
- image_copy_tmp.cols - data_tmp.rect.x,
- title, NULL);
-
- snprintf(title, 80, "Height:");
- data_tmp.rect.height = user_iface_getint(1,
- image_copy_tmp.rows - data_tmp.rect.y,
- image_copy_tmp.rows - data_tmp.rect.y,
- title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- data_cast = (struct Img_Iface_Data_SetROI *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "ROI: (%i,%i) w=%i,h=%i",
- data_cast->rect.x,
- data_cast->rect.y,
- data_cast->rect.width,
- data_cast->rect.height);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Set ROI */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_SET_ROI, data);
-}
-
-static void img_iface_set_ROI_2rect (void *data)
-{
- struct Img_Iface_Data_SetROI data_tmp;
- struct Img_Iface_Data_SetROI *data_cast;
-
- /* Data */
- if (!data) {
- data_tmp.rect.x = rectangle.x;
- data_tmp.rect.y = rectangle.y;
- data_tmp.rect.width = rectangle.width;
- data_tmp.rect.height = rectangle.height;
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- data_cast = (struct Img_Iface_Data_SetROI *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "ROI: (%i,%i) w=%i,h=%i",
- data_cast->rect.x,
- data_cast->rect.y,
- data_cast->rect.width,
- data_cast->rect.height);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Set ROI */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_SET_ROI, data);
-}
-
-/* ----- ------- Operations on arrays */
-static void img_iface_and_2ref (void)
-{
- /* Must have same channels */
- if (image_copy_tmp.channels() != image_ref.channels()) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Bitwise AND");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Bitwise AND to reference */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_AND_2REF, (void *)&image_ref);
-}
-
-static void img_iface_not (void)
-{
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Invert color");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Bitwise NOT */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_NOT, NULL);
-}
-
-static void img_iface_or_2ref (void)
-{
- /* Must have same channels */
- if (image_copy_tmp.channels() != image_ref.channels()) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Bitwise OR");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Bitwise OR to reference */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_OR_2REF, (void *)&image_ref);
-}
-
-static void img_iface_component (void *data)
-{
- /* Must have at least 3 channels */
- if (image_copy_tmp.channels() < 3) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Data */
- struct Img_Iface_Data_Component data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Component:");
- data_tmp.cmp = user_iface_getint(0, 0,
- image_copy_tmp.channels() - 1,
- title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Component *data_cast;
- data_cast = (struct Img_Iface_Data_Component *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Component %i",
- data_cast->cmp);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Filter: extract component */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_COMPONENT, data);
-}
-
-/* ----- Imgproc: Image processing */
-/* ----- ------- Image filtering */
-static void img_iface_dilate (void *data)
-{
- /* Data */
- struct Img_Iface_Data_Dilate_Erode data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Iterations:");
- data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Dilate_Erode *data_cast;
- data_cast = (struct Img_Iface_Data_Dilate_Erode *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Dilate i=%i",
- data_cast->i);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Dilate */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data);
-}
-
-static void img_iface_erode (void *data)
-{
- /* Data */
- struct Img_Iface_Data_Dilate_Erode data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Iterations:");
- data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Dilate_Erode *data_cast;
- data_cast = (struct Img_Iface_Data_Dilate_Erode *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Erode i=%i",
- data_cast->i);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Erode */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data);
-}
-
-static void img_iface_dilate_erode (void *data)
-{
- /* Data */
- struct Img_Iface_Data_Dilate_Erode data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Iterations:");
- data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Dilate_Erode *data_cast;
- data_cast = (struct Img_Iface_Data_Dilate_Erode *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Dilate-erode i=%i",
- data_cast->i);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Dilate */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data);
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data);
-}
-
-static void img_iface_erode_dilate (void *data)
-{
- /* Data */
- struct Img_Iface_Data_Dilate_Erode data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Iterations:");
- data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Dilate_Erode *data_cast;
- data_cast = (struct Img_Iface_Data_Dilate_Erode *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Erode-dilate i=%i",
- data_cast->i);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Dilate */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data);
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data);
-}
-
-static void img_iface_smooth (void *data)
-{
- /* Data */
- struct Img_Iface_Data_Smooth data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Method: MEAN=1, GAUSS=2, MEDIAN=3");
- data_tmp.method = user_iface_getint(1, 3, 3, title, NULL);
-
- snprintf(title, 80, "Kernel size: 3, 5, 7, ...");
- data_tmp.ksize = user_iface_getint(3, 3, INFINITY, title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Smooth *data_cast;
- data_cast = (struct Img_Iface_Data_Smooth *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Smooth mth=%i [%ix%i]",
- data_cast->method,
- data_cast->ksize,
- data_cast->ksize);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Filter: smooth */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_SMOOTH, data);
-}
-
-static void img_iface_sobel (void *data)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Data */
- struct Img_Iface_Data_Sobel data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Order of the derivative x");
- data_tmp.dx = user_iface_getint(0, 1, 10, title, NULL);
-
- snprintf(title, 80, "Order of the derivative y");
- data_tmp.dy = user_iface_getint(0, 1, 10, title, NULL);
-
- snprintf(title, 80, "Size of the extended Sobel kernel (-1 -> Scharr");
- data_tmp.ksize = user_iface_getint(-1, 3, 7, title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Sobel *data_cast;
- data_cast = (struct Img_Iface_Data_Sobel *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Sobel dx=%i;dy=%i [ks=%i]",
- data_cast->dx,
- data_cast->dy,
- data_cast->ksize);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Filter: sobel */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_SOBEL, data);
-}
-
-static void img_iface_border (void *data)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Data */
- struct Img_Iface_Data_Border data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Size");
- data_tmp.size = user_iface_getint(1, 1, 0xF000, title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Border *data_cast;
- data_cast = (struct Img_Iface_Data_Border *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Border size=%i",
- data_cast->size);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Add border */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_BORDER, data);
-}
-
-/* ----- ------- Geometric image transformations */
-static void img_iface_mirror (void *data)
-{
- /* Data */
- struct Img_Iface_Data_Mirror data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Axis: 0=x; 1=y");
- data_tmp.axis = user_iface_getint(0, 1, 1, title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Mirror *data_cast;
- data_cast = (struct Img_Iface_Data_Mirror *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Mirror axis: %i",
- data_cast->axis);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Mirror */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_MIRROR, data);
-}
-
-static void img_iface_rotate_orto (void *data)
-{
- /* Data */
- struct Img_Iface_Data_Rotate_Orto data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Rotate (counterclockwise) n * pi/2 rad; n:");
- data_tmp.n = user_iface_getint(1, 1, 3, title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Rotate_Orto *data_cast;
- data_cast = (struct Img_Iface_Data_Rotate_Orto *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Rotate %i * pi/2 rad",
- data_cast->n);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Rotate ortogonally */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE_ORTO, data);
-}
-
-static void img_iface_rotate (void *data)
-{
- /* Data */
- struct Img_Iface_Data_Rotate data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Center: x:");
- data_tmp.center.x = user_iface_getdbl(0, 0, INFINITY, title, NULL);
-
- snprintf(title, 80, "Center: y:");
- data_tmp.center.y = user_iface_getdbl(0, 0, INFINITY, title, NULL);
-
- snprintf(title, 80, "Angle: (deg)");
- data_tmp.angle = user_iface_getdbl(-INFINITY, 0, INFINITY, title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Rotate *data_cast;
- data_cast = (struct Img_Iface_Data_Rotate *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Rotate (%.2f,%.2f) %lfº",
- data_cast->center.x,
- data_cast->center.y,
- data_cast->angle);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Rotate ortogonally */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE, data);
-}
-
-static void img_iface_rotate_2rect (void *data)
-{
- /* Data */
- struct Img_Iface_Data_Rotate data_tmp;
- if (!data) {
- data_tmp.center.x = rectangle_rot.center.x;
- data_tmp.center.y = rectangle_rot.center.y;
- data_tmp.angle = rectangle_rot.angle;
-
- /* If angle is < -45º, it is taking into acount the incorrect side */
- if (data_tmp.angle < -45.0) {
- data_tmp.angle += 90.0;
- }
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Rotate to rectangle");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Rotate ortogonally */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE, data);
-}
-
-/* ----- ------- Miscellaneous image transformations */
-static void img_iface_adaptive_thr (void *data)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Data */
- struct Img_Iface_Data_Adaptive_Thr data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Method: MEAN=0, GAUSS=1");
- data_tmp.method = user_iface_getint(0, 1, 1, title, NULL);
-
- snprintf(title, 80, "Type: BIN=0, BIN_INV=1");
- data_tmp.thr_typ = user_iface_getint(0, 0, 1, title, NULL);
-
- snprintf(title, 80, "Kernel size: 3, 5, 7, ...");
- data_tmp.ksize = user_iface_getint(3, 3, INFINITY, title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Adaptive_Thr *data_cast;
- data_cast = (struct Img_Iface_Data_Adaptive_Thr *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Threshold mth=%i, typ=%i, ks=%i",
- data_cast->method,
- data_cast->thr_typ,
- data_cast->ksize);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Filter: adaptive threshold */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_ADAPTIVE_THRESHOLD, data);
-}
-
-static void img_iface_cvt_color (void *data)
-{
- /* Must have at least 3 channels */
- if (image_copy_tmp.channels() < 3) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Data */
- struct Img_Iface_Data_Cvt_Color data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Method: BGR2GRAY = 6, BGR2HSV = 40");
- data_tmp.method = user_iface_getint(0, 0,
- cv::COLOR_COLORCVT_MAX,
- title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Cvt_Color *data_cast;
- data_cast = (struct Img_Iface_Data_Cvt_Color *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Convert color %i",
- data_cast->method);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Filter: BGR to gray */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_CVT_COLOR, data);
-}
-
-static void img_iface_distance_transform (void)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Distance transform");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Distance transform */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_DISTANCE_TRANSFORM, NULL);
-}
-
-static void img_iface_threshold (void *data)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Data */
- struct Img_Iface_Data_Threshold data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Type: BIN=0, BIN_INV=1, TRUNC=2, TOZ=3, TOZ_INV=4");
- data_tmp.thr_typ = user_iface_getint(0, 0, 4, title, NULL);
-
- snprintf(title, 80, "Value: 0 to 255 (or -1 for Otsu's algorithm)");
- data_tmp.thr_val = user_iface_getint(-1, 0, 255, title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Threshold *data_cast;
- data_cast = (struct Img_Iface_Data_Threshold *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Threshold typ=%i, val=%i",
- data_cast->thr_typ,
- data_cast->thr_val);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Filter: threshold */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_THRESHOLD, data);
-}
-
-/* ----- ------- Histograms */
-static void img_iface_histogram (void *data)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Data */
- struct Img_Iface_Data_Histogram data_tmp;
- if (!data) {
- data_tmp.hist_c0 = &histogram_c0;
- data_tmp.hist_img = &hist_img_c1;
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Histogram");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Histogram */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_HISTOGRAM, data);
-}
-
-static void img_iface_histogram_c3 (void *data)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 3) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Data */
- struct Img_Iface_Data_Histogram data_tmp;
- if (!data) {
- data_tmp.hist_c0 = &histogram_c0;
- data_tmp.hist_c1 = &histogram_c1;
- data_tmp.hist_c2 = &histogram_c2;
- data_tmp.hist_img = &hist_img_c3;
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Histogram (3 channels)");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Histogram */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_HISTOGRAM_C3, data);
-}
-
-/* ----- ------- Structural analysis and shape descriptors */
-static void img_iface_contours (void *data)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Data */
- struct Img_Iface_Data_Contours data_tmp;
- if (!data) {
- data_tmp.contours = &contours;
- data_tmp.hierarchy = &hierarchy;
-
- data = (void *)&data_tmp;
- }
-
- /* Contours */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_CONTOURS, data);
-
- /* Write into log */
- struct Img_Iface_Data_Contours *data_cast;
- data_cast = (struct Img_Iface_Data_Contours *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Contours n=%i",
- (int)data_cast->contours->size());
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-}
-
-static void img_iface_contours_size (void *data)
-{
- /* Data */
- struct Img_Iface_Data_Contours_Size data_tmp;
- if (!data) {
- data_tmp.contours = &contours;
- data_tmp.area = area;
- data_tmp.perimeter = perimeter;
-
- data = (void *)&data_tmp;
- }
-
- /* Contours size */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_CONTOURS_SIZE, data);
-
- /* Write into log */
- struct Img_Iface_Data_Contours_Size *data_cast;
- data_cast = (struct Img_Iface_Data_Contours_Size *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Contours size:");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
- int i;
- for (i = 0; i < (int)data_cast->contours->size(); i++) {
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "cnt[%i]: A=%lf; P=%lf;",
- i,
- data_cast->area[i],
- data_cast->perimeter[i]);
- user_iface_log.lvl[user_iface_log.len] = 2;
- (user_iface_log.len)++;
- }
-}
-
-static void img_iface_bounding_rect (void *data)
-{
- /* Data */
- struct Img_Iface_Data_Bounding_Rect data_tmp;
- if (!data) {
- if(!contours.size()) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len],
- LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
- data_tmp.contour = &(contours[0]);
- data_tmp.rect = &rectangle;
- data_tmp.show = true;
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Bounding rectangle");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Enclosing rectangle */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_BOUNDING_RECT, data);
-}
-
-static void img_iface_fit_ellipse (void *data)
-{
- /* Data */
- struct Img_Iface_Data_MinARect data_tmp;
- if (!data) {
- if(!contours.size()) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len],
- LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
- data_tmp.contour = &(contours[0]);
-
- data_tmp.rect = &rectangle_rot;
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Fit ellipse");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Enclosing rectangle */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_FIT_ELLIPSE, data);
-}
-
-static void img_iface_min_area_rect (void *data)
-{
- /* Data */
- struct Img_Iface_Data_MinARect data_tmp;
- if (!data) {
- if(!contours.size()) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len],
- LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
- data_tmp.contour = &(contours[0]);
- data_tmp.rect = &rectangle_rot;
- data_tmp.show = true;
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Min area rectangle");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Enclosing rectangle */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_MIN_AREA_RECT, data);
-}
-
-/* ----- ------- Feature detection */
-static void img_iface_hough_circles (void *data)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Data */
- struct Img_Iface_Data_Hough_Circles data_tmp;
- if (!data) {
- data_tmp.circles = &circles;
-
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Minimum distance:");
- data_tmp.dist_min = user_iface_getdbl(0, 5, INFINITY, title, NULL);
-
- snprintf(title, 80, "param 1:");
- data_tmp.param_1 = user_iface_getdbl(0, 200, INFINITY, title, NULL);
-
- snprintf(title, 80, "param 2:");
- data_tmp.param_2 = user_iface_getdbl(0, 100, INFINITY, title, NULL);
-
- snprintf(title, 80, "Minimum radius");
- data_tmp.radius_min = user_iface_getint(0, 10, INFINITY, title, NULL);
-
- snprintf(title, 80, "Maximum radius");
- data_tmp.radius_max = user_iface_getint(0, 0, INFINITY, title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Circles */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_HOUGH_CIRCLES, data);
-
- /* Write into log */
- struct Img_Iface_Data_Hough_Circles *data_cast;
- data_cast = (struct Img_Iface_Data_Hough_Circles *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Circles n=%i",
- (int)data_cast->circles->size());
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-}
-
-/* img_orb -------------------------------------------------------------------*/
-static void img_iface_align (void)
-{
- /* Must have defined a reference */
- if (image_ref.empty()) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Reference is NULL");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Align to reference");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Align to reference image_ref */
- img_orb_act(&image_ref, &image_copy_tmp, IMG_ORB_ACT_ALIGN);
-}
-
-/* img_calib3d ---------------------------------------------------------------*/
-static void img_iface_calibrate (void *data)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Data */
- struct Img_Iface_Data_Calibrate data_tmp;
- if (!data) {
- data_tmp.intrinsic_mat = &intrinsic_mat;
- data_tmp.dist_coefs = &dist_coefs;
- data_tmp.rvecs = &rvecs;
- data_tmp.tvecs = &tvecs;
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Calibrate");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Contours */
- img_calib3d_act(&image_copy_tmp, IMG_CALIB3D_ACT_CALIBRATE, data);
-}
-
-static void img_iface_undistort (void *data)
-{
- /* Data */
- struct Img_Iface_Data_Undistort data_tmp;
- if (!data) {
- data_tmp.intrinsic_mat = &intrinsic_mat;
- data_tmp.dist_coefs = &dist_coefs;
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Undistort");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Contours */
- img_calib3d_act(&image_copy_tmp, IMG_CALIB3D_ACT_UNDISTORT, data);
-}
-
-/* img_zbar ------------------------------------------------------------------*/
-static void img_iface_decode (void *data)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Data */
- struct Img_Iface_Data_Decode data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Type of code: (0 for all)");
- data_tmp.code_type = (enum zbar::zbar_symbol_type_e)
- user_iface_getint(0, 0, INT_MAX,
- title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Decode *data_cast;
- data_cast = (struct Img_Iface_Data_Decode *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Detect codes c=%i",
- data_cast->code_type);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Decode */
- img_zb_act(&image_copy_tmp, IMG_ZB_ACT_DECODE, data);
-
- /* Results */
- if (!zb_codes.n) {
- /* No text found */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! No code detected");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
- } else {
- /* Write results into log */
- int i;
- for (i = 0; i < zb_codes.n; i++) {
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "%s -- '%s'",
- zb_codes.arr[i].sym_name,
- zb_codes.arr[i].data);
- user_iface_log.lvl[user_iface_log.len] = 2;
- (user_iface_log.len)++;
- }
- }
-}
-
-/* img_ocr -------------------------------------------------------------------*/
-static void img_iface_read (void *data)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Data */
- struct Img_Iface_Data_Read data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Language: ENG = 0, SPA = 1, CAT = 2");
- data_tmp.lang = user_iface_getint(0, 1, 2, title, NULL);
-
- snprintf(title, 80, "Config: none = 0, Price = 1");
- data_tmp.conf = user_iface_getint(0, 1, 2, title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Read *data_cast;
- data_cast = (struct Img_Iface_Data_Read *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "OCR (lang=%i) [c=%i]",
- data_cast->lang,
- data_cast->conf);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Adapt image data */
- data_cast->img.data = image_copy_tmp.data;
- data_cast->img.width = image_copy_tmp.size().width;
- data_cast->img.height = image_copy_tmp.size().height;
- data_cast->img.B_per_pix = image_copy_tmp.channels();
- data_cast->img.B_per_line = image_copy_tmp.step1();
-
- /* OCR */
- img_ocr_act(IMG_OCR_ACT_READ, data);
-
- /* Results */
- if (img_ocr_text[0] == '\0') {
- /* No text found */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! No text detected");
- user_iface_log.lvl[user_iface_log.len] = 2;
- (user_iface_log.len)++;
- }
-}
-
-/* img_iface -----------------------------------------------------------------*/
-static void img_iface_apply (void)
-{
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Apply changes");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Write tmp into old */
- image_copy_old.release();
- image_copy_tmp.copyTo(image_copy_old);
-}
-
-static void img_iface_discard (void)
-{
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Discard changes");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Discard tmp image copy */
- image_copy_tmp.release();
- image_copy_old.copyTo(image_copy_tmp);
-}
-
-static void img_iface_save_mem (void *data)
-{
- /* Which memory to use */
- int x;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "mem_X; X:");
- x = user_iface_getint(0, 0, IMG_MEM_SIZE - 1, title, NULL);
- } else {
- x = *(int *)data;
- }
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Save to mem_%i", x);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Write into mem */
- image_mem[x].release();
- image_copy_tmp.copyTo(image_mem[x]);
-}
-
-static void img_iface_load_mem (void *data)
-{
- /* Which memory to use */
- int x;
- if (!data) {
- /* Ask user which memory to use */
- char title [80];
- snprintf(title, 80, "mem_X; X:");
- x = user_iface_getint(0, 0, IMG_MEM_SIZE - 1, title, NULL);
- } else {
- x = *(int *)data;
- }
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Load from mem_%i", x);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- if (!image_mem[x].empty()) {
- /* Discard tmp image copy */
- image_copy_tmp.release();
-
- /* Load from mem */
- image_mem[x].copyTo(image_copy_tmp);
- }
-}
-
-static void img_iface_save_ref (void)
-{
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Save to reference");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Write into ref */
- image_ref.release();
- image_copy_tmp.copyTo(image_ref);
- image_ref = image_copy_tmp;
-}
-
-/* save ----------------------------------------------------------------------*/
-static void img_iface_save_file (void)
-{
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Save as...");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Write into image struct (save.c) */
- image.release();
- image_copy_tmp.copyTo(image);
-
- /* Save into file */
- save_image_file(NULL, NULL);
-}
-
-static void img_iface_save_update (void)
-{
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Save: update img");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Write into image struct (save.c) */
- image.release();
- image_copy_tmp.copyTo(image);
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* errno */ + #include <cerrno> + /* INFINITY */ + #include <cmath> + #include <cstddef> + /* snprintf() */ + #include <cstdio> + +/* Standard C++ --------------------------------------------------------------*/ + /* class std::vector */ + #include <vector> + +/* Packages ------------------------------------------------------------------*/ + /* openCV */ + #include <opencv2/opencv.hpp> + +/* Project -------------------------------------------------------------------*/ + /* load_image_file() */ + #include "save.hpp" + /* user_iface_log */ + #include "user_iface.hpp" + +/* Module --------------------------------------------------------------------*/ + /* img_alx_act() */ + #include "img_alx.hpp" + /* img_cv_act() */ + #include "img_cv.hpp" + /* img_orb_act() */ + #include "img_orb.hpp" + /* img_calib3d_act() */ + #include "img_calib3d.hpp" + /* img_zb_act() */ + #include "img_zbar.hpp" + /* img_ocr_act() */ + #include "img_ocr.hpp" + + #include "img_iface.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define IMG_MEM_SIZE (20) + + # define WIN_NAME_IMG "Image" + # define WIN_NAME_HIST "Hist" + # define WIN_TIMEOUT (500) + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ + char img_ocr_text [OCR_TEXT_MAX]; + struct Img_Iface_ZB_Codes zb_codes; + +/* Static --------------------------------------------------------------------*/ +static class cv::Mat image_copy_old; +static class cv::Mat image_copy_tmp; +static class cv::Mat image_mem [IMG_MEM_SIZE]; +static class cv::Mat image_ref; +static class cv::Mat histogram_c0; +static class cv::Mat histogram_c1; +static class cv::Mat histogram_c2; +static class cv::Mat hist_img_c1; +static class cv::Mat hist_img_c3; +static class std::vector <class std::vector <cv::Point_ <int>>> contours; +static double area [CONTOURS_MAX]; +static double perimeter [CONTOURS_MAX]; +static class cv::Mat hierarchy; +static class cv::Rect_ <int> rectangle; +static class cv::RotatedRect rectangle_rot; +static class std::vector <class cv::Vec <float, 3>> circles; +static class cv::Mat intrinsic_mat; +static class cv::Mat dist_coefs; +static class std::vector <class cv::Mat> rvecs; +static class std::vector <class cv::Mat> tvecs; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ + /* img_alx */ +static void img_iface_local_max (void); +static void img_iface_skeleton (void); +static void img_iface_lines_horizontal (void); +static void img_iface_lines_vertical (void); +static void img_iface_mean_horizontal (void); +static void img_iface_mean_vertical (void); +static void img_iface_median_horizontal (void); +static void img_iface_median_vertical (void); + + /* img_cv */ + /* Core: The core functionality */ + /* Pixel */ +static void img_iface_pixel_get (void *data); +static void img_iface_pixel_set (void *data); + /* ROI */ +static void img_iface_set_ROI (void *data); +static void img_iface_set_ROI_2rect (void *data); + /* Operations on Arrays */ +static void img_iface_and_2ref (void); +static void img_iface_not (void); +static void img_iface_or_2ref (void); +static void img_iface_component (void *data); + /* Imgproc: Image processing */ + /* Image filtering */ +static void img_iface_dilate (void *data); +static void img_iface_erode (void *data); +static void img_iface_dilate_erode (void *data); +static void img_iface_erode_dilate (void *data); +static void img_iface_smooth (void *data); +static void img_iface_sobel (void *data); +static void img_iface_border (void *data); + /* Geometric image transformations */ +static void img_iface_mirror (void *data); +static void img_iface_rotate_orto (void *data); +static void img_iface_rotate (void *data); +static void img_iface_rotate_2rect (void *data); + /* Miscellaneous image transformations */ +static void img_iface_adaptive_thr (void *data); +static void img_iface_cvt_color (void *data); +static void img_iface_distance_transform (void); +static void img_iface_threshold (void *data); + /* Histograms */ +static void img_iface_histogram (void *data); +static void img_iface_histogram_c3 (void *data); + /* Structural analysis and shape descriptors */ +static void img_iface_contours (void *data); +static void img_iface_contours_size (void *data); +static void img_iface_bounding_rect (void *data); +static void img_iface_fit_ellipse (void *data); +static void img_iface_min_area_rect (void *data); + /* Feature detection */ +static void img_iface_hough_circles (void *data); + + /* img_orb */ +static void img_iface_align (void); + /* img_calib3d */ +static void img_iface_calibrate (void *data); +static void img_iface_undistort (void *data); + + /* img_zbar */ +static void img_iface_decode (void *data); + /* img_ocr */ +static void img_iface_read (void *data); + + /* img_iface */ +static void img_iface_apply (void); +static void img_iface_discard (void); +static void img_iface_save_mem (void *data); +static void img_iface_load_mem (void *data); +static void img_iface_save_ref (void); + /* save */ +static void img_iface_save_file (void); +static void img_iface_save_update (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void img_iface_init (void) +{ + cv::namedWindow(WIN_NAME_HIST, cv::WINDOW_NORMAL); + cv::namedWindow(WIN_NAME_IMG, cv::WINDOW_NORMAL); + + hist_img_c1.release(); + hist_img_c1 = cv::Mat::zeros(cv::Size(256, 100), CV_8UC3); + hist_img_c3.release(); + hist_img_c3 = cv::Mat::zeros(cv::Size(256 * 3, 100), CV_8UC3); +} + +void img_iface_cleanup_main (void) +{ + int i; + + for (i = 0; i < IMG_MEM_SIZE; i++) { + image_mem[i].release(); + } + image_ref.release(); + + cv::destroyAllWindows(); +} + +void img_iface_load (const char *fpath, const char *fname) +{ + char file_path [FILENAME_MAX]; + char file_name [FILENAME_MAX]; + + /* Init */ + img_iface_init(); + + /* Set file_path */ + if (!fpath) { + snprintf(file_path, FILENAME_MAX, "%s", saved_path); + } else { + snprintf(file_path, FILENAME_MAX, "%s", fpath); + } + + /* Set file_name */ + if (!fname) { + /* Request file name */ + user_iface_fname(file_path, file_name); + } else { + snprintf(file_name, FILENAME_MAX, "%s", fname); + } + + /* Load file */ + errno = 0; + load_image_file(file_path, file_name); + + if (!errno) { + /* Make a static copy of image */ + image.copyTo(image_copy_old); + image.copyTo(image_copy_tmp); + } +} + +void img_iface_cleanup (void) +{ + image_copy_old.release(); + image_copy_tmp.release(); + histogram_c0.release(); + histogram_c1.release(); + histogram_c2.release(); + hist_img_c1.release(); + hist_img_c3.release(); +} + +void img_iface_act (int action, void *data) +{ + switch (action) { + /* img_alx */ + case IMG_IFACE_ACT_LOCAL_MAX: + img_iface_local_max(); + break; + case IMG_IFACE_ACT_SKELETON: + img_iface_skeleton(); + break; + case IMG_IFACE_ACT_LINES_HORIZONTAL: + img_iface_lines_horizontal(); + break; + case IMG_IFACE_ACT_LINES_VERTICAL: + img_iface_lines_vertical(); + break; + case IMG_IFACE_ACT_MEAN_HORIZONTAL: + img_iface_mean_horizontal(); + break; + case IMG_IFACE_ACT_MEAN_VERTICAL: + img_iface_mean_vertical(); + break; + case IMG_IFACE_ACT_MEDIAN_HORIZONTAL: + img_iface_median_horizontal(); + break; + case IMG_IFACE_ACT_MEDIAN_VERTICAL: + img_iface_median_vertical(); + break; + + /* img_cv */ + /* Core: The core functionality */ + /* Pixel */ + case IMG_IFACE_ACT_PIXEL_GET: + img_iface_pixel_get(data); + break; + case IMG_IFACE_ACT_PIXEL_SET: + img_iface_pixel_set(data); + break; + /* ROI */ + case IMG_IFACE_ACT_SET_ROI: + img_iface_set_ROI(data); + break; + case IMG_IFACE_ACT_SET_ROI_2RECT: + img_iface_set_ROI_2rect(data); + break; + /* Operations on Arrays */ + case IMG_IFACE_ACT_AND_2REF: + img_iface_and_2ref(); + break; + case IMG_IFACE_ACT_NOT: + img_iface_not(); + break; + case IMG_IFACE_ACT_OR_2REF: + img_iface_or_2ref(); + break; + case IMG_IFACE_ACT_COMPONENT: + img_iface_component(data); + break; + /* Imgproc: Image processing */ + /* Image filtering */ + case IMG_IFACE_ACT_DILATE: + img_iface_dilate(data); + break; + case IMG_IFACE_ACT_ERODE: + img_iface_erode(data); + break; + case IMG_IFACE_ACT_DILATE_ERODE: + img_iface_dilate_erode(data); + break; + case IMG_IFACE_ACT_ERODE_DILATE: + img_iface_erode_dilate(data); + break; + case IMG_IFACE_ACT_SMOOTH: + img_iface_smooth(data); + break; + case IMG_IFACE_ACT_SOBEL: + img_iface_sobel(data); + break; + case IMG_IFACE_ACT_BORDER: + img_iface_border(data); + break; + /* Geometric image transformations */ + case IMG_IFACE_ACT_MIRROR: + img_iface_mirror(data); + break; + case IMG_IFACE_ACT_ROTATE_ORTO: + img_iface_rotate_orto(data); + break; + case IMG_IFACE_ACT_ROTATE: + img_iface_rotate(data); + break; + case IMG_IFACE_ACT_ROTATE_2RECT: + img_iface_rotate_2rect(data); + break; + /* Miscellaneous image transformations */ + case IMG_IFACE_ACT_ADAPTIVE_THRESHOLD: + img_iface_adaptive_thr(data); + break; + case IMG_IFACE_ACT_CVT_COLOR: + img_iface_cvt_color(data); + break; + case IMG_IFACE_ACT_DISTANCE_TRANSFORM: + img_iface_distance_transform(); + break; + case IMG_IFACE_ACT_THRESHOLD: + img_iface_threshold(data); + break; + /* Histograms */ + case IMG_IFACE_ACT_HISTOGRAM: + img_iface_histogram(data); + break; + case IMG_IFACE_ACT_HISTOGRAM_C3: + img_iface_histogram_c3(data); + break; + /* Structural analysis and shape descriptors */ + case IMG_IFACE_ACT_CONTOURS: + img_iface_contours(data); + break; + case IMG_IFACE_ACT_CONTOURS_SIZE: + img_iface_contours_size(data); + break; + case IMG_IFACE_ACT_BOUNDING_RECT: + img_iface_bounding_rect(data); + break; + case IMG_IFACE_ACT_FIT_ELLIPSE: + img_iface_fit_ellipse(data); + break; + case IMG_IFACE_ACT_MIN_AREA_RECT: + img_iface_min_area_rect(data); + break; + /* Feature detection */ + case IMG_IFACE_ACT_HOUGH_CIRCLES: + img_iface_hough_circles(data); + break; + + /* img_orb */ + case IMG_IFACE_ACT_ALIGN: + img_iface_align(); + break; + + /* img_calib3d */ + case IMG_IFACE_ACT_CALIBRATE: + img_iface_calibrate(data); + break; + case IMG_IFACE_ACT_UNDISTORT: + img_iface_undistort(data); + break; + + /* img_zbar */ + case IMG_IFACE_ACT_DECODE: + img_iface_decode(data); + break; + + /* img_ocr */ + case IMG_IFACE_ACT_READ: + img_iface_read(data); + break; + + /* img_iface */ + case IMG_IFACE_ACT_APPLY: + img_iface_apply(); + break; + case IMG_IFACE_ACT_DISCARD: + img_iface_discard(); + break; + case IMG_IFACE_ACT_SAVE_MEM: + img_iface_save_mem(data); + break; + case IMG_IFACE_ACT_LOAD_MEM: + img_iface_load_mem(data); + break; + case IMG_IFACE_ACT_SAVE_REF: + img_iface_save_ref(); + break; + + /* save */ + case IMG_IFACE_ACT_SAVE_FILE: + img_iface_save_file(); + break; + case IMG_IFACE_ACT_SAVE_UPDT: + img_iface_save_update(); + break; + + default: + /* Invalid action */ + break; + } +} + +void img_iface_show_img (void) +{ + cv::imshow(WIN_NAME_IMG, image_copy_tmp); + cv::waitKey(WIN_TIMEOUT); +} + +void img_iface_show_hist_c1 (void) +{ + cv::imshow(WIN_NAME_HIST, hist_img_c1); + cv::waitKey(WIN_TIMEOUT); +} + +void img_iface_show_hist_c3 (void) +{ + cv::imshow(WIN_NAME_HIST, hist_img_c3); + cv::waitKey(WIN_TIMEOUT); +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +/* img_alx --------------------------------------------------------------------*/ +static void img_iface_local_max (void) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! Invalid input"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + return; + } + + /* Local maxima */ + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_LOCAL_MAX, NULL); + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Local maxima"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +static void img_iface_skeleton (void) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! Invalid input"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + return; + } + + /* Skeleton */ + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_SKELETON, NULL); + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Skeleton"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +static void img_iface_lines_horizontal (void) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! Invalid input"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + return; + } + + /* Horizontal lines */ + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_LINES_HORIZONTAL, NULL); + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Horizontal lines"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +static void img_iface_lines_vertical (void) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! Invalid input"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + return; + } + + /* Vertical lines */ + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_LINES_VERTICAL, NULL); + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Vertical lines"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +static void img_iface_mean_horizontal (void) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! Invalid input"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + return; + } + + /* Horizontal lines */ + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEAN_HORIZONTAL, NULL); + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Horizontal mean"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +static void img_iface_mean_vertical (void) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! Invalid input"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + return; + } + + /* Horizontal lines */ + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEAN_VERTICAL, NULL); + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Vertical mean"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +static void img_iface_median_horizontal (void) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! Invalid input"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + return; + } + + /* Horizontal lines */ + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEDIAN_HORIZONTAL, NULL); + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Horizontal median"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +static void img_iface_median_vertical (void) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! Invalid input"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + return; + } + + /* Horizontal lines */ + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEDIAN_VERTICAL, NULL); + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Vertical median"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +/* img_cv --------------------------------------------------------------------*/ +/* ----- Core: The core functionality */ +/* ----- ------- Pixel */ +static void img_iface_pixel_get (void *data) +{ + struct Img_Iface_Data_Pixel_Get data_tmp; + struct Img_Iface_Data_Pixel_Get *data_cast; + unsigned char val; + char title [80]; + + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! Invalid input"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + return; + } + + /* Data */ + if (!data) { + data_tmp.val = &val; + + /* Ask user */ + snprintf(title, 80, "x:"); + data_tmp.x = user_iface_getint(0, 0, + image_copy_tmp.cols, + title, NULL); + + snprintf(title, 80, "y:"); + data_tmp.y = user_iface_getint(0, 0, + image_copy_tmp.rows, + title, NULL); + + data = (void *)&data_tmp; + } + + /* Get pixel value */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_PIXEL_GET, data); + + /* Write into log */ + data_cast = (struct Img_Iface_Data_Pixel_Get *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Pixel get: (%i, %i): %i", + data_cast->x, + data_cast->y, + *(data_cast->val)); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +static void img_iface_pixel_set (void *data) +{ + struct Img_Iface_Data_Pixel_Set data_tmp; + struct Img_Iface_Data_Pixel_Set *data_cast; + char title [80]; + + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! Invalid input"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + return; + } + + /* Data */ + if (!data) { + /* Ask user */ + snprintf(title, 80, "x:"); + data_tmp.x = user_iface_getint(0, 0, + image_copy_tmp.cols, + title, NULL); + + snprintf(title, 80, "y:"); + data_tmp.y = user_iface_getint(0, 0, + image_copy_tmp.rows, + title, NULL); + + snprintf(title, 80, "val:"); + data_tmp.val = user_iface_getint(0, 0, 255, + title, NULL); + + data = (void *)&data_tmp; + } + + /* Set pixel value */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_PIXEL_SET, data); + + /* Write into log */ + data_cast = (struct Img_Iface_Data_Pixel_Set *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Pixel get: (%i, %i): %i", + data_cast->x, + data_cast->y, + data_cast->val); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +/* ----- ------- ROI */ +static void img_iface_set_ROI (void *data) +{ + struct Img_Iface_Data_SetROI data_tmp; + struct Img_Iface_Data_SetROI *data_cast; + char title [80]; + + /* Data */ + if (!data) { + /* Ask user */ + snprintf(title, 80, "Origin: x:"); + data_tmp.rect.x = user_iface_getint(0, 0, + image_copy_tmp.cols, + title, NULL); + + snprintf(title, 80, "Origin: y:"); + data_tmp.rect.y = user_iface_getint(0, 0, + image_copy_tmp.rows, + title, NULL); + + snprintf(title, 80, "Width:"); + data_tmp.rect.width = user_iface_getint(1, + image_copy_tmp.cols - data_tmp.rect.x, + image_copy_tmp.cols - data_tmp.rect.x, + title, NULL); + + snprintf(title, 80, "Height:"); + data_tmp.rect.height = user_iface_getint(1, + image_copy_tmp.rows - data_tmp.rect.y, + image_copy_tmp.rows - data_tmp.rect.y, + title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + data_cast = (struct Img_Iface_Data_SetROI *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "ROI: (%i,%i) w=%i,h=%i", + data_cast->rect.x, + data_cast->rect.y, + data_cast->rect.width, + data_cast->rect.height); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Set ROI */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_SET_ROI, data); +} + +static void img_iface_set_ROI_2rect (void *data) +{ + struct Img_Iface_Data_SetROI data_tmp; + struct Img_Iface_Data_SetROI *data_cast; + + /* Data */ + if (!data) { + data_tmp.rect.x = rectangle.x; + data_tmp.rect.y = rectangle.y; + data_tmp.rect.width = rectangle.width; + data_tmp.rect.height = rectangle.height; + + data = (void *)&data_tmp; + } + + /* Write into log */ + data_cast = (struct Img_Iface_Data_SetROI *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "ROI: (%i,%i) w=%i,h=%i", + data_cast->rect.x, + data_cast->rect.y, + data_cast->rect.width, + data_cast->rect.height); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Set ROI */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_SET_ROI, data); +} + +/* ----- ------- Operations on arrays */ +static void img_iface_and_2ref (void) +{ + /* Must have same channels */ + if (image_copy_tmp.channels() != image_ref.channels()) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! Invalid input"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + return; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Bitwise AND"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Bitwise AND to reference */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_AND_2REF, (void *)&image_ref); +} + +static void img_iface_not (void) +{ + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Invert color"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Bitwise NOT */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_NOT, NULL); +} + +static void img_iface_or_2ref (void) +{ + /* Must have same channels */ + if (image_copy_tmp.channels() != image_ref.channels()) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! Invalid input"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + return; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Bitwise OR"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Bitwise OR to reference */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_OR_2REF, (void *)&image_ref); +} + +static void img_iface_component (void *data) +{ + /* Must have at least 3 channels */ + if (image_copy_tmp.channels() < 3) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! Invalid input"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + return; + } + + /* Data */ + struct Img_Iface_Data_Component data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Component:"); + data_tmp.cmp = user_iface_getint(0, 0, + image_copy_tmp.channels() - 1, + title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Component *data_cast; + data_cast = (struct Img_Iface_Data_Component *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Component %i", + data_cast->cmp); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Filter: extract component */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_COMPONENT, data); +} + +/* ----- Imgproc: Image processing */ +/* ----- ------- Image filtering */ +static void img_iface_dilate (void *data) +{ + /* Data */ + struct Img_Iface_Data_Dilate_Erode data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Iterations:"); + data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Dilate_Erode *data_cast; + data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Dilate i=%i", + data_cast->i); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Dilate */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data); +} + +static void img_iface_erode (void *data) +{ + /* Data */ + struct Img_Iface_Data_Dilate_Erode data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Iterations:"); + data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Dilate_Erode *data_cast; + data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Erode i=%i", + data_cast->i); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Erode */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data); +} + +static void img_iface_dilate_erode (void *data) +{ + /* Data */ + struct Img_Iface_Data_Dilate_Erode data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Iterations:"); + data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Dilate_Erode *data_cast; + data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Dilate-erode i=%i", + data_cast->i); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Dilate */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data); + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data); +} + +static void img_iface_erode_dilate (void *data) +{ + /* Data */ + struct Img_Iface_Data_Dilate_Erode data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Iterations:"); + data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Dilate_Erode *data_cast; + data_cast = (struct Img_Iface_Data_Dilate_Erode *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Erode-dilate i=%i", + data_cast->i); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Dilate */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data); + img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data); +} + +static void img_iface_smooth (void *data) +{ + /* Data */ + struct Img_Iface_Data_Smooth data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Method: MEAN=1, GAUSS=2, MEDIAN=3"); + data_tmp.method = user_iface_getint(1, 3, 3, title, NULL); + + snprintf(title, 80, "Kernel size: 3, 5, 7, ..."); + data_tmp.ksize = user_iface_getint(3, 3, INFINITY, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Smooth *data_cast; + data_cast = (struct Img_Iface_Data_Smooth *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Smooth mth=%i [%ix%i]", + data_cast->method, + data_cast->ksize, + data_cast->ksize); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Filter: smooth */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_SMOOTH, data); +} + +static void img_iface_sobel (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! Invalid input"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + return; + } + + /* Data */ + struct Img_Iface_Data_Sobel data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Order of the derivative x"); + data_tmp.dx = user_iface_getint(0, 1, 10, title, NULL); + + snprintf(title, 80, "Order of the derivative y"); + data_tmp.dy = user_iface_getint(0, 1, 10, title, NULL); + + snprintf(title, 80, "Size of the extended Sobel kernel (-1 -> Scharr"); + data_tmp.ksize = user_iface_getint(-1, 3, 7, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Sobel *data_cast; + data_cast = (struct Img_Iface_Data_Sobel *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Sobel dx=%i;dy=%i [ks=%i]", + data_cast->dx, + data_cast->dy, + data_cast->ksize); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Filter: sobel */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_SOBEL, data); +} + +static void img_iface_border (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! Invalid input"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + return; + } + + /* Data */ + struct Img_Iface_Data_Border data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Size"); + data_tmp.size = user_iface_getint(1, 1, 0xF000, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Border *data_cast; + data_cast = (struct Img_Iface_Data_Border *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Border size=%i", + data_cast->size); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Add border */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_BORDER, data); +} + +/* ----- ------- Geometric image transformations */ +static void img_iface_mirror (void *data) +{ + /* Data */ + struct Img_Iface_Data_Mirror data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Axis: 0=x; 1=y"); + data_tmp.axis = user_iface_getint(0, 1, 1, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Mirror *data_cast; + data_cast = (struct Img_Iface_Data_Mirror *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Mirror axis: %i", + data_cast->axis); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Mirror */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_MIRROR, data); +} + +static void img_iface_rotate_orto (void *data) +{ + /* Data */ + struct Img_Iface_Data_Rotate_Orto data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Rotate (counterclockwise) n * pi/2 rad; n:"); + data_tmp.n = user_iface_getint(1, 1, 3, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Rotate_Orto *data_cast; + data_cast = (struct Img_Iface_Data_Rotate_Orto *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Rotate %i * pi/2 rad", + data_cast->n); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Rotate ortogonally */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE_ORTO, data); +} + +static void img_iface_rotate (void *data) +{ + /* Data */ + struct Img_Iface_Data_Rotate data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Center: x:"); + data_tmp.center.x = user_iface_getdbl(0, 0, INFINITY, title, NULL); + + snprintf(title, 80, "Center: y:"); + data_tmp.center.y = user_iface_getdbl(0, 0, INFINITY, title, NULL); + + snprintf(title, 80, "Angle: (deg)"); + data_tmp.angle = user_iface_getdbl(-INFINITY, 0, INFINITY, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Rotate *data_cast; + data_cast = (struct Img_Iface_Data_Rotate *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Rotate (%.2f,%.2f) %lfº", + data_cast->center.x, + data_cast->center.y, + data_cast->angle); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Rotate ortogonally */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE, data); +} + +static void img_iface_rotate_2rect (void *data) +{ + /* Data */ + struct Img_Iface_Data_Rotate data_tmp; + if (!data) { + data_tmp.center.x = rectangle_rot.center.x; + data_tmp.center.y = rectangle_rot.center.y; + data_tmp.angle = rectangle_rot.angle; + + /* If angle is < -45º, it is taking into acount the incorrect side */ + if (data_tmp.angle < -45.0) { + data_tmp.angle += 90.0; + } + + data = (void *)&data_tmp; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Rotate to rectangle"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Rotate ortogonally */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE, data); +} + +/* ----- ------- Miscellaneous image transformations */ +static void img_iface_adaptive_thr (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! Invalid input"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + return; + } + + /* Data */ + struct Img_Iface_Data_Adaptive_Thr data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Method: MEAN=0, GAUSS=1"); + data_tmp.method = user_iface_getint(0, 1, 1, title, NULL); + + snprintf(title, 80, "Type: BIN=0, BIN_INV=1"); + data_tmp.thr_typ = user_iface_getint(0, 0, 1, title, NULL); + + snprintf(title, 80, "Kernel size: 3, 5, 7, ..."); + data_tmp.ksize = user_iface_getint(3, 3, INFINITY, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Adaptive_Thr *data_cast; + data_cast = (struct Img_Iface_Data_Adaptive_Thr *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Threshold mth=%i, typ=%i, ks=%i", + data_cast->method, + data_cast->thr_typ, + data_cast->ksize); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Filter: adaptive threshold */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ADAPTIVE_THRESHOLD, data); +} + +static void img_iface_cvt_color (void *data) +{ + /* Must have at least 3 channels */ + if (image_copy_tmp.channels() < 3) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! Invalid input"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + return; + } + + /* Data */ + struct Img_Iface_Data_Cvt_Color data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Method: BGR2GRAY = 6, BGR2HSV = 40"); + data_tmp.method = user_iface_getint(0, 0, + cv::COLOR_COLORCVT_MAX, + title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Cvt_Color *data_cast; + data_cast = (struct Img_Iface_Data_Cvt_Color *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Convert color %i", + data_cast->method); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Filter: BGR to gray */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_CVT_COLOR, data); +} + +static void img_iface_distance_transform (void) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! Invalid input"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + return; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Distance transform"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Distance transform */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_DISTANCE_TRANSFORM, NULL); +} + +static void img_iface_threshold (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! Invalid input"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + return; + } + + /* Data */ + struct Img_Iface_Data_Threshold data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Type: BIN=0, BIN_INV=1, TRUNC=2, TOZ=3, TOZ_INV=4"); + data_tmp.thr_typ = user_iface_getint(0, 0, 4, title, NULL); + + snprintf(title, 80, "Value: 0 to 255 (or -1 for Otsu's algorithm)"); + data_tmp.thr_val = user_iface_getint(-1, 0, 255, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Threshold *data_cast; + data_cast = (struct Img_Iface_Data_Threshold *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Threshold typ=%i, val=%i", + data_cast->thr_typ, + data_cast->thr_val); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Filter: threshold */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_THRESHOLD, data); +} + +/* ----- ------- Histograms */ +static void img_iface_histogram (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! Invalid input"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + return; + } + + /* Data */ + struct Img_Iface_Data_Histogram data_tmp; + if (!data) { + data_tmp.hist_c0 = &histogram_c0; + data_tmp.hist_img = &hist_img_c1; + + data = (void *)&data_tmp; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Histogram"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Histogram */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_HISTOGRAM, data); +} + +static void img_iface_histogram_c3 (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 3) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! Invalid input"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + return; + } + + /* Data */ + struct Img_Iface_Data_Histogram data_tmp; + if (!data) { + data_tmp.hist_c0 = &histogram_c0; + data_tmp.hist_c1 = &histogram_c1; + data_tmp.hist_c2 = &histogram_c2; + data_tmp.hist_img = &hist_img_c3; + + data = (void *)&data_tmp; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Histogram (3 channels)"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Histogram */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_HISTOGRAM_C3, data); +} + +/* ----- ------- Structural analysis and shape descriptors */ +static void img_iface_contours (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! Invalid input"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + return; + } + + /* Data */ + struct Img_Iface_Data_Contours data_tmp; + if (!data) { + data_tmp.contours = &contours; + data_tmp.hierarchy = &hierarchy; + + data = (void *)&data_tmp; + } + + /* Contours */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_CONTOURS, data); + + /* Write into log */ + struct Img_Iface_Data_Contours *data_cast; + data_cast = (struct Img_Iface_Data_Contours *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Contours n=%i", + (int)data_cast->contours->size()); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +static void img_iface_contours_size (void *data) +{ + /* Data */ + struct Img_Iface_Data_Contours_Size data_tmp; + if (!data) { + data_tmp.contours = &contours; + data_tmp.area = area; + data_tmp.perimeter = perimeter; + + data = (void *)&data_tmp; + } + + /* Contours size */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_CONTOURS_SIZE, data); + + /* Write into log */ + struct Img_Iface_Data_Contours_Size *data_cast; + data_cast = (struct Img_Iface_Data_Contours_Size *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Contours size:"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + int i; + for (i = 0; i < (int)data_cast->contours->size(); i++) { + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "cnt[%i]: A=%lf; P=%lf;", + i, + data_cast->area[i], + data_cast->perimeter[i]); + user_iface_log.lvl[user_iface_log.len] = 2; + (user_iface_log.len)++; + } +} + +static void img_iface_bounding_rect (void *data) +{ + /* Data */ + struct Img_Iface_Data_Bounding_Rect data_tmp; + if (!data) { + if(!contours.size()) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], + LOG_LINE_LEN, + "! Invalid input"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + return; + } + data_tmp.contour = &(contours[0]); + data_tmp.rect = &rectangle; + data_tmp.show = true; + + data = (void *)&data_tmp; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Bounding rectangle"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Enclosing rectangle */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_BOUNDING_RECT, data); +} + +static void img_iface_fit_ellipse (void *data) +{ + /* Data */ + struct Img_Iface_Data_MinARect data_tmp; + if (!data) { + if(!contours.size()) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], + LOG_LINE_LEN, + "! Invalid input"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + return; + } + data_tmp.contour = &(contours[0]); + + data_tmp.rect = &rectangle_rot; + + data = (void *)&data_tmp; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Fit ellipse"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Enclosing rectangle */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_FIT_ELLIPSE, data); +} + +static void img_iface_min_area_rect (void *data) +{ + /* Data */ + struct Img_Iface_Data_MinARect data_tmp; + if (!data) { + if(!contours.size()) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], + LOG_LINE_LEN, + "! Invalid input"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + return; + } + data_tmp.contour = &(contours[0]); + data_tmp.rect = &rectangle_rot; + data_tmp.show = true; + + data = (void *)&data_tmp; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Min area rectangle"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Enclosing rectangle */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_MIN_AREA_RECT, data); +} + +/* ----- ------- Feature detection */ +static void img_iface_hough_circles (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! Invalid input"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + return; + } + + /* Data */ + struct Img_Iface_Data_Hough_Circles data_tmp; + if (!data) { + data_tmp.circles = &circles; + + /* Ask user */ + char title [80]; + snprintf(title, 80, "Minimum distance:"); + data_tmp.dist_min = user_iface_getdbl(0, 5, INFINITY, title, NULL); + + snprintf(title, 80, "param 1:"); + data_tmp.param_1 = user_iface_getdbl(0, 200, INFINITY, title, NULL); + + snprintf(title, 80, "param 2:"); + data_tmp.param_2 = user_iface_getdbl(0, 100, INFINITY, title, NULL); + + snprintf(title, 80, "Minimum radius"); + data_tmp.radius_min = user_iface_getint(0, 10, INFINITY, title, NULL); + + snprintf(title, 80, "Maximum radius"); + data_tmp.radius_max = user_iface_getint(0, 0, INFINITY, title, NULL); + + data = (void *)&data_tmp; + } + + /* Circles */ + img_cv_act(&image_copy_tmp, IMG_CV_ACT_HOUGH_CIRCLES, data); + + /* Write into log */ + struct Img_Iface_Data_Hough_Circles *data_cast; + data_cast = (struct Img_Iface_Data_Hough_Circles *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Circles n=%i", + (int)data_cast->circles->size()); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; +} + +/* img_orb -------------------------------------------------------------------*/ +static void img_iface_align (void) +{ + /* Must have defined a reference */ + if (image_ref.empty()) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! Reference is NULL"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + return; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Align to reference"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Align to reference image_ref */ + img_orb_act(&image_ref, &image_copy_tmp, IMG_ORB_ACT_ALIGN); +} + +/* img_calib3d ---------------------------------------------------------------*/ +static void img_iface_calibrate (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! Invalid input"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + return; + } + + /* Data */ + struct Img_Iface_Data_Calibrate data_tmp; + if (!data) { + data_tmp.intrinsic_mat = &intrinsic_mat; + data_tmp.dist_coefs = &dist_coefs; + data_tmp.rvecs = &rvecs; + data_tmp.tvecs = &tvecs; + + data = (void *)&data_tmp; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Calibrate"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Contours */ + img_calib3d_act(&image_copy_tmp, IMG_CALIB3D_ACT_CALIBRATE, data); +} + +static void img_iface_undistort (void *data) +{ + /* Data */ + struct Img_Iface_Data_Undistort data_tmp; + if (!data) { + data_tmp.intrinsic_mat = &intrinsic_mat; + data_tmp.dist_coefs = &dist_coefs; + + data = (void *)&data_tmp; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Undistort"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Contours */ + img_calib3d_act(&image_copy_tmp, IMG_CALIB3D_ACT_UNDISTORT, data); +} + +/* img_zbar ------------------------------------------------------------------*/ +static void img_iface_decode (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! Invalid input"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + return; + } + + /* Data */ + struct Img_Iface_Data_Decode data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Type of code: (0 for all)"); + data_tmp.code_type = (enum zbar::zbar_symbol_type_e) + user_iface_getint(0, 0, INT_MAX, + title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Decode *data_cast; + data_cast = (struct Img_Iface_Data_Decode *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Detect codes c=%i", + data_cast->code_type); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Decode */ + img_zb_act(&image_copy_tmp, IMG_ZB_ACT_DECODE, data); + + /* Results */ + if (!zb_codes.n) { + /* No text found */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! No code detected"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + } else { + /* Write results into log */ + int i; + for (i = 0; i < zb_codes.n; i++) { + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "%s -- '%s'", + zb_codes.arr[i].sym_name, + zb_codes.arr[i].data); + user_iface_log.lvl[user_iface_log.len] = 2; + (user_iface_log.len)++; + } + } +} + +/* img_ocr -------------------------------------------------------------------*/ +static void img_iface_read (void *data) +{ + /* Must have 1 channel */ + if (image_copy_tmp.channels() != 1) { + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! Invalid input"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + return; + } + + /* Data */ + struct Img_Iface_Data_Read data_tmp; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "Language: ENG = 0, SPA = 1, CAT = 2"); + data_tmp.lang = user_iface_getint(0, 1, 2, title, NULL); + + snprintf(title, 80, "Config: none = 0, Price = 1"); + data_tmp.conf = user_iface_getint(0, 1, 2, title, NULL); + + data = (void *)&data_tmp; + } + + /* Write into log */ + struct Img_Iface_Data_Read *data_cast; + data_cast = (struct Img_Iface_Data_Read *)data; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "OCR (lang=%i) [c=%i]", + data_cast->lang, + data_cast->conf); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Adapt image data */ + data_cast->img.data = image_copy_tmp.data; + data_cast->img.width = image_copy_tmp.size().width; + data_cast->img.height = image_copy_tmp.size().height; + data_cast->img.B_per_pix = image_copy_tmp.channels(); + data_cast->img.B_per_line = image_copy_tmp.step1(); + + /* OCR */ + img_ocr_act(IMG_OCR_ACT_READ, data); + + /* Results */ + if (img_ocr_text[0] == '\0') { + /* No text found */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "! No text detected"); + user_iface_log.lvl[user_iface_log.len] = 2; + (user_iface_log.len)++; + } +} + +/* img_iface -----------------------------------------------------------------*/ +static void img_iface_apply (void) +{ + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Apply changes"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Write tmp into old */ + image_copy_old.release(); + image_copy_tmp.copyTo(image_copy_old); +} + +static void img_iface_discard (void) +{ + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Discard changes"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Discard tmp image copy */ + image_copy_tmp.release(); + image_copy_old.copyTo(image_copy_tmp); +} + +static void img_iface_save_mem (void *data) +{ + /* Which memory to use */ + int x; + if (!data) { + /* Ask user */ + char title [80]; + snprintf(title, 80, "mem_X; X:"); + x = user_iface_getint(0, 0, IMG_MEM_SIZE - 1, title, NULL); + } else { + x = *(int *)data; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Save to mem_%i", x); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Write into mem */ + image_mem[x].release(); + image_copy_tmp.copyTo(image_mem[x]); +} + +static void img_iface_load_mem (void *data) +{ + /* Which memory to use */ + int x; + if (!data) { + /* Ask user which memory to use */ + char title [80]; + snprintf(title, 80, "mem_X; X:"); + x = user_iface_getint(0, 0, IMG_MEM_SIZE - 1, title, NULL); + } else { + x = *(int *)data; + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Load from mem_%i", x); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + if (!image_mem[x].empty()) { + /* Discard tmp image copy */ + image_copy_tmp.release(); + + /* Load from mem */ + image_mem[x].copyTo(image_copy_tmp); + } +} + +static void img_iface_save_ref (void) +{ + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Save to reference"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Write into ref */ + image_ref.release(); + image_copy_tmp.copyTo(image_ref); + image_ref = image_copy_tmp; +} + +/* save ----------------------------------------------------------------------*/ +static void img_iface_save_file (void) +{ + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Save as..."); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Write into image struct (save.c) */ + image.release(); + image_copy_tmp.copyTo(image); + + /* Save into file */ + save_image_file(NULL, NULL); +} + +static void img_iface_save_update (void) +{ + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Save: update img"); + user_iface_log.lvl[user_iface_log.len] = 1; + (user_iface_log.len)++; + + /* Write into image struct (save.c) */ + image.release(); + image_copy_tmp.copyTo(image); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/src/img_ocr.c b/modules/image/src/img_ocr.c index 5aba51e..c406abf 100644 --- a/modules/image/src/img_ocr.c +++ b/modules/image/src/img_ocr.c @@ -1,128 +1,128 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* INT_MAX */
- #include <limits.h>
- #include <stddef.h>
- /* snprintf() & FILENAME_MAX */
- #include <stdio.h>
-
-/* Packages ------------------------------------------------------------------*/
- /* OCR Tesseract */
- #include <tesseract/capi.h>
-
-/* Project -------------------------------------------------------------------*/
- /* share_path */
- #include "about.h"
-
-/* Module --------------------------------------------------------------------*/
- /* data & img_ocr_text & OCR_TEXT_MAX */
- #include "img_iface.h"
-
- #include "img_ocr.h"
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void img_ocr_read (void *data);
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void img_ocr_act (int action, void *data)
-{
- switch (action) {
- case IMG_OCR_ACT_READ:
- img_ocr_read(data);
- break;
- }
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void img_ocr_read (void *data)
-{
- struct TessBaseAPI *handle_ocr;
-
- /* Data */
- struct Img_Iface_Data_Read *data_cast;
- data_cast = (struct Img_Iface_Data_Read *)data;
-
- /* Language */
- int lang;
- char lang_str [20 + 1];
- lang = data_cast->lang;
- switch (lang) {
- case IMG_IFACE_OCR_LANG_ENG:
- sprintf(lang_str, "eng");
- break;
- case IMG_IFACE_OCR_LANG_SPA:
- sprintf(lang_str, "spa");
- break;
- case IMG_IFACE_OCR_LANG_CAT:
- sprintf(lang_str, "cat");
- break;
- case IMG_IFACE_OCR_LANG_DIGITS:
- sprintf(lang_str, "digits");
- break;
- case IMG_IFACE_OCR_LANG_DIGITS_COMMA:
- sprintf(lang_str, "digits_comma");
- break;
- }
-
- /* Config file */
- int conf;
- char conf_str [FILENAME_MAX];
- conf = data_cast->conf;
- switch (conf) {
- case IMG_IFACE_OCR_CONF_PRICE:
- snprintf(conf_str, 6, "%s/%s", share_path, "price");
- break;
- }
-
- /* init OCR */
- handle_ocr = TessBaseAPICreate();
- TessBaseAPIInit2(handle_ocr, NULL, lang_str,
-#ifdef OEM_LSTM_ONLY
- OEM_LSTM_ONLY);
-#else
- OEM_DEFAULT);
-#endif
-// OEM_TESSERACT_LSTM_COMBINED);
- if (conf) {
- /* Configure OCR (whitelist chars) */
- TessBaseAPIReadConfigFile(handle_ocr, conf_str);
- }
-
- /* scan image for text */
- TessBaseAPISetImage(handle_ocr, data_cast->img.data,
- data_cast->img.width, data_cast->img.height,
- data_cast->img.B_per_pix,
- data_cast->img.B_per_line);
- TessBaseAPIRecognize(handle_ocr, NULL);
- char *txt;
- txt = TessBaseAPIGetUTF8Text(handle_ocr);
-
- /* Copy text to global variable */
- snprintf(img_ocr_text, OCR_TEXT_MAX, "%s", txt);
-
- /* cleanup */
- TessDeleteText(txt);
- TessBaseAPIEnd(handle_ocr);
- TessBaseAPIDelete(handle_ocr);
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* INT_MAX */ + #include <limits.h> + #include <stddef.h> + /* snprintf() & FILENAME_MAX */ + #include <stdio.h> + +/* Packages ------------------------------------------------------------------*/ + /* OCR Tesseract */ + #include <tesseract/capi.h> + +/* Project -------------------------------------------------------------------*/ + /* share_path */ + #include "about.h" + +/* Module --------------------------------------------------------------------*/ + /* data & img_ocr_text & OCR_TEXT_MAX */ + #include "img_iface.h" + + #include "img_ocr.h" + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void img_ocr_read (void *data); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void img_ocr_act (int action, void *data) +{ + switch (action) { + case IMG_OCR_ACT_READ: + img_ocr_read(data); + break; + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void img_ocr_read (void *data) +{ + struct TessBaseAPI *handle_ocr; + + /* Data */ + struct Img_Iface_Data_Read *data_cast; + data_cast = (struct Img_Iface_Data_Read *)data; + + /* Language */ + int lang; + char lang_str [20 + 1]; + lang = data_cast->lang; + switch (lang) { + case IMG_IFACE_OCR_LANG_ENG: + sprintf(lang_str, "eng"); + break; + case IMG_IFACE_OCR_LANG_SPA: + sprintf(lang_str, "spa"); + break; + case IMG_IFACE_OCR_LANG_CAT: + sprintf(lang_str, "cat"); + break; + case IMG_IFACE_OCR_LANG_DIGITS: + sprintf(lang_str, "digits"); + break; + case IMG_IFACE_OCR_LANG_DIGITS_COMMA: + sprintf(lang_str, "digits_comma"); + break; + } + + /* Config file */ + int conf; + char conf_str [FILENAME_MAX]; + conf = data_cast->conf; + switch (conf) { + case IMG_IFACE_OCR_CONF_PRICE: + snprintf(conf_str, 6, "%s/%s", share_path, "price"); + break; + } + + /* init OCR */ + handle_ocr = TessBaseAPICreate(); + TessBaseAPIInit2(handle_ocr, NULL, lang_str, +#ifdef OEM_LSTM_ONLY + OEM_LSTM_ONLY); +#else + OEM_DEFAULT); +#endif +// OEM_TESSERACT_LSTM_COMBINED); + if (conf) { + /* Configure OCR (whitelist chars) */ + TessBaseAPIReadConfigFile(handle_ocr, conf_str); + } + + /* scan image for text */ + TessBaseAPISetImage(handle_ocr, data_cast->img.data, + data_cast->img.width, data_cast->img.height, + data_cast->img.B_per_pix, + data_cast->img.B_per_line); + TessBaseAPIRecognize(handle_ocr, NULL); + char *txt; + txt = TessBaseAPIGetUTF8Text(handle_ocr); + + /* Copy text to global variable */ + snprintf(img_ocr_text, OCR_TEXT_MAX, "%s", txt); + + /* cleanup */ + TessDeleteText(txt); + TessBaseAPIEnd(handle_ocr); + TessBaseAPIDelete(handle_ocr); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/src/img_orb.cpp b/modules/image/src/img_orb.cpp index f62203c..6d91085 100644 --- a/modules/image/src/img_orb.cpp +++ b/modules/image/src/img_orb.cpp @@ -1,126 +1,126 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C++ --------------------------------------------------------------*/
- /* class std::vector */
- #include <vector>
-
-/* Standard C ----------------------------------------------------------------*/
- /* snprintf() */
- #include <cstdio>
-
-/* Packages ------------------------------------------------------------------*/
- /* opencv */
- #include <opencv2/opencv.hpp>
- #include <opencv2/features2d/features2d.hpp>
-
-/* Module -------------------------------------------------------------------*/
- #include "img_orb.hpp"
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
- # define MAX_FEATURES (50000)
- # define GOOD_MATCH_P (0.25)
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void img_orb_align (class cv::Mat *img_0,
- class cv::Mat *img_1);
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void img_orb_act (class cv::Mat *img_ref,
- class cv::Mat *imgptr, int action)
-{
- switch (action) {
- case IMG_ORB_ACT_ALIGN:
- img_orb_align(img_ref, imgptr);
- break;
- }
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void img_orb_align (class cv::Mat *img_0,
- class cv::Mat *img_1)
-{
- /* Variables to store keypoints & descriptors */
- class std::vector <class cv::KeyPoint> keypoints_0;
- class std::vector <class cv::KeyPoint> keypoints_1;
- class cv::Mat descriptors_0;
- class cv::Mat descriptors_1;
-
- /* Detect ORB features & compute descriptors */
-#if 1
- /* OpenCV 2.x */
- class cv::ORB orb;
- orb(*img_0, cv::Mat(), keypoints_0, descriptors_0);
- orb(*img_1, cv::Mat(), keypoints_1, descriptors_1);
-#else
- /* OpenCV 3.x */
- class cv::Ptr <class cv::Feature2D> orb;
- orb = cv::ORB::create(MAX_FEATURES);
- orb->detectAndCompute(*img_0, cv::Mat(), keypoints_0, descriptors_0);
- orb->detectAndCompute(*img_1, cv::Mat(), keypoints_1, descriptors_1);
-#endif
-
-
- /* Match structures */
- class std::vector <struct cv::DMatch> matches;
- cv::Ptr <class cv::DescriptorMatcher> matcher;
- matcher = cv::DescriptorMatcher::create("BruteForce-Hamming");
- matcher->match(descriptors_1, descriptors_0, matches, cv::Mat());
-
- /* Sort matches by score */
- std::sort(matches.begin(), matches.end());
-
- /* Remove not so good matches */
- int good_matches;
- good_matches = GOOD_MATCH_P * matches.size();
- matches.erase(matches.begin() + good_matches, matches.end());
-
- /* Draw top matches */
- class cv::Mat img_matches;
- cv::drawMatches(*img_1, keypoints_1, *img_0, keypoints_0, matches,
- img_matches);
- cv::imwrite("matches.jpg", img_matches);
-
- /* Extract location of good matches */
- class std::vector <class cv::Point_ <float>> points_0;
- class std::vector <class cv::Point_ <float>> points_1;
- int i;
- for (i = 0; i < (int)matches.size(); i++) {
- points_1.push_back(keypoints_1[matches[i].queryIdx].pt);
- points_0.push_back(keypoints_0[matches[i].trainIdx].pt);
- }
-
- /* Find homography */
- class cv::Mat img_hg;
- img_hg = cv::findHomography(points_1, points_0, CV_RANSAC);
-
- /* Use homography to warp image */
- class cv::Mat img_align;
- cv::warpPerspective(*img_1, img_align, img_hg, img_0->size());
-
- /* Write img_align into img_1 */
- *img_1 = img_align;
- img_align.release();
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C++ --------------------------------------------------------------*/ + /* class std::vector */ + #include <vector> + +/* Standard C ----------------------------------------------------------------*/ + /* snprintf() */ + #include <cstdio> + +/* Packages ------------------------------------------------------------------*/ + /* opencv */ + #include <opencv2/opencv.hpp> + #include <opencv2/features2d/features2d.hpp> + +/* Module -------------------------------------------------------------------*/ + #include "img_orb.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define MAX_FEATURES (50000) + # define GOOD_MATCH_P (0.25) + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void img_orb_align (class cv::Mat *img_0, + class cv::Mat *img_1); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void img_orb_act (class cv::Mat *img_ref, + class cv::Mat *imgptr, int action) +{ + switch (action) { + case IMG_ORB_ACT_ALIGN: + img_orb_align(img_ref, imgptr); + break; + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void img_orb_align (class cv::Mat *img_0, + class cv::Mat *img_1) +{ + /* Variables to store keypoints & descriptors */ + class std::vector <class cv::KeyPoint> keypoints_0; + class std::vector <class cv::KeyPoint> keypoints_1; + class cv::Mat descriptors_0; + class cv::Mat descriptors_1; + + /* Detect ORB features & compute descriptors */ +#if 1 + /* OpenCV 2.x */ + class cv::ORB orb; + orb(*img_0, cv::Mat(), keypoints_0, descriptors_0); + orb(*img_1, cv::Mat(), keypoints_1, descriptors_1); +#else + /* OpenCV 3.x */ + class cv::Ptr <class cv::Feature2D> orb; + orb = cv::ORB::create(MAX_FEATURES); + orb->detectAndCompute(*img_0, cv::Mat(), keypoints_0, descriptors_0); + orb->detectAndCompute(*img_1, cv::Mat(), keypoints_1, descriptors_1); +#endif + + + /* Match structures */ + class std::vector <struct cv::DMatch> matches; + cv::Ptr <class cv::DescriptorMatcher> matcher; + matcher = cv::DescriptorMatcher::create("BruteForce-Hamming"); + matcher->match(descriptors_1, descriptors_0, matches, cv::Mat()); + + /* Sort matches by score */ + std::sort(matches.begin(), matches.end()); + + /* Remove not so good matches */ + int good_matches; + good_matches = GOOD_MATCH_P * matches.size(); + matches.erase(matches.begin() + good_matches, matches.end()); + + /* Draw top matches */ + class cv::Mat img_matches; + cv::drawMatches(*img_1, keypoints_1, *img_0, keypoints_0, matches, + img_matches); + cv::imwrite("matches.jpg", img_matches); + + /* Extract location of good matches */ + class std::vector <class cv::Point_ <float>> points_0; + class std::vector <class cv::Point_ <float>> points_1; + int i; + for (i = 0; i < (int)matches.size(); i++) { + points_1.push_back(keypoints_1[matches[i].queryIdx].pt); + points_0.push_back(keypoints_0[matches[i].trainIdx].pt); + } + + /* Find homography */ + class cv::Mat img_hg; + img_hg = cv::findHomography(points_1, points_0, CV_RANSAC); + + /* Use homography to warp image */ + class cv::Mat img_align; + cv::warpPerspective(*img_1, img_align, img_hg, img_0->size()); + + /* Write img_align into img_1 */ + *img_1 = img_align; + img_align.release(); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/src/img_zbar.cpp b/modules/image/src/img_zbar.cpp index 083093b..5a976a6 100644 --- a/modules/image/src/img_zbar.cpp +++ b/modules/image/src/img_zbar.cpp @@ -1,102 +1,102 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* INT_MAX */
- #include <climits>
- #include <cstddef>
- /* snprintf() */
- #include <cstdio>
-
-/* Packages ------------------------------------------------------------------*/
- /* opencv */
- #include <opencv2/opencv.hpp>
- /* zbar */
- #include <zbar.h>
-
-/* Module --------------------------------------------------------------------*/
- /* data & zb_codes */
- #include "img_iface.hpp"
-
- #include "img_zbar.hpp"
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void img_zb_decode (class cv::Mat *imgptr, void *data);
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void img_zb_act (class cv::Mat *imgptr, int action, void *data)
-{
- switch (action) {
- case IMG_ZB_ACT_DECODE:
- img_zb_decode(imgptr, data);
- break;
- }
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void img_zb_decode (class cv::Mat *imgptr, void *data)
-{
- struct zbar::zbar_image_scanner_s *scanner;
- struct zbar::zbar_image_s *image_zb;
- const struct zbar::zbar_symbol_s *symbol;
-
- /* Type of code to scan */
- enum zbar::zbar_symbol_type_e code_type;
- code_type = ((struct Img_Iface_Data_Decode *)data)->code_type;
-
- /* create & configure a reader */
- scanner = zbar::zbar_image_scanner_create();
- zbar::zbar_image_scanner_set_config(scanner, code_type,
- zbar::ZBAR_CFG_ENABLE, 1);
-
- /* wrap image data */
- image_zb = zbar::zbar_image_create();
- zbar::zbar_image_set_format(image_zb, *(int*)"GREY");
- zbar::zbar_image_set_size(image_zb, imgptr->cols, imgptr->rows);
- zbar::zbar_image_set_data(image_zb, (void *)(imgptr->data),
- (imgptr->cols * imgptr->rows),
- NULL);
-
- /* scan the image for barcodes */
- int i;
- zb_codes.n = zbar::zbar_scan_image(scanner, image_zb);
- if (zb_codes.n) {
- /* extract results */
- symbol = zbar::zbar_image_first_symbol(image_zb);
- for (i = 0; i < ZB_CODES_MAX && symbol; i++) {
- /* Write results into array */
- zb_codes.arr[i].type = zbar::zbar_symbol_get_type(symbol);
- snprintf(zb_codes.arr[i].sym_name, 80, "%s",
- zbar::zbar_get_symbol_name(
- zb_codes.arr[i].type));
- snprintf(zb_codes.arr[i].data, ZBAR_LEN_MAX, "%s",
- zbar::zbar_symbol_get_data(symbol));
-
- /* Load next symbol */
- symbol = zbar::zbar_symbol_next(symbol);
- }
- }
-
- /* clean up */
- zbar::zbar_image_destroy(image_zb);
- zbar::zbar_image_scanner_destroy(scanner);
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* INT_MAX */ + #include <climits> + #include <cstddef> + /* snprintf() */ + #include <cstdio> + +/* Packages ------------------------------------------------------------------*/ + /* opencv */ + #include <opencv2/opencv.hpp> + /* zbar */ + #include <zbar.h> + +/* Module --------------------------------------------------------------------*/ + /* data & zb_codes */ + #include "img_iface.hpp" + + #include "img_zbar.hpp" + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void img_zb_decode (class cv::Mat *imgptr, void *data); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void img_zb_act (class cv::Mat *imgptr, int action, void *data) +{ + switch (action) { + case IMG_ZB_ACT_DECODE: + img_zb_decode(imgptr, data); + break; + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void img_zb_decode (class cv::Mat *imgptr, void *data) +{ + struct zbar::zbar_image_scanner_s *scanner; + struct zbar::zbar_image_s *image_zb; + const struct zbar::zbar_symbol_s *symbol; + + /* Type of code to scan */ + enum zbar::zbar_symbol_type_e code_type; + code_type = ((struct Img_Iface_Data_Decode *)data)->code_type; + + /* create & configure a reader */ + scanner = zbar::zbar_image_scanner_create(); + zbar::zbar_image_scanner_set_config(scanner, code_type, + zbar::ZBAR_CFG_ENABLE, 1); + + /* wrap image data */ + image_zb = zbar::zbar_image_create(); + zbar::zbar_image_set_format(image_zb, *(int*)"GREY"); + zbar::zbar_image_set_size(image_zb, imgptr->cols, imgptr->rows); + zbar::zbar_image_set_data(image_zb, (void *)(imgptr->data), + (imgptr->cols * imgptr->rows), + NULL); + + /* scan the image for barcodes */ + int i; + zb_codes.n = zbar::zbar_scan_image(scanner, image_zb); + if (zb_codes.n) { + /* extract results */ + symbol = zbar::zbar_image_first_symbol(image_zb); + for (i = 0; i < ZB_CODES_MAX && symbol; i++) { + /* Write results into array */ + zb_codes.arr[i].type = zbar::zbar_symbol_get_type(symbol); + snprintf(zb_codes.arr[i].sym_name, 80, "%s", + zbar::zbar_get_symbol_name( + zb_codes.arr[i].type)); + snprintf(zb_codes.arr[i].data, ZBAR_LEN_MAX, "%s", + zbar::zbar_symbol_get_data(symbol)); + + /* Load next symbol */ + symbol = zbar::zbar_symbol_next(symbol); + } + } + + /* clean up */ + zbar::zbar_image_destroy(image_zb); + zbar::zbar_image_scanner_destroy(scanner); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/menu/inc/menu_clui.h b/modules/menu/inc/menu_clui.h index ae982a8..49de943 100644 --- a/modules/menu/inc/menu_clui.h +++ b/modules/menu/inc/menu_clui.h @@ -1,27 +1,27 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_MENU_CLUI_H
- # define VA_MENU_CLUI_H
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- void menu_clui (void);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* menu_clui.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_MENU_CLUI_H + # define VA_MENU_CLUI_H + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void menu_clui (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* menu_clui.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/menu/inc/menu_iface.h b/modules/menu/inc/menu_iface.h index 320cbd4..09a1164 100644 --- a/modules/menu/inc/menu_iface.h +++ b/modules/menu/inc/menu_iface.h @@ -1,43 +1,43 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_MENU_IFACE_H
- # define VA_MENU_IFACE_H
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Menu_Iface_Mode {
- MENU_IFACE_FOO = 0,
- MENU_IFACE_CLUI,
- MENU_IFACE_TUI
- };
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-extern int menu_iface_mode;
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
-void menu_iface (void);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* menu_iface.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_MENU_IFACE_H + # define VA_MENU_IFACE_H + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Menu_Iface_Mode { + MENU_IFACE_FOO = 0, + MENU_IFACE_CLUI, + MENU_IFACE_TUI + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +extern int menu_iface_mode; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void menu_iface (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* menu_iface.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/menu/inc/menu_iface.hpp b/modules/menu/inc/menu_iface.hpp index a1fbb25..1b5b60c 100644 --- a/modules/menu/inc/menu_iface.hpp +++ b/modules/menu/inc/menu_iface.hpp @@ -1,55 +1,55 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_MENU_IFACE_HPP
- # define VA_MENU_IFACE_HPP
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-extern "C" {
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Menu_Iface_Mode {
- MENU_IFACE_FOO = 0,
- MENU_IFACE_CLUI,
- MENU_IFACE_TUI
- };
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
- extern int menu_iface_mode;
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- void menu_iface (void);
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-} /* extern "C" */
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* menu_iface.hpp */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_MENU_IFACE_HPP + # define VA_MENU_IFACE_HPP + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Menu_Iface_Mode { + MENU_IFACE_FOO = 0, + MENU_IFACE_CLUI, + MENU_IFACE_TUI + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern int menu_iface_mode; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void menu_iface (void); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* menu_iface.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/menu/inc/menu_tui.h b/modules/menu/inc/menu_tui.h index 5ccaebd..74cfd5f 100644 --- a/modules/menu/inc/menu_tui.h +++ b/modules/menu/inc/menu_tui.h @@ -1,27 +1,27 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_MENU_TUI_H
- # define VA_MENU_TUI_H
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- void menu_tui (void);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* menu_tui.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_MENU_TUI_H + # define VA_MENU_TUI_H + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void menu_tui (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* menu_tui.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/menu/inc/parser.h b/modules/menu/inc/parser.h index 836385c..a29afcd 100644 --- a/modules/menu/inc/parser.h +++ b/modules/menu/inc/parser.h @@ -1,27 +1,27 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_PARSER_H
- # define VA_PARSER_H
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
-void parser (int argc, char *argv[]);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* parser.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PARSER_H + # define VA_PARSER_H + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void parser (int argc, char *argv[]); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* parser.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/menu/inc/parser.hpp b/modules/menu/inc/parser.hpp index ff40d1f..700a0aa 100644 --- a/modules/menu/inc/parser.hpp +++ b/modules/menu/inc/parser.hpp @@ -1,39 +1,39 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_PARSER_HPP
- # define VA_PARSER_HPP
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-extern "C" {
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- void parser (int argc, char *argv[]);
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-} /* extern "C" */
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* parser.hpp */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PARSER_HPP + # define VA_PARSER_HPP + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void parser (int argc, char *argv[]); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* parser.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/menu/src/menu_clui.c b/modules/menu/src/menu_clui.c index 49c58e2..db2a11e 100644 --- a/modules/menu/src/menu_clui.c +++ b/modules/menu/src/menu_clui.c @@ -1,116 +1,116 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
- #include "alx_input.h"
-
- #include "about.h"
-// #include "save.h"
- /* start_switch() */
- #include "start.h"
-
- #include "menu_clui.h"
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
- # define BUFF_SIZE (1024)
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-//static void menu_clui_rand (void);
-//static void menu_clui_custom (void);
-static void menu_clui_load (void);
-static void menu_clui_start (void);
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void menu_clui (void)
-{
- char buff [BUFF_SIZE];
- char ch;
-
- ch = 'n';
- printf("Read 'Disclaimer of warranty'? (yes/NO): ");
- fgets(buff, BUFF_SIZE, stdin);
- sscanf(buff, " %c", &ch);
- if (ch == 'y' || ch == 'Y') {
- puts (" >yes");
- print_share_file(SHARE_DISCLAIMER);
- } else {
- puts (" >NO");
- }
-
- ch = 'n';
- printf("Read 'License'? (yes/NO): ");
- fgets(buff, BUFF_SIZE, stdin);
- sscanf(buff, " %c", &ch);
- if (ch == 'y' || ch == 'Y') {
- puts (" >yes");
- print_share_file(SHARE_LICENSE);
- } else {
- puts (" >NO");
- }
-#if 0
- printf("Game interface? (NCURSES/text): ");
- scanf(" %c%*s ", &ch);
- if (ch == 't' || ch == 'T') {
- puts (" >text");
- // FIXME
- } else {
- puts (" >NCURSES");
- // FIXME
- }
-#endif
- menu_clui_load();
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void menu_clui_load (void)
-{
-#if 0
- /* File name */ // FIXME
- alx_w_getfname(USER_SAVED_DIR, saved_name, "File name:", saved_name, NULL);
-#endif
- menu_clui_start();
-}
-
-static void menu_clui_start (void)
-{
- puts(" >>START:");
- start_switch();
-
- char buff [BUFF_SIZE];
- char ch;
-
- ch = 'm';
- printf("Load again? (MENU/load/exit): ");
- fgets(buff, BUFF_SIZE, stdin);
- sscanf(buff, " %c", &ch);
- if (ch == 'p' || ch == 'P') {
- puts (" >load");
- menu_clui_start();
- } else if (ch == 'e' || ch == 'E') {
- puts (" >exit!");
- } else {
- puts (" >MENU");
- menu_clui();
- }
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + #include "alx_input.h" + + #include "about.h" +// #include "save.h" + /* start_switch() */ + #include "start.h" + + #include "menu_clui.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define BUFF_SIZE (1024) + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +//static void menu_clui_rand (void); +//static void menu_clui_custom (void); +static void menu_clui_load (void); +static void menu_clui_start (void); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void menu_clui (void) +{ + char buff [BUFF_SIZE]; + char ch; + + ch = 'n'; + printf("Read 'Disclaimer of warranty'? (yes/NO): "); + fgets(buff, BUFF_SIZE, stdin); + sscanf(buff, " %c", &ch); + if (ch == 'y' || ch == 'Y') { + puts (" >yes"); + print_share_file(SHARE_DISCLAIMER); + } else { + puts (" >NO"); + } + + ch = 'n'; + printf("Read 'License'? (yes/NO): "); + fgets(buff, BUFF_SIZE, stdin); + sscanf(buff, " %c", &ch); + if (ch == 'y' || ch == 'Y') { + puts (" >yes"); + print_share_file(SHARE_LICENSE); + } else { + puts (" >NO"); + } +#if 0 + printf("Game interface? (NCURSES/text): "); + scanf(" %c%*s ", &ch); + if (ch == 't' || ch == 'T') { + puts (" >text"); + // FIXME + } else { + puts (" >NCURSES"); + // FIXME + } +#endif + menu_clui_load(); +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void menu_clui_load (void) +{ +#if 0 + /* File name */ // FIXME + alx_w_getfname(USER_SAVED_DIR, saved_name, "File name:", saved_name, NULL); +#endif + menu_clui_start(); +} + +static void menu_clui_start (void) +{ + puts(" >>START:"); + start_switch(); + + char buff [BUFF_SIZE]; + char ch; + + ch = 'm'; + printf("Load again? (MENU/load/exit): "); + fgets(buff, BUFF_SIZE, stdin); + sscanf(buff, " %c", &ch); + if (ch == 'p' || ch == 'P') { + puts (" >load"); + menu_clui_start(); + } else if (ch == 'e' || ch == 'E') { + puts (" >exit!"); + } else { + puts (" >MENU"); + menu_clui(); + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/menu/src/menu_iface.c b/modules/menu/src/menu_iface.c index 1a00c29..03b1413 100644 --- a/modules/menu/src/menu_iface.c +++ b/modules/menu/src/menu_iface.c @@ -1,45 +1,45 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
- /* menu_clui() */
- #include "menu_clui.h"
- /* menu_tui() */
- #include "menu_tui.h"
-
- #include "menu_iface.h"
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-int menu_iface_mode;
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void menu_iface (void)
-{
- switch (menu_iface_mode) {
- case MENU_IFACE_FOO:
- break;
-
- case MENU_IFACE_CLUI:
- menu_clui();
- break;
-
- case MENU_IFACE_TUI:
- menu_tui();
- break;
- }
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + /* menu_clui() */ + #include "menu_clui.h" + /* menu_tui() */ + #include "menu_tui.h" + + #include "menu_iface.h" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +int menu_iface_mode; + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void menu_iface (void) +{ + switch (menu_iface_mode) { + case MENU_IFACE_FOO: + break; + + case MENU_IFACE_CLUI: + menu_clui(); + break; + + case MENU_IFACE_TUI: + menu_tui(); + break; + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/menu/src/menu_tui.c b/modules/menu/src/menu_tui.c index abf9636..72c7764 100644 --- a/modules/menu/src/menu_tui.c +++ b/modules/menu/src/menu_tui.c @@ -1,330 +1,330 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- #include <ncurses.h>
- #include <stdbool.h>
- #include <stddef.h>
-
-/* libalx --------------------------------------------------------------------*/
- #include "alx_ncur.h"
-
-/* Project -------------------------------------------------------------------*/
- /* printf_share_file() */
- #include "about.h"
- /* proc_debug */
- #include "proc_iface.h"
- /* saved_name */
- #include "save.h"
- /* start_switch() */
- #include "start.h"
- /* user_iface_log */
- #include "user_iface.h"
-
-/* Module --------------------------------------------------------------------*/
- #include "menu_tui.h"
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void menu_tui_continue (void);
-static void menu_tui_select (void);
-static void menu_tui_series (void);
-static void menu_tui_devel (void);
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void menu_tui (void)
-{
- alx_resume_curses();
-
- /* Menu dimensions & options */
- int h;
- int w;
- h = 23;
- w = 80;
- int N;
- N = 4;
- struct Alx_Menu mnu[4] = {
- {7, 4, "[0] Exit program"},
- {2, 4, "[1] Continue"},
- {4, 4, "[2] Disclaimer of warranty"},
- {5, 4, "[3] Terms and conditions"}
- };
-
- /* Menu */
- bool wh;
- int sw;
- wh = true;
- while (wh) {
- /* Menu loop */
- sw = alx_menu(h, w, N, mnu, "MENU:");
-
- /* Selection */
- switch (sw) {
- case 0:
- wh = false;
- break;
-
- case 1:
- menu_tui_continue();
- break;
-
- case 2:
- alx_pause_curses();
- print_share_file(SHARE_DISCLAIMER);
- getchar();
- alx_resume_curses();
- break;
-
- case 3:
- alx_pause_curses();
- print_share_file(SHARE_LICENSE);
- getchar();
- alx_resume_curses();
- break;
- }
- }
-
- alx_pause_curses();
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void menu_tui_continue (void)
-{
- /* Menu dimensions & options */
- WINDOW *win;
- int h;
- int w;
- int r;
- int c;
- h = 23;
- w = 80;
- r = 1;
- c = (80 - w) / 2;
- int N;
- N = 6;
- struct Alx_Menu mnu[6] = {
- {8, 4, "[0] Back"},
- {2, 4, "[1] Start"},
- {3, 4, "[2] Select"},
- {4, 4, "[3] Series"},
- {5, 4, "[4] Change file name"},
- {6, 4, "[5] DEVEL"}
- };
-
- /* Input box */
- int w2;
- int r2;
- w2 = w - 8;
- r2 = r + h - 5;
- char *txt[] = {"File name:"};
-
- /* Menu */
- bool wh;
- int sw;
- wh = true;
- while (wh) {
- /* Menu loop */
- win = newwin(h, w, r, c);
- mvwprintw(win, mnu[1].r, mnu[1].c, "%s (File: \"%s\")",
- mnu[1].t, saved_name);
- wrefresh(win);
- sw = alx_menu_2(win, N, mnu, "CONTINUE:");
-
- /* Selection */
- switch (sw) {
- case 0:
- wh = false;
- break;
-
- case 1:
- alx_win_del(win);
- alx_pause_curses();
- start_switch();
- alx_resume_curses();
- break;
-
- case 2:
- alx_win_del(win);
- menu_tui_select();
- break;
-
- case 3:
- alx_win_del(win);
- menu_tui_series();
- break;
-
- case 4:
- save_clr();
- alx_w_getfname(saved_path, saved_name, true, w2, r2,
- txt[0], NULL);
- alx_win_del(win);
- break;
-
- case 5:
- alx_win_del(win);
- menu_tui_devel();
- break;
- }
- }
-
- /* Cleanup */
- alx_win_del(win);
-}
-
-static void menu_tui_select (void)
-{
- /* Menu dimensions & options */
- int h;
- int w;
- h = 23;
- w = 80;
- int N;
- N = 3;
- struct Alx_Menu mnu[3] = {
- {6, 4, "[0] Back"},
- {2, 4, "[1] Single image"},
- {4, 4, "[2] Series"}
- };
-
- /* Menu loop */
- int sw;
- sw = alx_menu(h, w, N, mnu, "SELECT MODE:");
-
- /* Selection */
- switch (sw) {
- case 1:
- start_mode = START_SINGLE;
- break;
-
- case 2:
- start_mode = START_SERIES;
- break;
- }
-
-}
-
-static void menu_tui_series (void)
-{
- /* Menu dimensions & options */
- int h;
- int w;
- h = 23;
- w = 80;
- int N;
- N = 5;
- struct Alx_Menu mnu[5] = {
- {6, 4, "[0] Back"},
- {2, 4, "[1] Label"},
- {3, 4, "[2] Objects"},
- {4, 4, "[3] Coins"},
- {5, 4, "[4] Resistor"}
- };
-
- /* Menu loop */
- int sw;
- sw = alx_menu(h, w, N, mnu, "SELECT LEVEL:");
-
- /* Selection */
- switch (sw) {
- case 1:
- proc_mode = PROC_MODE_LABEL_SERIES;
- break;
- case 2:
- proc_mode = PROC_MODE_OBJECTS_SERIES;
- break;
- case 3:
- proc_mode = PROC_MODE_COINS_SERIES;
- break;
- case 4:
- proc_mode = PROC_MODE_RESISTOR_SERIES;
- break;
- }
-
-}
-
-static void menu_tui_devel (void)
-{
- WINDOW *win;
- int h;
- int w;
- int r;
- int c;
- h = 23;
- w = 80;
- r = 1;
- c = (80 - w) / 2;
- int N;
- N = 4;
- struct Alx_Menu mnu[4] = {
- {6, 4, "[0] Back"},
- {2, 4, "[1] Change process mode"},
- {3, 4, "[2] Change log mode"},
- {4, 4, "[3] Change user iface mode"}
- };
-
- /* Input box */
- int w2;
- int r2;
- w2 = w - 8;
- r2 = r + h - 5;
- char *txt[] = {
- "Modes: 0=Auto; 1=Stop@prod; 2=Delay@step; 3=Stop@step",
- "Modes: 0=Results; 1=Operations; 2=All",
- "Modes: 1=CLUI; 2=TUI"
- };
-
- /* Menu */
- win = newwin(h, w, r, c);
-
- /* Menu loop */
- bool wh;
- int sw;
- wh = true;
- while (wh) {
- /* Selection */
- sw = alx_menu_2(win, N, mnu, "DEVELOPER OPTIONS:");
-
- switch (sw) {
- case 0:
- wh = false;
- break;
-
- case 1:
- proc_debug = alx_w_getint(w2, r2, txt[0],
- PROC_DBG_NO, 0, PROC_DBG_STOP_STEP,
- NULL);
- break;
-
- case 2:
- user_iface_log.visible = alx_w_getint(w2, r2, txt[1],
- 0, 2, 2, NULL);
- break;
-
- case 3:
- user_iface_mode = alx_w_getint(w2, r2, txt[2],
- 1, 2, 2, NULL);
- break;
- }
- }
-
- /* Cleanup */
- alx_win_del(win);
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + #include <ncurses.h> + #include <stdbool.h> + #include <stddef.h> + +/* libalx --------------------------------------------------------------------*/ + #include "alx_ncur.h" + +/* Project -------------------------------------------------------------------*/ + /* printf_share_file() */ + #include "about.h" + /* proc_debug */ + #include "proc_iface.h" + /* saved_name */ + #include "save.h" + /* start_switch() */ + #include "start.h" + /* user_iface_log */ + #include "user_iface.h" + +/* Module --------------------------------------------------------------------*/ + #include "menu_tui.h" + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void menu_tui_continue (void); +static void menu_tui_select (void); +static void menu_tui_series (void); +static void menu_tui_devel (void); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void menu_tui (void) +{ + alx_resume_curses(); + + /* Menu dimensions & options */ + int h; + int w; + h = 23; + w = 80; + int N; + N = 4; + struct Alx_Menu mnu[4] = { + {7, 4, "[0] Exit program"}, + {2, 4, "[1] Continue"}, + {4, 4, "[2] Disclaimer of warranty"}, + {5, 4, "[3] Terms and conditions"} + }; + + /* Menu */ + bool wh; + int sw; + wh = true; + while (wh) { + /* Menu loop */ + sw = alx_menu(h, w, N, mnu, "MENU:"); + + /* Selection */ + switch (sw) { + case 0: + wh = false; + break; + + case 1: + menu_tui_continue(); + break; + + case 2: + alx_pause_curses(); + print_share_file(SHARE_DISCLAIMER); + getchar(); + alx_resume_curses(); + break; + + case 3: + alx_pause_curses(); + print_share_file(SHARE_LICENSE); + getchar(); + alx_resume_curses(); + break; + } + } + + alx_pause_curses(); +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void menu_tui_continue (void) +{ + /* Menu dimensions & options */ + WINDOW *win; + int h; + int w; + int r; + int c; + h = 23; + w = 80; + r = 1; + c = (80 - w) / 2; + int N; + N = 6; + struct Alx_Menu mnu[6] = { + {8, 4, "[0] Back"}, + {2, 4, "[1] Start"}, + {3, 4, "[2] Select"}, + {4, 4, "[3] Series"}, + {5, 4, "[4] Change file name"}, + {6, 4, "[5] DEVEL"} + }; + + /* Input box */ + int w2; + int r2; + w2 = w - 8; + r2 = r + h - 5; + char *txt[] = {"File name:"}; + + /* Menu */ + bool wh; + int sw; + wh = true; + while (wh) { + /* Menu loop */ + win = newwin(h, w, r, c); + mvwprintw(win, mnu[1].r, mnu[1].c, "%s (File: \"%s\")", + mnu[1].t, saved_name); + wrefresh(win); + sw = alx_menu_2(win, N, mnu, "CONTINUE:"); + + /* Selection */ + switch (sw) { + case 0: + wh = false; + break; + + case 1: + alx_win_del(win); + alx_pause_curses(); + start_switch(); + alx_resume_curses(); + break; + + case 2: + alx_win_del(win); + menu_tui_select(); + break; + + case 3: + alx_win_del(win); + menu_tui_series(); + break; + + case 4: + save_clr(); + alx_w_getfname(saved_path, saved_name, true, w2, r2, + txt[0], NULL); + alx_win_del(win); + break; + + case 5: + alx_win_del(win); + menu_tui_devel(); + break; + } + } + + /* Cleanup */ + alx_win_del(win); +} + +static void menu_tui_select (void) +{ + /* Menu dimensions & options */ + int h; + int w; + h = 23; + w = 80; + int N; + N = 3; + struct Alx_Menu mnu[3] = { + {6, 4, "[0] Back"}, + {2, 4, "[1] Single image"}, + {4, 4, "[2] Series"} + }; + + /* Menu loop */ + int sw; + sw = alx_menu(h, w, N, mnu, "SELECT MODE:"); + + /* Selection */ + switch (sw) { + case 1: + start_mode = START_SINGLE; + break; + + case 2: + start_mode = START_SERIES; + break; + } + +} + +static void menu_tui_series (void) +{ + /* Menu dimensions & options */ + int h; + int w; + h = 23; + w = 80; + int N; + N = 5; + struct Alx_Menu mnu[5] = { + {6, 4, "[0] Back"}, + {2, 4, "[1] Label"}, + {3, 4, "[2] Objects"}, + {4, 4, "[3] Coins"}, + {5, 4, "[4] Resistor"} + }; + + /* Menu loop */ + int sw; + sw = alx_menu(h, w, N, mnu, "SELECT LEVEL:"); + + /* Selection */ + switch (sw) { + case 1: + proc_mode = PROC_MODE_LABEL_SERIES; + break; + case 2: + proc_mode = PROC_MODE_OBJECTS_SERIES; + break; + case 3: + proc_mode = PROC_MODE_COINS_SERIES; + break; + case 4: + proc_mode = PROC_MODE_RESISTOR_SERIES; + break; + } + +} + +static void menu_tui_devel (void) +{ + WINDOW *win; + int h; + int w; + int r; + int c; + h = 23; + w = 80; + r = 1; + c = (80 - w) / 2; + int N; + N = 4; + struct Alx_Menu mnu[4] = { + {6, 4, "[0] Back"}, + {2, 4, "[1] Change process mode"}, + {3, 4, "[2] Change log mode"}, + {4, 4, "[3] Change user iface mode"} + }; + + /* Input box */ + int w2; + int r2; + w2 = w - 8; + r2 = r + h - 5; + char *txt[] = { + "Modes: 0=Auto; 1=Stop@prod; 2=Delay@step; 3=Stop@step", + "Modes: 0=Results; 1=Operations; 2=All", + "Modes: 1=CLUI; 2=TUI" + }; + + /* Menu */ + win = newwin(h, w, r, c); + + /* Menu loop */ + bool wh; + int sw; + wh = true; + while (wh) { + /* Selection */ + sw = alx_menu_2(win, N, mnu, "DEVELOPER OPTIONS:"); + + switch (sw) { + case 0: + wh = false; + break; + + case 1: + proc_debug = alx_w_getint(w2, r2, txt[0], + PROC_DBG_NO, 0, PROC_DBG_STOP_STEP, + NULL); + break; + + case 2: + user_iface_log.visible = alx_w_getint(w2, r2, txt[1], + 0, 2, 2, NULL); + break; + + case 3: + user_iface_mode = alx_w_getint(w2, r2, txt[2], + 1, 2, 2, NULL); + break; + } + } + + /* Cleanup */ + alx_win_del(win); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/menu/src/parser.c b/modules/menu/src/parser.c index 6b03264..ef8cec9 100644 --- a/modules/menu/src/parser.c +++ b/modules/menu/src/parser.c @@ -1,140 +1,140 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- #include <getopt.h>
- /* FILE & fopen() & snprintf() & FILENAME_MAX */
- #include <stdio.h>
- /* exit() */
- #include <stdlib.h>
-
-/* Project -------------------------------------------------------------------*/
- /* print_share_...() */
- #include "about.h"
- /* user_iface_mode */
- #include "user_iface.h"
- /* saved_name */
- #include "save.h"
-
-/* Module --------------------------------------------------------------------*/
- /* menu_iface_mode */
- #include "menu_iface.h"
-
- #include "parser.h"
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
- # define OPT_LIST "hLuv""f:i:"
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void parse_file (char* argument);
-static void parse_iface (char* argument);
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void parser (int argc, char *argv[])
-{
- int opt = 0;
- int opt_index = 0;
-
- struct option long_options[] = {
- /* Standard */
- {"help", no_argument, 0, 'h'},
- {"license", no_argument, 0, 'L'},
- {"usage", no_argument, 0, 'u'},
- {"version", no_argument, 0, 'v'},
- /* Non-standard */
- {"file", required_argument, 0, 'f'},
- {"iface", required_argument, 0, 'i'},
- /* Null */
- {0, 0, 0, 0}
- };
-
- while ((opt = getopt_long(argc, argv, OPT_LIST, long_options,
- &opt_index)) != -1) {
-
- switch (opt) {
- /* Standard */
- case 'h':
- print_share_file(SHARE_HELP);
- exit(EXIT_SUCCESS);
-
- case 'L':
- print_share_file(SHARE_LICENSE);
- exit(EXIT_SUCCESS);
-
- case 'u':
- print_share_file(SHARE_USAGE);
- exit(EXIT_SUCCESS);
-
- case 'v':
- print_version();
- exit(EXIT_SUCCESS);
-
- /* Non-standard */
- case 'f':
- parse_file(optarg);
- break;
-
- case 'i':
- parse_iface(optarg);
- break;
-
- case '?':
- /* getopt_long already printed an error message. */
-
- default:
- print_share_file(SHARE_USAGE);
- exit(EXIT_FAILURE);
- }
- }
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void parse_file (char* argument)
-{
- // FIXME
- FILE *fp;
- fp = fopen(argument, "r");
- if (!fp) {
- printf("--file argument not valid\n");
- printf("It must be a valid file name (relative to saved dir)\n");
- exit(EXIT_FAILURE);
- } else {
- fclose(fp);
-
- sprintf(saved_path, "");
- snprintf(saved_name, FILENAME_MAX, "%s", argument);
- }
-}
-
-static void parse_iface (char* argument)
-{
- menu_iface_mode = atoi(argument);
- user_iface_mode = menu_iface_mode;
- if (menu_iface_mode < MENU_IFACE_CLUI || menu_iface_mode > MENU_IFACE_TUI) {
- printf("--iface argument not valid\n");
- printf("It must be an integer [%i U %i]\n", MENU_IFACE_CLUI, MENU_IFACE_TUI);
- exit(EXIT_FAILURE);
- }
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + #include <getopt.h> + /* FILE & fopen() & snprintf() & FILENAME_MAX */ + #include <stdio.h> + /* exit() */ + #include <stdlib.h> + +/* Project -------------------------------------------------------------------*/ + /* print_share_...() */ + #include "about.h" + /* user_iface_mode */ + #include "user_iface.h" + /* saved_name */ + #include "save.h" + +/* Module --------------------------------------------------------------------*/ + /* menu_iface_mode */ + #include "menu_iface.h" + + #include "parser.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define OPT_LIST "hLuv""f:i:" + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void parse_file (char* argument); +static void parse_iface (char* argument); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void parser (int argc, char *argv[]) +{ + int opt = 0; + int opt_index = 0; + + struct option long_options[] = { + /* Standard */ + {"help", no_argument, 0, 'h'}, + {"license", no_argument, 0, 'L'}, + {"usage", no_argument, 0, 'u'}, + {"version", no_argument, 0, 'v'}, + /* Non-standard */ + {"file", required_argument, 0, 'f'}, + {"iface", required_argument, 0, 'i'}, + /* Null */ + {0, 0, 0, 0} + }; + + while ((opt = getopt_long(argc, argv, OPT_LIST, long_options, + &opt_index)) != -1) { + + switch (opt) { + /* Standard */ + case 'h': + print_share_file(SHARE_HELP); + exit(EXIT_SUCCESS); + + case 'L': + print_share_file(SHARE_LICENSE); + exit(EXIT_SUCCESS); + + case 'u': + print_share_file(SHARE_USAGE); + exit(EXIT_SUCCESS); + + case 'v': + print_version(); + exit(EXIT_SUCCESS); + + /* Non-standard */ + case 'f': + parse_file(optarg); + break; + + case 'i': + parse_iface(optarg); + break; + + case '?': + /* getopt_long already printed an error message. */ + + default: + print_share_file(SHARE_USAGE); + exit(EXIT_FAILURE); + } + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void parse_file (char* argument) +{ + // FIXME + FILE *fp; + fp = fopen(argument, "r"); + if (!fp) { + printf("--file argument not valid\n"); + printf("It must be a valid file name (relative to saved dir)\n"); + exit(EXIT_FAILURE); + } else { + fclose(fp); + + sprintf(saved_path, ""); + snprintf(saved_name, FILENAME_MAX, "%s", argument); + } +} + +static void parse_iface (char* argument) +{ + menu_iface_mode = atoi(argument); + user_iface_mode = menu_iface_mode; + if (menu_iface_mode < MENU_IFACE_CLUI || menu_iface_mode > MENU_IFACE_TUI) { + printf("--iface argument not valid\n"); + printf("It must be an integer [%i U %i]\n", MENU_IFACE_CLUI, MENU_IFACE_TUI); + exit(EXIT_FAILURE); + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_coins.h b/modules/proc/inc/proc_coins.h index 211971c..7e29d7d 100644 --- a/modules/proc/inc/proc_coins.h +++ b/modules/proc/inc/proc_coins.h @@ -1,48 +1,48 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_PROC_COINS_H
- # define VA_PROC_COINS_H
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Proc_Coins {
- COINS_OK,
- COINS_NOK_COINS,
- COINS_NOK_OVERLAP,
- COINS_NOK_SIZE
- };
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- int proc_coins (void);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* proc_coins.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_COINS_H + # define VA_PROC_COINS_H + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Coins { + COINS_OK, + COINS_NOK_COINS, + COINS_NOK_OVERLAP, + COINS_NOK_SIZE + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_coins (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_coins.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_coins.hpp b/modules/proc/inc/proc_coins.hpp index 5b64870..9315324 100644 --- a/modules/proc/inc/proc_coins.hpp +++ b/modules/proc/inc/proc_coins.hpp @@ -1,60 +1,60 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_PROC_COINS_HPP
- # define VA_PROC_COINS_HPP
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Proc_Coins {
- COINS_OK,
- COINS_NOK_COINS,
- COINS_NOK_OVERLAP,
- COINS_NOK_SIZE
- };
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-extern "C" {
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- int proc_coins (void);
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-} /* extern "C" */
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* proc_coins.hpp */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_COINS_HPP + # define VA_PROC_COINS_HPP + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Coins { + COINS_OK, + COINS_NOK_COINS, + COINS_NOK_OVERLAP, + COINS_NOK_SIZE + }; + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_coins (void); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_coins.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_common.h b/modules/proc/inc/proc_common.h index e0a6e36..1d4077e 100644 --- a/modules/proc/inc/proc_common.h +++ b/modules/proc/inc/proc_common.h @@ -1,45 +1,45 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_PROC_COMMON_H
- # define VA_PROC_COMMON_H
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- void proc_show_img (void);
-
- void clock_start (void);
- void clock_stop (const char *txt);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* proc_common.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_COMMON_H + # define VA_PROC_COMMON_H + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void proc_show_img (void); + + void clock_start (void); + void clock_stop (const char *txt); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_common.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_common.hpp b/modules/proc/inc/proc_common.hpp index 85d5eb3..7332b84 100644 --- a/modules/proc/inc/proc_common.hpp +++ b/modules/proc/inc/proc_common.hpp @@ -1,111 +1,111 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_PROC_COMMON_HPP
- # define VA_PROC_COMMON_HPP
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-extern "C" {
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
-void proc_apply (void);
-void proc_save_mem (int n);
-void proc_load_mem (int n);
-void proc_save_ref (void);
-void proc_save_file (void);
-void proc_save_update (void);
-
-void proc_local_max (void);
-void proc_skeleton (void);
-void proc_lines_vertical (void);
-void proc_median_horizontal (void);
-void proc_median_vertical (void);
-
-void proc_pixel_get (int x, int y, unsigned char *val);
-void proc_pixel_set (int x, int y, unsigned char val);
-void proc_ROI (int x, int y, int w, int h);
-void proc_and_2ref (void);
-void proc_not (void);
-void proc_or_2ref (void);
-void proc_cmp (int cmp);
-void proc_dilate (int size);
-void proc_erode (int size);
-void proc_dilate_erode (int size);
-void proc_erode_dilate (int size);
-void proc_smooth (int method, int ksize);
-void proc_border (int size);
-void proc_rotate (double center_x, double center_y, double angle);
-void proc_adaptive_threshold (int method, int type, int ksize);
-void proc_cvt_color (int method);
-void proc_distance_transform (void);
-void proc_threshold (int type, int ksize);
-void proc_contours (
- std::vector <std::vector <class cv::Point_ <int>>> *contours,
- class cv::Mat *hierarchy);
-void proc_contours_size (
- std::vector <std::vector <class cv::Point_ <int>>> *contours,
- double *area,
- double *perimeter);
-void proc_bounding_rect (
- std::vector <class cv::Point_ <int>> *contour,
- class cv::Rect_ <int> *rect,
- bool show);
-void proc_fit_ellipse (
- std::vector <class cv::Point_ <int>> *contour,
- class cv::RotatedRect *rect,
- bool show);
-void proc_min_area_rect (
- std::vector <class cv::Point_ <int>> *contour,
- class cv::RotatedRect *rect,
- bool show);
-
-void proc_OCR (int lang, int conf);
-void proc_zbar (int type);
-
-void proc_show_img (void);
-
-void clock_start (void);
-void clock_stop (const char *txt);
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-} /* extern "C" */
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* proc_common.hpp */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_COMMON_HPP + # define VA_PROC_COMMON_HPP + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void proc_apply (void); +void proc_save_mem (int n); +void proc_load_mem (int n); +void proc_save_ref (void); +void proc_save_file (void); +void proc_save_update (void); + +void proc_local_max (void); +void proc_skeleton (void); +void proc_lines_vertical (void); +void proc_median_horizontal (void); +void proc_median_vertical (void); + +void proc_pixel_get (int x, int y, unsigned char *val); +void proc_pixel_set (int x, int y, unsigned char val); +void proc_ROI (int x, int y, int w, int h); +void proc_and_2ref (void); +void proc_not (void); +void proc_or_2ref (void); +void proc_cmp (int cmp); +void proc_dilate (int size); +void proc_erode (int size); +void proc_dilate_erode (int size); +void proc_erode_dilate (int size); +void proc_smooth (int method, int ksize); +void proc_border (int size); +void proc_rotate (double center_x, double center_y, double angle); +void proc_adaptive_threshold (int method, int type, int ksize); +void proc_cvt_color (int method); +void proc_distance_transform (void); +void proc_threshold (int type, int ksize); +void proc_contours ( + std::vector <std::vector <class cv::Point_ <int>>> *contours, + class cv::Mat *hierarchy); +void proc_contours_size ( + std::vector <std::vector <class cv::Point_ <int>>> *contours, + double *area, + double *perimeter); +void proc_bounding_rect ( + std::vector <class cv::Point_ <int>> *contour, + class cv::Rect_ <int> *rect, + bool show); +void proc_fit_ellipse ( + std::vector <class cv::Point_ <int>> *contour, + class cv::RotatedRect *rect, + bool show); +void proc_min_area_rect ( + std::vector <class cv::Point_ <int>> *contour, + class cv::RotatedRect *rect, + bool show); + +void proc_OCR (int lang, int conf); +void proc_zbar (int type); + +void proc_show_img (void); + +void clock_start (void); +void clock_stop (const char *txt); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_common.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_iface.h b/modules/proc/inc/proc_iface.h index 7225f25..df62bfb 100644 --- a/modules/proc/inc/proc_iface.h +++ b/modules/proc/inc/proc_iface.h @@ -1,70 +1,70 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_PROC_IFACE_H
- # define VA_PROC_IFACE_H
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Proc_Mode {
- PROC_MODE_FOO,
-
- PROC_MODE = 0x008000u,
- PROC_MODE_LABEL_SERIES,
- PROC_MODE_LABEL_CALIB,
- PROC_MODE_OBJECTS_SERIES,
- PROC_MODE_OBJECTS_CALIB,
- PROC_MODE_COINS_SERIES,
- PROC_MODE_COINS_CALIB,
- PROC_MODE_RESISTOR_SERIES,
- PROC_MODE_RESISTOR_CALIB
- };
-
- enum Proc_DBG {
- PROC_DBG_NO,
- PROC_DBG_STOP_ITEM,
- PROC_DBG_DELAY_STEP,
- PROC_DBG_STOP_STEP
- };
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
- extern int proc_debug;
- extern int proc_mode;
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- int proc_iface_single (int action);
- void proc_iface_series (void);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* proc_iface.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_IFACE_H + # define VA_PROC_IFACE_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Mode { + PROC_MODE_FOO, + + PROC_MODE = 0x008000u, + PROC_MODE_LABEL_SERIES, + PROC_MODE_LABEL_CALIB, + PROC_MODE_OBJECTS_SERIES, + PROC_MODE_OBJECTS_CALIB, + PROC_MODE_COINS_SERIES, + PROC_MODE_COINS_CALIB, + PROC_MODE_RESISTOR_SERIES, + PROC_MODE_RESISTOR_CALIB + }; + + enum Proc_DBG { + PROC_DBG_NO, + PROC_DBG_STOP_ITEM, + PROC_DBG_DELAY_STEP, + PROC_DBG_STOP_STEP + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern int proc_debug; + extern int proc_mode; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_iface_single (int action); + void proc_iface_series (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_iface.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_iface.hpp b/modules/proc/inc/proc_iface.hpp index 941467b..534dec1 100644 --- a/modules/proc/inc/proc_iface.hpp +++ b/modules/proc/inc/proc_iface.hpp @@ -1,82 +1,82 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_PROC_IFACE_H
- # define VA_PROC_IFACE_H
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Proc_Mode {
- PROC_MODE_FOO,
-
- PROC_MODE = 0x008000u,
- PROC_MODE_LABEL_SERIES,
- PROC_MODE_LABEL_CALIB,
- PROC_MODE_OBJECTS_SERIES,
- PROC_MODE_OBJECTS_CALIB,
- PROC_MODE_COINS_SERIES,
- PROC_MODE_COINS_CALIB,
- PROC_MODE_RESISTOR_SERIES,
- PROC_MODE_RESISTOR_CALIB
- };
-
- enum Proc_DBG {
- PROC_DBG_NO,
- PROC_DBG_STOP_ITEM,
- PROC_DBG_DELAY_STEP,
- PROC_DBG_STOP_STEP
- };
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-extern "C" {
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
- extern int proc_debug;
- extern int proc_mode;
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- int proc_iface_single (int action);
- void proc_iface_series (void);
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-} /* extern "C" */
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* proc_iface.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_IFACE_H + # define VA_PROC_IFACE_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Mode { + PROC_MODE_FOO, + + PROC_MODE = 0x008000u, + PROC_MODE_LABEL_SERIES, + PROC_MODE_LABEL_CALIB, + PROC_MODE_OBJECTS_SERIES, + PROC_MODE_OBJECTS_CALIB, + PROC_MODE_COINS_SERIES, + PROC_MODE_COINS_CALIB, + PROC_MODE_RESISTOR_SERIES, + PROC_MODE_RESISTOR_CALIB + }; + + enum Proc_DBG { + PROC_DBG_NO, + PROC_DBG_STOP_ITEM, + PROC_DBG_DELAY_STEP, + PROC_DBG_STOP_STEP + }; + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern int proc_debug; + extern int proc_mode; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_iface_single (int action); + void proc_iface_series (void); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_iface.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_label.h b/modules/proc/inc/proc_label.h index 1792e43..a1091b8 100644 --- a/modules/proc/inc/proc_label.h +++ b/modules/proc/inc/proc_label.h @@ -1,50 +1,50 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_PROC_LABEL_H
- # define VA_PROC_LABEL_H
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Proc_Label {
- LABEL_OK,
- LABEL_NOK_LABEL,
- LABEL_NOK_CERDO,
- LABEL_NOK_BCODE,
- LABEL_NOK_PRODUCT,
- LABEL_NOK_PRICE
- };
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- int proc_label (void);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* proc_label.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_LABEL_H + # define VA_PROC_LABEL_H + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Label { + LABEL_OK, + LABEL_NOK_LABEL, + LABEL_NOK_CERDO, + LABEL_NOK_BCODE, + LABEL_NOK_PRODUCT, + LABEL_NOK_PRICE + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_label (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_label.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_label.hpp b/modules/proc/inc/proc_label.hpp index eb5dd66..b456a55 100644 --- a/modules/proc/inc/proc_label.hpp +++ b/modules/proc/inc/proc_label.hpp @@ -1,62 +1,62 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_PROC_LABEL_HPP
- # define VA_PROC_LABEL_HPP
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Proc_Label {
- LABEL_OK,
- LABEL_NOK_LABEL,
- LABEL_NOK_CERDO,
- LABEL_NOK_BCODE,
- LABEL_NOK_PRODUCT,
- LABEL_NOK_PRICE
- };
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-extern "C" {
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- int proc_label (void);
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-} /* extern "C" */
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* proc_label.hpp */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_LABEL_HPP + # define VA_PROC_LABEL_HPP + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Label { + LABEL_OK, + LABEL_NOK_LABEL, + LABEL_NOK_CERDO, + LABEL_NOK_BCODE, + LABEL_NOK_PRODUCT, + LABEL_NOK_PRICE + }; + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_label (void); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_label.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_objects.h b/modules/proc/inc/proc_objects.h index fb53ac4..be841ba 100644 --- a/modules/proc/inc/proc_objects.h +++ b/modules/proc/inc/proc_objects.h @@ -1,49 +1,49 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_PROC_OBJECTS_H
- # define VA_PROC_OBJECTS_H
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Proc_Objects {
- OBJECTS_OK,
- OBJECTS_NOK_PATTERN,
- OBJECTS_NOK_OBJECTS,
- OBJECTS_NOK_SIZE
- };
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- int proc_objects_calibrate (void);
- int proc_objects (void);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* proc_objects.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_OBJECTS_H + # define VA_PROC_OBJECTS_H + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Objects { + OBJECTS_OK, + OBJECTS_NOK_PATTERN, + OBJECTS_NOK_OBJECTS, + OBJECTS_NOK_SIZE + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_objects_calibrate (void); + int proc_objects (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_objects.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_objects.hpp b/modules/proc/inc/proc_objects.hpp index 300e625..1a3084f 100644 --- a/modules/proc/inc/proc_objects.hpp +++ b/modules/proc/inc/proc_objects.hpp @@ -1,61 +1,61 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_PROC_OBJECTS_HPP
- # define VA_PROC_OBJECTS_HPP
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Proc_Objects {
- OBJECTS_OK,
- OBJECTS_NOK_PATTERN,
- OBJECTS_NOK_OBJECTS,
- OBJECTS_NOK_SIZE
- };
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-extern "C" {
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- int proc_objects_calibrate (void);
- int proc_objects (void);
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-} /* extern "C" */
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* proc_objects.hpp */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_OBJECTS_HPP + # define VA_PROC_OBJECTS_HPP + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Objects { + OBJECTS_OK, + OBJECTS_NOK_PATTERN, + OBJECTS_NOK_OBJECTS, + OBJECTS_NOK_SIZE + }; + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_objects_calibrate (void); + int proc_objects (void); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_objects.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_resistor.h b/modules/proc/inc/proc_resistor.h index 7784ebb..ca60a8a 100644 --- a/modules/proc/inc/proc_resistor.h +++ b/modules/proc/inc/proc_resistor.h @@ -1,50 +1,50 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_PROC_RESISTOR_H
- # define VA_PROC_RESISTOR_H
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Proc_Resistor {
- RESISTOR_OK,
- RESISTOR_NOK_RESISTOR,
- RESISTOR_NOK_BANDS,
- RESISTOR_NOK_COLOR,
- RESISTOR_NOK_STD_VALUE,
- RESISTOR_NOK_TOLERANCE
- };
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- int proc_resistor (void);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* proc_resistor.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_RESISTOR_H + # define VA_PROC_RESISTOR_H + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Resistor { + RESISTOR_OK, + RESISTOR_NOK_RESISTOR, + RESISTOR_NOK_BANDS, + RESISTOR_NOK_COLOR, + RESISTOR_NOK_STD_VALUE, + RESISTOR_NOK_TOLERANCE + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_resistor (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_resistor.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_resistor.hpp b/modules/proc/inc/proc_resistor.hpp index 9982e6f..fce85d8 100644 --- a/modules/proc/inc/proc_resistor.hpp +++ b/modules/proc/inc/proc_resistor.hpp @@ -1,62 +1,62 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_PROC_RESISTOR_HPP
- # define VA_PROC_RESISTOR_HPP
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Proc_Resistor {
- RESISTOR_OK,
- RESISTOR_NOK_RESISTOR,
- RESISTOR_NOK_BANDS,
- RESISTOR_NOK_COLOR,
- RESISTOR_NOK_STD_VALUE,
- RESISTOR_NOK_TOLERANCE
- };
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-extern "C" {
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- int proc_resistor (void);
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-} /* extern "C" */
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* proc_resistor.hpp */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PROC_RESISTOR_HPP + # define VA_PROC_RESISTOR_HPP + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Proc_Resistor { + RESISTOR_OK, + RESISTOR_NOK_RESISTOR, + RESISTOR_NOK_BANDS, + RESISTOR_NOK_COLOR, + RESISTOR_NOK_STD_VALUE, + RESISTOR_NOK_TOLERANCE + }; + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + int proc_resistor (void); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* proc_resistor.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/src/proc_coins.cpp b/modules/proc/src/proc_coins.cpp index 71bbac2..8f26e71 100644 --- a/modules/proc/src/proc_coins.cpp +++ b/modules/proc/src/proc_coins.cpp @@ -1,378 +1,378 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* snprintf() & fflush() */
- #include <cstdio>
-
-/* Packages ------------------------------------------------------------------*/
- /* openCV */
- #include <opencv2/opencv.hpp>
-
-/* libalx ------------------------------------------------------------------*/
- /* alx_maximum_u8() */
- #include "alx_math.hpp"
-
-/* Project -------------------------------------------------------------------*/
- /* constants */
- #include "img_iface.hpp"
- /* user_iface_log */
- #include "user_iface.hpp"
-
-/* Module --------------------------------------------------------------------*/
- #include "proc_common.hpp"
-
- #include "proc_coins.hpp"
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
- # define COINS_MAX 1024
-
-
-/******************************************************************************
- ******* structs **************************************************************
- ******************************************************************************/
-struct Coins_Properties {
- /* position */
- int x;
- int y;
-
- /* value */
- uint8_t diameter_pix;
- double diameter_mm;
- double value;
-};
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-/* Global --------------------------------------------------------------------*/
-
-/* Static --------------------------------------------------------------------*/
-static class std::vector <class std::vector <class cv::Point_ <int>>> contours;
-static class cv::Mat hierarchy;
-static class cv::Rect_ <int> rectangle [COINS_MAX];
-static int coins_n;
-static struct Coins_Properties coins [COINS_MAX];
-static double ratio_mm_per_pix;
-static double value_total;
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void result_coins (int status);
-
-static void coins_segmentate (void);
-static int coins_positions (void);
-static void coins_diameters_pix (void);
-static void calibrate_mm_per_pix (void);
-static void coins_diameters_mm (void);
-static int coins_values (void);
-static double coin_value (double diameter_mm);
-static void coins_total_value (void);
-
-
-/******************************************************************************
- ******* global functions *****************************************************
- ******************************************************************************/
-int proc_coins (void)
-{
- int status;
-
- proc_save_mem(0);
- /* Segmentate coins */
- {
- /* Measure time */
- clock_start();
-
- coins_segmentate();
-
- /* Measure time */
- clock_stop("Segmentate coins");
- }
- /* Find coins positions */
- {
- /* Measure time */
- clock_start();
-
- status = coins_positions();
- if (status) {
- result_coins(status);
- return status;
- }
-
- /* Measure time */
- clock_stop("Find coins positions");
- }
- /* Get coin diameters in pixels */
- {
- /* Measure time */
- clock_start();
-
- coins_diameters_pix();
-
- /* Measure time */
- clock_stop("Coins diameters in pixels");
- }
- /* Calibrate with the biggest coin; every img should have a 2 € coin */
- {
- /* Measure time */
- clock_start();
-
- calibrate_mm_per_pix();
-
- /* Measure time */
- clock_stop("Calibrate (mm per pix)");
- }
- /* Get coins diameters in mm */
- {
- /* Measure time */
- clock_start();
-
- coins_diameters_mm();
-
- /* Measure time */
- clock_stop("Coins diameters in mm");
- }
- /* Get coins values (by their sizes) */
- {
- /* Measure time */
- clock_start();
-
- status = coins_values();
- if (status) {
- result_coins(status);
- return status;
- }
-
- /* Measure time */
- clock_stop("Coins values");
- }
- /* Add total value */
- {
- /* Measure time */
- clock_start();
-
- coins_total_value();
-
- /* Measure time */
- clock_stop("Total value");
- }
-
- status = COINS_OK;
- result_coins(status);
- return status;
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void result_coins (int status)
-{
- /* Cleanup */
-
- /* Write result into log */
- switch (status) {
- case COINS_OK:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Coin: OK");
- break;
- case COINS_NOK_COINS:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Coin: NOK_COINS");
- break;
-#if 0
- case COINS_NOK_OVERLAP:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Coin: NOK_OVERLAP");
- break;
-#endif
- case COINS_NOK_SIZE:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Coin: NOK_SIZE");
- break;
- default:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Coin: NOK");
- break;
- }
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-}
-
-static void coins_segmentate (void)
-{
- proc_load_mem(0);
-
- proc_cmp(IMG_IFACE_CMP_BLUE);
- proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU);
- proc_distance_transform();
- proc_local_max();
- proc_dilate(6);
- proc_save_mem(1);
-}
-
-static int coins_positions (void)
-{
- int status;
- int i;
-
- proc_load_mem(1);
-
- proc_contours(&contours, &hierarchy);
- coins_n = contours.size();
-
- /* If no contour is found, error: NOK_COINS */
- if (!coins_n) {
- status = COINS_NOK_COINS;
- return status;
- }
-
- /* Get position of each contour */
- for (i = 0; i < coins_n; i++) {
- proc_bounding_rect(&(contours[i]), &(rectangle[i]), true);
- coins[i].x = rectangle[i].x + rectangle[i].width / 2.0;
- coins[i].y = rectangle[i].y + rectangle[i].height / 2.0;
- }
-
- status = COINS_OK;
- return status;
-}
-
-static void coins_diameters_pix (void)
-{
- int i;
-
- proc_load_mem(1);
-
- /* Get coins diameters in pixels */
- for (i = 0; i < coins_n; i++) {
- proc_pixel_get(coins[i].x, coins[i].y,
- &(coins[i].diameter_pix));
- coins[i].diameter_pix *= 2;
- }
-}
-
-static void calibrate_mm_per_pix (void)
-{
- uint8_t coins_size_pix [coins_n];
- int i;
- int max_pos;
- int max_size;
-
- for (i = 0; i < coins_n; i++) {
- coins_size_pix[i] = coins[i].diameter_pix;
- }
-
- max_pos = alx_maximum_u8(coins_n, coins_size_pix);
- max_size = coins_size_pix[max_pos];
- ratio_mm_per_pix = 25.75 / max_size;
-}
-
-static void coins_diameters_mm (void)
-{
- int i;
-
- for (i = 0; i < coins_n; i++) {
- coins[i].diameter_mm = ratio_mm_per_pix *
- coins[i].diameter_pix;
-
- /* Write diameters into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Coin[%i]: %.2lf mm",
- i,
- coins[i].diameter_mm);
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
- }
-}
-
-static int coins_values (void)
-{
- int status;
- int i;
-
- for (i = 0; i < coins_n; i++) {
- coins[i].value = coin_value(coins[i].diameter_mm);
-
- /* If a coin is of invalid size, error: NOK_SIZE */
- if (coins[i].value < 0) {
- status = COINS_NOK_SIZE;
- return status;
- }
-
- /* Write values into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Coin[%i]: %.2lf EUR",
- i,
- coins[i].value);
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
- }
-
- status = COINS_OK;
- return status;
-}
-
-static double coin_value (double diameter_mm)
-{
- double value;
-
- /* Get coin value by its diameter in mm */
- if (diameter_mm > 27.00) {
- value = -1;
- } else if (diameter_mm > 25.00) {
- value = 2.00;
- } else if (diameter_mm > 23.75) {
- value = 0.50;
- } else if (diameter_mm > 22.75) {
- value = 1.00;
- } else if (diameter_mm > 21.75) {
- value = 0.20;
- } else if (diameter_mm > 20.50) {
- value = 0.05;
- } else if (diameter_mm > 19.25) {
- value = 0.10;
- } else if (diameter_mm > 17.50) {
- value = 0.02;
- } else if (diameter_mm > 15.00) {
- value = 0.01;
- } else {
- value = -1;
- }
-
- return value;
-}
-
-static void coins_total_value (void)
-{
- int i;
-
- value_total = 0.00;
-
- for (i = 0; i < coins_n; i++) {
- value_total += coins[i].value;
- }
-
- /* Write total value into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Total value: %.2lf EUR",
- value_total);
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* snprintf() & fflush() */ + #include <cstdio> + +/* Packages ------------------------------------------------------------------*/ + /* openCV */ + #include <opencv2/opencv.hpp> + +/* libalx ------------------------------------------------------------------*/ + /* alx_maximum_u8() */ + #include "alx_math.hpp" + +/* Project -------------------------------------------------------------------*/ + /* constants */ + #include "img_iface.hpp" + /* user_iface_log */ + #include "user_iface.hpp" + +/* Module --------------------------------------------------------------------*/ + #include "proc_common.hpp" + + #include "proc_coins.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define COINS_MAX 1024 + + +/****************************************************************************** + ******* structs ************************************************************** + ******************************************************************************/ +struct Coins_Properties { + /* position */ + int x; + int y; + + /* value */ + uint8_t diameter_pix; + double diameter_mm; + double value; +}; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ + +/* Static --------------------------------------------------------------------*/ +static class std::vector <class std::vector <class cv::Point_ <int>>> contours; +static class cv::Mat hierarchy; +static class cv::Rect_ <int> rectangle [COINS_MAX]; +static int coins_n; +static struct Coins_Properties coins [COINS_MAX]; +static double ratio_mm_per_pix; +static double value_total; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_coins (int status); + +static void coins_segmentate (void); +static int coins_positions (void); +static void coins_diameters_pix (void); +static void calibrate_mm_per_pix (void); +static void coins_diameters_mm (void); +static int coins_values (void); +static double coin_value (double diameter_mm); +static void coins_total_value (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +int proc_coins (void) +{ + int status; + + proc_save_mem(0); + /* Segmentate coins */ + { + /* Measure time */ + clock_start(); + + coins_segmentate(); + + /* Measure time */ + clock_stop("Segmentate coins"); + } + /* Find coins positions */ + { + /* Measure time */ + clock_start(); + + status = coins_positions(); + if (status) { + result_coins(status); + return status; + } + + /* Measure time */ + clock_stop("Find coins positions"); + } + /* Get coin diameters in pixels */ + { + /* Measure time */ + clock_start(); + + coins_diameters_pix(); + + /* Measure time */ + clock_stop("Coins diameters in pixels"); + } + /* Calibrate with the biggest coin; every img should have a 2 € coin */ + { + /* Measure time */ + clock_start(); + + calibrate_mm_per_pix(); + + /* Measure time */ + clock_stop("Calibrate (mm per pix)"); + } + /* Get coins diameters in mm */ + { + /* Measure time */ + clock_start(); + + coins_diameters_mm(); + + /* Measure time */ + clock_stop("Coins diameters in mm"); + } + /* Get coins values (by their sizes) */ + { + /* Measure time */ + clock_start(); + + status = coins_values(); + if (status) { + result_coins(status); + return status; + } + + /* Measure time */ + clock_stop("Coins values"); + } + /* Add total value */ + { + /* Measure time */ + clock_start(); + + coins_total_value(); + + /* Measure time */ + clock_stop("Total value"); + } + + status = COINS_OK; + result_coins(status); + return status; +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_coins (int status) +{ + /* Cleanup */ + + /* Write result into log */ + switch (status) { + case COINS_OK: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: OK"); + break; + case COINS_NOK_COINS: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK_COINS"); + break; +#if 0 + case COINS_NOK_OVERLAP: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK_OVERLAP"); + break; +#endif + case COINS_NOK_SIZE: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK_SIZE"); + break; + default: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK"); + break; + } + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + +static void coins_segmentate (void) +{ + proc_load_mem(0); + + proc_cmp(IMG_IFACE_CMP_BLUE); + proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU); + proc_distance_transform(); + proc_local_max(); + proc_dilate(6); + proc_save_mem(1); +} + +static int coins_positions (void) +{ + int status; + int i; + + proc_load_mem(1); + + proc_contours(&contours, &hierarchy); + coins_n = contours.size(); + + /* If no contour is found, error: NOK_COINS */ + if (!coins_n) { + status = COINS_NOK_COINS; + return status; + } + + /* Get position of each contour */ + for (i = 0; i < coins_n; i++) { + proc_bounding_rect(&(contours[i]), &(rectangle[i]), true); + coins[i].x = rectangle[i].x + rectangle[i].width / 2.0; + coins[i].y = rectangle[i].y + rectangle[i].height / 2.0; + } + + status = COINS_OK; + return status; +} + +static void coins_diameters_pix (void) +{ + int i; + + proc_load_mem(1); + + /* Get coins diameters in pixels */ + for (i = 0; i < coins_n; i++) { + proc_pixel_get(coins[i].x, coins[i].y, + &(coins[i].diameter_pix)); + coins[i].diameter_pix *= 2; + } +} + +static void calibrate_mm_per_pix (void) +{ + uint8_t coins_size_pix [coins_n]; + int i; + int max_pos; + int max_size; + + for (i = 0; i < coins_n; i++) { + coins_size_pix[i] = coins[i].diameter_pix; + } + + max_pos = alx_maximum_u8(coins_n, coins_size_pix); + max_size = coins_size_pix[max_pos]; + ratio_mm_per_pix = 25.75 / max_size; +} + +static void coins_diameters_mm (void) +{ + int i; + + for (i = 0; i < coins_n; i++) { + coins[i].diameter_mm = ratio_mm_per_pix * + coins[i].diameter_pix; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin[%i]: %.2lf mm", + i, + coins[i].diameter_mm); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + } +} + +static int coins_values (void) +{ + int status; + int i; + + for (i = 0; i < coins_n; i++) { + coins[i].value = coin_value(coins[i].diameter_mm); + + /* If a coin is of invalid size, error: NOK_SIZE */ + if (coins[i].value < 0) { + status = COINS_NOK_SIZE; + return status; + } + + /* Write values into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin[%i]: %.2lf EUR", + i, + coins[i].value); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + } + + status = COINS_OK; + return status; +} + +static double coin_value (double diameter_mm) +{ + double value; + + /* Get coin value by its diameter in mm */ + if (diameter_mm > 27.00) { + value = -1; + } else if (diameter_mm > 25.00) { + value = 2.00; + } else if (diameter_mm > 23.75) { + value = 0.50; + } else if (diameter_mm > 22.75) { + value = 1.00; + } else if (diameter_mm > 21.75) { + value = 0.20; + } else if (diameter_mm > 20.50) { + value = 0.05; + } else if (diameter_mm > 19.25) { + value = 0.10; + } else if (diameter_mm > 17.50) { + value = 0.02; + } else if (diameter_mm > 15.00) { + value = 0.01; + } else { + value = -1; + } + + return value; +} + +static void coins_total_value (void) +{ + int i; + + value_total = 0.00; + + for (i = 0; i < coins_n; i++) { + value_total += coins[i].value; + } + + /* Write total value into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Total value: %.2lf EUR", + value_total); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/src/proc_common.cpp b/modules/proc/src/proc_common.cpp index 86c137a..96b66f1 100644 --- a/modules/proc/src/proc_common.cpp +++ b/modules/proc/src/proc_common.cpp @@ -1,432 +1,432 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- #include <cstddef>
- /* snprintf() & fflush() */
- #include <cstdio>
- /* clock_t & clock() & CLOCKS_PER_SEC */
- #include <ctime>
-
-/* Packages ------------------------------------------------------------------*/
- /* openCV */
- #include <opencv2/opencv.hpp>
- /* enum zbar::zbar_symbol_type_e */
- #include <zbar.h>
-
-/* Project -------------------------------------------------------------------*/
- /* img_iface_act() */
- #include "img_iface.hpp"
- /* user_iface_log */
- #include "user_iface.hpp"
-
-/* Module --------------------------------------------------------------------*/
- /* enum Proc_DBG */
- #include "proc_iface.hpp"
-
- #include "proc_common.hpp"
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-/* Global --------------------------------------------------------------------*/
-
-/* Static --------------------------------------------------------------------*/
-static clock_t clock_0;
-static clock_t clock_1;
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* global functions *****************************************************
- ******************************************************************************/
-void proc_apply (void)
-{
- img_iface_act(IMG_IFACE_ACT_APPLY, NULL);
-}
-
-void proc_save_mem (int n)
-{
- img_iface_act(IMG_IFACE_ACT_SAVE_MEM, (void *)&n);
-}
-
-void proc_load_mem (int n)
-{
- img_iface_act(IMG_IFACE_ACT_LOAD_MEM, (void *)&n);
-
- proc_show_img();
-}
-
-void proc_save_ref (void)
-{
- img_iface_act(IMG_IFACE_ACT_SAVE_REF, NULL);
-}
-
-void proc_save_file (void)
-{
- img_iface_act(IMG_IFACE_ACT_SAVE_FILE, NULL);
-}
-
-void proc_save_update (void)
-{
- img_iface_act(IMG_IFACE_ACT_SAVE_UPDT, NULL);
-}
-
-void proc_local_max (void)
-{
- img_iface_act(IMG_IFACE_ACT_LOCAL_MAX, NULL);
-
- proc_show_img();
-}
-
-void proc_skeleton (void)
-{
- img_iface_act(IMG_IFACE_ACT_SKELETON, NULL);
-
- proc_show_img();
-}
-
-void proc_lines_vertical (void)
-{
- img_iface_act(IMG_IFACE_ACT_LINES_VERTICAL, NULL);
-
- proc_show_img();
-}
-
-void proc_median_horizontal (void)
-{
- img_iface_act(IMG_IFACE_ACT_MEDIAN_HORIZONTAL, NULL);
-
- proc_show_img();
-}
-
-void proc_median_vertical (void)
-{
- img_iface_act(IMG_IFACE_ACT_MEDIAN_VERTICAL, NULL);
-
- proc_show_img();
-}
-
-void proc_pixel_get (int x, int y, unsigned char *val)
-{
- struct Img_Iface_Data_Pixel_Get data;
- data.x = x;
- data.y = y;
- data.val = val;
- img_iface_act(IMG_IFACE_ACT_PIXEL_GET, (void *)&data);
-}
-
-void proc_pixel_set (int x, int y, unsigned char val)
-{
- struct Img_Iface_Data_Pixel_Set data;
- data.x = x;
- data.y = y;
- data.val = val;
- img_iface_act(IMG_IFACE_ACT_PIXEL_SET, (void *)&data);
-}
-
-void proc_ROI (int x, int y, int w, int h)
-{
- struct Img_Iface_Data_SetROI data;
-
- data.rect.x = x;
- data.rect.y = y;
- data.rect.width = w;
- data.rect.height = h;
- img_iface_act(IMG_IFACE_ACT_SET_ROI, (void *)&data);
-
- proc_show_img();
-}
-
-void proc_and_2ref (void)
-{
- img_iface_act(USER_IFACE_ACT_AND_2REF, NULL);
-
- proc_show_img();
-}
-
-void proc_not (void)
-{
- img_iface_act(USER_IFACE_ACT_NOT, NULL);
-
- proc_show_img();
-}
-
-void proc_or_2ref (void)
-{
- img_iface_act(USER_IFACE_ACT_OR_2REF, NULL);
-
- proc_show_img();
-}
-
-void proc_cmp (int cmp)
-{
- struct Img_Iface_Data_Component data;
-
- data.cmp = cmp;
- img_iface_act(IMG_IFACE_ACT_COMPONENT, (void *)&data);
-
- proc_show_img();
-}
-
-void proc_dilate (int size)
-{
- struct Img_Iface_Data_Dilate_Erode data;
-
- data.i = size;
- img_iface_act(IMG_IFACE_ACT_DILATE, (void *)&data);
-
- proc_show_img();
-}
-
-void proc_erode (int size)
-{
- struct Img_Iface_Data_Dilate_Erode data;
-
- data.i = size;
- img_iface_act(IMG_IFACE_ACT_ERODE, (void *)&data);
-
- proc_show_img();
-}
-
-void proc_dilate_erode (int size)
-{
- struct Img_Iface_Data_Dilate_Erode data;
-
- data.i = size;
- img_iface_act(IMG_IFACE_ACT_DILATE_ERODE, (void *)&data);
-
- proc_show_img();
-}
-
-void proc_erode_dilate (int size)
-{
- struct Img_Iface_Data_Dilate_Erode data;
-
- data.i = size;
- img_iface_act(IMG_IFACE_ACT_ERODE_DILATE, (void *)&data);
-
- proc_show_img();
-}
-
-void proc_smooth (int method, int ksize)
-{
- struct Img_Iface_Data_Smooth data;
-
- data.method = method;
- data.ksize = ksize;
- img_iface_act(IMG_IFACE_ACT_SMOOTH, (void *)&data);
-
- proc_show_img();
-}
-
-void proc_border (int size)
-{
- struct Img_Iface_Data_Border data;
-
- data.size = size;
- img_iface_act(IMG_IFACE_ACT_BORDER, (void *)&data);
-
- proc_show_img();
-}
-
-void proc_rotate (double center_x, double center_y, double angle)
-{
- struct Img_Iface_Data_Rotate data;
-
- data.center.x = center_x;
- data.center.y = center_y;
- data.angle = angle;
- img_iface_act(IMG_IFACE_ACT_ROTATE, (void *)&data);
-
- proc_show_img();
-}
-
-void proc_adaptive_threshold (int method, int type, int ksize)
-{
- struct Img_Iface_Data_Adaptive_Thr data;
-
- data.method = method;
- data.thr_typ = type;
- data.ksize = ksize;
- img_iface_act(USER_IFACE_ACT_ADAPTIVE_THRESHOLD, (void *)&data);
-
- proc_show_img();
-}
-
-void proc_cvt_color (int method)
-{
- struct Img_Iface_Data_Cvt_Color data;
-
- data.method = method;
- img_iface_act(IMG_IFACE_ACT_CVT_COLOR, (void *)&data);
-
- proc_show_img();
-}
-
-void proc_threshold (int type, int size)
-{
- struct Img_Iface_Data_Threshold data;
-
- data.thr_typ = type;
- data.thr_val = size;
- img_iface_act(IMG_IFACE_ACT_THRESHOLD, (void *)&data);
-
- proc_show_img();
-}
-
-void proc_distance_transform (void)
-{
- img_iface_act(IMG_IFACE_ACT_DISTANCE_TRANSFORM, NULL);
-
- proc_show_img();
-}
-
-void proc_contours (
- class std::vector <class std::vector <class cv::Point_ <int>>> *contours,
- class cv::Mat *hierarchy
-)
-{
- struct Img_Iface_Data_Contours data;
-
- data.contours = contours;
- data.hierarchy = hierarchy;
-
- img_iface_act(IMG_IFACE_ACT_CONTOURS, (void *)&data);
-
- proc_show_img();
-}
-
-void proc_contours_size (
- class std::vector <class std::vector <class cv::Point_ <int>>> *contours,
- double *area,
- double *perimeter
-)
-{
- struct Img_Iface_Data_Contours_Size data;
-
- data.contours = contours;
- data.area = area;
- data.perimeter = perimeter;
- img_iface_act(IMG_IFACE_ACT_CONTOURS_SIZE, (void *)&data);
-}
-
-void proc_bounding_rect (
- class std::vector <class cv::Point_ <int>> *contour,
- class cv::Rect_ <int> *rect,
- bool show
-)
-{
- struct Img_Iface_Data_Bounding_Rect data;
-
- data.contour = contour;
- data.rect = rect;
- data.show = show;
- img_iface_act(IMG_IFACE_ACT_BOUNDING_RECT, (void *)&data);
-
- if (show) {
- proc_show_img();
- }
-}
-
-void proc_fit_ellipse (
- class std::vector <class cv::Point_ <int>> *contour,
- class cv::RotatedRect *rect,
- bool show
-)
-{
- struct Img_Iface_Data_MinARect data;
-
- data.contour = contour;
- data.rect = rect;
- data.show = show;
- img_iface_act(IMG_IFACE_ACT_FIT_ELLIPSE, (void *)&data);
-
-
- if (show) {
- proc_show_img();
- }
-}
-
-void proc_min_area_rect (
- class std::vector <class cv::Point_ <int>> *contour,
- class cv::RotatedRect *rect,
- bool show
-)
-{
- struct Img_Iface_Data_MinARect data;
-
- data.contour = contour;
- data.rect = rect;
- data.show = show;
- img_iface_act(IMG_IFACE_ACT_MIN_AREA_RECT, (void *)&data);
-
- if (show) {
- proc_show_img();
- }
-}
-
-void proc_OCR (int lang, int conf)
-{
- struct Img_Iface_Data_Read data;
-
- data.lang = lang; /* eng=0, spa=1, cat=2 */
- data.conf = conf; /* none=0, price=1 */
- img_iface_act(IMG_IFACE_ACT_READ, (void *)&data);
-}
-
-void proc_zbar (int type)
-{
- struct Img_Iface_Data_Decode data;
-
- data.code_type = (enum zbar::zbar_symbol_type_e)type;
- img_iface_act(IMG_IFACE_ACT_DECODE, (void *)&data);
-}
-
-void proc_show_img (void)
-{
- if (proc_debug >= PROC_DBG_DELAY_STEP) {
- img_iface_show_img();
-
- if (proc_debug >= PROC_DBG_STOP_STEP) {
- getchar();
- }
- }
-}
-
-void clock_start (void)
-{
- clock_0 = clock();
-}
-
-void clock_stop (const char *txt)
-{
- clock_t clock_diff;
- double time_diff;
-
- clock_1 = clock();
- clock_diff = clock_1 - clock_0;
- time_diff = (double)clock_diff / (double)CLOCKS_PER_SEC;
-
- /* Write time_diff into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Time: %.3lf (%s)",
- time_diff, txt);
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + #include <cstddef> + /* snprintf() & fflush() */ + #include <cstdio> + /* clock_t & clock() & CLOCKS_PER_SEC */ + #include <ctime> + +/* Packages ------------------------------------------------------------------*/ + /* openCV */ + #include <opencv2/opencv.hpp> + /* enum zbar::zbar_symbol_type_e */ + #include <zbar.h> + +/* Project -------------------------------------------------------------------*/ + /* img_iface_act() */ + #include "img_iface.hpp" + /* user_iface_log */ + #include "user_iface.hpp" + +/* Module --------------------------------------------------------------------*/ + /* enum Proc_DBG */ + #include "proc_iface.hpp" + + #include "proc_common.hpp" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ + +/* Static --------------------------------------------------------------------*/ +static clock_t clock_0; +static clock_t clock_1; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void proc_apply (void) +{ + img_iface_act(IMG_IFACE_ACT_APPLY, NULL); +} + +void proc_save_mem (int n) +{ + img_iface_act(IMG_IFACE_ACT_SAVE_MEM, (void *)&n); +} + +void proc_load_mem (int n) +{ + img_iface_act(IMG_IFACE_ACT_LOAD_MEM, (void *)&n); + + proc_show_img(); +} + +void proc_save_ref (void) +{ + img_iface_act(IMG_IFACE_ACT_SAVE_REF, NULL); +} + +void proc_save_file (void) +{ + img_iface_act(IMG_IFACE_ACT_SAVE_FILE, NULL); +} + +void proc_save_update (void) +{ + img_iface_act(IMG_IFACE_ACT_SAVE_UPDT, NULL); +} + +void proc_local_max (void) +{ + img_iface_act(IMG_IFACE_ACT_LOCAL_MAX, NULL); + + proc_show_img(); +} + +void proc_skeleton (void) +{ + img_iface_act(IMG_IFACE_ACT_SKELETON, NULL); + + proc_show_img(); +} + +void proc_lines_vertical (void) +{ + img_iface_act(IMG_IFACE_ACT_LINES_VERTICAL, NULL); + + proc_show_img(); +} + +void proc_median_horizontal (void) +{ + img_iface_act(IMG_IFACE_ACT_MEDIAN_HORIZONTAL, NULL); + + proc_show_img(); +} + +void proc_median_vertical (void) +{ + img_iface_act(IMG_IFACE_ACT_MEDIAN_VERTICAL, NULL); + + proc_show_img(); +} + +void proc_pixel_get (int x, int y, unsigned char *val) +{ + struct Img_Iface_Data_Pixel_Get data; + data.x = x; + data.y = y; + data.val = val; + img_iface_act(IMG_IFACE_ACT_PIXEL_GET, (void *)&data); +} + +void proc_pixel_set (int x, int y, unsigned char val) +{ + struct Img_Iface_Data_Pixel_Set data; + data.x = x; + data.y = y; + data.val = val; + img_iface_act(IMG_IFACE_ACT_PIXEL_SET, (void *)&data); +} + +void proc_ROI (int x, int y, int w, int h) +{ + struct Img_Iface_Data_SetROI data; + + data.rect.x = x; + data.rect.y = y; + data.rect.width = w; + data.rect.height = h; + img_iface_act(IMG_IFACE_ACT_SET_ROI, (void *)&data); + + proc_show_img(); +} + +void proc_and_2ref (void) +{ + img_iface_act(USER_IFACE_ACT_AND_2REF, NULL); + + proc_show_img(); +} + +void proc_not (void) +{ + img_iface_act(USER_IFACE_ACT_NOT, NULL); + + proc_show_img(); +} + +void proc_or_2ref (void) +{ + img_iface_act(USER_IFACE_ACT_OR_2REF, NULL); + + proc_show_img(); +} + +void proc_cmp (int cmp) +{ + struct Img_Iface_Data_Component data; + + data.cmp = cmp; + img_iface_act(IMG_IFACE_ACT_COMPONENT, (void *)&data); + + proc_show_img(); +} + +void proc_dilate (int size) +{ + struct Img_Iface_Data_Dilate_Erode data; + + data.i = size; + img_iface_act(IMG_IFACE_ACT_DILATE, (void *)&data); + + proc_show_img(); +} + +void proc_erode (int size) +{ + struct Img_Iface_Data_Dilate_Erode data; + + data.i = size; + img_iface_act(IMG_IFACE_ACT_ERODE, (void *)&data); + + proc_show_img(); +} + +void proc_dilate_erode (int size) +{ + struct Img_Iface_Data_Dilate_Erode data; + + data.i = size; + img_iface_act(IMG_IFACE_ACT_DILATE_ERODE, (void *)&data); + + proc_show_img(); +} + +void proc_erode_dilate (int size) +{ + struct Img_Iface_Data_Dilate_Erode data; + + data.i = size; + img_iface_act(IMG_IFACE_ACT_ERODE_DILATE, (void *)&data); + + proc_show_img(); +} + +void proc_smooth (int method, int ksize) +{ + struct Img_Iface_Data_Smooth data; + + data.method = method; + data.ksize = ksize; + img_iface_act(IMG_IFACE_ACT_SMOOTH, (void *)&data); + + proc_show_img(); +} + +void proc_border (int size) +{ + struct Img_Iface_Data_Border data; + + data.size = size; + img_iface_act(IMG_IFACE_ACT_BORDER, (void *)&data); + + proc_show_img(); +} + +void proc_rotate (double center_x, double center_y, double angle) +{ + struct Img_Iface_Data_Rotate data; + + data.center.x = center_x; + data.center.y = center_y; + data.angle = angle; + img_iface_act(IMG_IFACE_ACT_ROTATE, (void *)&data); + + proc_show_img(); +} + +void proc_adaptive_threshold (int method, int type, int ksize) +{ + struct Img_Iface_Data_Adaptive_Thr data; + + data.method = method; + data.thr_typ = type; + data.ksize = ksize; + img_iface_act(USER_IFACE_ACT_ADAPTIVE_THRESHOLD, (void *)&data); + + proc_show_img(); +} + +void proc_cvt_color (int method) +{ + struct Img_Iface_Data_Cvt_Color data; + + data.method = method; + img_iface_act(IMG_IFACE_ACT_CVT_COLOR, (void *)&data); + + proc_show_img(); +} + +void proc_threshold (int type, int size) +{ + struct Img_Iface_Data_Threshold data; + + data.thr_typ = type; + data.thr_val = size; + img_iface_act(IMG_IFACE_ACT_THRESHOLD, (void *)&data); + + proc_show_img(); +} + +void proc_distance_transform (void) +{ + img_iface_act(IMG_IFACE_ACT_DISTANCE_TRANSFORM, NULL); + + proc_show_img(); +} + +void proc_contours ( + class std::vector <class std::vector <class cv::Point_ <int>>> *contours, + class cv::Mat *hierarchy +) +{ + struct Img_Iface_Data_Contours data; + + data.contours = contours; + data.hierarchy = hierarchy; + + img_iface_act(IMG_IFACE_ACT_CONTOURS, (void *)&data); + + proc_show_img(); +} + +void proc_contours_size ( + class std::vector <class std::vector <class cv::Point_ <int>>> *contours, + double *area, + double *perimeter +) +{ + struct Img_Iface_Data_Contours_Size data; + + data.contours = contours; + data.area = area; + data.perimeter = perimeter; + img_iface_act(IMG_IFACE_ACT_CONTOURS_SIZE, (void *)&data); +} + +void proc_bounding_rect ( + class std::vector <class cv::Point_ <int>> *contour, + class cv::Rect_ <int> *rect, + bool show +) +{ + struct Img_Iface_Data_Bounding_Rect data; + + data.contour = contour; + data.rect = rect; + data.show = show; + img_iface_act(IMG_IFACE_ACT_BOUNDING_RECT, (void *)&data); + + if (show) { + proc_show_img(); + } +} + +void proc_fit_ellipse ( + class std::vector <class cv::Point_ <int>> *contour, + class cv::RotatedRect *rect, + bool show +) +{ + struct Img_Iface_Data_MinARect data; + + data.contour = contour; + data.rect = rect; + data.show = show; + img_iface_act(IMG_IFACE_ACT_FIT_ELLIPSE, (void *)&data); + + + if (show) { + proc_show_img(); + } +} + +void proc_min_area_rect ( + class std::vector <class cv::Point_ <int>> *contour, + class cv::RotatedRect *rect, + bool show +) +{ + struct Img_Iface_Data_MinARect data; + + data.contour = contour; + data.rect = rect; + data.show = show; + img_iface_act(IMG_IFACE_ACT_MIN_AREA_RECT, (void *)&data); + + if (show) { + proc_show_img(); + } +} + +void proc_OCR (int lang, int conf) +{ + struct Img_Iface_Data_Read data; + + data.lang = lang; /* eng=0, spa=1, cat=2 */ + data.conf = conf; /* none=0, price=1 */ + img_iface_act(IMG_IFACE_ACT_READ, (void *)&data); +} + +void proc_zbar (int type) +{ + struct Img_Iface_Data_Decode data; + + data.code_type = (enum zbar::zbar_symbol_type_e)type; + img_iface_act(IMG_IFACE_ACT_DECODE, (void *)&data); +} + +void proc_show_img (void) +{ + if (proc_debug >= PROC_DBG_DELAY_STEP) { + img_iface_show_img(); + + if (proc_debug >= PROC_DBG_STOP_STEP) { + getchar(); + } + } +} + +void clock_start (void) +{ + clock_0 = clock(); +} + +void clock_stop (const char *txt) +{ + clock_t clock_diff; + double time_diff; + + clock_1 = clock(); + clock_diff = clock_1 - clock_0; + time_diff = (double)clock_diff / (double)CLOCKS_PER_SEC; + + /* Write time_diff into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Time: %.3lf (%s)", + time_diff, txt); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/src/proc_iface.c b/modules/proc/src/proc_iface.c index a90466e..240b766 100644 --- a/modules/proc/src/proc_iface.c +++ b/modules/proc/src/proc_iface.c @@ -1,215 +1,215 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* errno */
- #include <errno.h>
- #include <stdbool.h>
- /* snprintf() & fflush() */
- #include <stdio.h>
- /* clock_t & clock() & CLOCKS_PER_SEC */
- #include <time.h>
-
-/* libalx -------------------------------------------------------------------*/
- /* alx_sscan_fname() */
- #include "alx_input.h"
-
-/* Project -------------------------------------------------------------------*/
- /* img_iface_load() */
- #include "img_iface.h"
- /* user_iface_log */
- #include "user_iface.h"
- /* saved_path */
- #include "save.h"
-
-/* Module --------------------------------------------------------------------*/
- #include "proc_label.h"
- #include "proc_objects.h"
- #include "proc_coins.h"
- #include "proc_resistor.h"
- #include "proc_common.h"
-
- #include "proc_iface.h"
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-/* Global --------------------------------------------------------------------*/
- int proc_debug;
- int proc_mode;
-
-/* Static --------------------------------------------------------------------*/
-static char proc_path [FILENAME_MAX];
-static char proc_fail_path [FILENAME_MAX];
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* global functions *****************************************************
- ******************************************************************************/
-int proc_iface_single (int action)
-{
- int error;
- clock_t time_0;
- clock_t time_1;
- double time_tot;
-
- /* Init timer */
- time_0 = clock();
-
- /* Process */
- switch (action) {
- case PROC_MODE_LABEL_SERIES:
- error = proc_label();
- break;
- case PROC_MODE_OBJECTS_CALIB:
- error = proc_objects_calibrate();
- break;
- case PROC_MODE_OBJECTS_SERIES:
- error = proc_objects();
- break;
- case PROC_MODE_COINS_SERIES:
- error = proc_coins();
- break;
- case PROC_MODE_RESISTOR_SERIES:
- error = proc_resistor();
- break;
- default:
- error = -1;
- }
-
- /* End timer */
- time_1 = clock();
-
- /* Calculate time in seconds */
- time_tot = ((double) time_1 - time_0) / CLOCKS_PER_SEC;
-
- /* Write time into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Item total time: %.3lf",
- time_tot);
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-
- return error;
-}
-
-void proc_iface_series (void)
-{
- bool file_error;
- int num_len;
- char file_basename [FILENAME_MAX];
- char file_ext [80];
- char file_name [FILENAME_MAX];
- bool proc_error;
- char save_error_as [FILENAME_MAX];
- bool wh;
- /* if i starts being 0, the camera needs calibration */
- int i;
-
- switch (proc_mode) {
- case PROC_MODE_LABEL_SERIES:
- snprintf(proc_path, FILENAME_MAX, "%s", labels_path);
- snprintf(proc_fail_path, FILENAME_MAX, "%s", labels_fail_path);
- snprintf(file_basename, 80, "b");
- num_len = 4;
- snprintf(file_ext, 80, ".BMP");
- i = 1;
- break;
- case PROC_MODE_OBJECTS_SERIES:
- snprintf(proc_path, FILENAME_MAX, "%s", objects_path);
- snprintf(proc_fail_path, FILENAME_MAX, "%s", objects_fail_path);
- snprintf(file_basename, 80, "o");
- num_len = 4;
- snprintf(file_ext, 80, ".jpeg");
- i = 0;
- proc_mode++;
- break;
- case PROC_MODE_COINS_SERIES:
- snprintf(proc_path, FILENAME_MAX, "%s", coins_path);
- snprintf(proc_fail_path, FILENAME_MAX, "%s", coins_fail_path);
- snprintf(file_basename, 80, "c");
- num_len = 4;
- snprintf(file_ext, 80, ".png");
- i = 1;
- break;
- case PROC_MODE_RESISTOR_SERIES:
- snprintf(proc_path, FILENAME_MAX, "%s", resistors_path);
- snprintf(proc_fail_path, FILENAME_MAX, "%s", resistors_fail_path);
- snprintf(file_basename, 80, "r");
- num_len = 4;
- snprintf(file_ext, 80, ".png");
- i = 1;
- break;
- default:
- return;
- }
-
- wh = true;
- for (; wh; i++) {
- snprintf(file_name, FILENAME_MAX, "%s%04i%s",
- file_basename, i, file_ext);
-
- file_error = alx_sscan_fname(proc_path, file_name,
- true, file_name);
-
- if (file_error) {
- wh = false;
- } else {
- errno = 0;
- img_iface_load(proc_path, file_name);
-
- if (!errno) {
- /* Process */
- proc_error = proc_iface_single(proc_mode);
-
- if (proc_error) {
- /* Save failed image into file */
- proc_show_img();
- snprintf(save_error_as, FILENAME_MAX,
- "%s%0*i_err%s",
- file_basename,
- num_len, i,
- file_ext);
- save_image_file(proc_fail_path,
- save_error_as);
- }
-
- /* Show log */
- char txt_tmp [80];
- snprintf(txt_tmp, 80, "%04i", i);
- user_iface_show_log(txt_tmp, "Item");
-
- if (proc_debug >= PROC_DBG_STOP_ITEM) {
- getchar();
- }
- } else {
- printf("errno:%i\n", errno);
- }
- }
-
- if (!i) {
- proc_mode--;
- }
- }
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* errno */ + #include <errno.h> + #include <stdbool.h> + /* snprintf() & fflush() */ + #include <stdio.h> + /* clock_t & clock() & CLOCKS_PER_SEC */ + #include <time.h> + +/* libalx -------------------------------------------------------------------*/ + /* alx_sscan_fname() */ + #include "alx_input.h" + +/* Project -------------------------------------------------------------------*/ + /* img_iface_load() */ + #include "img_iface.h" + /* user_iface_log */ + #include "user_iface.h" + /* saved_path */ + #include "save.h" + +/* Module --------------------------------------------------------------------*/ + #include "proc_label.h" + #include "proc_objects.h" + #include "proc_coins.h" + #include "proc_resistor.h" + #include "proc_common.h" + + #include "proc_iface.h" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ + int proc_debug; + int proc_mode; + +/* Static --------------------------------------------------------------------*/ +static char proc_path [FILENAME_MAX]; +static char proc_fail_path [FILENAME_MAX]; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +int proc_iface_single (int action) +{ + int error; + clock_t time_0; + clock_t time_1; + double time_tot; + + /* Init timer */ + time_0 = clock(); + + /* Process */ + switch (action) { + case PROC_MODE_LABEL_SERIES: + error = proc_label(); + break; + case PROC_MODE_OBJECTS_CALIB: + error = proc_objects_calibrate(); + break; + case PROC_MODE_OBJECTS_SERIES: + error = proc_objects(); + break; + case PROC_MODE_COINS_SERIES: + error = proc_coins(); + break; + case PROC_MODE_RESISTOR_SERIES: + error = proc_resistor(); + break; + default: + error = -1; + } + + /* End timer */ + time_1 = clock(); + + /* Calculate time in seconds */ + time_tot = ((double) time_1 - time_0) / CLOCKS_PER_SEC; + + /* Write time into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Item total time: %.3lf", + time_tot); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + return error; +} + +void proc_iface_series (void) +{ + bool file_error; + int num_len; + char file_basename [FILENAME_MAX]; + char file_ext [80]; + char file_name [FILENAME_MAX]; + bool proc_error; + char save_error_as [FILENAME_MAX]; + bool wh; + /* if i starts being 0, the camera needs calibration */ + int i; + + switch (proc_mode) { + case PROC_MODE_LABEL_SERIES: + snprintf(proc_path, FILENAME_MAX, "%s", labels_path); + snprintf(proc_fail_path, FILENAME_MAX, "%s", labels_fail_path); + snprintf(file_basename, 80, "b"); + num_len = 4; + snprintf(file_ext, 80, ".BMP"); + i = 1; + break; + case PROC_MODE_OBJECTS_SERIES: + snprintf(proc_path, FILENAME_MAX, "%s", objects_path); + snprintf(proc_fail_path, FILENAME_MAX, "%s", objects_fail_path); + snprintf(file_basename, 80, "o"); + num_len = 4; + snprintf(file_ext, 80, ".jpeg"); + i = 0; + proc_mode++; + break; + case PROC_MODE_COINS_SERIES: + snprintf(proc_path, FILENAME_MAX, "%s", coins_path); + snprintf(proc_fail_path, FILENAME_MAX, "%s", coins_fail_path); + snprintf(file_basename, 80, "c"); + num_len = 4; + snprintf(file_ext, 80, ".png"); + i = 1; + break; + case PROC_MODE_RESISTOR_SERIES: + snprintf(proc_path, FILENAME_MAX, "%s", resistors_path); + snprintf(proc_fail_path, FILENAME_MAX, "%s", resistors_fail_path); + snprintf(file_basename, 80, "r"); + num_len = 4; + snprintf(file_ext, 80, ".png"); + i = 1; + break; + default: + return; + } + + wh = true; + for (; wh; i++) { + snprintf(file_name, FILENAME_MAX, "%s%04i%s", + file_basename, i, file_ext); + + file_error = alx_sscan_fname(proc_path, file_name, + true, file_name); + + if (file_error) { + wh = false; + } else { + errno = 0; + img_iface_load(proc_path, file_name); + + if (!errno) { + /* Process */ + proc_error = proc_iface_single(proc_mode); + + if (proc_error) { + /* Save failed image into file */ + proc_show_img(); + snprintf(save_error_as, FILENAME_MAX, + "%s%0*i_err%s", + file_basename, + num_len, i, + file_ext); + save_image_file(proc_fail_path, + save_error_as); + } + + /* Show log */ + char txt_tmp [80]; + snprintf(txt_tmp, 80, "%04i", i); + user_iface_show_log(txt_tmp, "Item"); + + if (proc_debug >= PROC_DBG_STOP_ITEM) { + getchar(); + } + } else { + printf("errno:%i\n", errno); + } + } + + if (!i) { + proc_mode--; + } + } +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/src/proc_label.cpp b/modules/proc/src/proc_label.cpp index 8615d98..57acf09 100644 --- a/modules/proc/src/proc_label.cpp +++ b/modules/proc/src/proc_label.cpp @@ -1,385 +1,385 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* snprintf() */
- #include <cstdio>
- /* strcmp() */
- #include <cstring>
-
-/* Packages ------------------------------------------------------------------*/
- /* openCV */
- #include <opencv2/opencv.hpp>
- /* zbar::ZBAR_EAN13 */
- #include <zbar.h>
-
-/* Project -------------------------------------------------------------------*/
- /* zb_codes */
- #include "img_iface.hpp"
- /* user_iface_log */
- #include "user_iface.hpp"
-
-/* Module --------------------------------------------------------------------*/
- #include "proc_common.hpp"
-
- #include "proc_label.hpp"
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-/* Global --------------------------------------------------------------------*/
-
-/* Static --------------------------------------------------------------------*/
-static class std::vector <class std::vector <class cv::Point_ <int>>> contours;
-static class cv::Mat hierarchy;
-static class cv::RotatedRect rect;
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void result_label (int status);
-
-static int label_find (void);
-static void label_align (void);
-static int find_cerdo (void);
-static int barcode_read (void);
-static int barcode_chk_prod (void);
-static void price_read (void);
-static int price_chk (void);
-
-
-/******************************************************************************
- ******* global functions *****************************************************
- ******************************************************************************/
-int proc_label (void)
-{
- int status;
-
- proc_save_mem(0);
- /* Find label (position and angle) */
- {
- /* Measure time */
- clock_start();
-
- status = label_find();
- if (status) {
- result_label(status);
- return status;
- }
-
- /* Measure time */
- clock_stop("Find label");
- }
- /* Align label and extract green component */
- {
- /* Measure time */
- clock_start();
-
- label_align();
-
- /* Measure time */
- clock_stop("Align label");
- }
- /* Find "Cerdo" in aligned image */
- {
- /* Measure time */
- clock_start();
-
- status = find_cerdo();
- if (status) {
- result_label(status);
- return status;
- }
-
- /* Measure time */
- clock_stop("Find cerdo (OCR)");
- }
- /* Read barcode in original image */
- {
- /* Measure time */
- clock_start();
-
- status = barcode_read();
- if (status) {
- result_label(status);
- return status;
- }
-
- /* Measure time */
- clock_stop("Read barcode (zbar)");
- }
- /* Check product code in barcode */
- {
- /* Measure time */
- clock_start();
-
- status = barcode_chk_prod();
- if (status) {
- result_label(status);
- return status;
- }
-
- /* Measure time */
- clock_stop("Chk product code");
- }
- /* Read price in aligned image (green component) */
- {
- /* Measure time */
- clock_start();
-
- price_read();
-
- /* Measure time */
- clock_stop("Read price (OCR)");
- }
- /* Check label price with barcode price */
- {
- /* Measure time */
- clock_start();
-
- status = price_chk();
- if (status) {
- result_label(status);
- return status;
- }
-
- /* Measure time */
- clock_stop("Check price");
- }
-
- status = LABEL_OK;
- result_label(status);
- return status;
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void result_label (int status)
-{
- /* Cleanup */
-
- /* Write result into log */
- switch (status) {
- case LABEL_OK:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Label: OK");
- break;
- case LABEL_NOK_LABEL:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Label: NOK_LABEL");
- break;
- case LABEL_NOK_CERDO:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Label: NOK_CERDO");
- break;
- case LABEL_NOK_BCODE:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Label: NOK_BCODE");
- break;
- case LABEL_NOK_PRODUCT:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Label: NOK_PRODUCT");
- break;
- case LABEL_NOK_PRICE:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Label: NOK_PRICE");
- break;
- default:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Label: NOK");
- break;
- }
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-}
-
-static int label_find (void)
-{
- int status;
- int tmp;
-
- proc_load_mem(0);
-
- proc_cmp(IMG_IFACE_CMP_BLUE);
- proc_smooth(IMGI_SMOOTH_MEDIAN, 7);
-#if 0
- proc_adaptive_threshold(CV_ADAPTIVE_THRESH_MEAN_C,
- CV_THRESH_BINARY, 5);
-#else
- proc_not();
-#endif
- proc_smooth(IMGI_SMOOTH_MEAN, 21);
- proc_threshold(cv::THRESH_BINARY_INV, 2);
- proc_dilate_erode(100);
- proc_contours(&contours, &hierarchy);
-
- /* If no contour is found, error: NOK_LABEL */
- if (!contours.size()) {
- status = LABEL_NOK_LABEL;
- return status;
- }
-
- proc_min_area_rect(&(contours[0]), &rect, true);
-
- /* If angle is < -45º, it is taking into acount the incorrect side */
- if (rect.angle < -45.0) {
- rect.angle += 90.0;
- tmp = rect.size.width;
- rect.size.width = rect.size.height;
- rect.size.height = tmp;
- }
-
- status = LABEL_OK;
- return status;
-}
-
-static void label_align (void)
-{
- proc_load_mem(0);
-
- proc_rotate(rect.center.x, rect.center.y, rect.angle);
- proc_cmp(IMG_IFACE_CMP_GREEN);
- proc_save_mem(1);
-}
-
-static int find_cerdo (void)
-{
- int status;
- int x;
- int y;
- int w;
- int h;
- bool cerdo_nok;
-
- proc_load_mem(1);
-
- x = rect.center.x - (1.05 * rect.size.width / 2);
- if (x < 0) {
- x = 0;
- }
- y = rect.center.y - (1.47 * rect.size.height / 2);
- if (y < 0) {
- y = 0;
- }
- w = rect.size.width / 2;
- h = rect.size.height * 0.20;
- proc_ROI(x, y, w, h);
- proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU);
- proc_erode(1);
- proc_OCR(IMG_IFACE_OCR_LANG_ENG, IMG_IFACE_OCR_CONF_NONE);
-
- /* Compare Label text to "Cerdo". */
- cerdo_nok = strncmp(img_ocr_text, "Cerdo",
- strlen("Cerdo"));
-
- /* If string doesn't match, error: NOK_CERDO */
- if (cerdo_nok) {
- status = LABEL_NOK_CERDO;
- return status;
- }
-
- status = LABEL_OK;
- return status;
-}
-
-static int barcode_read (void)
-{
- int status;
-
- proc_load_mem(0);
-
- proc_cmp(IMG_IFACE_CMP_GREEN);
- proc_zbar(zbar::ZBAR_EAN13);
-
- /* Check that 1 and only 1 bcode is read. */
- if (zb_codes.n != 1) {
- status = LABEL_NOK_BCODE;
- return status;
- }
-
- status = LABEL_OK;
- return status;
-}
-
-static int barcode_chk_prod (void)
-{
- int status;
- bool prod_nok;
-
- prod_nok = strncmp(zb_codes.arr[0].data, "2301703",
- strlen("2301703"));
- if (prod_nok) {
- status = LABEL_NOK_PRODUCT;
- return status;
- }
-
- status = LABEL_OK;
- return status;
-}
-
-static void price_read (void)
-{
- int x;
- int y;
- int w;
- int h;
-
- proc_load_mem(1);
-
- x = rect.center.x + (0.33 * rect.size.width / 2);
- y = rect.center.y + (0.64 * rect.size.height / 2);
- w = rect.size.width * 0.225;
- h = rect.size.height * 0.15;
- proc_ROI(x, y, w, h);
- proc_smooth(IMGI_SMOOTH_MEAN, 3);
- proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU);
- proc_dilate_erode(1);
- proc_threshold(cv::THRESH_BINARY, 1);
- proc_OCR(IMG_IFACE_OCR_LANG_DIGITS, IMG_IFACE_OCR_CONF_PRICE);
-}
-
-static int price_chk (void)
-{
- int status;
- char price [80];
- bool price_nok;
-
- /* Extract price from barcode */
- if (zb_codes.arr[0].data[8] != '0') {
- snprintf(price, 80, "%c%c.%c%c",
- zb_codes.arr[0].data[8],
- zb_codes.arr[0].data[9],
- zb_codes.arr[0].data[10],
- zb_codes.arr[0].data[11]);
- } else {
- snprintf(price, 80, "%c.%c%c",
- zb_codes.arr[0].data[9],
- zb_codes.arr[0].data[10],
- zb_codes.arr[0].data[11]);
- }
-
- /* Compare price from barcode and from text */
- price_nok = strncmp(img_ocr_text, price, strlen(price));
-
- if (price_nok) {
- status = LABEL_NOK_PRICE;
- return status;
- }
-
- status = LABEL_OK;
- return status;
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* snprintf() */ + #include <cstdio> + /* strcmp() */ + #include <cstring> + +/* Packages ------------------------------------------------------------------*/ + /* openCV */ + #include <opencv2/opencv.hpp> + /* zbar::ZBAR_EAN13 */ + #include <zbar.h> + +/* Project -------------------------------------------------------------------*/ + /* zb_codes */ + #include "img_iface.hpp" + /* user_iface_log */ + #include "user_iface.hpp" + +/* Module --------------------------------------------------------------------*/ + #include "proc_common.hpp" + + #include "proc_label.hpp" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ + +/* Static --------------------------------------------------------------------*/ +static class std::vector <class std::vector <class cv::Point_ <int>>> contours; +static class cv::Mat hierarchy; +static class cv::RotatedRect rect; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_label (int status); + +static int label_find (void); +static void label_align (void); +static int find_cerdo (void); +static int barcode_read (void); +static int barcode_chk_prod (void); +static void price_read (void); +static int price_chk (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +int proc_label (void) +{ + int status; + + proc_save_mem(0); + /* Find label (position and angle) */ + { + /* Measure time */ + clock_start(); + + status = label_find(); + if (status) { + result_label(status); + return status; + } + + /* Measure time */ + clock_stop("Find label"); + } + /* Align label and extract green component */ + { + /* Measure time */ + clock_start(); + + label_align(); + + /* Measure time */ + clock_stop("Align label"); + } + /* Find "Cerdo" in aligned image */ + { + /* Measure time */ + clock_start(); + + status = find_cerdo(); + if (status) { + result_label(status); + return status; + } + + /* Measure time */ + clock_stop("Find cerdo (OCR)"); + } + /* Read barcode in original image */ + { + /* Measure time */ + clock_start(); + + status = barcode_read(); + if (status) { + result_label(status); + return status; + } + + /* Measure time */ + clock_stop("Read barcode (zbar)"); + } + /* Check product code in barcode */ + { + /* Measure time */ + clock_start(); + + status = barcode_chk_prod(); + if (status) { + result_label(status); + return status; + } + + /* Measure time */ + clock_stop("Chk product code"); + } + /* Read price in aligned image (green component) */ + { + /* Measure time */ + clock_start(); + + price_read(); + + /* Measure time */ + clock_stop("Read price (OCR)"); + } + /* Check label price with barcode price */ + { + /* Measure time */ + clock_start(); + + status = price_chk(); + if (status) { + result_label(status); + return status; + } + + /* Measure time */ + clock_stop("Check price"); + } + + status = LABEL_OK; + result_label(status); + return status; +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_label (int status) +{ + /* Cleanup */ + + /* Write result into log */ + switch (status) { + case LABEL_OK: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Label: OK"); + break; + case LABEL_NOK_LABEL: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Label: NOK_LABEL"); + break; + case LABEL_NOK_CERDO: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Label: NOK_CERDO"); + break; + case LABEL_NOK_BCODE: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Label: NOK_BCODE"); + break; + case LABEL_NOK_PRODUCT: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Label: NOK_PRODUCT"); + break; + case LABEL_NOK_PRICE: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Label: NOK_PRICE"); + break; + default: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Label: NOK"); + break; + } + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + +static int label_find (void) +{ + int status; + int tmp; + + proc_load_mem(0); + + proc_cmp(IMG_IFACE_CMP_BLUE); + proc_smooth(IMGI_SMOOTH_MEDIAN, 7); +#if 0 + proc_adaptive_threshold(CV_ADAPTIVE_THRESH_MEAN_C, + CV_THRESH_BINARY, 5); +#else + proc_not(); +#endif + proc_smooth(IMGI_SMOOTH_MEAN, 21); + proc_threshold(cv::THRESH_BINARY_INV, 2); + proc_dilate_erode(100); + proc_contours(&contours, &hierarchy); + + /* If no contour is found, error: NOK_LABEL */ + if (!contours.size()) { + status = LABEL_NOK_LABEL; + return status; + } + + proc_min_area_rect(&(contours[0]), &rect, true); + + /* If angle is < -45º, it is taking into acount the incorrect side */ + if (rect.angle < -45.0) { + rect.angle += 90.0; + tmp = rect.size.width; + rect.size.width = rect.size.height; + rect.size.height = tmp; + } + + status = LABEL_OK; + return status; +} + +static void label_align (void) +{ + proc_load_mem(0); + + proc_rotate(rect.center.x, rect.center.y, rect.angle); + proc_cmp(IMG_IFACE_CMP_GREEN); + proc_save_mem(1); +} + +static int find_cerdo (void) +{ + int status; + int x; + int y; + int w; + int h; + bool cerdo_nok; + + proc_load_mem(1); + + x = rect.center.x - (1.05 * rect.size.width / 2); + if (x < 0) { + x = 0; + } + y = rect.center.y - (1.47 * rect.size.height / 2); + if (y < 0) { + y = 0; + } + w = rect.size.width / 2; + h = rect.size.height * 0.20; + proc_ROI(x, y, w, h); + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_erode(1); + proc_OCR(IMG_IFACE_OCR_LANG_ENG, IMG_IFACE_OCR_CONF_NONE); + + /* Compare Label text to "Cerdo". */ + cerdo_nok = strncmp(img_ocr_text, "Cerdo", + strlen("Cerdo")); + + /* If string doesn't match, error: NOK_CERDO */ + if (cerdo_nok) { + status = LABEL_NOK_CERDO; + return status; + } + + status = LABEL_OK; + return status; +} + +static int barcode_read (void) +{ + int status; + + proc_load_mem(0); + + proc_cmp(IMG_IFACE_CMP_GREEN); + proc_zbar(zbar::ZBAR_EAN13); + + /* Check that 1 and only 1 bcode is read. */ + if (zb_codes.n != 1) { + status = LABEL_NOK_BCODE; + return status; + } + + status = LABEL_OK; + return status; +} + +static int barcode_chk_prod (void) +{ + int status; + bool prod_nok; + + prod_nok = strncmp(zb_codes.arr[0].data, "2301703", + strlen("2301703")); + if (prod_nok) { + status = LABEL_NOK_PRODUCT; + return status; + } + + status = LABEL_OK; + return status; +} + +static void price_read (void) +{ + int x; + int y; + int w; + int h; + + proc_load_mem(1); + + x = rect.center.x + (0.33 * rect.size.width / 2); + y = rect.center.y + (0.64 * rect.size.height / 2); + w = rect.size.width * 0.225; + h = rect.size.height * 0.15; + proc_ROI(x, y, w, h); + proc_smooth(IMGI_SMOOTH_MEAN, 3); + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_dilate_erode(1); + proc_threshold(cv::THRESH_BINARY, 1); + proc_OCR(IMG_IFACE_OCR_LANG_DIGITS, IMG_IFACE_OCR_CONF_PRICE); +} + +static int price_chk (void) +{ + int status; + char price [80]; + bool price_nok; + + /* Extract price from barcode */ + if (zb_codes.arr[0].data[8] != '0') { + snprintf(price, 80, "%c%c.%c%c", + zb_codes.arr[0].data[8], + zb_codes.arr[0].data[9], + zb_codes.arr[0].data[10], + zb_codes.arr[0].data[11]); + } else { + snprintf(price, 80, "%c.%c%c", + zb_codes.arr[0].data[9], + zb_codes.arr[0].data[10], + zb_codes.arr[0].data[11]); + } + + /* Compare price from barcode and from text */ + price_nok = strncmp(img_ocr_text, price, strlen(price)); + + if (price_nok) { + status = LABEL_NOK_PRICE; + return status; + } + + status = LABEL_OK; + return status; +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/src/proc_objects.cpp b/modules/proc/src/proc_objects.cpp index 5c30a52..026cb25 100644 --- a/modules/proc/src/proc_objects.cpp +++ b/modules/proc/src/proc_objects.cpp @@ -1,697 +1,697 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* snprintf() */
- #include <cstdio>
-
-/* Packages ------------------------------------------------------------------*/
- /* openCV */
- #include <opencv2/opencv.hpp>
-
-/* libalx ------------------------------------------------------------------*/
- /* alx_maximum_u8() */
- #include "alx_math.hpp"
-
-/* Project -------------------------------------------------------------------*/
- /* constants */
- #include "img_iface.hpp"
- /* user_iface_log */
- #include "user_iface.hpp"
-
-/* Module --------------------------------------------------------------------*/
- #include "proc_common.hpp"
-
- #include "proc_objects.hpp"
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
- # define OBJECTS_MAX (1024)
- # define PATTERN_SQUARE_LEN_MM (10.0)
-
- # define PATTERN_DILATE (2)
-
-
-/******************************************************************************
- ******* structs **************************************************************
- ******************************************************************************/
-struct Point {
- uint16_t x_pix;
- uint16_t y_pix;
-
- double x_mm;
- double y_mm;
-};
-
-struct Pattern_Square {
- struct Point pos;
-
- uint8_t len;
-};
-
-struct Pattern_Properties {
- /* center */
- struct Point center;
- struct Point origin;
-
- /* Angle */
- double angle;
-
- /* Size */
- uint16_t height;
- uint16_t width;
-
- /* Squares (distance calibration) */
- struct Pattern_Square square [OBJECTS_MAX];
-};
-
-struct Objects_Properties {
- /* position */
- struct Point pos;
-
- /* Angle */
- double angle;
-
- /* Area */
- double area_pix2;
- double area_mm2;
-
- /* Perimeter */
- double perimeter_pix;
- double perimeter_mm;
-
- /* type */
- double ratio_p2_a;
- double area_rect;
- double ratio_a_arect;
- double perimeter_rect;
- double ratio_p_prect;
-};
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-/* Global --------------------------------------------------------------------*/
-
-/* Static --------------------------------------------------------------------*/
-static class std::vector <class std::vector <class cv::Point_ <int>>> contours;
-static class cv::Mat hierarchy;
-static class cv::RotatedRect rect_rot [OBJECTS_MAX];
-static class cv::Rect_ <int> rect [OBJECTS_MAX];
-static struct Pattern_Properties pattern;
-static int squares_n;
-static double ratio_mm_pix;
-static int objects_n;
-static struct Objects_Properties objects [OBJECTS_MAX];
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void result_objects (int status);
-
-static void pattern_bgr2gray (void);
-static int pattern_find (void);
-static void pattern_rotation_get (void);
-static void pattern_rotation_fix (void);
-static void pattern_dimensions_get (void);
-static void pattern_dimensions_fix (void);
-static void pattern_squares_find (void);
-static void pattern_squares_pos_get (void);
-static void pattern_squares_len_get (void);
-static void pattern_calib_mm_pix (void);
-
-static void objects_bgr2gray (void);
-static void objects_rotation_fix (void);
-static void objects_dimensions_fix (void);
-static void objects_segment (void);
-static int objects_contours (void);
-static void objects_position_pix (void);
-static void objects_size_pix (void);
-static void objects_shape (void);
-static void objects_position_mm (void);
-static void objects_size_mm (void);
-static void objects_log (void);
-
-
-/******************************************************************************
- ******* global functions *****************************************************
- ******************************************************************************/
-int proc_objects_calibrate (void)
-{
- int status;
-
- proc_save_mem(0);
- /* Calibrate angle with the whole pattern */
- {
- /* Measure time */
- clock_start();
-
- pattern_bgr2gray();
- status = pattern_find();
- if (status) {
- result_objects(status);
- return status;
- }
- pattern_rotation_get();
- pattern_rotation_fix();
-
- /* Measure time */
- clock_stop("Calibrate: rotation");
- }
- /* Segmentate pattern squares */
- {
- /* Measure time */
- clock_start();
-
- pattern_dimensions_get();
- pattern_dimensions_fix();
-
- /* Measure time */
- clock_stop("Calibrate: dimensions");
- }
- /* Find squares */
- {
- /* Measure time */
- clock_start();
-
- pattern_squares_find();
- pattern_squares_pos_get();
- pattern_squares_len_get();
- pattern_calib_mm_pix();
-
- /* Measure time */
- clock_stop("Calibrate (mm per pix)");
- }
-
- status = OBJECTS_OK;
- result_objects(status);
- return status;
-}
-
-int proc_objects (void)
-{
- int status;
-
- proc_save_mem(0);
- /* Align image */
- {
- /* Measure time */
- clock_start();
-
- objects_bgr2gray();
- objects_rotation_fix();
- objects_dimensions_fix();
-
- /* Measure time */
- clock_stop("Align image to pattern");
- }
- /* Segment objects */
- {
- /* Measure time */
- clock_start();
-
- objects_segment();
-
- /* Measure time */
- clock_stop("Segment objects");
- }
- /* Find objects positions */
- {
- /* Measure time */
- clock_start();
-
- status = objects_contours();
- if (status) {
- result_objects(status);
- return status;
- }
-
- /* Measure time */
- clock_stop("Find objects");
- }
- /* Get objects properties in pixels */
- {
- /* Measure time */
- clock_start();
-
- objects_position_pix();
- objects_position_mm();
-
- /* Measure time */
- clock_stop("Objects positions");
- }
- /* Get objects properties in mm */
- {
- /* Measure time */
- clock_start();
-
- objects_size_pix();
- objects_size_mm();
-
- /* Measure time */
- clock_stop("Objects sizes");
- }
- /* Get objects properties in mm */
- {
- /* Measure time */
- clock_start();
-
- objects_shape();
-
- /* Measure time */
- clock_stop("Objects shapes");
- }
- /* Print properties of objects into log */
- {
- /* Measure time */
- clock_start();
-
- objects_log();
-
- /* Measure time */
- clock_stop("Objects properties (log)");
- }
-
- status = OBJECTS_OK;
- result_objects(status);
- return status;
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void result_objects (int status)
-{
- /* Write result into log */
- switch (status) {
- case OBJECTS_OK:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Coin: OK");
- break;
- case OBJECTS_NOK_OBJECTS:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Coin: NOK_OBJECTS");
- break;
-
- case OBJECTS_NOK_SIZE:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Coin: NOK_SIZE");
- break;
- default:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Coin: NOK");
- break;
- }
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-}
-
-/* calibration ---------------------------------------------------------------*/
-static void pattern_bgr2gray (void)
-{
- proc_load_mem(0);
-
- proc_cvt_color(cv::COLOR_BGR2GRAY);
- proc_save_mem(1);
-}
-
-static int pattern_find (void)
-{
- int status;
-
- proc_load_mem(1);
-
- proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU);
- proc_erode_dilate(16);
- proc_dilate(2);
- proc_contours(&contours, &hierarchy);
-
- /* If no contour is found, error: NOK_PATTERN */
- if (contours.size() != 1) {
- status = OBJECTS_NOK_PATTERN;
- return status;
- }
-
- status = OBJECTS_OK;
- return status;
-}
-
-static void pattern_rotation_get (void)
-{
- proc_min_area_rect(&(contours[0]), &(rect_rot[0]), true);
-
- /* If angle is < -45º, it is taking into account the incorrect side */
- if (rect_rot[0].angle < -45.0) {
- rect_rot[0].angle += 90.0;
- }
- pattern.angle = rect_rot[0].angle;
- pattern.center.x_pix = rect_rot[0].center.x;
- pattern.center.y_pix = rect_rot[0].center.y;
-
- /* Write pattern properties into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "pattern angle = %lf DEG",
- -pattern.angle);
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "pattern center (x) = %i pix",
- pattern.center.x_pix);
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "pattern center (y) = %i pix",
- pattern.center.y_pix);
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-}
-
-static void pattern_rotation_fix (void)
-{
- proc_load_mem(1);
-
- /* invert image before rotation to avoid black bands */
- proc_not();
- proc_rotate(pattern.center.x_pix, pattern.center.y_pix, pattern.angle);
- proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU);
- proc_save_mem(2);
-}
-
-static void pattern_dimensions_get (void)
-{
- proc_load_mem(2);
-
- proc_erode_dilate(16);
- proc_dilate(PATTERN_DILATE);
- proc_contours(&contours, &hierarchy);
- proc_bounding_rect(&(contours[0]), &(rect[0]), true);
-}
-
-static void pattern_dimensions_fix (void)
-{
- /* Need to correct also pattern dilatation (pattern_dimensions_get()) */
- pattern.origin.x_pix = rect[0].x;
- pattern.origin.y_pix = rect[0].y;
- pattern.width = rect[0].width;
- pattern.height = rect[0].height;
-
- proc_load_mem(2);
-
- proc_ROI(pattern.origin.x_pix, pattern.origin.y_pix,
- pattern.width, pattern.height);
- proc_save_mem(3);
-}
-
-static void pattern_squares_find (void)
-{
- proc_load_mem(3);
-
- proc_distance_transform();
- proc_local_max();
- proc_dilate(6);
- proc_save_mem(4);
-
- proc_contours(&contours, &hierarchy);
- squares_n = contours.size();
-}
-
-static void pattern_squares_pos_get (void)
-{
- int i;
-
- /* Get position of each contour */
- for (i = 0; i < squares_n; i++) {
- proc_bounding_rect(&(contours[i]), &(rect[i]), true);
-
- pattern.square[i].pos.x_pix = rect[i].x + rect[i].width/2.0;
- pattern.square[i].pos.y_pix = rect[i].y + rect[i].height/2.0;
- }
-}
-
-static void pattern_squares_len_get (void)
-{
- int i;
-
- proc_load_mem(4);
-
- /* Get pattern square side lenght in pixels */
- for (i = 0; i < squares_n; i++) {
- proc_pixel_get(pattern.square[i].pos.x_pix,
- pattern.square[i].pos.y_pix,
- &(pattern.square[i].len));
- pattern.square[i].len *= 2;
- }
-}
-
-static void pattern_calib_mm_pix (void)
-{
- int i;
- uint8_t pattern_len [OBJECTS_MAX];
- uint8_t median_size;
-
- for (i = 0; i < squares_n; i++) {
- pattern_len[i] = pattern.square[i].len;
- }
-
- median_size = alx_median_u8(squares_n, pattern_len);
- ratio_mm_pix = PATTERN_SQUARE_LEN_MM / median_size;
-
- /* Write diameters into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "mm/pix = %lf",
- ratio_mm_pix);
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-}
-
-/* process -------------------------------------------------------------------*/
-static void objects_bgr2gray (void)
-{
- proc_load_mem(0);
-
- proc_cvt_color(cv::COLOR_BGR2GRAY);
- proc_save_mem(1);
-}
-
-static void objects_rotation_fix (void)
-{
- proc_load_mem(1);
-
- /* invert image before rotation to avoid black bands */
- proc_not();
- proc_rotate(pattern.center.x_pix, pattern.center.y_pix, pattern.angle);
- proc_save_mem(2);
-}
-
-static void objects_dimensions_fix (void)
-{
- /* Need to correct also pattern dilatation (pattern_dimensions_get()) */
- proc_load_mem(2);
-
- proc_ROI(pattern.origin.x_pix, pattern.origin.y_pix,
- pattern.width, pattern.height);
- proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU);
- proc_save_mem(3);
-}
-
-static void objects_segment (void)
-{
- proc_load_mem(3);
-
- proc_dilate_erode(3);
- proc_erode_dilate(3);
- proc_save_mem(4);
-
- proc_distance_transform();
- proc_threshold(cv::THRESH_BINARY_INV, 30);
- proc_distance_transform();
- proc_skeleton();
- proc_threshold(cv::THRESH_BINARY_INV, 10);
- proc_save_ref();
- proc_save_mem(5);
-
- proc_load_mem(3);
- proc_and_2ref();
- proc_distance_transform();
- proc_threshold(cv::THRESH_BINARY, 10);
- proc_save_mem(6);
-}
-
-static int objects_contours (void)
-{
- int status;
-
- proc_load_mem(6);
-
- proc_contours(&contours, &hierarchy);
- objects_n = contours.size();
-
- /* If no contour is found, error: NOK_OBJECTS */
- if (!objects_n) {
- status = OBJECTS_NOK_OBJECTS;
- return status;
- }
-
- status = OBJECTS_OK;
- return status;
-}
-
-static void objects_position_pix (void)
-{
- int i;
-
- /* Get position of each contour */
- for (i = 0; i < objects_n; i++) {
- proc_fit_ellipse(&(contours[i]), &(rect_rot[i]), true);
-
- objects[i].pos.x_pix = rect_rot[i].center.x;
- objects[i].pos.y_pix = rect_rot[i].center.y;
-
- objects[i].angle = -rect_rot[i].angle + 90.0;
- if (objects[i].angle < 0) {
- objects[i].angle += 180.0;
- }
- }
-}
-
-static void objects_position_mm (void)
-{
- int i;
-
- /* Get position of each contour */
- for (i = 0; i < objects_n; i++) {
- objects[i].pos.x_mm = ratio_mm_pix * objects[i].pos.x_pix;
- objects[i].pos.y_mm = ratio_mm_pix * objects[i].pos.y_pix;
- }
-}
-
-static void objects_size_pix (void)
-{
- double area [OBJECTS_MAX];
- double perimeter [OBJECTS_MAX];
- int i;
-
- /* Get size of each contour */
- proc_contours_size(&contours, area, perimeter);
- for (i = 0; i < objects_n; i++) {
- objects[i].area_pix2 = area[i];
- objects[i].perimeter_pix = perimeter[i];
- }
-}
-
-static void objects_size_mm (void)
-{
- int i;
-
- /* Get position of each contour */
- for (i = 0; i < objects_n; i++) {
- objects[i].area_mm2 = pow(ratio_mm_pix, 2) *
- objects[i].area_pix2;
- objects[i].perimeter_mm = ratio_mm_pix *
- objects[i].perimeter_pix;
- }
-}
-
-static void objects_shape (void)
-{
- int i;
-
- /* Get shape of each contour */
- for (i = 0; i < objects_n; i++) {
- proc_min_area_rect(&(contours[i]), &(rect_rot[i]), true);
-
- objects[i].ratio_p2_a = pow(objects[i].perimeter_pix, 2) /
- objects[i].area_pix2;
-
- objects[i].area_rect = rect_rot[i].size.width *
- rect_rot[i].size.height;
- objects[i].perimeter_rect = 2.0 *
- (rect_rot[i].size.width +
- rect_rot[i].size.height);
-
- objects[i].ratio_p_prect = objects[i].perimeter_pix /
- objects[i].perimeter_rect;
- objects[i].ratio_a_arect = objects[i].area_pix2 /
- objects[i].area_rect;
- }
-}
-
-static void objects_log (void)
-{
- int i;
-
- /* Get coins diameters in mm */
- for (i = 0; i < objects_n; i++) {
- /* Write diameters into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Object[%i]:",
- i);
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-
- /* Write diameters into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- " pos: (%.1lf, %.1lf) mm",
- objects[i].pos.x_mm,
- objects[i].pos.y_mm);
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-
- /* Write diameters into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- " ang = %.1lf DEG",
- objects[i].angle);
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-
- /* Write diameters into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- " A = %.1lf mm2",
- objects[i].area_mm2);
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-
- /* Write diameters into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- " P = %.1lf mm",
- objects[i].perimeter_mm);
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-
- /* Write diameters into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- " p2/A = %.2lf",
- objects[i].ratio_p2_a);
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-
- /* Write diameters into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- " p/p_r = %.2lf",
- objects[i].ratio_p_prect);
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-
- /* Write diameters into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- " A/A_r = %.2lf",
- objects[i].ratio_a_arect);
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
- }
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* snprintf() */ + #include <cstdio> + +/* Packages ------------------------------------------------------------------*/ + /* openCV */ + #include <opencv2/opencv.hpp> + +/* libalx ------------------------------------------------------------------*/ + /* alx_maximum_u8() */ + #include "alx_math.hpp" + +/* Project -------------------------------------------------------------------*/ + /* constants */ + #include "img_iface.hpp" + /* user_iface_log */ + #include "user_iface.hpp" + +/* Module --------------------------------------------------------------------*/ + #include "proc_common.hpp" + + #include "proc_objects.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define OBJECTS_MAX (1024) + # define PATTERN_SQUARE_LEN_MM (10.0) + + # define PATTERN_DILATE (2) + + +/****************************************************************************** + ******* structs ************************************************************** + ******************************************************************************/ +struct Point { + uint16_t x_pix; + uint16_t y_pix; + + double x_mm; + double y_mm; +}; + +struct Pattern_Square { + struct Point pos; + + uint8_t len; +}; + +struct Pattern_Properties { + /* center */ + struct Point center; + struct Point origin; + + /* Angle */ + double angle; + + /* Size */ + uint16_t height; + uint16_t width; + + /* Squares (distance calibration) */ + struct Pattern_Square square [OBJECTS_MAX]; +}; + +struct Objects_Properties { + /* position */ + struct Point pos; + + /* Angle */ + double angle; + + /* Area */ + double area_pix2; + double area_mm2; + + /* Perimeter */ + double perimeter_pix; + double perimeter_mm; + + /* type */ + double ratio_p2_a; + double area_rect; + double ratio_a_arect; + double perimeter_rect; + double ratio_p_prect; +}; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ + +/* Static --------------------------------------------------------------------*/ +static class std::vector <class std::vector <class cv::Point_ <int>>> contours; +static class cv::Mat hierarchy; +static class cv::RotatedRect rect_rot [OBJECTS_MAX]; +static class cv::Rect_ <int> rect [OBJECTS_MAX]; +static struct Pattern_Properties pattern; +static int squares_n; +static double ratio_mm_pix; +static int objects_n; +static struct Objects_Properties objects [OBJECTS_MAX]; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_objects (int status); + +static void pattern_bgr2gray (void); +static int pattern_find (void); +static void pattern_rotation_get (void); +static void pattern_rotation_fix (void); +static void pattern_dimensions_get (void); +static void pattern_dimensions_fix (void); +static void pattern_squares_find (void); +static void pattern_squares_pos_get (void); +static void pattern_squares_len_get (void); +static void pattern_calib_mm_pix (void); + +static void objects_bgr2gray (void); +static void objects_rotation_fix (void); +static void objects_dimensions_fix (void); +static void objects_segment (void); +static int objects_contours (void); +static void objects_position_pix (void); +static void objects_size_pix (void); +static void objects_shape (void); +static void objects_position_mm (void); +static void objects_size_mm (void); +static void objects_log (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +int proc_objects_calibrate (void) +{ + int status; + + proc_save_mem(0); + /* Calibrate angle with the whole pattern */ + { + /* Measure time */ + clock_start(); + + pattern_bgr2gray(); + status = pattern_find(); + if (status) { + result_objects(status); + return status; + } + pattern_rotation_get(); + pattern_rotation_fix(); + + /* Measure time */ + clock_stop("Calibrate: rotation"); + } + /* Segmentate pattern squares */ + { + /* Measure time */ + clock_start(); + + pattern_dimensions_get(); + pattern_dimensions_fix(); + + /* Measure time */ + clock_stop("Calibrate: dimensions"); + } + /* Find squares */ + { + /* Measure time */ + clock_start(); + + pattern_squares_find(); + pattern_squares_pos_get(); + pattern_squares_len_get(); + pattern_calib_mm_pix(); + + /* Measure time */ + clock_stop("Calibrate (mm per pix)"); + } + + status = OBJECTS_OK; + result_objects(status); + return status; +} + +int proc_objects (void) +{ + int status; + + proc_save_mem(0); + /* Align image */ + { + /* Measure time */ + clock_start(); + + objects_bgr2gray(); + objects_rotation_fix(); + objects_dimensions_fix(); + + /* Measure time */ + clock_stop("Align image to pattern"); + } + /* Segment objects */ + { + /* Measure time */ + clock_start(); + + objects_segment(); + + /* Measure time */ + clock_stop("Segment objects"); + } + /* Find objects positions */ + { + /* Measure time */ + clock_start(); + + status = objects_contours(); + if (status) { + result_objects(status); + return status; + } + + /* Measure time */ + clock_stop("Find objects"); + } + /* Get objects properties in pixels */ + { + /* Measure time */ + clock_start(); + + objects_position_pix(); + objects_position_mm(); + + /* Measure time */ + clock_stop("Objects positions"); + } + /* Get objects properties in mm */ + { + /* Measure time */ + clock_start(); + + objects_size_pix(); + objects_size_mm(); + + /* Measure time */ + clock_stop("Objects sizes"); + } + /* Get objects properties in mm */ + { + /* Measure time */ + clock_start(); + + objects_shape(); + + /* Measure time */ + clock_stop("Objects shapes"); + } + /* Print properties of objects into log */ + { + /* Measure time */ + clock_start(); + + objects_log(); + + /* Measure time */ + clock_stop("Objects properties (log)"); + } + + status = OBJECTS_OK; + result_objects(status); + return status; +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_objects (int status) +{ + /* Write result into log */ + switch (status) { + case OBJECTS_OK: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: OK"); + break; + case OBJECTS_NOK_OBJECTS: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK_OBJECTS"); + break; + + case OBJECTS_NOK_SIZE: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK_SIZE"); + break; + default: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Coin: NOK"); + break; + } + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + +/* calibration ---------------------------------------------------------------*/ +static void pattern_bgr2gray (void) +{ + proc_load_mem(0); + + proc_cvt_color(cv::COLOR_BGR2GRAY); + proc_save_mem(1); +} + +static int pattern_find (void) +{ + int status; + + proc_load_mem(1); + + proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU); + proc_erode_dilate(16); + proc_dilate(2); + proc_contours(&contours, &hierarchy); + + /* If no contour is found, error: NOK_PATTERN */ + if (contours.size() != 1) { + status = OBJECTS_NOK_PATTERN; + return status; + } + + status = OBJECTS_OK; + return status; +} + +static void pattern_rotation_get (void) +{ + proc_min_area_rect(&(contours[0]), &(rect_rot[0]), true); + + /* If angle is < -45º, it is taking into account the incorrect side */ + if (rect_rot[0].angle < -45.0) { + rect_rot[0].angle += 90.0; + } + pattern.angle = rect_rot[0].angle; + pattern.center.x_pix = rect_rot[0].center.x; + pattern.center.y_pix = rect_rot[0].center.y; + + /* Write pattern properties into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "pattern angle = %lf DEG", + -pattern.angle); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "pattern center (x) = %i pix", + pattern.center.x_pix); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "pattern center (y) = %i pix", + pattern.center.y_pix); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + +static void pattern_rotation_fix (void) +{ + proc_load_mem(1); + + /* invert image before rotation to avoid black bands */ + proc_not(); + proc_rotate(pattern.center.x_pix, pattern.center.y_pix, pattern.angle); + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_save_mem(2); +} + +static void pattern_dimensions_get (void) +{ + proc_load_mem(2); + + proc_erode_dilate(16); + proc_dilate(PATTERN_DILATE); + proc_contours(&contours, &hierarchy); + proc_bounding_rect(&(contours[0]), &(rect[0]), true); +} + +static void pattern_dimensions_fix (void) +{ + /* Need to correct also pattern dilatation (pattern_dimensions_get()) */ + pattern.origin.x_pix = rect[0].x; + pattern.origin.y_pix = rect[0].y; + pattern.width = rect[0].width; + pattern.height = rect[0].height; + + proc_load_mem(2); + + proc_ROI(pattern.origin.x_pix, pattern.origin.y_pix, + pattern.width, pattern.height); + proc_save_mem(3); +} + +static void pattern_squares_find (void) +{ + proc_load_mem(3); + + proc_distance_transform(); + proc_local_max(); + proc_dilate(6); + proc_save_mem(4); + + proc_contours(&contours, &hierarchy); + squares_n = contours.size(); +} + +static void pattern_squares_pos_get (void) +{ + int i; + + /* Get position of each contour */ + for (i = 0; i < squares_n; i++) { + proc_bounding_rect(&(contours[i]), &(rect[i]), true); + + pattern.square[i].pos.x_pix = rect[i].x + rect[i].width/2.0; + pattern.square[i].pos.y_pix = rect[i].y + rect[i].height/2.0; + } +} + +static void pattern_squares_len_get (void) +{ + int i; + + proc_load_mem(4); + + /* Get pattern square side lenght in pixels */ + for (i = 0; i < squares_n; i++) { + proc_pixel_get(pattern.square[i].pos.x_pix, + pattern.square[i].pos.y_pix, + &(pattern.square[i].len)); + pattern.square[i].len *= 2; + } +} + +static void pattern_calib_mm_pix (void) +{ + int i; + uint8_t pattern_len [OBJECTS_MAX]; + uint8_t median_size; + + for (i = 0; i < squares_n; i++) { + pattern_len[i] = pattern.square[i].len; + } + + median_size = alx_median_u8(squares_n, pattern_len); + ratio_mm_pix = PATTERN_SQUARE_LEN_MM / median_size; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "mm/pix = %lf", + ratio_mm_pix); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + +/* process -------------------------------------------------------------------*/ +static void objects_bgr2gray (void) +{ + proc_load_mem(0); + + proc_cvt_color(cv::COLOR_BGR2GRAY); + proc_save_mem(1); +} + +static void objects_rotation_fix (void) +{ + proc_load_mem(1); + + /* invert image before rotation to avoid black bands */ + proc_not(); + proc_rotate(pattern.center.x_pix, pattern.center.y_pix, pattern.angle); + proc_save_mem(2); +} + +static void objects_dimensions_fix (void) +{ + /* Need to correct also pattern dilatation (pattern_dimensions_get()) */ + proc_load_mem(2); + + proc_ROI(pattern.origin.x_pix, pattern.origin.y_pix, + pattern.width, pattern.height); + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_save_mem(3); +} + +static void objects_segment (void) +{ + proc_load_mem(3); + + proc_dilate_erode(3); + proc_erode_dilate(3); + proc_save_mem(4); + + proc_distance_transform(); + proc_threshold(cv::THRESH_BINARY_INV, 30); + proc_distance_transform(); + proc_skeleton(); + proc_threshold(cv::THRESH_BINARY_INV, 10); + proc_save_ref(); + proc_save_mem(5); + + proc_load_mem(3); + proc_and_2ref(); + proc_distance_transform(); + proc_threshold(cv::THRESH_BINARY, 10); + proc_save_mem(6); +} + +static int objects_contours (void) +{ + int status; + + proc_load_mem(6); + + proc_contours(&contours, &hierarchy); + objects_n = contours.size(); + + /* If no contour is found, error: NOK_OBJECTS */ + if (!objects_n) { + status = OBJECTS_NOK_OBJECTS; + return status; + } + + status = OBJECTS_OK; + return status; +} + +static void objects_position_pix (void) +{ + int i; + + /* Get position of each contour */ + for (i = 0; i < objects_n; i++) { + proc_fit_ellipse(&(contours[i]), &(rect_rot[i]), true); + + objects[i].pos.x_pix = rect_rot[i].center.x; + objects[i].pos.y_pix = rect_rot[i].center.y; + + objects[i].angle = -rect_rot[i].angle + 90.0; + if (objects[i].angle < 0) { + objects[i].angle += 180.0; + } + } +} + +static void objects_position_mm (void) +{ + int i; + + /* Get position of each contour */ + for (i = 0; i < objects_n; i++) { + objects[i].pos.x_mm = ratio_mm_pix * objects[i].pos.x_pix; + objects[i].pos.y_mm = ratio_mm_pix * objects[i].pos.y_pix; + } +} + +static void objects_size_pix (void) +{ + double area [OBJECTS_MAX]; + double perimeter [OBJECTS_MAX]; + int i; + + /* Get size of each contour */ + proc_contours_size(&contours, area, perimeter); + for (i = 0; i < objects_n; i++) { + objects[i].area_pix2 = area[i]; + objects[i].perimeter_pix = perimeter[i]; + } +} + +static void objects_size_mm (void) +{ + int i; + + /* Get position of each contour */ + for (i = 0; i < objects_n; i++) { + objects[i].area_mm2 = pow(ratio_mm_pix, 2) * + objects[i].area_pix2; + objects[i].perimeter_mm = ratio_mm_pix * + objects[i].perimeter_pix; + } +} + +static void objects_shape (void) +{ + int i; + + /* Get shape of each contour */ + for (i = 0; i < objects_n; i++) { + proc_min_area_rect(&(contours[i]), &(rect_rot[i]), true); + + objects[i].ratio_p2_a = pow(objects[i].perimeter_pix, 2) / + objects[i].area_pix2; + + objects[i].area_rect = rect_rot[i].size.width * + rect_rot[i].size.height; + objects[i].perimeter_rect = 2.0 * + (rect_rot[i].size.width + + rect_rot[i].size.height); + + objects[i].ratio_p_prect = objects[i].perimeter_pix / + objects[i].perimeter_rect; + objects[i].ratio_a_arect = objects[i].area_pix2 / + objects[i].area_rect; + } +} + +static void objects_log (void) +{ + int i; + + /* Get coins diameters in mm */ + for (i = 0; i < objects_n; i++) { + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Object[%i]:", + i); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " pos: (%.1lf, %.1lf) mm", + objects[i].pos.x_mm, + objects[i].pos.y_mm); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " ang = %.1lf DEG", + objects[i].angle); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " A = %.1lf mm2", + objects[i].area_mm2); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " P = %.1lf mm", + objects[i].perimeter_mm); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " p2/A = %.2lf", + objects[i].ratio_p2_a); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " p/p_r = %.2lf", + objects[i].ratio_p_prect); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Write diameters into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + " A/A_r = %.2lf", + objects[i].ratio_a_arect); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/src/proc_resistor.cpp b/modules/proc/src/proc_resistor.cpp index cdac617..58f1fe4 100644 --- a/modules/proc/src/proc_resistor.cpp +++ b/modules/proc/src/proc_resistor.cpp @@ -1,1459 +1,1459 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* pow() */
- #include <cmath>
- /* snprintf() & fflush() */
- #include <cstdio>
-
-/* Packages ------------------------------------------------------------------*/
- /* openCV */
- #include <opencv2/opencv.hpp>
-
-/* Project -------------------------------------------------------------------*/
- /* CONSTANTS */
- #include "img_iface.hpp"
- /* user_iface_log */
- #include "user_iface.hpp"
-
-/* Module --------------------------------------------------------------------*/
- #include "proc_common.hpp"
-
- #include "proc_resistor.hpp"
-
-
-/******************************************************************************
- ******* structs **************************************************************
- ******************************************************************************/
-struct Resistor_Bands {
- /* position */
- int x;
- int y;
-
- /* value */
- unsigned char h;
- unsigned char s;
- unsigned char v;
-};
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-/* Global --------------------------------------------------------------------*/
-
-/* Static --------------------------------------------------------------------*/
-static class std::vector <class std::vector <class cv::Point_ <int>>> contours;
-static class cv::Mat hierarchy;
-static class cv::RotatedRect rect_rot;
-static class cv::Rect_ <int> rect;
-static int bkgd;
-static int bands_n;
-static struct Resistor_Bands bands [5];
-static char code [6];
-static int base;
-static float resistance;
-static int tolerance;
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void result_resistor (int status);
-
-static int resistor_find (void);
-static void resistor_align (void);
-static void resistor_dimensions_0 (void);
-static void resistor_crop_0 (void);
-static void resistor_bkgd (void);
-static void resistor_dimensions_1 (void);
-static void resistor_crop_1 (void);
-static void separate_bkgd_bands_h (void);
-static void separate_bkgd_bands_s (void);
-static void separate_bkgd_bands_v (void);
-static void bkgd_find (void);
-static int bands_find (void);
-static void bands_colors (void);
-static void bands_code (void);
-static char band_hsv2code (struct Resistor_Bands *band);
-static void bands_code_deduce_0 (void);
-static void bands_code_deduce_1 (void);
-static int bands_code_deduce_no (void);
-static void resistor_value (void);
-static int resistor_tolerance (void);
-static int chk_std_value (void);
-
-
-/******************************************************************************
- ******* global functions *****************************************************
- ******************************************************************************/
-int proc_resistor (void)
-{
- int status;
-
- proc_save_mem(0);
- /* Find resistor (position and angle) */
- {
- /* Measure time */
- clock_start();
-
- status = resistor_find();
- if (status) {
- result_resistor(status);
- return status;
- }
-
- /* Measure time */
- clock_stop("Find resistor");
- }
- /* Align resistor, find its dimensions, and crop */
- {
- /* Measure time */
- clock_start();
-
- resistor_align();
- resistor_dimensions_0();
- resistor_crop_0();
-
- /* Measure time */
- clock_stop("Align, dimensions, & crop");
- }
- /* Find backgroung color */
- {
- /* Measure time */
- clock_start();
-
- resistor_bkgd();
-
- /* Measure time */
- clock_stop("Background color");
- }
- /* Crop more */
- {
- /* Measure time */
- clock_start();
-
- resistor_dimensions_1();
- resistor_crop_1();
-
- /* Measure time */
- clock_stop("Crop more");
- }
- /* Separate background (BK) and lines (WH) */
- {
- /* Measure time */
- clock_start();
-
- separate_bkgd_bands_h();
- separate_bkgd_bands_s();
- separate_bkgd_bands_v();
- bkgd_find();
-
- /* Measure time */
- clock_stop("Separate bkgd from bands");
- }
- /* Find bands: contours -> rectangles */
- {
- /* Measure time */
- clock_start();
-
- status = bands_find();
- if (status) {
- result_resistor(status);
- return status;
- }
-
- /* Measure time */
- clock_stop("Find bands");
- }
- /* Read values on the center of each band */
- {
- /* Measure time */
- clock_start();
-
- bands_colors();
-
- /* Measure time */
- clock_stop("Bands' colors");
- }
- /* Interpret colors */
- {
- /* Measure time */
- clock_start();
-
- bands_code();
- bands_code_deduce_0();
- bands_code_deduce_1();
- status = bands_code_deduce_no();
- if (status) {
- result_resistor(status);
- return status;
- }
-
- /* Measure time */
- clock_stop("Interpret colors");
- }
- /* Calculate resistor value & tolerance */
- {
- /* Measure time */
- clock_start();
-
- resistor_value();
- status = resistor_tolerance();
- if (status) {
- result_resistor(status);
- return status;
- }
-
- /* Write resistor value into log */
- if (bands_n != 1) {
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Resistance: %.2E ± %i%% Ohm",
- resistance, tolerance);
- } else {
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Resistance: 0 Ohm");
- }
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-
- /* Measure time */
- clock_stop("Calculate resistance & tolerance");
- }
- /* Check STD value */
- {
- /* Measure time */
- clock_start();
-
- status = chk_std_value();
- if (status) {
- result_resistor(status);
- return status;
- }
-
- /* Measure time */
- clock_stop("Chk STD values");
- }
-
- status = RESISTOR_OK;
- result_resistor(status);
- return status;
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void result_resistor (int status)
-{
- /* Write result into log */
- switch (status) {
- case RESISTOR_OK:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Resistor: OK");
- break;
- case RESISTOR_NOK_RESISTOR:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Resistor: NOK_RESISTOR");
- break;
- case RESISTOR_NOK_BANDS:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Resistor: NOK_BANDS");
- break;
- case RESISTOR_NOK_COLOR:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Resistor: NOK_COLOR");
- break;
- case RESISTOR_NOK_STD_VALUE:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Resistor: NOK_STD_VALUE");
- break;
- case RESISTOR_NOK_TOLERANCE:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Resistor: NOK_TOLERANCE");
- break;
- default:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Resistor: NOK");
- break;
- }
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-}
-
-static int resistor_find (void)
-{
- int status;
-
- proc_load_mem(0);
-
- /* BGR -> HSV */
- proc_cvt_color(cv::COLOR_BGR2HSV);
- proc_save_mem(19);
-
- proc_cmp(IMG_IFACE_CMP_SATURATION);
- proc_smooth(IMGI_SMOOTH_MEDIAN, 7);
- proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU);
- proc_save_mem(1);
- proc_dilate_erode(10);
- proc_contours(&contours, &hierarchy);
-
- /* If no contour is found, error: NOK_RESISTOR */
- if (!contours.size()) {
- status = RESISTOR_NOK_RESISTOR;
- return status;
- }
-
- proc_min_area_rect(&(contours[0]), &rect_rot, true);
-
- /* If angle is < -45º, it is taking into acount the incorrect side */
- if (rect_rot.angle < -45.0) {
- rect_rot.angle += 90.0;
- }
-
- status = RESISTOR_OK;
- return status;
-}
-
-static void resistor_align (void)
-{
- proc_load_mem(19);
- proc_rotate(rect_rot.center.x, rect_rot.center.y, rect_rot.angle);
- proc_save_mem(2);
- proc_load_mem(1);
- proc_rotate(rect_rot.center.x, rect_rot.center.y, rect_rot.angle);
- proc_save_mem(3);
-}
-
-static void resistor_dimensions_0 (void)
-{
- proc_load_mem(3);
-
- proc_dilate_erode(10);
- proc_contours(&contours, &hierarchy);
- proc_bounding_rect(&(contours[0]), &rect, true);
-}
-
-static void resistor_crop_0 (void)
-{
- int x;
- int y;
- int w;
- int h;
-
- proc_load_mem(2);
-
- w = rect.width;
- h = rect.height;
- x = rect.x;
- y = rect.y;
- proc_ROI(x, y, w, h);
- proc_save_mem(4);
-}
-
-static void resistor_bkgd (void)
-{
- uint8_t bkgd_hue;
- uint8_t bkgd_sat;
-
- /* hue */
- proc_load_mem(4);
- proc_cmp(IMG_IFACE_CMP_HUE);
- proc_median_vertical();
- proc_median_horizontal();
- proc_pixel_get(0, 0, &bkgd_hue);
-
- /* saturation */
- proc_load_mem(4);
- proc_cmp(IMG_IFACE_CMP_SATURATION);
- proc_median_vertical();
- proc_median_horizontal();
- proc_pixel_get(0, 0, &bkgd_sat);
-
- if (bkgd_hue < 50) {
- /* Beige */
- bkgd = 0;
- } else {
- /* Blue */
- if ((bkgd_hue < 90) || (bkgd_sat < 100)) {
- /* Teal blue */
- bkgd = 1;
- } else if (bkgd_hue >= 105) {
- /* Dark blue */
- bkgd = 2;
- } else {
- /* Normal blue */
- bkgd = 3;
- }
- }
-}
-
-static void resistor_dimensions_1 (void)
-{
- proc_load_mem(3);
-
- proc_dilate_erode(10);
- proc_erode_dilate((rect.height * 0.67) / 2);
- proc_contours(&contours, &hierarchy);
- proc_bounding_rect(&(contours[0]), &rect, true);
-}
-
-static void resistor_crop_1 (void)
-{
- int x;
- int y;
- int w;
- int h;
-
- proc_load_mem(2);
-
- w = rect.width * 0.95;
- h = rect.height * 0.8;
- x = rect.x + w * (1.0 - 0.95) / 2.0;
- y = rect.y + h * (1.0 - 0.8) / 2.0;
- proc_ROI(x, y, w, h);
- proc_save_mem(4);
-}
-
-static void separate_bkgd_bands_h (void)
-{
- proc_load_mem(4);
-
- proc_cmp(IMG_IFACE_CMP_HUE);
- proc_median_vertical();
- proc_save_mem(9);
-
- switch (bkgd) {
- case 0:
- proc_threshold(cv::THRESH_TOZERO_INV, 20);
- proc_threshold(cv::THRESH_TOZERO, 5);
- break;
- case 1:
- proc_threshold(cv::THRESH_TOZERO_INV, 100);
- proc_threshold(cv::THRESH_TOZERO, 70);
- break;
- case 2:
- proc_threshold(cv::THRESH_TOZERO_INV, 115);
- proc_threshold(cv::THRESH_TOZERO, 100);
- break;
- case 3:
- proc_threshold(cv::THRESH_TOZERO_INV, 110);
- proc_threshold(cv::THRESH_TOZERO, 90);
- break;
- }
- proc_threshold(cv::THRESH_BINARY_INV, 1);
- proc_save_mem(5);
-}
-
-static void separate_bkgd_bands_s (void)
-{
- proc_load_mem(4);
-
- proc_cmp(IMG_IFACE_CMP_SATURATION);
- proc_median_vertical();
- proc_save_mem(10);
-
- switch (bkgd) {
-
- case 0:
- proc_threshold(cv::THRESH_TOZERO_INV, 160);
- proc_threshold(cv::THRESH_TOZERO, 110);
- break;
- case 1:
- proc_threshold(cv::THRESH_TOZERO_INV, 180);
- proc_threshold(cv::THRESH_TOZERO, 30);
- break;
- case 2:
- proc_threshold(cv::THRESH_TOZERO_INV, 190);
- proc_threshold(cv::THRESH_TOZERO, 170);
- break;
- case 3:
- proc_threshold(cv::THRESH_TOZERO_INV, 210);
- proc_threshold(cv::THRESH_TOZERO, 120);
- break;
- }
- proc_threshold(cv::THRESH_BINARY_INV, 1);
- proc_save_mem(6);
-}
-
-static void separate_bkgd_bands_v (void)
-{
- proc_load_mem(4);
-
- proc_cmp(IMG_IFACE_CMP_VALUE);
- proc_median_vertical();
- proc_save_mem(11);
-
- switch (bkgd) {
- case 0:
- proc_threshold(cv::THRESH_TOZERO_INV, 170);
- proc_threshold(cv::THRESH_TOZERO, 100);
- break;
-
- case 1:
- proc_threshold(cv::THRESH_TOZERO_INV, 180);
- proc_threshold(cv::THRESH_TOZERO, 100);
- break;
- case 2:
- proc_threshold(cv::THRESH_TOZERO_INV, 180);
- proc_threshold(cv::THRESH_TOZERO, 150);
- break;
- case 3:
- proc_threshold(cv::THRESH_TOZERO_INV, 190);
- proc_threshold(cv::THRESH_TOZERO, 90);
- break;
- }
- proc_threshold(cv::THRESH_BINARY_INV, 1);
- proc_save_mem(7);
-}
-
-static void bkgd_find (void)
-{
- /* Merge the components: H | S | V */
- proc_load_mem(7);
- proc_save_ref();
- proc_load_mem(6);
- proc_or_2ref();
- proc_save_ref();
- proc_load_mem(5);
- proc_or_2ref();
- if (rect.width * 0.95 > 80) {
- proc_dilate_erode(1);
- }
- proc_save_mem(8);
-}
-
-static int bands_find (void)
-{
- int status;
-
- proc_load_mem(8);
-
- /* Contours */
- proc_contours(&contours, &hierarchy);
- if (contours.size() > 5) {
- proc_load_mem(8);
- proc_dilate_erode(1);
- proc_contours(&contours, &hierarchy);
- }
-
- bands_n = contours.size();
- if ((bands_n == 0) || (bands_n == 2) || (bands_n > 5)) {
- status = RESISTOR_NOK_BANDS;
- return status;
- }
-
- /* Band 0 (hundreds) */
- if (bands_n == 5) {
- proc_bounding_rect(&(contours[4]), &rect, true);
- bands[0].x = rect.x + rect.width / 2.0;
- bands[0].y = rect.y + rect.height / 2.0;
- }
-
- /* Band 1 (tens) */
- if (bands_n >= 3) {
- if (bands_n > 3) {
- proc_bounding_rect(&(contours[3]), &rect, true);
- } else {
- proc_bounding_rect(&(contours[2]), &rect, true);
- }
- bands[1].x = rect.x + rect.width / 2.0;
- bands[1].y = rect.y + rect.height / 2.0;
- }
-
- /* Band 2 (units) */
- if (bands_n > 3) {
- proc_bounding_rect(&(contours[2]), &rect, true);
- } else if (bands_n == 3) {
- proc_bounding_rect(&(contours[1]), &rect, true);
- } else { /* bands_n == 1 */
- proc_bounding_rect(&(contours[0]), &rect, true);
- }
- bands[2].x = rect.x + rect.width / 2.0;
- bands[2].y = rect.y + rect.height / 2.0;
-
- /* Band 3 (multiplier) */
- if (bands_n >= 3) {
- if (bands_n > 3) {
- proc_bounding_rect(&(contours[1]), &rect, true);
- } else {
- proc_bounding_rect(&(contours[0]), &rect, true);
- }
- bands[3].x = rect.x + rect.width / 2.0;
- bands[3].y = rect.y + rect.height / 2.0;
- }
-
- /* Band 4 (tolerance) */
- if (bands_n > 3) {
- proc_bounding_rect(&(contours[0]), &rect, true);
- bands[4].x = rect.x + rect.width / 2.0;
- bands[4].y = rect.y + rect.height / 2.0;
- }
-
- status = RESISTOR_OK;
- return status;
-}
-
-static void bands_colors (void)
-{
- /* Hue */
- proc_load_mem(9);
- if (bands_n == 5) {
- proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].h));
- }
- if (bands_n >= 3) {
- proc_pixel_get(bands[1].x, bands[1].y, &(bands[1].h));
- }
- proc_pixel_get(bands[2].x, bands[2].y, &(bands[2].h));
- if (bands_n >= 3) {
- proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].h));
- }
- if (bands_n > 3) {
- proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].h));
- }
-
- /* Saturation */
- proc_load_mem(10);
- if (bands_n == 5) {
- proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].s));
- }
- if (bands_n >= 3) {
- proc_pixel_get(bands[1].x, bands[1].y, &(bands[1].s));
- }
- proc_pixel_get(bands[2].x, bands[2].y, &(bands[2].s));
- if (bands_n >= 3) {
- proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].s));
- }
- if (bands_n > 3) {
- proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].s));
- }
-
- /* Value */
- proc_load_mem(11);
- if (bands_n == 5) {
- proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].v));
- }
- if (bands_n >= 3) {
- proc_pixel_get(bands[1].x, bands[1].y, &(bands[1].v));
- }
- proc_pixel_get(bands[2].x, bands[2].y, &(bands[2].v));
- if (bands_n >= 3) {
- proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].v));
- }
- if (bands_n > 3) {
- proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].v));
- }
-}
-
-static void bands_code (void)
-{
- int i;
-
- /* Init to 0 */
- for (i = 0; i < 6; i++) {
- code[i] = '\0';
- }
-
- /* Band 0 (hundreds) */
- if (bands_n == 5) {
- code[0] = band_hsv2code(&bands[0]);
- } else {
- code[0] = 'n';
- }
-
-
- /* Band 1 (tens) */
- if (bands_n != 1) {
- code[1] = band_hsv2code(&bands[1]);
- } else {
- code[1] = 'n';
- }
-
- /* Band 2 (units) */
- code[2] = band_hsv2code(&bands[2]);
-
- /* Band 3 (multiplier) */
- if (bands_n != 1) {
- code[3] = band_hsv2code(&bands[3]);
- } else {
- code[3] = 'n';
- }
-
- /* Band 4 (tolerance) */
- if (bands_n > 3) {
- code[4] = band_hsv2code(&bands[4]);
- } else {
- code[4] = 'n';
- }
-
- /* Write bands' code into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Code: \"%s\"",
- code);
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-}
-
-static char band_hsv2code (struct Resistor_Bands *band)
-{
- char ch;
-
- /*
- * Not able to segmentate:
- * q = 1 2
- * w = 2 3
- * e = 3 g
- * r = 3 4
- * t = 1 8
- * y = 0 1
- * u = 0 1 8
- */
-
- if (band->h < 10) {
- // 1 2 3
- if (band->s < 90) {
- // 1 3
- if (band->v < 85) {
- ch = '1';
- } else {
- ch = '3';
- }
- } else if (band->s < 140) {
- // 1 2 3
- if (band->v < 60) {
- ch = '1';
- } else if (band->v < 85) {
- // 1 2
- ch = 'q';
- } else if (band->v < 90) {
- ch = '2';
- } else if (band->v < 150) {
- // 2 3
- ch = 'w';
- } else {
- ch = '3';
- }
- } else if (band->s < 210) {
- // 2 3
- if (band->v < 90) {
- ch = '2';
- } else if (band->v < 150) {
- // 2 3
- ch = 'w';
- } else {
- ch = '3';
- }
- } else {
- ch = '3';
- }
- } else if (band->h < 35) {
- // 1 3 g
- if (band->s < 130) {
- // 1 3
- if (band->v < 85) {
- ch = '1';
- } else {
- ch = '3';
- }
- } else if (band->s < 140) {
- // 1 3 g
- if (band->v < 85) {
- ch = '1';
- } else if (band->v < 120) {
- ch = '3';
- } else {
- // 3 g
- ch = 'e';
- }
- } else if (band->s < 180) {
- // 3 g
- if (band->v < 120) {
- ch = '3';
- } else {
- // 3 g
- ch = 'e';
- }
- } else {
- ch = '3';
- }
- } else if (band->h < 50) {
- // 1 3
- if (band->s < 140) {
- // 1 3
- if (band->v < 85) {
- ch = '1';
- } else {
- ch = '3';
- }
- } else {
- ch = '3';
- }
- } else if (band->h < 60) {
- // 1 3 4
- if (band->s < 140) {
- // 1 3
- if (band->v < 85) {
- ch = '1';
- } else {
- ch = '3';
- }
- } else if (band->s < 160) {
- ch = '3';
- } else if (band->s < 180) {
- // 3 4
- if (band->v < 110) {
- // 3 4
- ch = 'r';
- } else {
- ch = '3';
- }
- } else {
- ch = '3';
- }
- } else if (band->h < 80) {
- // 1 5
- if (band->s < 165) {
- ch = '1';
- } else {
- ch = '5';
- }
- } else if (band->h < 90) {
- ch = '1';
- } else if (band->h < 100) {
- // 0 1 8 9
- if (band->s < 40) {
- // 1 8 9
- if (band->v < 55) {
- ch = '1';
- } else if (band->v < 80) {
- // 1 8
- ch = 't';
- } else if (band->v < 125) {
- ch = '1';
- } else {
- ch = '9';
- }
- } else if (band->s < 70) {
- // 0 1 8 9
- if (band->v < 45) {
- ch = '0';
- } else if (band->v < 55) {
- // 0 1
- ch = 'y';
- } else if (band->v < 75) {
- // 0 1 8
- ch = 'u';
- } else if (band->v < 80) {
- // 1 8
- ch = 't';
- } else if (band->v < 125) {
- ch = '1';
- } else {
- ch = '9';
- }
- } else if (band->s < 100) {
- // 0 1 8
- if (band->v < 45) {
- ch = '0';
- } else if (band->v < 55) {
- // 0 1
- ch = 'y';
- } else if (band->v < 75) {
- // 0 1 8
- ch = 'u';
- } else if (band->v < 80) {
- // 1 8
- ch = 't';
- } else {
- ch = '1';
- }
- } else if (band->s < 140) {
- // 0 1
- if (band->v < 45) {
- ch = '0';
- } else if (band->v < 75) {
- // 0 1
- ch = 'y';
- } else {
- ch = '1';
- }
- } else {
- ch = '0';
- }
- } else if (band->h < 110) {
- // 0 1 6 8
- if (band->s < 40) {
- // 1 8
- if (band->v < 55) {
- ch = '1';
- } else if (band->v < 80) {
- // 1 8
- ch = 't';
- } else {
- ch = '1';
- }
- } else if (band->s < 100) {
- // 0 1 8
- if (band->v < 45) {
- ch = '0';
- } else if (band->v < 55) {
- // 0 1
- ch = 'y';
- } else if (band->v < 75) {
- // 0 1 8
- ch = 'u';
- } else if (band->v < 80) {
- // 1 8
- ch = 't';
- } else {
- ch = '1';
- }
- } else if (band->s < 140) {
- // 0 1
- if (band->v < 45) {
- ch = '0';
- } else if (band->v < 75) {
- // 0 1
- ch = 'y';
- } else {
- ch = '1';
- }
- } else if (band->s < 200) {
- ch = '0';
- } else {
- ch = '6';
- }
- } else if (band->h < 120) {
- // 0 1 6 7
- if (band->s < 40) {
- ch = '1';
- } else if (band->s < 90) {
- // 0 1
- if (band->v < 45) {
- ch = '0';
- } else if (band->v < 75) {
- // 0 1
- ch = 'y';
- } else {
- ch = '1';
- }
- } else if (band->s < 110) {
- // 0 1 7
- if (band->v < 45) {
- ch = '0';
- } else if (band->v < 75) {
- // 0 1
- ch = 'y';
- } else if (band->v < 120) {
- ch = '1';
- } else {
- ch = '7';
- }
- } else if (band->s < 140) {
- // 0 1
- if (band->v < 45) {
- ch = '0';
- } else if (band->v < 75) {
- // 0 1
- ch = 'y';
- } else {
- ch = '1';
- }
- } else if (band->s < 200) {
- ch = '0';
- } else {
- ch = '6';
- }
- } else if (band->h < 130) {
- // 0 1 7
- if (band->s < 40) {
- ch = '1';
- } else if (band->s < 90) {
- // 0 1
- if (band->v < 45) {
- ch = '0';
- } else if (band->v < 75) {
- // 0 1
- ch = 'y';
- } else {
- ch = '1';
- }
- } else if (band->s < 110) {
- // 0 1 7
- if (band->v < 45) {
- ch = '0';
- } else if (band->v < 75) {
- // 0 1
- ch = 'y';
- } else if (band->v < 120) {
- ch = '1';
- } else {
- ch = '7';
- }
- } else if (band->s < 140) {
- // 0 1
- if (band->v < 45) {
- ch = '0';
- } else if (band->v < 75) {
- // 0 1
- ch = 'y';
- } else {
- ch = '1';
- }
- } else {
- ch = '0';
- }
- } else if (band->h < 140) {
- // 0 1
- if (band->s < 40) {
- ch = '1';
- } else if (band->s < 140) {
- // 0 1
- if (band->v < 45) {
- ch = '0';
- } else if (band->v < 75) {
- // 0 1
- ch = 'y';
- } else {
- ch = '1';
- }
- } else {
- ch = '0';
- }
- } else if (band->h < 150) {
- ch = '0';
- } else {
- ch = '2';
- }
-
- return ch;
-}
-
-static void bands_code_deduce_0 (void)
-{
- /*
- * Not able to segmentate:
- * q = 1 2
- * w = 2 3
- * e = 3 g
- * r = 3 4
- * t = 1 8
- * y = 0 1
- * u = 0 1 8
- */
-
- /* Band 0 (hundreds) */
- switch (code[0]) {
- case 'e':
- code[0] = '3';
- break;
- case 'y':
- code[0] = '1';
- break;
- case 'u':
- code[0] = 't';
- break;
- }
-
- /* Band 2 (units) */
- switch (code[2]) {
- case 'e':
- code[2] = '3';
- break;
- }
-
- /* Band 3 (multiplier) */
- switch (code[3]) {
- case 't':
- code[3] = '1';
- break;
- case 'u':
- code[3] = 'y';
- break;
- }
-
- /* Band 4 (tolerance) */
- switch (code[4]) {
- case 'w':
- code[4] = '2';
- break;
- case 'e':
- code[4] = 'g';
- break;
- case 't':
- code[4] = '1';
- break;
- case 'y':
- code[4] = '1';
- break;
- case 'u':
- code[4] = '1';
- break;
- }
-
- /* Write bands' code into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Code: \"%s\"",
- code);
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-}
-
-static void bands_code_deduce_1 (void)
-{
- /*
- * Not able to segmentate:
-
- * q = 1 2
- * w = 2 3
- * e = 3 g
- * r = 3 4
- * t = 1 8
- * y = 0 1
-
- * u = 0 1 8
- */
-
- /* Band 0 (hundreds) */
- switch (code[0]) {
- case 'q':
- switch (code[1]) {
- case '1':
- case '3':
- case '5':
- case '6':
- case '8':
- code[0] = '1';
- break;
- case '2':
- case '4':
- case '7':
- code[0] = '2';
- break;
- case '0':
- // q
- break;
- }
- break;
- case 'w':
- switch (code[1]) {
- case '2':
- case '4':
- case '7':
- code[0] = '2';
- break;
- case '3':
- case '6':
- case '9':
- code[0] = '3';
- break;
- case '0':
- // w
- break;
- }
- break;
- case 'r':
- switch (code[1]) {
- case '0':
- case '6':
- case '9':
- code[0] = '3';
- break;
- case '7':
- code[0] = '4';
- break;
- case '3':
- // r
- break;
- }
- break;
- case 't':
- switch (code[1]) {
- case '0':
- case '1':
- case '3':
- case '5':
- case '6':
- case '8':
- code[0] = '1';
- break;
- case '2':
- // t
- break;
- }
- break;
- }
-
- /* Band 1 (tens) */
- switch (code[1]) {
- case 'q':
- switch (code[0]) {
- case '5':
- case '9':
- code[1] = '1';
- break;
- case '2':
- case '6':
- case '8':
- code[1] = '2';
- break;
- case '1':
- // q
- break;
- }
- break;
- case 'w':
- switch (code[0]) {
- case '2':
- case '6':
- case '8':
- code[1] = '2';
- break;
- case '3':
- case '4':
- code[1] = '3';
- break;
- case '1':
- // w
- break;
- }
- break;
- case 't':
- switch (code[0]) {
- case '5':
- case '9':
- code[1] = '1';
- break;
- case '6':
- code[1] = '8';
- break;
- case '1':
- // t
- break;
- }
- break;
- case 'y':
- switch (code[0]) {
- case '2':
- case '3':
- code[1] = '0';
- break;
- case '5':
- case '9':
- code[1] = '1';
- break;
- case '1':
- // y
- break;
- }
- break;
- case 'u':
- switch (code[0]) {
- case '2':
- case '3':
- code[1] = '0';
- break;
- case '5':
- case '9':
- code[1] = '1';
- break;
- case '6':
- code[1] = '8';
- break;
- case '1':
- // u
- break;
- }
- break;
- }
-
- /* Band 2 (units) */
- switch (code[2]) {
- case 'y':
- code[2] = '0';
- break;
- case 'u':
- code[2] = '0';
- break;
- }
-
- /* Band 3 (multiplier) */
- switch (code[3]) {
- case 'y':
- code[3] = '0';
- break;
- }
-
- /* Band 4 (tolerance) */
- switch (code[4]) {
- case 'q':
- code[4] = '2';
- break;
- }
-
- /* Write bands' code into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Code: \"%s\"",
- code);
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-}
-
-static int bands_code_deduce_no (void)
-{
- int status;
- int i;
-
- /*
- * Not able to segmentate:
- * q = 1 2
- * w = 2 3
- * e = 3 g
- * r = 3 4
- * t = 1 8
- * y = 0 1
- * u = 0 1 8
- */
-
- for (i = 0; i < 5; i++) {
- switch (code[i]) {
- case 'q':
- case 'w':
- case 'e':
- case 'r':
- case 't':
- case 'y':
- case 'u':
- code[i] = '?';
- break;
- }
- }
-
- for (i = 0; i < 5; i++) {
- if (code[i] == '?') {
- status = RESISTOR_NOK_COLOR;
- return status;
- }
- }
-
- /* Write bands' code into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Code: \"%s\"",
- code);
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-
- status = RESISTOR_OK;
- return status;
-}
-
-static void resistor_value (void)
-{
- int power;
-
- /* Base value */
- base = code[2] - '0';
- if (code[1] != 'n') {
- base += (code[1] - '0') * 10;
- }
- if (code[0] != 'n') {
- base += (code[0] - '0') * 100;
- }
-
- /* Calculate resistance */
- if ((code[3] > '0') && (code[3] < '9')) {
- power = code[3] - '0';
- } else if (code[3] == 'g') {
- power = -1;
- } else if (code[3] == 's') {
- power = -2;
- } else {
- // error
- return;
- }
- resistance = base * pow(10, power);
-}
-
-static int resistor_tolerance (void)
-{
- int status;
-
- if (bands_n != 1) {
- switch (code[4]) {
- case '1':
- tolerance = 1;
- break;
- case '2':
- tolerance = 2;
- break;
- case '4':
- case 'g':
- case 'n':
- tolerance = 5;
- break;
- case '8':
- tolerance = 10;
- break;
- default:
- status = RESISTOR_NOK_TOLERANCE;
- return status;
- }
- }
-
- status = RESISTOR_OK;
- return status;
-}
-
-static int chk_std_value (void)
-{
- int status;
- /* Check that base value is a standard value */
- int std_values_10 [12] = {10,12,15,18,22,27,33,39,47,56,68,82};
- int std_values_5 [12] = {11,13,16,20,24,30,36,43,51,62,75,91};
- bool std_value_nok = true;
- int i;
-
- if (bands_n != 1) {
- for (i = 0; i < 12; i++) {
- if (base == std_values_10[i]) {
- std_value_nok = false;
- }
- if (base == (std_values_10[i] * 10)) {
- std_value_nok = false;
- }
- }
- if (tolerance <= 5) {
- for (i = 0; i < 12; i++) {
- if (base == std_values_5[i]) {
- std_value_nok = false;
- }
- if (base == (std_values_5[i] * 10)) {
- std_value_nok = false;
- }
- }
- }
- } else {
- if (base == 0) {
- std_value_nok = false;
- }
- }
-
- if (std_value_nok) {
- status = RESISTOR_NOK_STD_VALUE;
- return status;
- }
-
- status = RESISTOR_OK;
- return status;
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* pow() */ + #include <cmath> + /* snprintf() & fflush() */ + #include <cstdio> + +/* Packages ------------------------------------------------------------------*/ + /* openCV */ + #include <opencv2/opencv.hpp> + +/* Project -------------------------------------------------------------------*/ + /* CONSTANTS */ + #include "img_iface.hpp" + /* user_iface_log */ + #include "user_iface.hpp" + +/* Module --------------------------------------------------------------------*/ + #include "proc_common.hpp" + + #include "proc_resistor.hpp" + + +/****************************************************************************** + ******* structs ************************************************************** + ******************************************************************************/ +struct Resistor_Bands { + /* position */ + int x; + int y; + + /* value */ + unsigned char h; + unsigned char s; + unsigned char v; +}; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ + +/* Static --------------------------------------------------------------------*/ +static class std::vector <class std::vector <class cv::Point_ <int>>> contours; +static class cv::Mat hierarchy; +static class cv::RotatedRect rect_rot; +static class cv::Rect_ <int> rect; +static int bkgd; +static int bands_n; +static struct Resistor_Bands bands [5]; +static char code [6]; +static int base; +static float resistance; +static int tolerance; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_resistor (int status); + +static int resistor_find (void); +static void resistor_align (void); +static void resistor_dimensions_0 (void); +static void resistor_crop_0 (void); +static void resistor_bkgd (void); +static void resistor_dimensions_1 (void); +static void resistor_crop_1 (void); +static void separate_bkgd_bands_h (void); +static void separate_bkgd_bands_s (void); +static void separate_bkgd_bands_v (void); +static void bkgd_find (void); +static int bands_find (void); +static void bands_colors (void); +static void bands_code (void); +static char band_hsv2code (struct Resistor_Bands *band); +static void bands_code_deduce_0 (void); +static void bands_code_deduce_1 (void); +static int bands_code_deduce_no (void); +static void resistor_value (void); +static int resistor_tolerance (void); +static int chk_std_value (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +int proc_resistor (void) +{ + int status; + + proc_save_mem(0); + /* Find resistor (position and angle) */ + { + /* Measure time */ + clock_start(); + + status = resistor_find(); + if (status) { + result_resistor(status); + return status; + } + + /* Measure time */ + clock_stop("Find resistor"); + } + /* Align resistor, find its dimensions, and crop */ + { + /* Measure time */ + clock_start(); + + resistor_align(); + resistor_dimensions_0(); + resistor_crop_0(); + + /* Measure time */ + clock_stop("Align, dimensions, & crop"); + } + /* Find backgroung color */ + { + /* Measure time */ + clock_start(); + + resistor_bkgd(); + + /* Measure time */ + clock_stop("Background color"); + } + /* Crop more */ + { + /* Measure time */ + clock_start(); + + resistor_dimensions_1(); + resistor_crop_1(); + + /* Measure time */ + clock_stop("Crop more"); + } + /* Separate background (BK) and lines (WH) */ + { + /* Measure time */ + clock_start(); + + separate_bkgd_bands_h(); + separate_bkgd_bands_s(); + separate_bkgd_bands_v(); + bkgd_find(); + + /* Measure time */ + clock_stop("Separate bkgd from bands"); + } + /* Find bands: contours -> rectangles */ + { + /* Measure time */ + clock_start(); + + status = bands_find(); + if (status) { + result_resistor(status); + return status; + } + + /* Measure time */ + clock_stop("Find bands"); + } + /* Read values on the center of each band */ + { + /* Measure time */ + clock_start(); + + bands_colors(); + + /* Measure time */ + clock_stop("Bands' colors"); + } + /* Interpret colors */ + { + /* Measure time */ + clock_start(); + + bands_code(); + bands_code_deduce_0(); + bands_code_deduce_1(); + status = bands_code_deduce_no(); + if (status) { + result_resistor(status); + return status; + } + + /* Measure time */ + clock_stop("Interpret colors"); + } + /* Calculate resistor value & tolerance */ + { + /* Measure time */ + clock_start(); + + resistor_value(); + status = resistor_tolerance(); + if (status) { + result_resistor(status); + return status; + } + + /* Write resistor value into log */ + if (bands_n != 1) { + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Resistance: %.2E ± %i%% Ohm", + resistance, tolerance); + } else { + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Resistance: 0 Ohm"); + } + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + /* Measure time */ + clock_stop("Calculate resistance & tolerance"); + } + /* Check STD value */ + { + /* Measure time */ + clock_start(); + + status = chk_std_value(); + if (status) { + result_resistor(status); + return status; + } + + /* Measure time */ + clock_stop("Chk STD values"); + } + + status = RESISTOR_OK; + result_resistor(status); + return status; +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void result_resistor (int status) +{ + /* Write result into log */ + switch (status) { + case RESISTOR_OK: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Resistor: OK"); + break; + case RESISTOR_NOK_RESISTOR: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Resistor: NOK_RESISTOR"); + break; + case RESISTOR_NOK_BANDS: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Resistor: NOK_BANDS"); + break; + case RESISTOR_NOK_COLOR: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Resistor: NOK_COLOR"); + break; + case RESISTOR_NOK_STD_VALUE: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Resistor: NOK_STD_VALUE"); + break; + case RESISTOR_NOK_TOLERANCE: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Resistor: NOK_TOLERANCE"); + break; + default: + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Resistor: NOK"); + break; + } + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + +static int resistor_find (void) +{ + int status; + + proc_load_mem(0); + + /* BGR -> HSV */ + proc_cvt_color(cv::COLOR_BGR2HSV); + proc_save_mem(19); + + proc_cmp(IMG_IFACE_CMP_SATURATION); + proc_smooth(IMGI_SMOOTH_MEDIAN, 7); + proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); + proc_save_mem(1); + proc_dilate_erode(10); + proc_contours(&contours, &hierarchy); + + /* If no contour is found, error: NOK_RESISTOR */ + if (!contours.size()) { + status = RESISTOR_NOK_RESISTOR; + return status; + } + + proc_min_area_rect(&(contours[0]), &rect_rot, true); + + /* If angle is < -45º, it is taking into acount the incorrect side */ + if (rect_rot.angle < -45.0) { + rect_rot.angle += 90.0; + } + + status = RESISTOR_OK; + return status; +} + +static void resistor_align (void) +{ + proc_load_mem(19); + proc_rotate(rect_rot.center.x, rect_rot.center.y, rect_rot.angle); + proc_save_mem(2); + proc_load_mem(1); + proc_rotate(rect_rot.center.x, rect_rot.center.y, rect_rot.angle); + proc_save_mem(3); +} + +static void resistor_dimensions_0 (void) +{ + proc_load_mem(3); + + proc_dilate_erode(10); + proc_contours(&contours, &hierarchy); + proc_bounding_rect(&(contours[0]), &rect, true); +} + +static void resistor_crop_0 (void) +{ + int x; + int y; + int w; + int h; + + proc_load_mem(2); + + w = rect.width; + h = rect.height; + x = rect.x; + y = rect.y; + proc_ROI(x, y, w, h); + proc_save_mem(4); +} + +static void resistor_bkgd (void) +{ + uint8_t bkgd_hue; + uint8_t bkgd_sat; + + /* hue */ + proc_load_mem(4); + proc_cmp(IMG_IFACE_CMP_HUE); + proc_median_vertical(); + proc_median_horizontal(); + proc_pixel_get(0, 0, &bkgd_hue); + + /* saturation */ + proc_load_mem(4); + proc_cmp(IMG_IFACE_CMP_SATURATION); + proc_median_vertical(); + proc_median_horizontal(); + proc_pixel_get(0, 0, &bkgd_sat); + + if (bkgd_hue < 50) { + /* Beige */ + bkgd = 0; + } else { + /* Blue */ + if ((bkgd_hue < 90) || (bkgd_sat < 100)) { + /* Teal blue */ + bkgd = 1; + } else if (bkgd_hue >= 105) { + /* Dark blue */ + bkgd = 2; + } else { + /* Normal blue */ + bkgd = 3; + } + } +} + +static void resistor_dimensions_1 (void) +{ + proc_load_mem(3); + + proc_dilate_erode(10); + proc_erode_dilate((rect.height * 0.67) / 2); + proc_contours(&contours, &hierarchy); + proc_bounding_rect(&(contours[0]), &rect, true); +} + +static void resistor_crop_1 (void) +{ + int x; + int y; + int w; + int h; + + proc_load_mem(2); + + w = rect.width * 0.95; + h = rect.height * 0.8; + x = rect.x + w * (1.0 - 0.95) / 2.0; + y = rect.y + h * (1.0 - 0.8) / 2.0; + proc_ROI(x, y, w, h); + proc_save_mem(4); +} + +static void separate_bkgd_bands_h (void) +{ + proc_load_mem(4); + + proc_cmp(IMG_IFACE_CMP_HUE); + proc_median_vertical(); + proc_save_mem(9); + + switch (bkgd) { + case 0: + proc_threshold(cv::THRESH_TOZERO_INV, 20); + proc_threshold(cv::THRESH_TOZERO, 5); + break; + case 1: + proc_threshold(cv::THRESH_TOZERO_INV, 100); + proc_threshold(cv::THRESH_TOZERO, 70); + break; + case 2: + proc_threshold(cv::THRESH_TOZERO_INV, 115); + proc_threshold(cv::THRESH_TOZERO, 100); + break; + case 3: + proc_threshold(cv::THRESH_TOZERO_INV, 110); + proc_threshold(cv::THRESH_TOZERO, 90); + break; + } + proc_threshold(cv::THRESH_BINARY_INV, 1); + proc_save_mem(5); +} + +static void separate_bkgd_bands_s (void) +{ + proc_load_mem(4); + + proc_cmp(IMG_IFACE_CMP_SATURATION); + proc_median_vertical(); + proc_save_mem(10); + + switch (bkgd) { + + case 0: + proc_threshold(cv::THRESH_TOZERO_INV, 160); + proc_threshold(cv::THRESH_TOZERO, 110); + break; + case 1: + proc_threshold(cv::THRESH_TOZERO_INV, 180); + proc_threshold(cv::THRESH_TOZERO, 30); + break; + case 2: + proc_threshold(cv::THRESH_TOZERO_INV, 190); + proc_threshold(cv::THRESH_TOZERO, 170); + break; + case 3: + proc_threshold(cv::THRESH_TOZERO_INV, 210); + proc_threshold(cv::THRESH_TOZERO, 120); + break; + } + proc_threshold(cv::THRESH_BINARY_INV, 1); + proc_save_mem(6); +} + +static void separate_bkgd_bands_v (void) +{ + proc_load_mem(4); + + proc_cmp(IMG_IFACE_CMP_VALUE); + proc_median_vertical(); + proc_save_mem(11); + + switch (bkgd) { + case 0: + proc_threshold(cv::THRESH_TOZERO_INV, 170); + proc_threshold(cv::THRESH_TOZERO, 100); + break; + + case 1: + proc_threshold(cv::THRESH_TOZERO_INV, 180); + proc_threshold(cv::THRESH_TOZERO, 100); + break; + case 2: + proc_threshold(cv::THRESH_TOZERO_INV, 180); + proc_threshold(cv::THRESH_TOZERO, 150); + break; + case 3: + proc_threshold(cv::THRESH_TOZERO_INV, 190); + proc_threshold(cv::THRESH_TOZERO, 90); + break; + } + proc_threshold(cv::THRESH_BINARY_INV, 1); + proc_save_mem(7); +} + +static void bkgd_find (void) +{ + /* Merge the components: H | S | V */ + proc_load_mem(7); + proc_save_ref(); + proc_load_mem(6); + proc_or_2ref(); + proc_save_ref(); + proc_load_mem(5); + proc_or_2ref(); + if (rect.width * 0.95 > 80) { + proc_dilate_erode(1); + } + proc_save_mem(8); +} + +static int bands_find (void) +{ + int status; + + proc_load_mem(8); + + /* Contours */ + proc_contours(&contours, &hierarchy); + if (contours.size() > 5) { + proc_load_mem(8); + proc_dilate_erode(1); + proc_contours(&contours, &hierarchy); + } + + bands_n = contours.size(); + if ((bands_n == 0) || (bands_n == 2) || (bands_n > 5)) { + status = RESISTOR_NOK_BANDS; + return status; + } + + /* Band 0 (hundreds) */ + if (bands_n == 5) { + proc_bounding_rect(&(contours[4]), &rect, true); + bands[0].x = rect.x + rect.width / 2.0; + bands[0].y = rect.y + rect.height / 2.0; + } + + /* Band 1 (tens) */ + if (bands_n >= 3) { + if (bands_n > 3) { + proc_bounding_rect(&(contours[3]), &rect, true); + } else { + proc_bounding_rect(&(contours[2]), &rect, true); + } + bands[1].x = rect.x + rect.width / 2.0; + bands[1].y = rect.y + rect.height / 2.0; + } + + /* Band 2 (units) */ + if (bands_n > 3) { + proc_bounding_rect(&(contours[2]), &rect, true); + } else if (bands_n == 3) { + proc_bounding_rect(&(contours[1]), &rect, true); + } else { /* bands_n == 1 */ + proc_bounding_rect(&(contours[0]), &rect, true); + } + bands[2].x = rect.x + rect.width / 2.0; + bands[2].y = rect.y + rect.height / 2.0; + + /* Band 3 (multiplier) */ + if (bands_n >= 3) { + if (bands_n > 3) { + proc_bounding_rect(&(contours[1]), &rect, true); + } else { + proc_bounding_rect(&(contours[0]), &rect, true); + } + bands[3].x = rect.x + rect.width / 2.0; + bands[3].y = rect.y + rect.height / 2.0; + } + + /* Band 4 (tolerance) */ + if (bands_n > 3) { + proc_bounding_rect(&(contours[0]), &rect, true); + bands[4].x = rect.x + rect.width / 2.0; + bands[4].y = rect.y + rect.height / 2.0; + } + + status = RESISTOR_OK; + return status; +} + +static void bands_colors (void) +{ + /* Hue */ + proc_load_mem(9); + if (bands_n == 5) { + proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].h)); + } + if (bands_n >= 3) { + proc_pixel_get(bands[1].x, bands[1].y, &(bands[1].h)); + } + proc_pixel_get(bands[2].x, bands[2].y, &(bands[2].h)); + if (bands_n >= 3) { + proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].h)); + } + if (bands_n > 3) { + proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].h)); + } + + /* Saturation */ + proc_load_mem(10); + if (bands_n == 5) { + proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].s)); + } + if (bands_n >= 3) { + proc_pixel_get(bands[1].x, bands[1].y, &(bands[1].s)); + } + proc_pixel_get(bands[2].x, bands[2].y, &(bands[2].s)); + if (bands_n >= 3) { + proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].s)); + } + if (bands_n > 3) { + proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].s)); + } + + /* Value */ + proc_load_mem(11); + if (bands_n == 5) { + proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].v)); + } + if (bands_n >= 3) { + proc_pixel_get(bands[1].x, bands[1].y, &(bands[1].v)); + } + proc_pixel_get(bands[2].x, bands[2].y, &(bands[2].v)); + if (bands_n >= 3) { + proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].v)); + } + if (bands_n > 3) { + proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].v)); + } +} + +static void bands_code (void) +{ + int i; + + /* Init to 0 */ + for (i = 0; i < 6; i++) { + code[i] = '\0'; + } + + /* Band 0 (hundreds) */ + if (bands_n == 5) { + code[0] = band_hsv2code(&bands[0]); + } else { + code[0] = 'n'; + } + + + /* Band 1 (tens) */ + if (bands_n != 1) { + code[1] = band_hsv2code(&bands[1]); + } else { + code[1] = 'n'; + } + + /* Band 2 (units) */ + code[2] = band_hsv2code(&bands[2]); + + /* Band 3 (multiplier) */ + if (bands_n != 1) { + code[3] = band_hsv2code(&bands[3]); + } else { + code[3] = 'n'; + } + + /* Band 4 (tolerance) */ + if (bands_n > 3) { + code[4] = band_hsv2code(&bands[4]); + } else { + code[4] = 'n'; + } + + /* Write bands' code into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Code: \"%s\"", + code); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + +static char band_hsv2code (struct Resistor_Bands *band) +{ + char ch; + + /* + * Not able to segmentate: + * q = 1 2 + * w = 2 3 + * e = 3 g + * r = 3 4 + * t = 1 8 + * y = 0 1 + * u = 0 1 8 + */ + + if (band->h < 10) { + // 1 2 3 + if (band->s < 90) { + // 1 3 + if (band->v < 85) { + ch = '1'; + } else { + ch = '3'; + } + } else if (band->s < 140) { + // 1 2 3 + if (band->v < 60) { + ch = '1'; + } else if (band->v < 85) { + // 1 2 + ch = 'q'; + } else if (band->v < 90) { + ch = '2'; + } else if (band->v < 150) { + // 2 3 + ch = 'w'; + } else { + ch = '3'; + } + } else if (band->s < 210) { + // 2 3 + if (band->v < 90) { + ch = '2'; + } else if (band->v < 150) { + // 2 3 + ch = 'w'; + } else { + ch = '3'; + } + } else { + ch = '3'; + } + } else if (band->h < 35) { + // 1 3 g + if (band->s < 130) { + // 1 3 + if (band->v < 85) { + ch = '1'; + } else { + ch = '3'; + } + } else if (band->s < 140) { + // 1 3 g + if (band->v < 85) { + ch = '1'; + } else if (band->v < 120) { + ch = '3'; + } else { + // 3 g + ch = 'e'; + } + } else if (band->s < 180) { + // 3 g + if (band->v < 120) { + ch = '3'; + } else { + // 3 g + ch = 'e'; + } + } else { + ch = '3'; + } + } else if (band->h < 50) { + // 1 3 + if (band->s < 140) { + // 1 3 + if (band->v < 85) { + ch = '1'; + } else { + ch = '3'; + } + } else { + ch = '3'; + } + } else if (band->h < 60) { + // 1 3 4 + if (band->s < 140) { + // 1 3 + if (band->v < 85) { + ch = '1'; + } else { + ch = '3'; + } + } else if (band->s < 160) { + ch = '3'; + } else if (band->s < 180) { + // 3 4 + if (band->v < 110) { + // 3 4 + ch = 'r'; + } else { + ch = '3'; + } + } else { + ch = '3'; + } + } else if (band->h < 80) { + // 1 5 + if (band->s < 165) { + ch = '1'; + } else { + ch = '5'; + } + } else if (band->h < 90) { + ch = '1'; + } else if (band->h < 100) { + // 0 1 8 9 + if (band->s < 40) { + // 1 8 9 + if (band->v < 55) { + ch = '1'; + } else if (band->v < 80) { + // 1 8 + ch = 't'; + } else if (band->v < 125) { + ch = '1'; + } else { + ch = '9'; + } + } else if (band->s < 70) { + // 0 1 8 9 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 55) { + // 0 1 + ch = 'y'; + } else if (band->v < 75) { + // 0 1 8 + ch = 'u'; + } else if (band->v < 80) { + // 1 8 + ch = 't'; + } else if (band->v < 125) { + ch = '1'; + } else { + ch = '9'; + } + } else if (band->s < 100) { + // 0 1 8 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 55) { + // 0 1 + ch = 'y'; + } else if (band->v < 75) { + // 0 1 8 + ch = 'u'; + } else if (band->v < 80) { + // 1 8 + ch = 't'; + } else { + ch = '1'; + } + } else if (band->s < 140) { + // 0 1 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 75) { + // 0 1 + ch = 'y'; + } else { + ch = '1'; + } + } else { + ch = '0'; + } + } else if (band->h < 110) { + // 0 1 6 8 + if (band->s < 40) { + // 1 8 + if (band->v < 55) { + ch = '1'; + } else if (band->v < 80) { + // 1 8 + ch = 't'; + } else { + ch = '1'; + } + } else if (band->s < 100) { + // 0 1 8 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 55) { + // 0 1 + ch = 'y'; + } else if (band->v < 75) { + // 0 1 8 + ch = 'u'; + } else if (band->v < 80) { + // 1 8 + ch = 't'; + } else { + ch = '1'; + } + } else if (band->s < 140) { + // 0 1 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 75) { + // 0 1 + ch = 'y'; + } else { + ch = '1'; + } + } else if (band->s < 200) { + ch = '0'; + } else { + ch = '6'; + } + } else if (band->h < 120) { + // 0 1 6 7 + if (band->s < 40) { + ch = '1'; + } else if (band->s < 90) { + // 0 1 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 75) { + // 0 1 + ch = 'y'; + } else { + ch = '1'; + } + } else if (band->s < 110) { + // 0 1 7 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 75) { + // 0 1 + ch = 'y'; + } else if (band->v < 120) { + ch = '1'; + } else { + ch = '7'; + } + } else if (band->s < 140) { + // 0 1 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 75) { + // 0 1 + ch = 'y'; + } else { + ch = '1'; + } + } else if (band->s < 200) { + ch = '0'; + } else { + ch = '6'; + } + } else if (band->h < 130) { + // 0 1 7 + if (band->s < 40) { + ch = '1'; + } else if (band->s < 90) { + // 0 1 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 75) { + // 0 1 + ch = 'y'; + } else { + ch = '1'; + } + } else if (band->s < 110) { + // 0 1 7 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 75) { + // 0 1 + ch = 'y'; + } else if (band->v < 120) { + ch = '1'; + } else { + ch = '7'; + } + } else if (band->s < 140) { + // 0 1 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 75) { + // 0 1 + ch = 'y'; + } else { + ch = '1'; + } + } else { + ch = '0'; + } + } else if (band->h < 140) { + // 0 1 + if (band->s < 40) { + ch = '1'; + } else if (band->s < 140) { + // 0 1 + if (band->v < 45) { + ch = '0'; + } else if (band->v < 75) { + // 0 1 + ch = 'y'; + } else { + ch = '1'; + } + } else { + ch = '0'; + } + } else if (band->h < 150) { + ch = '0'; + } else { + ch = '2'; + } + + return ch; +} + +static void bands_code_deduce_0 (void) +{ + /* + * Not able to segmentate: + * q = 1 2 + * w = 2 3 + * e = 3 g + * r = 3 4 + * t = 1 8 + * y = 0 1 + * u = 0 1 8 + */ + + /* Band 0 (hundreds) */ + switch (code[0]) { + case 'e': + code[0] = '3'; + break; + case 'y': + code[0] = '1'; + break; + case 'u': + code[0] = 't'; + break; + } + + /* Band 2 (units) */ + switch (code[2]) { + case 'e': + code[2] = '3'; + break; + } + + /* Band 3 (multiplier) */ + switch (code[3]) { + case 't': + code[3] = '1'; + break; + case 'u': + code[3] = 'y'; + break; + } + + /* Band 4 (tolerance) */ + switch (code[4]) { + case 'w': + code[4] = '2'; + break; + case 'e': + code[4] = 'g'; + break; + case 't': + code[4] = '1'; + break; + case 'y': + code[4] = '1'; + break; + case 'u': + code[4] = '1'; + break; + } + + /* Write bands' code into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Code: \"%s\"", + code); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + +static void bands_code_deduce_1 (void) +{ + /* + * Not able to segmentate: + + * q = 1 2 + * w = 2 3 + * e = 3 g + * r = 3 4 + * t = 1 8 + * y = 0 1 + + * u = 0 1 8 + */ + + /* Band 0 (hundreds) */ + switch (code[0]) { + case 'q': + switch (code[1]) { + case '1': + case '3': + case '5': + case '6': + case '8': + code[0] = '1'; + break; + case '2': + case '4': + case '7': + code[0] = '2'; + break; + case '0': + // q + break; + } + break; + case 'w': + switch (code[1]) { + case '2': + case '4': + case '7': + code[0] = '2'; + break; + case '3': + case '6': + case '9': + code[0] = '3'; + break; + case '0': + // w + break; + } + break; + case 'r': + switch (code[1]) { + case '0': + case '6': + case '9': + code[0] = '3'; + break; + case '7': + code[0] = '4'; + break; + case '3': + // r + break; + } + break; + case 't': + switch (code[1]) { + case '0': + case '1': + case '3': + case '5': + case '6': + case '8': + code[0] = '1'; + break; + case '2': + // t + break; + } + break; + } + + /* Band 1 (tens) */ + switch (code[1]) { + case 'q': + switch (code[0]) { + case '5': + case '9': + code[1] = '1'; + break; + case '2': + case '6': + case '8': + code[1] = '2'; + break; + case '1': + // q + break; + } + break; + case 'w': + switch (code[0]) { + case '2': + case '6': + case '8': + code[1] = '2'; + break; + case '3': + case '4': + code[1] = '3'; + break; + case '1': + // w + break; + } + break; + case 't': + switch (code[0]) { + case '5': + case '9': + code[1] = '1'; + break; + case '6': + code[1] = '8'; + break; + case '1': + // t + break; + } + break; + case 'y': + switch (code[0]) { + case '2': + case '3': + code[1] = '0'; + break; + case '5': + case '9': + code[1] = '1'; + break; + case '1': + // y + break; + } + break; + case 'u': + switch (code[0]) { + case '2': + case '3': + code[1] = '0'; + break; + case '5': + case '9': + code[1] = '1'; + break; + case '6': + code[1] = '8'; + break; + case '1': + // u + break; + } + break; + } + + /* Band 2 (units) */ + switch (code[2]) { + case 'y': + code[2] = '0'; + break; + case 'u': + code[2] = '0'; + break; + } + + /* Band 3 (multiplier) */ + switch (code[3]) { + case 'y': + code[3] = '0'; + break; + } + + /* Band 4 (tolerance) */ + switch (code[4]) { + case 'q': + code[4] = '2'; + break; + } + + /* Write bands' code into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Code: \"%s\"", + code); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; +} + +static int bands_code_deduce_no (void) +{ + int status; + int i; + + /* + * Not able to segmentate: + * q = 1 2 + * w = 2 3 + * e = 3 g + * r = 3 4 + * t = 1 8 + * y = 0 1 + * u = 0 1 8 + */ + + for (i = 0; i < 5; i++) { + switch (code[i]) { + case 'q': + case 'w': + case 'e': + case 'r': + case 't': + case 'y': + case 'u': + code[i] = '?'; + break; + } + } + + for (i = 0; i < 5; i++) { + if (code[i] == '?') { + status = RESISTOR_NOK_COLOR; + return status; + } + } + + /* Write bands' code into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, + "Code: \"%s\"", + code); + user_iface_log.lvl[user_iface_log.len] = 0; + (user_iface_log.len)++; + + status = RESISTOR_OK; + return status; +} + +static void resistor_value (void) +{ + int power; + + /* Base value */ + base = code[2] - '0'; + if (code[1] != 'n') { + base += (code[1] - '0') * 10; + } + if (code[0] != 'n') { + base += (code[0] - '0') * 100; + } + + /* Calculate resistance */ + if ((code[3] > '0') && (code[3] < '9')) { + power = code[3] - '0'; + } else if (code[3] == 'g') { + power = -1; + } else if (code[3] == 's') { + power = -2; + } else { + // error + return; + } + resistance = base * pow(10, power); +} + +static int resistor_tolerance (void) +{ + int status; + + if (bands_n != 1) { + switch (code[4]) { + case '1': + tolerance = 1; + break; + case '2': + tolerance = 2; + break; + case '4': + case 'g': + case 'n': + tolerance = 5; + break; + case '8': + tolerance = 10; + break; + default: + status = RESISTOR_NOK_TOLERANCE; + return status; + } + } + + status = RESISTOR_OK; + return status; +} + +static int chk_std_value (void) +{ + int status; + /* Check that base value is a standard value */ + int std_values_10 [12] = {10,12,15,18,22,27,33,39,47,56,68,82}; + int std_values_5 [12] = {11,13,16,20,24,30,36,43,51,62,75,91}; + bool std_value_nok = true; + int i; + + if (bands_n != 1) { + for (i = 0; i < 12; i++) { + if (base == std_values_10[i]) { + std_value_nok = false; + } + if (base == (std_values_10[i] * 10)) { + std_value_nok = false; + } + } + if (tolerance <= 5) { + for (i = 0; i < 12; i++) { + if (base == std_values_5[i]) { + std_value_nok = false; + } + if (base == (std_values_5[i] * 10)) { + std_value_nok = false; + } + } + } + } else { + if (base == 0) { + std_value_nok = false; + } + } + + if (std_value_nok) { + status = RESISTOR_NOK_STD_VALUE; + return status; + } + + status = RESISTOR_OK; + return status; +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/save/inc/save.h b/modules/save/inc/save.h index dc0d850..d398a0b 100644 --- a/modules/save/inc/save.h +++ b/modules/save/inc/save.h @@ -1,74 +1,74 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_SAVE_H
- # define VA_SAVE_H
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* FILENAME_MAX */
- #include <stdio.h>
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
- # define ENV_HOME "HOME"
-
- # define USER_PROG_DIR "vision-artificial/"
- # define USER_SAVED_DIR "vision-artificial/saved/"
- # define USER_LABELS_DIR "vision-artificial/labels/"
- # define USER_LABELS_FAIL_DIR "vision-artificial/labels/fail"
- # define USER_OBJECTS_DIR "vision-artificial/objects/"
- # define USER_OBJECTS_FAIL_DIR "vision-artificial/objects/fail"
- # define USER_COINS_DIR "vision-artificial/coins/"
- # define USER_COINS_FAIL_DIR "vision-artificial/coins/fail"
- # define USER_RESISTORS_DIR "vision-artificial/resistors/"
- # define USER_RESISTORS_FAIL_DIR "vision-artificial/resistors/fail"
- # define SAVED_NAME_DEFAULT "saved"
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
- extern char home_path [FILENAME_MAX];
- extern char user_prog_path [FILENAME_MAX];
- extern char saved_path [FILENAME_MAX];
- extern char labels_path [FILENAME_MAX];
- extern char labels_fail_path [FILENAME_MAX];
- extern char objects_path [FILENAME_MAX];
- extern char objects_fail_path [FILENAME_MAX];
- extern char coins_path [FILENAME_MAX];
- extern char coins_fail_path [FILENAME_MAX];
- extern char resistors_path [FILENAME_MAX];
- extern char resistors_fail_path [FILENAME_MAX];
- extern char saved_name [FILENAME_MAX];
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- void save_init (void);
- void save_cleanup (void);
- void save_clr (void);
- void load_image_file (const char *fpath, const char *fname);
- void save_image_file (const char *fpath, const char *save_as);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* save.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_SAVE_H + # define VA_SAVE_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* FILENAME_MAX */ + #include <stdio.h> + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define ENV_HOME "HOME" + + # define USER_PROG_DIR "vision-artificial/" + # define USER_SAVED_DIR "vision-artificial/saved/" + # define USER_LABELS_DIR "vision-artificial/labels/" + # define USER_LABELS_FAIL_DIR "vision-artificial/labels/fail" + # define USER_OBJECTS_DIR "vision-artificial/objects/" + # define USER_OBJECTS_FAIL_DIR "vision-artificial/objects/fail" + # define USER_COINS_DIR "vision-artificial/coins/" + # define USER_COINS_FAIL_DIR "vision-artificial/coins/fail" + # define USER_RESISTORS_DIR "vision-artificial/resistors/" + # define USER_RESISTORS_FAIL_DIR "vision-artificial/resistors/fail" + # define SAVED_NAME_DEFAULT "saved" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern char home_path [FILENAME_MAX]; + extern char user_prog_path [FILENAME_MAX]; + extern char saved_path [FILENAME_MAX]; + extern char labels_path [FILENAME_MAX]; + extern char labels_fail_path [FILENAME_MAX]; + extern char objects_path [FILENAME_MAX]; + extern char objects_fail_path [FILENAME_MAX]; + extern char coins_path [FILENAME_MAX]; + extern char coins_fail_path [FILENAME_MAX]; + extern char resistors_path [FILENAME_MAX]; + extern char resistors_fail_path [FILENAME_MAX]; + extern char saved_name [FILENAME_MAX]; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void save_init (void); + void save_cleanup (void); + void save_clr (void); + void load_image_file (const char *fpath, const char *fname); + void save_image_file (const char *fpath, const char *save_as); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* save.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/save/inc/save.hpp b/modules/save/inc/save.hpp index edabbf3..70025ad 100644 --- a/modules/save/inc/save.hpp +++ b/modules/save/inc/save.hpp @@ -1,91 +1,91 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_SAVE_HPP
- # define VA_SAVE_HPP
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* FILENAME_MAX */
- #include <cstdio>
-
-/* Project -------------------------------------------------------------------*/
- /* opencv */
- #include <opencv2/opencv.hpp>
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-extern "C" {
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
- # define ENV_HOME "HOME"
-
- # define USER_PROG_DIR "vision-artificial/"
- # define USER_SAVED_DIR "vision-artificial/saved/"
- # define USER_LABELS_DIR "vision-artificial/labels/"
- # define USER_LABELS_FAIL_DIR "vision-artificial/labels/fail"
- # define USER_OBJECTS_DIR "vision-artificial/objects/"
- # define USER_OBJECTS_FAIL_DIR "vision-artificial/objects/fail"
- # define USER_COINS_DIR "vision-artificial/coins/"
- # define USER_COINS_FAIL_DIR "vision-artificial/coins/fail"
- # define USER_RESISTORS_DIR "vision-artificial/resistors/"
- # define USER_RESISTORS_FAIL_DIR "vision-artificial/resistors/fail"
- # define SAVED_NAME_DEFAULT "saved"
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
- extern class cv::Mat image;
- extern char home_path [FILENAME_MAX];
- extern char user_prog_path [FILENAME_MAX];
- extern char saved_path [FILENAME_MAX];
- extern char labels_path [FILENAME_MAX];
- extern char labels_fail_path [FILENAME_MAX];
- extern char objects_path [FILENAME_MAX];
- extern char objects_fail_path [FILENAME_MAX];
- extern char coins_path [FILENAME_MAX];
- extern char coins_fail_path [FILENAME_MAX];
- extern char resistors_path [FILENAME_MAX];
- extern char resistors_fail_path [FILENAME_MAX];
- extern char saved_name [FILENAME_MAX];
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- void save_init (void);
- void save_cleanup (void);
- void save_clr (void);
- void load_image_file (const char *fpath, const char *fname);
- void save_image_file (const char *fpath, const char *save_as);
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-} /* extern "C" */
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* save.hpp */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_SAVE_HPP + # define VA_SAVE_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* FILENAME_MAX */ + #include <cstdio> + +/* Project -------------------------------------------------------------------*/ + /* opencv */ + #include <opencv2/opencv.hpp> + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define ENV_HOME "HOME" + + # define USER_PROG_DIR "vision-artificial/" + # define USER_SAVED_DIR "vision-artificial/saved/" + # define USER_LABELS_DIR "vision-artificial/labels/" + # define USER_LABELS_FAIL_DIR "vision-artificial/labels/fail" + # define USER_OBJECTS_DIR "vision-artificial/objects/" + # define USER_OBJECTS_FAIL_DIR "vision-artificial/objects/fail" + # define USER_COINS_DIR "vision-artificial/coins/" + # define USER_COINS_FAIL_DIR "vision-artificial/coins/fail" + # define USER_RESISTORS_DIR "vision-artificial/resistors/" + # define USER_RESISTORS_FAIL_DIR "vision-artificial/resistors/fail" + # define SAVED_NAME_DEFAULT "saved" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern class cv::Mat image; + extern char home_path [FILENAME_MAX]; + extern char user_prog_path [FILENAME_MAX]; + extern char saved_path [FILENAME_MAX]; + extern char labels_path [FILENAME_MAX]; + extern char labels_fail_path [FILENAME_MAX]; + extern char objects_path [FILENAME_MAX]; + extern char objects_fail_path [FILENAME_MAX]; + extern char coins_path [FILENAME_MAX]; + extern char coins_fail_path [FILENAME_MAX]; + extern char resistors_path [FILENAME_MAX]; + extern char resistors_fail_path [FILENAME_MAX]; + extern char saved_name [FILENAME_MAX]; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void save_init (void); + void save_cleanup (void); + void save_clr (void); + void load_image_file (const char *fpath, const char *fname); + void save_image_file (const char *fpath, const char *save_as); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* save.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/save/src/save.cpp b/modules/save/src/save.cpp index 861a06e..0255a43 100644 --- a/modules/save/src/save.cpp +++ b/modules/save/src/save.cpp @@ -1,194 +1,194 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* errno */
- #include <cerrno>
- /* fscanf() & fprintf() & FILE & FILENAME_MAX & snprintf() */
- #include <cstdio>
- /* getenv() */
- #include <cstdlib>
-
-/* Linux ---------------------------------------------------------------------*/
- /* mkdir */
- #include <sys/stat.h>
-
-/* Packages ------------------------------------------------------------------*/
- /* opencv */
- #include <opencv2/opencv.hpp>
-
-/* Project -------------------------------------------------------------------*/
- /* user_iface_save_name() */
- #include "user_iface.hpp"
-
-/* Module --------------------------------------------------------------------*/
- #include "save.hpp"
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-class cv::Mat image;
-char home_path [FILENAME_MAX];
-char user_prog_path [FILENAME_MAX];
-char saved_path [FILENAME_MAX];
-char labels_path [FILENAME_MAX];
-char labels_fail_path [FILENAME_MAX];
-char objects_path [FILENAME_MAX];
-char objects_fail_path [FILENAME_MAX];
-char coins_path [FILENAME_MAX];
-char coins_fail_path [FILENAME_MAX];
-char resistors_path [FILENAME_MAX];
-char resistors_fail_path [FILENAME_MAX];
-char saved_name [FILENAME_MAX];
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void save_init (void)
-{
- snprintf(home_path, FILENAME_MAX, "%s/", getenv(ENV_HOME));
- snprintf(user_prog_path, FILENAME_MAX, "%s/%s/", home_path, USER_PROG_DIR);
- snprintf(saved_path, FILENAME_MAX, "%s/%s/", home_path, USER_SAVED_DIR);
- snprintf(labels_path, FILENAME_MAX, "%s/%s/", home_path, USER_LABELS_DIR);
- snprintf(labels_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_LABELS_FAIL_DIR);
- snprintf(objects_path, FILENAME_MAX, "%s/%s/", home_path, USER_OBJECTS_DIR);
- snprintf(objects_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_OBJECTS_FAIL_DIR);
- snprintf(coins_path, FILENAME_MAX, "%s/%s/", home_path, USER_COINS_DIR);
- snprintf(coins_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_COINS_FAIL_DIR);
- snprintf(resistors_path, FILENAME_MAX, "%s/%s/", home_path, USER_RESISTORS_DIR);
- snprintf(resistors_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_RESISTORS_FAIL_DIR);
- sprintf(saved_name, "");
-
- int err;
- err = mkdir(user_prog_path, 0700);
-
- if (!err) {
- } else {
-
- switch (errno) {
- case EACCES:
- printf("err = EACCES");
-// exit(EXIT_FAILURE);
- break;
-
- case EEXIST:
- /* OK */
- break;
-
- default:
- printf("WTF?!");
-// exit(EXIT_FAILURE);
- }
- }
-
- mkdir(saved_path, 0700);
- mkdir(labels_path, 0700);
- mkdir(labels_fail_path, 0700);
-}
-
-void save_clr (void)
-{
- snprintf(saved_path, FILENAME_MAX, "%s/%s/", home_path, USER_SAVED_DIR);
-}
-
-void load_image_file (const char *fpath, const char *fname)
-{
- char file_path [FILENAME_MAX];
- char file_name [FILENAME_MAX];
-
- /* Free old image */
- image.release();
-
- /* Set file_path */
- if (!fpath) {
- /* Default path */
- save_clr();
- snprintf(file_path, FILENAME_MAX, "%s", saved_path);
- } else {
- snprintf(file_path, FILENAME_MAX, "%s", fpath);
- }
-
- /* Set file_name */
- if (!fname) {
- /* Request file name */
- user_iface_fname(file_path, saved_name);
- } else {
- snprintf(saved_name, FILENAME_MAX, "%s", fname);
- }
-
- /* File name */
- snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name);
-
- /* Load image */
- image = cv::imread(file_name, CV_LOAD_IMAGE_COLOR);
-
- /* Manage load error */
- if (image.empty()) {
- printf("Could not load file: %s\n", file_name);
-// exit(0);
- }
-}
-
-void save_cleanup (void)
-{
- /* Free old image */
- image.release();
-}
-
-void save_image_file (const char *fpath, const char *save_as)
-{
- char file_path [FILENAME_MAX];
- char file_name [FILENAME_MAX];
- FILE *fp;
-
- /* Set file_path */
- if (!fpath) {
- /* Default path */
- save_clr();
- snprintf(file_path, FILENAME_MAX, "%s", saved_path);
- } else {
- snprintf(file_path, FILENAME_MAX, "%s", fpath);
- }
-
- /* Set file_name */
- if (!save_as) {
- /* Default name */
- snprintf(saved_name, FILENAME_MAX, "%s", SAVED_NAME_DEFAULT);
- /* Request file name */
- user_iface_fname(saved_path, saved_name);
- } else {
- snprintf(saved_name, FILENAME_MAX, "%s", save_as);
- }
-
- /* Prepend the path */
- snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name);
-
- fp = fopen(file_name, "r");
- if (fp) {
- /* Name in use; ask once more */
- fclose(fp);
- user_iface_fname(saved_path, saved_name);
- snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name);
- }
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "%s", saved_name);
- user_iface_log.lvl[user_iface_log.len] = 2;
- (user_iface_log.len)++;
-
-
- /* Write to a new file */
- cv::imwrite(file_name, image);
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* errno */ + #include <cerrno> + /* fscanf() & fprintf() & FILE & FILENAME_MAX & snprintf() */ + #include <cstdio> + /* getenv() */ + #include <cstdlib> + +/* Linux ---------------------------------------------------------------------*/ + /* mkdir */ + #include <sys/stat.h> + +/* Packages ------------------------------------------------------------------*/ + /* opencv */ + #include <opencv2/opencv.hpp> + +/* Project -------------------------------------------------------------------*/ + /* user_iface_save_name() */ + #include "user_iface.hpp" + +/* Module --------------------------------------------------------------------*/ + #include "save.hpp" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +class cv::Mat image; +char home_path [FILENAME_MAX]; +char user_prog_path [FILENAME_MAX]; +char saved_path [FILENAME_MAX]; +char labels_path [FILENAME_MAX]; +char labels_fail_path [FILENAME_MAX]; +char objects_path [FILENAME_MAX]; +char objects_fail_path [FILENAME_MAX]; +char coins_path [FILENAME_MAX]; +char coins_fail_path [FILENAME_MAX]; +char resistors_path [FILENAME_MAX]; +char resistors_fail_path [FILENAME_MAX]; +char saved_name [FILENAME_MAX]; + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void save_init (void) +{ + snprintf(home_path, FILENAME_MAX, "%s/", getenv(ENV_HOME)); + snprintf(user_prog_path, FILENAME_MAX, "%s/%s/", home_path, USER_PROG_DIR); + snprintf(saved_path, FILENAME_MAX, "%s/%s/", home_path, USER_SAVED_DIR); + snprintf(labels_path, FILENAME_MAX, "%s/%s/", home_path, USER_LABELS_DIR); + snprintf(labels_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_LABELS_FAIL_DIR); + snprintf(objects_path, FILENAME_MAX, "%s/%s/", home_path, USER_OBJECTS_DIR); + snprintf(objects_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_OBJECTS_FAIL_DIR); + snprintf(coins_path, FILENAME_MAX, "%s/%s/", home_path, USER_COINS_DIR); + snprintf(coins_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_COINS_FAIL_DIR); + snprintf(resistors_path, FILENAME_MAX, "%s/%s/", home_path, USER_RESISTORS_DIR); + snprintf(resistors_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_RESISTORS_FAIL_DIR); + sprintf(saved_name, ""); + + int err; + err = mkdir(user_prog_path, 0700); + + if (!err) { + } else { + + switch (errno) { + case EACCES: + printf("err = EACCES"); +// exit(EXIT_FAILURE); + break; + + case EEXIST: + /* OK */ + break; + + default: + printf("WTF?!"); +// exit(EXIT_FAILURE); + } + } + + mkdir(saved_path, 0700); + mkdir(labels_path, 0700); + mkdir(labels_fail_path, 0700); +} + +void save_clr (void) +{ + snprintf(saved_path, FILENAME_MAX, "%s/%s/", home_path, USER_SAVED_DIR); +} + +void load_image_file (const char *fpath, const char *fname) +{ + char file_path [FILENAME_MAX]; + char file_name [FILENAME_MAX]; + + /* Free old image */ + image.release(); + + /* Set file_path */ + if (!fpath) { + /* Default path */ + save_clr(); + snprintf(file_path, FILENAME_MAX, "%s", saved_path); + } else { + snprintf(file_path, FILENAME_MAX, "%s", fpath); + } + + /* Set file_name */ + if (!fname) { + /* Request file name */ + user_iface_fname(file_path, saved_name); + } else { + snprintf(saved_name, FILENAME_MAX, "%s", fname); + } + + /* File name */ + snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name); + + /* Load image */ + image = cv::imread(file_name, CV_LOAD_IMAGE_COLOR); + + /* Manage load error */ + if (image.empty()) { + printf("Could not load file: %s\n", file_name); +// exit(0); + } +} + +void save_cleanup (void) +{ + /* Free old image */ + image.release(); +} + +void save_image_file (const char *fpath, const char *save_as) +{ + char file_path [FILENAME_MAX]; + char file_name [FILENAME_MAX]; + FILE *fp; + + /* Set file_path */ + if (!fpath) { + /* Default path */ + save_clr(); + snprintf(file_path, FILENAME_MAX, "%s", saved_path); + } else { + snprintf(file_path, FILENAME_MAX, "%s", fpath); + } + + /* Set file_name */ + if (!save_as) { + /* Default name */ + snprintf(saved_name, FILENAME_MAX, "%s", SAVED_NAME_DEFAULT); + /* Request file name */ + user_iface_fname(saved_path, saved_name); + } else { + snprintf(saved_name, FILENAME_MAX, "%s", save_as); + } + + /* Prepend the path */ + snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name); + + fp = fopen(file_name, "r"); + if (fp) { + /* Name in use; ask once more */ + fclose(fp); + user_iface_fname(saved_path, saved_name); + snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name); + } + + /* Write into log */ + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "%s", saved_name); + user_iface_log.lvl[user_iface_log.len] = 2; + (user_iface_log.len)++; + + + /* Write to a new file */ + cv::imwrite(file_name, image); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/user/inc/user_clui.h b/modules/user/inc/user_clui.h index dffc625..916fe00 100644 --- a/modules/user/inc/user_clui.h +++ b/modules/user/inc/user_clui.h @@ -1,30 +1,30 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_USER_CLUI_H
- # define VA_USER_CLUI_H
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
-void user_clui_init (void);
-int user_clui (const char *title, const char *subtitle);
-void user_clui_fname (const char *filepath, char *filename);
-void user_clui_show_log (const char *title, const char *subtitle);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* user_clui.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_USER_CLUI_H + # define VA_USER_CLUI_H + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void user_clui_init (void); +int user_clui (const char *title, const char *subtitle); +void user_clui_fname (const char *filepath, char *filename); +void user_clui_show_log (const char *title, const char *subtitle); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* user_clui.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/user/inc/user_iface.h b/modules/user/inc/user_iface.h index f4511be..f65d708 100644 --- a/modules/user/inc/user_iface.h +++ b/modules/user/inc/user_iface.h @@ -1,163 +1,163 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_USER_IFACE_H
- # define VA_USER_IFACE_H
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
- # define LOG_LEN (1048576)
- # define LOG_LINE_LEN (80)
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* intX_t */
- #include <stdint.h>
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Player_Iface_Mode {
- USER_IFACE_FOO,
- USER_IFACE_CLUI,
- USER_IFACE_TUI
- };
-
- enum Player_Iface_Action {
- USER_IFACE_ACT_FOO = 0x000000u,
-
- USER_IFACE_ACT_ALX = 0x000010u,
- USER_IFACE_ACT_LOCAL_MAX,
- USER_IFACE_ACT_SKELETON,
- USER_IFACE_ACT_LINES_HORIZONTAL,
- USER_IFACE_ACT_LINES_VERTICAL,
- USER_IFACE_ACT_MEAN_HORIZONTAL,
- USER_IFACE_ACT_MEAN_VERTICAL,
- USER_IFACE_ACT_MEDIAN_HORIZONTAL,
- USER_IFACE_ACT_MEDIAN_VERTICAL,
-
- USER_IFACE_ACT_CV = 0x000100u,
- USER_IFACE_ACT_PIXEL_GET,
- USER_IFACE_ACT_PIXEL_SET,
- USER_IFACE_ACT_SET_ROI,
- USER_IFACE_ACT_SET_ROI_2RECT,
- USER_IFACE_ACT_AND_2REF,
- USER_IFACE_ACT_NOT,
- USER_IFACE_ACT_OR_2REF,
- USER_IFACE_ACT_COMPONENT,
- USER_IFACE_ACT_DILATE,
- USER_IFACE_ACT_ERODE,
- USER_IFACE_ACT_DILATE_ERODE,
- USER_IFACE_ACT_ERODE_DILATE,
- USER_IFACE_ACT_SMOOTH,
- USER_IFACE_ACT_SOBEL,
- USER_IFACE_ACT_BORDER,
- USER_IFACE_ACT_MIRROR,
- USER_IFACE_ACT_ROTATE_ORTO,
- USER_IFACE_ACT_ROTATE,
- USER_IFACE_ACT_ROTATE_2RECT,
- USER_IFACE_ACT_ADAPTIVE_THRESHOLD,
- USER_IFACE_ACT_CVT_COLOR,
- USER_IFACE_ACT_DISTANCE_TRANSFORM,
- USER_IFACE_ACT_THRESHOLD,
- USER_IFACE_ACT_HISTOGRAM,
- USER_IFACE_ACT_HISTOGRAM_C3,
- USER_IFACE_ACT_CONTOURS,
- USER_IFACE_ACT_CONTOURS_SIZE,
- USER_IFACE_ACT_BOUNDING_RECT,
- USER_IFACE_ACT_FIT_ELLIPSE,
- USER_IFACE_ACT_MIN_AREA_RECT,
- USER_IFACE_ACT_HOUGH_CIRCLES,
-
- USER_IFACE_ACT_ORB = 0x000200u,
- USER_IFACE_ACT_ALIGN,
-
- USER_IFACE_ACT_CALIB3D = 0x000400u,
- USER_IFACE_ACT_CALIBRATE,
- USER_IFACE_ACT_UNDISTORT,
-
- USER_IFACE_ACT_ZB = 0x000800u,
- USER_IFACE_ACT_DECODE,
-
- USER_IFACE_ACT_OCR = 0x001000u,
- USER_IFACE_ACT_READ,
-
- USER_IFACE_ACT_IMGI = 0x002000u,
- USER_IFACE_ACT_APPLY,
- USER_IFACE_ACT_DISCARD,
- USER_IFACE_ACT_SAVE_MEM,
- USER_IFACE_ACT_LOAD_MEM,
- USER_IFACE_ACT_SAVE_REF,
-
- USER_IFACE_ACT_SAVE = 0x004000u,
- USER_IFACE_ACT_SAVE_FILE,
- USER_IFACE_ACT_SAVE_UPDT,
-
- USER_IFACE_ACT_PROC = 0x008000u,
- USER_IFACE_ACT_PROC_LABEL_SERIES,
- USER_IFACE_ACT_PROC_LABEL_CALIB,
- USER_IFACE_ACT_PROC_OBJECTS_SERIES,
- USER_IFACE_ACT_PROC_OBJECTS_CALIB,
- USER_IFACE_ACT_PROC_COINS_SERIES,
- USER_IFACE_ACT_PROC_COINS_CALIB,
- USER_IFACE_ACT_PROC_RESISTOR_SERIES,
- USER_IFACE_ACT_PROC_RESISTOR_CALIB,
-
- USER_IFACE_ACT_USRI = 0x010000u,
- USER_IFACE_ACT_SHOW_OCR,
- USER_IFACE_ACT_QUIT
- };
-
-
-/******************************************************************************
- ******* structs **************************************************************
- ******************************************************************************/
- struct User_Iface_Log {
- int len;
- char line [LOG_LEN] [LOG_LINE_LEN];
- int lvl [LOG_LEN];
- int visible;
- };
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
- extern int user_iface_mode;
- extern struct User_Iface_Log user_iface_log;
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- void user_iface_init (void);
- void user_iface_cleanup (void);
- void user_iface (void);
- void user_iface_show_log (const char *title, const char *subtitle);
- void user_iface_fname (const char *filepath, char *filename);
- double user_iface_getdbl (double m, double def, double M,
- const char *title, const char *help);
- int64_t user_iface_getint (double m, int64_t def, double M,
- const char *title, const char *help);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* user_iface.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_USER_IFACE_H + # define VA_USER_IFACE_H + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define LOG_LEN (1048576) + # define LOG_LINE_LEN (80) + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* intX_t */ + #include <stdint.h> + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Player_Iface_Mode { + USER_IFACE_FOO, + USER_IFACE_CLUI, + USER_IFACE_TUI + }; + + enum Player_Iface_Action { + USER_IFACE_ACT_FOO = 0x000000u, + + USER_IFACE_ACT_ALX = 0x000010u, + USER_IFACE_ACT_LOCAL_MAX, + USER_IFACE_ACT_SKELETON, + USER_IFACE_ACT_LINES_HORIZONTAL, + USER_IFACE_ACT_LINES_VERTICAL, + USER_IFACE_ACT_MEAN_HORIZONTAL, + USER_IFACE_ACT_MEAN_VERTICAL, + USER_IFACE_ACT_MEDIAN_HORIZONTAL, + USER_IFACE_ACT_MEDIAN_VERTICAL, + + USER_IFACE_ACT_CV = 0x000100u, + USER_IFACE_ACT_PIXEL_GET, + USER_IFACE_ACT_PIXEL_SET, + USER_IFACE_ACT_SET_ROI, + USER_IFACE_ACT_SET_ROI_2RECT, + USER_IFACE_ACT_AND_2REF, + USER_IFACE_ACT_NOT, + USER_IFACE_ACT_OR_2REF, + USER_IFACE_ACT_COMPONENT, + USER_IFACE_ACT_DILATE, + USER_IFACE_ACT_ERODE, + USER_IFACE_ACT_DILATE_ERODE, + USER_IFACE_ACT_ERODE_DILATE, + USER_IFACE_ACT_SMOOTH, + USER_IFACE_ACT_SOBEL, + USER_IFACE_ACT_BORDER, + USER_IFACE_ACT_MIRROR, + USER_IFACE_ACT_ROTATE_ORTO, + USER_IFACE_ACT_ROTATE, + USER_IFACE_ACT_ROTATE_2RECT, + USER_IFACE_ACT_ADAPTIVE_THRESHOLD, + USER_IFACE_ACT_CVT_COLOR, + USER_IFACE_ACT_DISTANCE_TRANSFORM, + USER_IFACE_ACT_THRESHOLD, + USER_IFACE_ACT_HISTOGRAM, + USER_IFACE_ACT_HISTOGRAM_C3, + USER_IFACE_ACT_CONTOURS, + USER_IFACE_ACT_CONTOURS_SIZE, + USER_IFACE_ACT_BOUNDING_RECT, + USER_IFACE_ACT_FIT_ELLIPSE, + USER_IFACE_ACT_MIN_AREA_RECT, + USER_IFACE_ACT_HOUGH_CIRCLES, + + USER_IFACE_ACT_ORB = 0x000200u, + USER_IFACE_ACT_ALIGN, + + USER_IFACE_ACT_CALIB3D = 0x000400u, + USER_IFACE_ACT_CALIBRATE, + USER_IFACE_ACT_UNDISTORT, + + USER_IFACE_ACT_ZB = 0x000800u, + USER_IFACE_ACT_DECODE, + + USER_IFACE_ACT_OCR = 0x001000u, + USER_IFACE_ACT_READ, + + USER_IFACE_ACT_IMGI = 0x002000u, + USER_IFACE_ACT_APPLY, + USER_IFACE_ACT_DISCARD, + USER_IFACE_ACT_SAVE_MEM, + USER_IFACE_ACT_LOAD_MEM, + USER_IFACE_ACT_SAVE_REF, + + USER_IFACE_ACT_SAVE = 0x004000u, + USER_IFACE_ACT_SAVE_FILE, + USER_IFACE_ACT_SAVE_UPDT, + + USER_IFACE_ACT_PROC = 0x008000u, + USER_IFACE_ACT_PROC_LABEL_SERIES, + USER_IFACE_ACT_PROC_LABEL_CALIB, + USER_IFACE_ACT_PROC_OBJECTS_SERIES, + USER_IFACE_ACT_PROC_OBJECTS_CALIB, + USER_IFACE_ACT_PROC_COINS_SERIES, + USER_IFACE_ACT_PROC_COINS_CALIB, + USER_IFACE_ACT_PROC_RESISTOR_SERIES, + USER_IFACE_ACT_PROC_RESISTOR_CALIB, + + USER_IFACE_ACT_USRI = 0x010000u, + USER_IFACE_ACT_SHOW_OCR, + USER_IFACE_ACT_QUIT + }; + + +/****************************************************************************** + ******* structs ************************************************************** + ******************************************************************************/ + struct User_Iface_Log { + int len; + char line [LOG_LEN] [LOG_LINE_LEN]; + int lvl [LOG_LEN]; + int visible; + }; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern int user_iface_mode; + extern struct User_Iface_Log user_iface_log; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void user_iface_init (void); + void user_iface_cleanup (void); + void user_iface (void); + void user_iface_show_log (const char *title, const char *subtitle); + void user_iface_fname (const char *filepath, char *filename); + double user_iface_getdbl (double m, double def, double M, + const char *title, const char *help); + int64_t user_iface_getint (double m, int64_t def, double M, + const char *title, const char *help); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* user_iface.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/user/inc/user_iface.hpp b/modules/user/inc/user_iface.hpp index c127d93..134f5dd 100644 --- a/modules/user/inc/user_iface.hpp +++ b/modules/user/inc/user_iface.hpp @@ -1,175 +1,175 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_USER_IFACE_HPP
- # define VA_USER_IFACE_HPP
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
- # define LOG_LEN (1048576)
- # define LOG_LINE_LEN (80)
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* intX_t */
- #include <cstdint>
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Player_Iface_Mode {
- USER_IFACE_FOO,
- USER_IFACE_CLUI,
- USER_IFACE_TUI
- };
-
- enum Player_Iface_Action {
- USER_IFACE_ACT_FOO = 0x000000u,
-
- USER_IFACE_ACT_ALX = 0x000010u,
- USER_IFACE_ACT_LOCAL_MAX,
- USER_IFACE_ACT_SKELETON,
- USER_IFACE_ACT_LINES_HORIZONTAL,
- USER_IFACE_ACT_LINES_VERTICAL,
- USER_IFACE_ACT_MEAN_HORIZONTAL,
- USER_IFACE_ACT_MEAN_VERTICAL,
- USER_IFACE_ACT_MEDIAN_HORIZONTAL,
- USER_IFACE_ACT_MEDIAN_VERTICAL,
-
- USER_IFACE_ACT_CV = 0x000100u,
- USER_IFACE_ACT_PIXEL_GET,
- USER_IFACE_ACT_PIXEL_SET,
- USER_IFACE_ACT_SET_ROI,
- USER_IFACE_ACT_SET_ROI_2RECT,
- USER_IFACE_ACT_AND_2REF,
- USER_IFACE_ACT_NOT,
- USER_IFACE_ACT_OR_2REF,
- USER_IFACE_ACT_COMPONENT,
- USER_IFACE_ACT_DILATE,
- USER_IFACE_ACT_ERODE,
- USER_IFACE_ACT_DILATE_ERODE,
- USER_IFACE_ACT_ERODE_DILATE,
- USER_IFACE_ACT_SMOOTH,
- USER_IFACE_ACT_SOBEL,
- USER_IFACE_ACT_BORDER,
- USER_IFACE_ACT_MIRROR,
- USER_IFACE_ACT_ROTATE_ORTO,
- USER_IFACE_ACT_ROTATE,
- USER_IFACE_ACT_ROTATE_2RECT,
- USER_IFACE_ACT_ADAPTIVE_THRESHOLD,
- USER_IFACE_ACT_CVT_COLOR,
- USER_IFACE_ACT_DISTANCE_TRANSFORM,
- USER_IFACE_ACT_THRESHOLD,
- USER_IFACE_ACT_HISTOGRAM,
- USER_IFACE_ACT_HISTOGRAM_C3,
- USER_IFACE_ACT_CONTOURS,
- USER_IFACE_ACT_CONTOURS_SIZE,
- USER_IFACE_ACT_BOUNDING_RECT,
- USER_IFACE_ACT_FIT_ELLIPSE,
- USER_IFACE_ACT_MIN_AREA_RECT,
- USER_IFACE_ACT_HOUGH_CIRCLES,
-
- USER_IFACE_ACT_ORB = 0x000200u,
- USER_IFACE_ACT_ALIGN,
-
- USER_IFACE_ACT_CALIB3D = 0x000400u,
- USER_IFACE_ACT_CALIBRATE,
- USER_IFACE_ACT_UNDISTORT,
-
- USER_IFACE_ACT_ZB = 0x000800u,
- USER_IFACE_ACT_DECODE,
-
- USER_IFACE_ACT_OCR = 0x001000u,
- USER_IFACE_ACT_READ,
-
- USER_IFACE_ACT_IMGI = 0x002000u,
- USER_IFACE_ACT_APPLY,
- USER_IFACE_ACT_DISCARD,
- USER_IFACE_ACT_SAVE_MEM,
- USER_IFACE_ACT_LOAD_MEM,
- USER_IFACE_ACT_SAVE_REF,
-
- USER_IFACE_ACT_SAVE = 0x004000u,
- USER_IFACE_ACT_SAVE_FILE,
- USER_IFACE_ACT_SAVE_UPDT,
-
- USER_IFACE_ACT_PROC = 0x008000u,
- USER_IFACE_ACT_PROC_LABEL_SERIES,
- USER_IFACE_ACT_PROC_LABEL_CALIB,
- USER_IFACE_ACT_PROC_OBJECTS_SERIES,
- USER_IFACE_ACT_PROC_OBJECTS_CALIB,
- USER_IFACE_ACT_PROC_COINS_SERIES,
- USER_IFACE_ACT_PROC_COINS_CALIB,
- USER_IFACE_ACT_PROC_RESISTOR_SERIES,
- USER_IFACE_ACT_PROC_RESISTOR_CALIB,
-
- USER_IFACE_ACT_USRI = 0x010000u,
- USER_IFACE_ACT_SHOW_OCR,
- USER_IFACE_ACT_QUIT
- };
-
-
-/******************************************************************************
- ******* structs **************************************************************
- ******************************************************************************/
- struct User_Iface_Log {
- int len;
- char line [LOG_LEN] [LOG_LINE_LEN];
- int lvl [LOG_LEN];
- int visible;
- };
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-extern "C" {
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
- extern int user_iface_mode;
- extern struct User_Iface_Log user_iface_log;
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- void user_iface_init (void);
- void user_iface_cleanup (void);
- void user_iface (void);
- void user_iface_show_log (const char *title, const char *subtitle);
- void user_iface_fname (const char *filepath, char *filename);
- double user_iface_getdbl (double m, double def, double M,
- const char *title, const char *help);
- int64_t user_iface_getint (double m, int64_t def, double M,
- const char *title, const char *help);
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-} /* extern "C" */
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* user_iface.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_USER_IFACE_HPP + # define VA_USER_IFACE_HPP + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define LOG_LEN (1048576) + # define LOG_LINE_LEN (80) + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* intX_t */ + #include <cstdint> + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Player_Iface_Mode { + USER_IFACE_FOO, + USER_IFACE_CLUI, + USER_IFACE_TUI + }; + + enum Player_Iface_Action { + USER_IFACE_ACT_FOO = 0x000000u, + + USER_IFACE_ACT_ALX = 0x000010u, + USER_IFACE_ACT_LOCAL_MAX, + USER_IFACE_ACT_SKELETON, + USER_IFACE_ACT_LINES_HORIZONTAL, + USER_IFACE_ACT_LINES_VERTICAL, + USER_IFACE_ACT_MEAN_HORIZONTAL, + USER_IFACE_ACT_MEAN_VERTICAL, + USER_IFACE_ACT_MEDIAN_HORIZONTAL, + USER_IFACE_ACT_MEDIAN_VERTICAL, + + USER_IFACE_ACT_CV = 0x000100u, + USER_IFACE_ACT_PIXEL_GET, + USER_IFACE_ACT_PIXEL_SET, + USER_IFACE_ACT_SET_ROI, + USER_IFACE_ACT_SET_ROI_2RECT, + USER_IFACE_ACT_AND_2REF, + USER_IFACE_ACT_NOT, + USER_IFACE_ACT_OR_2REF, + USER_IFACE_ACT_COMPONENT, + USER_IFACE_ACT_DILATE, + USER_IFACE_ACT_ERODE, + USER_IFACE_ACT_DILATE_ERODE, + USER_IFACE_ACT_ERODE_DILATE, + USER_IFACE_ACT_SMOOTH, + USER_IFACE_ACT_SOBEL, + USER_IFACE_ACT_BORDER, + USER_IFACE_ACT_MIRROR, + USER_IFACE_ACT_ROTATE_ORTO, + USER_IFACE_ACT_ROTATE, + USER_IFACE_ACT_ROTATE_2RECT, + USER_IFACE_ACT_ADAPTIVE_THRESHOLD, + USER_IFACE_ACT_CVT_COLOR, + USER_IFACE_ACT_DISTANCE_TRANSFORM, + USER_IFACE_ACT_THRESHOLD, + USER_IFACE_ACT_HISTOGRAM, + USER_IFACE_ACT_HISTOGRAM_C3, + USER_IFACE_ACT_CONTOURS, + USER_IFACE_ACT_CONTOURS_SIZE, + USER_IFACE_ACT_BOUNDING_RECT, + USER_IFACE_ACT_FIT_ELLIPSE, + USER_IFACE_ACT_MIN_AREA_RECT, + USER_IFACE_ACT_HOUGH_CIRCLES, + + USER_IFACE_ACT_ORB = 0x000200u, + USER_IFACE_ACT_ALIGN, + + USER_IFACE_ACT_CALIB3D = 0x000400u, + USER_IFACE_ACT_CALIBRATE, + USER_IFACE_ACT_UNDISTORT, + + USER_IFACE_ACT_ZB = 0x000800u, + USER_IFACE_ACT_DECODE, + + USER_IFACE_ACT_OCR = 0x001000u, + USER_IFACE_ACT_READ, + + USER_IFACE_ACT_IMGI = 0x002000u, + USER_IFACE_ACT_APPLY, + USER_IFACE_ACT_DISCARD, + USER_IFACE_ACT_SAVE_MEM, + USER_IFACE_ACT_LOAD_MEM, + USER_IFACE_ACT_SAVE_REF, + + USER_IFACE_ACT_SAVE = 0x004000u, + USER_IFACE_ACT_SAVE_FILE, + USER_IFACE_ACT_SAVE_UPDT, + + USER_IFACE_ACT_PROC = 0x008000u, + USER_IFACE_ACT_PROC_LABEL_SERIES, + USER_IFACE_ACT_PROC_LABEL_CALIB, + USER_IFACE_ACT_PROC_OBJECTS_SERIES, + USER_IFACE_ACT_PROC_OBJECTS_CALIB, + USER_IFACE_ACT_PROC_COINS_SERIES, + USER_IFACE_ACT_PROC_COINS_CALIB, + USER_IFACE_ACT_PROC_RESISTOR_SERIES, + USER_IFACE_ACT_PROC_RESISTOR_CALIB, + + USER_IFACE_ACT_USRI = 0x010000u, + USER_IFACE_ACT_SHOW_OCR, + USER_IFACE_ACT_QUIT + }; + + +/****************************************************************************** + ******* structs ************************************************************** + ******************************************************************************/ + struct User_Iface_Log { + int len; + char line [LOG_LEN] [LOG_LINE_LEN]; + int lvl [LOG_LEN]; + int visible; + }; + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +extern "C" { + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + extern int user_iface_mode; + extern struct User_Iface_Log user_iface_log; + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ + void user_iface_init (void); + void user_iface_cleanup (void); + void user_iface (void); + void user_iface_show_log (const char *title, const char *subtitle); + void user_iface_fname (const char *filepath, char *filename); + double user_iface_getdbl (double m, double def, double M, + const char *title, const char *help); + int64_t user_iface_getint (double m, int64_t def, double M, + const char *title, const char *help); + + +/****************************************************************************** + ******* C wrapper ************************************************************ + ******************************************************************************/ +} /* extern "C" */ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* user_iface.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/user/inc/user_tui.h b/modules/user/inc/user_tui.h index d8f9a3c..c9c027c 100644 --- a/modules/user/inc/user_tui.h +++ b/modules/user/inc/user_tui.h @@ -1,36 +1,36 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_USER_TUI_H
- # define VA_USER_TUI_H
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
-void user_tui_init (void);
-void user_tui_cleanup (void);
-int user_tui (const char *title, const char *subtitle);
-void user_tui_show_log (const char *title, const char *subtitle);
-void user_tui_fname (const char *filepath, char *filename);
-double user_tui_getdbl (double m, double def, double M,
- const char *title, const char *help);
-int64_t user_tui_getint (double m, int64_t def, double M,
- const char *title, const char *help);
-void user_tui_show_ocr (void);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* user_tui.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_USER_TUI_H + # define VA_USER_TUI_H + + +/****************************************************************************** + ******* functions ************************************************************ + ******************************************************************************/ +void user_tui_init (void); +void user_tui_cleanup (void); +int user_tui (const char *title, const char *subtitle); +void user_tui_show_log (const char *title, const char *subtitle); +void user_tui_fname (const char *filepath, char *filename); +double user_tui_getdbl (double m, double def, double M, + const char *title, const char *help); +int64_t user_tui_getint (double m, int64_t def, double M, + const char *title, const char *help); +void user_tui_show_ocr (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# endif /* user_tui.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/user/src/user_clui.c b/modules/user/src/user_clui.c index 9a4405a..0799df3 100644 --- a/modules/user/src/user_clui.c +++ b/modules/user/src/user_clui.c @@ -1,622 +1,622 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* printf() & fgets() & sscanf() */
- #include <stdio.h>
-
-/* Project -------------------------------------------------------------------*/
- /*img_ocr_text */
- #include "img_iface.h"
-
-/* libalx --------------------------------------------------------------------*/
- /* alx_sscan_fname() */
- #include "alx_input.h"
-
-/* Module --------------------------------------------------------------------*/
- /* user_iface_log */
- #include "user_iface.h"
-
- #include "user_clui.h"
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
- # define BUFF_SIZE (1024)
-
-
-/******************************************************************************
- ******* static variables *****************************************************
- ******************************************************************************/
-static int log_pos;
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
- /* Log */
-static void log_loop (void);
- /* Input */
-static int usr_input (void);
- /* Help */
-static void show_help (void);
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void user_clui_init (void)
-{
- log_pos = 0;
-}
-
-int user_clui (const char *title, const char *subtitle)
-{
- int action;
-
- /* User action */
- show_help();
- user_clui_show_log(title, subtitle);
- action = usr_input();
-
- return action;
-}
-
-void user_clui_fname (const char *filepath, char *filename)
-{
- puts("File name:");
- puts("Valid extensions: .bmp .dib .jpeg .png .pbm .pgm .ppm .tiff");
- fgets(filename, FILENAME_MAX, stdin);
- alx_sscan_fname(filepath, filename, false, filename);
-}
-
-void user_clui_show_log (const char *title, const char *subtitle)
-{
- puts("________________________________________________________________________________");
-
- /* Board */
- log_loop();
-
- /* Subtitle & title */
- printf("%s - %s\n", subtitle, title);
- puts("--------------------------------------------------------------------------------");
-
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-/* Log -----------------------------------------------------------------------*/
-static void log_loop (void)
-{
- int lvl;
-
- putchar('\n');
- for (; log_pos < user_iface_log.len; log_pos++) {
- if (user_iface_log.lvl[log_pos] <= user_iface_log.visible) {
- for (lvl = 0; lvl < user_iface_log.lvl[log_pos]; lvl++) {
- printf("\t");
- }
- printf("%s\n", user_iface_log.line[log_pos]);
- }
- }
- putchar('\n');
-}
-
-/* Input ---------------------------------------------------------------------*/
-static int usr_input (void)
-{
- int action;
-
- char buff [BUFF_SIZE];
- char ch [10];
-
- int i;
- for (i = 0; i < 10; i++) {
- ch[i] = '\0';
- }
- buff[0] = '\0';
-
- /* Wait for input */
- fgets(buff, BUFF_SIZE, stdin);
-
- /* Interpret input */
- sscanf(buff, " %c%c%c%c%c", &ch[0], &ch[1], &ch[2], &ch[3], &ch[4]);
- switch (ch[0]) {
- case '+':
- action = USER_IFACE_ACT_APPLY;
- break;
-
- case '-':
- action = USER_IFACE_ACT_DISCARD;
- break;
-
- case 'e':
- /* Exercises from class */
- switch (ch[1]) {
- case '1':
- /* Label */
- switch (ch[2]) {
- case '1':
- action = USER_IFACE_ACT_PROC_LABEL_SERIES;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '2':
- /* Objects */
- switch (ch[2]) {
- case '0':
- action = USER_IFACE_ACT_PROC_OBJECTS_CALIB;
- break;
- case '1':
- action = USER_IFACE_ACT_PROC_OBJECTS_SERIES;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '3':
- /* Coins */
- switch (ch[2]) {
- case '1':
- action = USER_IFACE_ACT_PROC_COINS_SERIES;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '4':
- /* Resistor */
- switch (ch[2]) {
- case '1':
- action = USER_IFACE_ACT_PROC_RESISTOR_SERIES;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
-
- case 'f':
- /* Use simple funtions */
- switch (ch[1]) {
- case '0':
- /* img_alx */
- switch (ch[2]) {
- case '0':
- /* Distance transform postprocessing */
- switch (ch[3]) {
- case '0':
- action = USER_IFACE_ACT_LOCAL_MAX;
- break;
- case '1':
- action = USER_IFACE_ACT_SKELETON;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '1':
- /* Lines */
- switch (ch[3]) {
- case '0':
- action = USER_IFACE_ACT_LINES_HORIZONTAL;
- break;
- case '1':
- action = USER_IFACE_ACT_LINES_VERTICAL;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '2':
- /* Smooth */
- switch (ch[3]) {
- case '0':
- action = USER_IFACE_ACT_MEAN_HORIZONTAL;
- break;
- case '1':
- action = USER_IFACE_ACT_MEAN_VERTICAL;
- break;
- case '2':
- action = USER_IFACE_ACT_MEDIAN_HORIZONTAL;
- break;
- case '3':
- action = USER_IFACE_ACT_MEDIAN_VERTICAL;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '1':
- /* img_cv */
- switch (ch[2]) {
- case '0':
- /* Core: The core functionality */
- switch (ch[3]) {
- case '0':
- /* Pixel */
- switch (ch[4]) {
- case '0':
- action = USER_IFACE_ACT_PIXEL_GET;
- break;
- case '1':
- action = USER_IFACE_ACT_PIXEL_SET;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '1':
- /* ROI */
- switch (ch[4]) {
- case '0':
- action = USER_IFACE_ACT_SET_ROI;
- break;
- case '1':
- action = USER_IFACE_ACT_SET_ROI_2RECT;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '2':
- /* Operations on Arrays */
- switch (ch[4]) {
- case '0':
- action = USER_IFACE_ACT_AND_2REF;
- break;
- case '1':
- action = USER_IFACE_ACT_NOT;
- break;
- case '2':
- action = USER_IFACE_ACT_OR_2REF;
- break;
- case '3':
- action = USER_IFACE_ACT_COMPONENT;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '1':
- /* Imgproc: Image processing */
- switch (ch[3]) {
- case '0':
- /* Image filtering */
- switch (ch[4]) {
- case '0':
- action = USER_IFACE_ACT_DILATE;
- break;
- case '1':
- action = USER_IFACE_ACT_ERODE;
- break;
- case '2':
- action = USER_IFACE_ACT_DILATE_ERODE;
- break;
- case '3':
- action = USER_IFACE_ACT_ERODE_DILATE;
- break;
- case '4':
- action = USER_IFACE_ACT_SMOOTH;
- break;
- case '5':
- action = USER_IFACE_ACT_SOBEL;
- break;
- case '6':
- action = USER_IFACE_ACT_BORDER;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '1':
- /* Geometric image transformations */
- switch (ch[4]) {
- case '0':
- action = USER_IFACE_ACT_MIRROR;
- break;
- case '1':
- action = USER_IFACE_ACT_ROTATE_ORTO;
- break;
- case '2':
- action = USER_IFACE_ACT_ROTATE;
- break;
- case '3':
- action = USER_IFACE_ACT_ROTATE_2RECT;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '2':
- /* Miscellaneous image transformations */
- switch (ch[4]) {
- case '0':
- action = USER_IFACE_ACT_ADAPTIVE_THRESHOLD;
- break;
- case '1':
- action = USER_IFACE_ACT_CVT_COLOR;
- break;
- case '2':
- action = USER_IFACE_ACT_DISTANCE_TRANSFORM;
- break;
- case '3':
- action = USER_IFACE_ACT_THRESHOLD;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '3':
- /* Histograms */
- switch (ch[4]) {
- case '0':
- action = USER_IFACE_ACT_HISTOGRAM;
- break;
- case '1':
- action = USER_IFACE_ACT_HISTOGRAM_C3;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '4':
- /* Structural analysis and shape descriptors */
- switch (ch[4]) {
- case '0':
- action = USER_IFACE_ACT_CONTOURS;
- break;
- case '1':
- action = USER_IFACE_ACT_CONTOURS_SIZE;
- break;
- case '2':
- action = USER_IFACE_ACT_BOUNDING_RECT;
- break;
- case '3':
- action = USER_IFACE_ACT_FIT_ELLIPSE;
- break;
- case '4':
- action = USER_IFACE_ACT_MIN_AREA_RECT;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '5':
- /* Feature detection */
- switch (ch[4]) {
- case '0':
- action = USER_IFACE_ACT_HOUGH_CIRCLES;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '2':
- /* img_orb */
- switch (ch[2]) {
- case '0':
- action = USER_IFACE_ACT_ALIGN;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '3':
- /* img_calib3d */
- switch (ch[2]) {
- case '0':
- action = USER_IFACE_ACT_CALIBRATE;
- break;
- case '1':
- action = USER_IFACE_ACT_UNDISTORT;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '4':
- /* img_zbar */
- switch (ch[2]) {
- case '0':
- action = USER_IFACE_ACT_DECODE;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '5':
- /* img_ocr */
- switch (ch[2]) {
- case '0':
- action = USER_IFACE_ACT_READ;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
-
- case 'l':
- action = USER_IFACE_ACT_LOAD_MEM;
- break;
-
- case 'm':
- action = USER_IFACE_ACT_SAVE_MEM;
- break;
-
- case 'q':
- action = USER_IFACE_ACT_QUIT;
- break;
-
- case 'r':
- action = USER_IFACE_ACT_SAVE_REF;
- break;
-
- case 's':
- action = USER_IFACE_ACT_SAVE_FILE;
- break;
-
- case 'u':
- /* User iface actions */
- switch (ch[1]) {
- case '1':
- action = USER_IFACE_ACT_SHOW_OCR;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
-
- case 'x':
- /* Special sequence "xyzzy" */
- if (ch[1] == 'y') {
- if (ch[2] == 'z') {
- if (ch[3] == 'z') {
- if (ch[4] == 'y') {
- action = USER_IFACE_ACT_FOO;
- }
- }
- }
- }
- break;
-
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
-
- return action;
-}
-
-/* * * * * * * * * *
- * * * Help * * * * * * *
- * * * * * * * * * */
-static void show_help (void)
-{
- // FIXME
- printf("Apply: %s\n", "Space");
- printf("Discard: %s\n", "Backspace");
- printf("Save to mem: %c\n", 'm');
- printf("Load from mem: %c\n", 'l');
- printf("Save to ref: %c\n", 'r');
- printf("Save to file: %c\n", 's');
- printf("Functions:\n");
- printf(" - Local maxima: %s\n", "f000");
- printf(" - Skeleton: %s\n", "f001");
- printf(" - Horizontal lines: %s\n", "f010");
- printf(" - Vertical lines: %s\n", "f011");
- printf(" - Horizontal mean: %s\n", "f020");
- printf(" - Vertical mean: %s\n", "f021");
- printf(" - Horizontal median: %s\n", "f022");
- printf(" - Vertical median: %s\n", "f023");
- printf(" - Pixel get: %s\n", "f1000");
- printf(" - Pixel set: %s\n", "f1001");
- printf(" - Set ROI: %s\n", "f1010");
- printf(" - Set ROI 2rect: %s\n", "f1011");
- printf(" - Bitwise AND 2ref: %s\n", "f1020");
- printf(" - Bitwise NOT: %s\n", "f1021");
- printf(" - Bitwise OR 2ref: %s\n", "f1022");
- printf(" - Component: %s\n", "f1023");
- printf(" - Dilate: %s\n", "f1100");
- printf(" - Erode: %s\n", "f1101");
- printf(" - D-E: %s\n", "f1102");
- printf(" - E-D: %s\n", "f1103");
- printf(" - Smooth: %s\n", "f1104");
- printf(" - Sobel: %s\n", "f1105");
- printf(" - Border: %s\n", "f1106");
- printf(" - Mirror: %s\n", "f1110");
- printf(" - Rotate ortogonally: %s\n", "f1111");
- printf(" - Rotate: %s\n", "f1112");
- printf(" - Rotate 2rect_rot: %s\n", "f1113");
- printf(" - Adaptive threshold: %s\n", "f1120");
- printf(" - Cvt color: %s\n", "f1121");
- printf(" - Distance transform: %s\n", "f1122");
- printf(" - Threshold: %s\n", "f1123");
- printf(" - Histogram: %s\n", "f1130");
- printf(" - Histogram (3 chan): %s\n", "f1131");
- printf(" - Contours: %s\n", "f1140");
- printf(" - Contours size: %s\n", "f1141");
- printf(" - Bounding rectangle: %s\n", "f1142");
- printf(" - Fit ellipse: %s\n", "f1143");
- printf(" - Min. area rectangle: %s\n", "f1144");
- printf(" - Hough circles: %s\n", "f1150");
- printf(" - Align 2ref (ORB): %s\n", "f20");
- printf(" - Calibrate (Calib3d): %s\n", "f30");
- printf(" - Undistort (Calib3d): %s\n", "f31");
- printf(" - Scan codes (ZBAR): %s\n", "f40");
- printf(" - Scan text (OCR): %s\n", "f50");
- printf("Exercises:\n");
- printf(" - Label: %s\n", "e11");
- printf(" - Objects (calib): %s\n", "e20");
- printf(" - Objects: %s\n", "e21");
- printf(" - Coins: %s\n", "e31");
- printf(" - Resistor: %s\n", "e41");
- printf("Other:\n");
- printf(" - Show OCR text: %s\n", "u1");
- printf("Quit: %c\n", 'q');
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* printf() & fgets() & sscanf() */ + #include <stdio.h> + +/* Project -------------------------------------------------------------------*/ + /*img_ocr_text */ + #include "img_iface.h" + +/* libalx --------------------------------------------------------------------*/ + /* alx_sscan_fname() */ + #include "alx_input.h" + +/* Module --------------------------------------------------------------------*/ + /* user_iface_log */ + #include "user_iface.h" + + #include "user_clui.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define BUFF_SIZE (1024) + + +/****************************************************************************** + ******* static variables ***************************************************** + ******************************************************************************/ +static int log_pos; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ + /* Log */ +static void log_loop (void); + /* Input */ +static int usr_input (void); + /* Help */ +static void show_help (void); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void user_clui_init (void) +{ + log_pos = 0; +} + +int user_clui (const char *title, const char *subtitle) +{ + int action; + + /* User action */ + show_help(); + user_clui_show_log(title, subtitle); + action = usr_input(); + + return action; +} + +void user_clui_fname (const char *filepath, char *filename) +{ + puts("File name:"); + puts("Valid extensions: .bmp .dib .jpeg .png .pbm .pgm .ppm .tiff"); + fgets(filename, FILENAME_MAX, stdin); + alx_sscan_fname(filepath, filename, false, filename); +} + +void user_clui_show_log (const char *title, const char *subtitle) +{ + puts("________________________________________________________________________________"); + + /* Board */ + log_loop(); + + /* Subtitle & title */ + printf("%s - %s\n", subtitle, title); + puts("--------------------------------------------------------------------------------"); + +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +/* Log -----------------------------------------------------------------------*/ +static void log_loop (void) +{ + int lvl; + + putchar('\n'); + for (; log_pos < user_iface_log.len; log_pos++) { + if (user_iface_log.lvl[log_pos] <= user_iface_log.visible) { + for (lvl = 0; lvl < user_iface_log.lvl[log_pos]; lvl++) { + printf("\t"); + } + printf("%s\n", user_iface_log.line[log_pos]); + } + } + putchar('\n'); +} + +/* Input ---------------------------------------------------------------------*/ +static int usr_input (void) +{ + int action; + + char buff [BUFF_SIZE]; + char ch [10]; + + int i; + for (i = 0; i < 10; i++) { + ch[i] = '\0'; + } + buff[0] = '\0'; + + /* Wait for input */ + fgets(buff, BUFF_SIZE, stdin); + + /* Interpret input */ + sscanf(buff, " %c%c%c%c%c", &ch[0], &ch[1], &ch[2], &ch[3], &ch[4]); + switch (ch[0]) { + case '+': + action = USER_IFACE_ACT_APPLY; + break; + + case '-': + action = USER_IFACE_ACT_DISCARD; + break; + + case 'e': + /* Exercises from class */ + switch (ch[1]) { + case '1': + /* Label */ + switch (ch[2]) { + case '1': + action = USER_IFACE_ACT_PROC_LABEL_SERIES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* Objects */ + switch (ch[2]) { + case '0': + action = USER_IFACE_ACT_PROC_OBJECTS_CALIB; + break; + case '1': + action = USER_IFACE_ACT_PROC_OBJECTS_SERIES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '3': + /* Coins */ + switch (ch[2]) { + case '1': + action = USER_IFACE_ACT_PROC_COINS_SERIES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '4': + /* Resistor */ + switch (ch[2]) { + case '1': + action = USER_IFACE_ACT_PROC_RESISTOR_SERIES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + + case 'f': + /* Use simple funtions */ + switch (ch[1]) { + case '0': + /* img_alx */ + switch (ch[2]) { + case '0': + /* Distance transform postprocessing */ + switch (ch[3]) { + case '0': + action = USER_IFACE_ACT_LOCAL_MAX; + break; + case '1': + action = USER_IFACE_ACT_SKELETON; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '1': + /* Lines */ + switch (ch[3]) { + case '0': + action = USER_IFACE_ACT_LINES_HORIZONTAL; + break; + case '1': + action = USER_IFACE_ACT_LINES_VERTICAL; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* Smooth */ + switch (ch[3]) { + case '0': + action = USER_IFACE_ACT_MEAN_HORIZONTAL; + break; + case '1': + action = USER_IFACE_ACT_MEAN_VERTICAL; + break; + case '2': + action = USER_IFACE_ACT_MEDIAN_HORIZONTAL; + break; + case '3': + action = USER_IFACE_ACT_MEDIAN_VERTICAL; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '1': + /* img_cv */ + switch (ch[2]) { + case '0': + /* Core: The core functionality */ + switch (ch[3]) { + case '0': + /* Pixel */ + switch (ch[4]) { + case '0': + action = USER_IFACE_ACT_PIXEL_GET; + break; + case '1': + action = USER_IFACE_ACT_PIXEL_SET; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '1': + /* ROI */ + switch (ch[4]) { + case '0': + action = USER_IFACE_ACT_SET_ROI; + break; + case '1': + action = USER_IFACE_ACT_SET_ROI_2RECT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* Operations on Arrays */ + switch (ch[4]) { + case '0': + action = USER_IFACE_ACT_AND_2REF; + break; + case '1': + action = USER_IFACE_ACT_NOT; + break; + case '2': + action = USER_IFACE_ACT_OR_2REF; + break; + case '3': + action = USER_IFACE_ACT_COMPONENT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '1': + /* Imgproc: Image processing */ + switch (ch[3]) { + case '0': + /* Image filtering */ + switch (ch[4]) { + case '0': + action = USER_IFACE_ACT_DILATE; + break; + case '1': + action = USER_IFACE_ACT_ERODE; + break; + case '2': + action = USER_IFACE_ACT_DILATE_ERODE; + break; + case '3': + action = USER_IFACE_ACT_ERODE_DILATE; + break; + case '4': + action = USER_IFACE_ACT_SMOOTH; + break; + case '5': + action = USER_IFACE_ACT_SOBEL; + break; + case '6': + action = USER_IFACE_ACT_BORDER; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '1': + /* Geometric image transformations */ + switch (ch[4]) { + case '0': + action = USER_IFACE_ACT_MIRROR; + break; + case '1': + action = USER_IFACE_ACT_ROTATE_ORTO; + break; + case '2': + action = USER_IFACE_ACT_ROTATE; + break; + case '3': + action = USER_IFACE_ACT_ROTATE_2RECT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* Miscellaneous image transformations */ + switch (ch[4]) { + case '0': + action = USER_IFACE_ACT_ADAPTIVE_THRESHOLD; + break; + case '1': + action = USER_IFACE_ACT_CVT_COLOR; + break; + case '2': + action = USER_IFACE_ACT_DISTANCE_TRANSFORM; + break; + case '3': + action = USER_IFACE_ACT_THRESHOLD; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '3': + /* Histograms */ + switch (ch[4]) { + case '0': + action = USER_IFACE_ACT_HISTOGRAM; + break; + case '1': + action = USER_IFACE_ACT_HISTOGRAM_C3; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '4': + /* Structural analysis and shape descriptors */ + switch (ch[4]) { + case '0': + action = USER_IFACE_ACT_CONTOURS; + break; + case '1': + action = USER_IFACE_ACT_CONTOURS_SIZE; + break; + case '2': + action = USER_IFACE_ACT_BOUNDING_RECT; + break; + case '3': + action = USER_IFACE_ACT_FIT_ELLIPSE; + break; + case '4': + action = USER_IFACE_ACT_MIN_AREA_RECT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '5': + /* Feature detection */ + switch (ch[4]) { + case '0': + action = USER_IFACE_ACT_HOUGH_CIRCLES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* img_orb */ + switch (ch[2]) { + case '0': + action = USER_IFACE_ACT_ALIGN; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '3': + /* img_calib3d */ + switch (ch[2]) { + case '0': + action = USER_IFACE_ACT_CALIBRATE; + break; + case '1': + action = USER_IFACE_ACT_UNDISTORT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '4': + /* img_zbar */ + switch (ch[2]) { + case '0': + action = USER_IFACE_ACT_DECODE; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '5': + /* img_ocr */ + switch (ch[2]) { + case '0': + action = USER_IFACE_ACT_READ; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + + case 'l': + action = USER_IFACE_ACT_LOAD_MEM; + break; + + case 'm': + action = USER_IFACE_ACT_SAVE_MEM; + break; + + case 'q': + action = USER_IFACE_ACT_QUIT; + break; + + case 'r': + action = USER_IFACE_ACT_SAVE_REF; + break; + + case 's': + action = USER_IFACE_ACT_SAVE_FILE; + break; + + case 'u': + /* User iface actions */ + switch (ch[1]) { + case '1': + action = USER_IFACE_ACT_SHOW_OCR; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + + case 'x': + /* Special sequence "xyzzy" */ + if (ch[1] == 'y') { + if (ch[2] == 'z') { + if (ch[3] == 'z') { + if (ch[4] == 'y') { + action = USER_IFACE_ACT_FOO; + } + } + } + } + break; + + default: + action = USER_IFACE_ACT_FOO; + break; + } + + return action; +} + +/* * * * * * * * * * + * * * Help * * * * * * * + * * * * * * * * * */ +static void show_help (void) +{ + // FIXME + printf("Apply: %s\n", "Space"); + printf("Discard: %s\n", "Backspace"); + printf("Save to mem: %c\n", 'm'); + printf("Load from mem: %c\n", 'l'); + printf("Save to ref: %c\n", 'r'); + printf("Save to file: %c\n", 's'); + printf("Functions:\n"); + printf(" - Local maxima: %s\n", "f000"); + printf(" - Skeleton: %s\n", "f001"); + printf(" - Horizontal lines: %s\n", "f010"); + printf(" - Vertical lines: %s\n", "f011"); + printf(" - Horizontal mean: %s\n", "f020"); + printf(" - Vertical mean: %s\n", "f021"); + printf(" - Horizontal median: %s\n", "f022"); + printf(" - Vertical median: %s\n", "f023"); + printf(" - Pixel get: %s\n", "f1000"); + printf(" - Pixel set: %s\n", "f1001"); + printf(" - Set ROI: %s\n", "f1010"); + printf(" - Set ROI 2rect: %s\n", "f1011"); + printf(" - Bitwise AND 2ref: %s\n", "f1020"); + printf(" - Bitwise NOT: %s\n", "f1021"); + printf(" - Bitwise OR 2ref: %s\n", "f1022"); + printf(" - Component: %s\n", "f1023"); + printf(" - Dilate: %s\n", "f1100"); + printf(" - Erode: %s\n", "f1101"); + printf(" - D-E: %s\n", "f1102"); + printf(" - E-D: %s\n", "f1103"); + printf(" - Smooth: %s\n", "f1104"); + printf(" - Sobel: %s\n", "f1105"); + printf(" - Border: %s\n", "f1106"); + printf(" - Mirror: %s\n", "f1110"); + printf(" - Rotate ortogonally: %s\n", "f1111"); + printf(" - Rotate: %s\n", "f1112"); + printf(" - Rotate 2rect_rot: %s\n", "f1113"); + printf(" - Adaptive threshold: %s\n", "f1120"); + printf(" - Cvt color: %s\n", "f1121"); + printf(" - Distance transform: %s\n", "f1122"); + printf(" - Threshold: %s\n", "f1123"); + printf(" - Histogram: %s\n", "f1130"); + printf(" - Histogram (3 chan): %s\n", "f1131"); + printf(" - Contours: %s\n", "f1140"); + printf(" - Contours size: %s\n", "f1141"); + printf(" - Bounding rectangle: %s\n", "f1142"); + printf(" - Fit ellipse: %s\n", "f1143"); + printf(" - Min. area rectangle: %s\n", "f1144"); + printf(" - Hough circles: %s\n", "f1150"); + printf(" - Align 2ref (ORB): %s\n", "f20"); + printf(" - Calibrate (Calib3d): %s\n", "f30"); + printf(" - Undistort (Calib3d): %s\n", "f31"); + printf(" - Scan codes (ZBAR): %s\n", "f40"); + printf(" - Scan text (OCR): %s\n", "f50"); + printf("Exercises:\n"); + printf(" - Label: %s\n", "e11"); + printf(" - Objects (calib): %s\n", "e20"); + printf(" - Objects: %s\n", "e21"); + printf(" - Coins: %s\n", "e31"); + printf(" - Resistor: %s\n", "e41"); + printf("Other:\n"); + printf(" - Show OCR text: %s\n", "u1"); + printf("Quit: %c\n", 'q'); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/user/src/user_iface.c b/modules/user/src/user_iface.c index 629dfd8..f465944 100644 --- a/modules/user/src/user_iface.c +++ b/modules/user/src/user_iface.c @@ -1,227 +1,227 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* intX_t */
- #include <stdint.h>
- /* snprintf() & fflush() */
- #include <stdio.h>
-
-/* Project -------------------------------------------------------------------*/
- /* img_iface_act_nodata() */
- #include "img_iface.h"
- /* proc_iface() */
- #include "proc_iface.h"
-
-/* Module --------------------------------------------------------------------*/
- /* user_clui() & ...save_name() */
- #include "user_clui.h"
- /* user_tui() & ...init() & ...cleanup() & ...save_name() */
- #include "user_tui.h"
-
- #include "user_iface.h"
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
- # define TITLE_SIZE (20)
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-int user_iface_mode;
-struct User_Iface_Log user_iface_log;
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-void user_iface_act (int action);
-void user_iface_show_ocr (void);
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void user_iface_init (void)
-{
- user_iface_log.len = 0;
-
- switch (user_iface_mode) {
- case USER_IFACE_CLUI:
- user_clui_init();
- break;
-
- case USER_IFACE_TUI:
- user_tui_init();
- break;
- }
-}
-
-void user_iface_cleanup (void)
-{
- switch (user_iface_mode) {
- case USER_IFACE_CLUI:
- break;
-
- case USER_IFACE_TUI:
- user_tui_cleanup();
- break;
- }
-
- fflush(stdout);
-}
-
-void user_iface (void)
-{
- char title[TITLE_SIZE];
- char subtitle[TITLE_SIZE];
- int user_action;
-
- snprintf(title, TITLE_SIZE, "Title");
- snprintf(subtitle, TITLE_SIZE, "Subtitle");
-
- do {
- /* Display image */
- img_iface_show_img();
-
- /* Request user action */
- switch (user_iface_mode) {
- case USER_IFACE_CLUI:
- user_action = user_clui(title, subtitle);
- break;
-
- case USER_IFACE_TUI:
- user_action = user_tui(title, subtitle);
- break;
-
- default:
- user_action = USER_IFACE_ACT_FOO;
- break;
- }
-
- /* Do action */
- user_iface_act(user_action);
- } while (user_action != USER_IFACE_ACT_QUIT);
-}
-
-void user_iface_show_log (const char *title, const char *subtitle)
-{
- switch (user_iface_mode) {
- case USER_IFACE_CLUI:
- user_clui_show_log(title, subtitle);
- break;
-
- case USER_IFACE_TUI:
- user_tui_show_log(title, subtitle);
- break;
- }
-}
-
-void user_iface_fname (const char *filepath, char *filename)
-{
- switch (user_iface_mode) {
- case USER_IFACE_CLUI:
- user_clui_fname(filepath, filename);
- break;
-
- case USER_IFACE_TUI:
- user_tui_fname(filepath, filename);
- break;
- }
-}
-
-int64_t user_iface_getint (double m, int64_t def, double M,
- const char *title, const char *help)
-{
- int64_t i;
-
- switch (user_iface_mode) {
- case USER_IFACE_CLUI:
- // FIXME
- i = 1;
- break;
-
- case USER_IFACE_TUI:
- i = user_tui_getint(m, def, M, title, help);
- break;
-
- default:
- i = 1;
- break;
- }
-
- return i;
-}
-
-double user_iface_getdbl (double m, double def, double M,
- const char *title, const char *help)
-{
- int64_t i;
-
- switch (user_iface_mode) {
- case USER_IFACE_CLUI:
- // FIXME
- i = 1;
- break;
-
- case USER_IFACE_TUI:
- i = user_tui_getdbl(m, def, M, title, help);
- break;
-
- default:
- i = 1;
- break;
- }
-
- return i;
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-void user_iface_act (int action)
-{
- if (action & USER_IFACE_ACT_USRI) {
- switch (action) {
- case USER_IFACE_ACT_SHOW_OCR:
- user_iface_show_ocr();
- break;
- case USER_IFACE_ACT_QUIT:
- /* do nothing */
- break;
- }
-
- } else if (action & USER_IFACE_ACT_PROC) {
- proc_iface_single(action);
-
- } else {
- img_iface_act_nodata(action);
- }
-}
-
-void user_iface_show_ocr (void)
-{
- switch (user_iface_mode) {
- case USER_IFACE_CLUI:
- // FIXME
- break;
-
- case USER_IFACE_TUI:
- user_tui_show_ocr();
- break;
- }
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* intX_t */ + #include <stdint.h> + /* snprintf() & fflush() */ + #include <stdio.h> + +/* Project -------------------------------------------------------------------*/ + /* img_iface_act_nodata() */ + #include "img_iface.h" + /* proc_iface() */ + #include "proc_iface.h" + +/* Module --------------------------------------------------------------------*/ + /* user_clui() & ...save_name() */ + #include "user_clui.h" + /* user_tui() & ...init() & ...cleanup() & ...save_name() */ + #include "user_tui.h" + + #include "user_iface.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + # define TITLE_SIZE (20) + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +int user_iface_mode; +struct User_Iface_Log user_iface_log; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +void user_iface_act (int action); +void user_iface_show_ocr (void); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void user_iface_init (void) +{ + user_iface_log.len = 0; + + switch (user_iface_mode) { + case USER_IFACE_CLUI: + user_clui_init(); + break; + + case USER_IFACE_TUI: + user_tui_init(); + break; + } +} + +void user_iface_cleanup (void) +{ + switch (user_iface_mode) { + case USER_IFACE_CLUI: + break; + + case USER_IFACE_TUI: + user_tui_cleanup(); + break; + } + + fflush(stdout); +} + +void user_iface (void) +{ + char title[TITLE_SIZE]; + char subtitle[TITLE_SIZE]; + int user_action; + + snprintf(title, TITLE_SIZE, "Title"); + snprintf(subtitle, TITLE_SIZE, "Subtitle"); + + do { + /* Display image */ + img_iface_show_img(); + + /* Request user action */ + switch (user_iface_mode) { + case USER_IFACE_CLUI: + user_action = user_clui(title, subtitle); + break; + + case USER_IFACE_TUI: + user_action = user_tui(title, subtitle); + break; + + default: + user_action = USER_IFACE_ACT_FOO; + break; + } + + /* Do action */ + user_iface_act(user_action); + } while (user_action != USER_IFACE_ACT_QUIT); +} + +void user_iface_show_log (const char *title, const char *subtitle) +{ + switch (user_iface_mode) { + case USER_IFACE_CLUI: + user_clui_show_log(title, subtitle); + break; + + case USER_IFACE_TUI: + user_tui_show_log(title, subtitle); + break; + } +} + +void user_iface_fname (const char *filepath, char *filename) +{ + switch (user_iface_mode) { + case USER_IFACE_CLUI: + user_clui_fname(filepath, filename); + break; + + case USER_IFACE_TUI: + user_tui_fname(filepath, filename); + break; + } +} + +int64_t user_iface_getint (double m, int64_t def, double M, + const char *title, const char *help) +{ + int64_t i; + + switch (user_iface_mode) { + case USER_IFACE_CLUI: + // FIXME + i = 1; + break; + + case USER_IFACE_TUI: + i = user_tui_getint(m, def, M, title, help); + break; + + default: + i = 1; + break; + } + + return i; +} + +double user_iface_getdbl (double m, double def, double M, + const char *title, const char *help) +{ + int64_t i; + + switch (user_iface_mode) { + case USER_IFACE_CLUI: + // FIXME + i = 1; + break; + + case USER_IFACE_TUI: + i = user_tui_getdbl(m, def, M, title, help); + break; + + default: + i = 1; + break; + } + + return i; +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +void user_iface_act (int action) +{ + if (action & USER_IFACE_ACT_USRI) { + switch (action) { + case USER_IFACE_ACT_SHOW_OCR: + user_iface_show_ocr(); + break; + case USER_IFACE_ACT_QUIT: + /* do nothing */ + break; + } + + } else if (action & USER_IFACE_ACT_PROC) { + proc_iface_single(action); + + } else { + img_iface_act_nodata(action); + } +} + +void user_iface_show_ocr (void) +{ + switch (user_iface_mode) { + case USER_IFACE_CLUI: + // FIXME + break; + + case USER_IFACE_TUI: + user_tui_show_ocr(); + break; + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/user/src/user_tui.c b/modules/user/src/user_tui.c index 305e1d2..4c10dc6 100644 --- a/modules/user/src/user_tui.c +++ b/modules/user/src/user_tui.c @@ -1,771 +1,771 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- #include <inttypes.h>
- /* WINDOW & wgetch() & KEY_... & ... */
- #include <ncurses.h>
-
-/* libalx --------------------------------------------------------------------*/
- /* alx_..._curses() & alx_ncur_prn_...() */
- #include "alx_ncur.h"
-
-/* Project -------------------------------------------------------------------*/
- /*img_ocr_text */
- #include "img_iface.h"
-
-/* Module --------------------------------------------------------------------*/
- /* user_iface_log */
- #include "user_iface.h"
-
- #include "user_tui.h"
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-static WINDOW *win_log;
-static WINDOW *win_help;
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
- /* Log */
-static void log_loop (void);
- /* Input */
-static int usr_input (void);
- /* Help */
-static void show_help (void);
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void user_tui_init (void)
-{
- /* Use curses mode */
- alx_resume_curses();
-
- /* Dimensions: log */
- const int h1 = 54;
- const int w1 = 40;
- const int r1 = 0;
- const int c1 = 30;
- win_log = newwin(h1, w1, r1, c1);
-
- /* Dimensions: help */
- const int h2 = 54;
- const int w2 = 40;
- const int r2 = 0;
- const int c2 = 0;
- win_help = newwin(h2, w2, r2, c2);
-
- /* Activate keypad, don't echo input */
- keypad(win_log, true);
- noecho();
-}
-
-void user_tui_cleanup (void)
-{
- /* Del wins & return to terminal mode */
- alx_win_del(win_log);
- alx_win_del(win_help);
- alx_pause_curses();
-}
-
-int user_tui (const char *title, const char *subtitle)
-{
- int action;
-// action = USER_IFACE_ACT_FOO;
-
- show_help();
- user_tui_show_log(title, subtitle);
- action = usr_input();
-
- return action;
-}
-
-void user_tui_fname (const char *filepath, char *filename)
-{
- /* Input box */
- int w;
- int r;
- w = 75;
- r = 10;
-
- /* Request name */
- alx_w_getfname(filepath, filename, false, w, r, "File name:",
- "Valid extensions: .bmp .dib .jpeg .png .pbm .pgm .ppm .tiff");
-}
-
-void user_tui_show_log (const char *title, const char *subtitle)
-{
- /* Clear & box */
- werase(win_log);
- box(win_log, 0, 0);
-
- /* Title */
- alx_ncur_prn_title(win_log, title);
- /* Subtitle */
- alx_ncur_prn_subtitle(win_log, subtitle);
-
- /* Log */
- log_loop();
-
- /* Refresh */
- wrefresh(win_log);
-}
-
-double user_tui_getdbl (double m, double def, double M,
- const char *title, const char *help)
-{
- /* Input box */
- int w;
- int r;
- w = 75;
- r = 10;
-
- /* Request int */
- double R;
- R = alx_w_getdbl(w, r, title, m, def, M, help);
- return R;
-}
-
-int64_t user_tui_getint (double m, int64_t def, double M,
- const char *title, const char *help)
-{
- /* Input box */
- int w;
- int r;
- w = 75;
- r = 10;
-
- /* Request int */
- int64_t i;
- i = alx_w_getint(w, r, title, m, def, M, help);
- return i;
-}
-
-void user_tui_show_ocr (void)
-{
- alx_pause_curses();
-
- printf("%s", img_ocr_text);
- getchar();
-
- alx_resume_curses();
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-/* Log -----------------------------------------------------------------------*/
-static void log_loop (void)
-{
- int i;
- int i_0;
- int l;
- int l_0;
-
- if (user_iface_log.len > 51) {
- i_0 = user_iface_log.len - 51;
- l_0 = 1;
- mvwprintw(win_log, 1, 10, "...");
- } else {
- i_0 = 0;
- l_0 = 0;
- }
-
- l = l_0;
- for (i = i_0; i < user_iface_log.len; i++) {
- if (user_iface_log.lvl[i] <= user_iface_log.visible) {
- mvwprintw(win_log, (1 + l),
- (1 + 4 * user_iface_log.lvl[i]),
- "%.*s",
- 40 - 2 - 4 * user_iface_log.lvl[i],
- user_iface_log.line[i]);
- l++;
- }
- }
-}
-
-/* Input ---------------------------------------------------------------------*/
-static int usr_input (void)
-{
- int action;
- wchar_t ch;
-
- /* Interpret input */
- ch = wgetch(win_log);
- switch (ch) {
- case ' ':
- action = USER_IFACE_ACT_APPLY;
- break;
-
- /* ASCII 0x08 is BS */
- case KEY_BACKSPACE:
- case 0x08:
- action = USER_IFACE_ACT_DISCARD;
- break;
-
- case 'e':
- /* Exercises from class */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '1':
- /* Label */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '1':
- action = USER_IFACE_ACT_PROC_LABEL_SERIES;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '2':
- /* Objects */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_PROC_OBJECTS_CALIB;
- break;
- case '1':
- action = USER_IFACE_ACT_PROC_OBJECTS_SERIES;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '3':
- /* Coins */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '1':
- action = USER_IFACE_ACT_PROC_COINS_SERIES;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '4':
- /* Resistor */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '1':
- action = USER_IFACE_ACT_PROC_RESISTOR_SERIES;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
-
- case 'f':
- /* Use simple funtions */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- /* img_alx */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- /* Distance transform postprocessing */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_LOCAL_MAX;
- break;
- case '1':
- action = USER_IFACE_ACT_SKELETON;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '1':
- /* Lines */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_LINES_HORIZONTAL;
- break;
- case '1':
- action = USER_IFACE_ACT_LINES_VERTICAL;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '2':
- /* Smooth */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_MEAN_HORIZONTAL;
- break;
- case '1':
- action = USER_IFACE_ACT_MEAN_VERTICAL;
- break;
- case '2':
- action = USER_IFACE_ACT_MEDIAN_HORIZONTAL;
- break;
- case '3':
- action = USER_IFACE_ACT_MEDIAN_VERTICAL;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '1':
- /* img_cv */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- /* Core: The core functionality */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- /* Pixel */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_PIXEL_GET;
- break;
- case '1':
- action = USER_IFACE_ACT_PIXEL_SET;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '1':
- /* ROI */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_SET_ROI;
- break;
- case '1':
- action = USER_IFACE_ACT_SET_ROI_2RECT;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '2':
- /* Operations on Arrays */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_AND_2REF;
- break;
- case '1':
- action = USER_IFACE_ACT_NOT;
- break;
- case '2':
- action = USER_IFACE_ACT_OR_2REF;
- break;
- case '3':
- action = USER_IFACE_ACT_COMPONENT;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '1':
- /* Imgproc: Image processing */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- /* Image filtering */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_DILATE;
- break;
- case '1':
- action = USER_IFACE_ACT_ERODE;
- break;
- case '2':
- action = USER_IFACE_ACT_DILATE_ERODE;
- break;
- case '3':
- action = USER_IFACE_ACT_ERODE_DILATE;
- break;
- case '4':
- action = USER_IFACE_ACT_SMOOTH;
- break;
- case '5':
- action = USER_IFACE_ACT_SOBEL;
- break;
- case '6':
- action = USER_IFACE_ACT_BORDER;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '1':
- /* Geometric image transformations */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_MIRROR;
- break;
- case '1':
- action = USER_IFACE_ACT_ROTATE_ORTO;
- break;
- case '2':
- action = USER_IFACE_ACT_ROTATE;
- break;
- case '3':
- action = USER_IFACE_ACT_ROTATE_2RECT;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '2':
- /* Miscellaneous image transformations */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_ADAPTIVE_THRESHOLD;
- break;
- case '1':
- action = USER_IFACE_ACT_CVT_COLOR;
- break;
- case '2':
- action = USER_IFACE_ACT_DISTANCE_TRANSFORM;
- break;
- case '3':
- action = USER_IFACE_ACT_THRESHOLD;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '3':
- /* Histograms */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_HISTOGRAM;
- break;
- case '1':
- action = USER_IFACE_ACT_HISTOGRAM_C3;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '4':
- /* Structural analysis and shape descriptors */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_CONTOURS;
- break;
- case '1':
- action = USER_IFACE_ACT_CONTOURS_SIZE;
- break;
- case '2':
- action = USER_IFACE_ACT_BOUNDING_RECT;
- break;
- case '3':
- action = USER_IFACE_ACT_FIT_ELLIPSE;
- break;
- case '4':
- action = USER_IFACE_ACT_MIN_AREA_RECT;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '5':
- /* Feature detection */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_HOUGH_CIRCLES;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '2':
- /* img_orb */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_ALIGN;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '3':
- /* img_calib3d */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_CALIBRATE;
- break;
- case '1':
- action = USER_IFACE_ACT_UNDISTORT;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '4':
- /* img_zbar */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_DECODE;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '5':
- /* img_ocr */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_READ;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
-
- case 'l':
- action = USER_IFACE_ACT_LOAD_MEM;
- break;
-
- case 'm':
- action = USER_IFACE_ACT_SAVE_MEM;
- break;
-
- case 'q':
- action = USER_IFACE_ACT_QUIT;
- break;
-
- case 'r':
- action = USER_IFACE_ACT_SAVE_REF;
- break;
-
- case 's':
- action = USER_IFACE_ACT_SAVE_FILE;
- break;
-
- case 'u':
- /* User iface actions */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '1':
- action = USER_IFACE_ACT_SHOW_OCR;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
-
- case 'x':
- action = USER_IFACE_ACT_FOO;
-
- /* Special sequence "xyzzy" */
- ch = wgetch(win_log);
- if (ch == 'y') {
- ch = wgetch(win_log);
- if (ch == 'z') {
-
- ch = wgetch(win_log);
- if (ch == 'z') {
-
- ch = wgetch(win_log);
- if (ch == 'y') {
- action = USER_IFACE_ACT_FOO;
- }
- }
- }
- }
- break;
-
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
-
- return action;
-}
-
-/* * * * * * * * * *
- * * * Help * * * * * * *
- * * * * * * * * * */
-static void show_help (void)
-{
- /* Clear */
- werase(win_help);
-
- int r;
- int c;
-
- r = 0;
- c = 0;
- mvwprintw(win_help, r++, c, "Apply: %s", "Space");
- mvwprintw(win_help, r++, c, "Discard: %s", "BS");
- mvwprintw(win_help, r++, c, "Save to mem: %c", 'm');
- mvwprintw(win_help, r++, c, "Load from mem: %c", 'l');
- mvwprintw(win_help, r++, c, "Save to ref: %c", 'r');
- mvwprintw(win_help, r++, c, "Save to file: %c", 's');
- mvwprintw(win_help, r++, c, "Functions:");
- mvwprintw(win_help, r++, c, " - Local maxima: %s", "f000");
- mvwprintw(win_help, r++, c, " - Skeleton: %s", "f001");
- mvwprintw(win_help, r++, c, " - Horizontal lines: %s", "f010");
- mvwprintw(win_help, r++, c, " - Vertical lines: %s", "f011");
- mvwprintw(win_help, r++, c, " - Horizontal mean: %s", "f020");
- mvwprintw(win_help, r++, c, " - Vertical mean: %s", "f021");
- mvwprintw(win_help, r++, c, " - Horizontal median: %s", "f022");
- mvwprintw(win_help, r++, c, " - Vertical median: %s", "f023");
- mvwprintw(win_help, r++, c, " - Pixel get: %s", "f1000");
- mvwprintw(win_help, r++, c, " - Pixel set: %s", "f1001");
- mvwprintw(win_help, r++, c, " - Set ROI: %s", "f1010");
- mvwprintw(win_help, r++, c, " - Set ROI 2rect: %s", "f1011");
- mvwprintw(win_help, r++, c, " - Bitwise AND 2ref: %s", "f1020");
- mvwprintw(win_help, r++, c, " - Bitwise NOT: %s", "f1021");
- mvwprintw(win_help, r++, c, " - Bitwise OR 2ref: %s", "f1022");
- mvwprintw(win_help, r++, c, " - Component: %s", "f1023");
- mvwprintw(win_help, r++, c, " - Dilate: %s", "f1100");
- mvwprintw(win_help, r++, c, " - Erode: %s", "f1101");
- mvwprintw(win_help, r++, c, " - D-E: %s", "f1102");
- mvwprintw(win_help, r++, c, " - E-D: %s", "f1103");
- mvwprintw(win_help, r++, c, " - Smooth: %s", "f1104");
- mvwprintw(win_help, r++, c, " - Sobel: %s", "f1105");
- mvwprintw(win_help, r++, c, " - Border: %s", "f1106");
- mvwprintw(win_help, r++, c, " - Mirror: %s", "f1110");
- mvwprintw(win_help, r++, c, " - Rotate ortogonally: %s", "f1111");
- mvwprintw(win_help, r++, c, " - Rotate: %s", "f1112");
- mvwprintw(win_help, r++, c, " - Rotate 2rect_rot: %s", "f1113");
- mvwprintw(win_help, r++, c, " - Adaptive threshold: %s", "f1120");
- mvwprintw(win_help, r++, c, " - Cvt color: %s", "f1121");
- mvwprintw(win_help, r++, c, " - Distance transform: %s", "f1122");
- mvwprintw(win_help, r++, c, " - Threshold: %s", "f1123");
- mvwprintw(win_help, r++, c, " - Histogram: %s", "f1130");
- mvwprintw(win_help, r++, c, " - Histogram (3 chan): %s", "f1131");
- mvwprintw(win_help, r++, c, " - Contours: %s", "f1140");
- mvwprintw(win_help, r++, c, " - Contours size: %s", "f1141");
- mvwprintw(win_help, r++, c, " - Bounding rectangle: %s", "f1142");
- mvwprintw(win_help, r++, c, " - Fit ellipse: %s", "f1143");
- mvwprintw(win_help, r++, c, " - Min. area rectangle: %s", "f1144");
- mvwprintw(win_help, r++, c, " - Hough circles: %s", "f1150");
- mvwprintw(win_help, r++, c, " - Align 2ref (ORB): %s", "f20");
- mvwprintw(win_help, r++, c, " - Calibrate (Calib3d): %s", "f30");
- mvwprintw(win_help, r++, c, " - Undistort (Calib3d): %s", "f31");
- mvwprintw(win_help, r++, c, " - Scan codes (ZBAR): %s", "f40");
- mvwprintw(win_help, r++, c, " - Scan text (OCR): %s", "f50");
- mvwprintw(win_help, r++, c, "Exercises:");
- mvwprintw(win_help, r++, c, " - Label: %s", "e11");
- mvwprintw(win_help, r++, c, " - Objects (calib): %s", "e20");
- mvwprintw(win_help, r++, c, " - Objects: %s", "e21");
- mvwprintw(win_help, r++, c, " - Coins: %s", "e31");
- mvwprintw(win_help, r++, c, " - Resistor: %s", "e41");
- mvwprintw(win_help, r++, c, "Other:");
- mvwprintw(win_help, r++, c, " - Show OCR: %s", "u1");
- mvwprintw(win_help, r++, c, "Quit: %c", 'q');
-
- /* Refresh */
- wrefresh(win_help);
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + #include <inttypes.h> + /* WINDOW & wgetch() & KEY_... & ... */ + #include <ncurses.h> + +/* libalx --------------------------------------------------------------------*/ + /* alx_..._curses() & alx_ncur_prn_...() */ + #include "alx_ncur.h" + +/* Project -------------------------------------------------------------------*/ + /*img_ocr_text */ + #include "img_iface.h" + +/* Module --------------------------------------------------------------------*/ + /* user_iface_log */ + #include "user_iface.h" + + #include "user_tui.h" + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +static WINDOW *win_log; +static WINDOW *win_help; + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ + /* Log */ +static void log_loop (void); + /* Input */ +static int usr_input (void); + /* Help */ +static void show_help (void); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +void user_tui_init (void) +{ + /* Use curses mode */ + alx_resume_curses(); + + /* Dimensions: log */ + const int h1 = 54; + const int w1 = 40; + const int r1 = 0; + const int c1 = 30; + win_log = newwin(h1, w1, r1, c1); + + /* Dimensions: help */ + const int h2 = 54; + const int w2 = 40; + const int r2 = 0; + const int c2 = 0; + win_help = newwin(h2, w2, r2, c2); + + /* Activate keypad, don't echo input */ + keypad(win_log, true); + noecho(); +} + +void user_tui_cleanup (void) +{ + /* Del wins & return to terminal mode */ + alx_win_del(win_log); + alx_win_del(win_help); + alx_pause_curses(); +} + +int user_tui (const char *title, const char *subtitle) +{ + int action; +// action = USER_IFACE_ACT_FOO; + + show_help(); + user_tui_show_log(title, subtitle); + action = usr_input(); + + return action; +} + +void user_tui_fname (const char *filepath, char *filename) +{ + /* Input box */ + int w; + int r; + w = 75; + r = 10; + + /* Request name */ + alx_w_getfname(filepath, filename, false, w, r, "File name:", + "Valid extensions: .bmp .dib .jpeg .png .pbm .pgm .ppm .tiff"); +} + +void user_tui_show_log (const char *title, const char *subtitle) +{ + /* Clear & box */ + werase(win_log); + box(win_log, 0, 0); + + /* Title */ + alx_ncur_prn_title(win_log, title); + /* Subtitle */ + alx_ncur_prn_subtitle(win_log, subtitle); + + /* Log */ + log_loop(); + + /* Refresh */ + wrefresh(win_log); +} + +double user_tui_getdbl (double m, double def, double M, + const char *title, const char *help) +{ + /* Input box */ + int w; + int r; + w = 75; + r = 10; + + /* Request int */ + double R; + R = alx_w_getdbl(w, r, title, m, def, M, help); + return R; +} + +int64_t user_tui_getint (double m, int64_t def, double M, + const char *title, const char *help) +{ + /* Input box */ + int w; + int r; + w = 75; + r = 10; + + /* Request int */ + int64_t i; + i = alx_w_getint(w, r, title, m, def, M, help); + return i; +} + +void user_tui_show_ocr (void) +{ + alx_pause_curses(); + + printf("%s", img_ocr_text); + getchar(); + + alx_resume_curses(); +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +/* Log -----------------------------------------------------------------------*/ +static void log_loop (void) +{ + int i; + int i_0; + int l; + int l_0; + + if (user_iface_log.len > 51) { + i_0 = user_iface_log.len - 51; + l_0 = 1; + mvwprintw(win_log, 1, 10, "..."); + } else { + i_0 = 0; + l_0 = 0; + } + + l = l_0; + for (i = i_0; i < user_iface_log.len; i++) { + if (user_iface_log.lvl[i] <= user_iface_log.visible) { + mvwprintw(win_log, (1 + l), + (1 + 4 * user_iface_log.lvl[i]), + "%.*s", + 40 - 2 - 4 * user_iface_log.lvl[i], + user_iface_log.line[i]); + l++; + } + } +} + +/* Input ---------------------------------------------------------------------*/ +static int usr_input (void) +{ + int action; + wchar_t ch; + + /* Interpret input */ + ch = wgetch(win_log); + switch (ch) { + case ' ': + action = USER_IFACE_ACT_APPLY; + break; + + /* ASCII 0x08 is BS */ + case KEY_BACKSPACE: + case 0x08: + action = USER_IFACE_ACT_DISCARD; + break; + + case 'e': + /* Exercises from class */ + ch = wgetch(win_log); + + switch (ch) { + case '1': + /* Label */ + ch = wgetch(win_log); + + switch (ch) { + case '1': + action = USER_IFACE_ACT_PROC_LABEL_SERIES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* Objects */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_PROC_OBJECTS_CALIB; + break; + case '1': + action = USER_IFACE_ACT_PROC_OBJECTS_SERIES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '3': + /* Coins */ + ch = wgetch(win_log); + + switch (ch) { + case '1': + action = USER_IFACE_ACT_PROC_COINS_SERIES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '4': + /* Resistor */ + ch = wgetch(win_log); + + switch (ch) { + case '1': + action = USER_IFACE_ACT_PROC_RESISTOR_SERIES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + + case 'f': + /* Use simple funtions */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + /* img_alx */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + /* Distance transform postprocessing */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_LOCAL_MAX; + break; + case '1': + action = USER_IFACE_ACT_SKELETON; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '1': + /* Lines */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_LINES_HORIZONTAL; + break; + case '1': + action = USER_IFACE_ACT_LINES_VERTICAL; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* Smooth */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_MEAN_HORIZONTAL; + break; + case '1': + action = USER_IFACE_ACT_MEAN_VERTICAL; + break; + case '2': + action = USER_IFACE_ACT_MEDIAN_HORIZONTAL; + break; + case '3': + action = USER_IFACE_ACT_MEDIAN_VERTICAL; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '1': + /* img_cv */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + /* Core: The core functionality */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + /* Pixel */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_PIXEL_GET; + break; + case '1': + action = USER_IFACE_ACT_PIXEL_SET; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '1': + /* ROI */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_SET_ROI; + break; + case '1': + action = USER_IFACE_ACT_SET_ROI_2RECT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* Operations on Arrays */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_AND_2REF; + break; + case '1': + action = USER_IFACE_ACT_NOT; + break; + case '2': + action = USER_IFACE_ACT_OR_2REF; + break; + case '3': + action = USER_IFACE_ACT_COMPONENT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '1': + /* Imgproc: Image processing */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + /* Image filtering */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_DILATE; + break; + case '1': + action = USER_IFACE_ACT_ERODE; + break; + case '2': + action = USER_IFACE_ACT_DILATE_ERODE; + break; + case '3': + action = USER_IFACE_ACT_ERODE_DILATE; + break; + case '4': + action = USER_IFACE_ACT_SMOOTH; + break; + case '5': + action = USER_IFACE_ACT_SOBEL; + break; + case '6': + action = USER_IFACE_ACT_BORDER; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '1': + /* Geometric image transformations */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_MIRROR; + break; + case '1': + action = USER_IFACE_ACT_ROTATE_ORTO; + break; + case '2': + action = USER_IFACE_ACT_ROTATE; + break; + case '3': + action = USER_IFACE_ACT_ROTATE_2RECT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* Miscellaneous image transformations */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_ADAPTIVE_THRESHOLD; + break; + case '1': + action = USER_IFACE_ACT_CVT_COLOR; + break; + case '2': + action = USER_IFACE_ACT_DISTANCE_TRANSFORM; + break; + case '3': + action = USER_IFACE_ACT_THRESHOLD; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '3': + /* Histograms */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_HISTOGRAM; + break; + case '1': + action = USER_IFACE_ACT_HISTOGRAM_C3; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '4': + /* Structural analysis and shape descriptors */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_CONTOURS; + break; + case '1': + action = USER_IFACE_ACT_CONTOURS_SIZE; + break; + case '2': + action = USER_IFACE_ACT_BOUNDING_RECT; + break; + case '3': + action = USER_IFACE_ACT_FIT_ELLIPSE; + break; + case '4': + action = USER_IFACE_ACT_MIN_AREA_RECT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '5': + /* Feature detection */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_HOUGH_CIRCLES; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '2': + /* img_orb */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_ALIGN; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '3': + /* img_calib3d */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_CALIBRATE; + break; + case '1': + action = USER_IFACE_ACT_UNDISTORT; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '4': + /* img_zbar */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_DECODE; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + case '5': + /* img_ocr */ + ch = wgetch(win_log); + + switch (ch) { + case '0': + action = USER_IFACE_ACT_READ; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + + case 'l': + action = USER_IFACE_ACT_LOAD_MEM; + break; + + case 'm': + action = USER_IFACE_ACT_SAVE_MEM; + break; + + case 'q': + action = USER_IFACE_ACT_QUIT; + break; + + case 'r': + action = USER_IFACE_ACT_SAVE_REF; + break; + + case 's': + action = USER_IFACE_ACT_SAVE_FILE; + break; + + case 'u': + /* User iface actions */ + ch = wgetch(win_log); + + switch (ch) { + case '1': + action = USER_IFACE_ACT_SHOW_OCR; + break; + default: + action = USER_IFACE_ACT_FOO; + break; + } + break; + + case 'x': + action = USER_IFACE_ACT_FOO; + + /* Special sequence "xyzzy" */ + ch = wgetch(win_log); + if (ch == 'y') { + ch = wgetch(win_log); + if (ch == 'z') { + + ch = wgetch(win_log); + if (ch == 'z') { + + ch = wgetch(win_log); + if (ch == 'y') { + action = USER_IFACE_ACT_FOO; + } + } + } + } + break; + + default: + action = USER_IFACE_ACT_FOO; + break; + } + + return action; +} + +/* * * * * * * * * * + * * * Help * * * * * * * + * * * * * * * * * */ +static void show_help (void) +{ + /* Clear */ + werase(win_help); + + int r; + int c; + + r = 0; + c = 0; + mvwprintw(win_help, r++, c, "Apply: %s", "Space"); + mvwprintw(win_help, r++, c, "Discard: %s", "BS"); + mvwprintw(win_help, r++, c, "Save to mem: %c", 'm'); + mvwprintw(win_help, r++, c, "Load from mem: %c", 'l'); + mvwprintw(win_help, r++, c, "Save to ref: %c", 'r'); + mvwprintw(win_help, r++, c, "Save to file: %c", 's'); + mvwprintw(win_help, r++, c, "Functions:"); + mvwprintw(win_help, r++, c, " - Local maxima: %s", "f000"); + mvwprintw(win_help, r++, c, " - Skeleton: %s", "f001"); + mvwprintw(win_help, r++, c, " - Horizontal lines: %s", "f010"); + mvwprintw(win_help, r++, c, " - Vertical lines: %s", "f011"); + mvwprintw(win_help, r++, c, " - Horizontal mean: %s", "f020"); + mvwprintw(win_help, r++, c, " - Vertical mean: %s", "f021"); + mvwprintw(win_help, r++, c, " - Horizontal median: %s", "f022"); + mvwprintw(win_help, r++, c, " - Vertical median: %s", "f023"); + mvwprintw(win_help, r++, c, " - Pixel get: %s", "f1000"); + mvwprintw(win_help, r++, c, " - Pixel set: %s", "f1001"); + mvwprintw(win_help, r++, c, " - Set ROI: %s", "f1010"); + mvwprintw(win_help, r++, c, " - Set ROI 2rect: %s", "f1011"); + mvwprintw(win_help, r++, c, " - Bitwise AND 2ref: %s", "f1020"); + mvwprintw(win_help, r++, c, " - Bitwise NOT: %s", "f1021"); + mvwprintw(win_help, r++, c, " - Bitwise OR 2ref: %s", "f1022"); + mvwprintw(win_help, r++, c, " - Component: %s", "f1023"); + mvwprintw(win_help, r++, c, " - Dilate: %s", "f1100"); + mvwprintw(win_help, r++, c, " - Erode: %s", "f1101"); + mvwprintw(win_help, r++, c, " - D-E: %s", "f1102"); + mvwprintw(win_help, r++, c, " - E-D: %s", "f1103"); + mvwprintw(win_help, r++, c, " - Smooth: %s", "f1104"); + mvwprintw(win_help, r++, c, " - Sobel: %s", "f1105"); + mvwprintw(win_help, r++, c, " - Border: %s", "f1106"); + mvwprintw(win_help, r++, c, " - Mirror: %s", "f1110"); + mvwprintw(win_help, r++, c, " - Rotate ortogonally: %s", "f1111"); + mvwprintw(win_help, r++, c, " - Rotate: %s", "f1112"); + mvwprintw(win_help, r++, c, " - Rotate 2rect_rot: %s", "f1113"); + mvwprintw(win_help, r++, c, " - Adaptive threshold: %s", "f1120"); + mvwprintw(win_help, r++, c, " - Cvt color: %s", "f1121"); + mvwprintw(win_help, r++, c, " - Distance transform: %s", "f1122"); + mvwprintw(win_help, r++, c, " - Threshold: %s", "f1123"); + mvwprintw(win_help, r++, c, " - Histogram: %s", "f1130"); + mvwprintw(win_help, r++, c, " - Histogram (3 chan): %s", "f1131"); + mvwprintw(win_help, r++, c, " - Contours: %s", "f1140"); + mvwprintw(win_help, r++, c, " - Contours size: %s", "f1141"); + mvwprintw(win_help, r++, c, " - Bounding rectangle: %s", "f1142"); + mvwprintw(win_help, r++, c, " - Fit ellipse: %s", "f1143"); + mvwprintw(win_help, r++, c, " - Min. area rectangle: %s", "f1144"); + mvwprintw(win_help, r++, c, " - Hough circles: %s", "f1150"); + mvwprintw(win_help, r++, c, " - Align 2ref (ORB): %s", "f20"); + mvwprintw(win_help, r++, c, " - Calibrate (Calib3d): %s", "f30"); + mvwprintw(win_help, r++, c, " - Undistort (Calib3d): %s", "f31"); + mvwprintw(win_help, r++, c, " - Scan codes (ZBAR): %s", "f40"); + mvwprintw(win_help, r++, c, " - Scan text (OCR): %s", "f50"); + mvwprintw(win_help, r++, c, "Exercises:"); + mvwprintw(win_help, r++, c, " - Label: %s", "e11"); + mvwprintw(win_help, r++, c, " - Objects (calib): %s", "e20"); + mvwprintw(win_help, r++, c, " - Objects: %s", "e21"); + mvwprintw(win_help, r++, c, " - Coins: %s", "e31"); + mvwprintw(win_help, r++, c, " - Resistor: %s", "e41"); + mvwprintw(win_help, r++, c, "Other:"); + mvwprintw(win_help, r++, c, " - Show OCR: %s", "u1"); + mvwprintw(win_help, r++, c, "Quit: %c", 'q'); + + /* Refresh */ + wrefresh(win_help); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/main.cpp b/src/main.cpp index 875cfbd..f672b68 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,88 +1,88 @@ -/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* getchar() */
- #include <cstdio>
-
-/* libalx --------------------------------------------------------------------*/
- #include "alx_ncur.hpp"
-
-/* Project -------------------------------------------------------------------*/
- /* about_init() & print_cpright() */
- #include "about.hpp"
- #include "img_iface.hpp"
- #include "menu_iface.hpp"
- #include "user_iface.hpp"
- #include "parser.hpp"
- #include "save.hpp"
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void init_all (int *argc, char *(*argv[]));
-static void cleanup (void);
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-int main (int argc, char *argv[])
-{
- init_all(&argc, &argv);
-
- /* Print copyright () and wait for any key to continue */
- print_share_file(SHARE_COPYRIGHT);
- getchar();
-
- /* Menu () */
- menu_iface();
-
- cleanup();
-
- return 0;
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void init_all (int *argc, char *(*argv[]))
-{
- /* Init curses */
- alx_start_curses();
- alx_pause_curses();
-
- /* Init modules */
- about_init();
- save_init();
-
- /* Modes */
- menu_iface_mode = MENU_IFACE_TUI;
- user_iface_mode = USER_IFACE_TUI;
- user_iface_log.visible = 2;
-
- /* Parse command line options */
- parser(*argc, *argv);
-}
-
-static void cleanup (void)
-{
- /* Clean img buffers */
- img_iface_cleanup_main();
-
- /* End curses */
- alx_resume_curses();
- alx_end_curses();
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +/* Standard C ----------------------------------------------------------------*/ + /* getchar() */ + #include <cstdio> + +/* libalx --------------------------------------------------------------------*/ + #include "alx_ncur.hpp" + +/* Project -------------------------------------------------------------------*/ + /* about_init() & print_cpright() */ + #include "about.hpp" + #include "img_iface.hpp" + #include "menu_iface.hpp" + #include "user_iface.hpp" + #include "parser.hpp" + #include "save.hpp" + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void init_all (int *argc, char *(*argv[])); +static void cleanup (void); + + +/****************************************************************************** + ******* main ***************************************************************** + ******************************************************************************/ +int main (int argc, char *argv[]) +{ + init_all(&argc, &argv); + + /* Print copyright () and wait for any key to continue */ + print_share_file(SHARE_COPYRIGHT); + getchar(); + + /* Menu () */ + menu_iface(); + + cleanup(); + + return 0; +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +static void init_all (int *argc, char *(*argv[])) +{ + /* Init curses */ + alx_start_curses(); + alx_pause_curses(); + + /* Init modules */ + about_init(); + save_init(); + + /* Modes */ + menu_iface_mode = MENU_IFACE_TUI; + user_iface_mode = USER_IFACE_TUI; + user_iface_log.visible = 2; + + /* Parse command line options */ + parser(*argc, *argv); +} + +static void cleanup (void) +{ + /* Clean img buffers */ + img_iface_cleanup_main(); + + /* End curses */ + alx_resume_curses(); + alx_end_curses(); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ |