diff options
author | alejandro-colomar <colomar.6.4.3@gmail.com> | 2019-08-01 20:23:33 +0200 |
---|---|---|
committer | alejandro-colomar <colomar.6.4.3@gmail.com> | 2019-08-01 20:23:33 +0200 |
commit | bfb3ae86f97cc362dc6db04111a422e48ce6995c (patch) | |
tree | 2ecc7aba1be1d0fa1abb60ab0fb9ca3a11d4fef8 | |
parent | 069a4844b1043f68414d680ab55a4aebc6ab9523 (diff) |
Remove proc code
27 files changed, 7 insertions, 4256 deletions
diff --git a/bin/Makefile b/bin/Makefile index 07d404a..83377ba 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -11,25 +11,17 @@ OBJS = \ $(TMP_DIR)/image/ocr.o \ $(TMP_DIR)/image/orb.o \ $(TMP_DIR)/image/zbar.o \ - $(TMP_DIR)/menu/clui.o \ $(TMP_DIR)/menu/iface.o \ $(TMP_DIR)/menu/parse.o \ $(TMP_DIR)/menu/tui.o \ - $(TMP_DIR)/proc/common.o \ - $(TMP_DIR)/proc/iface.o \ - $(TMP_DIR)/proc/label.o \ - $(TMP_DIR)/proc/lighters.o \ - $(TMP_DIR)/proc/objects.o \ - $(TMP_DIR)/proc/resistor.o \ $(TMP_DIR)/save/save.o \ $(TMP_DIR)/share/share.o \ - $(TMP_DIR)/user/clui.o \ $(TMP_DIR)/user/iface.o \ $(TMP_DIR)/user/tui.o DEPS_LIBS = \ $(LIBALX_LIB_DIR)/libalx-cv.a \ - $(LIBALX_LIB_DIR)/libalx-gsl.a \ $(LIBALX_LIB_DIR)/libalx-ncurses.a \ + $(LIBALX_LIB_DIR)/libalx-gsl.a \ $(LIBALX_LIB_DIR)/libalx-base.a ALL = $(BIN_NAME) size @@ -37,9 +29,9 @@ ALL = $(BIN_NAME) size # static libs STATIC_LIBS = -L $(LIBALX_LIB_DIR) \ + -l alx-cv \ -l alx-ncurses \ -l alx-gsl \ - -l alx-cv \ -l alx-base diff --git a/inc/vision-artificial/proc/common.h b/inc/vision-artificial/proc/common.h deleted file mode 100644 index f5844fc..0000000 --- a/inc/vision-artificial/proc/common.h +++ /dev/null @@ -1,65 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -#ifndef VA_PROC_COMMON_H -#define VA_PROC_COMMON_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* structs / unions ***************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* extern functions ***************************************************** - ******************************************************************************/ -void proc_show_img (void); -void clock_start (void); -void clock_stop (const char *txt); - - -/****************************************************************************** - ******* static inline functions (prototypes) ********************************* - ******************************************************************************/ - - -/****************************************************************************** - ******* static inline functions (definitions) ******************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -#endif /* vision-artificial/proc/common.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/inc/vision-artificial/proc/common.hpp b/inc/vision-artificial/proc/common.hpp deleted file mode 100644 index 00d1f0a..0000000 --- a/inc/vision-artificial/proc/common.hpp +++ /dev/null @@ -1,127 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -#ifndef VA_PROC_COMMON_HPP -#define VA_PROC_COMMON_HPP - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -#include <cstdbool> - -#include <vector> - -#include <opencv2/core/core.hpp> - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* structs / unions ***************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* extern functions ***************************************************** - ******************************************************************************/ -extern "C" -{ -void proc_apply (void); -void proc_save_mem (ptrdiff_t n); -void proc_load_mem (ptrdiff_t 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 (ptrdiff_t x, ptrdiff_t y, unsigned char *val); -void proc_pixel_set (ptrdiff_t x, ptrdiff_t 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 (float center_x, float 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 ( - class std::vector <class std::vector <class cv::Point_ <int>>> *contours, - class cv::Mat *hierarchy); -void proc_contours_size ( - const class std::vector <class std::vector <class cv::Point_ <int>>> *contours, - double *area, - double *perimeter); -void proc_bounding_rect ( - const class std::vector <class cv::Point_ <int>> *contour, - class cv::Rect_ <int> *rect, - bool show); -void proc_fit_ellipse ( - const class std::vector <class cv::Point_ <int>> *contour, - class cv::RotatedRect *rect, - bool show); -void proc_min_area_rect ( - const class 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); -} - - -/****************************************************************************** - ******* static inline functions (prototypes) ********************************* - ******************************************************************************/ - - -/****************************************************************************** - ******* static inline functions (definitions) ******************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -#endif /* vision-artificial/proc/common.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/inc/vision-artificial/proc/iface.h b/inc/vision-artificial/proc/iface.h deleted file mode 100644 index 267809c..0000000 --- a/inc/vision-artificial/proc/iface.h +++ /dev/null @@ -1,88 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* 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, - PROC_MODE_LIGHTERS_SERIES, - PROC_MODE_LIGHTERS_CALIB -}; - -enum Proc_DBG { - PROC_DBG_NO, - PROC_DBG_STOP_ITEM, - PROC_DBG_DELAY_STEP, - PROC_DBG_STOP_STEP -}; - - -/****************************************************************************** - ******* structs / unions ***************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern int proc_debug; -extern int proc_mode; - - -/****************************************************************************** - ******* extern functions ***************************************************** - ******************************************************************************/ -int proc_iface_single (int action); -void proc_iface_series (void); - - -/****************************************************************************** - ******* static inline functions (prototypes) ********************************* - ******************************************************************************/ - - -/****************************************************************************** - ******* static inline functions (definitions) ******************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -#endif /* vision-artificial/proc/iface.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/inc/vision-artificial/proc/iface.hpp b/inc/vision-artificial/proc/iface.hpp deleted file mode 100644 index ce54ead..0000000 --- a/inc/vision-artificial/proc/iface.hpp +++ /dev/null @@ -1,91 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -#ifndef VA_PROC_IFACE_HPP -#define VA_PROC_IFACE_HPP - - -/****************************************************************************** - ******* 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, - PROC_MODE_LIGHTERS_SERIES, - PROC_MODE_LIGHTERS_CALIB -}; - -enum Proc_DBG { - PROC_DBG_NO, - PROC_DBG_STOP_ITEM, - PROC_DBG_DELAY_STEP, - PROC_DBG_STOP_STEP -}; - - -/****************************************************************************** - ******* structs / unions ***************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern int proc_debug; -extern int proc_mode; - - -/****************************************************************************** - ******* extern functions ***************************************************** - ******************************************************************************/ -extern "C" -{ -int proc_iface_single (int action); -void proc_iface_series (void); -} - - -/****************************************************************************** - ******* static inline functions (prototypes) ********************************* - ******************************************************************************/ - - -/****************************************************************************** - ******* static inline functions (definitions) ******************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -#endif /* vision-artificial/proc/iface.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/inc/vision-artificial/proc/label.h b/inc/vision-artificial/proc/label.h deleted file mode 100644 index 0731ada..0000000 --- a/inc/vision-artificial/proc/label.h +++ /dev/null @@ -1,71 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -#ifndef VA_PROC_LABEL_H -#define VA_PROC_LABEL_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ -enum Proc_Label { - LABEL_OK, - LABEL_NOK_LABEL, - LABEL_NOK_CERDO, - LABEL_NOK_BCODE, - LABEL_NOK_PRODUCT, - LABEL_NOK_PRICE -}; - - -/****************************************************************************** - ******* structs / unions ***************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* extern functions ***************************************************** - ******************************************************************************/ -int proc_label (void); - - -/****************************************************************************** - ******* static inline functions (prototypes) ********************************* - ******************************************************************************/ - - -/****************************************************************************** - ******* static inline functions (definitions) ******************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -#endif /* vision-artificial/proc/label.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/inc/vision-artificial/proc/label.hpp b/inc/vision-artificial/proc/label.hpp deleted file mode 100644 index e4a2adf..0000000 --- a/inc/vision-artificial/proc/label.hpp +++ /dev/null @@ -1,74 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -#ifndef VA_PROC_LABEL_HPP -#define VA_PROC_LABEL_HPP - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ -enum Proc_Label { - LABEL_OK, - LABEL_NOK_LABEL, - LABEL_NOK_CERDO, - LABEL_NOK_BCODE, - LABEL_NOK_PRODUCT, - LABEL_NOK_PRICE -}; - - -/****************************************************************************** - ******* structs / unions ***************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* extern functions ***************************************************** - ******************************************************************************/ -extern "C" -{ -int proc_label (void); -} - - -/****************************************************************************** - ******* static inline functions (prototypes) ********************************* - ******************************************************************************/ - - -/****************************************************************************** - ******* static inline functions (definitions) ******************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -#endif /* vision-artificial/proc/label.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/inc/vision-artificial/proc/lighters.h b/inc/vision-artificial/proc/lighters.h deleted file mode 100644 index 1b6eea4..0000000 --- a/inc/vision-artificial/proc/lighters.h +++ /dev/null @@ -1,68 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -#ifndef VA_PROC_LIGHTERS_H -#define VA_PROC_LIGHTERS_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ -enum Proc_Lighter { - LIGHTER_OK, - LIGHTER_NOK_LIGHTER, - LIGHTER_NOK_SIZE -}; - - -/****************************************************************************** - ******* structs / unions ***************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* extern functions ***************************************************** - ******************************************************************************/ -int proc_lighter (void); - - -/****************************************************************************** - ******* static inline functions (prototypes) ********************************* - ******************************************************************************/ - - -/****************************************************************************** - ******* static inline functions (definitions) ******************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -#endif /* vision-artificial/proc/lighters.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/inc/vision-artificial/proc/lighters.hpp b/inc/vision-artificial/proc/lighters.hpp deleted file mode 100644 index daf3ac0..0000000 --- a/inc/vision-artificial/proc/lighters.hpp +++ /dev/null @@ -1,71 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -#ifndef VA_PROC_LIGHTERS_HPP -#define VA_PROC_LIGHTERS_HPP - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ -enum Proc_Lighter { - LIGHTER_OK, - LIGHTER_NOK_LIGHTER, - LIGHTER_NOK_SIZE -}; - - -/****************************************************************************** - ******* structs / unions ***************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* extern functions ***************************************************** - ******************************************************************************/ -extern "C" -{ -int proc_lighter (void); -} - - -/****************************************************************************** - ******* static inline functions (prototypes) ********************************* - ******************************************************************************/ - - -/****************************************************************************** - ******* static inline functions (definitions) ******************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -#endif /* vision-artificial/proc/lighters.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/inc/vision-artificial/proc/objects.h b/inc/vision-artificial/proc/objects.h deleted file mode 100644 index 32e57ff..0000000 --- a/inc/vision-artificial/proc/objects.h +++ /dev/null @@ -1,70 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -#ifndef VA_PROC_OBJECTS_H -#define VA_PROC_OBJECTS_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ -enum Proc_Objects { - OBJECTS_OK, - OBJECTS_NOK_PATTERN, - OBJECTS_NOK_OBJECTS, - OBJECTS_NOK_SIZE -}; - - -/****************************************************************************** - ******* structs / unions ***************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* extern functions ***************************************************** - ******************************************************************************/ -int proc_objects_calibrate (void); -int proc_objects (void); - - -/****************************************************************************** - ******* static inline functions (prototypes) ********************************* - ******************************************************************************/ - - -/****************************************************************************** - ******* static inline functions (definitions) ******************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -#endif /* vision-artificial/proc/objects.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/inc/vision-artificial/proc/objects.hpp b/inc/vision-artificial/proc/objects.hpp deleted file mode 100644 index 405ef82..0000000 --- a/inc/vision-artificial/proc/objects.hpp +++ /dev/null @@ -1,73 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -#ifndef VA_PROC_OBJECTS_HPP -#define VA_PROC_OBJECTS_HPP - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ -enum Proc_Objects { - OBJECTS_OK, - OBJECTS_NOK_PATTERN, - OBJECTS_NOK_OBJECTS, - OBJECTS_NOK_SIZE -}; - - -/****************************************************************************** - ******* structs / unions ***************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* extern functions ***************************************************** - ******************************************************************************/ -extern "C" -{ -int proc_objects_calibrate (void); -int proc_objects (void); -} - - -/****************************************************************************** - ******* static inline functions (prototypes) ********************************* - ******************************************************************************/ - - -/****************************************************************************** - ******* static inline functions (definitions) ******************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -#endif /* vision-artificial/proc/objects.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/inc/vision-artificial/proc/resistor.h b/inc/vision-artificial/proc/resistor.h deleted file mode 100644 index 51dd735..0000000 --- a/inc/vision-artificial/proc/resistor.h +++ /dev/null @@ -1,71 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -#ifndef VA_PROC_RESISTOR_H -#define VA_PROC_RESISTOR_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ -enum Proc_Resistor { - RESISTOR_OK, - RESISTOR_NOK_RESISTOR, - RESISTOR_NOK_BANDS, - RESISTOR_NOK_COLOR, - RESISTOR_NOK_STD_VALUE, - RESISTOR_NOK_TOLERANCE -}; - - -/****************************************************************************** - ******* structs / unions ***************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* extern functions ***************************************************** - ******************************************************************************/ -int proc_resistor (void); - - -/****************************************************************************** - ******* static inline functions (prototypes) ********************************* - ******************************************************************************/ - - -/****************************************************************************** - ******* static inline functions (definitions) ******************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -#endif /* vision-artificial/proc/resistor.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/inc/vision-artificial/proc/resistor.hpp b/inc/vision-artificial/proc/resistor.hpp deleted file mode 100644 index d69908e..0000000 --- a/inc/vision-artificial/proc/resistor.hpp +++ /dev/null @@ -1,74 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -#ifndef VA_PROC_RESISTOR_HPP -#define VA_PROC_RESISTOR_HPP - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ -enum Proc_Resistor { - RESISTOR_OK, - RESISTOR_NOK_RESISTOR, - RESISTOR_NOK_BANDS, - RESISTOR_NOK_COLOR, - RESISTOR_NOK_STD_VALUE, - RESISTOR_NOK_TOLERANCE -}; - - -/****************************************************************************** - ******* structs / unions ***************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* extern functions ***************************************************** - ******************************************************************************/ -extern "C" -{ -int proc_resistor (void); -} - - -/****************************************************************************** - ******* static inline functions (prototypes) ********************************* - ******************************************************************************/ - - -/****************************************************************************** - ******* static inline functions (definitions) ******************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -#endif /* vision-artificial/proc/resistor.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/src/image/iface.cpp b/src/image/iface.cpp index 3aeb799..87a4ffa 100644 --- a/src/image/iface.cpp +++ b/src/image/iface.cpp @@ -199,7 +199,7 @@ void img_iface_load (const char *fpath, const char *fname) if (!fname) user_iface_fname(fpath, file_name); else - snprintf(file_name, FILENAME_MAX, "%s", fname); + UNUSED(alx_sbprintf(file_name, NULL, "%s", fname)); errno = 0; load_image_file(path, file_name); diff --git a/src/menu/tui.c b/src/menu/tui.c index abe14e5..eefb6dd 100644 --- a/src/menu/tui.c +++ b/src/menu/tui.c @@ -22,7 +22,6 @@ #include "libalx/extra/ncurses/menu.h" #include "vision-artificial/ctrl/start.h" -#include "vision-artificial/proc/iface.h" #include "vision-artificial/save/save.h" #include "vision-artificial/share/share.h" #include "vision-artificial/user/iface.h" @@ -169,12 +168,10 @@ static void menu_continue (void) static void menu_devel (void) { static const struct Alx_Ncurses_Menu mnu[] = { - {5, 4, "[0] Back"}, - {2, 4, "[1] Change process mode"}, - {3, 4, "[2] Change log mode"} + {4, 4, "[0] Back"}, + {2, 4, "[1] Change log mode"} }; static const char *const txt[] = { - "Modes: 0=Auto; 1=Stop@prod; 2=Delay@step; 3=Stop@step", "Modes: 0=Results; 1=Operations; 2=All" }; WINDOW *win; @@ -204,13 +201,8 @@ static void menu_devel (void) wh = false; break; case 1: - proc_debug = alx_ncurses_get_int(PROC_DBG_NO, 0, - PROC_DBG_STOP_STEP, - w2, r2, txt[0], NULL, 2); - break; - case 2: user_iface_log.visible = alx_ncurses_get_u8(0, 2, 2, - w2, r2, txt[1], NULL, 2); + w2, r2, txt[0], NULL, 2); break; } } diff --git a/src/proc/common.cpp b/src/proc/common.cpp deleted file mode 100644 index bc2a602..0000000 --- a/src/proc/common.cpp +++ /dev/null @@ -1,359 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -#include "vision-artificial/proc/common.hpp" - -#include <cstddef> -#include <cstdio> -#include <ctime> - -#include <opencv2/core/core.hpp> - -#include "libalx/base/stdio/seekc.hpp" - -#include "vision-artificial/image/iface.hpp" -#include "vision-artificial/proc/iface.hpp" -#include "vision-artificial/user/iface.hpp" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* structs / unions ***************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ -/* Static --------------------------------------------------------------------*/ -static clock_t clock_0; -static clock_t clock_1; - - -/****************************************************************************** - ******* static functions (prototypes) **************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -void proc_apply (void) -{ - img_iface_act(IMG_IFACE_ACT_APPLY); -} - -void proc_save_mem (ptrdiff_t n) -{ - img_iface_act(IMG_IFACE_ACT_SAVE_MEM/*, (const void *)&n*/); -} - -void proc_load_mem (ptrdiff_t n) -{ - - img_iface_act(IMG_IFACE_ACT_LOAD_MEM/*, (const void *)&n*/); - - proc_show_img(); -} - -void proc_save_ref (void) -{ - img_iface_act(IMG_IFACE_ACT_SAVE_REF); -} - -void proc_save_file (void) -{ - img_iface_act(IMG_IFACE_ACT_SAVE_FILE); -} - -void proc_save_update (void) -{ - img_iface_act(IMG_IFACE_ACT_SAVE_UPDT); -} - -void proc_local_max (void) -{ - - img_iface_act(IMG_IFACE_ACT_LOCAL_MAX); - proc_show_img(); -} - -void proc_skeleton (void) -{ - - img_iface_act(IMG_IFACE_ACT_SKELETON); - proc_show_img(); -} - -void proc_lines_vertical (void) -{ - - img_iface_act(IMG_IFACE_ACT_LINES_VERTICAL); - proc_show_img(); -} - -void proc_median_horizontal (void) -{ - - img_iface_act(IMG_IFACE_ACT_MEDIAN_HORIZONTAL); - proc_show_img(); -} - -void proc_median_vertical (void) -{ - - img_iface_act(IMG_IFACE_ACT_MEDIAN_VERTICAL); - proc_show_img(); -} - -void proc_pixel_get (ptrdiff_t x, ptrdiff_t y, unsigned char *val) -{ - - img_iface_act(IMG_IFACE_ACT_PIXEL_GET/*, (const void *)&data*/); -} - -void proc_pixel_set (ptrdiff_t x, ptrdiff_t y, unsigned char val) -{ - - img_iface_act(IMG_IFACE_ACT_PIXEL_SET/*, (const void *)&data*/); - proc_show_img(); -} - -void proc_ROI (int x, int y, int w, int h) -{ - - img_iface_act(IMG_IFACE_ACT_SET_ROI/*, (const void *)&data*/); - proc_show_img(); -} - -void proc_and_2ref (void) -{ - - img_iface_act(USER_IFACE_ACT_AND_2REF); - proc_show_img(); -} - -void proc_not (void) -{ - - img_iface_act(USER_IFACE_ACT_NOT); - proc_show_img(); -} - -void proc_or_2ref (void) -{ - - img_iface_act(USER_IFACE_ACT_OR_2REF); - proc_show_img(); -} - -void proc_cmp (int cmp) -{ - - img_iface_act(IMG_IFACE_ACT_COMPONENT/*, (const void *)&data*/); - proc_show_img(); -} - -void proc_dilate (int size) -{ - - img_iface_act(IMG_IFACE_ACT_DILATE/*, (const void *)&data*/); - proc_show_img(); -} - -void proc_erode (int size) -{ - - img_iface_act(IMG_IFACE_ACT_ERODE/*, (const void *)&data*/); - proc_show_img(); -} - -void proc_dilate_erode (int size) -{ - - img_iface_act(IMG_IFACE_ACT_DILATE_ERODE/*, (const void *)&data*/); - proc_show_img(); -} - -void proc_erode_dilate (int size) -{ - - img_iface_act(IMG_IFACE_ACT_ERODE_DILATE/*, (const void *)&data*/); - proc_show_img(); -} - -void proc_smooth (int method, int ksize) -{ - - img_iface_act(IMG_IFACE_ACT_SMOOTH/*, (const void *)&data*/); - proc_show_img(); -} - -void proc_border (int size) -{ - - img_iface_act(IMG_IFACE_ACT_BORDER/*, (const void *)&data*/); - proc_show_img(); -} - -void proc_rotate (float center_x, float center_y, double angle) -{ - - img_iface_act(IMG_IFACE_ACT_ROTATE/*, (const void *)&data*/); - proc_show_img(); -} - -void proc_adaptive_threshold (int method, int type, int ksize) -{ - - img_iface_act(USER_IFACE_ACT_ADAPTIVE_THRESHOLD/*, (void *)&data*/); - proc_show_img(); -} - -void proc_cvt_color (int method) -{ - - img_iface_act(IMG_IFACE_ACT_CVT_COLOR/*, (const void *)&data*/); - proc_show_img(); -} - -void proc_threshold (int type, int size) -{ - - img_iface_act(IMG_IFACE_ACT_THRESHOLD/*, (const void *)&data*/); - proc_show_img(); -} - -void proc_distance_transform (void) -{ - - img_iface_act(IMG_IFACE_ACT_DISTANCE_TRANSFORM); - proc_show_img(); -} - -void proc_contours( - class std::vector <class std::vector <class cv::Point_<int>>> *contours, - class cv::Mat *hierarchy) -{ - - img_iface_act(IMG_IFACE_ACT_CONTOURS/*, (const void *)&data*/); - proc_show_img(); -} - -void proc_contours_size( - const class std::vector <class std::vector <class cv::Point_ <int>>> *contours, - double *area, - double *perimeter) -{ - - img_iface_act(IMG_IFACE_ACT_CONTOURS_SIZE/*, (const void *)&data*/); -} - -void proc_bounding_rect( - const class std::vector <class cv::Point_ <int>> *contour, - class cv::Rect_ <int> *rect, - bool show) -{ - - img_iface_act(IMG_IFACE_ACT_BOUNDING_RECT/*, (const void *)&data*/); - if (show) - proc_show_img(); -} - -void proc_fit_ellipse ( - const class std::vector <class cv::Point_ <int>> *contour, - class cv::RotatedRect *rect, - bool show -) -{ - - img_iface_act(IMG_IFACE_ACT_FIT_ELLIPSE/*, (const void *)&data*/); - if (show) - proc_show_img(); -} - -void proc_min_area_rect ( - const class std::vector <class cv::Point_ <int>> *contour, - class cv::RotatedRect *rect, - bool show -) -{ - - img_iface_act(IMG_IFACE_ACT_MIN_AREA_RECT/*, (const 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/*, (const void *)&data*/); -} - -void proc_zbar (int type) -{ - struct Img_Iface_Data_Decode data; - - data = (struct Img_Iface_Data_Decode){ - .code_type = type, - }; - img_iface_act(IMG_IFACE_ACT_DECODE/*, (const void *)&data*/); -} - -void proc_show_img (void) -{ - - if (proc_debug < PROC_DBG_DELAY_STEP) - return; - img_iface_show_img(); - if (proc_debug >= PROC_DBG_STOP_STEP) - alx_wait4enter(); -} - -void clock_start (void) -{ - clock_0 = clock(); -} - -void clock_stop (const char *txt) -{ - clock_t clock_diff; - double time_diff; - char tmp[LOG_LINE_LEN]; - - clock_1 = clock(); - clock_diff = clock_1 - clock_0; - time_diff = (double)clock_diff / (double)CLOCKS_PER_SEC; - - snprintf(tmp, LOG_LINE_LEN, "Time: %.3lf (%s)", time_diff, txt); - user_iface_log_write(0, tmp); -} - - -/****************************************************************************** - ******* static functions (definitions) *************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/src/proc/iface.c b/src/proc/iface.c deleted file mode 100644 index 0b28691..0000000 --- a/src/proc/iface.c +++ /dev/null @@ -1,212 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -#include "vision-artificial/proc/iface.h" - -#include <errno.h> -#include <stdbool.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> - -#include "libalx/base/compiler/size.h" -#include "libalx/base/stdio/sscan.h" -#include "libalx/base/stdio/seekc.h" - -#include "vision-artificial/image/iface.h" -#include "vision-artificial/proc/common.h" -#include "vision-artificial/proc/label.h" -#include "vision-artificial/proc/lighters.h" -#include "vision-artificial/proc/objects.h" -#include "vision-artificial/proc/resistor.h" -#include "vision-artificial/save/save.h" -#include "vision-artificial/user/iface.h" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* structs / unions ***************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ - int proc_debug; - int proc_mode; -/* Static --------------------------------------------------------------------*/ -static char proc_path [FILENAME_MAX]; -static char proc_fail_path [FILENAME_MAX]; - - -/****************************************************************************** - ******* static functions (prototypes) **************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -int proc_iface_single (int action) -{ - int error; - clock_t time_0; - clock_t time_1; - double time_tot; - char txt[LOG_LINE_LEN]; - - time_0 = clock(); - - 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_RESISTOR_SERIES: - error = proc_resistor(); - break; - case PROC_MODE_LIGHTERS_SERIES: - error = proc_lighter(); - break; - default: - error = -1; - } - - time_1 = clock(); - time_tot = ((double) time_1 - time_0) / CLOCKS_PER_SEC; - snprintf(txt, LOG_LINE_LEN, "Item total time: %.3lf", time_tot); - user_iface_log_write(0, txt); - - return error; -} - -void proc_iface_series (void) -{ - int num_len; - char file_basename[FILENAME_MAX]; - char file_ext[FILENAME_MAX]; - char file_name[FILENAME_MAX]; - char save_error_as[FILENAME_MAX]; - /* if i starts being 0, the camera needs calibration */ - int i; - char txt[LOG_LINE_LEN]; - char tmp[FILENAME_MAX]; - - 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, FILENAME_MAX, "b"); - num_len = 4; - snprintf(file_ext, FILENAME_MAX, ".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, FILENAME_MAX, "o"); - num_len = 4; - snprintf(file_ext, FILENAME_MAX, ".jpeg"); - i = 0; - proc_mode++; - 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, FILENAME_MAX, "r"); - num_len = 4; - snprintf(file_ext, FILENAME_MAX, ".png"); - i = 1; - break; - case PROC_MODE_LIGHTERS_SERIES: - snprintf(proc_path, FILENAME_MAX, "%s", lighters_path); - snprintf(proc_fail_path, FILENAME_MAX, "%s",lighters_fail_path); - snprintf(file_basename, FILENAME_MAX, "lighters"); - num_len = 4; - snprintf(file_ext, FILENAME_MAX, ".png"); - i = 1; - break; - default: - return; - } - - for (;; i++) { - if (snprintf(file_name, FILENAME_MAX, "%s%04i%s", - file_basename, - i, file_ext) >= FILENAME_MAX) { - goto err_path; - } - - memcpy(tmp, file_name, ARRAY_SIZE(file_name)); - if (alx_sscan_fname(proc_path, file_name, true, tmp)) - break; - - errno = 0; - img_iface_load(proc_path, file_name); - - if (errno) { - printf("errno:%i\n", errno); - goto err_load; - } - - /* Process */ - if (proc_iface_single(proc_mode)) { - /* Save failed image into file */ - proc_show_img(); - if (snprintf(save_error_as, FILENAME_MAX,"%s%0*i_err%s", - file_basename, num_len, i, - file_ext) >= FILENAME_MAX) { - goto err_path; - } - save_image_file(proc_fail_path, save_error_as); - } - - /* Show log */ - snprintf(txt, LOG_LINE_LEN, "%04i", i); - user_iface_show_log(txt, "Item"); - - if (proc_debug >= PROC_DBG_STOP_ITEM) - alx_wait4enter(); -err_load: - if (!i) - proc_mode--; - } - - return; - -err_path: - printf("Path is too large and has been truncated\n"); - exit(EXIT_FAILURE); -} - - -/****************************************************************************** - ******* static functions (definitions) *************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/src/proc/label.cpp b/src/proc/label.cpp deleted file mode 100644 index f6698c6..0000000 --- a/src/proc/label.cpp +++ /dev/null @@ -1,296 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -#include "vision-artificial/proc/label.hpp" - -#include <cstdio> -#include <cstring> - -#include <opencv2/core/core.hpp> -#include <opencv2/imgproc/imgproc.hpp> -#include <zbar.h> - -#include "libalx/base/stdlib/swap.hpp" - -#include "vision-artificial/image/iface.hpp" -#include "vision-artificial/proc/common.hpp" -#include "vision-artificial/user/iface.hpp" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* structs / unions ***************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* 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 (prototypes) **************************************** - ******************************************************************************/ -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) */ - clock_start(); - status = label_find(); - if (status) { - result_label(status); - return status; - } - clock_stop("Find label"); - - /* Align label and extract green component */ - clock_start(); - label_align(); - clock_stop("Align label"); - - /* Find "Cerdo" in aligned image */ - clock_start(); - status = find_cerdo(); - if (status) { - result_label(status); - return status; - } - clock_stop("Find cerdo (OCR)"); - - /* Read barcode in original image */ - clock_start(); - status = barcode_read(); - if (status) { - result_label(status); - return status; - } - clock_stop("Read barcode (zbar)"); - - /* Check product code in barcode */ - clock_start(); - status = barcode_chk_prod(); - if (status) { - result_label(status); - return status; - } - clock_stop("Chk product code"); - - /* Read price in aligned image (green component) */ - clock_start(); - price_read(); - clock_stop("Read price (OCR)"); - - /* Check label price with barcode price */ - clock_start(); - status = price_chk(); - if (status) { - result_label(status); - return status; - } - clock_stop("Check price"); - - result_label(LABEL_OK); - return 0; -} - - -/****************************************************************************** - ******* static functions (definitions) *************************************** - ******************************************************************************/ -static void result_label (int status) -{ - - switch (status) { - case LABEL_OK: - user_iface_log_write(0, "Label: OK"); - break; - case LABEL_NOK_LABEL: - user_iface_log_write(0, "Label: NOK_LABEL"); - break; - case LABEL_NOK_CERDO: - user_iface_log_write(0, "Label: NOK_CERDO"); - break; - case LABEL_NOK_BCODE: - user_iface_log_write(0, "Label: NOK_BCODE"); - break; - case LABEL_NOK_PRODUCT: - user_iface_log_write(0, "Label: NOK_PRODUCT"); - break; - case LABEL_NOK_PRICE: - user_iface_log_write(0, "Label: NOK_PRICE"); - break; - default: - user_iface_log_write(0, "Label: NOK"); - break; - } -} - -static int label_find (void) -{ - - 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 (!contours.size()) - return LABEL_NOK_LABEL; - - 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; - ALX_SWAP(&rect.size.width, &rect.size.height); - } - - return 0; -} - -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 x, y; - int w, h; - - 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); - - if (strncmp(img_ocr_text, "Cerdo", strlen("Cerdo"))) - return LABEL_NOK_CERDO; - return 0; -} - -static int barcode_read (void) -{ - - proc_load_mem(0); - - proc_cmp(IMG_IFACE_CMP_GREEN); - proc_zbar(zbar::ZBAR_EAN13); - if (zb_codes.n != 1) - return LABEL_NOK_BCODE; - return 0; -} - -static int barcode_chk_prod(void) -{ - - if (strncmp(zb_codes.arr[0].data, "2301703", strlen("2301703"))) - return LABEL_NOK_PRODUCT; - return LABEL_OK; -} - -static void price_read (void) -{ - int x, y; - int w, 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) -{ - char price[80]; - - /* 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 */ - if (strncmp(img_ocr_text, price, strlen(price))) - return LABEL_NOK_PRICE; - return 0; -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/src/proc/lighters.cpp b/src/proc/lighters.cpp deleted file mode 100644 index 40a7113..0000000 --- a/src/proc/lighters.cpp +++ /dev/null @@ -1,427 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -#include "vision-artificial/proc/lighters.hpp" - -#include <cstddef> -#include <cstdio> - -#include <opencv2/core/core.hpp> -#include <opencv2/imgproc/imgproc.hpp> - -#include "libalx/base/stdlib/swap.hpp" - -#include "vision-artificial/image/iface.hpp" -#include "vision-artificial/proc/common.hpp" -#include "vision-artificial/user/iface.hpp" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ -enum Lighter_Hood { - HOOD_OK, - HOOD_NOT_PRESENT, - HOOD_NOT_OK -}; - - -/****************************************************************************** - ******* structs / unions ***************************************************** - ******************************************************************************/ -struct Lighter_Point { - uint16_t x; - uint16_t y; -}; - -struct Size { - uint16_t h; - uint16_t w; -}; - -struct Lighter_Properties { - struct Lighter_Point pos; - struct Size size; - double angle; - - bool fork; - bool valve; - int hood_; - bool hood; - bool wheel; - - bool ok; -}; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ -/* Static --------------------------------------------------------------------*/ -static class std::vector <class std::vector <class cv::Point_ <int>>> contours_all; -static class std::vector <class std::vector <class cv::Point_ <int>>> contours_one; -static class cv::Mat hierarchy; -static class cv::RotatedRect rect_rot[CONTOURS_MAX]; -static class cv::Rect_ <int> rect; -static struct Lighter_Properties lighter[CONTOURS_MAX]; -static ptrdiff_t lighters_n; - - -/****************************************************************************** - ******* static functions (prototypes) **************************************** - ******************************************************************************/ -static void result_lighter (int status); - -static void lighters_bgr2gray (void); -static void lighters_segment_full (void); -static int lighters_find (void); -static void lighter_segment_body (int i); -static void lighter_rm_body (int i); -static void lighter_crop_head (int i); -static void lighter_chk_hood (int i); -static void lighter_rm_hood (void); -static void lighter_chk_fork (int i); -static void lighter_chk_wheel (int i); -static void lighter_chk_valve (int i); -static void lighters_log (void); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -int proc_lighter (void) -{ - - proc_save_mem(0); - /* Segment lighters */ - clock_start(); - lighters_bgr2gray(); - lighters_segment_full(); - lighters_find(); - clock_stop("Segment lighters"); - - /* Check each lighter */ - for (ptrdiff_t i = 0; i < lighters_n; i++) { - clock_start(); - lighter[i].ok = true; - lighter_segment_body(i); - lighter_rm_body(i); - lighter_crop_head(i); - lighter_chk_hood(i); - if (lighter[i].hood_ != HOOD_NOT_PRESENT) { - lighter_rm_hood(); - } else { - proc_load_mem(7); - proc_save_mem(8); - } - lighter_chk_fork(i); - lighter_chk_wheel(i); - lighter_chk_valve(i); - clock_stop("Check parts"); - } - - /* Print results of lighters into log */ - clock_start(); - lighters_log(); - clock_stop("Lighters properties (log)"); - - result_lighter(LIGHTER_OK); - return 0; -} - - -/****************************************************************************** - ******* static functions (definitions) *************************************** - ******************************************************************************/ -static void result_lighter (int status) -{ - - switch (status) { - case LIGHTER_OK: - user_iface_log_write(0, "Coin: OK"); - break; - case LIGHTER_NOK_LIGHTER: - user_iface_log_write(0, "Coin: NOK_LIGHTER"); - break; - - case LIGHTER_NOK_SIZE: - user_iface_log_write(0, "Coin: NOK_SIZE"); - break; - default: - user_iface_log_write(0, "Coin: NOK"); - } -} - -/* process -------------------------------------------------------------------*/ -static void lighters_bgr2gray (void) -{ - - proc_load_mem(0); - - proc_cvt_color(cv::COLOR_BGR2GRAY); - proc_not(); - proc_save_mem(1); - - proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); - proc_border(100); - proc_save_mem(3); - - proc_load_mem(1); - proc_border(100); - proc_save_mem(2); -} - -static void lighters_segment_full (void) -{ - - proc_load_mem(3); - proc_erode_dilate(1); - proc_dilate_erode(2); - proc_save_mem(4); -} - -static int lighters_find (void) -{ - - proc_load_mem(4); - proc_contours(&contours_all, &hierarchy); - lighters_n = contours_all.size(); - if (!lighters_n) - return LIGHTER_NOK_LIGHTER; - - for (ptrdiff_t i = 0; i < lighters_n; i++) { - proc_min_area_rect(&contours_all[i], &rect_rot[i], true); - /* If width > height, - * it is taking into acount the incorrect side */ - if (rect_rot[i].size.width > rect_rot[i].size.height) { - rect_rot[i].angle += 90.0; - ALX_SWAP(&rect_rot[i].size.width, - &rect_rot[i].size.height); - } - lighter[i].pos.x = rect_rot[i].center.x; - lighter[i].pos.y = rect_rot[i].center.y; - lighter[i].angle = -rect_rot[i].angle; - lighter[i].size.h = rect_rot[i].size.height; - lighter[i].size.w = rect_rot[i].size.width; - } - - return 0; -} - -static void lighter_segment_body (int i) -{ - int x, y; - int w, h; - - proc_load_mem(2); - - proc_rotate(lighter[i].pos.x, lighter[i].pos.y, -lighter[i].angle); - w = lighter[i].size.w * 1.25; - h = lighter[i].size.h * 1.25; - x = lighter[i].pos.x - (w / 2.0); - y = lighter[i].pos.y - (h / 2.0); - proc_ROI(x, y, w, h); - proc_threshold(cv::THRESH_BINARY, UINT8_MAX - 165); - - proc_erode_dilate(1); - proc_dilate_erode(1); - proc_erode_dilate(lighter[i].size.w * 0.43); - proc_save_mem(5); - - proc_contours(&contours_one, &hierarchy); - proc_bounding_rect(&contours_one[0], &rect, true); -} - -static void lighter_rm_body (int i) -{ - int x, y; - int w, h; - - proc_load_mem(5); - proc_not(); - proc_erode(5); - proc_save_ref(); - - proc_load_mem(3); - proc_rotate(lighter[i].pos.x, lighter[i].pos.y, -lighter[i].angle); - w = lighter[i].size.w * 1.25; - h = lighter[i].size.h * 1.25; - x = lighter[i].pos.x - (w / 2.0); - y = lighter[i].pos.y - (h / 2.0); - proc_ROI(x, y, w, h); - proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); - proc_and_2ref(); - proc_save_mem(6); -} - -static void lighter_crop_head (int i) -{ - int x, y; - int w, h; - - proc_load_mem(6); - - w = rect.width * 1.15; - h = rect.width * 0.65; - x = rect.x - rect.width * 0.075; - y = rect.y - rect.width * 0.65; - proc_ROI(x, y, w, h); - rect.x = x; - rect.y = y; - rect.width = w; - rect.height = h; - lighter[i].size.w = w; - lighter[i].size.h = h; - proc_save_mem(7); -} - -static void lighter_chk_hood (int i) -{ - uint8_t val1; - uint8_t val2; - proc_load_mem(7); - - proc_pixel_get(rect.width * 0.2, rect.height * 0.3, &val1); - proc_pixel_set(rect.width * 0.2, rect.height * 0.3, UINT8_MAX / 2); - proc_save_mem(9); - - if (val1) { - proc_pixel_get(rect.width *0.2, rect.height *0.8, &val2); - proc_pixel_set(rect.width *0.2, rect.height *0.8, UINT8_MAX /2); - if (val2) { - lighter[i].hood_ = HOOD_OK; - lighter[i].hood = true; - } else { - lighter[i].hood_ = HOOD_NOT_OK; - lighter[i].hood = false; - lighter[i].ok = false; - } - } else { - lighter[i].hood_ = HOOD_NOT_PRESENT; - lighter[i].hood = false; - lighter[i].ok = false; - } -} - -static void lighter_rm_hood (void) -{ - - proc_load_mem(7); - proc_border(2); - proc_save_ref(); - - proc_dilate_erode(2); - proc_erode_dilate(rect.height * 0.25); - proc_dilate(2); - proc_not(); - proc_and_2ref(); - proc_save_mem(8); -} - -static void lighter_chk_fork (int i) -{ - uint8_t val; - - proc_load_mem(8); - - proc_dilate_erode(2); - proc_pixel_get(rect.width * 0.8, rect.height * 0.8, &val); - proc_pixel_set(rect.width * 0.8, rect.height * 0.8, UINT8_MAX / 2); - proc_save_mem(10); - - if (val) { - lighter[i].fork = true; - } else { - lighter[i].fork = false; - lighter[i].ok = false; - } -} - -static void lighter_chk_wheel (int i) -{ - uint8_t val; - - proc_load_mem(8); - - proc_dilate(5); - proc_pixel_get(rect.width * 0.58, rect.height * 0.19, &val); - proc_pixel_set(rect.width * 0.58, rect.height * 0.19, UINT8_MAX / 2); - proc_save_mem(11); - - if (val) { - lighter[i].wheel = true; - } else { - lighter[i].wheel = false; - lighter[i].ok = false; - } -} - -static void lighter_chk_valve (int i) -{ - uint8_t val; - - proc_load_mem(8); - - if (lighter[i].hood_ == HOOD_NOT_PRESENT) - proc_dilate(5); - else - proc_dilate(10); - proc_pixel_get(rect.width * 0.07, rect.height * 0.92, &val); - proc_pixel_set(rect.width * 0.07, rect.height * 0.92, UINT8_MAX / 2); - proc_save_mem(12); - - if (val) { - lighter[i].valve = true; - } else { - lighter[i].valve = false; - lighter[i].ok = false; - } -} - -static void lighters_log (void) -{ - char txt[LOG_LINE_LEN]; - - for (ptrdiff_t i = 0; i < lighters_n; i++) { - snprintf(txt, LOG_LINE_LEN, "Lighter[%ti]:", i); - user_iface_log_write(0, txt); - snprintf(txt, LOG_LINE_LEN, " pos: (%i, %i) pix", - lighter[i].pos.x, lighter[i].pos.y); - user_iface_log_write(0, txt); - snprintf(txt, LOG_LINE_LEN, " ang = %.1lf DEG", - lighter[i].angle); - user_iface_log_write(0, txt); - snprintf(txt, LOG_LINE_LEN, " hood = %s", - lighter[i].hood ? "ok" : "nok"); - user_iface_log_write(0, txt); - snprintf(txt, LOG_LINE_LEN, " fork = %s", - lighter[i].fork ? "ok" : "nok"); - user_iface_log_write(0, txt); - snprintf(txt, LOG_LINE_LEN, " wheel = %s", - lighter[i].wheel ? "ok" : "nok"); - user_iface_log_write(0, txt); - snprintf(txt, LOG_LINE_LEN, " valve = %s", - lighter[i].valve ? "ok" : "nok"); - user_iface_log_write(0, txt); - snprintf(txt, LOG_LINE_LEN, " RESULT = %s", - lighter[i].ok ? "OK" : "NOK"); - user_iface_log_write(0, txt); - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/src/proc/objects.cpp b/src/proc/objects.cpp deleted file mode 100644 index c160fc0..0000000 --- a/src/proc/objects.cpp +++ /dev/null @@ -1,551 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -#include "vision-artificial/proc/objects.hpp" - -#include <cstddef> -#include <cstdio> - -#include <opencv2/core/core.hpp> -#include <opencv2/imgproc/imgproc.hpp> - -#include "libalx/extra/gsl/rstat/median.hpp" - -#include "vision-artificial/image/iface.hpp" -#include "vision-artificial/proc/common.hpp" -#include "vision-artificial/user/iface.hpp" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ -#define OBJECTS_MAX (0xFFF) -#define PATTERN_SQUARE_LEN_MM (10.0) - -#define PATTERN_DILATE (2) - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* structs / unions ***************************************************** - ******************************************************************************/ -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 { - struct Point center; - struct Point origin; - - double angle; - - uint16_t height; - uint16_t width; - - /* Squares (distance calibration) */ - struct Pattern_Square square[OBJECTS_MAX]; -}; - -struct Objects_Properties { - struct Point pos; - - double angle; - - double area_pix2; - double area_mm2; - double perimeter_pix; - double perimeter_mm; - - 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 ptrdiff_t squares_n; -static double ratio_mm_pix; -static ptrdiff_t objects_n; -static struct Objects_Properties objects[OBJECTS_MAX]; - - -/****************************************************************************** - ******* static functions (prototypes) **************************************** - ******************************************************************************/ -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 */ - clock_start(); - pattern_bgr2gray(); - status = pattern_find(); - if (status) { - result_objects(status); - return status; - } - pattern_rotation_get(); - pattern_rotation_fix(); - clock_stop("Calibrate: rotation"); - - /* Segmentate pattern squares */ - clock_start(); - pattern_dimensions_get(); - pattern_dimensions_fix(); - clock_stop("Calibrate: dimensions"); - - /* Find squares */ - clock_start(); - pattern_squares_find(); - pattern_squares_pos_get(); - pattern_squares_len_get(); - pattern_calib_mm_pix(); - clock_stop("Calibrate (mm per pix)"); - - result_objects(OBJECTS_OK); - return 0; -} - -int proc_objects (void) -{ - int status; - - proc_save_mem(0); - /* Align image */ - clock_start(); - objects_bgr2gray(); - objects_rotation_fix(); - objects_dimensions_fix(); - clock_stop("Align image to pattern"); - - /* Segment objects */ - clock_start(); - objects_segment(); - clock_stop("Segment objects"); - - /* Find objects positions */ - clock_start(); - status = objects_contours(); - if (status) { - result_objects(status); - return status; - } - clock_stop("Find objects"); - - /* Get objects properties in pixels */ - clock_start(); - objects_position_pix(); - objects_position_mm(); - clock_stop("Objects positions"); - - /* Get objects properties in mm */ - clock_start(); - objects_size_pix(); - objects_size_mm(); - clock_stop("Objects sizes"); - - /* Get objects properties in mm */ - clock_start(); - objects_shape(); - clock_stop("Objects shapes"); - - /* Print properties of objects into log */ - clock_start(); - objects_log(); - clock_stop("Objects properties (log)"); - - result_objects(OBJECTS_OK); - return 0; -} - - -/****************************************************************************** - ******* static functions (definitions) *************************************** - ******************************************************************************/ -static void result_objects (int status) -{ - - switch (status) { - case OBJECTS_OK: - user_iface_log_write(0, "Coin: OK"); - break; - case OBJECTS_NOK_OBJECTS: - user_iface_log_write(0, "Coin: NOK_OBJECTS"); - break; - - case OBJECTS_NOK_SIZE: - user_iface_log_write(0, "Coin: NOK_SIZE"); - break; - default: - user_iface_log_write(0, "Coin: NOK"); - } -} - -/* 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) -{ - - 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 (contours.size() != 1) - return OBJECTS_NOK_PATTERN; - - return 0; -} - -static void pattern_rotation_get (void) -{ - char txt[LOG_LINE_LEN]; - - 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; - - snprintf(txt, LOG_LINE_LEN, "pattern angle = %lf DEG", - -pattern.angle); - user_iface_log_write(0, txt); - snprintf(txt, LOG_LINE_LEN, "pattern center (x) = %i pix", - pattern.center.x_pix); - user_iface_log_write(0, txt); - snprintf(txt, LOG_LINE_LEN, "pattern center (y) = %i pix", - pattern.center.y_pix); - user_iface_log_write(0, txt); -} - -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) -{ - - for (ptrdiff_t 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) -{ - - proc_load_mem(4); - for (ptrdiff_t 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) -{ - uint8_t pattern_len[OBJECTS_MAX]; - uint8_t median_size; - char txt[LOG_LINE_LEN]; - - for (ptrdiff_t i = 0; i < squares_n; i++) - pattern_len[i] = pattern.square[i].len; - median_size = alx_gsl_rstat_median_u8(squares_n, pattern_len); - ratio_mm_pix = PATTERN_SQUARE_LEN_MM / median_size; - - snprintf(txt, LOG_LINE_LEN, "mm/pix = %lf", ratio_mm_pix); - user_iface_log_write(0, txt); -} - -/* 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) -{ - - proc_load_mem(6); - - proc_contours(&contours, &hierarchy); - objects_n = contours.size(); - if (!objects_n) - return OBJECTS_NOK_OBJECTS; - - return 0; -} - -static void objects_position_pix (void) -{ - - for (ptrdiff_t 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) -{ - - for (ptrdiff_t 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]; - - proc_contours_size(&contours, area, perimeter); - for (ptrdiff_t i = 0; i < objects_n; i++) { - objects[i].area_pix2 = area[i]; - objects[i].perimeter_pix = perimeter[i]; - } -} - -static void objects_size_mm (void) -{ - - for (ptrdiff_t 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) -{ - - for (ptrdiff_t 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) -{ - char txt[LOG_LINE_LEN]; - - for (ptrdiff_t i = 0; i < objects_n; i++) { - snprintf(txt, LOG_LINE_LEN, "Object[%ti]:", i); - user_iface_log_write(0, txt); - snprintf(txt, LOG_LINE_LEN, " pos: (%.1lf, %.1lf) mm", - objects[i].pos.x_mm, - objects[i].pos.y_mm); - user_iface_log_write(0, txt); - snprintf(txt, LOG_LINE_LEN, " ang = %.1lf DEG", - objects[i].angle); - user_iface_log_write(0, txt); - snprintf(txt, LOG_LINE_LEN, " A = %.1lf mm2", - objects[i].area_mm2); - user_iface_log_write(0, txt); - snprintf(txt, LOG_LINE_LEN, " P = %.1lf mm", - objects[i].perimeter_mm); - user_iface_log_write(0, txt); - snprintf(txt, LOG_LINE_LEN, " p2/A = %.2lf", - objects[i].ratio_p2_a); - user_iface_log_write(0, txt); - snprintf(txt, LOG_LINE_LEN, " p/p_r = %.2lf", - objects[i].ratio_p_prect); - user_iface_log_write(0, txt); - snprintf(txt, LOG_LINE_LEN, " A/A_r = %.2lf", - objects[i].ratio_a_arect); - user_iface_log_write(0, txt); - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/src/proc/resistor.cpp b/src/proc/resistor.cpp deleted file mode 100644 index 0f60b17..0000000 --- a/src/proc/resistor.cpp +++ /dev/null @@ -1,1280 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -#include "vision-artificial/proc/resistor.hpp" - -#include <cmath> -#include <cstdio> -#include <cstring> - -#include <opencv2/core/core.hpp> -#include <opencv2/imgproc/imgproc.hpp> - -#include "libalx/base/compiler/size.hpp" - -#include "vision-artificial/image/iface.hpp" -#include "vision-artificial/proc/common.hpp" -#include "vision-artificial/user/iface.hpp" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* structs / unions ***************************************************** - ******************************************************************************/ -struct Resistor_Bands { - int x; - int y; - - 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 (prototypes) **************************************** - ******************************************************************************/ -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 void log_resistance (void); -static int chk_std_value (void); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -int proc_resistor (void) -{ - int status; - - proc_save_mem(0); - /* Find resistor (position and angle) */ - clock_start(); - status = resistor_find(); - if (status) { - result_resistor(status); - return status; - } - clock_stop("Find resistor"); - - /* Align resistor, find its dimensions, and crop */ - clock_start(); - resistor_align(); - resistor_dimensions_0(); - resistor_crop_0(); - clock_stop("Align, dimensions, & crop"); - - /* Find backgroung color */ - clock_start(); - resistor_bkgd(); - clock_stop("Background color"); - - /* Crop more */ - clock_start(); - resistor_dimensions_1(); - resistor_crop_1(); - clock_stop("Crop more"); - - /* Separate background (BK) and lines (WH) */ - clock_start(); - separate_bkgd_bands_h(); - separate_bkgd_bands_s(); - separate_bkgd_bands_v(); - bkgd_find(); - clock_stop("Separate bkgd from bands"); - - /* Find bands: contours -> rectangles */ - clock_start(); - status = bands_find(); - if (status) { - result_resistor(status); - return status; - } - clock_stop("Find bands"); - - /* Read values on the center of each band */ - clock_start(); - bands_colors(); - clock_stop("Bands' colors"); - - /* Interpret colors */ - clock_start(); - bands_code(); - bands_code_deduce_0(); - bands_code_deduce_1(); - status = bands_code_deduce_no(); - if (status) { - result_resistor(status); - return status; - } - clock_stop("Interpret colors"); - - /* Calculate resistor value & tolerance */ - clock_start(); - resistor_value(); - status = resistor_tolerance(); - if (status) { - result_resistor(status); - return status; - } - log_resistance(); - clock_stop("Calculate resistance & tolerance"); - - /* Check STD value */ - clock_start(); - status = chk_std_value(); - if (status) { - result_resistor(status); - return status; - } - clock_stop("Chk STD values"); - - result_resistor(status); - return 0; -} - - -/****************************************************************************** - ******* static functions (definitions) *************************************** - ******************************************************************************/ -static void result_resistor (int status) -{ - - switch (status) { - case RESISTOR_OK: - user_iface_log_write(0, "Resistor: OK"); - break; - case RESISTOR_NOK_RESISTOR: - user_iface_log_write(0, "Resistor: NOK_RESISTOR"); - break; - case RESISTOR_NOK_BANDS: - user_iface_log_write(0, "Resistor: NOK_BANDS"); - break; - case RESISTOR_NOK_COLOR: - user_iface_log_write(0, "Resistor: NOK_COLOR"); - break; - case RESISTOR_NOK_STD_VALUE: - user_iface_log_write(0, "Resistor: NOK_STD_VALUE"); - break; - case RESISTOR_NOK_TOLERANCE: - user_iface_log_write(0, "Resistor: NOK_TOLERANCE"); - break; - default: - user_iface_log_write(0, "Resistor: NOK"); - break; - } -} - -static int resistor_find (void) -{ - - 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 (!contours.size()) - return RESISTOR_NOK_RESISTOR; - - 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; - - return 0; -} - -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, y; - int w, 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)) - bkgd = 1; /* Teal blue */ - else if (bkgd_hue >= 105) - bkgd = 2; /* Dark blue */ - else - bkgd = 3; /* Normal blue */ - } -} - -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) -{ - - proc_load_mem(8); - - proc_contours(&contours, &hierarchy); - bands_n = contours.size(); - if (bands_n > 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)) - return RESISTOR_NOK_BANDS; - - /* 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; - } - - return 0; -} - -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) -{ - char txt[LOG_LINE_LEN]; - - memset(code, 0, ARRAY_SIZE(code)); - - /* 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'; - - snprintf(txt, LOG_LINE_LEN, "Code: \"%s\"", code); - user_iface_log_write(0, txt); -} - -static char band_hsv2code (struct Resistor_Bands *band) -{ - char c; - - /* - * 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) - c = '1'; - else - c = '3'; - } else if (band->s < 140) { - // 1 2 3 - if (band->v < 60) - c = '1'; - else if (band->v < 85) - c = 'q'; // 1 2 - else if (band->v < 90) - c = '2'; - else if (band->v < 150) - c = 'w'; // 2 3 - else - c = '3'; - } else if (band->s < 210) { - // 2 3 - if (band->v < 90) - c = '2'; - else if (band->v < 150) - c = 'w'; // 2 3 - else - c = '3'; - } else { - c = '3'; - } - } else if (band->h < 35) { - // 1 3 g - if (band->s < 130) { - // 1 3 - if (band->v < 85) - c = '1'; - else - c = '3'; - } else if (band->s < 140) { - // 1 3 g - if (band->v < 85) - c = '1'; - else if (band->v < 120) - c = '3'; - else - c = 'e'; // 3 g - } else if (band->s < 180) { - // 3 g - if (band->v < 120) - c = '3'; - else - c = 'e'; // 3 g - } else { - c = '3'; - } - } else if (band->h < 50) { - // 1 3 - if (band->s < 140) { - // 1 3 - if (band->v < 85) - c = '1'; - else - c = '3'; - } else { - c = '3'; - } - } else if (band->h < 60) { - // 1 3 4 - if (band->s < 140) { - // 1 3 - if (band->v < 85) - c = '1'; - else - c = '3'; - } else if (band->s < 160) { - c = '3'; - } else if (band->s < 180) { - // 3 4 - if (band->v < 110) - c = 'r'; // 3 4 - else - c = '3'; - } else { - c = '3'; - } - } else if (band->h < 80) { - // 1 5 - if (band->s < 165) - c = '1'; - else - c = '5'; - } else if (band->h < 90) { - c = '1'; - } else if (band->h < 100) { - // 0 1 8 9 - if (band->s < 40) { - // 1 8 9 - if (band->v < 55) - c = '1'; - else if (band->v < 80) - c = 't'; // 1 8 - else if (band->v < 125) - c = '1'; - else - c = '9'; - } else if (band->s < 70) { - // 0 1 8 9 - if (band->v < 45) - c = '0'; - else if (band->v < 55) - c = 'y'; // 0 1 - else if (band->v < 75) - c = 'u'; // 0 1 8 - else if (band->v < 80) - c = 't'; // 1 8 - else if (band->v < 125) - c = '1'; - else - c = '9'; - } else if (band->s < 100) { - // 0 1 8 - if (band->v < 45) - c = '0'; - else if (band->v < 55) - c = 'y'; // 0 1 - else if (band->v < 75) - c = 'u'; // 0 1 8 - else if (band->v < 80) - c = 't'; // 1 8 - else - c = '1'; - } else if (band->s < 140) { - // 0 1 - if (band->v < 45) - c = '0'; - else if (band->v < 75) - c = 'y'; // 0 1 - else - c = '1'; - } else { - c = '0'; - } - } else if (band->h < 110) { - // 0 1 6 8 - if (band->s < 40) { - // 1 8 - if (band->v < 55) - c = '1'; - else if (band->v < 80) - c = 't'; // 1 8 - else - c = '1'; - } else if (band->s < 100) { - // 0 1 8 - if (band->v < 45) - c = '0'; - else if (band->v < 55) - c = 'y'; // 0 1 - else if (band->v < 75) - c = 'u'; // 0 1 8 - else if (band->v < 80) - c = 't'; // 1 8 - else - c = '1'; - } else if (band->s < 140) { - // 0 1 - if (band->v < 45) - c = '0'; - else if (band->v < 75) - c = 'y'; // 0 1 - else - c = '1'; - } else if (band->s < 200) { - c = '0'; - } else { - c = '6'; - } - } else if (band->h < 120) { - // 0 1 6 7 - if (band->s < 40) { - c = '1'; - } else if (band->s < 90) { - // 0 1 - if (band->v < 45) - c = '0'; - else if (band->v < 75) - c = 'y'; // 0 1 - else - c = '1'; - } else if (band->s < 110) { - // 0 1 7 - if (band->v < 45) - c = '0'; - else if (band->v < 75) - c = 'y'; // 0 1 - else if (band->v < 120) - c = '1'; - else - c = '7'; - } else if (band->s < 140) { - // 0 1 - if (band->v < 45) - c = '0'; - else if (band->v < 75) - c = 'y'; // 0 1 - else - c = '1'; - } else if (band->s < 200) { - c = '0'; - } else { - c = '6'; - } - } else if (band->h < 130) { - // 0 1 7 - if (band->s < 40) { - c = '1'; - } else if (band->s < 90) { - // 0 1 - if (band->v < 45) - c = '0'; - else if (band->v < 75) - c = 'y'; // 0 1 - else - c = '1'; - } else if (band->s < 110) { - // 0 1 7 - if (band->v < 45) - c = '0'; - else if (band->v < 75) - c = 'y'; // 0 1 - else if (band->v < 120) - c = '1'; - else - c = '7'; - } else if (band->s < 140) { - // 0 1 - if (band->v < 45) - c = '0'; - else if (band->v < 75) - c = 'y'; // 0 1 - else - c = '1'; - } else { - c = '0'; - } - } else if (band->h < 140) { - // 0 1 - if (band->s < 40) { - c = '1'; - } else if (band->s < 140) { - // 0 1 - if (band->v < 45) - c = '0'; - else if (band->v < 75) - c = 'y'; // 0 1 - else - c = '1'; - } else { - c = '0'; - } - } else if (band->h < 150) { - c = '0'; - } else { - c = '2'; - } - - return c; -} - -static void bands_code_deduce_0 (void) -{ - char txt[LOG_LINE_LEN]; - - /* - * 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; - } - - snprintf(txt, LOG_LINE_LEN, "Code: \"%s\"", code); - user_iface_log_write(0, txt); -} - -static void bands_code_deduce_1 (void) -{ - char txt[LOG_LINE_LEN]; - - /* - * 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; - } - - snprintf(txt, LOG_LINE_LEN, "Code: \"%s\"", code); - user_iface_log_write(0, txt); -} - -static int bands_code_deduce_no (void) -{ - char txt[LOG_LINE_LEN]; - - /* - * 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 (ptrdiff_t i = 0; i < 5; i++) { - switch (code[i]) { - case 'q': - case 'w': - case 'e': - case 'r': - case 't': - case 'y': - case 'u': - code[i] = '?'; - } - } - - for (ptrdiff_t i = 0; i < 5; i++) { - if (code[i] == '?') - return RESISTOR_NOK_COLOR; - } - - snprintf(txt, LOG_LINE_LEN, "Code: \"%s\"", code); - user_iface_log_write(0, txt); - - return 0; -} - -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 - return; - - resistance = base * pow(10, power); -} - -static int resistor_tolerance (void) -{ - - 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: - return RESISTOR_NOK_TOLERANCE; - } - } - - return 0; -} - -static void log_resistance (void) -{ - char txt[LOG_LINE_LEN]; - - if (bands_n != 1) { - snprintf(txt, LOG_LINE_LEN,"Resistance: %.2E ± %i%% Ohm", - resistance, tolerance); - user_iface_log_write(0, txt); - } else { - user_iface_log_write(0, "Resistance: 0 Ohm"); - } -} - -static int chk_std_value (void) -{ - /* 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}; - - if (bands_n == 1) { - if (base) - return RESISTOR_NOK_STD_VALUE; - return 0; - } - - for (ptrdiff_t i = 0; i < 12; i++) { - if (base == std_values_10[i]) - return 0; - if (base == (std_values_10[i] * 10)) - return 0; - } - if (tolerance <= 5) { - for (ptrdiff_t i = 0; i < 12; i++) { - if (base == std_values_5[i]) - return 0; - if (base == (std_values_5[i] * 10)) - return 0; - } - } - - return RESISTOR_NOK_STD_VALUE; -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/src/user/iface.c b/src/user/iface.c index 0056abb..12efb5b 100644 --- a/src/user/iface.c +++ b/src/user/iface.c @@ -16,7 +16,6 @@ #include "libalx/base/stdio/get.h" #include "vision-artificial/image/iface.h" -#include "vision-artificial/proc/iface.h" #include "vision-artificial/user/tui.h" @@ -155,8 +154,6 @@ static void user_iface_act (int action) /* do nothing */ break; } - } else if (action & USER_IFACE_ACT_PROC) { - proc_iface_single(action); } else { img_iface_act(action); } diff --git a/tmp/Makefile b/tmp/Makefile index d564a1c..18ab0f8 100644 --- a/tmp/Makefile +++ b/tmp/Makefile @@ -32,7 +32,7 @@ MAIN_SRC = \ # action PHONY := all -all: $(OBJ) share ctrl image menu proc save user +all: $(OBJ) share ctrl image menu save user PHONY += share @@ -55,11 +55,6 @@ menu: @echo " MAKE tmp/$@" $(Q)$(MAKE) -C $(TMP_DIR)/$@/ -PHONY += proc -proc: - @echo " MAKE tmp/$@" - $(Q)$(MAKE) -C $(TMP_DIR)/$@/ - PHONY += save save: @echo " MAKE tmp/$@" diff --git a/tmp/ctrl/Makefile b/tmp/ctrl/Makefile index da57c66..01fc38d 100644 --- a/tmp/ctrl/Makefile +++ b/tmp/ctrl/Makefile @@ -17,7 +17,6 @@ OBJ = \ START_INC = \ $(INC_DIR)/vision-artificial/ctrl/start.h \ - $(INC_DIR)/vision-artificial/proc/iface.h \ $(INC_DIR)/vision-artificial/save/save.h \ $(INC_DIR)/vision-artificial/user/iface.h START_SRC = \ diff --git a/tmp/menu/Makefile b/tmp/menu/Makefile index 4e85382..47dd53c 100644 --- a/tmp/menu/Makefile +++ b/tmp/menu/Makefile @@ -41,7 +41,6 @@ TUI_INC = \ $(LIBALX_INC_DIR)/libalx/extra/ncurses/get.h \ $(LIBALX_INC_DIR)/libalx/extra/ncurses/menu.h \ $(INC_DIR)/vision-artificial/ctrl/start.h \ - $(INC_DIR)/vision-artificial/proc/iface.h \ $(INC_DIR)/vision-artificial/save/save.h \ $(INC_DIR)/vision-artificial/share/share.h \ $(INC_DIR)/vision-artificial/user/iface.h diff --git a/tmp/proc/Makefile b/tmp/proc/Makefile deleted file mode 100644 index af9638e..0000000 --- a/tmp/proc/Makefile +++ /dev/null @@ -1,154 +0,0 @@ -#! /usr/bin/make -f - -################################################################################ -# Copyright (C) 2019 Alejandro Colomar Andrés -# SPDX-License-Identifier: GPL-2.0-only -################################################################################ -# *AUTHOR* -# FULL NAME "Alejandro Colomar Andrés" -# EMAIL "1903716@gmail.com" -################################################################################ - -################################################################################ -# dependencies - -OBJ = \ - common.o \ - iface.o \ - label.o \ - lighters.o \ - objects.o \ - resistor.o - -COMMON_INC = \ - $(INC_DIR)/vision-artificial/proc/common.hpp \ - $(LIBALX_INC_DIR)/libalx/base/stdio/seekc.hpp \ - $(INC_DIR)/vision-artificial/image/iface.hpp \ - $(INC_DIR)/vision-artificial/proc/iface.hpp \ - $(INC_DIR)/vision-artificial/user/iface.hpp -COMMON_SRC = \ - $(SRC_DIR)/proc/common.cpp - -IFACE_INC = \ - $(INC_DIR)/vision-artificial/proc/iface.h \ - $(LIBALX_INC_DIR)/libalx/base/compiler/size.h \ - $(LIBALX_INC_DIR)/libalx/base/stdio/sscan.h \ - $(LIBALX_INC_DIR)/libalx/base/stdio/seekc.h \ - $(INC_DIR)/vision-artificial/image/iface.h \ - $(INC_DIR)/vision-artificial/proc/common.h \ - $(INC_DIR)/vision-artificial/proc/label.h \ - $(INC_DIR)/vision-artificial/proc/lighters.h \ - $(INC_DIR)/vision-artificial/proc/objects.h \ - $(INC_DIR)/vision-artificial/proc/resistor.h \ - $(INC_DIR)/vision-artificial/save/save.h \ - $(INC_DIR)/vision-artificial/user/iface.h -IFACE_SRC = \ - $(SRC_DIR)/proc/iface.c - -LABEL_INC = \ - $(INC_DIR)/vision-artificial/proc/label.hpp \ - $(LIBALX_INC_DIR)/libalx/base/stdlib/swap.hpp \ - $(INC_DIR)/vision-artificial/image/iface.hpp \ - $(INC_DIR)/vision-artificial/proc/common.hpp \ - $(INC_DIR)/vision-artificial/user/iface.hpp -LABEL_SRC = \ - $(SRC_DIR)/proc/label.cpp - -LIGHTERS_INC = \ - $(INC_DIR)/vision-artificial/proc/lighters.hpp \ - $(LIBALX_INC_DIR)/libalx/base/stdlib/swap.hpp \ - $(INC_DIR)/vision-artificial/image/iface.hpp \ - $(INC_DIR)/vision-artificial/proc/common.hpp \ - $(INC_DIR)/vision-artificial/user/iface.hpp -LIGHTERS_SRC = \ - $(SRC_DIR)/proc/lighters.cpp - -OBJECTS_INC = \ - $(INC_DIR)/vision-artificial/proc/objects.hpp \ - $(LIBALX_INC_DIR)/libalx/extra/gsl/rstat/median.hpp \ - $(INC_DIR)/vision-artificial/image/iface.hpp \ - $(INC_DIR)/vision-artificial/proc/common.hpp \ - $(INC_DIR)/vision-artificial/user/iface.hpp -OBJECTS_SRC = \ - $(SRC_DIR)/proc/objects.cpp - -RESISTOR_INC = \ - $(INC_DIR)/vision-artificial/proc/resistor.hpp \ - $(LIBALX_INC_DIR)/libalx/base/compiler/size.hpp \ - $(INC_DIR)/vision-artificial/image/iface.hpp \ - $(INC_DIR)/vision-artificial/proc/common.hpp \ - $(INC_DIR)/vision-artificial/user/iface.hpp -RESISTOR_SRC = \ - $(SRC_DIR)/proc/resistor.cpp - -################################################################################ -# target: dependencies -# action - -PHONY := all -all: $(OBJ) - - -coins.s: $(COINS_SRC) $(COINS_INC) - @echo " CXX vision-artificial/proc/$@" - $(Q)$(CXX) $(CXXFLAGS) -I $(INC_DIR) -S $< -o $@ -coins.o: coins.s - @echo " AS vision-artificial/proc/$@" - $(Q)$(AS) $< -o $@ - -common.s: $(COMMON_SRC) $(COMMON_INC) - @echo " CXX vision-artificial/proc/$@" - $(Q)$(CXX) $(CXXFLAGS) -I $(INC_DIR) -S $< -o $@ -common.o: common.s - @echo " AS vision-artificial/proc/$@" - $(Q)$(AS) $< -o $@ - -iface.s: $(IFACE_SRC) $(IFACE_INC) - @echo " CC vision-artificial/proc/$@" - $(Q)$(CC) $(CFLAGS) -I $(INC_DIR) -S $< -o $@ -iface.o: iface.s - @echo " AS vision-artificial/proc/$@" - $(Q)$(AS) $< -o $@ - -label.s: $(LABEL_SRC) $(LABEL_INC) - @echo " CXX vision-artificial/proc/$@" - $(Q)$(CXX) $(CXXFLAGS) -I $(INC_DIR) -S $< -o $@ -label.o: label.s - @echo " AS vision-artificial/proc/$@" - $(Q)$(AS) $< -o $@ - -lighters.s: $(LIGHTERS_SRC) $(LIGHTERS_INC) - @echo " CXX vision-artificial/proc/$@" - $(Q)$(CXX) $(CXXFLAGS) -I $(INC_DIR) -S $< -o $@ -lighters.o: lighters.s - @echo " AS vision-artificial/proc/$@" - $(Q)$(AS) $< -o $@ - -objects.s: $(OBJECTS_SRC) $(OBJECTS_INC) - @echo " CXX vision-artificial/proc/$@" - $(Q)$(CXX) $(CXXFLAGS) -I $(INC_DIR) -S $< -o $@ -objects.o: objects.s - @echo " AS vision-artificial/proc/$@" - $(Q)$(AS) $< -o $@ - -resistor.s: $(RESISTOR_SRC) $(RESISTOR_INC) - @echo " CXX vision-artificial/proc/$@" - $(Q)$(CXX) $(CXXFLAGS) -I $(INC_DIR) -S $< -o $@ -resistor.o: resistor.s - @echo " AS vision-artificial/proc/$@" - $(Q)$(AS) $< -o $@ - - -PHONY += clean -clean: - @echo " RM *.o *.s" - $(Q)rm -f *.o *.s - -################################################################################ -# Declare the contents of the .PHONY variable as phony. -.PHONY: $(PHONY) - - -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/tmp/user/Makefile b/tmp/user/Makefile index 69dc95c..1447e28 100644 --- a/tmp/user/Makefile +++ b/tmp/user/Makefile @@ -20,7 +20,6 @@ IFACE_INC = \ $(INC_DIR)/vision-artificial/user/iface.h \ $(LIBALX_INC_DIR)/libalx/base/stdio/get.h \ $(INC_DIR)/vision-artificial/image/iface.h \ - $(INC_DIR)/vision-artificial/proc/iface.h \ $(INC_DIR)/vision-artificial/user/tui.h IFACE_SRC = \ $(SRC_DIR)/user/iface.c |