diff options
author | Alex <colomar.6.4.3@gmail.com> | 2019-04-07 18:56:08 +0100 |
---|---|---|
committer | Alex <colomar.6.4.3@gmail.com> | 2019-04-07 18:56:08 +0100 |
commit | 667ea210f5423a3ccc7fb806087688df24271a2f (patch) | |
tree | c8c416b35c56d11c9899c414f6bf6b8826578e1c | |
parent | 3d4e4e0733e8628d17a79881738ee3f236fed3e7 (diff) |
Restructure code; Use libalx v1~b2;
131 files changed, 8464 insertions, 9128 deletions
@@ -1,4 +1,4 @@ *.o *.s *.a -bin/vision-artificial2 +bin/vision-artificial* diff --git a/Checkstyle/checkstyle b/Checkstyle/checkstyle index 052c674..02cfad2 100755 --- a/Checkstyle/checkstyle +++ b/Checkstyle/checkstyle @@ -12,10 +12,7 @@ # variables # ################################################################################ dirs=( - ../src/ - ../inc/ - ../modules/ - ../libalx/ + ../ ) @@ -1,6 +1,6 @@ -#!/usr/bin/make -f +#! /usr/bin/make -f VERSION = 2 -PATCHLEVEL = 0 +PATCHLEVEL = 1 SUBLEVEL = 0 EXTRAVERSION = NAME = @@ -70,6 +70,40 @@ PROGRAMVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$( export PROGRAMVERSION ################################################################################ +# directories + +MAIN_DIR = $(CURDIR) + +LIBALX_DIR = $(CURDIR)/libalx/ +LIBALX_INC_DIR = $(LIBALX_DIR)/inc/ +LIBALX_LIB_DIR = $(LIBALX_DIR)/lib/libalx/ + +BIN_DIR = $(CURDIR)/bin/ +INC_DIR = $(CURDIR)/inc/ +SRC_DIR = $(CURDIR)/src/ +TMP_DIR = $(CURDIR)/tmp/ + +export MAIN_DIR +export LIBALX_DIR +export LIBALX_INC_DIR +export LIBALX_LIB_DIR +export BIN_DIR +export INC_DIR +export SRC_DIR +export TMP_DIR + +# FIXME: Set local or not local when building a package +INSTALL_BIN_DIR = /usr/local/bin/ +#INSTALL_BIN_DIR = /usr/bin/ +INSTALL_SHARE_DIR = /usr/local/share/ +#INSTALL_SHARE_DIR = /usr/share/ +INSTALL_VAR_DIR = /var/local/ +#INSTALL_VAR_DIR = /var/lib/ + +export INSTALL_DIR +export INSTALL_SHARE_DIR + +################################################################################ # Make variables (CC, etc...) CC = gcc CXX = g++ @@ -87,7 +121,7 @@ export SZ ################################################################################ # cflags -CFLAGS_STD = -std=c11 +CFLAGS_STD = -std=c17 CFLAGS_STD += -Wpedantic CFLAGS_OPT = -O3 @@ -106,12 +140,11 @@ CFLAGS_PKG += `pkg-config --cflags opencv` CFLAGS_PKG += `pkg-config --cflags zbar` CFLAGS_PKG += `pkg-config --cflags tesseract` CFLAGS_PKG += `pkg-config --cflags lept` +CFLAGS_PKG += -I $(LIBALX_INC_DIR) CFLAGS_D = -D PROG_VERSION=\"$(PROGRAMVERSION)\" CFLAGS_D += -D INSTALL_SHARE_DIR=\"$(INSTALL_SHARE_DIR)\" -CFLAGS_D += -D SHARE_DIR=\"$(SHARE_DIR)\" CFLAGS_D += -D INSTALL_VAR_DIR=\"$(INSTALL_VAR_DIR)\" -CFLAGS_D += -D VAR_DIR=\"$(VAR_DIR)\" CFLAGS = $(CFLAGS_STD) CFLAGS += $(CFLAGS_OPT) @@ -140,12 +173,11 @@ CXXFLAGS_PKG += `pkg-config --cflags opencv` CXXFLAGS_PKG += `pkg-config --cflags zbar` CXXFLAGS_PKG += `pkg-config --cflags tesseract` CXXFLAGS_PKG += `pkg-config --cflags lept` +CXXFLAGS_PKG += -I $(LIBALX_INC_DIR) CXXFLAGS_D = -D PROG_VERSION=\"$(PROGRAMVERSION)\" CXXFLAGS_D += -D INSTALL_SHARE_DIR=\"$(INSTALL_SHARE_DIR)\" -CXXFLAGS_D += -D SHARE_DIR=\"$(SHARE_DIR)\" CXXFLAGS_D += -D INSTALL_VAR_DIR=\"$(INSTALL_VAR_DIR)\" -CXXFLAGS_D += -D VAR_DIR=\"$(VAR_DIR)\" CXXFLAGS = $(CXXFLAGS_STD) CXXFLAGS += $(CXXFLAGS_OPT) @@ -168,34 +200,6 @@ LIBS = $(LIBS_PKG) export LIBS ################################################################################ -# directories - -MAIN_DIR = $(CURDIR) - -LIBALX_DIR = $(CURDIR)/libalx/ -MODULES_DIR = $(CURDIR)/modules/ -TMP_DIR = $(CURDIR)/tmp/ -BIN_DIR = $(CURDIR)/bin/ - -export MAIN_DIR -export LIBALX_DIR -export MODULES_DIR - -# FIXME: Set local or not local when building a package -INSTALL_BIN_DIR = /usr/local/bin/ -#INSTALL_BIN_DIR = /usr/bin/ -INSTALL_SHARE_DIR = /usr/local/share/ -#INSTALL_SHARE_DIR = /usr/share/ -SHARE_DIR = vision-artificial/ -INSTALL_VAR_DIR = /var/local/ -#INSTALL_VAR_DIR = /var/lib/ -VAR_DIR = vision-artificial/ - -export INSTALL_DIR -export INSTALL_SHARE_DIR -export SHARE_DIR - -################################################################################ # executables BIN_NAME = vision-artificial2 @@ -208,33 +212,30 @@ export BIN_NAME # That's the default target when none is given on the command line PHONY := all -all: libalx modules main binary +all: bin PHONY += libalx libalx: - @echo ' MAKE libalx' - $(Q)$(MAKE) base -C $(LIBALX_DIR) - $(Q)$(MAKE) io -C $(LIBALX_DIR) - $(Q)$(MAKE) curses -C $(LIBALX_DIR) - @echo - -PHONY += modules -modules: libalx - @echo ' MAKE modules' - $(Q)$(MAKE) -C $(MODULES_DIR) + @echo " MAKE $@" + $(Q)$(MAKE) errno -C $(LIBALX_DIR) + $(Q)$(MAKE) math -C $(LIBALX_DIR) + $(Q)$(MAKE) stdio -C $(LIBALX_DIR) + $(Q)$(MAKE) stdlib -C $(LIBALX_DIR) + $(Q)$(MAKE) string -C $(LIBALX_DIR) + $(Q)$(MAKE) ncurses -C $(LIBALX_DIR) @echo -PHONY += main -main: modules libalx - @echo ' MAKE main' - $(Q)$(MAKE) -C $(TMP_DIR) +PHONY += tmp +tmp: + @echo " MAKE $@" + $(Q)$(MAKE) -C $(TMP_DIR) @echo -PHONY += binary -binary: main - @echo ' MAKE binary' - $(Q)$(MAKE) -C $(BIN_DIR) +PHONY += bin +bin: tmp libalx + @echo " MAKE $@" + $(Q)$(MAKE) -C $(BIN_DIR) @echo PHONY += install @@ -243,11 +244,11 @@ install: uninstall @echo " MKDIR $(INSTALL_BIN_DIR)/" $(Q)mkdir -p $(DESTDIR)/$(INSTALL_BIN_DIR)/ @echo " CP $(BIN_NAME)" - $(Q)cp $(BIN_DIR)/$(BIN_NAME) $(DESTDIR)/$(INSTALL_BIN_DIR)/ - @echo " MKDIR $(INSTALL_SHARE_DIR)/$(SHARE_DIR)/" - $(Q)mkdir -p $(DESTDIR)/$(INSTALL_SHARE_DIR)/$(SHARE_DIR)/ - @echo " CP -r share/*" - $(Q)cp -r ./share/* $(DESTDIR)/$(INSTALL_SHARE_DIR)/$(SHARE_DIR)/ + $(Q)cp -v $(BIN_DIR)/$(BIN_NAME) $(DESTDIR)/$(INSTALL_BIN_DIR)/ + @echo " MKDIR $(INSTALL_SHARE_DIR)/vision-artificial/" + $(Q)mkdir -p $(DESTDIR)/$(INSTALL_SHARE_DIR)/vision-artificial/ + @echo " CP -r share/vision-artificial/*" + $(Q)cp -r -v ./share/vision-artificial/* $(DESTDIR)/$(INSTALL_SHARE_DIR)/vision-artificial/ @echo " Done" @echo @@ -256,24 +257,22 @@ uninstall: @echo " Clean old installations:" @echo " RM bin" $(Q)rm -f $(DESTDIR)/$(INSTALL_BIN_DIR)/$(BIN_NAME) - @echo " RM -r $(INSTALL_SHARE_DIR)/$(SHARE_DIR)/" - $(Q)rm -f -r $(DESTDIR)/$(INSTALL_SHARE_DIR)/$(SHARE_DIR)/ + @echo " RM -r $(INSTALL_SHARE_DIR)/vision-artificial/" + $(Q)rm -f -r $(DESTDIR)/$(INSTALL_SHARE_DIR)/vision-artificial/ @echo " Done" @echo PHONY += clean clean: - @echo ' CLEAN modules' - $(Q)$(MAKE) clean -C $(MODULES_DIR) - @echo ' CLEAN tmp' - $(Q)$(MAKE) clean -C $(TMP_DIR) - @echo ' CLEAN bin' - $(Q)$(MAKE) clean -C $(BIN_DIR) + @echo " RM *.o *.s *.a $(BIN_NAME)" + $(Q)find $(TMP_DIR) -type f -name '*.o' -exec rm '{}' '+' + $(Q)find $(TMP_DIR) -type f -name '*.s' -exec rm '{}' '+' + $(Q)find $(BIN_DIR) -type f -name '*$(BIN_NAME)' -exec rm '{}' '+' @echo -PHONY += mrproper -mrproper: clean - @echo ' CLEAN libalx' +PHONY += distclean +distclean: clean + @echo " CLEAN libalx" $(Q)$(MAKE) clean -C $(LIBALX_DIR) @echo @@ -281,14 +280,13 @@ PHONY += help help: @echo 'Cleaning targets:' @echo ' clean - Remove all generated files' - @echo ' mrproper - Remove all generated files (including libraries)' + @echo ' distclean - Remove all generated files (including libraries)' @echo @echo 'Other generic targets:' @echo ' all - Build all targets marked with [*]' @echo '* libalx - Build the libalx library' - @echo '* modules - Build all modules' - @echo '* object - Build the main object' - @echo '* binary - Build the binary' + @echo '* tmp - Compile all files' + @echo '* bin - Build the binary' @echo ' install - Install the program into the filesystem' @echo ' uninstall - Uninstall the program off the filesystem' @echo @@ -302,8 +300,6 @@ help: .PHONY: $(PHONY) - - ################################################################################ ######## End of file ########################################################### ################################################################################ diff --git a/bin/Makefile b/bin/Makefile index e1f17df..d0b2d7b 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -1,40 +1,64 @@ -# -*- MakeFile -*- - -# directories - -LIBALX_LIB_DIR = $(LIBALX_DIR)/lib/ - -MODULES_TMP_DIR = $(MODULES_DIR)/tmp/ - -TMP_DIR = $(MAIN_DIR)/tmp/ +#! /usr/bin/make -f # dependencies -ALL = $(BIN_NAME) size -MAIN_OBJ_MODULES = modules.o -MAIN_OBJS = $(TMP_DIR)/main.o \ - $(patsubst %,$(MODULES_TMP_DIR)/%,$(MAIN_OBJ_MODULES)) +OBJS = \ + $(TMP_DIR)/main.o \ + $(TMP_DIR)/about/about.o \ + $(TMP_DIR)/ctrl/start.o \ + $(TMP_DIR)/image/alx.o \ + $(TMP_DIR)/image/calib3d.o \ + $(TMP_DIR)/image/cv.o \ + $(TMP_DIR)/image/iface.o \ + $(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/coins.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)/user/clui.o \ + $(TMP_DIR)/user/iface.o \ + $(TMP_DIR)/user/tui.o +DEPS_LIBS = \ + $(LIBALX_LIB_DIR)/libalx-ncurses.a \ + $(LIBALX_LIB_DIR)/libalx-stdio.a \ + $(LIBALX_LIB_DIR)/libalx-errno.a \ + $(LIBALX_LIB_DIR)/libalx-math.a \ + $(LIBALX_LIB_DIR)/libalx-stdlib.a \ + $(LIBALX_LIB_DIR)/libalx-string.a -MAIN_LIB_LIBALX = libalx-base.a libalx-io.a libalx-curses.a -MAIN_LIBS = \ - $(patsubst %,$(LIBALX_LIB_DIR)/%,$(MAIN_LIB_LIBALX)) +ALL = $(BIN_NAME) size # static libs -STATIC_LIB_LIBALX = -L $(LIBALX_LIB_DIR) \ - -l alx-curses -l alx-io -l alx-base -STATIC_LIBS = $(STATIC_LIB_LIBALX) +STATIC_LIBS = -L $(LIBALX_LIB_DIR) \ + -l alx-ncurses \ + -l alx-stdio \ + -l alx-string \ + -l alx-errno \ + -l alx-math \ + -l alx-stdlib # target: dependencies # action +PHONY := all all: $(ALL) -$(BIN_NAME): $(MAIN_OBJS) $(MAIN_LIBS) +$(BIN_NAME): $(OBJS) $(DEPS_LIBS) @echo " CXX $@" - $(Q)$(CXX) $(MAIN_OBJS) -o $@ $(STATIC_LIBS) $(LIBS) + $(Q)$(CXX) $(OBJS) -o $@ $(STATIC_LIBS) $(LIBS) size: $(BIN_NAME) @echo " SZ $(BIN_NAME)" @@ -43,7 +67,11 @@ size: $(BIN_NAME) clean: @echo " RM $(ALL)" - $(Q)rm -f $(ALL) + $(Q)rm -f $(ALL) + +################################################################################ +# Declare the contents of the .PHONY variable as phony. +.PHONY: $(PHONY) ################################################################################ ######## End of file ########################################################### diff --git a/modules/about/inc/about.h b/inc/vision-artificial/about/about.h index 381f13d..4faa574 100644 --- a/modules/about/inc/about.h +++ b/inc/vision-artificial/about/about.h @@ -7,35 +7,39 @@ /****************************************************************************** ******* include guard ******************************************************** ******************************************************************************/ -# ifndef VA_ABOUT_H - # define VA_ABOUT_H +#ifndef VA_ABOUT_ABOUT_H +#define VA_ABOUT_ABOUT_H /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* FILENAME_MAX */ - #include <stdio.h> +#include <stddef.h> +#include <stdio.h> /****************************************************************************** ******* macros *************************************************************** ******************************************************************************/ - # define PROG_NAME "vision-artificial" - # define PROG_YEAR "2018" +#define PROG_NAME "vision-artificial" +#define PROG_YEAR "2018" /****************************************************************************** ******* enums **************************************************************** ******************************************************************************/ - enum Share_File { - SHARE_COPYRIGHT, - SHARE_DISCLAIMER, - SHARE_HELP, - SHARE_LICENSE, - SHARE_USAGE - }; +enum Share_File { + SHARE_COPYRIGHT, + SHARE_DISCLAIMER, + SHARE_HELP, + SHARE_LICENSE, + SHARE_USAGE +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ /****************************************************************************** @@ -45,18 +49,29 @@ extern char share_path [FILENAME_MAX]; /****************************************************************************** - ******* functions ************************************************************ + ******* extern functions ***************************************************** ******************************************************************************/ void about_init (void); -void snprint_share_file (char *dest, int destsize, int share_file); +void snprint_share_file (ptrdiff_t size, char buff[restrict size], + int file); void print_share_file (int share_file); void print_version (void); /****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** ******* include guard ******************************************************** ******************************************************************************/ -# endif /* about.h */ +#endif /* vision-artificial/about/about.h */ /****************************************************************************** diff --git a/modules/about/inc/about.hpp b/inc/vision-artificial/about/about.hpp index 31d5977..1970a2b 100644 --- a/modules/about/inc/about.hpp +++ b/inc/vision-artificial/about/about.hpp @@ -7,41 +7,41 @@ /****************************************************************************** ******* include guard ******************************************************** ******************************************************************************/ -# ifndef VA_ABOUT_HPP - # define VA_ABOUT_HPP +#ifndef VA_ABOUT_ABOUT_HPP +#define VA_ABOUT_ABOUT_HPP /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* FILENAME_MAX */ - #include <cstdio> +#include <cstddef> +#include <cstdio> + +#include "libalx/base/stddef/restrict.hpp" /****************************************************************************** - ******* C wrapper ************************************************************ + ******* macros *************************************************************** ******************************************************************************/ -extern "C" { +#define PROG_NAME "vision-artificial" +#define PROG_YEAR "2018" /****************************************************************************** - ******* macros *************************************************************** + ******* enums **************************************************************** ******************************************************************************/ - # define PROG_NAME "vision-artificial" - # define PROG_YEAR "2018" +enum Share_File { + SHARE_COPYRIGHT, + SHARE_DISCLAIMER, + SHARE_HELP, + SHARE_LICENSE, + SHARE_USAGE +}; /****************************************************************************** - ******* enums **************************************************************** + ******* structs / unions ***************************************************** ******************************************************************************/ - enum Share_File { - SHARE_COPYRIGHT, - SHARE_DISCLAIMER, - SHARE_HELP, - SHARE_LICENSE, - SHARE_USAGE - }; /****************************************************************************** @@ -51,24 +51,32 @@ extern char share_path [FILENAME_MAX]; /****************************************************************************** - ******* functions ************************************************************ + ******* extern functions ***************************************************** ******************************************************************************/ +extern "C" +{ void about_init (void); -void snprint_share_file (char *dest, int destsize, int share_file); +void snprint_share_file (ptrdiff_t size, char *restrict buff, + int file); void print_share_file (int share_file); void print_version (void); +} + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ /****************************************************************************** - ******* C wrapper ************************************************************ + ******* static inline functions (definitions) ******************************** ******************************************************************************/ -} /* extern "C" */ /****************************************************************************** ******* include guard ******************************************************** ******************************************************************************/ -# endif /* about.hpp */ +#endif /* vision-artificial/about/about.hpp */ /****************************************************************************** diff --git a/modules/proc/inc/proc_objects.hpp b/inc/vision-artificial/ctrl/start.h index 8794150..c7daeff 100644 --- a/modules/proc/inc/proc_objects.hpp +++ b/inc/vision-artificial/ctrl/start.h @@ -7,54 +7,56 @@ /****************************************************************************** ******* include guard ******************************************************** ******************************************************************************/ -# ifndef VA_PROC_OBJECTS_HPP - # define VA_PROC_OBJECTS_HPP +#ifndef VA_CTRL_START_H +#define VA_CTRL_START_H /****************************************************************************** - ******* macros *************************************************************** + ******* headers ************************************************************** ******************************************************************************/ /****************************************************************************** ******* enums **************************************************************** ******************************************************************************/ - enum Proc_Objects { - OBJECTS_OK, - OBJECTS_NOK_PATTERN, - OBJECTS_NOK_OBJECTS, - OBJECTS_NOK_SIZE - }; +enum Start_Mode { + START_FOO = 0, + START_SINGLE, + START_SERIES +}; /****************************************************************************** - ******* C wrapper ************************************************************ + ******* structs / unions ***************************************************** ******************************************************************************/ -extern "C" { /****************************************************************************** ******* variables ************************************************************ ******************************************************************************/ +extern int start_mode; /****************************************************************************** - ******* functions ************************************************************ + ******* extern functions ***************************************************** ******************************************************************************/ -int proc_objects_calibrate (void); -int proc_objects (void); +void start_switch (void); /****************************************************************************** - ******* C wrapper ************************************************************ + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** ******************************************************************************/ -} /* extern "C" */ /****************************************************************************** ******* include guard ******************************************************** ******************************************************************************/ -# endif /* proc_objects.hpp */ +#endif /* vision-artificial/ctrl/start.h */ /****************************************************************************** diff --git a/inc/vision-artificial/image/alx.hpp b/inc/vision-artificial/image/alx.hpp new file mode 100644 index 0000000..cecb3a7 --- /dev/null +++ b/inc/vision-artificial/image/alx.hpp @@ -0,0 +1,77 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_IMAGE_ALX_H +#define VA_IMAGE_ALX_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include <opencv2/opencv.hpp> + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Img_Alx_Action { + IMG_ALX_ACT_FOO = 0x000000u, + + IMG_ALX_ACT_ALX = 0x000010u, + IMG_ALX_ACT_LOCAL_MAX, + IMG_ALX_ACT_SKELETON, + IMG_ALX_ACT_LINES_HORIZONTAL, + IMG_ALX_ACT_LINES_VERTICAL, + IMG_ALX_ACT_MEAN_HORIZONTAL, + IMG_ALX_ACT_MEAN_VERTICAL, + IMG_ALX_ACT_MEDIAN_HORIZONTAL, + IMG_ALX_ACT_MEDIAN_VERTICAL +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void img_alx_act (class cv::Mat *imgptr, int action, const void *data); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/image/alx.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/image/calib3d.hpp b/inc/vision-artificial/image/calib3d.hpp new file mode 100644 index 0000000..97a561a --- /dev/null +++ b/inc/vision-artificial/image/calib3d.hpp @@ -0,0 +1,71 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_IMAGE_CALIB3D_HPP +#define VA_IMAGE_CALIB3D_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include <opencv2/opencv.hpp> + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Img_Calib3d_Action { + IMG_CALIB3D_ACT_FOO = 0x000000u, + + IMG_CALIB3D_ACT_CALIB3D = 0x000400u, + IMG_CALIB3D_ACT_CALIBRATE, + IMG_CALIB3D_ACT_UNDISTORT +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void img_calib3d_act(class cv::Mat *imgptr, int action, const void *data); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/image/calib3d.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/inc/img_cv.hpp b/inc/vision-artificial/image/cv.hpp index 1840ca6..681497a 100644 --- a/modules/image/inc/img_cv.hpp +++ b/inc/vision-artificial/image/cv.hpp @@ -7,52 +7,51 @@ /****************************************************************************** ******* include guard ******************************************************** ******************************************************************************/ -# ifndef VA_IMG_CV_H - # define VA_IMG_CV_H +#ifndef VA_IMAGE_CV_H +#define VA_IMAGE_CV_H /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ -/* packages ------------------------------------------------------------------*/ - #include <opencv2/opencv.hpp> +#include <opencv2/opencv.hpp> /****************************************************************************** ******* enums **************************************************************** ******************************************************************************/ - enum Img_Cv_Action { - IMG_CV_ACT_FOO = 0x000000u, +enum Img_Cv_Action { + IMG_CV_ACT_FOO = 0x000000u, - IMG_CV_ACT_CV = 0x000100u, - IMG_CV_ACT_PIXEL_GET, - IMG_CV_ACT_PIXEL_SET, - IMG_CV_ACT_SET_ROI, - IMG_CV_ACT_AND_2REF, - IMG_CV_ACT_NOT, - IMG_CV_ACT_OR_2REF, - IMG_CV_ACT_COMPONENT, - IMG_CV_ACT_DILATE, - IMG_CV_ACT_ERODE, - IMG_CV_ACT_SMOOTH, - IMG_CV_ACT_SOBEL, - IMG_CV_ACT_BORDER, - IMG_CV_ACT_MIRROR, - IMG_CV_ACT_ROTATE_ORTO, - IMG_CV_ACT_ROTATE, - IMG_CV_ACT_ADAPTIVE_THRESHOLD, - IMG_CV_ACT_CVT_COLOR, - IMG_CV_ACT_DISTANCE_TRANSFORM, - IMG_CV_ACT_THRESHOLD, - IMG_CV_ACT_HISTOGRAM, - IMG_CV_ACT_HISTOGRAM_C3, - IMG_CV_ACT_CONTOURS, - IMG_CV_ACT_CONTOURS_SIZE, - IMG_CV_ACT_BOUNDING_RECT, - IMG_CV_ACT_FIT_ELLIPSE, - IMG_CV_ACT_MIN_AREA_RECT, - IMG_CV_ACT_HOUGH_CIRCLES - }; + IMG_CV_ACT_CV = 0x000100u, + IMG_CV_ACT_PIXEL_GET, + IMG_CV_ACT_PIXEL_SET, + IMG_CV_ACT_SET_ROI, + IMG_CV_ACT_AND_2REF, + IMG_CV_ACT_NOT, + IMG_CV_ACT_OR_2REF, + IMG_CV_ACT_COMPONENT, + IMG_CV_ACT_DILATE, + IMG_CV_ACT_ERODE, + IMG_CV_ACT_SMOOTH, + IMG_CV_ACT_SOBEL, + IMG_CV_ACT_BORDER, + IMG_CV_ACT_MIRROR, + IMG_CV_ACT_ROTATE_ORTO, + IMG_CV_ACT_ROTATE, + IMG_CV_ACT_ADAPTIVE_THRESHOLD, + IMG_CV_ACT_CVT_COLOR, + IMG_CV_ACT_DISTANCE_TRANSFORM, + IMG_CV_ACT_THRESHOLD, + IMG_CV_ACT_HISTOGRAM, + IMG_CV_ACT_HISTOGRAM_C3, + IMG_CV_ACT_CONTOURS, + IMG_CV_ACT_CONTOURS_SIZE, + IMG_CV_ACT_BOUNDING_RECT, + IMG_CV_ACT_FIT_ELLIPSE, + IMG_CV_ACT_MIN_AREA_RECT, + IMG_CV_ACT_HOUGH_CIRCLES +}; /****************************************************************************** @@ -64,7 +63,7 @@ void img_cv_act (class cv::Mat *imgptr, int action, const void *data); /****************************************************************************** ******* include guard ******************************************************** ******************************************************************************/ -# endif /* img_cv.h */ +#endif /* vision-artificial/image/cv.h */ /****************************************************************************** diff --git a/inc/vision-artificial/image/iface.h b/inc/vision-artificial/image/iface.h new file mode 100644 index 0000000..f98a553 --- /dev/null +++ b/inc/vision-artificial/image/iface.h @@ -0,0 +1,191 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_IMAGE_IFACE_H +#define VA_IMAGE_IFACE_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include <stddef.h> + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +#define CONTOURS_MAX (0xFFFF) +#define OCR_TEXT_MAX (0xFFFFFF) +#define ZB_CODES_MAX (10) +#define ZBAR_LEN_MAX (0xFFFFFF) + +#define IMG_IFACE_THR_OTSU (-1) + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Img_Iface_Action { + IMG_IFACE_ACT_FOO = 0x000000u, + + IMG_IFACE_ACT_ALX = 0x000010u, + IMG_IFACE_ACT_LOCAL_MAX, + IMG_IFACE_ACT_SKELETON, + IMG_IFACE_ACT_LINES_HORIZONTAL, + IMG_IFACE_ACT_LINES_VERTICAL, + IMG_IFACE_ACT_MEAN_HORIZONTAL, + IMG_IFACE_ACT_MEAN_VERTICAL, + IMG_IFACE_ACT_MEDIAN_HORIZONTAL, + IMG_IFACE_ACT_MEDIAN_VERTICAL, + + IMG_IFACE_ACT_CV = 0x000100u, + IMG_IFACE_ACT_PIXEL_GET, + IMG_IFACE_ACT_PIXEL_SET, + IMG_IFACE_ACT_SET_ROI, + IMG_IFACE_ACT_SET_ROI_2RECT, + IMG_IFACE_ACT_AND_2REF, + IMG_IFACE_ACT_NOT, + IMG_IFACE_ACT_OR_2REF, + IMG_IFACE_ACT_COMPONENT, + IMG_IFACE_ACT_DILATE, + IMG_IFACE_ACT_ERODE, + IMG_IFACE_ACT_DILATE_ERODE, + IMG_IFACE_ACT_ERODE_DILATE, + IMG_IFACE_ACT_SMOOTH, + IMG_IFACE_ACT_SOBEL, + IMG_IFACE_ACT_BORDER, + IMG_IFACE_ACT_MIRROR, + IMG_IFACE_ACT_ROTATE_ORTO, + IMG_IFACE_ACT_ROTATE, + IMG_IFACE_ACT_ROTATE_2RECT, + IMG_IFACE_ACT_ADAPTIVE_THRESHOLD, + IMG_IFACE_ACT_CVT_COLOR, + IMG_IFACE_ACT_DISTANCE_TRANSFORM, + IMG_IFACE_ACT_THRESHOLD, + IMG_IFACE_ACT_HISTOGRAM, + IMG_IFACE_ACT_HISTOGRAM_C3, + IMG_IFACE_ACT_CONTOURS, + IMG_IFACE_ACT_CONTOURS_SIZE, + IMG_IFACE_ACT_BOUNDING_RECT, + IMG_IFACE_ACT_FIT_ELLIPSE, + IMG_IFACE_ACT_MIN_AREA_RECT, + IMG_IFACE_ACT_HOUGH_CIRCLES, + + IMG_IFACE_ACT_ORB = 0x000200u, + IMG_IFACE_ACT_ALIGN, + + IMG_IFACE_ACT_CALIB3D = 0x000400u, + IMG_IFACE_ACT_CALIBRATE, + IMG_IFACE_ACT_UNDISTORT, + + IMG_IFACE_ACT_ZB = 0x000800u, + IMG_IFACE_ACT_DECODE, + + IMG_IFACE_ACT_OCR = 0x001000u, + IMG_IFACE_ACT_READ, + + IMG_IFACE_ACT_IMGI = 0x002000u, + IMG_IFACE_ACT_APPLY, + IMG_IFACE_ACT_DISCARD, + IMG_IFACE_ACT_SAVE_MEM, + IMG_IFACE_ACT_LOAD_MEM, + IMG_IFACE_ACT_SAVE_REF, + + IMG_IFACE_ACT_SAVE = 0x004000u, + IMG_IFACE_ACT_SAVE_FILE, + IMG_IFACE_ACT_SAVE_UPDT +}; + +enum Img_Iface_Cmp_BGR { + IMG_IFACE_CMP_BLUE = 0, + IMG_IFACE_CMP_GREEN, + IMG_IFACE_CMP_RED +}; + +enum Img_Iface_Cmp_HSV { + IMG_IFACE_CMP_HUE = 0, + IMG_IFACE_CMP_SATURATION, + IMG_IFACE_CMP_VALUE +}; + +enum ImgI_Smooth { + IMGI_SMOOTH_MEAN = 0, + IMGI_SMOOTH_GAUSS, + IMGI_SMOOTH_MEDIAN +}; + +enum Img_Iface_OCR_Lang { + IMG_IFACE_OCR_LANG_ENG = 0, + IMG_IFACE_OCR_LANG_SPA, + IMG_IFACE_OCR_LANG_CAT, + IMG_IFACE_OCR_LANG_DIGITS, + IMG_IFACE_OCR_LANG_DIGITS_COMMA +}; + +enum Img_Iface_OCR_Conf { + IMG_IFACE_OCR_CONF_NONE = 0, + IMG_IFACE_OCR_CONF_PRICE +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ +struct Img_Iface_Data_Read { + int lang; + int conf; + struct { + void *data; + ptrdiff_t width; + ptrdiff_t height; + int B_per_pix; + int B_per_line; + } img; +}; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +extern char img_ocr_text [OCR_TEXT_MAX]; +extern struct Img_Iface_ZB_Codes zb_codes; + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void img_iface_init (void); +void img_iface_deinit (void); +void img_iface_load (const char *fpath, const char *fname); +void img_iface_cleanup (void); +void img_iface_act (int action, const void *data); +void img_iface_show_img (void); +void img_iface_show_hist_c1 (void); +void img_iface_show_hist_c3 (void); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/image/iface.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/image/iface.hpp b/inc/vision-artificial/image/iface.hpp new file mode 100644 index 0000000..3d1fdd4 --- /dev/null +++ b/inc/vision-artificial/image/iface.hpp @@ -0,0 +1,333 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_IMAGE_IFACE_HPP +#define VA_IMAGE_IFACE_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include <cstddef> + +#include <vector> + +#include <opencv2/opencv.hpp> + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +#define CONTOURS_MAX (0xFFFF) +#define OCR_TEXT_MAX (0xFFFFFF) +#define ZB_CODES_MAX (10) +#define ZBAR_LEN_MAX (0xFFFFFF) + +#define IMG_IFACE_THR_OTSU (-1) + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Img_Iface_Action { + IMG_IFACE_ACT_FOO = 0x000000u, + + IMG_IFACE_ACT_ALX = 0x000010u, + IMG_IFACE_ACT_LOCAL_MAX, + IMG_IFACE_ACT_SKELETON, + IMG_IFACE_ACT_LINES_HORIZONTAL, + IMG_IFACE_ACT_LINES_VERTICAL, + IMG_IFACE_ACT_MEAN_HORIZONTAL, + IMG_IFACE_ACT_MEAN_VERTICAL, + IMG_IFACE_ACT_MEDIAN_HORIZONTAL, + IMG_IFACE_ACT_MEDIAN_VERTICAL, + + IMG_IFACE_ACT_CV = 0x000100u, + IMG_IFACE_ACT_PIXEL_GET, + IMG_IFACE_ACT_PIXEL_SET, + IMG_IFACE_ACT_SET_ROI, + IMG_IFACE_ACT_SET_ROI_2RECT, + IMG_IFACE_ACT_AND_2REF, + IMG_IFACE_ACT_NOT, + IMG_IFACE_ACT_OR_2REF, + IMG_IFACE_ACT_COMPONENT, + IMG_IFACE_ACT_DILATE, + IMG_IFACE_ACT_ERODE, + IMG_IFACE_ACT_DILATE_ERODE, + IMG_IFACE_ACT_ERODE_DILATE, + IMG_IFACE_ACT_SMOOTH, + IMG_IFACE_ACT_SOBEL, + IMG_IFACE_ACT_BORDER, + IMG_IFACE_ACT_MIRROR, + IMG_IFACE_ACT_ROTATE_ORTO, + IMG_IFACE_ACT_ROTATE, + IMG_IFACE_ACT_ROTATE_2RECT, + IMG_IFACE_ACT_ADAPTIVE_THRESHOLD, + IMG_IFACE_ACT_CVT_COLOR, + IMG_IFACE_ACT_DISTANCE_TRANSFORM, + IMG_IFACE_ACT_THRESHOLD, + IMG_IFACE_ACT_HISTOGRAM, + IMG_IFACE_ACT_HISTOGRAM_C3, + IMG_IFACE_ACT_CONTOURS, + IMG_IFACE_ACT_CONTOURS_SIZE, + IMG_IFACE_ACT_BOUNDING_RECT, + IMG_IFACE_ACT_FIT_ELLIPSE, + IMG_IFACE_ACT_MIN_AREA_RECT, + IMG_IFACE_ACT_HOUGH_CIRCLES, + + IMG_IFACE_ACT_ORB = 0x000200u, + IMG_IFACE_ACT_ALIGN, + + IMG_IFACE_ACT_CALIB3D = 0x000400u, + IMG_IFACE_ACT_CALIBRATE, + IMG_IFACE_ACT_UNDISTORT, + + IMG_IFACE_ACT_ZB = 0x000800u, + IMG_IFACE_ACT_DECODE, + + IMG_IFACE_ACT_OCR = 0x001000u, + IMG_IFACE_ACT_READ, + + IMG_IFACE_ACT_IMGI = 0x002000u, + IMG_IFACE_ACT_APPLY, + IMG_IFACE_ACT_DISCARD, + IMG_IFACE_ACT_SAVE_MEM, + IMG_IFACE_ACT_LOAD_MEM, + IMG_IFACE_ACT_SAVE_REF, + + IMG_IFACE_ACT_SAVE = 0x004000u, + IMG_IFACE_ACT_SAVE_FILE, + IMG_IFACE_ACT_SAVE_UPDT +}; + +enum Img_Iface_Cmp { + IMG_IFACE_CMP_BLUE = 0, + IMG_IFACE_CMP_GREEN, + IMG_IFACE_CMP_RED +}; + +enum Img_Iface_Cmp_HSV { + IMG_IFACE_CMP_HUE = 0, + IMG_IFACE_CMP_SATURATION, + IMG_IFACE_CMP_VALUE +}; + +enum ImgI_Smooth { + IMGI_SMOOTH_MEAN = 1, + IMGI_SMOOTH_GAUSS, + IMGI_SMOOTH_MEDIAN +}; + +enum Img_Iface_OCR_Lang { + IMG_IFACE_OCR_LANG_ENG = 0, + IMG_IFACE_OCR_LANG_SPA, + IMG_IFACE_OCR_LANG_CAT, + IMG_IFACE_OCR_LANG_DIGITS, + IMG_IFACE_OCR_LANG_DIGITS_COMMA +}; + +enum Img_Iface_OCR_Conf { + IMG_IFACE_OCR_CONF_NONE = 0, + IMG_IFACE_OCR_CONF_PRICE +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ +/* cv ------------------------------------------------------------------------*/ +struct Img_Iface_Data_Pixel_Get { + unsigned char *val; + ptrdiff_t x; + ptrdiff_t y; +}; + +struct Img_Iface_Data_Pixel_Set { + unsigned char val; + ptrdiff_t x; + ptrdiff_t y; +}; + +struct Img_Iface_Data_SetROI { + class cv::Rect_ <int> rect; +}; + +struct Img_Iface_Data_Component { + ptrdiff_t cmp; +}; + +struct Img_Iface_Data_Dilate_Erode { + int i; +}; + +struct Img_Iface_Data_Smooth { + int method; + int ksize; +}; + +struct Img_Iface_Data_Sobel { + int dx; + int dy; + int ksize; +}; + +struct Img_Iface_Data_Border { + ptrdiff_t size; +}; + +struct Img_Iface_Data_Mirror { + int axis; +}; + +struct Img_Iface_Data_Rotate_Orto { + int n; +}; + +struct Img_Iface_Data_Rotate { + class cv::Point_ <float> center; + double angle; +}; + +struct Img_Iface_Data_Adaptive_Thr { + int method; + int thr_typ; + int ksize; +}; + +struct Img_Iface_Data_Cvt_Color { + int method; +}; + +struct Img_Iface_Data_Threshold { + int thr_typ; + int thr_val; +}; + +struct Img_Iface_Data_Histogram { + class cv::Mat *hist_c0; + class cv::Mat *hist_c1; + class cv::Mat *hist_c2; + class cv::Mat *hist_img; +}; + +struct Img_Iface_Data_Contours { + class std::vector <class std::vector <class cv::Point_ <int>>> *contours; + class cv::Mat *hierarchy; +}; + +struct Img_Iface_Data_Contours_Size { + const class std::vector <class std::vector <class cv::Point_ <int>>> *contours; + double *area; + double *perimeter; +}; + +struct Img_Iface_Data_Bounding_Rect { + const class std::vector <class cv::Point_ <int>> *contour; + class cv::Rect_ <int> *rect; + bool show; +}; + +struct Img_Iface_Data_MinARect { + const class std::vector <class cv::Point_ <int>> *contour; + class cv::RotatedRect *rect; + bool show; +}; + +struct Img_Iface_Data_Hough_Circles { + class std::vector <class cv::Vec <float, 3>> *circles; + double dist_min; + double param_1; + double param_2; + int radius_min; + int radius_max; +}; + +/* calib3d -------------------------------------------------------------------*/ +struct Img_Iface_Data_Calibrate { + class cv::Mat *intrinsic_mat; + class cv::Mat *dist_coefs; + class std::vector <class cv::Mat> *rvecs; + class std::vector <class cv::Mat> *tvecs; +}; + +struct Img_Iface_Data_Undistort { + const class cv::Mat *intrinsic_mat; + const class cv::Mat *dist_coefs; +}; + +/* zbar ----------------------------------------------------------------------*/ +struct Img_Iface_Data_Decode { + int code_type; +}; + +struct Img_Iface_ZB_Codes { + ptrdiff_t n; + struct { + int type; + char sym_name [80]; + char data [ZBAR_LEN_MAX]; + } arr [ZB_CODES_MAX]; +}; + +/* ocr -----------------------------------------------------------------------*/ +struct Img_Iface_Data_Read { + int lang; + int conf; + struct { + void *data; + ptrdiff_t width; + ptrdiff_t height; + int B_per_pix; + int B_per_line; + } img; +}; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +extern char img_ocr_text [OCR_TEXT_MAX]; +extern struct Img_Iface_ZB_Codes zb_codes; + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +extern "C" +{ +void img_iface_init (void); +void img_iface_deinit (void); +void img_iface_load (const char *fpath, const char *fname); +void img_iface_cleanup (void); +void img_iface_act (int action, const void *data); +void img_iface_show_img (void); +void img_iface_show_hist_c1 (void); +void img_iface_show_hist_c3 (void); +} + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/image/iface.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/image/ocr.h b/inc/vision-artificial/image/ocr.h new file mode 100644 index 0000000..adf30b9 --- /dev/null +++ b/inc/vision-artificial/image/ocr.h @@ -0,0 +1,64 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_IMAGE_OCR_H +#define VA_IMAGE_OCR_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Img_OCR_Action { + IMG_OCR_ACT_FOO = 0x000000u, + + IMG_OCR_ACT_OCR = 0x001000u, + IMG_OCR_ACT_READ +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void img_ocr_act (int action, const void *data); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/image/ocr.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_lighters.hpp b/inc/vision-artificial/image/ocr.hpp index 7d69dc6..7984152 100644 --- a/modules/proc/inc/proc_lighters.hpp +++ b/inc/vision-artificial/image/ocr.hpp @@ -7,8 +7,13 @@ /****************************************************************************** ******* include guard ******************************************************** ******************************************************************************/ -# ifndef VA_PROC_LIGHTERS_H - # define VA_PROC_LIGHTERS_H +#ifndef VA_IMG_OCR_HPP +#define VA_IMG_OCR_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ /****************************************************************************** @@ -19,40 +24,41 @@ /****************************************************************************** ******* enums **************************************************************** ******************************************************************************/ - enum Proc_Lighter { - LIGHTER_OK, - LIGHTER_NOK_LIGHTER, - LIGHTER_NOK_SIZE - }; +enum Img_OCR_Action { + IMG_OCR_ACT_FOO = 0x000000u, + + IMG_OCR_ACT_OCR = 0x001000u, + IMG_OCR_ACT_READ +}; /****************************************************************************** - ******* C wrapper ************************************************************ + ******* structs / unions ***************************************************** ******************************************************************************/ -extern "C" { /****************************************************************************** - ******* variables ************************************************************ + ******* extern functions ***************************************************** ******************************************************************************/ +extern "C" { +void img_ocr_act (int action, const void *data); +} /****************************************************************************** - ******* functions ************************************************************ + ******* static inline functions (prototypes) ********************************* ******************************************************************************/ -int proc_lighter (void); /****************************************************************************** - ******* C wrapper ************************************************************ + ******* static inline functions (definitions) ******************************** ******************************************************************************/ -} /* extern "C" */ /****************************************************************************** ******* include guard ******************************************************** ******************************************************************************/ -# endif /* proc_lighters.hpp */ +#endif /* vision-artificial/image/ocr.hpp */ /****************************************************************************** diff --git a/inc/vision-artificial/image/orb.hpp b/inc/vision-artificial/image/orb.hpp new file mode 100644 index 0000000..98f5b14 --- /dev/null +++ b/inc/vision-artificial/image/orb.hpp @@ -0,0 +1,71 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_IMAGE_ORB_HPP +#define VA_IMAGE_ORB_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include <opencv2/opencv.hpp> + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Img_ORB_Action { + IMG_ORB_ACT_FOO = 0x000000u, + + IMG_ORB_ACT_ORB = 0x000200u, + IMG_ORB_ACT_ALIGN +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void img_orb_act (const class cv::Mat *img_ref, + class cv::Mat *imgptr, int action); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/image/orb.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/image/zbar.hpp b/inc/vision-artificial/image/zbar.hpp new file mode 100644 index 0000000..6072289 --- /dev/null +++ b/inc/vision-artificial/image/zbar.hpp @@ -0,0 +1,70 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_IMAGE_ZBAR_HPP +#define VA_IMAGE_ZBAR_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include <opencv2/opencv.hpp> + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Img_ZB_Action { + IMG_ZB_ACT_FOO = 0x000000u, + + IMG_ZB_ACT_ZB = 0x000800u, + IMG_ZB_ACT_DECODE +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void img_zb_act (class cv::Mat *imgptr, int action, const void *data); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/image/zbar.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/menu/clui.h b/inc/vision-artificial/menu/clui.h new file mode 100644 index 0000000..02ac0d5 --- /dev/null +++ b/inc/vision-artificial/menu/clui.h @@ -0,0 +1,63 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_MENU_CLUI_H +#define VA_MENU_CLUI_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void menu_clui (void); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/menu/clui.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/inc/proc_iface.hpp b/inc/vision-artificial/menu/iface.h index a0d0f7d..e671c8d 100644 --- a/modules/proc/inc/proc_iface.hpp +++ b/inc/vision-artificial/menu/iface.h @@ -7,8 +7,8 @@ /****************************************************************************** ******* include guard ******************************************************** ******************************************************************************/ -# ifndef VA_PROC_IFACE_H - # define VA_PROC_IFACE_H +#ifndef VA_MENU_IFACE_H +#define VA_MENU_IFACE_H /****************************************************************************** @@ -24,60 +24,44 @@ /****************************************************************************** ******* 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 + enum Menu_Iface_Mode { + MENU_IFACE_FOO = 0, + MENU_IFACE_CLUI, + MENU_IFACE_TUI }; /****************************************************************************** - ******* C wrapper ************************************************************ + ******* structs / unions ***************************************************** ******************************************************************************/ -extern "C" { /****************************************************************************** ******* variables ************************************************************ ******************************************************************************/ -extern int proc_debug; -extern int proc_mode; +extern int menu_iface_mode; + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void menu_iface (void); /****************************************************************************** - ******* functions ************************************************************ + ******* static inline functions (prototypes) ********************************* ******************************************************************************/ -int proc_iface_single (int action); -void proc_iface_series (void); /****************************************************************************** - ******* C wrapper ************************************************************ + ******* static inline functions (definitions) ******************************** ******************************************************************************/ -} /* extern "C" */ /****************************************************************************** ******* include guard ******************************************************** ******************************************************************************/ -# endif /* proc_iface.h */ +#endif /* vision-artificial/menu/iface.h */ /****************************************************************************** diff --git a/inc/vision-artificial/menu/iface.hpp b/inc/vision-artificial/menu/iface.hpp new file mode 100644 index 0000000..825c1eb --- /dev/null +++ b/inc/vision-artificial/menu/iface.hpp @@ -0,0 +1,72 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_MENU_IFACE_HPP +#define VA_MENU_IFACE_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + enum Menu_Iface_Mode { + MENU_IFACE_FOO = 0, + MENU_IFACE_CLUI, + MENU_IFACE_TUI + }; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +extern int menu_iface_mode; + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +extern "C" +{ +void menu_iface (void); +} + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/menu/iface.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/menu/parse.h b/inc/vision-artificial/menu/parse.h new file mode 100644 index 0000000..9bd1182 --- /dev/null +++ b/inc/vision-artificial/menu/parse.h @@ -0,0 +1,63 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_PARSE_H +#define VA_PARSE_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void parse (int argc, char *argv[]); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/menu/parse.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/menu/parse.hpp b/inc/vision-artificial/menu/parse.hpp new file mode 100644 index 0000000..85dcbef --- /dev/null +++ b/inc/vision-artificial/menu/parse.hpp @@ -0,0 +1,66 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +# ifndef VA_PARSER_HPP + # define VA_PARSER_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +extern "C" +{ +void parse (int argc, char *argv[]); +} + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/menu/parse.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/menu/tui.h b/inc/vision-artificial/menu/tui.h new file mode 100644 index 0000000..a55ab49 --- /dev/null +++ b/inc/vision-artificial/menu/tui.h @@ -0,0 +1,63 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_MENU_TUI_H +#define VA_MENU_TUI_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void menu_tui (void); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/menu/tui.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/proc/coins.h b/inc/vision-artificial/proc/coins.h new file mode 100644 index 0000000..74c7ede --- /dev/null +++ b/inc/vision-artificial/proc/coins.h @@ -0,0 +1,69 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_PROC_COINS_H +#define VA_PROC_COINS_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Proc_Coins { + COINS_OK, + COINS_NOK_COINS, + COINS_NOK_OVERLAP, + COINS_NOK_SIZE +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +int proc_coins (void); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/proc/coins.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/proc/coins.hpp b/inc/vision-artificial/proc/coins.hpp new file mode 100644 index 0000000..d64486e --- /dev/null +++ b/inc/vision-artificial/proc/coins.hpp @@ -0,0 +1,72 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_PROC_COINS_HPP +#define VA_PROC_COINS_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Proc_Coins { + COINS_OK, + COINS_NOK_COINS, + COINS_NOK_OVERLAP, + COINS_NOK_SIZE +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +extern "C" +{ +int proc_coins (void); +} + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/proc/coins.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/proc/common.h b/inc/vision-artificial/proc/common.h new file mode 100644 index 0000000..f5844fc --- /dev/null +++ b/inc/vision-artificial/proc/common.h @@ -0,0 +1,65 @@ +/****************************************************************************** + * 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/modules/proc/inc/proc_common.hpp b/inc/vision-artificial/proc/common.hpp index 4dc8ee1..0b65f05 100644 --- a/modules/proc/inc/proc_common.hpp +++ b/inc/vision-artificial/proc/common.hpp @@ -7,8 +7,18 @@ /****************************************************************************** ******* include guard ******************************************************** ******************************************************************************/ -# ifndef VA_PROC_COMMON_HPP - # define VA_PROC_COMMON_HPP +#ifndef VA_PROC_COMMON_HPP +#define VA_PROC_COMMON_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include <cstdbool> + +#include <vector> + +#include <opencv2/opencv.hpp> /****************************************************************************** @@ -22,9 +32,8 @@ /****************************************************************************** - ******* C wrapper ************************************************************ + ******* structs / unions ***************************************************** ******************************************************************************/ -extern "C" { /****************************************************************************** @@ -33,11 +42,13 @@ extern "C" { /****************************************************************************** - ******* functions ************************************************************ + ******* extern functions ***************************************************** ******************************************************************************/ +extern "C" +{ void proc_apply (void); -void proc_save_mem (int n); -void proc_load_mem (int n); +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); @@ -48,8 +59,8 @@ void proc_lines_vertical (void); void proc_median_horizontal (void); void proc_median_vertical (void); -void proc_pixel_get (int x, int y, unsigned char *val); -void proc_pixel_set (int x, int y, unsigned char val); +void proc_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); @@ -61,7 +72,7 @@ void proc_dilate_erode (int size); void proc_erode_dilate (int size); void proc_smooth (int method, int ksize); void proc_border (int size); -void proc_rotate (double center_x, double center_y, double angle); +void proc_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); @@ -90,21 +101,25 @@ 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) ********************************* + ******************************************************************************/ /****************************************************************************** - ******* C wrapper ************************************************************ + ******* static inline functions (definitions) ******************************** ******************************************************************************/ -} /* extern "C" */ /****************************************************************************** ******* include guard ******************************************************** ******************************************************************************/ -# endif /* proc_common.hpp */ +#endif /* vision-artificial/proc/common.hpp */ /****************************************************************************** diff --git a/inc/vision-artificial/proc/iface.h b/inc/vision-artificial/proc/iface.h new file mode 100644 index 0000000..267809c --- /dev/null +++ b/inc/vision-artificial/proc/iface.h @@ -0,0 +1,88 @@ +/****************************************************************************** + * 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 new file mode 100644 index 0000000..ce54ead --- /dev/null +++ b/inc/vision-artificial/proc/iface.hpp @@ -0,0 +1,91 @@ +/****************************************************************************** + * 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 new file mode 100644 index 0000000..0731ada --- /dev/null +++ b/inc/vision-artificial/proc/label.h @@ -0,0 +1,71 @@ +/****************************************************************************** + * 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 new file mode 100644 index 0000000..e4a2adf --- /dev/null +++ b/inc/vision-artificial/proc/label.hpp @@ -0,0 +1,74 @@ +/****************************************************************************** + * 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 new file mode 100644 index 0000000..1b6eea4 --- /dev/null +++ b/inc/vision-artificial/proc/lighters.h @@ -0,0 +1,68 @@ +/****************************************************************************** + * 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 new file mode 100644 index 0000000..daf3ac0 --- /dev/null +++ b/inc/vision-artificial/proc/lighters.hpp @@ -0,0 +1,71 @@ +/****************************************************************************** + * 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 new file mode 100644 index 0000000..32e57ff --- /dev/null +++ b/inc/vision-artificial/proc/objects.h @@ -0,0 +1,70 @@ +/****************************************************************************** + * 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 new file mode 100644 index 0000000..405ef82 --- /dev/null +++ b/inc/vision-artificial/proc/objects.hpp @@ -0,0 +1,73 @@ +/****************************************************************************** + * 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/modules/proc/inc/proc_resistor.hpp b/inc/vision-artificial/proc/resistor.h index 31f70cf..51dd735 100644 --- a/modules/proc/inc/proc_resistor.hpp +++ b/inc/vision-artificial/proc/resistor.h @@ -7,8 +7,13 @@ /****************************************************************************** ******* include guard ******************************************************** ******************************************************************************/ -# ifndef VA_PROC_RESISTOR_HPP - # define VA_PROC_RESISTOR_HPP +#ifndef VA_PROC_RESISTOR_H +#define VA_PROC_RESISTOR_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ /****************************************************************************** @@ -19,20 +24,19 @@ /****************************************************************************** ******* enums **************************************************************** ******************************************************************************/ - enum Proc_Resistor { - RESISTOR_OK, - RESISTOR_NOK_RESISTOR, - RESISTOR_NOK_BANDS, - RESISTOR_NOK_COLOR, - RESISTOR_NOK_STD_VALUE, - RESISTOR_NOK_TOLERANCE - }; +enum Proc_Resistor { + RESISTOR_OK, + RESISTOR_NOK_RESISTOR, + RESISTOR_NOK_BANDS, + RESISTOR_NOK_COLOR, + RESISTOR_NOK_STD_VALUE, + RESISTOR_NOK_TOLERANCE +}; /****************************************************************************** - ******* C wrapper ************************************************************ + ******* structs / unions ***************************************************** ******************************************************************************/ -extern "C" { /****************************************************************************** @@ -41,21 +45,25 @@ extern "C" { /****************************************************************************** - ******* functions ************************************************************ + ******* extern functions ***************************************************** ******************************************************************************/ int proc_resistor (void); /****************************************************************************** - ******* C wrapper ************************************************************ + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** ******************************************************************************/ -} /* extern "C" */ /****************************************************************************** ******* include guard ******************************************************** ******************************************************************************/ -# endif /* proc_resistor.hpp */ +#endif /* vision-artificial/proc/resistor.h */ /****************************************************************************** diff --git a/inc/vision-artificial/proc/resistor.hpp b/inc/vision-artificial/proc/resistor.hpp new file mode 100644 index 0000000..d69908e --- /dev/null +++ b/inc/vision-artificial/proc/resistor.hpp @@ -0,0 +1,74 @@ +/****************************************************************************** + * 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/modules/save/inc/save.h b/inc/vision-artificial/save/save.h index 4ab65ab..87bddae 100644 --- a/modules/save/inc/save.h +++ b/inc/vision-artificial/save/save.h @@ -7,36 +7,44 @@ /****************************************************************************** ******* include guard ******************************************************** ******************************************************************************/ -# ifndef VA_SAVE_H - # define VA_SAVE_H +#ifndef VA_SAVE_SAVE_H +#define VA_SAVE_SAVE_H /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* FILENAME_MAX */ - #include <stdio.h> +#include <stdio.h> /****************************************************************************** ******* macros *************************************************************** ******************************************************************************/ - # define ENV_HOME "HOME" - - # define USER_PROG_DIR "vision-artificial/" - # define USER_SAVED_DIR "vision-artificial/saved/" - # define USER_LABELS_DIR "vision-artificial/labels/" - # define USER_LABELS_FAIL_DIR "vision-artificial/labels/fail" - # define USER_LIGHTERS_DIR "vision-artificial/lighters/" - # define USER_LIGHTERS_FAIL_DIR "vision-artificial/lighters/fail" - # define USER_OBJECTS_DIR "vision-artificial/objects/" - # define USER_OBJECTS_FAIL_DIR "vision-artificial/objects/fail" - # define USER_COINS_DIR "vision-artificial/coins/" - # define USER_COINS_FAIL_DIR "vision-artificial/coins/fail" - # define USER_RESISTORS_DIR "vision-artificial/resistors/" - # define USER_RESISTORS_FAIL_DIR "vision-artificial/resistors/fail" - # define SAVED_NAME_DEFAULT "saved" +#define ENV_HOME "HOME" + +#define USER_PROG_DIR "vision-artificial/" +#define USER_SAVED_DIR "vision-artificial/saved/" +#define USER_LABELS_DIR "vision-artificial/labels/" +#define USER_LABELS_FAIL_DIR "vision-artificial/labels/fail" +#define USER_LIGHTERS_DIR "vision-artificial/lighters/" +#define USER_LIGHTERS_FAIL_DIR "vision-artificial/lighters/fail" +#define USER_OBJECTS_DIR "vision-artificial/objects/" +#define USER_OBJECTS_FAIL_DIR "vision-artificial/objects/fail" +#define USER_COINS_DIR "vision-artificial/coins/" +#define USER_COINS_FAIL_DIR "vision-artificial/coins/fail" +#define USER_RESISTORS_DIR "vision-artificial/resistors/" +#define USER_RESISTORS_FAIL_DIR "vision-artificial/resistors/fail" +#define SAVED_NAME_DEFAULT "saved" + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ /****************************************************************************** @@ -59,19 +67,31 @@ extern char saved_name [FILENAME_MAX]; /****************************************************************************** - ******* functions ************************************************************ + ******* extern functions ***************************************************** ******************************************************************************/ void save_init (void); void save_cleanup (void); -void save_clr (void); -void load_image_file (const char *fpath, const char *fname); -void save_image_file (const char *fpath, const char *save_as); +void save_reset_fpath(void); +void load_image_file (const char *restrict fpath, + const char *restrict fname); +void save_image_file (const char *restrict fpath, + const char *restrict save_as); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ /****************************************************************************** ******* include guard ******************************************************** ******************************************************************************/ -# endif /* save.h */ +#endif /* vision-artificial/save/save.h */ /****************************************************************************** diff --git a/modules/save/inc/save.hpp b/inc/vision-artificial/save/save.hpp index bf60bca..aa05474 100644 --- a/modules/save/inc/save.hpp +++ b/inc/vision-artificial/save/save.hpp @@ -7,26 +7,18 @@ /****************************************************************************** ******* include guard ******************************************************** ******************************************************************************/ -# ifndef VA_SAVE_HPP - # define VA_SAVE_HPP +#ifndef VA_SAVE_SAVE_HPP +#define VA_SAVE_SAVE_HPP /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* FILENAME_MAX */ - #include <cstdio> +#include <cstdio> -/* Project -------------------------------------------------------------------*/ - /* opencv */ - #include <opencv2/opencv.hpp> +#include <opencv2/opencv.hpp> - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { +#include "libalx/base/stddef/restrict.hpp" /****************************************************************************** @@ -50,6 +42,16 @@ extern "C" { /****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** ******* variables ************************************************************ ******************************************************************************/ extern class cv::Mat image; @@ -70,25 +72,32 @@ extern char saved_name [FILENAME_MAX]; /****************************************************************************** - ******* functions ************************************************************ + ******* extern functions ***************************************************** ******************************************************************************/ +extern "C" +{ void save_init (void); void save_cleanup (void); -void save_clr (void); +void save_reset_fpath(void); void load_image_file (const char *fpath, const char *fname); void save_image_file (const char *fpath, const char *save_as); +} + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ /****************************************************************************** - ******* C wrapper ************************************************************ + ******* static inline functions (definitions) ******************************** ******************************************************************************/ -} /* extern "C" */ /****************************************************************************** ******* include guard ******************************************************** ******************************************************************************/ -# endif /* save.hpp */ +#endif /* vision-artificial/save/save.hpp */ /****************************************************************************** diff --git a/modules/proc/inc/proc_coins.hpp b/inc/vision-artificial/user/clui.h index f1b0824..158c019 100644 --- a/modules/proc/inc/proc_coins.hpp +++ b/inc/vision-artificial/user/clui.h @@ -7,53 +7,51 @@ /****************************************************************************** ******* include guard ******************************************************** ******************************************************************************/ -# ifndef VA_PROC_COINS_HPP - # define VA_PROC_COINS_HPP +#ifndef VA_USER_CLUI_H +#define VA_USER_CLUI_H /****************************************************************************** - ******* macros *************************************************************** + ******* headers ************************************************************** ******************************************************************************/ /****************************************************************************** - ******* enums **************************************************************** + ******* macros *************************************************************** ******************************************************************************/ - enum Proc_Coins { - COINS_OK, - COINS_NOK_COINS, - COINS_NOK_OVERLAP, - COINS_NOK_SIZE - }; /****************************************************************************** - ******* C wrapper ************************************************************ + ******* enums **************************************************************** ******************************************************************************/ -extern "C" { /****************************************************************************** - ******* variables ************************************************************ + ******* structs / unions ***************************************************** ******************************************************************************/ /****************************************************************************** - ******* functions ************************************************************ + ******* variables ************************************************************ ******************************************************************************/ -int proc_coins (void); /****************************************************************************** - ******* C wrapper ************************************************************ + ******* extern functions ***************************************************** ******************************************************************************/ -} /* extern "C" */ +int user_clui (const char *restrict title, + const char *restrict subtitle); +void user_clui_fname (const char *restrict fpath, + char *restrict fname); +void user_clui_show_log (const char *restrict title, + const char *restrict subtitle); +void user_clui_show_ocr (void); /****************************************************************************** ******* include guard ******************************************************** ******************************************************************************/ -# endif /* proc_coins.hpp */ +#endif /* vision-artificial/user/clui.h */ /****************************************************************************** diff --git a/inc/vision-artificial/user/iface.h b/inc/vision-artificial/user/iface.h new file mode 100644 index 0000000..887493f --- /dev/null +++ b/inc/vision-artificial/user/iface.h @@ -0,0 +1,182 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_USER_IFACE_H +#define VA_USER_IFACE_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include <stddef.h> +#include <stdint.h> + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +#define LOG_LEN (0xFFFFF) +#define LOG_LINE_LEN (80) + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Player_Iface_Mode { + USER_IFACE_FOO, + USER_IFACE_CLUI, + USER_IFACE_TUI +}; + +enum Player_Iface_Action { + USER_IFACE_ACT_FOO = 0x000000u, + + USER_IFACE_ACT_ALX = 0x000010u, + USER_IFACE_ACT_LOCAL_MAX, + USER_IFACE_ACT_SKELETON, + USER_IFACE_ACT_LINES_HORIZONTAL, + USER_IFACE_ACT_LINES_VERTICAL, + USER_IFACE_ACT_MEAN_HORIZONTAL, + USER_IFACE_ACT_MEAN_VERTICAL, + USER_IFACE_ACT_MEDIAN_HORIZONTAL, + USER_IFACE_ACT_MEDIAN_VERTICAL, + + USER_IFACE_ACT_CV = 0x000100u, + USER_IFACE_ACT_PIXEL_GET, + USER_IFACE_ACT_PIXEL_SET, + USER_IFACE_ACT_SET_ROI, + USER_IFACE_ACT_SET_ROI_2RECT, + USER_IFACE_ACT_AND_2REF, + USER_IFACE_ACT_NOT, + USER_IFACE_ACT_OR_2REF, + USER_IFACE_ACT_COMPONENT, + USER_IFACE_ACT_DILATE, + USER_IFACE_ACT_ERODE, + USER_IFACE_ACT_DILATE_ERODE, + USER_IFACE_ACT_ERODE_DILATE, + USER_IFACE_ACT_SMOOTH, + USER_IFACE_ACT_SOBEL, + USER_IFACE_ACT_BORDER, + USER_IFACE_ACT_MIRROR, + USER_IFACE_ACT_ROTATE_ORTO, + USER_IFACE_ACT_ROTATE, + USER_IFACE_ACT_ROTATE_2RECT, + USER_IFACE_ACT_ADAPTIVE_THRESHOLD, + USER_IFACE_ACT_CVT_COLOR, + USER_IFACE_ACT_DISTANCE_TRANSFORM, + USER_IFACE_ACT_THRESHOLD, + USER_IFACE_ACT_HISTOGRAM, + USER_IFACE_ACT_HISTOGRAM_C3, + USER_IFACE_ACT_CONTOURS, + USER_IFACE_ACT_CONTOURS_SIZE, + USER_IFACE_ACT_BOUNDING_RECT, + USER_IFACE_ACT_FIT_ELLIPSE, + USER_IFACE_ACT_MIN_AREA_RECT, + USER_IFACE_ACT_HOUGH_CIRCLES, + + USER_IFACE_ACT_ORB = 0x000200u, + USER_IFACE_ACT_ALIGN, + + USER_IFACE_ACT_CALIB3D = 0x000400u, + USER_IFACE_ACT_CALIBRATE, + USER_IFACE_ACT_UNDISTORT, + + USER_IFACE_ACT_ZB = 0x000800u, + USER_IFACE_ACT_DECODE, + + USER_IFACE_ACT_OCR = 0x001000u, + USER_IFACE_ACT_READ, + + USER_IFACE_ACT_IMGI = 0x002000u, + USER_IFACE_ACT_APPLY, + USER_IFACE_ACT_DISCARD, + USER_IFACE_ACT_SAVE_MEM, + USER_IFACE_ACT_LOAD_MEM, + USER_IFACE_ACT_SAVE_REF, + + USER_IFACE_ACT_SAVE = 0x004000u, + USER_IFACE_ACT_SAVE_FILE, + USER_IFACE_ACT_SAVE_UPDT, + + USER_IFACE_ACT_PROC = 0x008000u, + USER_IFACE_ACT_PROC_LABEL_SERIES, + USER_IFACE_ACT_PROC_LABEL_CALIB, + USER_IFACE_ACT_PROC_OBJECTS_SERIES, + USER_IFACE_ACT_PROC_OBJECTS_CALIB, + USER_IFACE_ACT_PROC_COINS_SERIES, + USER_IFACE_ACT_PROC_COINS_CALIB, + USER_IFACE_ACT_PROC_RESISTOR_SERIES, + USER_IFACE_ACT_PROC_RESISTOR_CALIB, + USER_IFACE_ACT_PROC_LIGHTERS_SERIES, + USER_IFACE_ACT_PROC_LIGHTERS_CALIB, + + USER_IFACE_ACT_USRI = 0x010000u, + USER_IFACE_ACT_SHOW_OCR, + USER_IFACE_ACT_QUIT +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ +struct User_Iface_Log { + ptrdiff_t len; + ptrdiff_t pos; + char line[LOG_LEN][LOG_LINE_LEN]; + uint8_t lvl[LOG_LEN]; + uint8_t visible; +}; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +extern int user_iface_mode; +extern struct User_Iface_Log user_iface_log; + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void user_iface_init (void); +void user_iface_cleanup (void); +void user_iface (void); +void user_iface_show_log (const char *restrict title, + const char *restrict subtitle); +void user_iface_fname (const char *restrict filepath, + char *restrict filename); +double user_iface_getdbl (double m, double def, double M, + const char *restrict title, + const char *restrict help); +int user_iface_getint (double m, int64_t def, double M, + const char *restrict title, + const char *restrict help); +void user_iface_log_write (ptrdiff_t lvl, const char *restrict msg); +const char *user_iface_log_read (void); + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/user/iface.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/user/iface.hpp b/inc/vision-artificial/user/iface.hpp new file mode 100644 index 0000000..a22c96c --- /dev/null +++ b/inc/vision-artificial/user/iface.hpp @@ -0,0 +1,187 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_USER_IFACE_HPP +#define VA_USER_IFACE_HPP + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include <cstddef> +#include <cstdint> + +#include "libalx/base/stddef/restrict.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +#define LOG_LEN (0xFFFFF) +#define LOG_LINE_LEN (80) + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Player_Iface_Mode { + USER_IFACE_FOO, + USER_IFACE_CLUI, + USER_IFACE_TUI +}; + +enum Player_Iface_Action { + USER_IFACE_ACT_FOO = 0x000000u, + + USER_IFACE_ACT_ALX = 0x000010u, + USER_IFACE_ACT_LOCAL_MAX, + USER_IFACE_ACT_SKELETON, + USER_IFACE_ACT_LINES_HORIZONTAL, + USER_IFACE_ACT_LINES_VERTICAL, + USER_IFACE_ACT_MEAN_HORIZONTAL, + USER_IFACE_ACT_MEAN_VERTICAL, + USER_IFACE_ACT_MEDIAN_HORIZONTAL, + USER_IFACE_ACT_MEDIAN_VERTICAL, + + USER_IFACE_ACT_CV = 0x000100u, + USER_IFACE_ACT_PIXEL_GET, + USER_IFACE_ACT_PIXEL_SET, + USER_IFACE_ACT_SET_ROI, + USER_IFACE_ACT_SET_ROI_2RECT, + USER_IFACE_ACT_AND_2REF, + USER_IFACE_ACT_NOT, + USER_IFACE_ACT_OR_2REF, + USER_IFACE_ACT_COMPONENT, + USER_IFACE_ACT_DILATE, + USER_IFACE_ACT_ERODE, + USER_IFACE_ACT_DILATE_ERODE, + USER_IFACE_ACT_ERODE_DILATE, + USER_IFACE_ACT_SMOOTH, + USER_IFACE_ACT_SOBEL, + USER_IFACE_ACT_BORDER, + USER_IFACE_ACT_MIRROR, + USER_IFACE_ACT_ROTATE_ORTO, + USER_IFACE_ACT_ROTATE, + USER_IFACE_ACT_ROTATE_2RECT, + USER_IFACE_ACT_ADAPTIVE_THRESHOLD, + USER_IFACE_ACT_CVT_COLOR, + USER_IFACE_ACT_DISTANCE_TRANSFORM, + USER_IFACE_ACT_THRESHOLD, + USER_IFACE_ACT_HISTOGRAM, + USER_IFACE_ACT_HISTOGRAM_C3, + USER_IFACE_ACT_CONTOURS, + USER_IFACE_ACT_CONTOURS_SIZE, + USER_IFACE_ACT_BOUNDING_RECT, + USER_IFACE_ACT_FIT_ELLIPSE, + USER_IFACE_ACT_MIN_AREA_RECT, + USER_IFACE_ACT_HOUGH_CIRCLES, + + USER_IFACE_ACT_ORB = 0x000200u, + USER_IFACE_ACT_ALIGN, + + USER_IFACE_ACT_CALIB3D = 0x000400u, + USER_IFACE_ACT_CALIBRATE, + USER_IFACE_ACT_UNDISTORT, + + USER_IFACE_ACT_ZB = 0x000800u, + USER_IFACE_ACT_DECODE, + + USER_IFACE_ACT_OCR = 0x001000u, + USER_IFACE_ACT_READ, + + USER_IFACE_ACT_IMGI = 0x002000u, + USER_IFACE_ACT_APPLY, + USER_IFACE_ACT_DISCARD, + USER_IFACE_ACT_SAVE_MEM, + USER_IFACE_ACT_LOAD_MEM, + USER_IFACE_ACT_SAVE_REF, + + USER_IFACE_ACT_SAVE = 0x004000u, + USER_IFACE_ACT_SAVE_FILE, + USER_IFACE_ACT_SAVE_UPDT, + + USER_IFACE_ACT_PROC = 0x008000u, + USER_IFACE_ACT_PROC_LABEL_SERIES, + USER_IFACE_ACT_PROC_LABEL_CALIB, + USER_IFACE_ACT_PROC_OBJECTS_SERIES, + USER_IFACE_ACT_PROC_OBJECTS_CALIB, + USER_IFACE_ACT_PROC_COINS_SERIES, + USER_IFACE_ACT_PROC_COINS_CALIB, + USER_IFACE_ACT_PROC_RESISTOR_SERIES, + USER_IFACE_ACT_PROC_RESISTOR_CALIB, + USER_IFACE_ACT_PROC_LIGHTERS_SERIES, + USER_IFACE_ACT_PROC_LIGHTERS_CALIB, + + USER_IFACE_ACT_USRI = 0x010000u, + USER_IFACE_ACT_SHOW_OCR, + USER_IFACE_ACT_QUIT +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ +struct User_Iface_Log { + ptrdiff_t len; + ptrdiff_t pos; + char line[LOG_LEN][LOG_LINE_LEN]; + uint8_t lvl[LOG_LEN]; + uint8_t visible; +}; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +extern int user_iface_mode; +extern struct User_Iface_Log user_iface_log; + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +extern "C" +{ +void user_iface_init (void); +void user_iface_cleanup (void); +void user_iface (void); +void user_iface_show_log (const char *restrict title, + const char *restrict subtitle); +void user_iface_fname (const char *restrict filepath, + char *restrict filename); +double user_iface_getdbl (double m, double def, double M, + const char *restrict title, + const char *restrict help); +int user_iface_getint (double m, int64_t def, double M, + const char *restrict title, + const char *restrict help); +void user_iface_log_write (ptrdiff_t lvl, const char *restrict msg); +const char *user_iface_log_read (void); +} + + +/****************************************************************************** + ******* static inline functions (prototypes) ********************************* + ******************************************************************************/ + + +/****************************************************************************** + ******* static inline functions (definitions) ******************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/user/iface.hpp */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/inc/vision-artificial/user/tui.h b/inc/vision-artificial/user/tui.h new file mode 100644 index 0000000..1be58c9 --- /dev/null +++ b/inc/vision-artificial/user/tui.h @@ -0,0 +1,67 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#ifndef VA_USER_TUI_H +#define VA_USER_TUI_H + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* extern functions ***************************************************** + ******************************************************************************/ +void user_tui_init (void); +void user_tui_cleanup (void); +int user_tui (const char *restrict title, + const char *restrict subtitle); +void user_tui_show_log (const char *restrict title, + const char *restrict subtitle); +void user_tui_fname (const char *restrict fpath, + char *restrict fname); +double user_tui_getdbl (double m, double def, double M, + const char *restrict title, + const char *restrict help); +int user_tui_getint (int m, int def, int M, + const char *restrict title, + const char *restrict help); +void user_tui_show_ocr (void); + + +/****************************************************************************** + ******* include guard ******************************************************** + ******************************************************************************/ +#endif /* vision-artificial/user/tui.h */ + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/libalx b/libalx -Subproject 3e83ecf11efc99fbba7e6b4a09c071ec20e87dd +Subproject d95dd760ac01bd2000f0a38d0a1cc9fa2c1125f diff --git a/modules/Makefile b/modules/Makefile deleted file mode 100644 index 61b5871..0000000 --- a/modules/Makefile +++ /dev/null @@ -1,66 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -ABOUT_DIR = $(MODULES_DIR)/about/ -CTRL_DIR = $(MODULES_DIR)/ctrl/ -IMG_DIR = $(MODULES_DIR)/image/ -MENU_DIR = $(MODULES_DIR)/menu/ -PROC_DIR = $(MODULES_DIR)/proc/ -SAVE_DIR = $(MODULES_DIR)/save/ -USR_DIR = $(MODULES_DIR)/user/ - -TMP_DIR = $(MODULES_DIR)/tmp/ - -export ABOUT_DIR -export CTRL_DIR -export IMG_DIR -export MENU_DIR -export PROC_DIR -export SAVE_DIR -export USR_DIR - -# dependencies - - -# target: dependencies -# action - -PHONY := all -all: - @echo ' MAKE modules: about' - $(Q)$(MAKE) -C $(ABOUT_DIR) - @echo ' MAKE modules: ctrl' - $(Q)$(MAKE) -C $(CTRL_DIR) - @echo ' MAKE modules: image' - $(Q)$(MAKE) -C $(IMG_DIR) - @echo ' MAKE modules: menu' - $(Q)$(MAKE) -C $(MENU_DIR) - @echo ' MAKE modules: proc' - $(Q)$(MAKE) -C $(PROC_DIR) - @echo ' MAKE modules: save' - $(Q)$(MAKE) -C $(SAVE_DIR) - @echo ' MAKE modules: usr' - $(Q)$(MAKE) -C $(USR_DIR) - @echo ' MAKE modules.o' - $(Q)$(MAKE) -C $(TMP_DIR) - - -PHONY += clean -clean: - @echo " RM *.o *.s" - $(Q)find . -type f -name '*.o' -exec rm '{}' '+' - $(Q)find . -type f -name '*.s' -exec rm '{}' '+' - -################################################################################ -# Declare the contents of the .PHONY variable as phony. -.PHONY: $(PHONY) - - - - -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/modules/about/Makefile b/modules/about/Makefile deleted file mode 100644 index c1c25ef..0000000 --- a/modules/about/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -TMP_DIR = $(ABOUT_DIR)/tmp/ - -# target: dependencies -# action - -all: - $(Q)cd $(TMP_DIR) && $(MAKE) && cd .. - -clean: - $(Q)cd $(TMP_DIR) && $(MAKE) clean && cd .. - -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/modules/about/tmp/Makefile b/modules/about/tmp/Makefile deleted file mode 100644 index 21afd1b..0000000 --- a/modules/about/tmp/Makefile +++ /dev/null @@ -1,49 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -LIBALX_INC_DIR = $(LIBALX_DIR)/inc/ - -INC_DIR = $(ABOUT_DIR)/inc/ -SRC_DIR = $(ABOUT_DIR)/src/ - -# dependencies - -_ALL = about.o -ALL = $(_ALL) about_mod.o - -ABOU_INC_LIBALX = libalx/io/alx_file.h -ABOU_INC = about.h -ABOU_DEPS = $(SRC_DIR)/about.c \ - $(patsubst %,$(LIBALX_INC_DIR)/%,$(ABOU_INC_LIBALX)) \ - $(patsubst %,$(INC_DIR)/%,$(ABOU_INC)) -ABOU_INC_DIRS = -I $(INC_DIR) \ - -I $(LIBALX_INC_DIR) - -# target: dependencies -# action - -all: $(ALL) - - -about_mod.o: $(_ALL) - @echo " LD $@" - $(Q)$(LD) -r $^ -o $@ - - -about.s: $(ABOU_DEPS) - @echo " CC $@" - $(Q)$(CC) $(CFLAGS) $(ABOU_INC_DIRS) -S $< -o $@ -about.o: about.s - @echo " AS $@" - $(Q)$(AS) $< -o $@ - - -clean: - $(Q)rm -f *.o *.s - -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/modules/ctrl/Makefile b/modules/ctrl/Makefile deleted file mode 100644 index 966cac1..0000000 --- a/modules/ctrl/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -TMP_DIR = $(CTRL_DIR)/tmp/ - -# target: dependencies -# action - -PHONY := all -all: - $(Q)$(MAKE) -C $(TMP_DIR) - - -PHONY += clean -clean: - $(Q)$(MAKE) clean -C $(TMP_DIR) - -################################################################################ -# Declare the contents of the .PHONY variable as phony. -.PHONY: $(PHONY) - - - - -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/modules/ctrl/inc/start.h b/modules/ctrl/inc/start.h deleted file mode 100644 index e8273f1..0000000 --- a/modules/ctrl/inc/start.h +++ /dev/null @@ -1,44 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_START_H - # define VA_START_H - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Start_Mode { - START_FOO = 0, - START_SINGLE, - START_SERIES - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - extern int start_mode; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ - void start_switch (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* start.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/ctrl/tmp/Makefile b/modules/ctrl/tmp/Makefile deleted file mode 100644 index 4859f7c..0000000 --- a/modules/ctrl/tmp/Makefile +++ /dev/null @@ -1,70 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -IMG_INC_DIR = $(IMG_DIR)/inc/ -PROC_INC_DIR = $(PROC_DIR)/inc/ -SAVE_INC_DIR = $(SAVE_DIR)/inc/ -USR_INC_DIR = $(USR_DIR)/inc/ - -INC_DIR = $(CTRL_DIR)/inc/ -SRC_DIR = $(CTRL_DIR)/src/ - -# dependencies - -_ALL = start.o -ALL = $(_ALL) ctrl_mod.o - -STRT_INC_IMG = img_iface.h -STRT_INC_PROC = proc_iface.h -STRT_INC_SAVE = save.h -STRT_INC_USR = user_iface.h -STRT_INC = start.h -STRT_DEPS = $(SRC_DIR)/start.c \ - $(patsubst %,$(IMG_INC_DIR)/%,$(STRT_INC_IMG)) \ - $(patsubst %,$(PROC_INC_DIR)/%,$(STRT_INC_PROC)) \ - $(patsubst %,$(SAVE_INC_DIR)/%,$(STRT_INC_SAVE)) \ - $(patsubst %,$(USR_INC_DIR)/%,$(STRT_INC_USR)) \ - $(patsubst %,$(INC_DIR)/%,$(STRT_INC)) -STRT_INC_DIRS = -I $(INC_DIR) \ - -I $(IMG_INC_DIR) \ - -I $(PROC_INC_DIR) \ - -I $(SAVE_INC_DIR) \ - -I $(USR_INC_DIR) - -# target: dependencies -# action - -PHONY := all -all: $(ALL) - - -ctrl_mod.o: $(_ALL) - $(Q)$(LD) -r $^ -o $@ - @echo " LD $@" - - -start.s: $(STRT_DEPS) - $(Q)$(CC) $(CFLAGS) $(STRT_INC_DIRS) -S $< -o $@ - @echo " CC $@" -start.o: start.s - $(Q)$(AS) $< -o $@ - @echo " AS $@" - - -PHONY += clean -clean: - $(Q)rm -f *.o *.s - -################################################################################ -# Declare the contents of the .PHONY variable as phony. -.PHONY: $(PHONY) - - - - -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/modules/image/Makefile b/modules/image/Makefile deleted file mode 100644 index 58a5792..0000000 --- a/modules/image/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -TMP_DIR = $(IMG_DIR)/tmp/ - -# target: dependencies -# action - -all: - $(Q)cd $(TMP_DIR) && $(MAKE) && cd .. - -clean: - $(Q)cd $(TMP_DIR) && $(MAKE) clean && cd .. - -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/modules/image/inc/img_alx.hpp b/modules/image/inc/img_alx.hpp deleted file mode 100644 index 0c2558a..0000000 --- a/modules/image/inc/img_alx.hpp +++ /dev/null @@ -1,53 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_ALX_H - # define VA_IMG_ALX_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - /* openCV */ - #include <opencv2/opencv.hpp> - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_Alx_Action { - IMG_ALX_ACT_FOO = 0x000000u, - - IMG_ALX_ACT_ALX = 0x000010u, - IMG_ALX_ACT_LOCAL_MAX, - IMG_ALX_ACT_SKELETON, - IMG_ALX_ACT_LINES_HORIZONTAL, - IMG_ALX_ACT_LINES_VERTICAL, - IMG_ALX_ACT_MEAN_HORIZONTAL, - IMG_ALX_ACT_MEAN_VERTICAL, - IMG_ALX_ACT_MEDIAN_HORIZONTAL, - IMG_ALX_ACT_MEDIAN_VERTICAL - }; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void img_alx_act (class cv::Mat *imgptr, int action, const void *data); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_alx.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/image/inc/img_calib3d.hpp b/modules/image/inc/img_calib3d.hpp deleted file mode 100644 index a2c9f7c..0000000 --- a/modules/image/inc/img_calib3d.hpp +++ /dev/null @@ -1,47 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_CALIB3D_HPP - # define VA_IMG_CALIB3D_HPP - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - /* openCV */ - #include <opencv2/opencv.hpp> - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_Calib3d_Action { - IMG_CALIB3D_ACT_FOO = 0x000000u, - - IMG_CALIB3D_ACT_CALIB3D = 0x000400u, - IMG_CALIB3D_ACT_CALIBRATE, - IMG_CALIB3D_ACT_UNDISTORT - }; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void img_calib3d_act (class cv::Mat *imgptr, int action, const void *data); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_calib3d.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/image/inc/img_iface.h b/modules/image/inc/img_iface.h deleted file mode 100644 index 1b755aa..0000000 --- a/modules/image/inc/img_iface.h +++ /dev/null @@ -1,185 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_IFACE_H - # define VA_IMG_IFACE_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <stddef.h> - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ -/* Constants -----------------------------------------------------------------*/ - # define CONTOURS_MAX (65536) - # define OCR_TEXT_MAX (1048576) - # define ZB_CODES_MAX (10) - # define ZBAR_LEN_MAX (1048576) - - # define IMG_IFACE_THR_OTSU (-1) - -/* Functions -----------------------------------------------------------------*/ - # define img_iface_act_nodata(x) img_iface_act(x, NULL) - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_Iface_Action { - IMG_IFACE_ACT_FOO = 0x000000u, - - IMG_IFACE_ACT_ALX = 0x000010u, - IMG_IFACE_ACT_LOCAL_MAX, - IMG_IFACE_ACT_SKELETON, - IMG_IFACE_ACT_LINES_HORIZONTAL, - IMG_IFACE_ACT_LINES_VERTICAL, - IMG_IFACE_ACT_MEAN_HORIZONTAL, - IMG_IFACE_ACT_MEAN_VERTICAL, - IMG_IFACE_ACT_MEDIAN_HORIZONTAL, - IMG_IFACE_ACT_MEDIAN_VERTICAL, - - IMG_IFACE_ACT_CV = 0x000100u, - IMG_IFACE_ACT_PIXEL_GET, - IMG_IFACE_ACT_PIXEL_SET, - IMG_IFACE_ACT_SET_ROI, - IMG_IFACE_ACT_SET_ROI_2RECT, - IMG_IFACE_ACT_AND_2REF, - IMG_IFACE_ACT_NOT, - IMG_IFACE_ACT_OR_2REF, - IMG_IFACE_ACT_COMPONENT, - IMG_IFACE_ACT_DILATE, - IMG_IFACE_ACT_ERODE, - IMG_IFACE_ACT_DILATE_ERODE, - IMG_IFACE_ACT_ERODE_DILATE, - IMG_IFACE_ACT_SMOOTH, - IMG_IFACE_ACT_SOBEL, - IMG_IFACE_ACT_BORDER, - IMG_IFACE_ACT_MIRROR, - IMG_IFACE_ACT_ROTATE_ORTO, - IMG_IFACE_ACT_ROTATE, - IMG_IFACE_ACT_ROTATE_2RECT, - IMG_IFACE_ACT_ADAPTIVE_THRESHOLD, - IMG_IFACE_ACT_CVT_COLOR, - IMG_IFACE_ACT_DISTANCE_TRANSFORM, - IMG_IFACE_ACT_THRESHOLD, - IMG_IFACE_ACT_HISTOGRAM, - IMG_IFACE_ACT_HISTOGRAM_C3, - IMG_IFACE_ACT_CONTOURS, - IMG_IFACE_ACT_CONTOURS_SIZE, - IMG_IFACE_ACT_BOUNDING_RECT, - IMG_IFACE_ACT_FIT_ELLIPSE, - IMG_IFACE_ACT_MIN_AREA_RECT, - IMG_IFACE_ACT_HOUGH_CIRCLES, - - IMG_IFACE_ACT_ORB = 0x000200u, - IMG_IFACE_ACT_ALIGN, - - IMG_IFACE_ACT_CALIB3D = 0x000400u, - IMG_IFACE_ACT_CALIBRATE, - IMG_IFACE_ACT_UNDISTORT, - - IMG_IFACE_ACT_ZB = 0x000800u, - IMG_IFACE_ACT_DECODE, - - IMG_IFACE_ACT_OCR = 0x001000u, - IMG_IFACE_ACT_READ, - - IMG_IFACE_ACT_IMGI = 0x002000u, - IMG_IFACE_ACT_APPLY, - IMG_IFACE_ACT_DISCARD, - IMG_IFACE_ACT_SAVE_MEM, - IMG_IFACE_ACT_LOAD_MEM, - IMG_IFACE_ACT_SAVE_REF, - - IMG_IFACE_ACT_SAVE = 0x004000u, - IMG_IFACE_ACT_SAVE_FILE, - IMG_IFACE_ACT_SAVE_UPDT - }; - - enum Img_Iface_Cmp_BGR { - IMG_IFACE_CMP_BLUE = 0, - IMG_IFACE_CMP_GREEN, - IMG_IFACE_CMP_RED - }; - - enum Img_Iface_Cmp_HSV { - IMG_IFACE_CMP_HUE = 0, - IMG_IFACE_CMP_SATURATION, - IMG_IFACE_CMP_VALUE - }; - - enum ImgI_Smooth { - IMGI_SMOOTH_MEAN = 0, - IMGI_SMOOTH_GAUSS, - IMGI_SMOOTH_MEDIAN - }; - - enum Img_Iface_OCR_Lang { - IMG_IFACE_OCR_LANG_ENG = 0, - IMG_IFACE_OCR_LANG_SPA, - IMG_IFACE_OCR_LANG_CAT, - IMG_IFACE_OCR_LANG_DIGITS, - IMG_IFACE_OCR_LANG_DIGITS_COMMA - }; - - enum Img_Iface_OCR_Conf { - IMG_IFACE_OCR_CONF_NONE = 0, - IMG_IFACE_OCR_CONF_PRICE - }; - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ - struct Img_Iface_Data_Read { - int lang; - int conf; - struct { - void *data; - int width; - int height; - int B_per_pix; - int B_per_line; - } img; - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern char img_ocr_text [OCR_TEXT_MAX]; -extern struct Img_Iface_ZB_Codes zb_codes; - - -/****************************************************************************** -******* functions ************************************************************ -******************************************************************************/ -void img_iface_cleanup_main (void); -void img_iface_load (const char *fpath, const char *fname); -void img_iface_cleanup (void); -void img_iface_act (int action, const void *data); -void img_iface_show_img (void); -void img_iface_show_hist_c1 (void); -void img_iface_show_hist_c3 (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_iface.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/image/inc/img_iface.hpp b/modules/image/inc/img_iface.hpp deleted file mode 100644 index fb80451..0000000 --- a/modules/image/inc/img_iface.hpp +++ /dev/null @@ -1,344 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_IFACE_HPP - # define VA_IMG_IFACE_HPP - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <cstddef> - -/* Standard C++ --------------------------------------------------------------*/ - /* class std::vector */ - #include <vector> - -/* Packages ------------------------------------------------------------------*/ - /* opencv */ - #include <opencv2/opencv.hpp> - /* zbar */ - #include <zbar.h> - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define CONTOURS_MAX (65536) - # define OCR_TEXT_MAX (1048576) - # define ZB_CODES_MAX (10) - # define ZBAR_LEN_MAX (1048576) - - # define IMG_IFACE_THR_OTSU (-1) - -/* Functions -----------------------------------------------------------------*/ - # define img_iface_act_nodata(x) \ - do { \ - img_iface_act(x, NULL); \ - } while (0) - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_Iface_Action { - IMG_IFACE_ACT_FOO = 0x000000u, - - IMG_IFACE_ACT_ALX = 0x000010u, - IMG_IFACE_ACT_LOCAL_MAX, - IMG_IFACE_ACT_SKELETON, - IMG_IFACE_ACT_LINES_HORIZONTAL, - IMG_IFACE_ACT_LINES_VERTICAL, - IMG_IFACE_ACT_MEAN_HORIZONTAL, - IMG_IFACE_ACT_MEAN_VERTICAL, - IMG_IFACE_ACT_MEDIAN_HORIZONTAL, - IMG_IFACE_ACT_MEDIAN_VERTICAL, - - IMG_IFACE_ACT_CV = 0x000100u, - IMG_IFACE_ACT_PIXEL_GET, - IMG_IFACE_ACT_PIXEL_SET, - IMG_IFACE_ACT_SET_ROI, - IMG_IFACE_ACT_SET_ROI_2RECT, - IMG_IFACE_ACT_AND_2REF, - IMG_IFACE_ACT_NOT, - IMG_IFACE_ACT_OR_2REF, - IMG_IFACE_ACT_COMPONENT, - IMG_IFACE_ACT_DILATE, - IMG_IFACE_ACT_ERODE, - IMG_IFACE_ACT_DILATE_ERODE, - IMG_IFACE_ACT_ERODE_DILATE, - IMG_IFACE_ACT_SMOOTH, - IMG_IFACE_ACT_SOBEL, - IMG_IFACE_ACT_BORDER, - IMG_IFACE_ACT_MIRROR, - IMG_IFACE_ACT_ROTATE_ORTO, - IMG_IFACE_ACT_ROTATE, - IMG_IFACE_ACT_ROTATE_2RECT, - IMG_IFACE_ACT_ADAPTIVE_THRESHOLD, - IMG_IFACE_ACT_CVT_COLOR, - IMG_IFACE_ACT_DISTANCE_TRANSFORM, - IMG_IFACE_ACT_THRESHOLD, - IMG_IFACE_ACT_HISTOGRAM, - IMG_IFACE_ACT_HISTOGRAM_C3, - IMG_IFACE_ACT_CONTOURS, - IMG_IFACE_ACT_CONTOURS_SIZE, - IMG_IFACE_ACT_BOUNDING_RECT, - IMG_IFACE_ACT_FIT_ELLIPSE, - IMG_IFACE_ACT_MIN_AREA_RECT, - IMG_IFACE_ACT_HOUGH_CIRCLES, - - IMG_IFACE_ACT_ORB = 0x000200u, - IMG_IFACE_ACT_ALIGN, - - IMG_IFACE_ACT_CALIB3D = 0x000400u, - IMG_IFACE_ACT_CALIBRATE, - IMG_IFACE_ACT_UNDISTORT, - - IMG_IFACE_ACT_ZB = 0x000800u, - IMG_IFACE_ACT_DECODE, - - IMG_IFACE_ACT_OCR = 0x001000u, - IMG_IFACE_ACT_READ, - - IMG_IFACE_ACT_IMGI = 0x002000u, - IMG_IFACE_ACT_APPLY, - IMG_IFACE_ACT_DISCARD, - IMG_IFACE_ACT_SAVE_MEM, - IMG_IFACE_ACT_LOAD_MEM, - IMG_IFACE_ACT_SAVE_REF, - - IMG_IFACE_ACT_SAVE = 0x004000u, - IMG_IFACE_ACT_SAVE_FILE, - IMG_IFACE_ACT_SAVE_UPDT - }; - - enum Img_Iface_Cmp { - IMG_IFACE_CMP_BLUE = 0, - IMG_IFACE_CMP_GREEN, - IMG_IFACE_CMP_RED - }; - - enum Img_Iface_Cmp_HSV { - IMG_IFACE_CMP_HUE = 0, - IMG_IFACE_CMP_SATURATION, - IMG_IFACE_CMP_VALUE - }; - - enum ImgI_Smooth { - IMGI_SMOOTH_MEAN = 1, - IMGI_SMOOTH_GAUSS, - IMGI_SMOOTH_MEDIAN - }; - - enum Img_Iface_OCR_Lang { - IMG_IFACE_OCR_LANG_ENG = 0, - IMG_IFACE_OCR_LANG_SPA, - IMG_IFACE_OCR_LANG_CAT, - IMG_IFACE_OCR_LANG_DIGITS, - IMG_IFACE_OCR_LANG_DIGITS_COMMA - }; - - enum Img_Iface_OCR_Conf { - IMG_IFACE_OCR_CONF_NONE = 0, - IMG_IFACE_OCR_CONF_PRICE - }; - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ -/* img_cv --------------------------------------------------------------------*/ - struct Img_Iface_Data_Pixel_Get { - unsigned char *val; - int x; - int y; - }; - - struct Img_Iface_Data_Pixel_Set { - unsigned char val; - int x; - int y; - }; - - struct Img_Iface_Data_SetROI { - class cv::Rect_ <int> rect; - }; - - struct Img_Iface_Data_Component { - int cmp; - }; - - struct Img_Iface_Data_Dilate_Erode { - int i; - }; - - struct Img_Iface_Data_Smooth { - int method; - int ksize; - }; - - struct Img_Iface_Data_Sobel { - int dx; - int dy; - int ksize; - }; - - struct Img_Iface_Data_Border { - int size; - }; - - struct Img_Iface_Data_Mirror { - int axis; - }; - - struct Img_Iface_Data_Rotate_Orto { - int n; - }; - - struct Img_Iface_Data_Rotate { - class cv::Point_ <float> center; - double angle; - }; - - struct Img_Iface_Data_Adaptive_Thr { - int method; - int thr_typ; - int ksize; - }; - - struct Img_Iface_Data_Cvt_Color { - int method; - }; - - struct Img_Iface_Data_Threshold { - int thr_typ; - int thr_val; - }; - - struct Img_Iface_Data_Histogram { - class cv::Mat *hist_c0; - class cv::Mat *hist_c1; - class cv::Mat *hist_c2; - class cv::Mat *hist_img; - }; - - struct Img_Iface_Data_Contours { - class std::vector <class std::vector <class cv::Point_ <int>>> *contours; - class cv::Mat *hierarchy; - }; - - struct Img_Iface_Data_Contours_Size { - const class std::vector <class std::vector <class cv::Point_ <int>>> *contours; - double *area; - double *perimeter; - }; - - struct Img_Iface_Data_Bounding_Rect { - const class std::vector <class cv::Point_ <int>> *contour; - class cv::Rect_ <int> *rect; - bool show; - }; - - struct Img_Iface_Data_MinARect { - const class std::vector <class cv::Point_ <int>> *contour; - class cv::RotatedRect *rect; - bool show; - }; - - struct Img_Iface_Data_Hough_Circles { - class std::vector <class cv::Vec <float, 3>> *circles; - double dist_min; - double param_1; - double param_2; - int radius_min; - int radius_max; - }; - -/* img_calib3d ---------------------------------------------------------------*/ - struct Img_Iface_Data_Calibrate { - class cv::Mat *intrinsic_mat; - class cv::Mat *dist_coefs; - class std::vector <class cv::Mat> *rvecs; - class std::vector <class cv::Mat> *tvecs; - }; - - struct Img_Iface_Data_Undistort { - const class cv::Mat *intrinsic_mat; - const class cv::Mat *dist_coefs; - }; - -/* img_zbar -------------------------------------------------------------------*/ - struct Img_Iface_Data_Decode { - enum zbar::zbar_symbol_type_e code_type; - }; - - struct Img_Iface_ZB_Codes { - int n; - struct { - enum zbar::zbar_symbol_type_e type; - char sym_name [80]; - char data [ZBAR_LEN_MAX]; - } arr [ZB_CODES_MAX]; - }; - -/* img_ocr -------------------------------------------------------------------*/ - struct Img_Iface_Data_Read { - int lang; - int conf; - struct { - void *data; - int width; - int height; - int B_per_pix; - int B_per_line; - } img; - }; - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern char img_ocr_text [OCR_TEXT_MAX]; -extern struct Img_Iface_ZB_Codes zb_codes; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void img_iface_cleanup_main (void); -void img_iface_load (const char *fpath, const char *fname); -void img_iface_cleanup (void); -void img_iface_act (int action, const void *data); -void img_iface_show_img (void); -void img_iface_show_hist_c1 (void); -void img_iface_show_hist_c3 (void); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_iface.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/image/inc/img_ocr.h b/modules/image/inc/img_ocr.h deleted file mode 100644 index febe2dd..0000000 --- a/modules/image/inc/img_ocr.h +++ /dev/null @@ -1,39 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_OCR_H - # define VA_IMG_OCR_H - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_OCR_Action { - IMG_OCR_ACT_FOO = 0x000000u, - - IMG_OCR_ACT_OCR = 0x001000u, - IMG_OCR_ACT_READ - }; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void img_ocr_act (int action, const void *data); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_ocr.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/image/inc/img_ocr.hpp b/modules/image/inc/img_ocr.hpp deleted file mode 100644 index 6791a36..0000000 --- a/modules/image/inc/img_ocr.hpp +++ /dev/null @@ -1,51 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_OCR_HPP - # define VA_IMG_OCR_HPP - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_OCR_Action { - IMG_OCR_ACT_FOO = 0x000000u, - - IMG_OCR_ACT_OCR = 0x001000u, - IMG_OCR_ACT_READ - }; - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void img_ocr_act (int action, const void *data); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_ocr.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/image/inc/img_orb.hpp b/modules/image/inc/img_orb.hpp deleted file mode 100644 index 9f6a1c3..0000000 --- a/modules/image/inc/img_orb.hpp +++ /dev/null @@ -1,47 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_ORB_HPP - # define VA_IMG_ORB_HPP - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - /* openCV */ - #include <opencv2/opencv.hpp> - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_ORB_Action { - IMG_ORB_ACT_FOO = 0x000000u, - - IMG_ORB_ACT_ORB = 0x000200u, - IMG_ORB_ACT_ALIGN - }; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void img_orb_act (const class cv::Mat *img_ref, - class cv::Mat *imgptr, int action); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_orb.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/image/inc/img_zbar.hpp b/modules/image/inc/img_zbar.hpp deleted file mode 100644 index b9a5143..0000000 --- a/modules/image/inc/img_zbar.hpp +++ /dev/null @@ -1,47 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_IMG_ZBAR_H - # define VA_IMG_ZBAR_H - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Packages ------------------------------------------------------------------*/ - /* openCV */ - #include <opencv2/opencv.hpp> - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Img_ZB_Action { - IMG_ZB_ACT_FOO = 0x000000u, - - IMG_ZB_ACT_ZB = 0x000800u, - IMG_ZB_ACT_DECODE - }; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void img_zb_act (class cv::Mat *imgptr, int action, const void *data); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* img_zbar.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/image/src/img_alx.cpp b/modules/image/src/img_alx.cpp deleted file mode 100644 index e832b5d..0000000 --- a/modules/image/src/img_alx.cpp +++ /dev/null @@ -1,370 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: (GPL-2.0-only OR LGPL-3.0-only) * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <cstdbool> - #include <cstdlib> - #include <cstdio> -/* Packages ------------------------------------------------------------------*/ - #include <opencv2/opencv.hpp> -/* libalx --------------------------------------------------------------------*/ - #include "libalx/alx_math.hpp" -/* Module --------------------------------------------------------------------*/ - #include "img_iface.hpp" - - #include "img_alx.hpp" - - -/****************************************************************************** - ******* static functions (prototypes) **************************************** - ******************************************************************************/ -static void img_alx_local_max (class cv::Mat *imgptr); -static void img_alx_skeleton (class cv::Mat *imgptr); -static void img_alx_lines_horizontal (class cv::Mat *imgptr); -static void img_alx_lines_vertical (class cv::Mat *imgptr); -static void img_alx_mean_horizontal (class cv::Mat *imgptr); -static void img_alx_mean_vertical (class cv::Mat *imgptr); -static void img_alx_median_horizontal (class cv::Mat *imgptr); -static void img_alx_median_vertical (class cv::Mat *imgptr); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -void img_alx_act (class cv::Mat *imgptr, int action, const void *data) -{ - - switch (action) { - case IMG_ALX_ACT_LOCAL_MAX: - img_alx_local_max(imgptr); - break; - case IMG_ALX_ACT_SKELETON: - img_alx_skeleton(imgptr); - break; - - case IMG_ALX_ACT_LINES_HORIZONTAL: - img_alx_lines_horizontal(imgptr); - break; - case IMG_ALX_ACT_LINES_VERTICAL: - img_alx_lines_vertical(imgptr); - break; - - case IMG_ALX_ACT_MEAN_HORIZONTAL: - img_alx_mean_horizontal(imgptr); - break; - case IMG_ALX_ACT_MEAN_VERTICAL: - img_alx_mean_vertical(imgptr); - break; - case IMG_ALX_ACT_MEDIAN_HORIZONTAL: - img_alx_median_horizontal(imgptr); - break; - case IMG_ALX_ACT_MEDIAN_VERTICAL: - img_alx_median_vertical(imgptr); - break; - } -} - - -/****************************************************************************** - ******* static functions (definitions) *************************************** - ******************************************************************************/ -static void img_alx_local_max (class cv::Mat *imgptr) -{ - int i; - int j; - int k; - int l; - /* Minimum distance between local maxima */ - const int dist_min = 16; - /* Minimum value of local maxima */ - const int val_min = 16; - class cv::Mat imgtmp; - - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - /* pointer to a pixel near img_pix (in imgptr) */ - uint8_t *near_pix; - /* pointer to a pixel (same position as img_pix, but in imgtmp) */ - uint8_t *tmp_pix; - - /* Tmp image copy */ - imgptr->copyTo(imgtmp); - - for (i = 0; i < imgptr->rows; i++) { - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - tmp_pix = imgtmp.data + i * imgptr->step + j; - - if (*img_pix < val_min) { - goto next_pixel; - } - - for (k = (i - dist_min); k < (i + dist_min + 1); k++) { - for (l = (j - dist_min); l < (j + dist_min + 1); l++) { - near_pix = imgptr->data + k * imgptr->step + l; - if ((k >= 0) && (k < imgptr->rows)) { - if ((l >= 0) && (l < imgptr->cols)) { - if (*img_pix < *near_pix) { - goto next_pixel; - } - } - } - } - } - - *tmp_pix = *img_pix; - continue; - -next_pixel: - *tmp_pix = 0; - } - } - - /* Cleanup */ - imgtmp.copyTo(*imgptr); - imgtmp.release(); -} - -static void img_alx_skeleton (class cv::Mat *imgptr) -{ - /* (Half of the) width of the skeleton */ - const int width = 5; - int dist_x; - int dist_y; - bool skeleton; - int cnt_lo [width]; - int cnt_hi_or_eq [width]; - class cv::Mat imgtmp; - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - /* pointer to a pixel near img_pix (in imgptr) */ - uint8_t *near_pix; - /* pointer to a pixel (same position as img_pix, but in imgtmp) */ - uint8_t *tmp_pix; - - int i; - int j; - int k; - int l; - int r; - - /* Tmp image copy */ - imgptr->copyTo(imgtmp); - - for (i = 0; i < imgptr->rows; i++) { - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - tmp_pix = imgtmp.data + i * imgptr->step + j; - - if (!(*img_pix)) { - *tmp_pix = 0; - continue; - } - - for (r = 0; r < width; r++) { - cnt_lo[r] = 0; - cnt_hi_or_eq[r] = 0; - } - - for (k = i - width; k <= i + width; k++) { - for (l = j - width; l <= j + width; l++) { - near_pix = imgptr->data + k * imgptr->step + l; - - dist_x = abs(k - i); - dist_y = abs(l - j); - - if ((k >= 0) && (k < imgptr->rows)) { - if ((l >= 0) && (l < imgptr->cols)) { - if (dist_x || dist_y) { - if (*near_pix < *img_pix) { - cnt_lo[std::max(dist_x, dist_y)]++; - } else { - cnt_hi_or_eq[std::max(dist_x, dist_y)]++; - } - } - } - } - - } - } - - skeleton = false; - for (r = 0; r < width; r++) { - if (cnt_lo[r] > (cnt_hi_or_eq[r] + (1.6) * (r + 1))) { - skeleton = true; - } - } - - if (skeleton) { - *tmp_pix = *img_pix; - } else { - *tmp_pix = 0; - } - } - } - - /* Cleanup */ - imgtmp.copyTo(*imgptr); - imgtmp.release(); -} - -static void img_alx_lines_horizontal (class cv::Mat *imgptr) -{ - int i; - int j; - bool white; - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - - for (i = 0; i < imgptr->rows; i++) { - white = false; - - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - if (*img_pix) { - white = true; - break; - } - } - - if (white) { - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - *img_pix = 255; - } - } - } -} - -static void img_alx_lines_vertical (class cv::Mat *imgptr) -{ - int i; - int j; - bool white; - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - - for (i = 0; i < imgptr->cols; i++) { - white = false; - - for (j = 0; j < imgptr->rows; j++) { - img_pix = imgptr->data + j * imgptr->step + i; - if (*img_pix) { - white = true; - break; - } - } - - if (white) { - for (j = 0; j < imgptr->rows; j++) { - img_pix = imgptr->data + j * imgptr->step + i; - *img_pix = 255; - } - } - } -} - -static void img_alx_mean_horizontal (class cv::Mat *imgptr) -{ - int i; - int j; - uint32_t tmp; - uint8_t mean; - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - - for (i = 0; i < imgptr->rows; i++) { - tmp = 0; - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - tmp += *img_pix; - } - mean = tmp / imgptr->cols; - - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - *img_pix = mean; - } - } -} - -static void img_alx_mean_vertical (class cv::Mat *imgptr) -{ - int i; - int j; - uint32_t tmp; - uint8_t mean; - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - - for (i = 0; i < imgptr->cols; i++) { - tmp = 0; - for (j = 0; j < imgptr->rows; j++) { - img_pix = imgptr->data + j * imgptr->step + i; - tmp += *img_pix; - } - mean = tmp / imgptr->rows; - - for (j = 0; j < imgptr->rows; j++) { - img_pix = imgptr->data + j * imgptr->step + i; - *img_pix = mean; - } - } -} - -static void img_alx_median_horizontal (class cv::Mat *imgptr) -{ - int i; - int j; - uint8_t row [imgptr->cols]; - uint8_t median; - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - - for (i = 0; i < imgptr->rows; i++) { - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - row[j] = *img_pix; - } - median = alx_median_u8(imgptr->cols, row); - - for (j = 0; j < imgptr->cols; j++) { - img_pix = imgptr->data + i * imgptr->step + j; - *img_pix = median; - } - } -} - -static void img_alx_median_vertical (class cv::Mat *imgptr) -{ - int i; - int j; - uint8_t col [imgptr->rows]; - uint8_t median; - /* pointer to a pixel (in imgptr) */ - uint8_t *img_pix; - - for (i = 0; i < imgptr->cols; i++) { - for (j = 0; j < imgptr->rows; j++) { - img_pix = imgptr->data + j * imgptr->step + i; - col[j] = *img_pix; - } - median = alx_median_u8(imgptr->rows, col); - - for (j = 0; j < imgptr->rows; j++) { - img_pix = imgptr->data + j * imgptr->step + i; - *img_pix = median; - } - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/image/src/img_iface.cpp b/modules/image/src/img_iface.cpp deleted file mode 100644 index 4411920..0000000 --- a/modules/image/src/img_iface.cpp +++ /dev/null @@ -1,2032 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <cerrno> - #include <cmath> - #include <cstddef> - #include <cstdio> -/* Standard C++ --------------------------------------------------------------*/ - #include <vector> -/* Packages ------------------------------------------------------------------*/ - #include <opencv2/opencv.hpp> -/* Project -------------------------------------------------------------------*/ - #include "save.hpp" - #include "user_iface.hpp" -/* Module --------------------------------------------------------------------*/ - #include "img_alx.hpp" - #include "img_cv.hpp" - #include "img_orb.hpp" - #include "img_calib3d.hpp" - #include "img_zbar.hpp" - #include "img_ocr.hpp" - - #include "img_iface.hpp" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define IMG_MEM_SIZE (20) - - # define WIN_NAME_IMG "Image" - # define WIN_NAME_HIST "Hist" - # define WIN_TIMEOUT (500) - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ - char img_ocr_text [OCR_TEXT_MAX]; - struct Img_Iface_ZB_Codes zb_codes; - -/* Static --------------------------------------------------------------------*/ -static class cv::Mat image_copy_old; -static class cv::Mat image_copy_tmp; -static class cv::Mat image_mem [IMG_MEM_SIZE]; -static class cv::Mat image_ref; -static class cv::Mat histogram_c0; -static class cv::Mat histogram_c1; -static class cv::Mat histogram_c2; -static class cv::Mat hist_img_c1; -static class cv::Mat hist_img_c3; -static class std::vector <class std::vector <cv::Point_ <int>>> contours; -static double area [CONTOURS_MAX]; -static double perimeter [CONTOURS_MAX]; -static class cv::Mat hierarchy; -static class cv::Rect_ <int> rectangle; -static class cv::RotatedRect rectangle_rot; -static class std::vector <class cv::Vec <float, 3>> circles; -static class cv::Mat intrinsic_mat; -static class cv::Mat dist_coefs; -static class std::vector <class cv::Mat> rvecs; -static class std::vector <class cv::Mat> tvecs; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ - /* img_alx */ -static void img_iface_local_max (void); -static void img_iface_skeleton (void); -static void img_iface_lines_horizontal (void); -static void img_iface_lines_vertical (void); -static void img_iface_mean_horizontal (void); -static void img_iface_mean_vertical (void); -static void img_iface_median_horizontal (void); -static void img_iface_median_vertical (void); - - /* img_cv */ - /* Core: The core functionality */ - /* Pixel */ -static void img_iface_pixel_get (const void *data); -static void img_iface_pixel_set (const void *data); - /* ROI */ -static void img_iface_set_ROI (const void *data); -static void img_iface_set_ROI_2rect (const void *data); - /* Operations on Arrays */ -static void img_iface_and_2ref (void); -static void img_iface_not (void); -static void img_iface_or_2ref (void); -static void img_iface_component (const void *data); - /* Imgproc: Image processing */ - /* Image filtering */ -static void img_iface_dilate (const void *data); -static void img_iface_erode (const void *data); -static void img_iface_dilate_erode (const void *data); -static void img_iface_erode_dilate (const void *data); -static void img_iface_smooth (const void *data); -static void img_iface_sobel (const void *data); -static void img_iface_border (const void *data); - /* Geometric image transformations */ -static void img_iface_mirror (const void *data); -static void img_iface_rotate_orto (const void *data); -static void img_iface_rotate (const void *data); -static void img_iface_rotate_2rect (const void *data); - /* Miscellaneous image transformations */ -static void img_iface_adaptive_thr (const void *data); -static void img_iface_cvt_color (const void *data); -static void img_iface_distance_transform (void); -static void img_iface_threshold (const void *data); - /* Histograms */ -static void img_iface_histogram (const void *data); -static void img_iface_histogram_c3 (const void *data); - /* Structural analysis and shape descriptors */ -static void img_iface_contours (const void *data); -static void img_iface_contours_size (const void *data); -static void img_iface_bounding_rect (const void *data); -static void img_iface_fit_ellipse (const void *data); -static void img_iface_min_area_rect (const void *data); - /* Feature detection */ -static void img_iface_hough_circles (const void *data); - - /* img_orb */ -static void img_iface_align (void); - /* img_calib3d */ -static void img_iface_calibrate (const void *data); -static void img_iface_undistort (const void *data); - - /* img_zbar */ -static void img_iface_decode (const void *data); - /* img_ocr */ -static void img_iface_read (const void *data); - - /* img_iface */ -static void img_iface_apply (void); -static void img_iface_discard (void); -static void img_iface_save_mem (const void *data); -static void img_iface_load_mem (const void *data); -static void img_iface_save_ref (void); - /* save */ -static void img_iface_save_file (void); -static void img_iface_save_update (void); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -void img_iface_init (void) -{ - cv::namedWindow(WIN_NAME_HIST, cv::WINDOW_NORMAL); - cv::namedWindow(WIN_NAME_IMG, cv::WINDOW_NORMAL); - - hist_img_c1.release(); - hist_img_c1 = cv::Mat::zeros(cv::Size(256, 100), CV_8UC3); - hist_img_c3.release(); - hist_img_c3 = cv::Mat::zeros(cv::Size(256 * 3, 100), CV_8UC3); -} - -void img_iface_cleanup_main (void) -{ - int i; - - for (i = 0; i < IMG_MEM_SIZE; i++) { - image_mem[i].release(); - } - image_ref.release(); - - cv::destroyAllWindows(); -} - -void img_iface_load (const char *fpath, const char *fname) -{ - char file_path [FILENAME_MAX]; - char file_name [FILENAME_MAX]; - - /* Init */ - img_iface_init(); - - /* Set file_path */ - if (!fpath) { - snprintf(file_path, FILENAME_MAX, "%s", saved_path); - } else { - snprintf(file_path, FILENAME_MAX, "%s", fpath); - } - - /* Set file_name */ - if (!fname) { - /* Request file name */ - user_iface_fname(file_path, file_name); - } else { - snprintf(file_name, FILENAME_MAX, "%s", fname); - } - - /* Load file */ - errno = 0; - load_image_file(file_path, file_name); - - if (!errno) { - /* Make a static copy of image */ - image.copyTo(image_copy_old); - image.copyTo(image_copy_tmp); - } -} - -void img_iface_cleanup (void) -{ - image_copy_old.release(); - image_copy_tmp.release(); - histogram_c0.release(); - histogram_c1.release(); - histogram_c2.release(); - hist_img_c1.release(); - hist_img_c3.release(); -} - -void img_iface_act (int action, const void *data) -{ - switch (action) { - /* img_alx */ - case IMG_IFACE_ACT_LOCAL_MAX: - img_iface_local_max(); - break; - case IMG_IFACE_ACT_SKELETON: - img_iface_skeleton(); - break; - case IMG_IFACE_ACT_LINES_HORIZONTAL: - img_iface_lines_horizontal(); - break; - case IMG_IFACE_ACT_LINES_VERTICAL: - img_iface_lines_vertical(); - break; - case IMG_IFACE_ACT_MEAN_HORIZONTAL: - img_iface_mean_horizontal(); - break; - case IMG_IFACE_ACT_MEAN_VERTICAL: - img_iface_mean_vertical(); - break; - case IMG_IFACE_ACT_MEDIAN_HORIZONTAL: - img_iface_median_horizontal(); - break; - case IMG_IFACE_ACT_MEDIAN_VERTICAL: - img_iface_median_vertical(); - break; - - /* img_cv */ - /* Core: The core functionality */ - /* Pixel */ - case IMG_IFACE_ACT_PIXEL_GET: - img_iface_pixel_get(data); - break; - case IMG_IFACE_ACT_PIXEL_SET: - img_iface_pixel_set(data); - break; - /* ROI */ - case IMG_IFACE_ACT_SET_ROI: - img_iface_set_ROI(data); - break; - case IMG_IFACE_ACT_SET_ROI_2RECT: - img_iface_set_ROI_2rect(data); - break; - /* Operations on Arrays */ - case IMG_IFACE_ACT_AND_2REF: - img_iface_and_2ref(); - break; - case IMG_IFACE_ACT_NOT: - img_iface_not(); - break; - case IMG_IFACE_ACT_OR_2REF: - img_iface_or_2ref(); - break; - case IMG_IFACE_ACT_COMPONENT: - img_iface_component(data); - break; - /* Imgproc: Image processing */ - /* Image filtering */ - case IMG_IFACE_ACT_DILATE: - img_iface_dilate(data); - break; - case IMG_IFACE_ACT_ERODE: - img_iface_erode(data); - break; - case IMG_IFACE_ACT_DILATE_ERODE: - img_iface_dilate_erode(data); - break; - case IMG_IFACE_ACT_ERODE_DILATE: - img_iface_erode_dilate(data); - break; - case IMG_IFACE_ACT_SMOOTH: - img_iface_smooth(data); - break; - case IMG_IFACE_ACT_SOBEL: - img_iface_sobel(data); - break; - case IMG_IFACE_ACT_BORDER: - img_iface_border(data); - break; - /* Geometric image transformations */ - case IMG_IFACE_ACT_MIRROR: - img_iface_mirror(data); - break; - case IMG_IFACE_ACT_ROTATE_ORTO: - img_iface_rotate_orto(data); - break; - case IMG_IFACE_ACT_ROTATE: - img_iface_rotate(data); - break; - case IMG_IFACE_ACT_ROTATE_2RECT: - img_iface_rotate_2rect(data); - break; - /* Miscellaneous image transformations */ - case IMG_IFACE_ACT_ADAPTIVE_THRESHOLD: - img_iface_adaptive_thr(data); - break; - case IMG_IFACE_ACT_CVT_COLOR: - img_iface_cvt_color(data); - break; - case IMG_IFACE_ACT_DISTANCE_TRANSFORM: - img_iface_distance_transform(); - break; - case IMG_IFACE_ACT_THRESHOLD: - img_iface_threshold(data); - break; - /* Histograms */ - case IMG_IFACE_ACT_HISTOGRAM: - img_iface_histogram(data); - break; - case IMG_IFACE_ACT_HISTOGRAM_C3: - img_iface_histogram_c3(data); - break; - /* Structural analysis and shape descriptors */ - case IMG_IFACE_ACT_CONTOURS: - img_iface_contours(data); - break; - case IMG_IFACE_ACT_CONTOURS_SIZE: - img_iface_contours_size(data); - break; - case IMG_IFACE_ACT_BOUNDING_RECT: - img_iface_bounding_rect(data); - break; - case IMG_IFACE_ACT_FIT_ELLIPSE: - img_iface_fit_ellipse(data); - break; - case IMG_IFACE_ACT_MIN_AREA_RECT: - img_iface_min_area_rect(data); - break; - /* Feature detection */ - case IMG_IFACE_ACT_HOUGH_CIRCLES: - img_iface_hough_circles(data); - break; - - /* img_orb */ - case IMG_IFACE_ACT_ALIGN: - img_iface_align(); - break; - - /* img_calib3d */ - case IMG_IFACE_ACT_CALIBRATE: - img_iface_calibrate(data); - break; - case IMG_IFACE_ACT_UNDISTORT: - img_iface_undistort(data); - break; - - /* img_zbar */ - case IMG_IFACE_ACT_DECODE: - img_iface_decode(data); - break; - - /* img_ocr */ - case IMG_IFACE_ACT_READ: - img_iface_read(data); - break; - - /* img_iface */ - case IMG_IFACE_ACT_APPLY: - img_iface_apply(); - break; - case IMG_IFACE_ACT_DISCARD: - img_iface_discard(); - break; - case IMG_IFACE_ACT_SAVE_MEM: - img_iface_save_mem(data); - break; - case IMG_IFACE_ACT_LOAD_MEM: - img_iface_load_mem(data); - break; - case IMG_IFACE_ACT_SAVE_REF: - img_iface_save_ref(); - break; - - /* save */ - case IMG_IFACE_ACT_SAVE_FILE: - img_iface_save_file(); - break; - case IMG_IFACE_ACT_SAVE_UPDT: - img_iface_save_update(); - break; - - default: - /* Invalid action */ - break; - } -} - -void img_iface_show_img (void) -{ - cv::imshow(WIN_NAME_IMG, image_copy_tmp); - cv::waitKey(WIN_TIMEOUT); -} - -void img_iface_show_hist_c1 (void) -{ - cv::imshow(WIN_NAME_HIST, hist_img_c1); - cv::waitKey(WIN_TIMEOUT); -} - -void img_iface_show_hist_c3 (void) -{ - cv::imshow(WIN_NAME_HIST, hist_img_c3); - cv::waitKey(WIN_TIMEOUT); -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -/* img_alx --------------------------------------------------------------------*/ -static void img_iface_local_max (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Invalid input"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - return; - } - - /* Local maxima */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_LOCAL_MAX, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Local maxima"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_skeleton (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Invalid input"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - return; - } - - /* Skeleton */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_SKELETON, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Skeleton"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_lines_horizontal (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Invalid input"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - return; - } - - /* Horizontal lines */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_LINES_HORIZONTAL, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Horizontal lines"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_lines_vertical (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Invalid input"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - return; - } - - /* Vertical lines */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_LINES_VERTICAL, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Vertical lines"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_mean_horizontal (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Invalid input"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - return; - } - - /* Horizontal lines */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEAN_HORIZONTAL, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Horizontal mean"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_mean_vertical (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Invalid input"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - return; - } - - /* Horizontal lines */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEAN_VERTICAL, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Vertical mean"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_median_horizontal (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Invalid input"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - return; - } - - /* Horizontal lines */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEDIAN_HORIZONTAL, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Horizontal median"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_median_vertical (void) -{ - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Invalid input"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - return; - } - - /* Horizontal lines */ - img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEDIAN_VERTICAL, NULL); - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Vertical median"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -/* img_cv --------------------------------------------------------------------*/ -/* ----- Core: The core functionality */ -/* ----- ------- Pixel */ -static void img_iface_pixel_get (const void *data) -{ - struct Img_Iface_Data_Pixel_Get data_tmp; - const struct Img_Iface_Data_Pixel_Get *data_cast; - unsigned char val; - char title [80]; - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Invalid input"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - return; - } - - /* Data */ - if (!data) { - data_tmp.val = &val; - - /* Ask user */ - snprintf(title, 80, "x:"); - data_tmp.x = user_iface_getint(0, 0, - image_copy_tmp.cols, - title, NULL); - - snprintf(title, 80, "y:"); - data_tmp.y = user_iface_getint(0, 0, - image_copy_tmp.rows, - title, NULL); - - data = (const void *)&data_tmp; - } - - /* Get pixel value */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_PIXEL_GET, data); - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Pixel_Get *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Pixel get: (%i, %i): %i", - data_cast->x, - data_cast->y, - *(data_cast->val)); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_pixel_set (const void *data) -{ - struct Img_Iface_Data_Pixel_Set data_tmp; - const struct Img_Iface_Data_Pixel_Set *data_cast; - char title [80]; - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Invalid input"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - return; - } - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "x:"); - data_tmp.x = user_iface_getint(0, 0, - image_copy_tmp.cols, - title, NULL); - - snprintf(title, 80, "y:"); - data_tmp.y = user_iface_getint(0, 0, - image_copy_tmp.rows, - title, NULL); - - snprintf(title, 80, "val:"); - data_tmp.val = user_iface_getint(0, 0, 255, - title, NULL); - - data = (const void *)&data_tmp; - } - - /* Set pixel value */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_PIXEL_SET, data); - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Pixel_Set *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Pixel get: (%i, %i): %i", - data_cast->x, - data_cast->y, - data_cast->val); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -/* ----- ------- ROI */ -static void img_iface_set_ROI (const void *data) -{ - struct Img_Iface_Data_SetROI data_tmp; - const struct Img_Iface_Data_SetROI *data_cast; - char title [80]; - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Origin: x:"); - data_tmp.rect.x = user_iface_getint(0, 0, - image_copy_tmp.cols, - title, NULL); - - snprintf(title, 80, "Origin: y:"); - data_tmp.rect.y = user_iface_getint(0, 0, - image_copy_tmp.rows, - title, NULL); - - snprintf(title, 80, "Width:"); - data_tmp.rect.width = user_iface_getint(1, - image_copy_tmp.cols - data_tmp.rect.x, - image_copy_tmp.cols - data_tmp.rect.x, - title, NULL); - - snprintf(title, 80, "Height:"); - data_tmp.rect.height = user_iface_getint(1, - image_copy_tmp.rows - data_tmp.rect.y, - image_copy_tmp.rows - data_tmp.rect.y, - title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_SetROI *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "ROI: (%i,%i) w=%i,h=%i", - data_cast->rect.x, - data_cast->rect.y, - data_cast->rect.width, - data_cast->rect.height); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Set ROI */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_SET_ROI, data); -} - -static void img_iface_set_ROI_2rect (const void *data) -{ - struct Img_Iface_Data_SetROI data_tmp; - const struct Img_Iface_Data_SetROI *data_cast; - - /* Data */ - if (!data) { - data_tmp.rect.x = rectangle.x; - data_tmp.rect.y = rectangle.y; - data_tmp.rect.width = rectangle.width; - data_tmp.rect.height = rectangle.height; - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_SetROI *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "ROI: (%i,%i) w=%i,h=%i", - data_cast->rect.x, - data_cast->rect.y, - data_cast->rect.width, - data_cast->rect.height); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Set ROI */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_SET_ROI, data); -} - -/* ----- ------- Operations on arrays */ -static void img_iface_and_2ref (void) -{ - - /* Must have same channels */ - if (image_copy_tmp.channels() != image_ref.channels()) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Invalid input"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - return; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Bitwise AND"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Bitwise AND to reference */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_AND_2REF, (const void *)&image_ref); -} - -static void img_iface_not (void) -{ - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Invert color"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Bitwise NOT */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_NOT, NULL); -} - -static void img_iface_or_2ref (void) -{ - - /* Must have same channels */ - if (image_copy_tmp.channels() != image_ref.channels()) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Invalid input"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - return; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Bitwise OR"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Bitwise OR to reference */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_OR_2REF, (const void *)&image_ref); -} - -static void img_iface_component (const void *data) -{ - struct Img_Iface_Data_Component data_tmp; - const struct Img_Iface_Data_Component *data_cast; - char title [80]; - - /* Must have at least 3 channels */ - if (image_copy_tmp.channels() < 3) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Invalid input"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - return; - } - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Component:"); - data_tmp.cmp = user_iface_getint(0, 0, - image_copy_tmp.channels() - 1, - title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Component *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Component %i", - data_cast->cmp); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Filter: extract component */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_COMPONENT, data); -} - -/* ----- Imgproc: Image processing */ -/* ----- ------- Image filtering */ -static void img_iface_dilate (const void *data) -{ - struct Img_Iface_Data_Dilate_Erode data_tmp; - const struct Img_Iface_Data_Dilate_Erode *data_cast; - char title [80]; - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Iterations:"); - data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Dilate_Erode *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Dilate i=%i", - data_cast->i); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Dilate */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data); -} - -static void img_iface_erode (const void *data) -{ - struct Img_Iface_Data_Dilate_Erode data_tmp; - const struct Img_Iface_Data_Dilate_Erode *data_cast; - char title [80]; - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Iterations:"); - data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Dilate_Erode *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Erode i=%i", - data_cast->i); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Erode */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data); -} - -static void img_iface_dilate_erode (const void *data) -{ - struct Img_Iface_Data_Dilate_Erode data_tmp; - const struct Img_Iface_Data_Dilate_Erode *data_cast; - char title [80]; - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Iterations:"); - data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Dilate_Erode *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Dilate-erode i=%i", - data_cast->i); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Dilate */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data); - img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data); -} - -static void img_iface_erode_dilate (const void *data) -{ - struct Img_Iface_Data_Dilate_Erode data_tmp; - const struct Img_Iface_Data_Dilate_Erode *data_cast; - char title [80]; - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Iterations:"); - data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Dilate_Erode *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Erode-dilate i=%i", - data_cast->i); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Dilate */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data); - img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data); -} - -static void img_iface_smooth (const void *data) -{ - struct Img_Iface_Data_Smooth data_tmp; - const struct Img_Iface_Data_Smooth *data_cast; - char title [80]; - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Method: MEAN=1, GAUSS=2, MEDIAN=3"); - data_tmp.method = user_iface_getint(1, 3, 3, title, NULL); - - snprintf(title, 80, "Kernel size: 3, 5, 7, ..."); - data_tmp.ksize = user_iface_getint(3, 3, INFINITY, title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Smooth *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Smooth mth=%i [%ix%i]", - data_cast->method, - data_cast->ksize, - data_cast->ksize); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Filter: smooth */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_SMOOTH, data); -} - -static void img_iface_sobel (const void *data) -{ - struct Img_Iface_Data_Sobel data_tmp; - const struct Img_Iface_Data_Sobel *data_cast; - char title [80]; - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Invalid input"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - return; - } - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Order of the derivative x"); - data_tmp.dx = user_iface_getint(0, 1, 10, title, NULL); - - snprintf(title, 80, "Order of the derivative y"); - data_tmp.dy = user_iface_getint(0, 1, 10, title, NULL); - - snprintf(title, 80, "Size of the extended Sobel kernel (-1 -> Scharr"); - data_tmp.ksize = user_iface_getint(-1, 3, 7, title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Sobel *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Sobel dx=%i;dy=%i [ks=%i]", - data_cast->dx, - data_cast->dy, - data_cast->ksize); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Filter: sobel */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_SOBEL, data); -} - -static void img_iface_border (const void *data) -{ - struct Img_Iface_Data_Border data_tmp; - const struct Img_Iface_Data_Border *data_cast; - char title [80]; - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Invalid input"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - return; - } - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Size"); - data_tmp.size = user_iface_getint(1, 1, 0xF000, title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Border *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Border size=%i", - data_cast->size); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Add border */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_BORDER, data); -} - -/* ----- ------- Geometric image transformations */ -static void img_iface_mirror (const void *data) -{ - struct Img_Iface_Data_Mirror data_tmp; - const struct Img_Iface_Data_Mirror *data_cast; - char title [80]; - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Axis: 0=x; 1=y"); - data_tmp.axis = user_iface_getint(0, 1, 1, title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Mirror *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Mirror axis: %i", - data_cast->axis); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Mirror */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_MIRROR, data); -} - -static void img_iface_rotate_orto (const void *data) -{ - struct Img_Iface_Data_Rotate_Orto data_tmp; - const struct Img_Iface_Data_Rotate_Orto *data_cast; - char title [80]; - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Rotate (counterclockwise) n * pi/2 rad; n:"); - data_tmp.n = user_iface_getint(1, 1, 3, title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Rotate_Orto *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Rotate %i * pi/2 rad", - data_cast->n); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Rotate ortogonally */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE_ORTO, data); -} - -static void img_iface_rotate (const void *data) -{ - struct Img_Iface_Data_Rotate data_tmp; - const struct Img_Iface_Data_Rotate *data_cast; - char title [80]; - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Center: x:"); - data_tmp.center.x = user_iface_getdbl(0, 0, INFINITY, title, NULL); - - snprintf(title, 80, "Center: y:"); - data_tmp.center.y = user_iface_getdbl(0, 0, INFINITY, title, NULL); - - snprintf(title, 80, "Angle: (deg)"); - data_tmp.angle = user_iface_getdbl(-INFINITY, 0, INFINITY, title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Rotate *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Rotate (%.2f,%.2f) %lfº", - data_cast->center.x, - data_cast->center.y, - data_cast->angle); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Rotate ortogonally */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE, data); -} - -static void img_iface_rotate_2rect (const void *data) -{ - struct Img_Iface_Data_Rotate data_tmp; - - /* Data */ - if (!data) { - data_tmp.center.x = rectangle_rot.center.x; - data_tmp.center.y = rectangle_rot.center.y; - data_tmp.angle = rectangle_rot.angle; - - /* If angle is < -45º, it is taking into acount the incorrect side */ - if (data_tmp.angle < -45.0) { - data_tmp.angle += 90.0; - } - - data = (const void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Rotate to rectangle"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Rotate ortogonally */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE, data); -} - -/* ----- ------- Miscellaneous image transformations */ -static void img_iface_adaptive_thr (const void *data) -{ - struct Img_Iface_Data_Adaptive_Thr data_tmp; - const struct Img_Iface_Data_Adaptive_Thr *data_cast; - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Invalid input"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - return; - } - - /* Data */ - if (!data) { - /* Ask user */ - char title [80]; - snprintf(title, 80, "Method: MEAN=0, GAUSS=1"); - data_tmp.method = user_iface_getint(0, 1, 1, title, NULL); - - snprintf(title, 80, "Type: BIN=0, BIN_INV=1"); - data_tmp.thr_typ = user_iface_getint(0, 0, 1, title, NULL); - - snprintf(title, 80, "Kernel size: 3, 5, 7, ..."); - data_tmp.ksize = user_iface_getint(3, 3, INFINITY, title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Adaptive_Thr *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Threshold mth=%i, typ=%i, ks=%i", - data_cast->method, - data_cast->thr_typ, - data_cast->ksize); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Filter: adaptive threshold */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_ADAPTIVE_THRESHOLD, data); -} - -static void img_iface_cvt_color (const void *data) -{ - struct Img_Iface_Data_Cvt_Color data_tmp; - const struct Img_Iface_Data_Cvt_Color *data_cast; - char title [80]; - - /* Must have at least 3 channels */ - if (image_copy_tmp.channels() < 3) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Invalid input"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - return; - } - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Method: BGR2GRAY = 6, BGR2HSV = 40"); - data_tmp.method = user_iface_getint(0, 0, - cv::COLOR_COLORCVT_MAX, - title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Cvt_Color *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Convert color %i", - data_cast->method); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Filter: BGR to gray */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_CVT_COLOR, data); -} - -static void img_iface_distance_transform (void) -{ - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Invalid input"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - return; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Distance transform"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Distance transform */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_DISTANCE_TRANSFORM, NULL); -} - -static void img_iface_threshold (const void *data) -{ - struct Img_Iface_Data_Threshold data_tmp; - const struct Img_Iface_Data_Threshold *data_cast; - char title [80]; - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Invalid input"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - return; - } - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Type: BIN=0, BIN_INV=1, TRUNC=2, TOZ=3, TOZ_INV=4"); - data_tmp.thr_typ = user_iface_getint(0, 0, 4, title, NULL); - - snprintf(title, 80, "Value: 0 to 255 (or -1 for Otsu's algorithm)"); - data_tmp.thr_val = user_iface_getint(-1, 0, 255, title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Threshold *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Threshold typ=%i, val=%i", - data_cast->thr_typ, - data_cast->thr_val); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Filter: threshold */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_THRESHOLD, data); -} - -/* ----- ------- Histograms */ -static void img_iface_histogram (const void *data) -{ - struct Img_Iface_Data_Histogram data_tmp; - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Invalid input"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - return; - } - - /* Data */ - if (!data) { - data_tmp.hist_c0 = &histogram_c0; - data_tmp.hist_img = &hist_img_c1; - - data = (const void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Histogram"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Histogram */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_HISTOGRAM, data); -} - -static void img_iface_histogram_c3 (const void *data) -{ - struct Img_Iface_Data_Histogram data_tmp; - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 3) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Invalid input"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - return; - } - - /* Data */ - if (!data) { - data_tmp.hist_c0 = &histogram_c0; - data_tmp.hist_c1 = &histogram_c1; - data_tmp.hist_c2 = &histogram_c2; - data_tmp.hist_img = &hist_img_c3; - - data = (const void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Histogram (3 channels)"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Histogram */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_HISTOGRAM_C3, data); -} - -/* ----- ------- Structural analysis and shape descriptors */ -static void img_iface_contours (const void *data) -{ - struct Img_Iface_Data_Contours data_tmp; - const struct Img_Iface_Data_Contours *data_cast; - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Invalid input"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - return; - } - - /* Data */ - if (!data) { - data_tmp.contours = &contours; - data_tmp.hierarchy = &hierarchy; - - data = (const void *)&data_tmp; - } - - /* Contours */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_CONTOURS, data); - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Contours *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Contours n=%i", - (int)data_cast->contours->size()); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -static void img_iface_contours_size (const void *data) -{ - struct Img_Iface_Data_Contours_Size data_tmp; - const struct Img_Iface_Data_Contours_Size *data_cast; - unsigned i; - - /* Data */ - if (!data) { - data_tmp.contours = &contours; - data_tmp.area = area; - data_tmp.perimeter = perimeter; - - data = (const void *)&data_tmp; - } - - /* Contours size */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_CONTOURS_SIZE, data); - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Contours_Size *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Contours size:"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - for (i = 0; i < data_cast->contours->size(); i++) { - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "cnt[%i]: A=%lf; P=%lf;", - i, - data_cast->area[i], - data_cast->perimeter[i]); - user_iface_log.lvl[user_iface_log.len] = 2; - (user_iface_log.len)++; - } -} - -static void img_iface_bounding_rect (const void *data) -{ - struct Img_Iface_Data_Bounding_Rect data_tmp; - - if (!data) { - if(!contours.size()) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], - LOG_LINE_LEN, - "! Invalid input"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - return; - } - data_tmp.contour = &(contours[0]); - data_tmp.rect = &rectangle; - data_tmp.show = true; - - data = (const void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Bounding rectangle"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Enclosing rectangle */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_BOUNDING_RECT, data); -} - -static void img_iface_fit_ellipse (const void *data) -{ - struct Img_Iface_Data_MinARect data_tmp; - - if (!data) { - if(!contours.size()) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], - LOG_LINE_LEN, - "! Invalid input"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - return; - } - data_tmp.contour = &(contours[0]); - - data_tmp.rect = &rectangle_rot; - - data = (const void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Fit ellipse"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Enclosing rectangle */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_FIT_ELLIPSE, data); -} - -static void img_iface_min_area_rect (const void *data) -{ - struct Img_Iface_Data_MinARect data_tmp; - - if (!data) { - if(!contours.size()) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], - LOG_LINE_LEN, - "! Invalid input"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - return; - } - data_tmp.contour = &(contours[0]); - data_tmp.rect = &rectangle_rot; - data_tmp.show = true; - - data = (const void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Min area rectangle"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Enclosing rectangle */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_MIN_AREA_RECT, data); -} - -/* ----- ------- Feature detection */ -static void img_iface_hough_circles (const void *data) -{ - struct Img_Iface_Data_Hough_Circles data_tmp; - const struct Img_Iface_Data_Hough_Circles *data_cast; - char title [80]; - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Invalid input"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - return; - } - - /* Data */ - if (!data) { - data_tmp.circles = &circles; - - /* Ask user */ - snprintf(title, 80, "Minimum distance:"); - data_tmp.dist_min = user_iface_getdbl(0, 5, INFINITY, title, NULL); - - snprintf(title, 80, "param 1:"); - data_tmp.param_1 = user_iface_getdbl(0, 200, INFINITY, title, NULL); - - snprintf(title, 80, "param 2:"); - data_tmp.param_2 = user_iface_getdbl(0, 100, INFINITY, title, NULL); - - snprintf(title, 80, "Minimum radius"); - data_tmp.radius_min = user_iface_getint(0, 10, INFINITY, title, NULL); - - snprintf(title, 80, "Maximum radius"); - data_tmp.radius_max = user_iface_getint(0, 0, INFINITY, title, NULL); - - data = (const void *)&data_tmp; - } - - /* Circles */ - img_cv_act(&image_copy_tmp, IMG_CV_ACT_HOUGH_CIRCLES, data); - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Hough_Circles *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Circles n=%i", - (int)data_cast->circles->size()); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; -} - -/* img_orb -------------------------------------------------------------------*/ -static void img_iface_align (void) -{ - /* Must have defined a reference */ - if (image_ref.empty()) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Reference is NULL"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - return; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Align to reference"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Align to reference image_ref */ - img_orb_act(&image_ref, &image_copy_tmp, IMG_ORB_ACT_ALIGN); -} - -/* img_calib3d ---------------------------------------------------------------*/ -static void img_iface_calibrate (const void *data) -{ - struct Img_Iface_Data_Calibrate data_tmp; - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Invalid input"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - return; - } - - /* Data */ - if (!data) { - data_tmp.intrinsic_mat = &intrinsic_mat; - data_tmp.dist_coefs = &dist_coefs; - data_tmp.rvecs = &rvecs; - data_tmp.tvecs = &tvecs; - - data = (const void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Calibrate"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Contours */ - img_calib3d_act(&image_copy_tmp, IMG_CALIB3D_ACT_CALIBRATE, data); -} - -static void img_iface_undistort (const void *data) -{ - struct Img_Iface_Data_Undistort data_tmp; - - /* Data */ - if (!data) { - data_tmp.intrinsic_mat = &intrinsic_mat; - data_tmp.dist_coefs = &dist_coefs; - - data = (const void *)&data_tmp; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Undistort"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Contours */ - img_calib3d_act(&image_copy_tmp, IMG_CALIB3D_ACT_UNDISTORT, data); -} - -/* img_zbar ------------------------------------------------------------------*/ -static void img_iface_decode (const void *data) -{ - struct Img_Iface_Data_Decode data_tmp; - const struct Img_Iface_Data_Decode *data_cast; - char title [80]; - int i; - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Invalid input"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - return; - } - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Type of code: (0 for all)"); - data_tmp.code_type = (enum zbar::zbar_symbol_type_e) - user_iface_getint(0, 0, INT_MAX, - title, NULL); - - data = (const void *)&data_tmp; - } - - /* Write into log */ - data_cast = (const struct Img_Iface_Data_Decode *)data; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Detect codes c=%i", - data_cast->code_type); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Decode */ - img_zb_act(&image_copy_tmp, IMG_ZB_ACT_DECODE, data); - - /* Results */ - if (!zb_codes.n) { - /* No text found */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! No code detected"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - } else { - /* Write results into log */ - for (i = 0; i < zb_codes.n; i++) { - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "%s -- '%s'", - zb_codes.arr[i].sym_name, - zb_codes.arr[i].data); - user_iface_log.lvl[user_iface_log.len] = 2; - (user_iface_log.len)++; - } - } -} - -/* img_ocr -------------------------------------------------------------------*/ -static void img_iface_read (const void *data) -{ - struct Img_Iface_Data_Read data_tmp; - const struct Img_Iface_Data_Read *data_cast; - char title [80]; - - /* Must have 1 channel */ - if (image_copy_tmp.channels() != 1) { - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! Invalid input"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - return; - } - - data_cast = (const struct Img_Iface_Data_Read *)data; - - /* Data */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "Language: ENG = 0, SPA = 1, CAT = 2"); - data_tmp.lang = user_iface_getint(0, 1, 2, title, NULL); - - snprintf(title, 80, "Config: none = 0, Price = 1"); - data_tmp.conf = user_iface_getint(0, 1, 2, title, NULL); - } else { - data_tmp.lang = data_cast->lang; - data_tmp.conf = data_cast->conf; - } - - /* Adapt image data */ - data_tmp.img.data = image_copy_tmp.data; - data_tmp.img.width = image_copy_tmp.size().width; - data_tmp.img.height = image_copy_tmp.size().height; - data_tmp.img.B_per_pix = image_copy_tmp.channels(); - data_tmp.img.B_per_line = image_copy_tmp.step1(); - - data = (const void *)&data_tmp; - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "OCR (lang=%i) [c=%i]", - data_cast->lang, - data_cast->conf); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* OCR */ - img_ocr_act(IMG_OCR_ACT_READ, data); - - /* Results */ - if (img_ocr_text[0] == '\0') { - /* No text found */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "! No text detected"); - user_iface_log.lvl[user_iface_log.len] = 2; - (user_iface_log.len)++; - } -} - -/* img_iface -----------------------------------------------------------------*/ -static void img_iface_apply (void) -{ - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Apply changes"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Write tmp into old */ - image_copy_old.release(); - image_copy_tmp.copyTo(image_copy_old); -} - -static void img_iface_discard (void) -{ - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Discard changes"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Discard tmp image copy */ - image_copy_tmp.release(); - image_copy_old.copyTo(image_copy_tmp); -} - -static void img_iface_save_mem (const void *data) -{ - int x; - char title [80]; - - /* Which memory to use */ - if (!data) { - /* Ask user */ - snprintf(title, 80, "mem_X; X:"); - x = user_iface_getint(0, 0, IMG_MEM_SIZE - 1, title, NULL); - } else { - x = *(const int *)data; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Save to mem_%i", x); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Write into mem */ - image_mem[x].release(); - image_copy_tmp.copyTo(image_mem[x]); -} - -static void img_iface_load_mem (const void *data) -{ - int x; - char title [80]; - - /* Which memory to use */ - if (!data) { - /* Ask user which memory to use */ - snprintf(title, 80, "mem_X; X:"); - x = user_iface_getint(0, 0, IMG_MEM_SIZE - 1, title, NULL); - } else { - x = *(const int *)data; - } - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Load from mem_%i", x); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - if (!image_mem[x].empty()) { - /* Discard tmp image copy */ - image_copy_tmp.release(); - - /* Load from mem */ - image_mem[x].copyTo(image_copy_tmp); - } -} - -static void img_iface_save_ref (void) -{ - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Save to reference"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Write into ref */ - image_ref.release(); - image_copy_tmp.copyTo(image_ref); -} - -/* save ----------------------------------------------------------------------*/ -static void img_iface_save_file (void) -{ - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Save as..."); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Write into image struct (save.c) */ - image.release(); - image_copy_tmp.copyTo(image); - - /* Save into file */ - save_image_file(NULL, NULL); -} - -static void img_iface_save_update (void) -{ - - /* Write into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Save: update img"); - user_iface_log.lvl[user_iface_log.len] = 1; - (user_iface_log.len)++; - - /* Write into image struct (save.c) */ - image.release(); - image_copy_tmp.copyTo(image); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/image/tmp/Makefile b/modules/image/tmp/Makefile deleted file mode 100644 index 2890fb6..0000000 --- a/modules/image/tmp/Makefile +++ /dev/null @@ -1,149 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -LIBALX_INC_DIR = $(LIBALX_DIR)/inc/ - -ABOUT_INC_DIR = $(ABOUT_DIR)/inc/ -SAVE_INC_DIR = $(SAVE_DIR)/inc/ -USR_INC_DIR = $(USR_DIR)/inc/ - -INC_DIR = $(IMG_DIR)/inc/ -SRC_DIR = $(IMG_DIR)/src/ - -# dependencies - -_ALL = img_alx.o img_cv.o img_orb.o img_calib3d.o \ - img_zbar.o img_ocr.o img_iface.o -ALL = $(_ALL) img_mod.o - -IMGALX_INC_LIBALX = libalx/alx_math.hpp -IMGALX_INC = img_alx.hpp img_iface.hpp -IMGALX_DEPS = $(SRC_DIR)/img_alx.cpp \ - $(patsubst %,$(INC_DIR)/%,$(IMGALX_INC)) \ - $(patsubst %,$(LIBALX_INC_DIR)/%,$(IMGALX_INC_LIBALX)) -IMGALX_INC_DIRS = -I $(INC_DIR) \ - -I $(LIBALX_INC_DIR) - -IMGCV_INC = img_cv.hpp img_iface.hpp -IMGCV_DEPS = $(SRC_DIR)/img_cv.cpp \ - $(patsubst %,$(INC_DIR)/%,$(IMGCV_INC)) -IMGCV_INC_DIRS = -I $(INC_DIR) - -IMGORB_INC = img_orb.hpp img_iface.hpp -IMGORB_DEPS = $(SRC_DIR)/img_orb.cpp \ - $(patsubst %,$(INC_DIR)/%,$(IMGORB_INC)) -IMGORB_INC_DIRS = -I $(INC_DIR) - -IMGC3D_INC = img_calib3d.hpp img_iface.hpp -IMGC3D_DEPS = $(SRC_DIR)/img_calib3d.cpp \ - $(patsubst %,$(INC_DIR)/%,$(IMGC3D_INC)) -IMGC3D_INC_DIRS = -I $(INC_DIR) - -IMGZB_INC = img_zbar.hpp img_iface.hpp -IMGZB_DEPS = $(SRC_DIR)/img_zbar.cpp \ - $(patsubst %,$(INC_DIR)/%,$(IMGZB_INC)) -IMGZB_INC_DIRS = -I $(INC_DIR) - -IMGOCR_INC_ABOUT = about.h -IMGOCR_INC = img_ocr.h img_iface.h -IMGOCR_DEPS = $(SRC_DIR)/img_ocr.c \ - $(patsubst %,$(INC_DIR)/%,$(IMGOCR_INC)) \ - $(patsubst %,$(ABOUT_INC_DIR)/%,$(IMGOCR_INC_ABOUT)) -IMGOCR_INC_DIRS = -I $(INC_DIR) \ - -I $(ABOUT_INC_DIR) - -IMGI_INC_SAVE = save.hpp -IMGI_INC_USR = user_iface.hpp -IMGI_INC = img_iface.hpp img_alx.hpp img_calib3d.hpp img_cv.hpp \ - img_zbar.hpp img_ocr.hpp img_orb.hpp -IMGI_DEPS = $(SRC_DIR)/img_iface.cpp \ - $(patsubst %,$(INC_DIR)/%,$(IMGI_INC)) \ - $(patsubst %,$(SAVE_INC_DIR)/%,$(IMGI_INC_SAVE)) \ - $(patsubst %,$(USR_INC_DIR)/%,$(IMGI_INC_USR)) -IMGI_INC_DIRS = -I $(INC_DIR) \ - -I $(SAVE_INC_DIR) \ - -I $(USR_INC_DIR) - -# target: dependencies -# action - -PHONY := all -all: $(ALL) - - -img_mod.o: $(_ALL) - $(Q)$(LD) -r $^ -o $@ - @echo " LD $@" - - -img_alx.s: $(IMGALX_DEPS) - @echo " CXX $@" - $(Q)$(CXX) $(CXXFLAGS) $(IMGALX_INC_DIRS) -S $< -o $@ -img_alx.o: img_alx.s - @echo " AS $@" - $(Q)$(AS) $< -o $@ - -img_cv.s: $(IMGCV_DEPS) - @echo " CXX $@" - $(Q)$(CXX) $(CXXFLAGS) $(IMGCV_INC_DIRS) -S $< -o $@ -img_cv.o: img_cv.s - @echo " AS $@" - $(Q)$(AS) $< -o $@ - -img_orb.s: $(IMGORB_DEPS) - @echo " CXX $@" - $(Q)$(CXX) $(CXXFLAGS) $(IMGORB_INC_DIRS) -S $< -o $@ -img_orb.o: img_orb.s - @echo " AS $@" - $(Q)$(AS) $< -o $@ - -img_calib3d.s: $(IMGC3D_DEPS) - @echo " CXX $@" - $(Q)$(CXX) $(CXXFLAGS) $(IMGC3D_INC_DIRS) -S $< -o $@ -img_calib3d.o: img_calib3d.s - @echo " AS $@" - $(Q)$(AS) $< -o $@ - -img_zbar.s: $(IMGZB_DEPS) - @echo " CXX $@" - $(Q)$(CXX) $(CXXFLAGS) $(IMGZB_INC_DIRS) -S $< -o $@ -img_zbar.o: img_zbar.s - @echo " AS $@" - $(Q)$(AS) $< -o $@ - -img_ocr.s: $(IMGOCR_DEPS) - @echo " CC $@" - $(Q)$(CC) $(CFLAGS) $(IMGOCR_INC_DIRS) -S $< -o $@ -img_ocr.o: img_ocr.s - @echo " AS $@" - $(Q)$(AS) $< -o $@ - -img_iface.s: $(IMGI_DEPS) - @echo " CXX $@" - $(Q)$(CXX) $(CXXFLAGS) $(IMGI_INC_DIRS) -S $< -o $@ -img_iface.o: img_iface.s - @echo " AS $@" - $(Q)$(AS) $< -o $@ - - -PHONY += clean -clean: - $(Q)rm -f *.o *.s - -################################################################################ -# Declare the contents of the .PHONY variable as phony. -.PHONY: $(PHONY) - - - - -################################################################################ -######## End of file ########################################################### -################################################################################ - -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/modules/menu/Makefile b/modules/menu/Makefile deleted file mode 100644 index 48ed965..0000000 --- a/modules/menu/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -TMP_DIR = $(MENU_DIR)/tmp/ - -# target: dependencies -# action - -all: - $(Q)cd $(TMP_DIR) && $(MAKE) && cd .. - -clean: - $(Q)cd $(TMP_DIR) && $(MAKE) clean && cd .. - -################################################################################ -######## End of file ########################################################### -################################################################################ -######## End of file ########################################################### -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/modules/menu/inc/menu_clui.h b/modules/menu/inc/menu_clui.h deleted file mode 100644 index a915645..0000000 --- a/modules/menu/inc/menu_clui.h +++ /dev/null @@ -1,28 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_MENU_CLUI_H - # define VA_MENU_CLUI_H - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void menu_clui (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* menu_clui.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/menu/inc/menu_iface.h b/modules/menu/inc/menu_iface.h deleted file mode 100644 index 1b76e0b..0000000 --- a/modules/menu/inc/menu_iface.h +++ /dev/null @@ -1,44 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_MENU_IFACE_H - # define VA_MENU_IFACE_H - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Menu_Iface_Mode { - MENU_IFACE_FOO = 0, - MENU_IFACE_CLUI, - MENU_IFACE_TUI - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern int menu_iface_mode; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void menu_iface (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* menu_iface.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/menu/inc/menu_iface.hpp b/modules/menu/inc/menu_iface.hpp deleted file mode 100644 index 6128711..0000000 --- a/modules/menu/inc/menu_iface.hpp +++ /dev/null @@ -1,56 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_MENU_IFACE_HPP - # define VA_MENU_IFACE_HPP - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Menu_Iface_Mode { - MENU_IFACE_FOO = 0, - MENU_IFACE_CLUI, - MENU_IFACE_TUI - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern int menu_iface_mode; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void menu_iface (void); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* menu_iface.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/menu/inc/menu_tui.h b/modules/menu/inc/menu_tui.h deleted file mode 100644 index 0f8e442..0000000 --- a/modules/menu/inc/menu_tui.h +++ /dev/null @@ -1,28 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_MENU_TUI_H - # define VA_MENU_TUI_H - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void menu_tui (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* menu_tui.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/menu/inc/parser.h b/modules/menu/inc/parser.h deleted file mode 100644 index 3843017..0000000 --- a/modules/menu/inc/parser.h +++ /dev/null @@ -1,28 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PARSER_H - # define VA_PARSER_H - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void parser (int argc, char *argv[]); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* parser.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/menu/inc/parser.hpp b/modules/menu/inc/parser.hpp deleted file mode 100644 index e40bbd3..0000000 --- a/modules/menu/inc/parser.hpp +++ /dev/null @@ -1,40 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PARSER_HPP - # define VA_PARSER_HPP - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void parser (int argc, char *argv[]); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* parser.hpp */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/menu/src/menu_iface.c b/modules/menu/src/menu_iface.c deleted file mode 100644 index a09a463..0000000 --- a/modules/menu/src/menu_iface.c +++ /dev/null @@ -1,44 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ - #include "menu_clui.h" - #include "menu_tui.h" - - #include "menu_iface.h" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -int menu_iface_mode; - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void menu_iface (void) -{ - switch (menu_iface_mode) { - case MENU_IFACE_FOO: - break; - - case MENU_IFACE_CLUI: - menu_clui(); - break; - - case MENU_IFACE_TUI: - menu_tui(); - break; - } -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/menu/src/menu_tui.c b/modules/menu/src/menu_tui.c deleted file mode 100644 index 8a6cb0b..0000000 --- a/modules/menu/src/menu_tui.c +++ /dev/null @@ -1,332 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <ncurses.h> - #include <stdbool.h> - #include <stddef.h> -/* libalx --------------------------------------------------------------------*/ - #include "libalx/curses/alx_ncur.h" -/* Project -------------------------------------------------------------------*/ - #include "about.h" - #include "proc_iface.h" - #include "save.h" - #include "start.h" - #include "user_iface.h" -/* Module --------------------------------------------------------------------*/ - #include "menu_tui.h" - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void menu_tui_continue (void); -static void menu_tui_select (void); -static void menu_tui_series (void); -static void menu_tui_devel (void); - - -/****************************************************************************** - ******* main ***************************************************************** - ******************************************************************************/ -void menu_tui (void) -{ - int h; - int w; - int N; - bool wh; - int sw; - - alx_resume_curses(); - - /* Menu dimensions & options */ - h = 23; - w = 80; - N = 4; - static const struct Alx_Menu mnu[4] = { - {7, 4, "[0] Exit program"}, - {2, 4, "[1] Continue"}, - {4, 4, "[2] Disclaimer of warranty"}, - {5, 4, "[3] Terms and conditions"} - }; - - /* Menu */ - wh = true; - while (wh) { - /* Menu loop */ - sw = alx_menu(h, w, N, mnu, "MENU:"); - - /* Selection */ - switch (sw) { - case 0: - wh = false; - break; - - case 1: - menu_tui_continue(); - break; - - case 2: - alx_pause_curses(); - print_share_file(SHARE_DISCLAIMER); - getchar(); - alx_resume_curses(); - break; - - case 3: - alx_pause_curses(); - print_share_file(SHARE_LICENSE); - getchar(); - alx_resume_curses(); - break; - } - } - - alx_pause_curses(); -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void menu_tui_continue (void) -{ - WINDOW *win; - int h; - int w; - int r; - int c; - int N; - int w2; - int r2; - bool wh; - int sw; - - /* Menu dimensions & options */ - h = 23; - w = 80; - r = 1; - c = (80 - w) / 2; - N = 6; - static const struct Alx_Menu mnu[6] = { - {8, 4, "[0] Back"}, - {2, 4, "[1] Start"}, - {3, 4, "[2] Select"}, - {4, 4, "[3] Series"}, - {5, 4, "[4] Change file name"}, - {6, 4, "[5] DEVEL"} - }; - - /* Input box */ - w2 = w - 8; - r2 = r + h - 5; - static const char *const txt[] = {"File name:"}; - - /* Menu */ - wh = true; - while (wh) { - /* Menu loop */ - win = newwin(h, w, r, c); - mvwprintw(win, mnu[1].r, mnu[1].c, "%s (File: \"%s\")", - mnu[1].t, saved_name); - wrefresh(win); - sw = alx_menu_2(win, N, mnu, "CONTINUE:"); - - /* Selection */ - switch (sw) { - case 0: - wh = false; - break; - - case 1: - alx_win_del(win); - alx_pause_curses(); - start_switch(); - alx_resume_curses(); - break; - - case 2: - alx_win_del(win); - menu_tui_select(); - break; - - case 3: - alx_win_del(win); - menu_tui_series(); - break; - - case 4: - save_clr(); - alx_w_getfname(saved_path, saved_name, true, w2, r2, - txt[0], NULL); - alx_win_del(win); - break; - - case 5: - alx_win_del(win); - menu_tui_devel(); - break; - } - } - - /* Cleanup */ - alx_win_del(win); -} - -static void menu_tui_select (void) -{ - int h; - int w; - int N; - int sw; - - /* Menu dimensions & options */ - h = 23; - w = 80; - N = 3; - static const struct Alx_Menu mnu[3] = { - {6, 4, "[0] Back"}, - {2, 4, "[1] Single image"}, - {4, 4, "[2] Series"} - }; - - /* Menu loop */ - sw = alx_menu(h, w, N, mnu, "SELECT MODE:"); - - /* Selection */ - switch (sw) { - case 1: - start_mode = START_SINGLE; - break; - - case 2: - start_mode = START_SERIES; - break; - } - -} - -static void menu_tui_series (void) -{ - int h; - int w; - int N; - int sw; - - /* Menu dimensions & options */ - h = 23; - w = 80; - N = 6; - static const struct Alx_Menu mnu[6] = { - {8, 4, "[0] Back"}, - {2, 4, "[1] Label"}, - {3, 4, "[2] Objects"}, - {4, 4, "[3] Coins"}, - {5, 4, "[4] Resistor"}, - {6, 4, "[5] Lighters"} - }; - - /* Menu loop */ - sw = alx_menu(h, w, N, mnu, "SELECT LEVEL:"); - - /* Selection */ - switch (sw) { - case 1: - proc_mode = PROC_MODE_LABEL_SERIES; - break; - case 2: - proc_mode = PROC_MODE_OBJECTS_SERIES; - break; - case 3: - proc_mode = PROC_MODE_COINS_SERIES; - break; - case 4: - proc_mode = PROC_MODE_RESISTOR_SERIES; - break; - case 5: - proc_mode = PROC_MODE_LIGHTERS_SERIES; - break; - } - -} - -static void menu_tui_devel (void) -{ - WINDOW *win; - int h; - int w; - int r; - int c; - int N; - int w2; - int r2; - bool wh; - int sw; - - h = 23; - w = 80; - r = 1; - c = (80 - w) / 2; - N = 4; - static const struct Alx_Menu mnu[4] = { - {6, 4, "[0] Back"}, - {2, 4, "[1] Change process mode"}, - {3, 4, "[2] Change log mode"}, - {4, 4, "[3] Change user iface mode"} - }; - - /* Input box */ - w2 = w - 8; - r2 = r + h - 5; - static const char *const txt[] = { - "Modes: 0=Auto; 1=Stop@prod; 2=Delay@step; 3=Stop@step", - "Modes: 0=Results; 1=Operations; 2=All", - "Modes: 1=CLUI; 2=TUI" - }; - - /* Menu */ - win = newwin(h, w, r, c); - - /* Menu loop */ - wh = true; - while (wh) { - /* Selection */ - sw = alx_menu_2(win, N, mnu, "DEVELOPER OPTIONS:"); - - switch (sw) { - case 0: - wh = false; - break; - - case 1: - proc_debug = alx_w_getint(w2, r2, txt[0], - PROC_DBG_NO, 0, - PROC_DBG_STOP_STEP, NULL); - break; - - case 2: - user_iface_log.visible = alx_w_getint(w2, r2, txt[1], - 0, 2, 2, NULL); - break; - - case 3: - user_iface_mode = alx_w_getint(w2, r2, txt[2], - 1, 2, 2, NULL); - break; - } - } - - /* Cleanup */ - alx_win_del(win); -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/menu/tmp/Makefile b/modules/menu/tmp/Makefile deleted file mode 100644 index cd39b92..0000000 --- a/modules/menu/tmp/Makefile +++ /dev/null @@ -1,123 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -LIBALX_INC_DIR = $(LIBALX_DIR)/inc/ - -ABOUT_INC_DIR = $(ABOUT_DIR)/inc/ -CTRL_INC_DIR = $(CTRL_DIR)/inc/ -PROC_INC_DIR = $(PROC_DIR)/inc/ -SAVE_INC_DIR = $(SAVE_DIR)/inc/ -USR_INC_DIR = $(USR_DIR)/inc/ - -INC_DIR = $(MENU_DIR)/inc/ -SRC_DIR = $(MENU_DIR)/src/ - -# dependencies - -_ALL = parser.o menu_iface.o menu_clui.o menu_tui.o -ALL = $(_ALL) menu_mod.o - -PARS_INC_ABOUT = about.h -PARS_INC_SAVE = save.h -PARS_INC_USR = user_iface.h -PARS_INC = parser.h menu_iface.h -PARS_DEPS = $(SRC_DIR)/parser.c \ - $(patsubst %,$(INC_DIR)/%,$(PARS_INC)) \ - $(patsubst %,$(ABOUT_INC_DIR)/%,$(PARS_INC_ABOUT)) \ - $(patsubst %,$(SAVE_INC_DIR)/%,$(PARS_INC_SAVE)) \ - $(patsubst %,$(USR_INC_DIR)/%,$(PARS_INC_USR)) -PARS_INC_DIRS = -I $(INC_DIR) \ - -I $(ABOUT_INC_DIR) \ - -I $(SAVE_INC_DIR) \ - -I $(USR_INC_DIR) - -MENUI_INC = menu_iface.h menu_clui.h menu_tui.h -MENUI_DEPS = $(SRC_DIR)/menu_iface.c \ - $(patsubst %,$(INC_DIR)/%,$(MENUI_INC)) -MENUI_INC_DIRS = -I $(INC_DIR) - -MENUCLUI_INC_LIBALX = libalx/io/alx_input.h -MENUCLUI_INC_ABOUT = about.h -MENUCLUI_INC_CTRL = start.h -MENUCLUI_INC_SAVE = save.h -MENUCLUI_INC = menu_clui.h -MENUCLUI_DEPS = $(SRC_DIR)/menu_clui.c \ - $(patsubst %,$(INC_DIR)/%,$(MENUCLUI_INC)) \ - $(patsubst %,$(LIBALX_INC_DIR)/%,$(MENUCLUI_INC_LIBALX)) \ - $(patsubst %,$(ABOUT_INC_DIR)/%,$(MENUCLUI_INC_ABOUT)) \ - $(patsubst %,$(CTRL_INC_DIR)/%,$(MENUCLUI_INC_CTRL)) \ - $(patsubst %,$(SAVE_INC_DIR)/%,$(MENUCLUI_INC_SAVE)) -MENUCLUI_INC_DIRS = -I $(INC_DIR) \ - -I $(LIBALX_INC_DIR) \ - -I $(ABOUT_INC_DIR) \ - -I $(CTRL_INC_DIR) \ - -I $(SAVE_INC_DIR) - -MENUTUI_INC_LIBALX = libalx/curses/alx_ncur.h -MENUTUI_INC_ABOUT = about.h -MENUTUI_INC_CTRL = start.h -MENUTUI_INC_PROC = proc_iface.h -MENUTUI_INC_SAVE = save.h -MENUTUI_INC_USR = user_iface.h -MENUTUI_INC = menu_tui.h -MENUTUI_DEPS = $(SRC_DIR)/menu_tui.c \ - $(patsubst %,$(INC_DIR)/%,$(MENUTUI_INC)) \ - $(patsubst %,$(LIBALX_INC_DIR)/%,$(MENUTUI_INC_LIBALX)) \ - $(patsubst %,$(ABOUT_INC_DIR)/%,$(MENUTUI_INC_ABOUT)) \ - $(patsubst %,$(CTRL_INC_DIR)/%,$(MENUTUI_INC_CTRL)) \ - $(patsubst %,$(PROC_INC_DIR)/%,$(MENUTUI_INC_PROC)) \ - $(patsubst %,$(SAVE_INC_DIR)/%,$(MENUTUI_INC_SAVE)) \ - $(patsubst %,$(USR_INC_DIR)/%,$(MENUTUI_INC_USR)) -MENUTUI_INC_DIRS = -I $(INC_DIR) \ - -I $(LIBALX_INC_DIR) \ - -I $(ABOUT_INC_DIR) \ - -I $(CTRL_INC_DIR) \ - -I $(PROC_INC_DIR) \ - -I $(SAVE_INC_DIR) \ - -I $(USR_INC_DIR) - -# target: dependencies -# action - -all: $(ALL) - - -menu_mod.o: $(_ALL) - $(Q)$(LD) -r $^ -o $@ - @echo " LD $@" - - -parser.s: $(PARS_DEPS) - $(Q)$(CC) $(CFLAGS) $(PARS_INC_DIRS) -S $< -o $@ - @echo " CC $@" -parser.o: parser.s - $(Q)$(AS) $< -o $@ - @echo " AS $@" - -menu_iface.s: $(MENUI_DEPS) - $(Q)$(CC) $(CFLAGS) $(MENUI_INC_DIRS) -S $< -o $@ - @echo " CC $@" -menu_iface.o: menu_iface.s - $(Q)$(AS) $< -o $@ - @echo " AS $@" - -menu_clui.s: $(MENUCLUI_DEPS) - $(Q)$(CC) $(CFLAGS) $(MENUCLUI_INC_DIRS) -S $< -o $@ - @echo " CC $@" -menu_clui.o: menu_clui.s - $(Q)$(AS) $< -o $@ - @echo " AS $@" - -menu_tui.s: $(MENUTUI_DEPS) - $(Q)$(CC) $(CFLAGS) $(MENUTUI_INC_DIRS) -S $< -o $@ - @echo " CC $@" -menu_tui.o: menu_tui.s - $(Q)$(AS) $< -o $@ - @echo " AS $@" - - -clean: - $(Q)rm -f *.o *.s diff --git a/modules/proc/Makefile b/modules/proc/Makefile deleted file mode 100644 index ea0eed1..0000000 --- a/modules/proc/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -TMP_DIR = $(PROC_DIR)/tmp/ - -# target: dependencies -# action - -all: - $(Q)cd $(TMP_DIR) && $(MAKE) && cd .. - -clean: - $(Q)cd $(TMP_DIR) && $(MAKE) clean && cd .. - -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/modules/proc/inc/proc_coins.h b/modules/proc/inc/proc_coins.h deleted file mode 100644 index 0052eb2..0000000 --- a/modules/proc/inc/proc_coins.h +++ /dev/null @@ -1,49 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_PROC_COINS_H - # define VA_PROC_COINS_H - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Coins { - COINS_OK, - COINS_NOK_COINS, - COINS_NOK_OVERLAP, - COINS_NOK_SIZE - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -int proc_coins (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_coins.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/inc/proc_common.h b/modules/proc/inc/proc_common.h deleted file mode 100644 index 9f84504..0000000 --- a/modules/proc/inc/proc_common.h +++ /dev/null @@ -1,46 +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 - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void proc_show_img (void); - -void clock_start (void); -void clock_stop (const char *txt); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_common.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/inc/proc_iface.h b/modules/proc/inc/proc_iface.h deleted file mode 100644 index 1001702..0000000 --- a/modules/proc/inc/proc_iface.h +++ /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_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 - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern int proc_debug; -extern int proc_mode; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -int proc_iface_single (int action); -void proc_iface_series (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_iface.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/inc/proc_label.h b/modules/proc/inc/proc_label.h deleted file mode 100644 index d1b78f1..0000000 --- a/modules/proc/inc/proc_label.h +++ /dev/null @@ -1,51 +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 - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Label { - LABEL_OK, - LABEL_NOK_LABEL, - LABEL_NOK_CERDO, - LABEL_NOK_BCODE, - LABEL_NOK_PRODUCT, - LABEL_NOK_PRICE - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -int proc_label (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_label.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/inc/proc_lighters.h b/modules/proc/inc/proc_lighters.h deleted file mode 100644 index 5771aad..0000000 --- a/modules/proc/inc/proc_lighters.h +++ /dev/null @@ -1,48 +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 - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Lighter { - LIGHTER_OK, - LIGHTER_NOK_LIGHTER, - LIGHTER_NOK_SIZE - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -int proc_lighter (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_lighters.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/inc/proc_objects.h b/modules/proc/inc/proc_objects.h deleted file mode 100644 index ed865fd..0000000 --- a/modules/proc/inc/proc_objects.h +++ /dev/null @@ -1,50 +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 - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Objects { - OBJECTS_OK, - OBJECTS_NOK_PATTERN, - OBJECTS_NOK_OBJECTS, - OBJECTS_NOK_SIZE - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -int proc_objects_calibrate (void); -int proc_objects (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_objects.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/inc/proc_resistor.h b/modules/proc/inc/proc_resistor.h deleted file mode 100644 index dea2ed7..0000000 --- a/modules/proc/inc/proc_resistor.h +++ /dev/null @@ -1,51 +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 - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Proc_Resistor { - RESISTOR_OK, - RESISTOR_NOK_RESISTOR, - RESISTOR_NOK_BANDS, - RESISTOR_NOK_COLOR, - RESISTOR_NOK_STD_VALUE, - RESISTOR_NOK_TOLERANCE - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -int proc_resistor (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* proc_resistor.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/src/proc_coins.cpp b/modules/proc/src/proc_coins.cpp deleted file mode 100644 index f824fe2..0000000 --- a/modules/proc/src/proc_coins.cpp +++ /dev/null @@ -1,369 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <cstdio> -/* Packages ------------------------------------------------------------------*/ - #include <opencv2/opencv.hpp> -/* libalx --------------------------------------------------------------------*/ - #include "libalx/alx_math.hpp" -/* Project -------------------------------------------------------------------*/ - #include "img_iface.hpp" - #include "user_iface.hpp" -/* Module --------------------------------------------------------------------*/ - #include "proc_common.hpp" - - #include "proc_coins.hpp" - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define COINS_MAX 1024 - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ -struct Coins_Properties { - /* position */ - int x; - int y; - - /* value */ - uint8_t diameter_pix; - double diameter_mm; - double value; -}; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ -/* Static --------------------------------------------------------------------*/ -static class std::vector <class std::vector <class cv::Point_ <int>>> contours; -static class cv::Mat hierarchy; -static class cv::Rect_ <int> rectangle [COINS_MAX]; -static int coins_n; -static struct Coins_Properties coins [COINS_MAX]; -static double ratio_mm_per_pix; -static double value_total; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_coins (int status); - -static void coins_segmentate (void); -static int coins_positions (void); -static void coins_diameters_pix (void); -static void calibrate_mm_per_pix (void); -static void coins_diameters_mm (void); -static int coins_values (void); -static double coin_value (double diameter_mm); -static void coins_total_value (void); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -int proc_coins (void) -{ - int status; - - proc_save_mem(0); - /* Segmentate coins */ - { - /* Measure time */ - clock_start(); - - coins_segmentate(); - - /* Measure time */ - clock_stop("Segmentate coins"); - } - /* Find coins positions */ - { - /* Measure time */ - clock_start(); - - status = coins_positions(); - if (status) { - result_coins(status); - return status; - } - - /* Measure time */ - clock_stop("Find coins positions"); - } - /* Get coin diameters in pixels */ - { - /* Measure time */ - clock_start(); - - coins_diameters_pix(); - - /* Measure time */ - clock_stop("Coins diameters in pixels"); - } - /* Calibrate with the biggest coin; every img should have a 2 € coin */ - { - /* Measure time */ - clock_start(); - - calibrate_mm_per_pix(); - - /* Measure time */ - clock_stop("Calibrate (mm per pix)"); - } - /* Get coins diameters in mm */ - { - /* Measure time */ - clock_start(); - - coins_diameters_mm(); - - /* Measure time */ - clock_stop("Coins diameters in mm"); - } - /* Get coins values (by their sizes) */ - { - /* Measure time */ - clock_start(); - - status = coins_values(); - if (status) { - result_coins(status); - return status; - } - - /* Measure time */ - clock_stop("Coins values"); - } - /* Add total value */ - { - /* Measure time */ - clock_start(); - - coins_total_value(); - - /* Measure time */ - clock_stop("Total value"); - } - - status = COINS_OK; - result_coins(status); - return status; -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_coins (int status) -{ - /* Cleanup */ - - /* Write result into log */ - switch (status) { - case COINS_OK: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: OK"); - break; - case COINS_NOK_COINS: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK_COINS"); - break; -#if 0 - case COINS_NOK_OVERLAP: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK_OVERLAP"); - break; -#endif - case COINS_NOK_SIZE: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK_SIZE"); - break; - default: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK"); - break; - } - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - -static void coins_segmentate (void) -{ - proc_load_mem(0); - - proc_cmp(IMG_IFACE_CMP_BLUE); - proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU); - proc_distance_transform(); - proc_local_max(); - proc_dilate(6); - proc_save_mem(1); -} - -static int coins_positions (void) -{ - int status; - int i; - - proc_load_mem(1); - - proc_contours(&contours, &hierarchy); - coins_n = contours.size(); - - /* If no contour is found, error: NOK_COINS */ - if (!coins_n) { - status = COINS_NOK_COINS; - return status; - } - - /* Get position of each contour */ - for (i = 0; i < coins_n; i++) { - proc_bounding_rect(&(contours[i]), &(rectangle[i]), true); - coins[i].x = rectangle[i].x + rectangle[i].width / 2.0; - coins[i].y = rectangle[i].y + rectangle[i].height / 2.0; - } - - status = COINS_OK; - return status; -} - -static void coins_diameters_pix (void) -{ - int i; - - proc_load_mem(1); - - /* Get coins diameters in pixels */ - for (i = 0; i < coins_n; i++) { - proc_pixel_get(coins[i].x, coins[i].y, - &(coins[i].diameter_pix)); - coins[i].diameter_pix *= 2; - } -} - -static void calibrate_mm_per_pix (void) -{ - uint8_t coins_size_pix [coins_n]; - int i; - int max_pos; - int max_size; - - for (i = 0; i < coins_n; i++) { - coins_size_pix[i] = coins[i].diameter_pix; - } - - max_pos = alx_maximum_u8(coins_n, coins_size_pix); - max_size = coins_size_pix[max_pos]; - ratio_mm_per_pix = 25.75 / max_size; -} - -static void coins_diameters_mm (void) -{ - int i; - - for (i = 0; i < coins_n; i++) { - coins[i].diameter_mm = ratio_mm_per_pix * - coins[i].diameter_pix; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin[%i]: %.2lf mm", - i, - coins[i].diameter_mm); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - } -} - -static int coins_values (void) -{ - int status; - int i; - - for (i = 0; i < coins_n; i++) { - coins[i].value = coin_value(coins[i].diameter_mm); - - /* If a coin is of invalid size, error: NOK_SIZE */ - if (coins[i].value < 0) { - status = COINS_NOK_SIZE; - return status; - } - - /* Write values into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin[%i]: %.2lf EUR", - i, - coins[i].value); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - } - - status = COINS_OK; - return status; -} - -static double coin_value (double diameter_mm) -{ - double value; - - /* Get coin value by its diameter in mm */ - if (diameter_mm > 27.00) { - value = -1; - } else if (diameter_mm > 25.00) { - value = 2.00; - } else if (diameter_mm > 23.75) { - value = 0.50; - } else if (diameter_mm > 22.75) { - value = 1.00; - } else if (diameter_mm > 21.75) { - value = 0.20; - } else if (diameter_mm > 20.50) { - value = 0.05; - } else if (diameter_mm > 19.25) { - value = 0.10; - } else if (diameter_mm > 17.50) { - value = 0.02; - } else if (diameter_mm > 15.00) { - value = 0.01; - } else { - value = -1; - } - - return value; -} - -static void coins_total_value (void) -{ - int i; - - value_total = 0.00; - - for (i = 0; i < coins_n; i++) { - value_total += coins[i].value; - } - - /* Write total value into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Total value: %.2lf EUR", - value_total); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/src/proc_label.cpp b/modules/proc/src/proc_label.cpp deleted file mode 100644 index 2f09c90..0000000 --- a/modules/proc/src/proc_label.cpp +++ /dev/null @@ -1,377 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <cstdio> - #include <cstring> -/* Packages ------------------------------------------------------------------*/ - #include <opencv2/opencv.hpp> - #include <zbar.h> -/* Project -------------------------------------------------------------------*/ - #include "img_iface.hpp" - #include "user_iface.hpp" -/* Module --------------------------------------------------------------------*/ - #include "proc_common.hpp" - - #include "proc_label.hpp" - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -/* Global --------------------------------------------------------------------*/ - -/* Static --------------------------------------------------------------------*/ -static class std::vector <class std::vector <class cv::Point_ <int>>> contours; -static class cv::Mat hierarchy; -static class cv::RotatedRect rect; - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_label (int status); - -static int label_find (void); -static void label_align (void); -static int find_cerdo (void); -static int barcode_read (void); -static int barcode_chk_prod (void); -static void price_read (void); -static int price_chk (void); - - -/****************************************************************************** - ******* global functions ***************************************************** - ******************************************************************************/ -int proc_label (void) -{ - int status; - - proc_save_mem(0); - /* Find label (position and angle) */ - { - /* Measure time */ - clock_start(); - - status = label_find(); - if (status) { - result_label(status); - return status; - } - - /* Measure time */ - clock_stop("Find label"); - } - /* Align label and extract green component */ - { - /* Measure time */ - clock_start(); - - label_align(); - - /* Measure time */ - clock_stop("Align label"); - } - /* Find "Cerdo" in aligned image */ - { - /* Measure time */ - clock_start(); - - status = find_cerdo(); - if (status) { - result_label(status); - return status; - } - - /* Measure time */ - clock_stop("Find cerdo (OCR)"); - } - /* Read barcode in original image */ - { - /* Measure time */ - clock_start(); - - status = barcode_read(); - if (status) { - result_label(status); - return status; - } - - /* Measure time */ - clock_stop("Read barcode (zbar)"); - } - /* Check product code in barcode */ - { - /* Measure time */ - clock_start(); - - status = barcode_chk_prod(); - if (status) { - result_label(status); - return status; - } - - /* Measure time */ - clock_stop("Chk product code"); - } - /* Read price in aligned image (green component) */ - { - /* Measure time */ - clock_start(); - - price_read(); - - /* Measure time */ - clock_stop("Read price (OCR)"); - } - /* Check label price with barcode price */ - { - /* Measure time */ - clock_start(); - - status = price_chk(); - if (status) { - result_label(status); - return status; - } - - /* Measure time */ - clock_stop("Check price"); - } - - status = LABEL_OK; - result_label(status); - return status; -} - - -/****************************************************************************** - ******* static functions ***************************************************** - ******************************************************************************/ -static void result_label (int status) -{ - /* Cleanup */ - - /* Write result into log */ - switch (status) { - case LABEL_OK: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Label: OK"); - break; - case LABEL_NOK_LABEL: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Label: NOK_LABEL"); - break; - case LABEL_NOK_CERDO: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Label: NOK_CERDO"); - break; - case LABEL_NOK_BCODE: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Label: NOK_BCODE"); - break; - case LABEL_NOK_PRODUCT: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Label: NOK_PRODUCT"); - break; - case LABEL_NOK_PRICE: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Label: NOK_PRICE"); - break; - default: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Label: NOK"); - break; - } - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; -} - -static int label_find (void) -{ - int status; - int tmp; - - proc_load_mem(0); - - proc_cmp(IMG_IFACE_CMP_BLUE); - proc_smooth(IMGI_SMOOTH_MEDIAN, 7); -#if 0 - proc_adaptive_threshold(CV_ADAPTIVE_THRESH_MEAN_C, - CV_THRESH_BINARY, 5); -#else - proc_not(); -#endif - proc_smooth(IMGI_SMOOTH_MEAN, 21); - proc_threshold(cv::THRESH_BINARY_INV, 2); - proc_dilate_erode(100); - proc_contours(&contours, &hierarchy); - - /* If no contour is found, error: NOK_LABEL */ - if (!contours.size()) { - status = LABEL_NOK_LABEL; - return status; - } - - proc_min_area_rect(&(contours[0]), &rect, true); - - /* If angle is < -45º, it is taking into acount the incorrect side */ - if (rect.angle < -45.0) { - rect.angle += 90.0; - tmp = rect.size.width; - rect.size.width = rect.size.height; - rect.size.height = tmp; - } - - status = LABEL_OK; - return status; -} - -static void label_align (void) -{ - proc_load_mem(0); - - proc_rotate(rect.center.x, rect.center.y, rect.angle); - proc_cmp(IMG_IFACE_CMP_GREEN); - proc_save_mem(1); -} - -static int find_cerdo (void) -{ - int status; - int x; - int y; - int w; - int h; - bool cerdo_nok; - - proc_load_mem(1); - - x = rect.center.x - (1.05 * rect.size.width / 2); - if (x < 0) { - x = 0; - } - y = rect.center.y - (1.47 * rect.size.height / 2); - if (y < 0) { - y = 0; - } - w = rect.size.width / 2; - h = rect.size.height * 0.20; - proc_ROI(x, y, w, h); - proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); - proc_erode(1); - proc_OCR(IMG_IFACE_OCR_LANG_ENG, IMG_IFACE_OCR_CONF_NONE); - - /* Compare Label text to "Cerdo". */ - cerdo_nok = strncmp(img_ocr_text, "Cerdo", - strlen("Cerdo")); - - /* If string doesn't match, error: NOK_CERDO */ - if (cerdo_nok) { - status = LABEL_NOK_CERDO; - return status; - } - - status = LABEL_OK; - return status; -} - -static int barcode_read (void) -{ - int status; - - proc_load_mem(0); - - proc_cmp(IMG_IFACE_CMP_GREEN); - proc_zbar(zbar::ZBAR_EAN13); - - /* Check that 1 and only 1 bcode is read. */ - if (zb_codes.n != 1) { - status = LABEL_NOK_BCODE; - return status; - } - - status = LABEL_OK; - return status; -} - -static int barcode_chk_prod (void) -{ - int status; - bool prod_nok; - - prod_nok = strncmp(zb_codes.arr[0].data, "2301703", - strlen("2301703")); - if (prod_nok) { - status = LABEL_NOK_PRODUCT; - return status; - } - - status = LABEL_OK; - return status; -} - -static void price_read (void) -{ - int x; - int y; - int w; - int h; - - proc_load_mem(1); - - x = rect.center.x + (0.33 * rect.size.width / 2); - y = rect.center.y + (0.64 * rect.size.height / 2); - w = rect.size.width * 0.225; - h = rect.size.height * 0.15; - proc_ROI(x, y, w, h); - proc_smooth(IMGI_SMOOTH_MEAN, 3); - proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU); - proc_dilate_erode(1); - proc_threshold(cv::THRESH_BINARY, 1); - proc_OCR(IMG_IFACE_OCR_LANG_DIGITS, IMG_IFACE_OCR_CONF_PRICE); -} - -static int price_chk (void) -{ - int status; - char price [80]; - bool price_nok; - - /* Extract price from barcode */ - if (zb_codes.arr[0].data[8] != '0') { - snprintf(price, 80, "%c%c.%c%c", - zb_codes.arr[0].data[8], - zb_codes.arr[0].data[9], - zb_codes.arr[0].data[10], - zb_codes.arr[0].data[11]); - } else { - snprintf(price, 80, "%c.%c%c", - zb_codes.arr[0].data[9], - zb_codes.arr[0].data[10], - zb_codes.arr[0].data[11]); - } - - /* Compare price from barcode and from text */ - price_nok = strncmp(img_ocr_text, price, strlen(price)); - - if (price_nok) { - status = LABEL_NOK_PRICE; - return status; - } - - status = LABEL_OK; - return status; -} - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/proc/tmp/Makefile b/modules/proc/tmp/Makefile deleted file mode 100644 index 531b63e..0000000 --- a/modules/proc/tmp/Makefile +++ /dev/null @@ -1,177 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -LIBALX_INC_DIR = $(LIBALX_DIR)/inc/ - -IMG_INC_DIR = $(IMG_DIR)/inc/ -SAVE_INC_DIR = $(SAVE_DIR)/inc/ -USR_INC_DIR = $(USR_DIR)/inc/ - -INC_DIR = $(PROC_DIR)/inc/ -SRC_DIR = $(PROC_DIR)/src/ - -# dependencies - -_ALL = proc_label.o proc_lighters.o proc_objects.o \ - proc_coins.o proc_resistor.o \ - proc_common.o proc_iface.o -ALL = $(_ALL) proc_mod.o - -PROC_LAB_INC_IMG = img_iface.hpp -PROC_LAB_INC_USR = user_iface.hpp -PROC_LAB_INC = proc_label.hpp proc_common.hpp -PROC_LAB_DEPS = $(SRC_DIR)/proc_label.cpp \ - $(patsubst %,$(INC_DIR)/%,$(PROC_LAB_INC)) \ - $(patsubst %,$(IMG_INC_DIR)/%,$(PROC_LAB_INC_IMG)) \ - $(patsubst %,$(USR_INC_DIR)/%,$(PROC_LAB_INC_USR)) -PROC_LAB_INC_DIRS = -I $(INC_DIR) \ - -I $(IMG_INC_DIR) \ - -I $(USR_INC_DIR) - -PROC_LGHT_INC_LIBALX = libalx/alx_math.hpp -PROC_LGHT_INC_IMG = img_iface.hpp -PROC_LGHT_INC_USR = user_iface.hpp -PROC_LGHT_INC = proc_lighters.hpp proc_common.hpp -PROC_LGHT_DEPS = $(SRC_DIR)/proc_lighters.cpp \ - $(patsubst %,$(INC_DIR)/%,$(PROC_LGHT_INC)) \ - $(patsubst %,$(IMG_INC_DIR)/%,$(PROC_LGHT_INC_IMG)) \ - $(patsubst %,$(USR_INC_DIR)/%,$(PROC_LGHT_INC_USR)) \ - $(patsubst %,$(LIBALX_INC_DIR)/%,$(PROC_LGHT_INC_LIBALX)) -PROC_LGHT_INC_DIRS = -I $(INC_DIR) \ - -I $(IMG_INC_DIR) \ - -I $(USR_INC_DIR) \ - -I $(LIBALX_INC_DIR) - -PROC_OBJS_INC_LIBALX = libalx/alx_math.hpp -PROC_OBJS_INC_IMG = img_iface.hpp -PROC_OBJS_INC_USR = user_iface.hpp -PROC_OBJS_INC = proc_objects.hpp proc_common.hpp -PROC_OBJS_DEPS = $(SRC_DIR)/proc_objects.cpp \ - $(patsubst %,$(INC_DIR)/%,$(PROC_OBJS_INC)) \ - $(patsubst %,$(IMG_INC_DIR)/%,$(PROC_OBJS_INC_IMG)) \ - $(patsubst %,$(USR_INC_DIR)/%,$(PROC_OBJS_INC_USR)) \ - $(patsubst %,$(LIBALX_INC_DIR)/%,$(PROC_OBJS_INC_LIBALX)) -PROC_OBJS_INC_DIRS = -I $(INC_DIR) \ - -I $(IMG_INC_DIR) \ - -I $(USR_INC_DIR) \ - -I $(LIBALX_INC_DIR) - -PROC_COIN_INC_LIBALX = libalx/alx_math.hpp -PROC_COIN_INC_IMG = img_iface.hpp -PROC_COIN_INC_USR = user_iface.hpp -PROC_COIN_INC = proc_coins.hpp proc_common.hpp -PROC_COIN_DEPS = $(SRC_DIR)/proc_coins.cpp \ - $(patsubst %,$(INC_DIR)/%,$(PROC_COIN_INC)) \ - $(patsubst %,$(IMG_INC_DIR)/%,$(PROC_COIN_INC_IMG)) \ - $(patsubst %,$(USR_INC_DIR)/%,$(PROC_COIN_INC_USR)) \ - $(patsubst %,$(LIBALX_INC_DIR)/%,$(PROC_COIN_INC_LIBALX)) -PROC_COIN_INC_DIRS = -I $(INC_DIR) \ - -I $(IMG_INC_DIR) \ - -I $(USR_INC_DIR) \ - -I $(LIBALX_INC_DIR) - -PROC_RES_INC_IMG = img_iface.hpp -PROC_RES_INC_USR = user_iface.hpp -PROC_RES_INC = proc_resistor.hpp proc_common.hpp -PROC_RES_DEPS = $(SRC_DIR)/proc_resistor.cpp \ - $(patsubst %,$(INC_DIR)/%,$(PROC_RES_INC)) \ - $(patsubst %,$(IMG_INC_DIR)/%,$(PROC_RES_INC_IMG)) \ - $(patsubst %,$(USR_INC_DIR)/%,$(PROC_RES_INC_USR)) -PROC_RES_INC_DIRS = -I $(INC_DIR) \ - -I $(IMG_INC_DIR) \ - -I $(USR_INC_DIR) - -PROC_CMN_INC_IMG = img_iface.hpp -PROC_CMN_INC_USR = user_iface.hpp -PROC_CMN_INC = proc_common.hpp -PROC_CMN_DEPS = $(SRC_DIR)/proc_common.cpp \ - $(patsubst %,$(INC_DIR)/%,$(PROC_CMN_INC)) \ - $(patsubst %,$(IMG_INC_DIR)/%,$(PROC_CMN_INC_IMG)) \ - $(patsubst %,$(USR_INC_DIR)/%,$(PROC_CMN_INC_USR)) -PROC_CMN_INC_DIRS = -I $(INC_DIR) \ - -I $(IMG_INC_DIR) \ - -I $(USR_INC_DIR) - -PROC_IFACE_INC_LIBALX = libalx/io/alx_input.h -PROC_IFACE_INC_IMG = img_iface.h -PROC_IFACE_INC_SAVE = save.h -PROC_IFACE_INC_USR = user_iface.h -PROC_IFACE_INC = proc_iface.h proc_label.h proc_coins.h proc_resistor.h -PROC_IFACE_DEPS = $(SRC_DIR)/proc_iface.c \ - $(patsubst %,$(INC_DIR)/%,$(PROC_IFACE_INC)) \ - $(patsubst %,$(IMG_INC_DIR)/%,$(PROC_IFACE_INC_IMG)) \ - $(patsubst %,$(SAVE_INC_DIR)/%,$(PROC_IFACE_INC_SAVE)) \ - $(patsubst %,$(USR_INC_DIR)/%,$(PROC_IFACE_INC_USR)) \ - $(patsubst %,$(LIBALX_INC_DIR)/%,$(PROC_IFACE_INC_LIBALX)) -PROC_IFACE_INC_DIRS = -I $(INC_DIR) \ - -I $(IMG_INC_DIR) \ - -I $(SAVE_INC_DIR) \ - -I $(USR_INC_DIR) \ - -I $(LIBALX_INC_DIR) - -# target: dependencies -# action - -all: $(ALL) - - -proc_mod.o: $(_ALL) - $(Q)$(LD) -r $^ -o $@ - @echo " LD $@" - - -proc_label.s: $(PROC_LAB_DEPS) - $(Q)$(CXX) $(CXXFLAGS) $(PROC_LAB_INC_DIRS) -S $< -o $@ - @echo " CXX $@" -proc_label.o: proc_label.s $(PROC_LAB_DEPS) - $(Q)$(AS) $< -o $@ - @echo " AS $@" - -proc_lighters.s: $(PROC_LGHT_DEPS) - $(Q)$(CXX) $(CXXFLAGS) $(PROC_LGHT_INC_DIRS) -S $< -o $@ - @echo " CXX $@" -proc_lighters.o: proc_lighters.s $(PROC_LGHT_DEPS) - $(Q)$(AS) $< -o $@ - @echo " AS $@" - -proc_objects.s: $(PROC_OBJS_DEPS) - $(Q)$(CXX) $(CXXFLAGS) $(PROC_OBJS_INC_DIRS) -S $< -o $@ - @echo " CXX $@" -proc_objects.o: proc_objects.s $(PROC_OBJS_DEPS) - $(Q)$(AS) $< -o $@ - @echo " AS $@" - -proc_coins.s: $(PROC_COIN_DEPS) - $(Q)$(CXX) $(CXXFLAGS) $(PROC_COIN_INC_DIRS) -S $< -o $@ - @echo " CXX $@" -proc_coins.o: proc_coins.s $(PROC_COIN_DEPS) - $(Q)$(AS) $< -o $@ - @echo " AS $@" - -proc_resistor.s: $(PROC_RES_DEPS) - $(Q)$(CXX) $(CXXFLAGS) $(PROC_RES_INC_DIRS) -S $< -o $@ - @echo " CXX $@" -proc_resistor.o: proc_resistor.s $(PROC_RES_DEPS) - $(Q)$(AS) $< -o $@ - @echo " AS $@" - -proc_common.s: $(PROC_CMN_DEPS) - $(Q)$(CXX) $(CXXFLAGS) $(PROC_CMN_INC_DIRS) -S $< -o $@ - @echo " CXX $@" -proc_common.o: proc_common.s $(PROC_CMN_DEPS) - $(Q)$(AS) $< -o $@ - @echo " AS $@" - -proc_iface.s: $(PROC_IFACE_DEPS) - $(Q)$(CC) $(CFLAGS) $(PROC_IFACE_INC_DIRS) -S $< -o $@ - @echo " CC $@" -proc_iface.o: proc_iface.s $(PROC_IFACE_DEPS) - $(Q)$(AS) $< -o $@ - @echo " AS $@" - - -clean: - $(Q)rm -f *.o *.s diff --git a/modules/save/Makefile b/modules/save/Makefile deleted file mode 100644 index 614a58c..0000000 --- a/modules/save/Makefile +++ /dev/null @@ -1,24 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -TMP_DIR = $(SAVE_DIR)/tmp/ - -# target: dependencies -# action - -all: - $(Q)cd $(TMP_DIR) && $(MAKE) && cd .. - -clean: - $(Q)cd $(TMP_DIR) && $(MAKE) clean && cd .. - -################################################################################ -######## End of file ########################################################### -################################################################################ -######## End of file ########################################################### -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/modules/save/tmp/Makefile b/modules/save/tmp/Makefile deleted file mode 100644 index 4f2abf9..0000000 --- a/modules/save/tmp/Makefile +++ /dev/null @@ -1,45 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -USR_INC_DIR = $(USR_DIR)/inc/ - -INC_DIR = $(SAVE_DIR)/inc/ -SRC_DIR = $(SAVE_DIR)/src/ - -# dependencies - -_ALL = save.o -ALL = $(_ALL) save_mod.o - -SAVE_INC_VIEW = user_iface.hpp -SAVE_INC = save.hpp -SAVE_DEPS = $(SRC_DIR)/save.cpp \ - $(patsubst %,$(INC_DIR)/%,$(SAVE_INC)) \ - $(patsubst %,$(USR_INC_DIR)/%,$(SAVE_INC_USR)) -SAVE_INC_DIRS = -I $(INC_DIR) \ - -I $(USR_INC_DIR) - -# target: dependencies -# action - -all: $(ALL) - - -save_mod.o: $(_ALL) - $(Q)$(LD) -r $^ -o $@ - @echo " LD $@" - - -save.s: $(SAVE_DEPS) - $(Q)$(CXX) $(CXXFLAGS) $(SAVE_INC_DIRS) -S $< -o $@ - @echo " CXX $@" -save.o: save.s - $(Q)$(AS) $< -o $@ - @echo " AS $@" - - -clean: - $(Q)rm -f *.o *.s diff --git a/modules/tmp/Makefile b/modules/tmp/Makefile deleted file mode 100644 index 93693cc..0000000 --- a/modules/tmp/Makefile +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/make -f - -# MACRO = substitute with this - -# directories - -ABOUT_TMP_DIR = $(ABOUT_DIR)/tmp/ -CTRL_TMP_DIR = $(CTRL_DIR)/tmp/ -IMG_TMP_DIR = $(IMG_DIR)/tmp/ -MENU_TMP_DIR = $(MENU_DIR)/tmp/ -PROC_TMP_DIR = $(PROC_DIR)/tmp/ -SAVE_TMP_DIR = $(SAVE_DIR)/tmp/ -USR_TMP_DIR = $(USR_DIR)/tmp/ - -# dependencies - -ALL = modules.o - -MODS_OBJ_ABOUT = about_mod.o -MODS_OBJ_CTRL = ctrl_mod.o -MODS_OBJ_IMG = img_mod.o -MODS_OBJ_MENU = menu_mod.o -MODS_OBJ_PROC = proc_mod.o -MODS_OBJ_SAVE = save_mod.o -MODS_OBJ_USR = user_mod.o -MODS_OBJS = $(patsubst %,$(ABOUT_TMP_DIR)/%,$(MODS_OBJ_ABOUT)) \ - $(patsubst %,$(CTRL_TMP_DIR)/%,$(MODS_OBJ_CTRL)) \ - $(patsubst %,$(IMG_TMP_DIR)/%,$(MODS_OBJ_IMG)) \ - $(patsubst %,$(MENU_TMP_DIR)/%,$(MODS_OBJ_MENU)) \ - $(patsubst %,$(PROC_TMP_DIR)/%,$(MODS_OBJ_PROC)) \ - $(patsubst %,$(SAVE_TMP_DIR)/%,$(MODS_OBJ_SAVE)) \ - $(patsubst %,$(USR_TMP_DIR)/%,$(MODS_OBJ_USR)) - -# target: dependencies -# action - -all: $(ALL) - - -modules.o: $(MODS_OBJS) - $(Q)$(LD) -r $^ -o $@ - @echo " LD $@" - - -clean: - $(Q)rm -f *.o diff --git a/modules/user/Makefile b/modules/user/Makefile deleted file mode 100644 index 82df218..0000000 --- a/modules/user/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -TMP_DIR = $(USR_DIR)/tmp/ - -# target: dependencies -# action - -all: - $(Q)cd $(TMP_DIR) && $(MAKE) && cd .. - -clean: - $(Q)cd $(TMP_DIR) && $(MAKE) clean && cd .. - -################################################################################ -######## End of file ########################################################### -################################################################################ diff --git a/modules/user/inc/user_clui.h b/modules/user/inc/user_clui.h deleted file mode 100644 index 807c508..0000000 --- a/modules/user/inc/user_clui.h +++ /dev/null @@ -1,31 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_USER_CLUI_H - # define VA_USER_CLUI_H - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void user_clui_init (void); -int user_clui (const char *title, const char *subtitle); -void user_clui_fname (const char *filepath, char *filename); -void user_clui_show_log (const char *title, const char *subtitle); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* user_clui.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/user/inc/user_iface.h b/modules/user/inc/user_iface.h deleted file mode 100644 index a994ae1..0000000 --- a/modules/user/inc/user_iface.h +++ /dev/null @@ -1,166 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_USER_IFACE_H - # define VA_USER_IFACE_H - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define LOG_LEN (1048576) - # define LOG_LINE_LEN (80) - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* intX_t */ - #include <stdint.h> - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Player_Iface_Mode { - USER_IFACE_FOO, - USER_IFACE_CLUI, - USER_IFACE_TUI - }; - - enum Player_Iface_Action { - USER_IFACE_ACT_FOO = 0x000000u, - - USER_IFACE_ACT_ALX = 0x000010u, - USER_IFACE_ACT_LOCAL_MAX, - USER_IFACE_ACT_SKELETON, - USER_IFACE_ACT_LINES_HORIZONTAL, - USER_IFACE_ACT_LINES_VERTICAL, - USER_IFACE_ACT_MEAN_HORIZONTAL, - USER_IFACE_ACT_MEAN_VERTICAL, - USER_IFACE_ACT_MEDIAN_HORIZONTAL, - USER_IFACE_ACT_MEDIAN_VERTICAL, - - USER_IFACE_ACT_CV = 0x000100u, - USER_IFACE_ACT_PIXEL_GET, - USER_IFACE_ACT_PIXEL_SET, - USER_IFACE_ACT_SET_ROI, - USER_IFACE_ACT_SET_ROI_2RECT, - USER_IFACE_ACT_AND_2REF, - USER_IFACE_ACT_NOT, - USER_IFACE_ACT_OR_2REF, - USER_IFACE_ACT_COMPONENT, - USER_IFACE_ACT_DILATE, - USER_IFACE_ACT_ERODE, - USER_IFACE_ACT_DILATE_ERODE, - USER_IFACE_ACT_ERODE_DILATE, - USER_IFACE_ACT_SMOOTH, - USER_IFACE_ACT_SOBEL, - USER_IFACE_ACT_BORDER, - USER_IFACE_ACT_MIRROR, - USER_IFACE_ACT_ROTATE_ORTO, - USER_IFACE_ACT_ROTATE, - USER_IFACE_ACT_ROTATE_2RECT, - USER_IFACE_ACT_ADAPTIVE_THRESHOLD, - USER_IFACE_ACT_CVT_COLOR, - USER_IFACE_ACT_DISTANCE_TRANSFORM, - USER_IFACE_ACT_THRESHOLD, - USER_IFACE_ACT_HISTOGRAM, - USER_IFACE_ACT_HISTOGRAM_C3, - USER_IFACE_ACT_CONTOURS, - USER_IFACE_ACT_CONTOURS_SIZE, - USER_IFACE_ACT_BOUNDING_RECT, - USER_IFACE_ACT_FIT_ELLIPSE, - USER_IFACE_ACT_MIN_AREA_RECT, - USER_IFACE_ACT_HOUGH_CIRCLES, - - USER_IFACE_ACT_ORB = 0x000200u, - USER_IFACE_ACT_ALIGN, - - USER_IFACE_ACT_CALIB3D = 0x000400u, - USER_IFACE_ACT_CALIBRATE, - USER_IFACE_ACT_UNDISTORT, - - USER_IFACE_ACT_ZB = 0x000800u, - USER_IFACE_ACT_DECODE, - - USER_IFACE_ACT_OCR = 0x001000u, - USER_IFACE_ACT_READ, - - USER_IFACE_ACT_IMGI = 0x002000u, - USER_IFACE_ACT_APPLY, - USER_IFACE_ACT_DISCARD, - USER_IFACE_ACT_SAVE_MEM, - USER_IFACE_ACT_LOAD_MEM, - USER_IFACE_ACT_SAVE_REF, - - USER_IFACE_ACT_SAVE = 0x004000u, - USER_IFACE_ACT_SAVE_FILE, - USER_IFACE_ACT_SAVE_UPDT, - - USER_IFACE_ACT_PROC = 0x008000u, - USER_IFACE_ACT_PROC_LABEL_SERIES, - USER_IFACE_ACT_PROC_LABEL_CALIB, - USER_IFACE_ACT_PROC_OBJECTS_SERIES, - USER_IFACE_ACT_PROC_OBJECTS_CALIB, - USER_IFACE_ACT_PROC_COINS_SERIES, - USER_IFACE_ACT_PROC_COINS_CALIB, - USER_IFACE_ACT_PROC_RESISTOR_SERIES, - USER_IFACE_ACT_PROC_RESISTOR_CALIB, - USER_IFACE_ACT_PROC_LIGHTERS_SERIES, - USER_IFACE_ACT_PROC_LIGHTERS_CALIB, - - USER_IFACE_ACT_USRI = 0x010000u, - USER_IFACE_ACT_SHOW_OCR, - USER_IFACE_ACT_QUIT - }; - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ - struct User_Iface_Log { - int len; - char line [LOG_LEN] [LOG_LINE_LEN]; - int lvl [LOG_LEN]; - int visible; - }; - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern int user_iface_mode; -extern struct User_Iface_Log user_iface_log; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void user_iface_init (void); -void user_iface_cleanup (void); -void user_iface (void); -void user_iface_show_log (const char *title, const char *subtitle); -void user_iface_fname (const char *filepath, char *filename); -double user_iface_getdbl (double m, double def, double M, - const char *title, const char *help); -int64_t user_iface_getint (double m, int64_t def, double M, - const char *title, const char *help); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* user_iface.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/user/inc/user_iface.hpp b/modules/user/inc/user_iface.hpp deleted file mode 100644 index 26fadfb..0000000 --- a/modules/user/inc/user_iface.hpp +++ /dev/null @@ -1,178 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_USER_IFACE_HPP - # define VA_USER_IFACE_HPP - - -/****************************************************************************** - ******* macros *************************************************************** - ******************************************************************************/ - # define LOG_LEN (1048576) - # define LOG_LINE_LEN (80) - - -/****************************************************************************** - ******* headers ************************************************************** - ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* intX_t */ - #include <cstdint> - - -/****************************************************************************** - ******* enums **************************************************************** - ******************************************************************************/ - enum Player_Iface_Mode { - USER_IFACE_FOO, - USER_IFACE_CLUI, - USER_IFACE_TUI - }; - - enum Player_Iface_Action { - USER_IFACE_ACT_FOO = 0x000000u, - - USER_IFACE_ACT_ALX = 0x000010u, - USER_IFACE_ACT_LOCAL_MAX, - USER_IFACE_ACT_SKELETON, - USER_IFACE_ACT_LINES_HORIZONTAL, - USER_IFACE_ACT_LINES_VERTICAL, - USER_IFACE_ACT_MEAN_HORIZONTAL, - USER_IFACE_ACT_MEAN_VERTICAL, - USER_IFACE_ACT_MEDIAN_HORIZONTAL, - USER_IFACE_ACT_MEDIAN_VERTICAL, - - USER_IFACE_ACT_CV = 0x000100u, - USER_IFACE_ACT_PIXEL_GET, - USER_IFACE_ACT_PIXEL_SET, - USER_IFACE_ACT_SET_ROI, - USER_IFACE_ACT_SET_ROI_2RECT, - USER_IFACE_ACT_AND_2REF, - USER_IFACE_ACT_NOT, - USER_IFACE_ACT_OR_2REF, - USER_IFACE_ACT_COMPONENT, - USER_IFACE_ACT_DILATE, - USER_IFACE_ACT_ERODE, - USER_IFACE_ACT_DILATE_ERODE, - USER_IFACE_ACT_ERODE_DILATE, - USER_IFACE_ACT_SMOOTH, - USER_IFACE_ACT_SOBEL, - USER_IFACE_ACT_BORDER, - USER_IFACE_ACT_MIRROR, - USER_IFACE_ACT_ROTATE_ORTO, - USER_IFACE_ACT_ROTATE, - USER_IFACE_ACT_ROTATE_2RECT, - USER_IFACE_ACT_ADAPTIVE_THRESHOLD, - USER_IFACE_ACT_CVT_COLOR, - USER_IFACE_ACT_DISTANCE_TRANSFORM, - USER_IFACE_ACT_THRESHOLD, - USER_IFACE_ACT_HISTOGRAM, - USER_IFACE_ACT_HISTOGRAM_C3, - USER_IFACE_ACT_CONTOURS, - USER_IFACE_ACT_CONTOURS_SIZE, - USER_IFACE_ACT_BOUNDING_RECT, - USER_IFACE_ACT_FIT_ELLIPSE, - USER_IFACE_ACT_MIN_AREA_RECT, - USER_IFACE_ACT_HOUGH_CIRCLES, - - USER_IFACE_ACT_ORB = 0x000200u, - USER_IFACE_ACT_ALIGN, - - USER_IFACE_ACT_CALIB3D = 0x000400u, - USER_IFACE_ACT_CALIBRATE, - USER_IFACE_ACT_UNDISTORT, - - USER_IFACE_ACT_ZB = 0x000800u, - USER_IFACE_ACT_DECODE, - - USER_IFACE_ACT_OCR = 0x001000u, - USER_IFACE_ACT_READ, - - USER_IFACE_ACT_IMGI = 0x002000u, - USER_IFACE_ACT_APPLY, - USER_IFACE_ACT_DISCARD, - USER_IFACE_ACT_SAVE_MEM, - USER_IFACE_ACT_LOAD_MEM, - USER_IFACE_ACT_SAVE_REF, - - USER_IFACE_ACT_SAVE = 0x004000u, - USER_IFACE_ACT_SAVE_FILE, - USER_IFACE_ACT_SAVE_UPDT, - - USER_IFACE_ACT_PROC = 0x008000u, - USER_IFACE_ACT_PROC_LABEL_SERIES, - USER_IFACE_ACT_PROC_LABEL_CALIB, - USER_IFACE_ACT_PROC_OBJECTS_SERIES, - USER_IFACE_ACT_PROC_OBJECTS_CALIB, - USER_IFACE_ACT_PROC_COINS_SERIES, - USER_IFACE_ACT_PROC_COINS_CALIB, - USER_IFACE_ACT_PROC_RESISTOR_SERIES, - USER_IFACE_ACT_PROC_RESISTOR_CALIB, - USER_IFACE_ACT_PROC_LIGHTERS_SERIES, - USER_IFACE_ACT_PROC_LIGHTERS_CALIB, - - USER_IFACE_ACT_USRI = 0x010000u, - USER_IFACE_ACT_SHOW_OCR, - USER_IFACE_ACT_QUIT - }; - - -/****************************************************************************** - ******* structs ************************************************************** - ******************************************************************************/ - struct User_Iface_Log { - int len; - char line [LOG_LEN] [LOG_LINE_LEN]; - int lvl [LOG_LEN]; - int visible; - }; - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -extern "C" { - - -/****************************************************************************** - ******* variables ************************************************************ - ******************************************************************************/ -extern int user_iface_mode; -extern struct User_Iface_Log user_iface_log; - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void user_iface_init (void); -void user_iface_cleanup (void); -void user_iface (void); -void user_iface_show_log (const char *title, const char *subtitle); -void user_iface_fname (const char *filepath, char *filename); -double user_iface_getdbl (double m, double def, double M, - const char *title, const char *help); -int64_t user_iface_getint (double m, int64_t def, double M, - const char *title, const char *help); - - -/****************************************************************************** - ******* C wrapper ************************************************************ - ******************************************************************************/ -} /* extern "C" */ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* user_iface.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/user/inc/user_tui.h b/modules/user/inc/user_tui.h deleted file mode 100644 index 64dd880..0000000 --- a/modules/user/inc/user_tui.h +++ /dev/null @@ -1,37 +0,0 @@ -/****************************************************************************** - * Copyright (C) 2018 Alejandro Colomar Andrés * - * SPDX-License-Identifier: GPL-2.0-only * - ******************************************************************************/ - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# ifndef VA_USER_TUI_H - # define VA_USER_TUI_H - - -/****************************************************************************** - ******* functions ************************************************************ - ******************************************************************************/ -void user_tui_init (void); -void user_tui_cleanup (void); -int user_tui (const char *title, const char *subtitle); -void user_tui_show_log (const char *title, const char *subtitle); -void user_tui_fname (const char *filepath, char *filename); -double user_tui_getdbl (double m, double def, double M, - const char *title, const char *help); -int64_t user_tui_getint (double m, int64_t def, double M, - const char *title, const char *help); -void user_tui_show_ocr (void); - - -/****************************************************************************** - ******* include guard ******************************************************** - ******************************************************************************/ -# endif /* user_tui.h */ - - -/****************************************************************************** - ******* end of file ********************************************************** - ******************************************************************************/ diff --git a/modules/user/tmp/Makefile b/modules/user/tmp/Makefile deleted file mode 100644 index bc4f607..0000000 --- a/modules/user/tmp/Makefile +++ /dev/null @@ -1,89 +0,0 @@ -# -*- MakeFile -*- - -# MACRO = substitute with this - -# directories - -LIBALX_INC_DIR = $(LIBALX_DIR)/inc/ -IMG_INC_DIR = $(IMG_DIR)/inc/ - -IMG_INC_DIR = $(IMG_DIR)/inc/ -MENU_INC_DIR = $(MENU_DIR)/inc/ -PROC_INC_DIR = $(PROC_DIR)/inc/ - -INC_DIR = $(USR_DIR)/inc/ -SRC_DIR = $(USR_DIR)/src/ - -# dependencies - -_ALL = user_iface.o user_clui.o user_tui.o -ALL = $(_ALL) user_mod.o - -UI_INC_IMG = img_iface.h -UI_INC_PROC = proc_iface.h -UI_INC = user_iface.h user_clui.h user_tui.h -UI_DEPS = $(SRC_DIR)/user_iface.c \ - $(patsubst %,$(INC_DIR)/%,$(UI_INC)) \ - $(patsubst %,$(IMG_INC_DIR)/%,$(UI_INC_IMG)) \ - $(patsubst %,$(PROC_INC_DIR)/%,$(UI_INC_PROC)) -UI_INC_DIRS = -I $(INC_DIR) \ - -I $(IMG_INC_DIR) \ - -I $(PROC_INC_DIR) - -UCLUI_INC_LIBALX = libalx/curses/alx_ncur.h -UCLUI_INC_IMG = img_iface.h -UCLUI_INC = user_clui.h user_iface.h -UCLUI_DEPS = $(SRC_DIR)/user_clui.c \ - $(patsubst %,$(INC_DIR)/%,$(UCLUI_INC)) \ - $(patsubst %,$(IMG_INC_DIR)/%,$(UCLUI_INC_IMG)) \ - $(patsubst %,$(LIBALX_INC_DIR)/%,$(UCLUI_INC_LIBALX)) -UCLUI_INC_DIRS = -I $(INC_DIR) \ - -I $(LIBALX_INC_DIR) \ - -I $(IMG_INC_DIR) - -UTUI_INC_LIBALX = libalx/curses/alx_ncur.h -UTUI_INC_IMG = img_iface.h -UTUI_INC = user_tui.h user_iface.h -UTUI_DEPS = $(SRC_DIR)/user_tui.c \ - $(patsubst %,$(INC_DIR)/%,$(UTUI_INC)) \ - $(patsubst %,$(IMG_INC_DIR)/%,$(UTUI_INC_IMG)) \ - $(patsubst %,$(LIBALX_INC_DIR)/%,$(UTUI_INC_LIBALX)) -UTUI_INC_DIRS = -I $(INC_DIR) \ - -I $(LIBALX_INC_DIR) \ - -I $(IMG_INC_DIR) - -# target: dependencies -# action - -all: $(ALL) - - -user_mod.o: $(_ALL) - $(Q)$(LD) -r $^ -o $@ - @echo " LD $@" - - -user_iface.s: $(UI_DEPS) - $(Q)$(CC) $(CFLAGS) $(UI_INC_DIRS) -S $< -o $@ - @echo " CC $@" -user_iface.o: user_iface.s - $(Q)$(AS) $< -o $@ - @echo " AS $@" - -user_clui.s: $(UCLUI_DEPS) - $(Q)$(CC) $(CFLAGS) $(UCLUI_INC_DIRS) -S $< -o $@ - @echo " CC $@" -user_clui.o: user_clui.s - $(Q)$(AS) $< -o $@ - @echo " AS $@" - -user_tui.s: $(UTUI_DEPS) - $(Q)$(CC) $(CFLAGS) $(UTUI_INC_DIRS) -S $< -o $@ - @echo " CC $@" -user_tui.o: user_tui.s - $(Q)$(AS) $< -o $@ - @echo " AS $@" - - -clean: - $(Q)rm -f *.o *.s diff --git a/share/COPYRIGHT.txt b/share/vision-artificial/COPYRIGHT.txt index 64ca5ad..64ca5ad 100644 --- a/share/COPYRIGHT.txt +++ b/share/vision-artificial/COPYRIGHT.txt diff --git a/share/DISCLAIMER.txt b/share/vision-artificial/DISCLAIMER.txt index 291440a..291440a 100644 --- a/share/DISCLAIMER.txt +++ b/share/vision-artificial/DISCLAIMER.txt diff --git a/share/HELP.txt b/share/vision-artificial/HELP.txt index 000f7ef..000f7ef 100644 --- a/share/HELP.txt +++ b/share/vision-artificial/HELP.txt diff --git a/share/LICENSE.txt b/share/vision-artificial/LICENSE.txt index 0776f74..0776f74 100644 --- a/share/LICENSE.txt +++ b/share/vision-artificial/LICENSE.txt diff --git a/share/README.txt b/share/vision-artificial/README.txt index b523695..b523695 100644 --- a/share/README.txt +++ b/share/vision-artificial/README.txt diff --git a/share/USAGE.txt b/share/vision-artificial/USAGE.txt index fcbbfc7..fcbbfc7 100644 --- a/share/USAGE.txt +++ b/share/vision-artificial/USAGE.txt diff --git a/share/price b/share/vision-artificial/price index c2b89cc..c2b89cc 100644 --- a/share/price +++ b/share/vision-artificial/price diff --git a/modules/about/src/about.c b/src/about/about.c index e36828b..60f5104 100644 --- a/modules/about/src/about.c +++ b/src/about/about.c @@ -7,24 +7,33 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* printf() */ - #include <stdio.h> - #include <stdlib.h> -/* libalx --------------------------------------------------------------------*/ - /* alx_snprint_file() */ - #include "libalx/io/alx_file.h" -/* Module --------------------------------------------------------------------*/ - #include "about.h" +#include "vision-artificial/about/about.h" + +#include <errno.h> +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> + +#include "libalx/base/errno/errno_str.h" +#include "libalx/base/stdio/sprint_file.h" /****************************************************************************** ******* macros *************************************************************** ******************************************************************************/ - # define BUFF_SIZE_TEXT (1048576) +#define BUFF_SIZE_TEXT (0xFFFF) /* 64 KiB */ +#define BEGINNING "\n┌──────────────────────────────────────────────────────────────────────────────┐\n" +#define ENDING "└──────────────────────────────────────────────────────────────────────────────┘\n\n" + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ - # define BEGINNING "\n┌──────────────────────────────────────────────────────────────────────────────┐\n" - # define ENDING "└──────────────────────────────────────────────────────────────────────────────┘\n\n" + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ /****************************************************************************** @@ -34,81 +43,84 @@ char share_path [FILENAME_MAX]; /****************************************************************************** - ******* main ***************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* global functions ***************************************************** ******************************************************************************/ void about_init (void) { - if (snprintf(share_path, FILENAME_MAX, "%s/%s/", - INSTALL_SHARE_DIR, - SHARE_DIR) >= FILENAME_MAX) { - goto err_path; - } + if (snprintf(share_path, FILENAME_MAX, "%s/estadistica/", + INSTALL_SHARE_DIR) >= FILENAME_MAX) { + goto err; + } return; - - -err_path: +err: printf("Path is too large and has been truncated\n"); exit(EXIT_FAILURE); } -void snprint_share_file (char *dest, int destsize, int share_file) +void snprint_share_file (ptrdiff_t size, char buff[restrict size], + int file) { - char file_name [FILENAME_MAX]; + char fname [FILENAME_MAX]; - switch (share_file) { + switch (file) { case SHARE_COPYRIGHT: - if (snprintf(file_name, FILENAME_MAX, "%s/%s", + if (snprintf(fname, FILENAME_MAX, "%s/%s", share_path, "COPYRIGHT.txt") >= FILENAME_MAX) { - goto err_path; + goto err; } break; case SHARE_DISCLAIMER: - if (snprintf(file_name, FILENAME_MAX, "%s/%s", + if (snprintf(fname, FILENAME_MAX, "%s/%s", share_path, "DISCLAIMER.txt") >= FILENAME_MAX) { - goto err_path; + goto err; } break; case SHARE_HELP: - if (snprintf(file_name, FILENAME_MAX, "%s/%s", + if (snprintf(fname, FILENAME_MAX, "%s/%s", share_path, "HELP.txt") >= FILENAME_MAX) { - goto err_path; + goto err; } break; case SHARE_LICENSE: - if (snprintf(file_name, FILENAME_MAX, "%s/%s", + if (snprintf(fname, FILENAME_MAX, "%s/%s", share_path, "LICENSE.txt") >= FILENAME_MAX) { - goto err_path; + goto err; } break; case SHARE_USAGE: - if (snprintf(file_name, FILENAME_MAX, "%s/%s", + if (snprintf(fname, FILENAME_MAX, "%s/%s", share_path, "USAGE.txt") >= FILENAME_MAX) { - goto err_path; + goto err; } break; } - alx_snprint_file(dest, destsize, file_name); + if (alx_snprint_file(size, buff, fname) < 0) + printf("%s: %s\n", errno_str[errno][0], errno_str[errno][1]); return; - -err_path: +err: printf("Path is too large and has been truncated\n"); printf("File could not be shown!\n"); } -void print_share_file (int share_file) +void print_share_file (int file) { char str [BUFF_SIZE_TEXT]; - snprint_share_file(str, BUFF_SIZE_TEXT, share_file); + snprint_share_file(BUFF_SIZE_TEXT, str, file); printf(BEGINNING); printf("%s", str); @@ -117,10 +129,16 @@ void print_share_file (int share_file) void print_version (void) { - printf("" PROG_NAME " " PROG_VERSION "\n\n"); + + printf(""PROG_NAME" "PROG_VERSION"\n\n"); } /****************************************************************************** + ******* static functions (definitions) *************************************** + ******************************************************************************/ + + +/****************************************************************************** ******* end of file ********************************************************** ******************************************************************************/ diff --git a/modules/ctrl/src/start.c b/src/ctrl/start.c index 8c33c93..5562503 100644 --- a/modules/ctrl/src/start.c +++ b/src/ctrl/start.c @@ -7,23 +7,16 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - /* errno */ - #include <errno.h> - #include <stddef.h> - /* printf() */ - #include <stdio.h> -/* Project -------------------------------------------------------------------*/ - /* img_iface_load() */ - #include "img_iface.h" - /* proc_iface_series() */ - #include "proc_iface.h" - /* saved_name*/ - #include "save.h" - /* user_iface() */ - #include "user_iface.h" -/* Module --------------------------------------------------------------------*/ - #include "start.h" +#include "vision-artificial/ctrl/start.h" + +#include <errno.h> +#include <stddef.h> +#include <stdio.h> + +#include "vision-artificial/image/iface.h" +#include "vision-artificial/proc/iface.h" +#include "vision-artificial/save/save.h" +#include "vision-artificial/user/iface.h" /****************************************************************************** @@ -67,13 +60,12 @@ void start_switch (void) ******************************************************************************/ static void start_foo (void) { - - /* empty */ } static void start_single (void) { + img_iface_init(); errno = 0; img_iface_load(NULL, saved_name); diff --git a/src/image/alx.cpp b/src/image/alx.cpp new file mode 100644 index 0000000..a0a6ae2 --- /dev/null +++ b/src/image/alx.cpp @@ -0,0 +1,430 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: (GPL-2.0-only OR LGPL-3.0-only) * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "vision-artificial/image/alx.hpp" + +#include <cstdbool> +#include <cstddef> +#include <cstdlib> +#include <cstdio> + +#include <opencv2/opencv.hpp> + +#include "libalx/base/math/arithmetic_mean.hpp" +#include "libalx/base/math/median.hpp" + +#include "vision-artificial/image/iface.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ +enum Cell { + NOT_LOCAL_MAX, + MAYBE_LOCAL_MAX, + LOCAL_MAX +}; + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ +static void img_alx_local_max (class cv::Mat *imgptr); +static void img_alx_skeleton (class cv::Mat *imgptr); +static void img_alx_lines_horizontal (class cv::Mat *imgptr); +static void img_alx_lines_vertical (class cv::Mat *imgptr); +static void img_alx_mean_horizontal (class cv::Mat *imgptr); +static void img_alx_mean_vertical (class cv::Mat *imgptr); +static void img_alx_median_horizontal (class cv::Mat *imgptr); +static void img_alx_median_vertical (class cv::Mat *imgptr); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void img_alx_act (class cv::Mat *imgptr, int action, const void *data) +{ + + switch (action) { + case IMG_ALX_ACT_LOCAL_MAX: + img_alx_local_max(imgptr); + break; + case IMG_ALX_ACT_SKELETON: + img_alx_skeleton(imgptr); + break; + + case IMG_ALX_ACT_LINES_HORIZONTAL: + img_alx_lines_horizontal(imgptr); + break; + case IMG_ALX_ACT_LINES_VERTICAL: + img_alx_lines_vertical(imgptr); + break; + + case IMG_ALX_ACT_MEAN_HORIZONTAL: + img_alx_mean_horizontal(imgptr); + break; + case IMG_ALX_ACT_MEAN_VERTICAL: + img_alx_mean_vertical(imgptr); + break; + case IMG_ALX_ACT_MEDIAN_HORIZONTAL: + img_alx_median_horizontal(imgptr); + break; + case IMG_ALX_ACT_MEDIAN_VERTICAL: + img_alx_median_vertical(imgptr); + break; + } +} + + +/****************************************************************************** + ******* static functions (definitions) *************************************** + ******************************************************************************/ +static void img_alx_local_max (class cv::Mat *imgptr) +{ + const ptrdiff_t rows = imgptr->rows; + const ptrdiff_t cols = imgptr->cols; + const ptrdiff_t step = imgptr->step; + /* Minimum distance between local maxima */ + const int dist = 4; + /* Minimum value of local maxima */ + const uint8_t val_min = 16; + class cv::Mat imgtmp; + int arr_tmp[rows][cols]; + bool wh; + /* pointer to a pixel (in imgptr) */ + const uint8_t *img_pix; + /* pointer to a pixel near img_pix (in imgptr) */ + const uint8_t *near_pix; + /* pointer to a pixel (same position as img_pix, but in imgtmp) */ + uint8_t *tmp_pix; + + /* Tmp image copy */ + imgptr->copyTo(imgtmp); + + memset(arr_tmp, 0, sizeof(arr_tmp)); + + for (ptrdiff_t i = 0; i < rows; i++) { + for (ptrdiff_t j = 0; j < cols; j++) { + img_pix = imgptr->data + i*step + j; + if (*img_pix < val_min) + continue; + + for (ptrdiff_t k = (i + dist + 1); k >= (i - dist - 1); k--) { + for (ptrdiff_t l = (j + dist + 1); l >= (j - dist - 1); l--) { + if ((k > 0) && (k < rows)) { + if ((l > 0) && (l < cols)) { + near_pix = imgptr->data + k*step + l; + if (*near_pix > *img_pix) + goto not_maxima; + if (*near_pix == *img_pix) + arr_tmp[i][j] = MAYBE_LOCAL_MAX; + } + } + } + } + if (!arr_tmp[i][j]) + arr_tmp[i][j] = LOCAL_MAX; + continue; +not_maxima: + ; + } + } + + do { + wh = false; + for (ptrdiff_t i = 0; i < rows; i++) { + for (ptrdiff_t j = 0; j < cols; j++) { + img_pix = imgptr->data + i*step + j; + if (arr_tmp[i][j] != MAYBE_LOCAL_MAX) + continue; + for (ptrdiff_t k = (i+dist+1); k >= (i-dist-1); k--) { + for (ptrdiff_t l = (j+dist+1); l >= (j-dist-1); l--) { + if ((k > 0) && (k < rows)) { + if ((l > 0) && (l < cols)) { + near_pix = imgptr->data + k*step + l; + if (*near_pix == *img_pix) { + if (!arr_tmp[k][l]) + goto not_maxima_2; + } + } + } + } + } + continue; +not_maxima_2: + wh = true; + arr_tmp[i][j] = 0; + } + } + } while (wh); + + for (ptrdiff_t i = 0; i < rows; i++) { + for (ptrdiff_t j = 0; j < cols; j++) { + if (!arr_tmp[i][j]) { + tmp_pix = imgtmp.data + i * step + j; + *tmp_pix = 0; + } + } + } + + /* Cleanup */ + imgtmp.copyTo(*imgptr); + imgtmp.release(); +} + +static void img_alx_skeleton (class cv::Mat *imgptr) +{ + const ptrdiff_t rows = imgptr->rows; + const ptrdiff_t cols = imgptr->cols; + const ptrdiff_t step = imgptr->step; + /* (Half of the) width of the skeleton */ + const ptrdiff_t width = 5; + ptrdiff_t dist_x; + ptrdiff_t dist_y; + bool skeleton; + int_fast16_t cnt_lo [width]; + int_fast16_t cnt_hi_or_eq [width]; + class cv::Mat imgtmp; + /* pointer to a pixel (in imgptr) */ + const uint8_t *img_pix; + /* pointer to a pixel near img_pix (in imgptr) */ + const uint8_t *near_pix; + /* pointer to a pixel (same position as img_pix, but in imgtmp) */ + uint8_t *tmp_pix; + + /* Tmp image copy */ + imgptr->copyTo(imgtmp); + + for (ptrdiff_t i = 0; i < rows; i++) { + for (ptrdiff_t j = 0; j < cols; j++) { + img_pix = imgptr->data + i * step + j; + tmp_pix = imgtmp.data + i * step + j; + + if (!(*img_pix)) { + *tmp_pix = 0; + continue; + } + + for (ptrdiff_t r = 0; r < width; r++) { + cnt_lo[r] = 0; + cnt_hi_or_eq[r] = 0; + } + + for (ptrdiff_t k = (i + width); k >= (i - width); k--) { + for (ptrdiff_t l = (j + width); l >= (j - width); l--) { + near_pix = imgptr->data + k * step + l; + + dist_x = abs(k - i); + dist_y = abs(l - j); + + if ((k >= 0) && (k < rows)) { + if ((l >= 0) && (l < cols)) { + if (dist_x || dist_y) { + if (*near_pix < *img_pix) + cnt_lo[std::max(dist_x, dist_y)]++; + else + cnt_hi_or_eq[std::max(dist_x, dist_y)]++; + } + } + } + + } + } + + skeleton = false; + for (ptrdiff_t r = 0; r < width; r++) { + if (cnt_lo[r] > (cnt_hi_or_eq[r] + (1.6) * (r + 1))) + skeleton = true; + } + + if (skeleton) + *tmp_pix = *img_pix; + else + *tmp_pix = 0; + } + } + + /* Cleanup */ + imgtmp.copyTo(*imgptr); + imgtmp.release(); +} + +static void img_alx_lines_horizontal (class cv::Mat *imgptr) +{ + const ptrdiff_t rows = imgptr->rows; + const ptrdiff_t cols = imgptr->cols; + const ptrdiff_t step = imgptr->step; + bool white; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + + for (ptrdiff_t i = 0; i < rows; i++) { + white = false; + + for (ptrdiff_t j = 0; j < cols; j++) { + img_pix = imgptr->data + i * step + j; + if (*img_pix) { + white = true; + break; + } + } + + if (white) { + for (ptrdiff_t j = 0; j < cols; j++) { + img_pix = imgptr->data + i * step + j; + *img_pix = 255; + } + } + } +} + +static void img_alx_lines_vertical (class cv::Mat *imgptr) +{ + const ptrdiff_t rows = imgptr->rows; + const ptrdiff_t cols = imgptr->cols; + const ptrdiff_t step = imgptr->step; + bool white; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + + for (ptrdiff_t i = 0; i < cols; i++) { + white = false; + + for (ptrdiff_t j = 0; j < rows; j++) { + img_pix = imgptr->data + j * step + i; + if (*img_pix) { + white = true; + break; + } + } + + if (white) { + for (ptrdiff_t j = 0; j < rows; j++) { + img_pix = imgptr->data + j * step + i; + *img_pix = 255; + } + } + } +} + +static void img_alx_mean_horizontal (class cv::Mat *imgptr) +{ + const ptrdiff_t rows = imgptr->rows; + const ptrdiff_t cols = imgptr->cols; + const ptrdiff_t step = imgptr->step; + uint8_t row [cols]; + uint8_t mean; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + + for (ptrdiff_t i = 0; i < rows; i++) { + for (ptrdiff_t j = 0; j < cols; j++) { + img_pix = imgptr->data + i * step + j; + row[j] = *img_pix; + } + mean = alx_arithmetic_mean_u8(cols, row); + + for (ptrdiff_t j = 0; j < cols; j++) { + img_pix = imgptr->data + i * step + j; + *img_pix = mean; + } + } +} + +static void img_alx_mean_vertical (class cv::Mat *imgptr) +{ + const ptrdiff_t rows = imgptr->rows; + const ptrdiff_t cols = imgptr->cols; + const ptrdiff_t step = imgptr->step; + uint8_t col [rows]; + uint8_t mean; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + + for (ptrdiff_t i = 0; i < cols; i++) { + for (ptrdiff_t j = 0; j < rows; j++) { + img_pix = imgptr->data + j * step + i; + col[j] = *img_pix; + } + mean = alx_arithmetic_mean_u8(rows, col); + + for (ptrdiff_t j = 0; j < rows; j++) { + img_pix = imgptr->data + j * step + i; + *img_pix = mean; + } + } +} + +static void img_alx_median_horizontal (class cv::Mat *imgptr) +{ + const ptrdiff_t rows = imgptr->rows; + const ptrdiff_t cols = imgptr->cols; + const ptrdiff_t step = imgptr->step; + uint8_t row [cols]; + uint8_t median; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + + for (ptrdiff_t i = 0; i < rows; i++) { + for (ptrdiff_t j = 0; j < cols; j++) { + img_pix = imgptr->data + i * step + j; + row[j] = *img_pix; + } + median = alx_median_u8(cols, row); + + for (ptrdiff_t j = 0; j < cols; j++) { + img_pix = imgptr->data + i * step + j; + *img_pix = median; + } + } +} + +static void img_alx_median_vertical (class cv::Mat *imgptr) +{ + const ptrdiff_t rows = imgptr->rows; + const ptrdiff_t cols = imgptr->cols; + const ptrdiff_t step = imgptr->step; + uint8_t col [rows]; + uint8_t median; + /* pointer to a pixel (in imgptr) */ + uint8_t *img_pix; + + for (ptrdiff_t i = 0; i < cols; i++) { + for (ptrdiff_t j = 0; j < rows; j++) { + img_pix = imgptr->data + j * step + i; + col[j] = *img_pix; + } + median = alx_median_u8(rows, col); + + for (ptrdiff_t j = 0; j < rows; j++) { + img_pix = imgptr->data + j * step + i; + *img_pix = median; + } + } +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/src/img_calib3d.cpp b/src/image/calib3d.cpp index cce54c3..43fa360 100644 --- a/modules/image/src/img_calib3d.cpp +++ b/src/image/calib3d.cpp @@ -7,37 +7,37 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ -/* Standard C++ --------------------------------------------------------------*/ - #include <vector> -/* Standard C ----------------------------------------------------------------*/ - #include <cstdio> -/* Packages ------------------------------------------------------------------*/ - #include <opencv2/opencv.hpp> - #include <opencv2/calib3d/calib3d.hpp> -/* Module -------------------------------------------------------------------*/ - #include "img_iface.hpp" +#include "vision-artificial/image/calib3d.hpp" - #include "img_calib3d.hpp" +#include <cstddef> +#include <cstdio> + +#include <vector> + +#include <opencv2/opencv.hpp> +#include <opencv2/calib3d/calib3d.hpp> + +#include "vision-artificial/image/iface.hpp" /****************************************************************************** ******* macros *************************************************************** ******************************************************************************/ - # define CORNERS_HOR (16) - # define CORNERS_VER (13) +#define CORNERS_HOR (16) +#define CORNERS_VER (13) /****************************************************************************** ******* static functions ***************************************************** ******************************************************************************/ -static void img_calib3d_calibrate (class cv::Mat *imgptr, const void *data); -static void img_calib3d_undistort (class cv::Mat *imgptr, const void *data); +static void img_calib3d_calibrate(class cv::Mat *imgptr, const void *data); +static void img_calib3d_undistort(class cv::Mat *imgptr, const void *data); /****************************************************************************** ******* main ***************************************************************** ******************************************************************************/ -void img_calib3d_act (class cv::Mat *imgptr, int action, const void *data) +void img_calib3d_act(class cv::Mat *imgptr, int action, const void *data) { switch (action) { case IMG_CALIB3D_ACT_CALIBRATE: @@ -54,7 +54,7 @@ void img_calib3d_act (class cv::Mat *imgptr, int action, const void *data) /****************************************************************************** ******* static functions ***************************************************** ******************************************************************************/ -static void img_calib3d_calibrate (class cv::Mat *imgptr, const void *data) +static void img_calib3d_calibrate(class cv::Mat *imgptr, const void *data) { const struct Img_Iface_Data_Calibrate *data_cast; class cv::Mat *intrinsic_mat; @@ -68,8 +68,6 @@ static void img_calib3d_calibrate (class cv::Mat *imgptr, const void *data) class std::vector <class cv::Point_ <float>> corners; class std::vector <class cv::Point3_ <float>> obj; bool found; - int i; - int j; data_cast = (const struct Img_Iface_Data_Calibrate *)data; intrinsic_mat = data_cast->intrinsic_mat; @@ -82,10 +80,9 @@ static void img_calib3d_calibrate (class cv::Mat *imgptr, const void *data) (*intrinsic_mat).ptr<float>(0)[0] = 1; (*intrinsic_mat).ptr<float>(1)[1] = 1; - for (i = 0; i < CORNERS_HOR; i++) { - for (j = 0; j < CORNERS_VER; j++) { + for (ptrdiff_t i = 0; i < CORNERS_HOR; i++) { + for (ptrdiff_t j = 0; j < CORNERS_VER; j++) obj.push_back(cv::Point3f(i, j * 10.0, 0.0)); - } } found = cv::findChessboardCorners(*imgptr, pattern_size, corners, @@ -105,7 +102,7 @@ static void img_calib3d_calibrate (class cv::Mat *imgptr, const void *data) *intrinsic_mat, *dist_coefs, *rvecs, *tvecs); } -static void img_calib3d_undistort (class cv::Mat *imgptr, const void *data) +static void img_calib3d_undistort(class cv::Mat *imgptr, const void *data) { class cv::Mat imgtmp; const struct Img_Iface_Data_Undistort *data_cast; diff --git a/modules/image/src/img_cv.cpp b/src/image/cv.cpp index eacaf98..b5d4877 100644 --- a/modules/image/src/img_cv.cpp +++ b/src/image/cv.cpp @@ -7,22 +7,43 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ -/* Standard C++ --------------------------------------------------------------*/ - #include <vector> -/* Standard C ----------------------------------------------------------------*/ - #include <cmath> - #include <cstdbool> - #include <cstdio> -/* Packages ------------------------------------------------------------------*/ - #include <opencv2/opencv.hpp> -/* Module --------------------------------------------------------------------*/ - #include "img_iface.hpp" +#include "vision-artificial/image/cv.hpp" - #include "img_cv.hpp" +#include <cmath> +#include <cstdbool> +#include <cstddef> +#include <cstdint> +#include <cstdio> + +#include <vector> + +#include <opencv2/opencv.hpp> + +#include "vision-artificial/image/iface.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ /****************************************************************************** - ******* static functions ***************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** ******************************************************************************/ /* Core: The core functionality */ /* Pixel */ @@ -49,7 +70,7 @@ static void img_cv_rotate (class cv::Mat *imgptr, const void *data); /* Miscellaneous image transformations */ static void img_cv_adaptive_thr (class cv::Mat *imgptr, const void *data); static void img_cv_cvt_color (class cv::Mat *imgptr, const void *data); -static void img_cv_distance_transform (class cv::Mat *imgptr); +static void img_cv_distance_transform(class cv::Mat *imgptr); static void img_cv_threshold (class cv::Mat *imgptr, const void *data); /* Histograms */ static void img_cv_histogram (class cv::Mat *imgptr, const void *data); @@ -65,7 +86,7 @@ static void img_cv_hough_circles (class cv::Mat *imgptr, const void *data); /****************************************************************************** - ******* main ***************************************************************** + ******* global functions ***************************************************** ******************************************************************************/ void img_cv_act (class cv::Mat *imgptr, int action, const void *data) { @@ -164,7 +185,7 @@ void img_cv_act (class cv::Mat *imgptr, int action, const void *data) /****************************************************************************** - ******* static functions ***************************************************** + ******* static functions (definitions) *************************************** ******************************************************************************/ /* Core: The core functionality */ /* ----- Pixel */ @@ -172,8 +193,8 @@ static void img_cv_pixel_get (const class cv::Mat *imgptr, const void *data) { const struct Img_Iface_Data_Pixel_Get *data_cast; unsigned char *val; - int x; - int y; + ptrdiff_t x; + ptrdiff_t y; data_cast = (const struct Img_Iface_Data_Pixel_Get *)data; val = data_cast->val; @@ -187,13 +208,13 @@ static void img_cv_pixel_set (class cv::Mat *imgptr, const void *data) { const struct Img_Iface_Data_Pixel_Set *data_cast; unsigned char val; - int x; - int y; + ptrdiff_t x; + ptrdiff_t y; data_cast = (const struct Img_Iface_Data_Pixel_Set *)data; - val = data_cast->val; - x = data_cast->x; - y = data_cast->y; + val = data_cast->val; + x = data_cast->x; + y = data_cast->y; imgptr->at<unsigned char>(y, x) = val; } @@ -201,9 +222,9 @@ static void img_cv_pixel_set (class cv::Mat *imgptr, const void *data) /* ----- ROI */ static void img_cv_set_ROI (class cv::Mat *imgptr, const void *data) { - class cv::Mat imgtmp; const struct Img_Iface_Data_SetROI *data_cast; const class cv::Rect_ <int> *rect; + class cv::Mat imgtmp; data_cast = (const struct Img_Iface_Data_SetROI *)data; rect = &(data_cast->rect); @@ -244,12 +265,12 @@ static void img_cv_or_2ref (class cv::Mat *imgptr, const void *data) static void img_cv_component (class cv::Mat *imgptr, const void *data) { - class cv::Mat cmp_img[3]; const struct Img_Iface_Data_Component *data_cast; - int cmp; + class cv::Mat cmp_img[3]; + int cmp; data_cast = (const struct Img_Iface_Data_Component *)data; - cmp = data_cast->cmp; + cmp = data_cast->cmp; cv::split(*imgptr, cmp_img); @@ -269,7 +290,7 @@ static void img_cv_dilate (class cv::Mat *imgptr, const void *data) int i; data_cast = (const struct Img_Iface_Data_Dilate_Erode *)data; - i = data_cast->i; + i = data_cast->i; cv::dilate(*imgptr, *imgptr, cv::Mat(), cv::Point(-1,-1), i, cv::BORDER_CONSTANT, cv::Scalar(0)); @@ -281,7 +302,7 @@ static void img_cv_erode (class cv::Mat *imgptr, const void *data) int i; data_cast = (const struct Img_Iface_Data_Dilate_Erode *)data; - i = data_cast->i; + i = data_cast->i; cv::erode(*imgptr, *imgptr, cv::Mat(), cv::Point(-1,-1), i, cv::BORDER_CONSTANT, cv::Scalar(0)); @@ -294,11 +315,10 @@ static void img_cv_smooth (class cv::Mat *imgptr, const void *data) int ksize; data_cast = (const struct Img_Iface_Data_Smooth *)data; - method = data_cast->method; - ksize = data_cast->ksize; - if (!(ksize % 2)) { + method = data_cast->method; + ksize = data_cast->ksize; + if (!(ksize % 2)) ksize++; - } switch (method) { case IMGI_SMOOTH_MEAN: @@ -323,12 +343,11 @@ static void img_cv_sobel (class cv::Mat *imgptr, const void *data) int ksize; data_cast = (const struct Img_Iface_Data_Sobel *)data; - dx = data_cast->dx; - dy = data_cast->dy; - ksize = data_cast->ksize; - if (!(ksize % 2)) { + dx = data_cast->dx; + dy = data_cast->dy; + ksize = data_cast->ksize; + if (!(ksize % 2)) ksize++; - } cv::Sobel(*imgptr, *imgptr, -1, dx, dy, ksize, 1, 0, cv::BORDER_DEFAULT); @@ -336,17 +355,21 @@ static void img_cv_sobel (class cv::Mat *imgptr, const void *data) static void img_cv_border (class cv::Mat *imgptr, const void *data) { - class cv::Mat imgtmp; const struct Img_Iface_Data_Border *data_cast; - int sz; + class cv::Mat imgtmp; + ptrdiff_t size; + ptrdiff_t rows; + ptrdiff_t cols; /* Data */ data_cast = (struct Img_Iface_Data_Border *)data; - sz = data_cast->size; + size = data_cast->size; + rows = imgptr->rows; + cols = imgptr->cols; - imgtmp = cv::Mat(cv::Size(imgptr->cols + sz, imgptr->rows + sz), CV_8U); + imgtmp = cv::Mat(cv::Size(cols + size, rows + size), CV_8U); - cv::copyMakeBorder(*imgptr, imgtmp, sz, sz, sz, sz, + cv::copyMakeBorder(*imgptr, imgtmp, size, size, size, size, cv::BORDER_CONSTANT, cv::Scalar(0)); imgtmp.copyTo(*imgptr); @@ -361,7 +384,7 @@ static void img_cv_mirror (class cv::Mat *imgptr, const void *data) int axis; data_cast = (const struct Img_Iface_Data_Mirror *)data; - axis = data_cast->axis; + axis = data_cast->axis; cv::flip(*imgptr, *imgptr, axis); } @@ -372,7 +395,7 @@ static void img_cv_rotate_orto (class cv::Mat *imgptr, const void *data) int n; data_cast = (struct Img_Iface_Data_Rotate_Orto *)data; - n = data_cast->n; + n = data_cast->n; switch (n) { case 1: @@ -396,20 +419,20 @@ static void img_cv_rotate_orto (class cv::Mat *imgptr, const void *data) static void img_cv_rotate (class cv::Mat *imgptr, const void *data) { - class cv::Mat map_matrix; const struct Img_Iface_Data_Rotate *data_cast; const class cv::Point_ <float> *center; - double angle; + class cv::Mat map_matrix; + double angle; + class cv::Size_ <int> size; data_cast = (const struct Img_Iface_Data_Rotate *)data; center = &(data_cast->center); angle = data_cast->angle; + size = imgptr->size(); map_matrix = cv::getRotationMatrix2D(*center, angle, 1); - - cv::warpAffine(*imgptr, *imgptr, map_matrix, imgptr->size(), - cv::INTER_LINEAR, cv::BORDER_CONSTANT, - cv::Scalar(0, 0, 0)); + cv::warpAffine(*imgptr, *imgptr, map_matrix, size, cv::INTER_LINEAR, + cv::BORDER_CONSTANT, cv::Scalar(0, 0, 0)); map_matrix.release(); } @@ -423,14 +446,14 @@ static void img_cv_adaptive_thr (class cv::Mat *imgptr, const void *data) int ksize; data_cast = (const struct Img_Iface_Data_Adaptive_Thr *)data; - method = data_cast->method; - thr_typ = data_cast->thr_typ; - ksize = data_cast->ksize; - if (!(ksize % 2)) { + method = data_cast->method; + thr_typ = data_cast->thr_typ; + ksize = data_cast->ksize; + if (!(ksize % 2)) ksize++; - } - cv::adaptiveThreshold(*imgptr, *imgptr, 255, method, thr_typ, ksize, 0); + cv::adaptiveThreshold(*imgptr, *imgptr, UINT8_MAX, method, thr_typ, + ksize, 0); } static void img_cv_cvt_color (class cv::Mat *imgptr, const void *data) @@ -439,12 +462,12 @@ static void img_cv_cvt_color (class cv::Mat *imgptr, const void *data) int method; data_cast = (const struct Img_Iface_Data_Cvt_Color *)data; - method = data_cast->method; + method = data_cast->method; cv::cvtColor(*imgptr, *imgptr, method, 0); } -static void img_cv_distance_transform (class cv::Mat *imgptr) +static void img_cv_distance_transform(class cv::Mat *imgptr) { class cv::Mat imgtmp; @@ -465,27 +488,27 @@ static void img_cv_threshold (class cv::Mat *imgptr, const void *data) data_cast = (const struct Img_Iface_Data_Threshold *)data; thr_typ = data_cast->thr_typ; thr_val = data_cast->thr_val; - if (thr_val == -1) { + if (thr_val == -1) thr_typ |= cv::THRESH_OTSU; - } - cv::threshold(*imgptr, *imgptr, thr_val, 0xFF, thr_typ); + cv::threshold(*imgptr, *imgptr, thr_val, UINT8_MAX, thr_typ); } /* ----- Histograms */ static void img_cv_histogram (class cv::Mat *imgptr, const void *data) { const struct Img_Iface_Data_Histogram *data_cast; - class cv::Mat *hist; - class cv::Mat *hist_img; const int h_size = 256; const float h_range_arr[] = {0.0, 256.0}; const float *h_range = {h_range_arr}; - int i; + class cv::Mat *hist; + class cv::Mat *hist_img; + ptrdiff_t rows; data_cast = (const struct Img_Iface_Data_Histogram *)data; hist = data_cast->hist_c0; hist_img = data_cast->hist_img; + rows = hist_img->rows; /* Write components into cmp_img[] */ cv::calcHist(imgptr, 1, 0, cv::Mat(), *hist, 1, &h_size, &h_range, @@ -494,16 +517,14 @@ static void img_cv_histogram (class cv::Mat *imgptr, const void *data) /* Init */ hist_img->setTo(cv::Scalar(0)); - /* Normalize the result to [0, hist_img->rows - 1] */ - cv::normalize(*hist, *hist, 0, hist_img->rows - 1, cv::NORM_MINMAX, -1, - cv::Mat()); + /* Normalize the result to [0, rows - 1] */ + cv::normalize(*hist, *hist, 0, rows-1, cv::NORM_MINMAX, -1, cv::Mat()); /* Draw hist into hist_img */ - for(i = 0; i < h_size; i++ ) { - cv::line(*hist_img, cv::Point(i, hist_img->rows - 0), - cv::Point(i, - hist_img->rows - hist->at<float>(i)), - cv::Scalar(255, 0, 0), 1, 8, 0); + for (ptrdiff_t i = 0; i < h_size; i++) { + cv::line(*hist_img, cv::Point(i, rows - 0), + cv::Point(i, rows - hist->at<float>(i)), + cv::Scalar(UINT8_MAX, 0, 0), 1, 8, 0); } /* Show histogram */ @@ -512,22 +533,23 @@ static void img_cv_histogram (class cv::Mat *imgptr, const void *data) static void img_cv_histogram_c3 (class cv::Mat *imgptr, const void *data) { - class cv::Mat cmp_img[3]; const struct Img_Iface_Data_Histogram *data_cast; - class cv::Mat *hist_c0; - class cv::Mat *hist_c1; - class cv::Mat *hist_c2; - class cv::Mat *hist_img; const int h_size = 256; const float h_range_arr[] = {0.0, 256.0}; const float *h_range = {h_range_arr}; - int i; + class cv::Mat cmp_img[3]; + class cv::Mat *hist_c0; + class cv::Mat *hist_c1; + class cv::Mat *hist_c2; + class cv::Mat *hist_img; + ptrdiff_t rows; data_cast = (const struct Img_Iface_Data_Histogram *)data; hist_c0 = data_cast->hist_c0; hist_c1 = data_cast->hist_c1; hist_c2 = data_cast->hist_c2; hist_img = data_cast->hist_img; + rows = hist_img->rows; /* Write components into cmp_img[] */ cv::split(*imgptr, cmp_img); @@ -544,32 +566,26 @@ static void img_cv_histogram_c3 (class cv::Mat *imgptr, const void *data) hist_img->setTo(cv::Scalar(0)); /* Normalize the result to [0, hist_img->rows - 1] */ - cv::normalize(*hist_c0, *hist_c0, 0, hist_img->rows - 1, - cv::NORM_MINMAX, -1, cv::Mat()); - cv::normalize(*hist_c1, *hist_c1, 0, hist_img->rows - 1, - cv::NORM_MINMAX, -1, cv::Mat()); - cv::normalize(*hist_c2, *hist_c2, 0, hist_img->rows - 1, - cv::NORM_MINMAX, -1, cv::Mat()); + cv::normalize(*hist_c0, *hist_c0, 0, rows - 1, cv::NORM_MINMAX, -1, + cv::Mat()); + cv::normalize(*hist_c1, *hist_c1, 0, rows - 1, cv::NORM_MINMAX, -1, + cv::Mat()); + cv::normalize(*hist_c2, *hist_c2, 0, rows - 1, cv::NORM_MINMAX, -1, + cv::Mat()); /* Draw hist into hist_img */ - for(i = 0; i < 256; i++ ) { - cv::line(*hist_img, cv::Point(3 * i, hist_img->rows - 0), - cv::Point(3 * i, - hist_img->rows - hist_c0->at<float>(i)), - cv::Scalar(255, 0, 0), 1, 8, 0); - } - for(i = 0; i < 256; i++ ) { - cv::line(*hist_img, cv::Point(3 * i + 1, hist_img->rows - 0), - cv::Point(3 * i + 1, - hist_img->rows - hist_c1->at<float>(i)), - cv::Scalar(0, 255, 0), 1, 8, 0); - } - for(i = 0; i < 256; i++ ) { - cv::line(*hist_img, cv::Point(3 * i + 2, hist_img->rows - 0), - cv::Point(3 * i + 2, - hist_img->rows - hist_c2->at<float>(i)), - cv::Scalar(0, 0, 255), 1, 8, 0); - } + for (ptrdiff_t i = 0; i < h_size; i++) + cv::line(*hist_img, cv::Point(3 * i, rows - 0), + cv::Point(3 * i, rows - hist_c0->at<float>(i)), + cv::Scalar(UINT8_MAX, 0, 0), 1, 8, 0); + for (ptrdiff_t i = 0; i < h_size; i++) + cv::line(*hist_img, cv::Point(3 * i + 1, rows - 0), + cv::Point(3*i+1, rows - hist_c1->at<float>(i)), + cv::Scalar(0, UINT8_MAX, 0), 1, 8, 0); + for (ptrdiff_t i = 0; i < h_size; i++) + cv::line(*hist_img, cv::Point(3 * i + 2, rows - 0), + cv::Point(3*i+2, rows - hist_c2->at<float>(i)), + cv::Scalar(0, 0, UINT8_MAX), 1, 8, 0); /* Show histogram */ img_iface_show_hist_c3(); @@ -584,25 +600,19 @@ static void img_cv_contours (class cv::Mat *imgptr, const void *data) { const struct Img_Iface_Data_Contours *data_cast; class std::vector<class std::vector<class cv::Point_<int>>> *contours; - class cv::Mat *hierarchy; + class cv::Mat *hierarchy; - /* Data */ data_cast = (const struct Img_Iface_Data_Contours *)data; - - /* Contours */ contours = data_cast->contours; hierarchy = data_cast->hierarchy; - /* Get contours */ - cv::findContours(*imgptr, *contours, *hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE); /* Set image to black */ imgptr->setTo(cv::Scalar(0)); - /* Draw contours in color */ - cv::drawContours(*imgptr, *contours, -1, cv::Scalar(255), 1, 8, + cv::drawContours(*imgptr, *contours, -1, cv::Scalar(UINT8_MAX), 1, 8, *hierarchy, 1, cvPoint(0, 0)); } @@ -610,32 +620,35 @@ static void img_cv_contours_size (const void *data) { const struct Img_Iface_Data_Contours_Size *data_cast; const class std::vector<class std::vector<class cv::Point_<int>>> *contours; - unsigned i; + ptrdiff_t size; data_cast = (const struct Img_Iface_Data_Contours_Size *)data; contours = data_cast->contours; + size = contours->size(); if (data_cast->area) { - for (i = 0; i < contours->size(); i++) { - data_cast->area[i] = cv::contourArea( - (*contours)[i], false); - } + for (ptrdiff_t i = 0; i < size; i++) + data_cast->area[i] = cv::contourArea((*contours)[i], + false); } if (data_cast->perimeter) { - for (i = 0; i < contours->size(); i++) { - data_cast->perimeter[i] = cv::arcLength( - (*contours)[i], true); - } + for (ptrdiff_t i = 0; i < size; i++) + data_cast->perimeter[i] = cv::arcLength((*contours)[i], + true); } } static void img_cv_bounding_rect (class cv::Mat *imgptr, const void *data) { - class cv::Point_ <float> vertices[4]; const struct Img_Iface_Data_Bounding_Rect *data_cast; const class std::vector <class cv::Point_ <int>> *contour; - class cv::Rect_ <int> *rect; - bool show; + class cv::Point_ <float> vertices[4]; + class cv::Rect_ <int> *rect; + bool show; + ptrdiff_t x; + ptrdiff_t y; + ptrdiff_t width; + ptrdiff_t height; data_cast = (const struct Img_Iface_Data_Bounding_Rect *)data; contour = data_cast->contour; @@ -643,72 +656,76 @@ static void img_cv_bounding_rect (class cv::Mat *imgptr, const void *data) show = data_cast->show; *rect = cv::boundingRect(*contour); + x = rect->x; + y = rect->y; + width = rect->width; + height = rect->height; + if (!show) + return; /* Draw rectangle */ - if (show) { - vertices[0].x = rect->x; - vertices[0].y = rect->y; - vertices[1].x = rect->x + rect->width; - vertices[1].y = rect->y; - vertices[2].x = rect->x + rect->width; - vertices[2].y = rect->y + rect->height; - vertices[3].x = rect->x; - vertices[3].y = rect->y + rect->height; - cv::line(*imgptr, cv::Point(vertices[0].x, vertices[0].y), - cv::Point(vertices[1].x, vertices[1].y), - CV_RGB(0, 0, 255), 1, 8, 0); - cv::line(*imgptr, cv::Point(vertices[1].x, vertices[1].y), - cv::Point(vertices[2].x, vertices[2].y), - CV_RGB(0, 0, 255), 1, 8, 0); - cv::line(*imgptr, cv::Point(vertices[2].x, vertices[2].y), - cv::Point(vertices[3].x, vertices[3].y), - CV_RGB(0, 0, 255), 1, 8, 0); - cv::line(*imgptr, cv::Point(vertices[3].x, vertices[3].y), - cv::Point(vertices[0].x, vertices[0].y), - CV_RGB(0, 0, 255), 1, 8, 0); - } + vertices[0].x = x; + vertices[0].y = y; + vertices[1].x = x + width; + vertices[1].y = y; + vertices[2].x = x + width; + vertices[2].y = y + height; + vertices[3].x = x; + vertices[3].y = y + height; + cv::line(*imgptr, cv::Point(vertices[0].x, vertices[0].y), + cv::Point(vertices[1].x, vertices[1].y), + CV_RGB(0, 0, UINT8_MAX), 1, 8, 0); + cv::line(*imgptr, cv::Point(vertices[1].x, vertices[1].y), + cv::Point(vertices[2].x, vertices[2].y), + CV_RGB(0, 0, UINT8_MAX), 1, 8, 0); + cv::line(*imgptr, cv::Point(vertices[2].x, vertices[2].y), + cv::Point(vertices[3].x, vertices[3].y), + CV_RGB(0, 0, UINT8_MAX), 1, 8, 0); + cv::line(*imgptr, cv::Point(vertices[3].x, vertices[3].y), + cv::Point(vertices[0].x, vertices[0].y), + CV_RGB(0, 0, UINT8_MAX), 1, 8, 0); } static void img_cv_fit_ellipse (class cv::Mat *imgptr, const void *data) { - class cv::Point_ <float> vertices[4]; const struct Img_Iface_Data_MinARect *data_cast; const class std::vector <class cv::Point_ <int>> *contour; - class cv::RotatedRect *rect; - bool show; + class cv::Point_ <float> vertices[4]; + class cv::RotatedRect *rect; + bool show; data_cast = (const struct Img_Iface_Data_MinARect *)data; - contour = data_cast->contour; - rect = data_cast->rect; - show = data_cast->show; + contour = data_cast->contour; + rect = data_cast->rect; + show = data_cast->show; - *rect = cv::fitEllipse(*contour); + *rect = cv::fitEllipse(*contour); + if (!show) + return; /* Draw rectangle */ - if (show) { - rect->points(vertices); - cv::line(*imgptr, cv::Point(vertices[0].x, vertices[0].y), - cv::Point(vertices[1].x, vertices[1].y), - CV_RGB(0, 0, 255), 1, 8, 0); - cv::line(*imgptr, cv::Point(vertices[1].x, vertices[1].y), - cv::Point(vertices[2].x, vertices[2].y), - CV_RGB(0, 0, 255), 1, 8, 0); - cv::line(*imgptr, cv::Point(vertices[2].x, vertices[2].y), - cv::Point(vertices[3].x, vertices[3].y), - CV_RGB(0, 0, 255), 1, 8, 0); - cv::line(*imgptr, cv::Point(vertices[3].x, vertices[3].y), - cv::Point(vertices[0].x, vertices[0].y), - CV_RGB(0, 0, 255), 1, 8, 0); - } + rect->points(vertices); + cv::line(*imgptr, cv::Point(vertices[0].x, vertices[0].y), + cv::Point(vertices[1].x, vertices[1].y), + CV_RGB(0, 0, UINT8_MAX), 1, 8, 0); + cv::line(*imgptr, cv::Point(vertices[1].x, vertices[1].y), + cv::Point(vertices[2].x, vertices[2].y), + CV_RGB(0, 0, UINT8_MAX), 1, 8, 0); + cv::line(*imgptr, cv::Point(vertices[2].x, vertices[2].y), + cv::Point(vertices[3].x, vertices[3].y), + CV_RGB(0, 0, UINT8_MAX), 1, 8, 0); + cv::line(*imgptr, cv::Point(vertices[3].x, vertices[3].y), + cv::Point(vertices[0].x, vertices[0].y), + CV_RGB(0, 0, UINT8_MAX), 1, 8, 0); } static void img_cv_min_area_rect (class cv::Mat *imgptr, const void *data) { - class cv::Point_ <float> vertices[4]; const struct Img_Iface_Data_MinARect *data_cast; const class std::vector <class cv::Point_ <int>> *contour; - class cv::RotatedRect *rect; - bool show; + class cv::Point_ <float> vertices[4]; + class cv::RotatedRect *rect; + bool show; data_cast = (const struct Img_Iface_Data_MinARect *)data; contour = data_cast->contour; @@ -717,37 +734,37 @@ static void img_cv_min_area_rect (class cv::Mat *imgptr, const void *data) *rect = cv::minAreaRect(*contour); + if (!show) + return; /* Draw rectangle */ - if (show) { - rect->points(vertices); - cv::line(*imgptr, cv::Point(vertices[0].x, vertices[0].y), - cv::Point(vertices[1].x, vertices[1].y), - CV_RGB(0, 0, 255), 1, 8, 0); - cv::line(*imgptr, cv::Point(vertices[1].x, vertices[1].y), - cv::Point(vertices[2].x, vertices[2].y), - CV_RGB(0, 0, 255), 1, 8, 0); - cv::line(*imgptr, cv::Point(vertices[2].x, vertices[2].y), - cv::Point(vertices[3].x, vertices[3].y), - CV_RGB(0, 0, 255), 1, 8, 0); - cv::line(*imgptr, cv::Point(vertices[3].x, vertices[3].y), - cv::Point(vertices[0].x, vertices[0].y), - CV_RGB(0, 0, 255), 1, 8, 0); - } + rect->points(vertices); + cv::line(*imgptr, cv::Point(vertices[0].x, vertices[0].y), + cv::Point(vertices[1].x, vertices[1].y), + CV_RGB(0, 0, UINT8_MAX), 1, 8, 0); + cv::line(*imgptr, cv::Point(vertices[1].x, vertices[1].y), + cv::Point(vertices[2].x, vertices[2].y), + CV_RGB(0, 0, UINT8_MAX), 1, 8, 0); + cv::line(*imgptr, cv::Point(vertices[2].x, vertices[2].y), + cv::Point(vertices[3].x, vertices[3].y), + CV_RGB(0, 0, UINT8_MAX), 1, 8, 0); + cv::line(*imgptr, cv::Point(vertices[3].x, vertices[3].y), + cv::Point(vertices[0].x, vertices[0].y), + CV_RGB(0, 0, UINT8_MAX), 1, 8, 0); } /* ----- Feature detection */ static void img_cv_hough_circles (class cv::Mat *imgptr, const void *data) { - class cv::Point_ <int> center; - int radius; - unsigned i; const struct Img_Iface_Data_Hough_Circles *data_cast; class std::vector <class cv::Vec <float, 3>> *circles; - double dist_min; - double param_1; - double param_2; - int radius_min; - int radius_max; + class cv::Point_ <int> center; + int radius; + double dist_min; + double param_1; + double param_2; + int radius_min; + int radius_max; + ptrdiff_t size; data_cast = (const struct Img_Iface_Data_Hough_Circles *)data; circles = data_cast->circles; @@ -765,18 +782,17 @@ static void img_cv_hough_circles (class cv::Mat *imgptr, const void *data) imgptr->setTo(cv::Scalar(0)); /* Draw circles */ - for (i = 0; i < circles->size(); i++) { + size = circles->size(); + for (ptrdiff_t i = 0; i < size; i++) { center.x = cvRound((*circles)[i][0]); center.y = cvRound((*circles)[i][1]); radius = cvRound((*circles)[i][2]); /* Draw the circle center */ -/* cv::circle(*imgptr, center, 3, - cv::Scalar(0, 255, 0), -1, 8, 0);*/ +/* cv::circle(*imgptr, center, 3, cv::Scalar(0, 255, 0), -1, 8, 0);*/ /* Draw the circle outline */ - cv::circle(*imgptr, center, radius, - cv::Scalar(250), 1, 8, 0); + cv::circle(*imgptr, center, radius, cv::Scalar(250), 1, 8, 0); } } diff --git a/src/image/iface.cpp b/src/image/iface.cpp new file mode 100644 index 0000000..8759bf4 --- /dev/null +++ b/src/image/iface.cpp @@ -0,0 +1,1489 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "vision-artificial/image/iface.hpp" + +#include <cerrno> +#include <cmath> +#include <cstddef> +#include <cstdio> + +#include <vector> + +#include <opencv2/opencv.hpp> + +#include "vision-artificial/image/alx.hpp" +#include "vision-artificial/image/calib3d.hpp" +#include "vision-artificial/image/cv.hpp" +#include "vision-artificial/image/ocr.hpp" +#include "vision-artificial/image/orb.hpp" +#include "vision-artificial/image/zbar.hpp" +#include "vision-artificial/save/save.hpp" +#include "vision-artificial/user/iface.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +#define IMG_MEM_SIZE (20) + +#define WIN_NAME_IMG "Image" +#define WIN_NAME_HIST "Hist" +#define WIN_TIMEOUT (500) + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ + char img_ocr_text [OCR_TEXT_MAX]; + struct Img_Iface_ZB_Codes zb_codes; +/* Static --------------------------------------------------------------------*/ +static class cv::Mat image_copy_old; +static class cv::Mat image_copy_tmp; +static class cv::Mat image_mem[IMG_MEM_SIZE]; +static class cv::Mat image_ref; +static class cv::Mat histogram_c0; +static class cv::Mat histogram_c1; +static class cv::Mat histogram_c2; +static class cv::Mat hist_img_c1; +static class cv::Mat hist_img_c3; +static class std::vector <class std::vector <cv::Point_ <int>>> contours; +static double area[CONTOURS_MAX]; +static double perimeter[CONTOURS_MAX]; +static class cv::Mat hierarchy; +static class cv::Rect_ <int> rectangle; +static class cv::RotatedRect rectangle_rot; +static class std::vector <class cv::Vec <float, 3>> circles; +static class cv::Mat intrinsic_mat; +static class cv::Mat dist_coefs; +static class std::vector <class cv::Mat> rvecs; +static class std::vector <class cv::Mat> tvecs; + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ + /* alx */ +static void img_iface_local_max (void); +static void img_iface_skeleton (void); +static void img_iface_lines_horizontal (void); +static void img_iface_lines_vertical (void); +static void img_iface_mean_horizontal (void); +static void img_iface_mean_vertical (void); +static void img_iface_median_horizontal (void); +static void img_iface_median_vertical (void); + /* cv */ + /* Core: The core functionality */ + /* Pixel */ +static void img_iface_pixel_get (const void *data); +static void img_iface_pixel_set (const void *data); + /* ROI */ +static void img_iface_set_ROI (const void *data); +static void img_iface_set_ROI_2rect (const void *data); + /* Operations on Arrays */ +static void img_iface_and_2ref (void); +static void img_iface_not (void); +static void img_iface_or_2ref (void); +static void img_iface_component (const void *data); + /* Imgproc: Image processing */ + /* Image filtering */ +static void img_iface_dilate (const void *data); +static void img_iface_erode (const void *data); +static void img_iface_dilate_erode (const void *data); +static void img_iface_erode_dilate (const void *data); +static void img_iface_smooth (const void *data); +static void img_iface_sobel (const void *data); +static void img_iface_border (const void *data); + /* Geometric image transformations */ +static void img_iface_mirror (const void *data); +static void img_iface_rotate_orto (const void *data); +static void img_iface_rotate (const void *data); +static void img_iface_rotate_2rect (const void *data); + /* Miscellaneous image transformations */ +static void img_iface_adaptive_thr (const void *data); +static void img_iface_cvt_color (const void *data); +static void img_iface_distance_transform (void); +static void img_iface_threshold (const void *data); + /* Histograms */ +static void img_iface_histogram (const void *data); +static void img_iface_histogram_c3 (const void *data); + /* Structural analysis and shape descriptors */ +static void img_iface_contours (const void *data); +static void img_iface_contours_size (const void *data); +static void img_iface_bounding_rect (const void *data); +static void img_iface_fit_ellipse (const void *data); +static void img_iface_min_area_rect (const void *data); + /* Feature detection */ +static void img_iface_hough_circles (const void *data); + /* orb */ +static void img_iface_align (void); + /* calib3d */ +static void img_iface_calibrate (const void *data); +static void img_iface_undistort (const void *data); + /* zbar */ +static void img_iface_decode (const void *data); + /* ocr */ +static void img_iface_read (const void *data); + /* iface */ +static void img_iface_apply (void); +static void img_iface_discard (void); +static void img_iface_save_mem (const void *data); +static void img_iface_load_mem (const void *data); +static void img_iface_save_ref (void); + /* save/save */ +static void img_iface_save_file (void); +static void img_iface_save_update (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void img_iface_init (void) +{ + + cv::namedWindow(WIN_NAME_HIST, cv::WINDOW_NORMAL); + cv::namedWindow(WIN_NAME_IMG, cv::WINDOW_NORMAL); + + hist_img_c1.release(); + hist_img_c1 = cv::Mat::zeros(cv::Size(256, 100), CV_8UC3); + hist_img_c3.release(); + hist_img_c3 = cv::Mat::zeros(cv::Size(256 * 3, 100), CV_8UC3); +} + +void img_iface_deinit (void) +{ + + for (ptrdiff_t i = 0; i < IMG_MEM_SIZE; i++) + image_mem[i].release(); + image_ref.release(); + + cv::destroyAllWindows(); +} + +void img_iface_load (const char *fpath, const char *fname) +{ + const char *path; + char file_name[FILENAME_MAX]; + + if (!fpath) + path = saved_path; + else + path = fpath; + + if (!fname) + user_iface_fname(fpath, file_name); + else + snprintf(file_name, FILENAME_MAX, "%s", fname); + + errno = 0; + load_image_file(path, file_name); + if (errno) + return; + + image.copyTo(image_copy_old); + image.copyTo(image_copy_tmp); +} + +void img_iface_cleanup (void) +{ + + image_copy_old.release(); + image_copy_tmp.release(); + histogram_c0.release(); + histogram_c1.release(); + histogram_c2.release(); + hist_img_c1.release(); + hist_img_c3.release(); +} + +void img_iface_act (int action, const void *data) +{ + + switch (action) { + /* img_alx */ + case IMG_IFACE_ACT_LOCAL_MAX: + img_iface_local_max(); + break; + case IMG_IFACE_ACT_SKELETON: + img_iface_skeleton(); + break; + case IMG_IFACE_ACT_LINES_HORIZONTAL: + img_iface_lines_horizontal(); + break; + case IMG_IFACE_ACT_LINES_VERTICAL: + img_iface_lines_vertical(); + break; + case IMG_IFACE_ACT_MEAN_HORIZONTAL: + img_iface_mean_horizontal(); + break; + case IMG_IFACE_ACT_MEAN_VERTICAL: + img_iface_mean_vertical(); + break; + case IMG_IFACE_ACT_MEDIAN_HORIZONTAL: + img_iface_median_horizontal(); + break; + case IMG_IFACE_ACT_MEDIAN_VERTICAL: + img_iface_median_vertical(); + break; + /* img_cv */ + /* Core: The core functionality */ + /* Pixel */ + case IMG_IFACE_ACT_PIXEL_GET: + img_iface_pixel_get(data); + break; + case IMG_IFACE_ACT_PIXEL_SET: + img_iface_pixel_set(data); + break; + /* ROI */ + case IMG_IFACE_ACT_SET_ROI: + img_iface_set_ROI(data); + break; + case IMG_IFACE_ACT_SET_ROI_2RECT: + img_iface_set_ROI_2rect(data); + break; + /* Operations on Arrays */ + case IMG_IFACE_ACT_AND_2REF: + img_iface_and_2ref(); + break; + case IMG_IFACE_ACT_NOT: + img_iface_not(); + break; + case IMG_IFACE_ACT_OR_2REF: + img_iface_or_2ref(); + break; + case IMG_IFACE_ACT_COMPONENT: + img_iface_component(data); + break; + /* Imgproc: Image processing */ + /* Image filtering */ + case IMG_IFACE_ACT_DILATE: + img_iface_dilate(data); + break; + case IMG_IFACE_ACT_ERODE: + img_iface_erode(data); + break; + case IMG_IFACE_ACT_DILATE_ERODE: + img_iface_dilate_erode(data); + break; + case IMG_IFACE_ACT_ERODE_DILATE: + img_iface_erode_dilate(data); + break; + case IMG_IFACE_ACT_SMOOTH: + img_iface_smooth(data); + break; + case IMG_IFACE_ACT_SOBEL: + img_iface_sobel(data); + break; + case IMG_IFACE_ACT_BORDER: + img_iface_border(data); + break; + /* Geometric image transformations */ + case IMG_IFACE_ACT_MIRROR: + img_iface_mirror(data); + break; + case IMG_IFACE_ACT_ROTATE_ORTO: + img_iface_rotate_orto(data); + break; + case IMG_IFACE_ACT_ROTATE: + img_iface_rotate(data); + break; + case IMG_IFACE_ACT_ROTATE_2RECT: + img_iface_rotate_2rect(data); + break; + /* Miscellaneous image transformations */ + case IMG_IFACE_ACT_ADAPTIVE_THRESHOLD: + img_iface_adaptive_thr(data); + break; + case IMG_IFACE_ACT_CVT_COLOR: + img_iface_cvt_color(data); + break; + case IMG_IFACE_ACT_DISTANCE_TRANSFORM: + img_iface_distance_transform(); + break; + case IMG_IFACE_ACT_THRESHOLD: + img_iface_threshold(data); + break; + /* Histograms */ + case IMG_IFACE_ACT_HISTOGRAM: + img_iface_histogram(data); + break; + case IMG_IFACE_ACT_HISTOGRAM_C3: + img_iface_histogram_c3(data); + break; + /* Structural analysis and shape descriptors */ + case IMG_IFACE_ACT_CONTOURS: + img_iface_contours(data); + break; + case IMG_IFACE_ACT_CONTOURS_SIZE: + img_iface_contours_size(data); + break; + case IMG_IFACE_ACT_BOUNDING_RECT: + img_iface_bounding_rect(data); + break; + case IMG_IFACE_ACT_FIT_ELLIPSE: + img_iface_fit_ellipse(data); + break; + case IMG_IFACE_ACT_MIN_AREA_RECT: + img_iface_min_area_rect(data); + break; + /* Feature detection */ + case IMG_IFACE_ACT_HOUGH_CIRCLES: + img_iface_hough_circles(data); + break; + /* img_orb */ + case IMG_IFACE_ACT_ALIGN: + img_iface_align(); + break; + /* img_calib3d */ + case IMG_IFACE_ACT_CALIBRATE: + img_iface_calibrate(data); + break; + case IMG_IFACE_ACT_UNDISTORT: + img_iface_undistort(data); + break; + /* img_zbar */ + case IMG_IFACE_ACT_DECODE: + img_iface_decode(data); + break; + /* img_ocr */ + case IMG_IFACE_ACT_READ: + img_iface_read(data); + break; + /* img_iface */ + case IMG_IFACE_ACT_APPLY: + img_iface_apply(); + break; + case IMG_IFACE_ACT_DISCARD: + img_iface_discard(); + break; + case IMG_IFACE_ACT_SAVE_MEM: + img_iface_save_mem(data); + break; + case IMG_IFACE_ACT_LOAD_MEM: + img_iface_load_mem(data); + break; + case IMG_IFACE_ACT_SAVE_REF: + img_iface_save_ref(); + break; + /* save */ + case IMG_IFACE_ACT_SAVE_FILE: + img_iface_save_file(); + break; + case IMG_IFACE_ACT_SAVE_UPDT: + img_iface_save_update(); + break; + default: + /* Invalid action */ + break; + } +} + +void img_iface_show_img (void) +{ + + cv::imshow(WIN_NAME_IMG, image_copy_tmp); + cv::waitKey(WIN_TIMEOUT); +} + +void img_iface_show_hist_c1 (void) +{ + + cv::imshow(WIN_NAME_HIST, hist_img_c1); + cv::waitKey(WIN_TIMEOUT); +} + +void img_iface_show_hist_c3 (void) +{ + + cv::imshow(WIN_NAME_HIST, hist_img_c3); + cv::waitKey(WIN_TIMEOUT); +} + + +/****************************************************************************** + ******* static functions ***************************************************** + ******************************************************************************/ +/* alx -----------------------------------------------------------------------*/ +static void img_iface_local_max (void) +{ + + if (image_copy_tmp.channels() != 1) + goto err; + + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_LOCAL_MAX, NULL); + + user_iface_log_write(1, "Local maxima"); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +static void img_iface_skeleton (void) +{ + + if (image_copy_tmp.channels() != 1) + goto err; + + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_SKELETON, NULL); + + user_iface_log_write(1, "Skeleton"); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +static void img_iface_lines_horizontal (void) +{ + + if (image_copy_tmp.channels() != 1) + goto err; + + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_LINES_HORIZONTAL, NULL); + + user_iface_log_write(1, "Horizontal lines"); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +static void img_iface_lines_vertical (void) +{ + + if (image_copy_tmp.channels() != 1) + goto err; + + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_LINES_VERTICAL, NULL); + + user_iface_log_write(1, "Vertical lines"); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +static void img_iface_mean_horizontal (void) +{ + + if (image_copy_tmp.channels() != 1) + goto err; + + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEAN_HORIZONTAL, NULL); + + user_iface_log_write(1, "Horizontal mean"); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +static void img_iface_mean_vertical (void) +{ + if (image_copy_tmp.channels() != 1) + goto err; + + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEAN_VERTICAL, NULL); + + user_iface_log_write(1, "Vertical mean"); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +static void img_iface_median_horizontal (void) +{ + + if (image_copy_tmp.channels() != 1) + goto err; + + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEDIAN_HORIZONTAL, NULL); + + user_iface_log_write(1, "Horizontal median"); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +static void img_iface_median_vertical (void) +{ + + if (image_copy_tmp.channels() != 1) + goto err; + + img_alx_act(&image_copy_tmp, IMG_ALX_ACT_MEDIAN_VERTICAL, NULL); + + user_iface_log_write(1, "Vertical median"); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +/* cv ------------------------------------------------------------------------*/ +/* ----- Core: The core functionality */ +/* ----- ------- Pixel */ +static void img_iface_pixel_get (const void *data) +{ + const struct Img_Iface_Data_Pixel_Get *data_cast; + struct Img_Iface_Data_Pixel_Get data_tmp; + unsigned char val; + ptrdiff_t tmp; + char txt[LOG_LINE_LEN]; + + if (image_copy_tmp.channels() != 1) + goto err; + + if (!data) { + data_tmp.val = &val; + tmp = image_copy_tmp.cols; + data_tmp.x = user_iface_getint(0, 0, tmp, "x:", NULL); + tmp = image_copy_tmp.rows; + data_tmp.y = user_iface_getint(0, 0, tmp, "y:", NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_PIXEL_GET, data); + + /* Write into user_iface_log_write */ + data_cast = (const struct Img_Iface_Data_Pixel_Get *)data; + snprintf(txt, LOG_LINE_LEN, "Pixel get: (%ti, %ti): %i", + data_cast->x, data_cast->y, *data_cast->val); + user_iface_log_write(1, txt); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +static void img_iface_pixel_set (const void *data) +{ + const struct Img_Iface_Data_Pixel_Set *data_cast; + struct Img_Iface_Data_Pixel_Set data_tmp; + ptrdiff_t tmp; + char txt[LOG_LINE_LEN]; + + if (image_copy_tmp.channels() != 1) + goto err; + + if (!data) { + tmp = image_copy_tmp.cols; + data_tmp.x = user_iface_getint(0, 0, tmp, "x:", NULL); + tmp = image_copy_tmp.rows; + data_tmp.y = user_iface_getint(0, 0, tmp, "y:", NULL); + data_tmp.val = user_iface_getint(0, 0, UINT8_MAX, "val:", NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_PIXEL_SET, data); + + data_cast = (const struct Img_Iface_Data_Pixel_Set *)data; + snprintf(txt, LOG_LINE_LEN, "Pixel get: (%ti, %ti): %i", + data_cast->x, data_cast->y, data_cast->val); + user_iface_log_write(1, txt); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +/* ----- ------- ROI */ +static void img_iface_set_ROI (const void *data) +{ + const struct Img_Iface_Data_SetROI *data_cast; + struct Img_Iface_Data_SetROI data_tmp; + ptrdiff_t tmp; + char txt[LOG_LINE_LEN]; + + if (!data) { + tmp = image_copy_tmp.cols; + data_tmp.rect.x = user_iface_getint(0, 0, tmp, "Origin: x:", + NULL); + tmp = image_copy_tmp.rows; + data_tmp.rect.y = user_iface_getint(0, 0, tmp, "Origin: y:", + NULL); + tmp = image_copy_tmp.cols - data_tmp.rect.x; + data_tmp.rect.width = user_iface_getint(1, tmp, tmp, "Width:", + NULL); + tmp = image_copy_tmp.rows - data_tmp.rect.y; + data_tmp.rect.height = user_iface_getint(1, tmp, tmp,"Height:", + NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_SET_ROI, data); + + data_cast = (const struct Img_Iface_Data_SetROI *)data; + snprintf(txt, LOG_LINE_LEN, "ROI: (%i,%i) w=%i,h=%i", + data_cast->rect.x, data_cast->rect.y, + data_cast->rect.width, data_cast->rect.height); + user_iface_log_write(1, txt); +} + +static void img_iface_set_ROI_2rect (const void *data) +{ + const struct Img_Iface_Data_SetROI *data_cast; + struct Img_Iface_Data_SetROI data_tmp; + char txt[LOG_LINE_LEN]; + + if (!data) { + data_tmp.rect.x = rectangle.x; + data_tmp.rect.y = rectangle.y; + data_tmp.rect.width = rectangle.width; + data_tmp.rect.height = rectangle.height; + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_SET_ROI, data); + + data_cast = (const struct Img_Iface_Data_SetROI *)data; + snprintf(txt, LOG_LINE_LEN, "ROI: (%i,%i) w=%i,h=%i", + data_cast->rect.x, data_cast->rect.y, + data_cast->rect.width, data_cast->rect.height); + user_iface_log_write(1, txt); +} + +/* ----- ------- Operations on arrays */ +static void img_iface_and_2ref (void) +{ + + if (image_copy_tmp.channels() != image_ref.channels()) + goto err; + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_AND_2REF, + (const void *)&image_ref); + + user_iface_log_write(1, "Bitwise AND"); + return; +err: + user_iface_log_write(1, "! Invalid input (Channels do not match ref)"); +} + +static void img_iface_not (void) +{ + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_NOT, NULL); + + user_iface_log_write(1, "Invert color"); +} + +static void img_iface_or_2ref (void) +{ + + if (image_copy_tmp.channels() != image_ref.channels()) + goto err; + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_OR_2REF, + (const void *)&image_ref); + + user_iface_log_write(1, "Bitwise OR"); + return; +err: + user_iface_log_write(1, "! Invalid input (Channels do not match ref)"); +} + +static void img_iface_component (const void *data) +{ + const struct Img_Iface_Data_Component *data_cast; + struct Img_Iface_Data_Component data_tmp; + ptrdiff_t tmp; + char txt[LOG_LINE_LEN]; + + if (image_copy_tmp.channels() < 2) + goto err; + + if (!data) { + tmp = image_copy_tmp.channels() - 1; + data_tmp.cmp = user_iface_getint(0, 0, tmp, "Component:", NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_COMPONENT, data); + + data_cast = (const struct Img_Iface_Data_Component *)data; + snprintf(txt, LOG_LINE_LEN, "Component %ti", data_cast->cmp); + user_iface_log_write(1, txt); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be >= 2 channels)"); +} + +/* ----- Imgproc: Image processing */ +/* ----- ------- Image filtering */ +static void img_iface_dilate (const void *data) +{ + const struct Img_Iface_Data_Dilate_Erode *data_cast; + struct Img_Iface_Data_Dilate_Erode data_tmp; + char txt[LOG_LINE_LEN]; + + if (!data) { + data_tmp.i = user_iface_getint(1, 1, INFINITY, "Iterations:", + NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data); + + data_cast = (const struct Img_Iface_Data_Dilate_Erode *)data; + snprintf(txt, LOG_LINE_LEN, "Dilate i = %i", data_cast->i); + user_iface_log_write(1, txt); +} + +static void img_iface_erode (const void *data) +{ + const struct Img_Iface_Data_Dilate_Erode *data_cast; + struct Img_Iface_Data_Dilate_Erode data_tmp; + char txt[LOG_LINE_LEN]; + + if (!data) { + data_tmp.i = user_iface_getint(1, 1, INFINITY, "Iterations:", + NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data); + + data_cast = (const struct Img_Iface_Data_Dilate_Erode *)data; + snprintf(txt, LOG_LINE_LEN, "Erode i = %i", data_cast->i); + user_iface_log_write(1, txt); +} + +static void img_iface_dilate_erode (const void *data) +{ + const struct Img_Iface_Data_Dilate_Erode *data_cast; + struct Img_Iface_Data_Dilate_Erode data_tmp; + char txt[LOG_LINE_LEN]; + + if (!data) { + data_tmp.i = user_iface_getint(1, 1, INFINITY, "Iterations:", + NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data); + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data); + + data_cast = (const struct Img_Iface_Data_Dilate_Erode *)data; + snprintf(txt, LOG_LINE_LEN, "Dilate-erode i = %i", data_cast->i); + user_iface_log_write(1, txt); +} + +static void img_iface_erode_dilate (const void *data) +{ + const struct Img_Iface_Data_Dilate_Erode *data_cast; + struct Img_Iface_Data_Dilate_Erode data_tmp; + char txt[LOG_LINE_LEN]; + + if (!data) { + data_tmp.i = user_iface_getint(1, 1, INFINITY, "Iterations:", + NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data); + img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data); + + data_cast = (const struct Img_Iface_Data_Dilate_Erode *)data; + snprintf(txt, LOG_LINE_LEN, "Erode-dilate i = %i", data_cast->i); + user_iface_log_write(1, txt); +} + +static void img_iface_smooth (const void *data) +{ + const struct Img_Iface_Data_Smooth *data_cast; + struct Img_Iface_Data_Smooth data_tmp; + char txt[LOG_LINE_LEN]; + + if (!data) { + data_tmp.method = user_iface_getint(1, 3, 3, + "Method: MEAN=1, GAUSS=2, MEDIAN=3", NULL); + data_tmp.ksize = user_iface_getint(3, 3, INFINITY, + "Kernel size: 3, 5, 7, ...", NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_SMOOTH, data); + + data_cast = (const struct Img_Iface_Data_Smooth *)data; + snprintf(txt, LOG_LINE_LEN, "Smooth mth = %i [%i x %i]", + data_cast->method, data_cast->ksize, data_cast->ksize); + user_iface_log_write(1, txt); +} + +static void img_iface_sobel (const void *data) +{ + const struct Img_Iface_Data_Sobel *data_cast; + struct Img_Iface_Data_Sobel data_tmp; + char txt[LOG_LINE_LEN]; + + if (image_copy_tmp.channels() != 1) + goto err; + + if (!data) { + data_tmp.dx = user_iface_getint(0, 1, 10, + "Order of the derivative x", NULL); + data_tmp.dy = user_iface_getint(0, 1, 10, + "Order of the derivative y", NULL); + data_tmp.ksize = user_iface_getint(-1, 3, 7, + "Size of the extended Sobel kernel (Scharr: -1)", + NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_SOBEL, data); + + data_cast = (const struct Img_Iface_Data_Sobel *)data; + snprintf(txt, LOG_LINE_LEN, "Sobel dx = %i; dy = %i [ks = %i]", + data_cast->dx, data_cast->dy, data_cast->ksize); + user_iface_log_write(1, txt); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +static void img_iface_border (const void *data) +{ + const struct Img_Iface_Data_Border *data_cast; + struct Img_Iface_Data_Border data_tmp; + char txt[LOG_LINE_LEN]; + + if (image_copy_tmp.channels() != 1) + goto err; + + if (!data) { + data_tmp.size = user_iface_getint(1, 1, INT16_MAX, "Size",NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_BORDER, data); + + data_cast = (const struct Img_Iface_Data_Border *)data; + snprintf(txt, LOG_LINE_LEN, "Border size = %ti", data_cast->size); + user_iface_log_write(1, txt); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +/* ----- ------- Geometric image transformations */ +static void img_iface_mirror (const void *data) +{ + const struct Img_Iface_Data_Mirror *data_cast; + struct Img_Iface_Data_Mirror data_tmp; + char txt[LOG_LINE_LEN]; + + if (!data) { + data_tmp.axis = user_iface_getint(0, 1, 1, "Axis: 0=x; 1=y", + NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_MIRROR, data); + + data_cast = (const struct Img_Iface_Data_Mirror *)data; + snprintf(txt, LOG_LINE_LEN, "Mirror axis: %i", data_cast->axis); + user_iface_log_write(1, txt); +} + +static void img_iface_rotate_orto (const void *data) +{ + const struct Img_Iface_Data_Rotate_Orto *data_cast; + struct Img_Iface_Data_Rotate_Orto data_tmp; + char txt[LOG_LINE_LEN]; + + if (!data) { + data_tmp.n = user_iface_getint(1, 1, 3, + "Rotate (counterclockwise) n * pi/2 rad; n:", + NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE_ORTO, data); + + data_cast = (const struct Img_Iface_Data_Rotate_Orto *)data; + snprintf(txt, LOG_LINE_LEN, "Rotate %i * pi/2 rad", data_cast->n); + user_iface_log_write(1, txt); +} + +static void img_iface_rotate (const void *data) +{ + const struct Img_Iface_Data_Rotate *data_cast; + struct Img_Iface_Data_Rotate data_tmp; + char txt[LOG_LINE_LEN]; + + if (!data) { + data_tmp.center.x = user_iface_getdbl(0, 0, INFINITY, + "Center: x:", NULL); + data_tmp.center.y = user_iface_getdbl(0, 0, INFINITY, + "Center: y:", NULL); + data_tmp.angle = user_iface_getdbl(-INFINITY, 0, INFINITY, + "Angle: (deg)", NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE, data); + + data_cast = (const struct Img_Iface_Data_Rotate *)data; + snprintf(txt, LOG_LINE_LEN, "Rotate (%.2f,%.2f) %lfº", + data_cast->center.x, data_cast->center.y, + data_cast->angle); + user_iface_log_write(1, txt); +} + +static void img_iface_rotate_2rect (const void *data) +{ + struct Img_Iface_Data_Rotate data_tmp; + + if (!data) { + data_tmp.center.x = rectangle_rot.center.x; + data_tmp.center.y = rectangle_rot.center.y; + data_tmp.angle = rectangle_rot.angle; + /* If angle is < -45º, + * it is taking into acount the incorrect side */ + if (data_tmp.angle < -45.0) + data_tmp.angle += 90.0; + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE, data); + + user_iface_log_write(1, "Rotate to rectangle"); +} + +/* ----- ------- Miscellaneous image transformations */ +static void img_iface_adaptive_thr (const void *data) +{ + const struct Img_Iface_Data_Adaptive_Thr *data_cast; + struct Img_Iface_Data_Adaptive_Thr data_tmp; + char txt[LOG_LINE_LEN]; + + if (image_copy_tmp.channels() != 1) + goto err; + + if (!data) { + data_tmp.method = user_iface_getint(0, 1, 1, + "Method: MEAN=0, GAUSS=1", NULL); + data_tmp.thr_typ = user_iface_getint(0, 0, 1, + "Type: BIN=0, BIN_INV=1", NULL); + data_tmp.ksize = user_iface_getint(3, 3, INFINITY, + "Kernel size: 3, 5, 7, ...", NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_ADAPTIVE_THRESHOLD, data); + + data_cast = (const struct Img_Iface_Data_Adaptive_Thr *)data; + snprintf(txt, LOG_LINE_LEN, "Threshold mth=%i, typ=%i, ks=%i", + data_cast->method, data_cast->thr_typ, + data_cast->ksize); + user_iface_log_write(1, txt); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +static void img_iface_cvt_color (const void *data) +{ + const struct Img_Iface_Data_Cvt_Color *data_cast; + struct Img_Iface_Data_Cvt_Color data_tmp; + char txt[LOG_LINE_LEN]; + + if (image_copy_tmp.channels() != 3) + goto err; + + if (!data) { + data_tmp.method =user_iface_getint(0, 0, cv::COLOR_COLORCVT_MAX, + "Method: BGR2GRAY = 6, BGR2HSV = 40", NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_CVT_COLOR, data); + + data_cast = (const struct Img_Iface_Data_Cvt_Color *)data; + snprintf(txt, LOG_LINE_LEN, "Convert color %i", data_cast->method); + user_iface_log_write(1, txt); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 3 channels)"); +} + +static void img_iface_distance_transform (void) +{ + + if (image_copy_tmp.channels() != 1) + goto err; + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_DISTANCE_TRANSFORM, NULL); + + user_iface_log_write(1, "Distance transform"); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +static void img_iface_threshold (const void *data) +{ + const struct Img_Iface_Data_Threshold *data_cast; + struct Img_Iface_Data_Threshold data_tmp; + char txt[LOG_LINE_LEN]; + + if (image_copy_tmp.channels() != 1) + goto err; + + if (!data) { + data_tmp.thr_typ = user_iface_getint(0, 0, 4, + "Type: BIN=0, BIN_INV=1, TRUNC=2, TOZ=3, TOZ_INV=4", + NULL); + data_tmp.thr_val = user_iface_getint(-1, 0, UINT8_MAX, + "Value: 0 to 255 (or -1 for Otsu's algorithm)", + NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_THRESHOLD, data); + + data_cast = (const struct Img_Iface_Data_Threshold *)data; + snprintf(txt, LOG_LINE_LEN, "Threshold typ = %i, val = %i", + data_cast->thr_typ, data_cast->thr_val); + user_iface_log_write(1, txt); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +/* ----- ------- Histograms */ +static void img_iface_histogram (const void *data) +{ + struct Img_Iface_Data_Histogram data_tmp; + + if (image_copy_tmp.channels() != 1) + goto err; + + if (!data) { + data_tmp.hist_c0 = &histogram_c0; + data_tmp.hist_img = &hist_img_c1; + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_HISTOGRAM, data); + + user_iface_log_write(1, "Histogram"); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +static void img_iface_histogram_c3 (const void *data) +{ + struct Img_Iface_Data_Histogram data_tmp; + + if (image_copy_tmp.channels() != 3) + goto err; + + if (!data) { + data_tmp.hist_c0 = &histogram_c0; + data_tmp.hist_c1 = &histogram_c1; + data_tmp.hist_c2 = &histogram_c2; + data_tmp.hist_img = &hist_img_c3; + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_HISTOGRAM_C3, data); + + user_iface_log_write(1, "Histogram (3 channels)"); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 3 channels)"); +} + +/* ----- ------- Structural analysis and shape descriptors */ +static void img_iface_contours (const void *data) +{ + const struct Img_Iface_Data_Contours *data_cast; + struct Img_Iface_Data_Contours data_tmp; + ptrdiff_t tmp; + char txt[LOG_LINE_LEN]; + + if (image_copy_tmp.channels() != 1) + goto err; + + if (!data) { + data_tmp.contours = &contours; + data_tmp.hierarchy = &hierarchy; + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_CONTOURS, data); + + data_cast = (const struct Img_Iface_Data_Contours *)data; + tmp = data_cast->contours->size(); + snprintf(txt, LOG_LINE_LEN, "Contours n = %ti", tmp); + user_iface_log_write(1, txt); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +static void img_iface_contours_size (const void *data) +{ + const struct Img_Iface_Data_Contours_Size *data_cast; + struct Img_Iface_Data_Contours_Size data_tmp; + ptrdiff_t tmp; + char txt[LOG_LINE_LEN]; + + if (!data) { + data_tmp.contours = &contours; + data_tmp.area = area; + data_tmp.perimeter = perimeter; + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_CONTOURS_SIZE, data); + + data_cast = (const struct Img_Iface_Data_Contours_Size *)data; + user_iface_log_write(1, "Contours size:"); + tmp = data_cast->contours->size(); + for (ptrdiff_t i = 0; i < tmp; i++) { + snprintf(txt, LOG_LINE_LEN, "cnt[%ti]: A = %lf; P = %lf;", + i, data_cast->area[i], data_cast->perimeter[i]); + user_iface_log_write(2, txt); + } +} + +static void img_iface_bounding_rect (const void *data) +{ + struct Img_Iface_Data_Bounding_Rect data_tmp; + + if (!data) { + if(!contours.size()) + goto err; + data_tmp.contour = &(contours[0]); + data_tmp.rect = &rectangle; + data_tmp.show = true; + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_BOUNDING_RECT, data); + + user_iface_log_write(1, "Bounding rectangle"); + return; +err: + user_iface_log_write(1, "! Invalid input (No contours saved)"); +} + +static void img_iface_fit_ellipse (const void *data) +{ + struct Img_Iface_Data_MinARect data_tmp; + + if (!data) { + if(!contours.size()) + goto err; + data_tmp.contour = &(contours[0]); + data_tmp.rect = &rectangle_rot; + data_tmp.show = true; + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_FIT_ELLIPSE, data); + + user_iface_log_write(1, "Fit ellipse"); + return; +err: + user_iface_log_write(1, "! Invalid input (No contours saved)"); +} + +static void img_iface_min_area_rect (const void *data) +{ + struct Img_Iface_Data_MinARect data_tmp; + + if (!data) { + if(!contours.size()) + goto err; + data_tmp.contour = &(contours[0]); + data_tmp.rect = &rectangle_rot; + data_tmp.show = true; + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_MIN_AREA_RECT, data); + + user_iface_log_write(1, "Min area rectangle"); + return; +err: + user_iface_log_write(1, "! Invalid input (No contours saved)"); +} + +/* ----- ------- Feature detection */ +static void img_iface_hough_circles (const void *data) +{ + const struct Img_Iface_Data_Hough_Circles *data_cast; + struct Img_Iface_Data_Hough_Circles data_tmp; + ptrdiff_t tmp; + char txt[LOG_LINE_LEN]; + + if (image_copy_tmp.channels() != 1) + goto err; + + if (!data) { + data_tmp.circles = &circles; + data_tmp.dist_min = user_iface_getdbl(0, 5, INFINITY, + "Minimum distance:", NULL); + data_tmp.param_1 = user_iface_getdbl(0, 200, INFINITY, + "param 1:", NULL); + data_tmp.param_2 = user_iface_getdbl(0, 100, INFINITY, + "param 2:", NULL); + data_tmp.radius_min = user_iface_getint(0, 10, INFINITY, + "Minimum radius", NULL); + data_tmp.radius_max = user_iface_getint(0, 0, INFINITY, + "Maximum radius", NULL); + data = (const void *)&data_tmp; + } + + img_cv_act(&image_copy_tmp, IMG_CV_ACT_HOUGH_CIRCLES, data); + + data_cast = (const struct Img_Iface_Data_Hough_Circles *)data; + tmp = data_cast->circles->size(); + snprintf(txt, LOG_LINE_LEN, "Circles n = %ti", tmp); + user_iface_log_write(1, txt); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +/* orb -----------------------------------------------------------------------*/ +static void img_iface_align (void) +{ + + if (image_ref.empty()) + goto err; + + img_orb_act(&image_ref, &image_copy_tmp, IMG_ORB_ACT_ALIGN); + + user_iface_log_write(1, "Align to reference"); + return; +err: + user_iface_log_write(1, "! Reference is NULL"); +} + +/* calib3d -------------------------------------------------------------------*/ +static void img_iface_calibrate (const void *data) +{ + struct Img_Iface_Data_Calibrate data_tmp; + + if (image_copy_tmp.channels() != 1) + goto err; + + if (!data) { + data_tmp.intrinsic_mat = &intrinsic_mat; + data_tmp.dist_coefs = &dist_coefs; + data_tmp.rvecs = &rvecs; + data_tmp.tvecs = &tvecs; + data = (const void *)&data_tmp; + } + + img_calib3d_act(&image_copy_tmp, IMG_CALIB3D_ACT_CALIBRATE, data); + + user_iface_log_write(1, "Calibrate"); + return; +err: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +static void img_iface_undistort (const void *data) +{ + struct Img_Iface_Data_Undistort data_tmp; + + if (!data) { + data_tmp.intrinsic_mat = &intrinsic_mat; + data_tmp.dist_coefs = &dist_coefs; + data = (const void *)&data_tmp; + } + + img_calib3d_act(&image_copy_tmp, IMG_CALIB3D_ACT_UNDISTORT, data); + + user_iface_log_write(1, "Undistort"); +} + +/* zbar ----------------------------------------------------------------------*/ +static void img_iface_decode (const void *data) +{ + struct Img_Iface_Data_Decode data_tmp; + const struct Img_Iface_Data_Decode *data_cast; + char txt[LOG_LINE_LEN]; + + if (image_copy_tmp.channels() != 1) + goto err_chan; + + if (!data) { + data_tmp.code_type = user_iface_getint(0, 0, INT_MAX, + "Type of code: (0 for all)", NULL); + data = (const void *)&data_tmp; + } + + img_zb_act(&image_copy_tmp, IMG_ZB_ACT_DECODE, data); + + data_cast = (const struct Img_Iface_Data_Decode *)data; + snprintf(txt, LOG_LINE_LEN, "Detect codes c = %i",data_cast->code_type); + user_iface_log_write(1, txt); + + if (!zb_codes.n) + goto err_zb; + for (ptrdiff_t i = 0; i < zb_codes.n; i++) { + snprintf(txt, LOG_LINE_LEN, "%s -- '%s'", + zb_codes.arr[i].sym_name, zb_codes.arr[i].data); + user_iface_log_write(2, txt); + } + return; +err_zb: + user_iface_log_write(2, "! No code detected"); + return; +err_chan: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +/* ocr -----------------------------------------------------------------------*/ +static void img_iface_read (const void *data) +{ + struct Img_Iface_Data_Read data_tmp; + const struct Img_Iface_Data_Read *data_cast; + char txt[LOG_LINE_LEN]; + + if (image_copy_tmp.channels() != 1) + goto err_chan; + + data_cast = (const struct Img_Iface_Data_Read *)data; + + if (!data) { + data_tmp.lang = user_iface_getint(0, 1, 2, + "Language: ENG = 0, SPA = 1, CAT = 2", NULL); + data_tmp.conf = user_iface_getint(0, 1, 2, + "Config: none = 0, Price = 1", NULL); + } else { + data_tmp.lang = data_cast->lang; + data_tmp.conf = data_cast->conf; + } + /* Adapt image data */ + data_tmp.img.data = image_copy_tmp.data; + data_tmp.img.width = image_copy_tmp.size().width; + data_tmp.img.height = image_copy_tmp.size().height; + data_tmp.img.B_per_pix = image_copy_tmp.channels(); + data_tmp.img.B_per_line = image_copy_tmp.step1(); + data = (const void *)&data_tmp; + + img_ocr_act(IMG_OCR_ACT_READ, data); + + snprintf(txt, LOG_LINE_LEN, "OCR (lang = %i) [c = %i]", + data_cast->lang, data_cast->conf); + user_iface_log_write(1, txt); + if (img_ocr_text[0] == '\0') + goto err_ocr; + return; +err_ocr: + user_iface_log_write(2, "! No text detected"); + return; +err_chan: + user_iface_log_write(1, "! Invalid input (Must be 1 channel)"); +} + +/* iface ---------------------------------------------------------------------*/ +static void img_iface_apply (void) +{ + + image_copy_old.release(); + image_copy_tmp.copyTo(image_copy_old); + + user_iface_log_write(1, "Apply changes"); +} + +static void img_iface_discard (void) +{ + + image_copy_tmp.release(); + image_copy_old.copyTo(image_copy_tmp); + + user_iface_log_write(1, "Discard changes"); +} + +static void img_iface_save_mem (const void *data) +{ + ptrdiff_t m; + char txt[LOG_LINE_LEN]; + + if (!data) + m = user_iface_getint(0, 0, IMG_MEM_SIZE -1,"mem[m]; m:",NULL); + else + m = *(const ptrdiff_t *)data; + + image_mem[m].release(); + image_copy_tmp.copyTo(image_mem[m]); + + snprintf(txt, LOG_LINE_LEN, "Save to mem[%ti]", m); + user_iface_log_write(1, txt); +} + +static void img_iface_load_mem (const void *data) +{ + ptrdiff_t m; + char txt[LOG_LINE_LEN]; + + if (!data) + m = user_iface_getint(0, 0, IMG_MEM_SIZE -1,"mem[m]; m:",NULL); + else + m = *(const ptrdiff_t *)data; + + if (image_mem[m].empty()) + goto err; + + image_copy_tmp.release(); + image_mem[m].copyTo(image_copy_tmp); + + snprintf(txt, LOG_LINE_LEN, "Load from mem[%ti]", m); + user_iface_log_write(1, txt); + return; +err: + user_iface_log_write(1, "! Empty memory"); +} + +static void img_iface_save_ref (void) +{ + + image_ref.release(); + image_copy_tmp.copyTo(image_ref); + + user_iface_log_write(1, "Save to reference"); +} + +/* save/save -----------------------------------------------------------------*/ +static void img_iface_save_file (void) +{ + + user_iface_log_write(1, "Save as..."); + + image.release(); + image_copy_tmp.copyTo(image); + save_image_file(NULL, NULL); +} + +static void img_iface_save_update (void) +{ + + image.release(); + image_copy_tmp.copyTo(image); + + user_iface_log_write(1, "Save: update img"); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/image/src/img_ocr.c b/src/image/ocr.c index 6c92250..4f6d3de 100644 --- a/modules/image/src/img_ocr.c +++ b/src/image/ocr.c @@ -7,32 +7,50 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <limits.h> - #include <stddef.h> - #include <stdio.h> -/* Packages ------------------------------------------------------------------*/ - #include <tesseract/capi.h> -/* Project -------------------------------------------------------------------*/ - /* share_path */ - #include "about.h" -/* Module --------------------------------------------------------------------*/ - #include "img_iface.h" +#include "vision-artificial/image/ocr.h" - #include "img_ocr.h" +#include <limits.h> +#include <stddef.h> +#include <stdio.h> + +#include <tesseract/capi.h> + +#include "vision-artificial/about/about.h" +#include "vision-artificial/image/iface.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ /****************************************************************************** - ******* static functions ***************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** ******************************************************************************/ static void img_ocr_read (const void *data); /****************************************************************************** - ******* main ***************************************************************** + ******* global functions ***************************************************** ******************************************************************************/ void img_ocr_act (int action, const void *data) { + switch (action) { case IMG_OCR_ACT_READ: img_ocr_read(data); @@ -42,16 +60,16 @@ void img_ocr_act (int action, const void *data) /****************************************************************************** - ******* static functions ***************************************************** + ******* static functions (definitions) *************************************** ******************************************************************************/ static void img_ocr_read (const void *data) { const struct Img_Iface_Data_Read *data_cast; - struct TessBaseAPI *handle_ocr; + struct TessBaseAPI *handle_ocr; int lang; - char lang_str [20 + 1]; + char lang_str[FILENAME_MAX]; int conf; - char conf_str [FILENAME_MAX]; + char conf_str[FILENAME_MAX]; char *txt; /* Data */ @@ -93,16 +111,16 @@ static void img_ocr_read (const void *data) /* init OCR */ handle_ocr = TessBaseAPICreate(); -#ifdef OEM_LSTM_ONLY +#if defined(OEM_LSTM_ONLY) TessBaseAPIInit2(handle_ocr, NULL, lang_str, OEM_LSTM_ONLY); #else TessBaseAPIInit2(handle_ocr, NULL, lang_str, OEM_DEFAULT); #endif /* TessBaseAPIInit2(handle_ocr, NULL, lang_str, OEM_TESSERACT_LSTM_COMBINED);*/ - if (conf) { - /* Configure OCR (whitelist chars) */ + + /* Configure OCR (whitelist chars) */ + if (conf) TessBaseAPIReadConfigFile(handle_ocr, conf_str); - } /* scan image for text */ TessBaseAPISetImage(handle_ocr, data_cast->img.data, diff --git a/modules/image/src/img_orb.cpp b/src/image/orb.cpp index 5c716b1..708eb3c 100644 --- a/modules/image/src/img_orb.cpp +++ b/src/image/orb.cpp @@ -7,33 +7,48 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ -/* Standard C++ --------------------------------------------------------------*/ - #include <vector> -/* Standard C ----------------------------------------------------------------*/ - #include <cstdio> -/* Packages ------------------------------------------------------------------*/ - #include <opencv2/opencv.hpp> - #include <opencv2/features2d/features2d.hpp> -/* Module -------------------------------------------------------------------*/ - #include "img_orb.hpp" +#include "vision-artificial/image/orb.hpp" + +#include <cstddef> +#include <cstdio> + +#include <vector> + +#include <opencv2/opencv.hpp> +#include <opencv2/features2d/features2d.hpp> /****************************************************************************** ******* macros *************************************************************** ******************************************************************************/ - # define MAX_FEATURES (50000) - # define GOOD_MATCH_P (0.25) +#define MAX_FEATURES (50000) +#define GOOD_MATCH_P (0.25) + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ /****************************************************************************** - ******* static functions ***************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** ******************************************************************************/ static void img_orb_align (const class cv::Mat *img_0, class cv::Mat *img_1); /****************************************************************************** - ******* main ***************************************************************** + ******* global functions ***************************************************** ******************************************************************************/ void img_orb_act (const class cv::Mat *img_ref, class cv::Mat *imgptr, int action) @@ -47,35 +62,41 @@ void img_orb_act (const class cv::Mat *img_ref, /****************************************************************************** - ******* static functions ***************************************************** + ******* static functions (definitions) *************************************** ******************************************************************************/ static void img_orb_align (const class cv::Mat *img_0, class cv::Mat *img_1) { - /* Variables to store keypoints & descriptors */ - class std::vector <class cv::KeyPoint> keypoints_0; - class std::vector <class cv::KeyPoint> keypoints_1; - class cv::Mat descriptors_0; - class cv::Mat descriptors_1; + class std::vector <class cv::KeyPoint> keypoints_0; + class std::vector <class cv::KeyPoint> keypoints_1; + class cv::Mat descriptors_0; + class cv::Mat descriptors_1; +#if (CV_VERSION_EPOCH == 2) + class cv::ORB orb; +#elif (CV_VERSION_EPOCH == 3) + class cv::Ptr <class cv::Feature2D> orb; +#endif + class std::vector <struct cv::DMatch> matches; + class cv::Ptr <class cv::DescriptorMatcher> matcher; + ptrdiff_t good_matches; + class cv::Mat img_matches; + class std::vector <class cv::Point_ <float>> points_0; + class std::vector <class cv::Point_ <float>> points_1; + ptrdiff_t size; + class cv::Mat img_hg; + class cv::Mat img_align; /* Detect ORB features & compute descriptors */ -#if 1 - /* OpenCV 2.x */ - class cv::ORB orb; +#if (CV_VERSION_EPOCH == 2) orb(*img_0, cv::Mat(), keypoints_0, descriptors_0); orb(*img_1, cv::Mat(), keypoints_1, descriptors_1); -#else - /* OpenCV 3.x */ - class cv::Ptr <class cv::Feature2D> orb; +#elif (CV_VERSION_EPOCH == 3) orb = cv::ORB::create(MAX_FEATURES); orb->detectAndCompute(*img_0, cv::Mat(), keypoints_0, descriptors_0); orb->detectAndCompute(*img_1, cv::Mat(), keypoints_1, descriptors_1); #endif - /* Match structures */ - class std::vector <struct cv::DMatch> matches; - cv::Ptr <class cv::DescriptorMatcher> matcher; matcher = cv::DescriptorMatcher::create("BruteForce-Hamming"); matcher->match(descriptors_1, descriptors_0, matches, cv::Mat()); @@ -83,31 +104,25 @@ static void img_orb_align (const class cv::Mat *img_0, std::sort(matches.begin(), matches.end()); /* Remove not so good matches */ - int good_matches; good_matches = GOOD_MATCH_P * matches.size(); matches.erase(matches.begin() + good_matches, matches.end()); /* Draw top matches */ - class cv::Mat img_matches; cv::drawMatches(*img_1, keypoints_1, *img_0, keypoints_0, matches, img_matches); cv::imwrite("matches.jpg", img_matches); /* Extract location of good matches */ - class std::vector <class cv::Point_ <float>> points_0; - class std::vector <class cv::Point_ <float>> points_1; - int i; - for (i = 0; i < (int)matches.size(); i++) { + size = matches.size(); + for (ptrdiff_t i = 0; i < size; i++) { points_1.push_back(keypoints_1[matches[i].queryIdx].pt); points_0.push_back(keypoints_0[matches[i].trainIdx].pt); } /* Find homography */ - class cv::Mat img_hg; img_hg = cv::findHomography(points_1, points_0, CV_RANSAC); /* Use homography to warp image */ - class cv::Mat img_align; cv::warpPerspective(*img_1, img_align, img_hg, img_0->size()); /* Write img_align into img_1 */ diff --git a/modules/image/src/img_zbar.cpp b/src/image/zbar.cpp index 952abe0..f11e751 100644 --- a/modules/image/src/img_zbar.cpp +++ b/src/image/zbar.cpp @@ -7,30 +7,50 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <climits> - #include <cstddef> - #include <cstdio> -/* Packages ------------------------------------------------------------------*/ - #include <opencv2/opencv.hpp> - #include <zbar.h> -/* Module --------------------------------------------------------------------*/ - #include "img_iface.hpp" +#include "vision-artificial/image/zbar.hpp" - #include "img_zbar.hpp" +#include <climits> +#include <cstddef> +#include <cstdio> + +#include <opencv2/opencv.hpp> +#include <zbar.h> + +#include "vision-artificial/image/iface.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ /****************************************************************************** - ******* static functions ***************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** ******************************************************************************/ static void img_zb_decode (class cv::Mat *imgptr, const void *data); /****************************************************************************** - ******* main ***************************************************************** + ******* global functions ***************************************************** ******************************************************************************/ void img_zb_act (class cv::Mat *imgptr, int action, const void *data) { + switch (action) { case IMG_ZB_ACT_DECODE: img_zb_decode(imgptr, data); @@ -40,18 +60,25 @@ void img_zb_act (class cv::Mat *imgptr, int action, const void *data) /****************************************************************************** - ******* static functions ***************************************************** + ******* static functions (definitions) *************************************** ******************************************************************************/ static void img_zb_decode (class cv::Mat *imgptr, const void *data) { + const struct zbar::zbar_symbol_s *symbol; struct zbar::zbar_image_scanner_s *scanner; struct zbar::zbar_image_s *image_zb; - const struct zbar::zbar_symbol_s *symbol; enum zbar::zbar_symbol_type_e code_type; - int i; + void *imgdata; + ptrdiff_t rows; + ptrdiff_t cols; + + imgdata = (void *)imgptr->data; + rows = imgptr->rows; + cols = imgptr->cols; /* Type of code to scan */ - code_type = ((const struct Img_Iface_Data_Decode *)data)->code_type; + code_type = (enum zbar::zbar_symbol_type_e) + ((const struct Img_Iface_Data_Decode *)data)->code_type; /* create & configure a reader */ scanner = zbar::zbar_image_scanner_create(); @@ -61,30 +88,29 @@ static void img_zb_decode (class cv::Mat *imgptr, const void *data) /* wrap image data */ image_zb = zbar::zbar_image_create(); zbar::zbar_image_set_format(image_zb, *(int*)"GREY"); - zbar::zbar_image_set_size(image_zb, imgptr->cols, imgptr->rows); - zbar::zbar_image_set_data(image_zb, (void *)(imgptr->data), - (imgptr->cols * imgptr->rows), - NULL); + zbar::zbar_image_set_size(image_zb, cols, rows); + zbar::zbar_image_set_data(image_zb, imgdata, cols * rows, NULL); /* scan the image for barcodes */ zb_codes.n = zbar::zbar_scan_image(scanner, image_zb); - if (zb_codes.n) { - /* extract results */ - symbol = zbar::zbar_image_first_symbol(image_zb); - for (i = 0; i < ZB_CODES_MAX && symbol; i++) { - /* Write results into array */ - zb_codes.arr[i].type = zbar::zbar_symbol_get_type(symbol); - snprintf(zb_codes.arr[i].sym_name, 80, "%s", - zbar::zbar_get_symbol_name( - zb_codes.arr[i].type)); - snprintf(zb_codes.arr[i].data, ZBAR_LEN_MAX, "%s", + if (!zb_codes.n) + goto not_found; + + /* extract results */ + symbol = zbar::zbar_image_first_symbol(image_zb); + for (ptrdiff_t i = 0; i < ZB_CODES_MAX && symbol; i++) { + zb_codes.arr[i].type = zbar::zbar_symbol_get_type(symbol); + code_type = (enum zbar::zbar_symbol_type_e)zb_codes.arr[i].type; + snprintf(zb_codes.arr[i].sym_name, 80, "%s", + zbar::zbar_get_symbol_name(code_type)); + snprintf(zb_codes.arr[i].data, ZBAR_LEN_MAX, "%s", zbar::zbar_symbol_get_data(symbol)); - /* Load next symbol */ - symbol = zbar::zbar_symbol_next(symbol); - } + /* Load next symbol */ + symbol = zbar::zbar_symbol_next(symbol); } +not_found: /* clean up */ zbar::zbar_image_destroy(image_zb); zbar::zbar_image_scanner_destroy(scanner); diff --git a/src/main.cpp b/src/main.cpp index b1bc046..1a8f5de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,24 +7,24 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <cstdio> -/* libalx --------------------------------------------------------------------*/ - #include "libalx/curses/alx_ncur.hpp" -/* Project -------------------------------------------------------------------*/ - #include "about.hpp" - #include "img_iface.hpp" - #include "menu_iface.hpp" - #include "user_iface.hpp" - #include "parser.hpp" - #include "save.hpp" +#include <cstdio> + +#include "libalx/base/stdio/wait.hpp" +#include "libalx/extra/ncurses/common.hpp" + +#include "vision-artificial/about/about.hpp" +#include "vision-artificial/image/iface.hpp" +#include "vision-artificial/menu/iface.hpp" +#include "vision-artificial/menu/parse.hpp" +#include "vision-artificial/save/save.hpp" +#include "vision-artificial/user/iface.hpp" /****************************************************************************** ******* static functions ***************************************************** ******************************************************************************/ -static void init_all (int *argc, char *(*argv[])); -static void cleanup (void); +static void init (int *argc, char *(*argv[])); +static void deinit (void); /****************************************************************************** @@ -33,14 +33,14 @@ static void cleanup (void); int main (int argc, char *argv[]) { - init_all(&argc, &argv); + init(&argc, &argv); print_share_file(SHARE_COPYRIGHT); - getchar(); + alx_wait4enter(); menu_iface(); - cleanup(); + deinit(); return 0; } @@ -49,11 +49,11 @@ int main (int argc, char *argv[]) /****************************************************************************** ******* static functions ***************************************************** ******************************************************************************/ -static void init_all (int *argc, char *(*argv[])) +static void init (int *argc, char *(*argv[])) { - alx_start_curses(); - alx_pause_curses(); + alx_ncurses_init(); + alx_ncurses_pause(); about_init(); save_init(); @@ -62,16 +62,16 @@ static void init_all (int *argc, char *(*argv[])) user_iface_mode = USER_IFACE_TUI; user_iface_log.visible = 2; - parser(*argc, *argv); + parse(*argc, *argv); } -static void cleanup (void) +static void deinit (void) { - img_iface_cleanup_main(); + img_iface_deinit(); - alx_resume_curses(); - alx_end_curses(); + alx_ncurses_resume(); + alx_ncurses_deinit(); } diff --git a/modules/menu/src/menu_clui.c b/src/menu/clui.c index 964d176..5e947b7 100644 --- a/modules/menu/src/menu_clui.c +++ b/src/menu/clui.c @@ -7,23 +7,39 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ - #include "libalx/io/alx_input.h" +#include "vision-artificial/menu/clui.h" - #include "about.h" -// #include "save.h" - #include "start.h" +#include <ctype.h> +#include <stdlib.h> - #include "menu_clui.h" +#include "libalx/base/stdio/get.h" + +#include "vision-artificial/about/about.h" +#include "vision-artificial/ctrl/start.h" /****************************************************************************** ******* macros *************************************************************** ******************************************************************************/ - # define BUFF_SIZE (1024) /****************************************************************************** - ******* static functions ***************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** ******************************************************************************/ //static void menu_clui_rand (void); //static void menu_clui_custom (void); @@ -32,45 +48,32 @@ static void menu_clui_start (void); /****************************************************************************** - ******* main ***************************************************************** + ******* global functions ***************************************************** ******************************************************************************/ void menu_clui (void) { - char buff [BUFF_SIZE]; - char c; - - c = 'n'; - printf("Read 'Disclaimer of warranty'? (yes/NO): "); - if (!fgets(buff, BUFF_SIZE, stdin)) - return; - if (sscanf(buff, " %c", &c) != 1) - return; - if (c == 'y' || c == 'Y') { + unsigned char c; + + c = alx_get_ch("ny", true, true, "Read 'Disclaimer of warranty'? (yes/NO): ", + NULL, 1); + if (tolower(c) == 'y') { printf(" >yes\n"); print_share_file(SHARE_DISCLAIMER); } else { printf(" >NO\n"); } - c = 'n'; - printf("Read 'License'? (yes/NO): "); - if (!fgets(buff, BUFF_SIZE, stdin)) - return; - if (sscanf(buff, " %c", &c) != 1) - return; - if (c == 'y' || c == 'Y') { + c = alx_get_ch("ny", true, true, "Read 'License'? (yes/NO): ", NULL, 1); + if (tolower(c) == 'y') { printf(" >yes\n"); print_share_file(SHARE_LICENSE); } else { printf(" >NO\n"); } #if 0 - printf("Game interface? (NCURSES/text): "); - if (!fgets(buff, BUFF_SIZE, stdin)) - return; - if (sscanf(buff, " %c", &c) != 1) - return; - if (c == 't' || c == 'T') { + c = alx_get_ch("nt", true, true, "Game interface? (NCURSES/text): ", + NULL, 1); + if (tolower(c) == 't') { printf(" >text\n"); // FIXME } else { @@ -83,10 +86,11 @@ void menu_clui (void) /****************************************************************************** - ******* static functions ***************************************************** + ******* static functions (definitions) *************************************** ******************************************************************************/ static void menu_clui_load (void) { + #if 0 /* File name */ /* FIXME */ alx_w_getfname(USER_SAVED_DIR, saved_name, "File name:", saved_name, NULL); @@ -96,23 +100,19 @@ static void menu_clui_load (void) static void menu_clui_start (void) { + unsigned char c; + printf(" >>START:\n"); start_switch(); - char buff [BUFF_SIZE]; - char c; - - c = 'm'; - printf("Load again? (MENU/load/exit): "); - if (!fgets(buff, BUFF_SIZE, stdin)) - return; - if (sscanf(buff, " %c", &c) != 1) - return; - if (c == 'p' || c == 'P') { + c = alx_get_ch("mle", true, true, "Load again? (MENU/load/exit): ", + NULL, 1); + if (tolower(c) == 'l') { printf(" >load\n"); menu_clui_start(); - } else if (c == 'e' || c == 'E') { + } else if (tolower(c) == 'e') { printf(" >exit!\n"); + exit(EXIT_SUCCESS); } else { printf(" >MENU\n"); menu_clui(); diff --git a/modules/proc/inc/proc_label.hpp b/src/menu/iface.c index ebb4446..4b8bbd7 100644 --- a/modules/proc/inc/proc_label.hpp +++ b/src/menu/iface.c @@ -5,10 +5,12 @@ /****************************************************************************** - ******* include guard ******************************************************** + ******* headers ************************************************************** ******************************************************************************/ -# ifndef VA_PROC_LABEL_HPP - # define VA_PROC_LABEL_HPP +#include "vision-artificial/menu/iface.h" + +#include "vision-artificial/menu/clui.h" +#include "vision-artificial/menu/tui.h" /****************************************************************************** @@ -19,43 +21,46 @@ /****************************************************************************** ******* enums **************************************************************** ******************************************************************************/ - enum Proc_Label { - LABEL_OK, - LABEL_NOK_LABEL, - LABEL_NOK_CERDO, - LABEL_NOK_BCODE, - LABEL_NOK_PRODUCT, - LABEL_NOK_PRICE - }; /****************************************************************************** - ******* C wrapper ************************************************************ + ******* structs / unions ***************************************************** ******************************************************************************/ -extern "C" { /****************************************************************************** ******* variables ************************************************************ ******************************************************************************/ +int menu_iface_mode; /****************************************************************************** - ******* functions ************************************************************ + ******* static functions (prototypes) **************************************** ******************************************************************************/ -int proc_label (void); /****************************************************************************** - ******* C wrapper ************************************************************ + ******* global functions ***************************************************** ******************************************************************************/ -} /* extern "C" */ +void menu_iface (void) +{ + + switch (menu_iface_mode) { + case MENU_IFACE_FOO: + break; + case MENU_IFACE_CLUI: + menu_clui(); + break; + case MENU_IFACE_TUI: + menu_tui(); + break; + } +} /****************************************************************************** - ******* include guard ******************************************************** + ******* static functions (definitions) *************************************** ******************************************************************************/ -# endif /* proc_label.hpp */ /****************************************************************************** diff --git a/modules/menu/src/parser.c b/src/menu/parse.c index acce385..959ec5f 100644 --- a/modules/menu/src/parser.c +++ b/src/menu/parse.c @@ -7,37 +7,53 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <getopt.h> - #include <stdio.h> - #include <stdlib.h> -/* Project -------------------------------------------------------------------*/ - #include "about.h" - #include "user_iface.h" - #include "save.h" -/* Module --------------------------------------------------------------------*/ - #include "menu_iface.h" +#include "vision-artificial/menu/parse.h" - #include "parser.h" +#include <stdio.h> +#include <stdlib.h> + +#include <getopt.h> + +#include "libalx/base/stdio/sscan.h" + +#include "vision-artificial/about/about.h" +#include "vision-artificial/menu/iface.h" +#include "vision-artificial/save/save.h" +#include "vision-artificial/user/iface.h" /****************************************************************************** ******* macros *************************************************************** ******************************************************************************/ - # define OPT_LIST "hLuv""f:i:" +#define OPT_LIST "hLuv""f:i:" + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ /****************************************************************************** - ******* static functions ***************************************************** + ******* structs / unions ***************************************************** ******************************************************************************/ -static void parse_file (char *argument); -static void parse_iface (char *argument); /****************************************************************************** - ******* main ***************************************************************** + ******* variables ************************************************************ ******************************************************************************/ -void parser (int argc, char *argv[]) + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ +static void parse_file (char *arg); +static void parse_iface (char *arg); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void parse (int argc, char *argv[]) { int opt = 0; int opt_index = 0; @@ -63,31 +79,25 @@ void parser (int argc, char *argv[]) case 'h': print_share_file(SHARE_HELP); exit(EXIT_SUCCESS); - case 'L': print_share_file(SHARE_LICENSE); exit(EXIT_SUCCESS); - case 'u': print_share_file(SHARE_USAGE); exit(EXIT_SUCCESS); - case 'v': print_version(); exit(EXIT_SUCCESS); - /* Non-standard */ case 'f': parse_file(optarg); break; - case 'i': parse_iface(optarg); break; case '?': /* getopt_long already printed an error message. */ - default: print_share_file(SHARE_USAGE); exit(EXIT_FAILURE); @@ -97,38 +107,43 @@ void parser (int argc, char *argv[]) /****************************************************************************** - ******* static functions ***************************************************** + ******* static functions (definitions) *************************************** ******************************************************************************/ -static void parse_file (char *argument) +static void parse_file (char *arg) { FILE *fp; /* FIXME */ - fp = fopen(argument, "r"); - if (!fp) { - printf("--file argument not valid\n"); - printf("It must be a valid file name (relative to saved dir)\n"); - exit(EXIT_FAILURE); - } else { - fclose(fp); - - saved_path[0] = '\0'; - snprintf(saved_name, FILENAME_MAX, "%s", argument); - } + fp = fopen(arg, "r"); + if (!fp) + goto err; + fclose(fp); + + saved_path[0] = '\0'; + snprintf(saved_name, FILENAME_MAX, "%s", arg); + + return; +err: + printf("--file argument not valid\n"); + printf("It must be a valid file name (relative to saved dir)\n"); + exit(EXIT_FAILURE); } -static void parse_iface (char *argument) +static void parse_iface (char *arg) { - menu_iface_mode = atoi(argument); - user_iface_mode = menu_iface_mode; - if ((menu_iface_mode < MENU_IFACE_CLUI) || - (menu_iface_mode > MENU_IFACE_TUI)) { - printf("--iface argument not valid\n"); - printf("It must be an integer [%i U %i]\n", - MENU_IFACE_CLUI, MENU_IFACE_TUI); - exit(EXIT_FAILURE); + if (alx_sscan_int(&menu_iface_mode, MENU_IFACE_CLUI, 0, MENU_IFACE_TUI, + arg)) { + goto err; } + user_iface_mode = menu_iface_mode; + + return; +err: + printf("--iface argument not valid\n"); + printf("It must be an integer [%i U %i]\n", MENU_IFACE_CLUI, + MENU_IFACE_TUI); + exit(EXIT_FAILURE); } diff --git a/src/menu/tui.c b/src/menu/tui.c new file mode 100644 index 0000000..6c0620e --- /dev/null +++ b/src/menu/tui.c @@ -0,0 +1,315 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "vision-artificial/menu/tui.h" + +#include <stdbool.h> +#include <stddef.h> +#include <stdint.h> + +#include <ncurses.h> + +#include "libalx/base/stddef/size.h" +#include "libalx/base/stdio/wait.h" +#include "libalx/extra/ncurses/common.h" +#include "libalx/extra/ncurses/get.h" +#include "libalx/extra/ncurses/menu.h" + +#include "vision-artificial/about/about.h" +#include "vision-artificial/ctrl/start.h" +#include "vision-artificial/proc/iface.h" +#include "vision-artificial/save/save.h" +#include "vision-artificial/user/iface.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ +static void menu_continue (void); +static void menu_select (void); +static void menu_series (void); +static void menu_devel (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +void menu_tui (void) +{ + int_fast8_t h, w; + bool wh; + int_fast8_t sw; + + alx_ncurses_resume(); + + h = 23; + w = 80; + + static const struct Alx_Ncurses_Menu mnu[] = { + {7, 4, "[0] Exit program"}, + {2, 4, "[1] Continue"}, + {4, 4, "[2] Disclaimer of warranty"}, + {5, 4, "[3] Terms and conditions"} + }; + + wh = true; + while (wh) { + sw = alx_ncurses_menu(h, w, ARRAY_SIZE(mnu), mnu, "MENU:"); + + switch (sw) { + case 0: + wh = false; + break; + case 1: + menu_continue(); + break; + case 2: + alx_ncurses_pause(); + print_share_file(SHARE_DISCLAIMER); + printf("Press ENTER to continue"); + alx_wait4enter(); + alx_ncurses_resume(); + break; + case 3: + alx_ncurses_pause(); + print_share_file(SHARE_LICENSE); + printf("Press ENTER to continue"); + alx_wait4enter(); + alx_ncurses_resume(); + break; + } + } + + alx_ncurses_pause(); +} + + +/****************************************************************************** + ******* static functions (definitions) *************************************** + ******************************************************************************/ +static void menu_continue (void) +{ + WINDOW *win; + int_fast8_t h, w; + int_fast8_t r, c; + int_fast8_t w2, r2; + bool wh; + int_fast8_t sw; + + h = 23; + w = 80; + r = 1; + c = (80 - w) / 2; + + static const struct Alx_Ncurses_Menu mnu[] = { + {8, 4, "[0] Back"}, + {2, 4, "[1] Start"}, + {3, 4, "[2] Select"}, + {4, 4, "[3] Series"}, + {5, 4, "[4] Change file name"}, + {6, 4, "[5] DEVEL"} + }; + + /* Input box */ + w2 = w - 8; + r2 = r + h - 5; + static const char *const txt[] = {"File name:"}; + + wh = true; + while (wh) { + win = newwin(h, w, r, c); + mvwprintw(win, mnu[1].r, mnu[1].c, "%s (File: \"%s\")", + mnu[1].t, saved_name); + sw = alx_ncurses_w_menu(win, ARRAY_SIZE(mnu), mnu, + "CONTINUE:"); + + switch (sw) { + case 0: + wh = false; + break; + case 1: + alx_ncurses_delwin(win); + alx_ncurses_pause(); + start_switch(); + alx_ncurses_resume(); + break; + case 2: + alx_ncurses_delwin(win); + menu_select(); + break; + case 3: + alx_ncurses_delwin(win); + menu_series(); + break; + case 4: + save_reset_fpath(); + alx_w_get_fname(saved_path, saved_name, true, w2, r2, + txt[0], NULL, 2); + alx_ncurses_delwin(win); + break; + case 5: + alx_ncurses_delwin(win); + menu_devel(); + break; + } + } + + alx_ncurses_delwin(win); +} + +static void menu_select (void) +{ + int_fast8_t h, w; + int_fast8_t sw; + + h = 23; + w = 80; + + static const struct Alx_Ncurses_Menu mnu[] = { + {6, 4, "[0] Back"}, + {2, 4, "[1] Single image"}, + {4, 4, "[2] Series"} + }; + + sw = alx_ncurses_menu(h, w, ARRAY_SIZE(mnu), mnu, "SELECT MODE:"); + + switch (sw) { + case 1: + start_mode = START_SINGLE; + break; + + case 2: + start_mode = START_SERIES; + break; + } + +} + +static void menu_series (void) +{ + int_fast8_t h, w; + int_fast8_t sw; + + h = 23; + w = 80; + + static const struct Alx_Ncurses_Menu mnu[] = { + {8, 4, "[0] Back"}, + {2, 4, "[1] Label"}, + {3, 4, "[2] Objects"}, + {4, 4, "[3] Coins"}, + {5, 4, "[4] Resistor"}, + {6, 4, "[5] Lighters"} + }; + + sw = alx_ncurses_menu(h, w, ARRAY_SIZE(mnu), mnu, "SELECT LEVEL:"); + + switch (sw) { + case 1: + proc_mode = PROC_MODE_LABEL_SERIES; + break; + case 2: + proc_mode = PROC_MODE_OBJECTS_SERIES; + break; + case 3: + proc_mode = PROC_MODE_COINS_SERIES; + break; + case 4: + proc_mode = PROC_MODE_RESISTOR_SERIES; + break; + case 5: + proc_mode = PROC_MODE_LIGHTERS_SERIES; + break; + } + +} + +static void menu_devel (void) +{ + WINDOW *win; + int_fast8_t h, w; + int_fast8_t r, c; + int_fast8_t w2, r2; + bool wh; + int_fast8_t sw; + + h = 23; + w = 80; + r = 1; + c = (80 - w) / 2; + + static const struct Alx_Ncurses_Menu mnu[] = { + {6, 4, "[0] Back"}, + {2, 4, "[1] Change process mode"}, + {3, 4, "[2] Change log mode"}, + {4, 4, "[3] Change user iface mode"} + }; + + /* Input box */ + w2 = w - 8; + r2 = r + h - 5; + static const char *const txt[] = { + "Modes: 0=Auto; 1=Stop@prod; 2=Delay@step; 3=Stop@step", + "Modes: 0=Results; 1=Operations; 2=All", + "Modes: 1=CLUI; 2=TUI" + }; + + win = newwin(h, w, r, c); + + wh = true; + while (wh) { + sw = alx_ncurses_w_menu(win, ARRAY_SIZE(mnu), mnu, + "DEVELOPER OPTIONS:"); + switch (sw) { + case 0: + wh = false; + break; + case 1: + proc_debug = alx_w_get_int(PROC_DBG_NO, 0, + PROC_DBG_STOP_STEP, + w2, r2, txt[0], NULL, 2); + break; + case 2: + user_iface_log.visible = alx_w_get_u8(0, 2, 2, + w2, r2, txt[1], NULL, 2); + break; + case 3: + user_iface_mode = alx_w_get_int(1, 2, 2, + w2, r2, txt[2], NULL, 2); + break; + } + } + + alx_ncurses_delwin(win); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/src/proc/coins.cpp b/src/proc/coins.cpp new file mode 100644 index 0000000..76d9640 --- /dev/null +++ b/src/proc/coins.cpp @@ -0,0 +1,291 @@ +/****************************************************************************** + * Copyright (C) 2018 Alejandro Colomar Andrés * + * SPDX-License-Identifier: GPL-2.0-only * + ******************************************************************************/ + + +/****************************************************************************** + ******* headers ************************************************************** + ******************************************************************************/ +#include "vision-artificial/proc/coins.hpp" + +#include <cstdio> + +#include <opencv2/opencv.hpp> + +#include "libalx/base/math/arithmetic_mean.hpp" +#include "libalx/base/stddef/size.hpp" +#include "libalx/base/stdlib/maximum.hpp" + +#include "vision-artificial/image/iface.hpp" +#include "vision-artificial/user/iface.hpp" +#include "vision-artificial/proc/common.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ +#define COINS_MAX (0xFFF) + +#define COIN_DIAMETER_2E (25.75) +#define COIN_DIAMETER_50c (24.25) +#define COIN_DIAMETER_1E (23.25) +#define COIN_DIAMETER_20c (22.25) +#define COIN_DIAMETER_5c (21.25) +#define COIN_DIAMETER_10c (19.75) +#define COIN_DIAMETER_2c (18.75) +#define COIN_DIAMETER_1c (16.25) + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ +struct Coins_Properties { + ptrdiff_t x; + ptrdiff_t y; + uint8_t diameter_pix; + double diameter_mm; + double value; +}; + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ +/* Static --------------------------------------------------------------------*/ +static class std::vector <class std::vector <class cv::Point_ <int>>> contours; +static class cv::Mat hierarchy; +static class cv::Rect_ <int> rectangle[COINS_MAX]; +static ptrdiff_t coins_n; +static struct Coins_Properties coins[COINS_MAX]; +static double ratio_mm_per_pix; +static double value_total; + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ +static void result_coins (int status); + +static void coins_segmentate (void); +static int coins_positions (void); +static void coins_diameters_pix (void); +static void calibrate_mm_per_pix (void); +static void coins_diameters_mm (void); +static int coins_values (void); +static double coin_value (double diameter_mm); +static void coins_total_value (void); + + +/****************************************************************************** + ******* global functions ***************************************************** + ******************************************************************************/ +int proc_coins (void) +{ + int status; + + proc_save_mem(0); + + /* Segmentate coins */ + clock_start(); + coins_segmentate(); + clock_stop("Segmentate coins"); + + /* Find coins positions */ + clock_start(); + status = coins_positions(); + if (status) { + result_coins(status); + return status; + } + clock_stop("Find coins positions"); + + /* Get coin diameters in pixels */ + clock_start(); + coins_diameters_pix(); + clock_stop("Coins diameters in pixels"); + + /* Calibrate with the biggest coin; every img should have a 2 € coin */ + clock_start(); + calibrate_mm_per_pix(); + clock_stop("Calibrate (mm per pix)"); + + /* Get coins diameters in mm */ + clock_start(); + coins_diameters_mm(); + clock_stop("Coins diameters in mm"); + + /* Get coins values (by their sizes) */ + clock_start(); + status = coins_values(); + if (status) { + result_coins(status); + return status; + } + clock_stop("Coins values"); + + /* Add total value */ + clock_start(); + coins_total_value(); + clock_stop("Total value"); + + result_coins(COINS_OK); + return 0; +} + + +/****************************************************************************** + ******* static functions (definitions) *************************************** + ******************************************************************************/ +static void result_coins (int status) +{ + + switch (status) { + case COINS_OK: + user_iface_log_write(0, "Coin: OK"); + break; + case COINS_NOK_COINS: + user_iface_log_write(0, "Coin: NOK_COINS"); + break; +#if 0 + case COINS_NOK_OVERLAP: + user_iface_log_write(0, "Coin: NOK_OVERLAP"); + break; +#endif + case COINS_NOK_SIZE: + user_iface_log_write(0, "Coin: NOK_SIZE"); + break; + default: + user_iface_log_write(0, "Coin: NOK"); + break; + } +} + +static void coins_segmentate (void) +{ + proc_load_mem(0); + + proc_cmp(IMG_IFACE_CMP_BLUE); + proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU); + proc_distance_transform(); + proc_local_max(); + proc_dilate(6); + proc_save_mem(1); +} + +static int coins_positions (void) +{ + + proc_load_mem(1); + + proc_contours(&contours, &hierarchy); + coins_n = contours.size(); + if (!coins_n) + return COINS_NOK_COINS; + for (ptrdiff_t i = 0; i < coins_n; i++) { + proc_bounding_rect(&contours[i], &rectangle[i], true); + coins[i].x = rectangle[i].x + rectangle[i].width / 2.0; + coins[i].y = rectangle[i].y + rectangle[i].height / 2.0; + } + + return 0; +} + +static void coins_diameters_pix (void) +{ + + proc_load_mem(1); + for (ptrdiff_t i = 0; i < coins_n; i++) { + proc_pixel_get(coins[i].x, coins[i].y, &coins[i].diameter_pix); + coins[i].diameter_pix *= 2; + } +} + +static void calibrate_mm_per_pix (void) +{ + uint8_t coins_size_pix[coins_n]; + int max_pos; + int max_size; + + for (ptrdiff_t i = 0; i < coins_n; i++) + coins_size_pix[i] = coins[i].diameter_pix; + + max_pos = alx_maximum_u8(ARRAY_SIZE(coins_size_pix), coins_size_pix); + max_size = coins_size_pix[max_pos]; + ratio_mm_per_pix = 25.75 / max_size; +} + +static void coins_diameters_mm (void) +{ + char txt[LOG_LINE_LEN]; + + for (ptrdiff_t i = 0; i < coins_n; i++) { + coins[i].diameter_mm = ratio_mm_per_pix * coins[i].diameter_pix; + snprintf(txt, LOG_LINE_LEN, "Coin[%ti]: %.2lf mm", + i, coins[i].diameter_mm); + user_iface_log_write(0, txt); + } +} + +static int coins_values (void) +{ + char txt[LOG_LINE_LEN]; + + for (ptrdiff_t i = 0; i < coins_n; i++) { + coins[i].value = coin_value(coins[i].diameter_mm); + if (coins[i].value < 0) + return COINS_NOK_SIZE; + snprintf(txt, LOG_LINE_LEN, "Coin[%ti]: %.2lf EUR", + i, coins[i].value); + user_iface_log_write(0, txt); + } + + return 0; +} + +static double coin_value (double diameter_mm) +{ + + if (diameter_mm > (COIN_DIAMETER_2E + 1.5)) + return -1; + if (diameter_mm > AVGfast(COIN_DIAMETER_2E, COIN_DIAMETER_50c,double_t)) + return 2.00; + if (diameter_mm > AVGfast(COIN_DIAMETER_50c, COIN_DIAMETER_1E,double_t)) + return 0.50; + if (diameter_mm > AVGfast(COIN_DIAMETER_1E, COIN_DIAMETER_20c,double_t)) + return 1.00; + if (diameter_mm > AVGfast(COIN_DIAMETER_20c, COIN_DIAMETER_5c,double_t)) + return 0.20; + if (diameter_mm > AVGfast(COIN_DIAMETER_5c, COIN_DIAMETER_10c,double_t)) + return 0.05; + if (diameter_mm > AVGfast(COIN_DIAMETER_10c, COIN_DIAMETER_2c,double_t)) + return 0.10; + if (diameter_mm > AVGfast(COIN_DIAMETER_2c, COIN_DIAMETER_1c, double_t)) + return 0.02; + if (diameter_mm > (COIN_DIAMETER_1c - 1.5)) + return 0.01; + return -1; +} + +static void coins_total_value (void) +{ + char txt[LOG_LINE_LEN]; + + value_total = 0.00; + for (ptrdiff_t i = 0; i < coins_n; i++) + value_total += coins[i].value; + + snprintf(txt, LOG_LINE_LEN, "Total value: %.2lf EUR",value_total); + user_iface_log_write(0, txt); +} + + +/****************************************************************************** + ******* end of file ********************************************************** + ******************************************************************************/ diff --git a/modules/proc/src/proc_common.cpp b/src/proc/common.cpp index d76e47f..82cb6eb 100644 --- a/modules/proc/src/proc_common.cpp +++ b/src/proc/common.cpp @@ -7,34 +7,47 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <cstddef> - #include <cstdio> - #include <ctime> -/* Packages ------------------------------------------------------------------*/ - #include <opencv2/opencv.hpp> - #include <zbar.h> -/* Project -------------------------------------------------------------------*/ - #include "img_iface.hpp" - #include "user_iface.hpp" -/* Module --------------------------------------------------------------------*/ - #include "proc_iface.hpp" - - #include "proc_common.hpp" +#include "vision-artificial/proc/common.hpp" + +#include <cstddef> +#include <cstdio> +#include <ctime> + +#include <opencv2/opencv.hpp> + +#include "libalx/base/stdio/wait.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 ***************************************************** + ******* static functions (prototypes) **************************************** ******************************************************************************/ @@ -43,17 +56,15 @@ static clock_t clock_1; ******************************************************************************/ void proc_apply (void) { - img_iface_act(IMG_IFACE_ACT_APPLY, NULL); } -void proc_save_mem (int n) +void proc_save_mem (ptrdiff_t n) { - img_iface_act(IMG_IFACE_ACT_SAVE_MEM, (const void *)&n); } -void proc_load_mem (int n) +void proc_load_mem (ptrdiff_t n) { img_iface_act(IMG_IFACE_ACT_LOAD_MEM, (const void *)&n); @@ -63,19 +74,16 @@ void proc_load_mem (int n) void proc_save_ref (void) { - img_iface_act(IMG_IFACE_ACT_SAVE_REF, NULL); } void proc_save_file (void) { - img_iface_act(IMG_IFACE_ACT_SAVE_FILE, NULL); } void proc_save_update (void) { - img_iface_act(IMG_IFACE_ACT_SAVE_UPDT, NULL); } @@ -83,7 +91,6 @@ void proc_local_max (void) { img_iface_act(IMG_IFACE_ACT_LOCAL_MAX, NULL); - proc_show_img(); } @@ -91,14 +98,13 @@ void proc_skeleton (void) { img_iface_act(IMG_IFACE_ACT_SKELETON, NULL); - proc_show_img(); } void proc_lines_vertical (void) { - img_iface_act(IMG_IFACE_ACT_LINES_VERTICAL, NULL); + img_iface_act(IMG_IFACE_ACT_LINES_VERTICAL, NULL); proc_show_img(); } @@ -106,7 +112,6 @@ void proc_median_horizontal (void) { img_iface_act(IMG_IFACE_ACT_MEDIAN_HORIZONTAL, NULL); - proc_show_img(); } @@ -114,27 +119,31 @@ void proc_median_vertical (void) { img_iface_act(IMG_IFACE_ACT_MEDIAN_VERTICAL, NULL); - proc_show_img(); } -void proc_pixel_get (int x, int y, unsigned char *val) +void proc_pixel_get (ptrdiff_t x, ptrdiff_t y, unsigned char *val) { struct Img_Iface_Data_Pixel_Get data; - data.x = x; - data.y = y; - data.val = val; + + data = (struct Img_Iface_Data_Pixel_Get){ + .val = val, + .x = x, + .y = y, + }; img_iface_act(IMG_IFACE_ACT_PIXEL_GET, (const void *)&data); } -void proc_pixel_set (int x, int y, unsigned char val) +void proc_pixel_set (ptrdiff_t x, ptrdiff_t y, unsigned char val) { struct Img_Iface_Data_Pixel_Set data; - data.x = x; - data.y = y; - data.val = val; - img_iface_act(IMG_IFACE_ACT_PIXEL_SET, (const void *)&data); + data = (struct Img_Iface_Data_Pixel_Set){ + .val = val, + .x = x, + .y = y, + }; + img_iface_act(IMG_IFACE_ACT_PIXEL_SET, (const void *)&data); proc_show_img(); } @@ -142,12 +151,15 @@ void proc_ROI (int x, int y, int w, int h) { struct Img_Iface_Data_SetROI data; - data.rect.x = x; - data.rect.y = y; - data.rect.width = w; - data.rect.height = h; + data = (struct Img_Iface_Data_SetROI){ + .rect = { + .x = x, + .y = y, + .width = w, + .height = h, + }, + }; img_iface_act(IMG_IFACE_ACT_SET_ROI, (const void *)&data); - proc_show_img(); } @@ -155,7 +167,6 @@ void proc_and_2ref (void) { img_iface_act(USER_IFACE_ACT_AND_2REF, NULL); - proc_show_img(); } @@ -163,7 +174,6 @@ void proc_not (void) { img_iface_act(USER_IFACE_ACT_NOT, NULL); - proc_show_img(); } @@ -171,7 +181,6 @@ void proc_or_2ref (void) { img_iface_act(USER_IFACE_ACT_OR_2REF, NULL); - proc_show_img(); } @@ -179,9 +188,10 @@ void proc_cmp (int cmp) { struct Img_Iface_Data_Component data; - data.cmp = cmp; + data = (struct Img_Iface_Data_Component){ + .cmp = cmp, + }; img_iface_act(IMG_IFACE_ACT_COMPONENT, (const void *)&data); - proc_show_img(); } @@ -189,9 +199,10 @@ void proc_dilate (int size) { struct Img_Iface_Data_Dilate_Erode data; - data.i = size; + data = (struct Img_Iface_Data_Dilate_Erode){ + .i = size, + }; img_iface_act(IMG_IFACE_ACT_DILATE, (const void *)&data); - proc_show_img(); } @@ -199,9 +210,10 @@ void proc_erode (int size) { struct Img_Iface_Data_Dilate_Erode data; - data.i = size; + data = (struct Img_Iface_Data_Dilate_Erode){ + .i = size, + }; img_iface_act(IMG_IFACE_ACT_ERODE, (const void *)&data); - proc_show_img(); } @@ -209,9 +221,10 @@ void proc_dilate_erode (int size) { struct Img_Iface_Data_Dilate_Erode data; - data.i = size; + data = (struct Img_Iface_Data_Dilate_Erode){ + .i = size, + }; img_iface_act(IMG_IFACE_ACT_DILATE_ERODE, (const void *)&data); - proc_show_img(); } @@ -219,9 +232,10 @@ void proc_erode_dilate (int size) { struct Img_Iface_Data_Dilate_Erode data; - data.i = size; + data = (struct Img_Iface_Data_Dilate_Erode){ + .i = size, + }; img_iface_act(IMG_IFACE_ACT_ERODE_DILATE, (const void *)&data); - proc_show_img(); } @@ -229,10 +243,11 @@ void proc_smooth (int method, int ksize) { struct Img_Iface_Data_Smooth data; - data.method = method; - data.ksize = ksize; + data = (struct Img_Iface_Data_Smooth){ + .method = method, + .ksize = ksize, + }; img_iface_act(IMG_IFACE_ACT_SMOOTH, (const void *)&data); - proc_show_img(); } @@ -240,21 +255,25 @@ void proc_border (int size) { struct Img_Iface_Data_Border data; - data.size = size; + data = (struct Img_Iface_Data_Border){ + .size = size, + }; img_iface_act(IMG_IFACE_ACT_BORDER, (const void *)&data); - proc_show_img(); } -void proc_rotate (double center_x, double center_y, double angle) +void proc_rotate (float center_x, float center_y, double angle) { struct Img_Iface_Data_Rotate data; - data.center.x = center_x; - data.center.y = center_y; - data.angle = angle; + data = (struct Img_Iface_Data_Rotate){ + .center = { + .x = center_x, + .y = center_y, + }, + .angle = angle, + }; img_iface_act(IMG_IFACE_ACT_ROTATE, (const void *)&data); - proc_show_img(); } @@ -262,11 +281,12 @@ void proc_adaptive_threshold (int method, int type, int ksize) { struct Img_Iface_Data_Adaptive_Thr data; - data.method = method; - data.thr_typ = type; - data.ksize = ksize; + data = (struct Img_Iface_Data_Adaptive_Thr){ + .method = method, + .thr_typ = type, + .ksize = ksize, + }; img_iface_act(USER_IFACE_ACT_ADAPTIVE_THRESHOLD, (void *)&data); - proc_show_img(); } @@ -274,9 +294,10 @@ void proc_cvt_color (int method) { struct Img_Iface_Data_Cvt_Color data; - data.method = method; + data = (struct Img_Iface_Data_Cvt_Color){ + .method = method, + }; img_iface_act(IMG_IFACE_ACT_CVT_COLOR, (const void *)&data); - proc_show_img(); } @@ -284,10 +305,11 @@ void proc_threshold (int type, int size) { struct Img_Iface_Data_Threshold data; - data.thr_typ = type; - data.thr_val = size; + data = (struct Img_Iface_Data_Threshold){ + .thr_typ = type, + .thr_val = size, + }; img_iface_act(IMG_IFACE_ACT_THRESHOLD, (const void *)&data); - proc_show_img(); } @@ -295,55 +317,53 @@ void proc_distance_transform (void) { img_iface_act(IMG_IFACE_ACT_DISTANCE_TRANSFORM, NULL); - proc_show_img(); } -void proc_contours ( - class std::vector <class std::vector <class cv::Point_ <int>>> *contours, - class cv::Mat *hierarchy -) +void proc_contours( + class std::vector <class std::vector <class cv::Point_<int>>> *contours, + class cv::Mat *hierarchy) { struct Img_Iface_Data_Contours data; - data.contours = contours; - data.hierarchy = hierarchy; - + data = (struct Img_Iface_Data_Contours){ + .contours = contours, + .hierarchy = 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 -) +void proc_contours_size( + const class std::vector <class std::vector <class cv::Point_ <int>>> *contours, + double *area, + double *perimeter) { struct Img_Iface_Data_Contours_Size data; - data.contours = contours; - data.area = area; - data.perimeter = perimeter; + data = (struct Img_Iface_Data_Contours_Size){ + .contours = contours, + .area = area, + .perimeter = perimeter, + }; img_iface_act(IMG_IFACE_ACT_CONTOURS_SIZE, (const void *)&data); } -void proc_bounding_rect ( +void proc_bounding_rect( const class std::vector <class cv::Point_ <int>> *contour, class cv::Rect_ <int> *rect, - bool show -) + bool show) { struct Img_Iface_Data_Bounding_Rect data; - data.contour = contour; - data.rect = rect; - data.show = show; + data = (struct Img_Iface_Data_Bounding_Rect){ + .contour = contour, + .rect = rect, + .show = show, + }; img_iface_act(IMG_IFACE_ACT_BOUNDING_RECT, (const void *)&data); - - if (show) { + if (show) proc_show_img(); - } } void proc_fit_ellipse ( @@ -354,15 +374,14 @@ void proc_fit_ellipse ( { struct Img_Iface_Data_MinARect data; - data.contour = contour; - data.rect = rect; - data.show = show; + data = (struct Img_Iface_Data_MinARect){ + .contour = contour, + .rect = rect, + .show = show, + }; img_iface_act(IMG_IFACE_ACT_FIT_ELLIPSE, (const void *)&data); - - - if (show) { + if (show) proc_show_img(); - } } void proc_min_area_rect ( @@ -373,22 +392,22 @@ void proc_min_area_rect ( { struct Img_Iface_Data_MinARect data; - data.contour = contour; - data.rect = rect; - data.show = show; + data = (struct Img_Iface_Data_MinARect){ + .contour = contour, + .rect = rect, + .show = show, + }; img_iface_act(IMG_IFACE_ACT_MIN_AREA_RECT, (const void *)&data); - - if (show) { + 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 */ + 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); } @@ -396,25 +415,24 @@ void proc_zbar (int type) { struct Img_Iface_Data_Decode data; - data.code_type = (enum zbar::zbar_symbol_type_e)type; + 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) { - img_iface_show_img(); - - if (proc_debug >= PROC_DBG_STOP_STEP) { - getchar(); - } - } + 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(); } @@ -422,20 +440,22 @@ 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; - /* Write time_diff into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Time: %.3lf (%s)", - time_diff, txt); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; + 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/modules/proc/src/proc_iface.c b/src/proc/iface.c index f14ba1d..9790e1c 100644 --- a/modules/proc/src/proc_iface.c +++ b/src/proc/iface.c @@ -7,27 +7,43 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <errno.h> - #include <stdbool.h> - #include <stdio.h> - #include <stdlib.h> - #include <time.h> -/* libalx -------------------------------------------------------------------*/ - #include "libalx/io/alx_input.h" -/* Project -------------------------------------------------------------------*/ - #include "img_iface.h" - #include "user_iface.h" - #include "save.h" -/* Module --------------------------------------------------------------------*/ - #include "proc_label.h" - #include "proc_lighters.h" - #include "proc_objects.h" - #include "proc_coins.h" - #include "proc_resistor.h" - #include "proc_common.h" - - #include "proc_iface.h" +#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/stddef/size.h" +#include "libalx/base/stdio/sscan.h" +#include "libalx/base/stdio/wait.h" + +#include "vision-artificial/image/iface.h" +#include "vision-artificial/proc/coins.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 ***************************************************** + ******************************************************************************/ /****************************************************************************** @@ -36,14 +52,13 @@ /* Global --------------------------------------------------------------------*/ int proc_debug; int proc_mode; - /* Static --------------------------------------------------------------------*/ static char proc_path [FILENAME_MAX]; static char proc_fail_path [FILENAME_MAX]; /****************************************************************************** - ******* static functions ***************************************************** + ******* static functions (prototypes) **************************************** ******************************************************************************/ @@ -56,11 +71,10 @@ int proc_iface_single (int action) clock_t time_0; clock_t time_1; double time_tot; + char txt[LOG_LINE_LEN]; - /* Init timer */ time_0 = clock(); - /* Process */ switch (action) { case PROC_MODE_LABEL_SERIES: error = proc_label(); @@ -84,34 +98,25 @@ int proc_iface_single (int action) error = -1; } - /* End timer */ - time_1 = clock(); - - /* Calculate time in seconds */ + time_1 = clock(); time_tot = ((double) time_1 - time_0) / CLOCKS_PER_SEC; - - /* Write time into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Item total time: %.3lf", - time_tot); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; + snprintf(txt, LOG_LINE_LEN, "Item total time: %.3lf", time_tot); + user_iface_log_write(0, txt); return error; } void proc_iface_series (void) { - bool file_error; int num_len; - char file_basename [FILENAME_MAX]; - char file_ext [FILENAME_MAX]; - char file_name [FILENAME_MAX]; - char save_error_as [FILENAME_MAX]; - bool wh; - /* if i starts being 0, the camera needs calibration */ + 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_tmp [FILENAME_MAX]; + char txt[LOG_LINE_LEN]; + char tmp[FILENAME_MAX]; switch (proc_mode) { case PROC_MODE_LABEL_SERIES: @@ -141,7 +146,7 @@ void proc_iface_series (void) 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(proc_fail_path, FILENAME_MAX,"%s",resistors_fail_path); snprintf(file_basename, FILENAME_MAX, "r"); num_len = 4; snprintf(file_ext, FILENAME_MAX, ".png"); @@ -149,7 +154,7 @@ void proc_iface_series (void) 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(proc_fail_path, FILENAME_MAX, "%s",lighters_fail_path); snprintf(file_basename, FILENAME_MAX, "lighters"); num_len = 4; snprintf(file_ext, FILENAME_MAX, ".png"); @@ -159,50 +164,43 @@ void proc_iface_series (void) return; } - wh = true; - for (; wh; i++) { + for (;; i++) { if (snprintf(file_name, FILENAME_MAX, "%s%04i%s", file_basename, i, file_ext) >= FILENAME_MAX) { goto err_path; } - file_error = alx_sscan_fname(proc_path, file_name, - true, file_name); + memcpy(tmp, file_name, ARRAY_SIZE(file_name)); + if (alx_sscan_fname(proc_path, file_name, true, tmp)) + break; - if (file_error) { - wh = false; - } else { - errno = 0; - img_iface_load(proc_path, file_name); + errno = 0; + img_iface_load(proc_path, file_name); - if (errno) { - printf("errno:%i\n", errno); - goto err_load; - } + 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, + /* 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); + goto err_path; } + save_image_file(proc_fail_path, save_error_as); + } - /* Show log */ - snprintf(txt_tmp, FILENAME_MAX, "%04i", i); - user_iface_show_log(txt_tmp, "Item"); + /* Show log */ + snprintf(txt, LOG_LINE_LEN, "%04i", i); + user_iface_show_log(txt, "Item"); - if (proc_debug >= PROC_DBG_STOP_ITEM) - getchar(); - } + if (proc_debug >= PROC_DBG_STOP_ITEM) + alx_wait4enter(); err_load: if (!i) proc_mode--; @@ -210,7 +208,6 @@ err_load: return; - err_path: printf("Path is too large and has been truncated\n"); exit(EXIT_FAILURE); @@ -218,7 +215,7 @@ err_path: /****************************************************************************** - ******* static functions ***************************************************** + ******* static functions (definitions) *************************************** ******************************************************************************/ diff --git a/src/proc/label.cpp b/src/proc/label.cpp new file mode 100644 index 0000000..5b5a3c7 --- /dev/null +++ b/src/proc/label.cpp @@ -0,0 +1,295 @@ +/****************************************************************************** + * 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/opencv.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/modules/proc/src/proc_lighters.cpp b/src/proc/lighters.cpp index 7242638..6eb9441 100644 --- a/modules/proc/src/proc_lighters.cpp +++ b/src/proc/lighters.cpp @@ -7,20 +7,18 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <cstddef> - #include <cstdio> -/* Packages ------------------------------------------------------------------*/ - #include <opencv2/opencv.hpp> -/* libalx ------------------------------------------------------------------*/ - #include "libalx/alx_math.hpp" -/* Project -------------------------------------------------------------------*/ - #include "img_iface.hpp" - #include "user_iface.hpp" -/* Module --------------------------------------------------------------------*/ - #include "proc_common.hpp" - - #include "proc_lighters.hpp" +#include "vision-artificial/proc/lighters.hpp" + +#include <cstddef> +#include <cstdio> + +#include <opencv2/opencv.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" /****************************************************************************** @@ -39,7 +37,7 @@ enum Lighter_Hood { /****************************************************************************** - ******* structs ************************************************************** + ******* structs / unions ***************************************************** ******************************************************************************/ struct Point { uint16_t x; @@ -52,7 +50,6 @@ struct Size { }; struct Lighter_Properties { - /* position */ struct Point pos; struct Size size; double angle; @@ -71,19 +68,18 @@ struct Lighter_Properties { ******* 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::RotatedRect rect_rot[CONTOURS_MAX]; static class cv::Rect_ <int> rect; -static struct Lighter_Properties lighter [CONTOURS_MAX]; -static unsigned lighters_n; +static struct Lighter_Properties lighter[CONTOURS_MAX]; +static ptrdiff_t lighters_n; /****************************************************************************** - ******* static functions ***************************************************** + ******* static functions (prototypes) **************************************** ******************************************************************************/ static void result_lighter (int status); @@ -106,27 +102,18 @@ static void lighters_log (void); ******************************************************************************/ int proc_lighter (void) { - int status; - int i; proc_save_mem(0); /* Segment lighters */ - { - /* Measure time */ - clock_start(); + clock_start(); + lighters_bgr2gray(); + lighters_segment_full(); + lighters_find(); + clock_stop("Segment lighters"); - lighters_bgr2gray(); - lighters_segment_full(); - lighters_find(); - - /* Measure time */ - clock_stop("Segment lighters"); - } /* Check each lighter */ - for (i = 0; (unsigned)i < lighters_n; i++) { - /* Measure time */ + for (ptrdiff_t i = 0; i < lighters_n; i++) { clock_start(); - lighter[i].ok = true; lighter_segment_body(i); lighter_rm_body(i); @@ -141,55 +128,39 @@ int proc_lighter (void) lighter_chk_fork(i); lighter_chk_wheel(i); lighter_chk_valve(i); - - /* Measure time */ clock_stop("Check parts"); } - /* Print results of lighters into log */ - { - /* Measure time */ - clock_start(); - lighters_log(); - - /* Measure time */ - clock_stop("Lighters properties (log)"); - } + /* Print results of lighters into log */ + clock_start(); + lighters_log(); + clock_stop("Lighters properties (log)"); - status = LIGHTER_OK; - result_lighter(status); - return status; + result_lighter(LIGHTER_OK); + return 0; } /****************************************************************************** - ******* static functions ***************************************************** + ******* static functions (definitions) *************************************** ******************************************************************************/ static void result_lighter (int status) { - /* Write result into log */ switch (status) { case LIGHTER_OK: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: OK"); + user_iface_log_write(0, "Coin: OK"); break; case LIGHTER_NOK_LIGHTER: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK_LIGHTER"); + user_iface_log_write(0, "Coin: NOK_LIGHTER"); break; case LIGHTER_NOK_SIZE: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK_SIZE"); + user_iface_log_write(0, "Coin: NOK_SIZE"); break; default: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK"); - break; + user_iface_log_write(0, "Coin: NOK"); } - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; } /* process -------------------------------------------------------------------*/ @@ -222,31 +193,22 @@ static void lighters_segment_full (void) static int lighters_find (void) { - int status; - int i; - int tmp; proc_load_mem(4); proc_contours(&contours_all, &hierarchy); lighters_n = contours_all.size(); + if (!lighters_n) + return LIGHTER_NOK_LIGHTER; - /* If no contour is found, error: NOK_RESISTOR */ - if (!lighters_n) { - status = LIGHTER_NOK_LIGHTER; - return status; - } - - for (i = 0; (unsigned)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 */ + 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; - tmp = rect_rot[i].size.width; - rect_rot[i].size.width = rect_rot[i].size.height; - rect_rot[i].size.height = tmp; + 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; @@ -254,16 +216,13 @@ static int lighters_find (void) lighter[i].size.w = rect_rot[i].size.width; } - status = LIGHTER_OK; - return status; + return 0; } static void lighter_segment_body (int i) { - int x; - int y; - int w; - int h; + int x, y; + int w, h; proc_load_mem(2); @@ -273,7 +232,7 @@ static void lighter_segment_body (int i) 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, 255 - 165); + proc_threshold(cv::THRESH_BINARY, UINT8_MAX - 165); proc_erode_dilate(1); proc_dilate_erode(1); @@ -281,15 +240,13 @@ static void lighter_segment_body (int i) proc_save_mem(5); proc_contours(&contours_one, &hierarchy); - proc_bounding_rect(&(contours_one[0]), &rect, true); + proc_bounding_rect(&contours_one[0], &rect, true); } static void lighter_rm_body (int i) { - int x; - int y; - int w; - int h; + int x, y; + int w, h; proc_load_mem(5); proc_not(); @@ -310,13 +267,11 @@ static void lighter_rm_body (int i) static void lighter_crop_head (int i) { - int x; - int y; - int w; - int h; + 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; @@ -342,8 +297,8 @@ static void lighter_chk_hood (int i) 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); + 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; @@ -418,11 +373,10 @@ static void lighter_chk_valve (int i) proc_load_mem(8); - if (lighter[i].hood_ == HOOD_NOT_PRESENT) { + if (lighter[i].hood_ == HOOD_NOT_PRESENT) proc_dilate(5); - } else { + 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); @@ -437,65 +391,32 @@ static void lighter_chk_valve (int i) static void lighters_log (void) { - int i; - - for (i = 0; (unsigned)i < lighters_n; i++) { - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Lighter[%i]:", - i); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " pos: (%i, %i) pix", - lighter[i].pos.x, - lighter[i].pos.y); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " ang = %.1lf DEG", - lighter[i].angle); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " hood = %s", - lighter[i].hood ? "ok" : "nok"); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " fork = %s", - lighter[i].fork ? "ok" : "nok"); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " wheel = %s", - lighter[i].wheel ? "ok" : "nok"); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " valve = %s", - lighter[i].valve ? "ok" : "nok"); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " RESULT = %s", - lighter[i].ok ? "OK" : "NOK"); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; + 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); } } diff --git a/modules/proc/src/proc_objects.cpp b/src/proc/objects.cpp index db5d5e3..dd00820 100644 --- a/modules/proc/src/proc_objects.cpp +++ b/src/proc/objects.cpp @@ -7,32 +7,36 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <cstdio> -/* Packages ------------------------------------------------------------------*/ - #include <opencv2/opencv.hpp> -/* libalx ------------------------------------------------------------------*/ - #include "libalx/alx_math.hpp" -/* Project -------------------------------------------------------------------*/ - #include "img_iface.hpp" - #include "user_iface.hpp" -/* Module --------------------------------------------------------------------*/ - #include "proc_common.hpp" +#include "vision-artificial/proc/objects.hpp" - #include "proc_objects.hpp" +#include <cstddef> +#include <cstdio> + +#include <opencv2/opencv.hpp> + +#include "libalx/base/math/median.hpp" + +#include "vision-artificial/image/iface.hpp" +#include "vision-artificial/proc/common.hpp" +#include "vision-artificial/user/iface.hpp" /****************************************************************************** ******* macros *************************************************************** ******************************************************************************/ - # define OBJECTS_MAX (1024) - # define PATTERN_SQUARE_LEN_MM (10.0) +#define OBJECTS_MAX (0xFFF) +#define PATTERN_SQUARE_LEN_MM (10.0) + +#define PATTERN_DILATE (2) - # define PATTERN_DILATE (2) + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ /****************************************************************************** - ******* structs ************************************************************** + ******* structs / unions ***************************************************** ******************************************************************************/ struct Point { uint16_t x_pix; @@ -44,42 +48,32 @@ struct Point { struct Pattern_Square { struct Point pos; - uint8_t len; }; struct Pattern_Properties { - /* center */ struct Point center; struct Point origin; - /* Angle */ double angle; - /* Size */ uint16_t height; uint16_t width; /* Squares (distance calibration) */ - struct Pattern_Square square [OBJECTS_MAX]; + struct Pattern_Square square[OBJECTS_MAX]; }; struct Objects_Properties { - /* position */ struct Point pos; - /* Angle */ double angle; - /* Area */ double area_pix2; double area_mm2; - - /* Perimeter */ double perimeter_pix; double perimeter_mm; - /* type */ double ratio_p2_a; double area_rect; double ratio_a_arect; @@ -92,21 +86,20 @@ struct Objects_Properties { ******* variables ************************************************************ ******************************************************************************/ /* Global --------------------------------------------------------------------*/ - /* Static --------------------------------------------------------------------*/ static class std::vector <class std::vector <class cv::Point_ <int>>> contours; -static class cv::Mat hierarchy; -static class cv::RotatedRect rect_rot [OBJECTS_MAX]; -static class cv::Rect_ <int> rect [OBJECTS_MAX]; -static struct Pattern_Properties pattern; -static int squares_n; -static double ratio_mm_pix; -static int objects_n; -static struct Objects_Properties objects [OBJECTS_MAX]; +static 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 ***************************************************** + ******* static functions (prototypes) **************************************** ******************************************************************************/ static void result_objects (int status); @@ -143,50 +136,33 @@ int proc_objects_calibrate (void) proc_save_mem(0); /* Calibrate angle with the whole pattern */ - { - /* Measure time */ - clock_start(); - - pattern_bgr2gray(); - status = pattern_find(); - if (status) { - result_objects(status); - return status; - } - pattern_rotation_get(); - pattern_rotation_fix(); - - /* Measure time */ - clock_stop("Calibrate: rotation"); + clock_start(); + pattern_bgr2gray(); + status = pattern_find(); + if (status) { + result_objects(status); + return status; } - /* Segmentate pattern squares */ - { - /* Measure time */ - clock_start(); + pattern_rotation_get(); + pattern_rotation_fix(); + clock_stop("Calibrate: rotation"); - pattern_dimensions_get(); - pattern_dimensions_fix(); + /* Segmentate pattern squares */ + clock_start(); + pattern_dimensions_get(); + pattern_dimensions_fix(); + clock_stop("Calibrate: dimensions"); - /* Measure time */ - clock_stop("Calibrate: dimensions"); - } /* Find squares */ - { - /* Measure time */ - clock_start(); - - pattern_squares_find(); - pattern_squares_pos_get(); - pattern_squares_len_get(); - pattern_calib_mm_pix(); - - /* Measure time */ - clock_stop("Calibrate (mm per pix)"); - } - - status = OBJECTS_OK; - result_objects(status); - return status; + 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) @@ -195,122 +171,79 @@ int proc_objects (void) proc_save_mem(0); /* Align image */ - { - /* Measure time */ - clock_start(); + clock_start(); + objects_bgr2gray(); + objects_rotation_fix(); + objects_dimensions_fix(); + clock_stop("Align image to pattern"); - objects_bgr2gray(); - objects_rotation_fix(); - objects_dimensions_fix(); - - /* Measure time */ - clock_stop("Align image to pattern"); - } /* Segment objects */ - { - /* Measure time */ - clock_start(); + clock_start(); + objects_segment(); + clock_stop("Segment objects"); - objects_segment(); - - /* Measure time */ - clock_stop("Segment objects"); - } /* Find objects positions */ - { - /* Measure time */ - clock_start(); - - status = objects_contours(); - if (status) { - result_objects(status); - return status; - } - - /* Measure time */ - clock_stop("Find objects"); + clock_start(); + status = objects_contours(); + if (status) { + result_objects(status); + return status; } - /* Get objects properties in pixels */ - { - /* Measure time */ - clock_start(); + clock_stop("Find objects"); - objects_position_pix(); - objects_position_mm(); + /* Get objects properties in pixels */ + clock_start(); + objects_position_pix(); + objects_position_mm(); + clock_stop("Objects positions"); - /* Measure time */ - clock_stop("Objects positions"); - } /* Get objects properties in mm */ - { - /* Measure time */ - clock_start(); + clock_start(); + objects_size_pix(); + objects_size_mm(); + clock_stop("Objects sizes"); - objects_size_pix(); - objects_size_mm(); - - /* Measure time */ - clock_stop("Objects sizes"); - } /* Get objects properties in mm */ - { - /* Measure time */ - clock_start(); + clock_start(); + objects_shape(); + clock_stop("Objects shapes"); - objects_shape(); - - /* Measure time */ - clock_stop("Objects shapes"); - } /* Print properties of objects into log */ - { - /* Measure time */ - clock_start(); + clock_start(); + objects_log(); + clock_stop("Objects properties (log)"); - objects_log(); - - /* Measure time */ - clock_stop("Objects properties (log)"); - } - - status = OBJECTS_OK; - result_objects(status); - return status; + result_objects(OBJECTS_OK); + return 0; } /****************************************************************************** - ******* static functions ***************************************************** + ******* static functions (definitions) *************************************** ******************************************************************************/ static void result_objects (int status) { - /* Write result into log */ + switch (status) { case OBJECTS_OK: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: OK"); + user_iface_log_write(0, "Coin: OK"); break; case OBJECTS_NOK_OBJECTS: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK_OBJECTS"); + user_iface_log_write(0, "Coin: NOK_OBJECTS"); break; case OBJECTS_NOK_SIZE: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK_SIZE"); + user_iface_log_write(0, "Coin: NOK_SIZE"); break; default: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Coin: NOK"); - break; + user_iface_log_write(0, "Coin: NOK"); } - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; } /* calibration ---------------------------------------------------------------*/ static void pattern_bgr2gray (void) { + proc_load_mem(0); proc_cvt_color(cv::COLOR_BGR2GRAY); @@ -319,7 +252,6 @@ static void pattern_bgr2gray (void) static int pattern_find (void) { - int status; proc_load_mem(1); @@ -327,49 +259,39 @@ static int pattern_find (void) proc_erode_dilate(16); proc_dilate(2); proc_contours(&contours, &hierarchy); + if (contours.size() != 1) + return OBJECTS_NOK_PATTERN; - /* If no contour is found, error: NOK_PATTERN */ - if (contours.size() != 1) { - status = OBJECTS_NOK_PATTERN; - return status; - } - - status = OBJECTS_OK; - return status; + 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) { + if (rect_rot[0].angle < -45.0) rect_rot[0].angle += 90.0; - } pattern.angle = rect_rot[0].angle; pattern.center.x_pix = rect_rot[0].center.x; pattern.center.y_pix = rect_rot[0].center.y; - /* Write pattern properties into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "pattern angle = %lf DEG", - -pattern.angle); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "pattern center (x) = %i pix", - pattern.center.x_pix); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "pattern center (y) = %i pix", - pattern.center.y_pix); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; + 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 */ @@ -381,6 +303,7 @@ static void pattern_rotation_fix (void) static void pattern_dimensions_get (void) { + proc_load_mem(2); proc_erode_dilate(16); @@ -391,6 +314,7 @@ static void pattern_dimensions_get (void) 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; @@ -398,7 +322,6 @@ static void pattern_dimensions_fix (void) 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); @@ -406,6 +329,7 @@ static void pattern_dimensions_fix (void) static void pattern_squares_find (void) { + proc_load_mem(3); proc_distance_transform(); @@ -419,12 +343,9 @@ static void pattern_squares_find (void) static void pattern_squares_pos_get (void) { - int i; - /* Get position of each contour */ - for (i = 0; i < squares_n; i++) { + 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; } @@ -432,43 +353,35 @@ static void pattern_squares_pos_get (void) static void pattern_squares_len_get (void) { - int i; proc_load_mem(4); - - /* Get pattern square side lenght in pixels */ - for (i = 0; i < squares_n; i++) { + 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; + pattern.square[i].pos.y_pix, + &(pattern.square[i].len)); + pattern.square[i].len *= 2; } } static void pattern_calib_mm_pix (void) { - int i; - uint8_t pattern_len [OBJECTS_MAX]; + uint8_t pattern_len[OBJECTS_MAX]; uint8_t median_size; + char txt[LOG_LINE_LEN]; - for (i = 0; i < squares_n; i++) { + for (ptrdiff_t i = 0; i < squares_n; i++) pattern_len[i] = pattern.square[i].len; - } - median_size = alx_median_u8(squares_n, pattern_len); ratio_mm_pix = PATTERN_SQUARE_LEN_MM / median_size; - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "mm/pix = %lf", - ratio_mm_pix); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; + 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); @@ -477,6 +390,7 @@ static void objects_bgr2gray (void) static void objects_rotation_fix (void) { + proc_load_mem(1); /* invert image before rotation to avoid black bands */ @@ -487,6 +401,7 @@ static void objects_rotation_fix (void) static void objects_dimensions_fix (void) { + /* Need to correct also pattern dilatation (pattern_dimensions_get()) */ proc_load_mem(2); @@ -498,6 +413,7 @@ static void objects_dimensions_fix (void) static void objects_segment (void) { + proc_load_mem(3); proc_dilate_erode(3); @@ -521,47 +437,34 @@ static void objects_segment (void) static int objects_contours (void) { - int status; proc_load_mem(6); proc_contours(&contours, &hierarchy); objects_n = contours.size(); + if (!objects_n) + return OBJECTS_NOK_OBJECTS; - /* If no contour is found, error: NOK_OBJECTS */ - if (!objects_n) { - status = OBJECTS_NOK_OBJECTS; - return status; - } - - status = OBJECTS_OK; - return status; + return 0; } static void objects_position_pix (void) { - int i; - /* Get position of each contour */ - for (i = 0; i < objects_n; i++) { + 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) { + if (objects[i].angle < 0) objects[i].angle += 180.0; - } } } static void objects_position_mm (void) { - int i; - /* Get position of each contour */ - for (i = 0; i < objects_n; i++) { + 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; } @@ -569,13 +472,11 @@ static void objects_position_mm (void) static void objects_size_pix (void) { - double area [OBJECTS_MAX]; - double perimeter [OBJECTS_MAX]; - int i; + double area[OBJECTS_MAX]; + double perimeter[OBJECTS_MAX]; - /* Get size of each contour */ proc_contours_size(&contours, area, perimeter); - for (i = 0; i < objects_n; i++) { + for (ptrdiff_t i = 0; i < objects_n; i++) { objects[i].area_pix2 = area[i]; objects[i].perimeter_pix = perimeter[i]; } @@ -583,10 +484,8 @@ static void objects_size_pix (void) static void objects_size_mm (void) { - int i; - /* Get position of each contour */ - for (i = 0; i < objects_n; i++) { + 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 * @@ -596,90 +495,52 @@ static void objects_size_mm (void) static void objects_shape (void) { - int i; - /* Get shape of each contour */ - for (i = 0; i < objects_n; i++) { + 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 * + 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 + + 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].ratio_p_prect = objects[i].perimeter_pix / objects[i].perimeter_rect; - objects[i].ratio_a_arect = objects[i].area_pix2 / + objects[i].ratio_a_arect = objects[i].area_pix2 / objects[i].area_rect; } } static void objects_log (void) { - int i; - - /* Get coins diameters in mm */ - for (i = 0; i < objects_n; i++) { - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Object[%i]:", - i); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " pos: (%.1lf, %.1lf) mm", - objects[i].pos.x_mm, - objects[i].pos.y_mm); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " ang = %.1lf DEG", - objects[i].angle); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " A = %.1lf mm2", - objects[i].area_mm2); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " P = %.1lf mm", - objects[i].perimeter_mm); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " p2/A = %.2lf", - objects[i].ratio_p2_a); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " p/p_r = %.2lf", - objects[i].ratio_p_prect); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Write diameters into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - " A/A_r = %.2lf", - objects[i].ratio_a_arect); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; + 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); } } diff --git a/modules/proc/src/proc_resistor.cpp b/src/proc/resistor.cpp index 33bb624..5c370e7 100644 --- a/modules/proc/src/proc_resistor.cpp +++ b/src/proc/resistor.cpp @@ -7,29 +7,38 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <cmath> - #include <cstdio> -/* Packages ------------------------------------------------------------------*/ - #include <opencv2/opencv.hpp> -/* Project -------------------------------------------------------------------*/ - #include "img_iface.hpp" - #include "user_iface.hpp" -/* Module --------------------------------------------------------------------*/ - #include "proc_common.hpp" +#include "vision-artificial/proc/resistor.hpp" - #include "proc_resistor.hpp" +#include <cmath> +#include <cstdio> +#include <cstring> + +#include <opencv2/opencv.hpp> + +#include "libalx/base/stddef/size.hpp" + +#include "vision-artificial/image/iface.hpp" +#include "vision-artificial/proc/common.hpp" +#include "vision-artificial/user/iface.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ /****************************************************************************** - ******* structs ************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** ******************************************************************************/ struct Resistor_Bands { - /* position */ - int x; - int y; + int x; + int y; - /* value */ unsigned char h; unsigned char s; unsigned char v; @@ -40,23 +49,22 @@ struct Resistor_Bands { ******* 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 class std::vector <class std::vector <class cv::Point_ <int>>> contours; +static class cv::Mat hierarchy; +static class cv::RotatedRect rect_rot; +static class cv::Rect_ <int> rect; +static int bkgd; +static int bands_n; +static struct Resistor_Bands bands[5]; +static char code[6]; +static int base; +static float resistance; +static int tolerance; /****************************************************************************** - ******* static functions ***************************************************** + ******* static functions (prototypes) **************************************** ******************************************************************************/ static void result_resistor (int status); @@ -80,6 +88,7 @@ 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); @@ -92,197 +101,124 @@ int proc_resistor (void) proc_save_mem(0); /* Find resistor (position and angle) */ - { - /* Measure time */ - clock_start(); - - status = resistor_find(); - if (status) { - result_resistor(status); - return status; - } - - /* Measure time */ - clock_stop("Find resistor"); + clock_start(); + status = resistor_find(); + if (status) { + result_resistor(status); + return status; } - /* Align resistor, find its dimensions, and crop */ - { - /* Measure time */ - clock_start(); + clock_stop("Find resistor"); - resistor_align(); - resistor_dimensions_0(); - resistor_crop_0(); + /* Align resistor, find its dimensions, and crop */ + clock_start(); + resistor_align(); + resistor_dimensions_0(); + resistor_crop_0(); + clock_stop("Align, dimensions, & crop"); - /* Measure time */ - clock_stop("Align, dimensions, & crop"); - } /* Find backgroung color */ - { - /* Measure time */ - clock_start(); - - resistor_bkgd(); + clock_start(); + resistor_bkgd(); + clock_stop("Background color"); - /* Measure time */ - clock_stop("Background color"); - } /* Crop more */ - { - /* Measure time */ - clock_start(); + clock_start(); + resistor_dimensions_1(); + resistor_crop_1(); + clock_stop("Crop more"); - resistor_dimensions_1(); - resistor_crop_1(); - - /* Measure time */ - clock_stop("Crop more"); - } /* Separate background (BK) and lines (WH) */ - { - /* Measure time */ - clock_start(); + clock_start(); + separate_bkgd_bands_h(); + separate_bkgd_bands_s(); + separate_bkgd_bands_v(); + bkgd_find(); + clock_stop("Separate bkgd from bands"); - separate_bkgd_bands_h(); - separate_bkgd_bands_s(); - separate_bkgd_bands_v(); - bkgd_find(); - - /* Measure time */ - clock_stop("Separate bkgd from bands"); - } /* Find bands: contours -> rectangles */ - { - /* Measure time */ - clock_start(); - - status = bands_find(); - if (status) { - result_resistor(status); - return status; - } - - /* Measure time */ - clock_stop("Find bands"); + clock_start(); + status = bands_find(); + if (status) { + result_resistor(status); + return status; } - /* Read values on the center of each band */ - { - /* Measure time */ - clock_start(); + clock_stop("Find bands"); - bands_colors(); + /* Read values on the center of each band */ + clock_start(); + bands_colors(); + clock_stop("Bands' colors"); - /* Measure time */ - clock_stop("Bands' colors"); - } /* Interpret colors */ - { - /* Measure time */ - clock_start(); - - bands_code(); - bands_code_deduce_0(); - bands_code_deduce_1(); - status = bands_code_deduce_no(); - if (status) { - result_resistor(status); - return status; - } - - /* Measure time */ - clock_stop("Interpret colors"); + clock_start(); + bands_code(); + bands_code_deduce_0(); + bands_code_deduce_1(); + status = bands_code_deduce_no(); + if (status) { + result_resistor(status); + return status; } - /* Calculate resistor value & tolerance */ - { - /* Measure time */ - clock_start(); - - resistor_value(); - status = resistor_tolerance(); - if (status) { - result_resistor(status); - return status; - } + clock_stop("Interpret colors"); - /* Write resistor value into log */ - if (bands_n != 1) { - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistance: %.2E ± %i%% Ohm", - resistance, tolerance); - } else { - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistance: 0 Ohm"); - } - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; - - /* Measure time */ - clock_stop("Calculate resistance & tolerance"); + /* Calculate resistor value & tolerance */ + clock_start(); + resistor_value(); + status = resistor_tolerance(); + if (status) { + result_resistor(status); + return status; } - /* Check STD value */ - { - /* Measure time */ - clock_start(); - - status = chk_std_value(); - if (status) { - result_resistor(status); - return status; - } + log_resistance(); + clock_stop("Calculate resistance & tolerance"); - /* Measure time */ - clock_stop("Chk STD values"); + /* Check STD value */ + clock_start(); + status = chk_std_value(); + if (status) { + result_resistor(status); + return status; } + clock_stop("Chk STD values"); - status = RESISTOR_OK; result_resistor(status); - return status; + return 0; } /****************************************************************************** - ******* static functions ***************************************************** + ******* static functions (definitions) *************************************** ******************************************************************************/ static void result_resistor (int status) { - /* Write result into log */ + switch (status) { case RESISTOR_OK: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistor: OK"); + user_iface_log_write(0, "Resistor: OK"); break; case RESISTOR_NOK_RESISTOR: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistor: NOK_RESISTOR"); + user_iface_log_write(0, "Resistor: NOK_RESISTOR"); break; case RESISTOR_NOK_BANDS: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistor: NOK_BANDS"); + user_iface_log_write(0, "Resistor: NOK_BANDS"); break; case RESISTOR_NOK_COLOR: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistor: NOK_COLOR"); + user_iface_log_write(0, "Resistor: NOK_COLOR"); break; case RESISTOR_NOK_STD_VALUE: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistor: NOK_STD_VALUE"); + user_iface_log_write(0, "Resistor: NOK_STD_VALUE"); break; case RESISTOR_NOK_TOLERANCE: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistor: NOK_TOLERANCE"); + user_iface_log_write(0, "Resistor: NOK_TOLERANCE"); break; default: - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Resistor: NOK"); + user_iface_log_write(0, "Resistor: NOK"); break; } - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; } static int resistor_find (void) { - int status; proc_load_mem(0); @@ -296,26 +232,20 @@ static int resistor_find (void) proc_save_mem(1); proc_dilate_erode(10); proc_contours(&contours, &hierarchy); + if (!contours.size()) + return RESISTOR_NOK_RESISTOR; - /* If no contour is found, error: NOK_RESISTOR */ - if (!contours.size()) { - status = RESISTOR_NOK_RESISTOR; - return status; - } - - proc_min_area_rect(&(contours[0]), &rect_rot, true); - + 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) { + if (rect_rot.angle < -45.0) rect_rot.angle += 90.0; - } - status = RESISTOR_OK; - return status; + 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); @@ -326,6 +256,7 @@ static void resistor_align (void) static void resistor_dimensions_0 (void) { + proc_load_mem(3); proc_dilate_erode(10); @@ -335,10 +266,8 @@ static void resistor_dimensions_0 (void) static void resistor_crop_0 (void) { - int x; - int y; - int w; - int h; + int x, y; + int w, h; proc_load_mem(2); @@ -374,27 +303,24 @@ static void resistor_bkgd (void) bkgd = 0; } else { /* Blue */ - if ((bkgd_hue < 90) || (bkgd_sat < 100)) { - /* Teal blue */ - bkgd = 1; - } else if (bkgd_hue >= 105) { - /* Dark blue */ - bkgd = 2; - } else { - /* Normal blue */ - bkgd = 3; - } + 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); + proc_bounding_rect(&contours[0], &rect, true); } static void resistor_crop_1 (void) @@ -416,6 +342,7 @@ static void resistor_crop_1 (void) static void separate_bkgd_bands_h (void) { + proc_load_mem(4); proc_cmp(IMG_IFACE_CMP_HUE); @@ -446,6 +373,7 @@ static void separate_bkgd_bands_h (void) static void separate_bkgd_bands_s (void) { + proc_load_mem(4); proc_cmp(IMG_IFACE_CMP_SATURATION); @@ -453,7 +381,6 @@ static void separate_bkgd_bands_s (void) proc_save_mem(10); switch (bkgd) { - case 0: proc_threshold(cv::THRESH_TOZERO_INV, 160); proc_threshold(cv::THRESH_TOZERO, 110); @@ -477,6 +404,7 @@ static void separate_bkgd_bands_s (void) static void separate_bkgd_bands_v (void) { + proc_load_mem(4); proc_cmp(IMG_IFACE_CMP_VALUE); @@ -508,6 +436,7 @@ static void separate_bkgd_bands_v (void) static void bkgd_find (void) { + /* Merge the components: H | S | V */ proc_load_mem(7); proc_save_ref(); @@ -524,178 +453,147 @@ static void bkgd_find (void) static int bands_find (void) { - int status; proc_load_mem(8); - /* Contours */ proc_contours(&contours, &hierarchy); - if (contours.size() > 5) { + bands_n = contours.size(); + if (bands_n > 5) { proc_load_mem(8); proc_dilate_erode(1); proc_contours(&contours, &hierarchy); + bands_n = contours.size(); } - - bands_n = contours.size(); - if ((bands_n == 0) || (bands_n == 2) || (bands_n > 5)) { - status = RESISTOR_NOK_BANDS; - return status; - } + 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); + 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); - } + 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); - } + 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); - } + 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); + proc_bounding_rect(&contours[0], &rect, true); bands[4].x = rect.x + rect.width / 2.0; bands[4].y = rect.y + rect.height / 2.0; } - status = RESISTOR_OK; - return status; + return 0; } static void bands_colors (void) { + /* Hue */ proc_load_mem(9); - if (bands_n == 5) { + if (bands_n == 5) proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].h)); - } - if (bands_n >= 3) { + 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) { + if (bands_n >= 3) proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].h)); - } - if (bands_n > 3) { + 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) { + if (bands_n == 5) proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].s)); - } - if (bands_n >= 3) { + 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) { + if (bands_n >= 3) proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].s)); - } - if (bands_n > 3) { + 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) { + if (bands_n == 5) proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].v)); - } - if (bands_n >= 3) { + 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) { + if (bands_n >= 3) proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].v)); - } - if (bands_n > 3) { + if (bands_n > 3) proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].v)); - } } static void bands_code (void) { - int i; + char txt[LOG_LINE_LEN]; - /* Init to 0 */ - for (i = 0; i < 6; i++) { - code[i] = '\0'; - } + memset(code, 0, ARRAY_SIZE(code)); /* Band 0 (hundreds) */ - if (bands_n == 5) { + if (bands_n == 5) code[0] = band_hsv2code(&bands[0]); - } else { + else code[0] = 'n'; - } - /* Band 1 (tens) */ - if (bands_n != 1) { + if (bands_n != 1) code[1] = band_hsv2code(&bands[1]); - } else { + else code[1] = 'n'; - } /* Band 2 (units) */ code[2] = band_hsv2code(&bands[2]); /* Band 3 (multiplier) */ - if (bands_n != 1) { + if (bands_n != 1) code[3] = band_hsv2code(&bands[3]); - } else { + else code[3] = 'n'; - } /* Band 4 (tolerance) */ - if (bands_n > 3) { + if (bands_n > 3) code[4] = band_hsv2code(&bands[4]); - } else { + else code[4] = 'n'; - } - /* Write bands' code into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Code: \"%s\"", - code); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; + snprintf(txt, LOG_LINE_LEN, "Code: \"%s\"", code); + user_iface_log_write(0, txt); } static char band_hsv2code (struct Resistor_Bands *band) { - char ch; + char c; /* * Not able to segmentate: @@ -712,324 +610,276 @@ static char band_hsv2code (struct Resistor_Bands *band) // 1 2 3 if (band->s < 90) { // 1 3 - if (band->v < 85) { - ch = '1'; - } else { - ch = '3'; - } + if (band->v < 85) + c = '1'; + else + c = '3'; } else if (band->s < 140) { // 1 2 3 - if (band->v < 60) { - ch = '1'; - } else if (band->v < 85) { - // 1 2 - ch = 'q'; - } else if (band->v < 90) { - ch = '2'; - } else if (band->v < 150) { - // 2 3 - ch = 'w'; - } else { - ch = '3'; - } + 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) { - ch = '2'; - } else if (band->v < 150) { - // 2 3 - ch = 'w'; - } else { - ch = '3'; - } + if (band->v < 90) + c = '2'; + else if (band->v < 150) + c = 'w'; // 2 3 + else + c = '3'; } else { - ch = '3'; + c = '3'; } } else if (band->h < 35) { // 1 3 g if (band->s < 130) { // 1 3 - if (band->v < 85) { - ch = '1'; - } else { - ch = '3'; - } + if (band->v < 85) + c = '1'; + else + c = '3'; } else if (band->s < 140) { // 1 3 g - if (band->v < 85) { - ch = '1'; - } else if (band->v < 120) { - ch = '3'; - } else { - // 3 g - ch = 'e'; - } + 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) { - ch = '3'; - } else { - // 3 g - ch = 'e'; - } + if (band->v < 120) + c = '3'; + else + c = 'e'; // 3 g } else { - ch = '3'; + c = '3'; } } else if (band->h < 50) { // 1 3 if (band->s < 140) { // 1 3 - if (band->v < 85) { - ch = '1'; - } else { - ch = '3'; - } + if (band->v < 85) + c = '1'; + else + c = '3'; } else { - ch = '3'; + c = '3'; } } else if (band->h < 60) { // 1 3 4 if (band->s < 140) { // 1 3 - if (band->v < 85) { - ch = '1'; - } else { - ch = '3'; - } + if (band->v < 85) + c = '1'; + else + c = '3'; } else if (band->s < 160) { - ch = '3'; + c = '3'; } else if (band->s < 180) { // 3 4 - if (band->v < 110) { - // 3 4 - ch = 'r'; - } else { - ch = '3'; - } + if (band->v < 110) + c = 'r'; // 3 4 + else + c = '3'; } else { - ch = '3'; + c = '3'; } } else if (band->h < 80) { // 1 5 - if (band->s < 165) { - ch = '1'; - } else { - ch = '5'; - } + if (band->s < 165) + c = '1'; + else + c = '5'; } else if (band->h < 90) { - ch = '1'; + c = '1'; } else if (band->h < 100) { // 0 1 8 9 if (band->s < 40) { // 1 8 9 - if (band->v < 55) { - ch = '1'; - } else if (band->v < 80) { - // 1 8 - ch = 't'; - } else if (band->v < 125) { - ch = '1'; - } else { - ch = '9'; - } + 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) { - ch = '0'; - } else if (band->v < 55) { - // 0 1 - ch = 'y'; - } else if (band->v < 75) { - // 0 1 8 - ch = 'u'; - } else if (band->v < 80) { - // 1 8 - ch = 't'; - } else if (band->v < 125) { - ch = '1'; - } else { - ch = '9'; - } + 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) { - ch = '0'; - } else if (band->v < 55) { - // 0 1 - ch = 'y'; - } else if (band->v < 75) { - // 0 1 8 - ch = 'u'; - } else if (band->v < 80) { - // 1 8 - ch = 't'; - } else { - ch = '1'; - } + 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) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else { - ch = '1'; - } + if (band->v < 45) + c = '0'; + else if (band->v < 75) + c = 'y'; // 0 1 + else + c = '1'; } else { - ch = '0'; + c = '0'; } } else if (band->h < 110) { // 0 1 6 8 if (band->s < 40) { // 1 8 - if (band->v < 55) { - ch = '1'; - } else if (band->v < 80) { - // 1 8 - ch = 't'; - } else { - ch = '1'; - } + 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) { - ch = '0'; - } else if (band->v < 55) { - // 0 1 - ch = 'y'; - } else if (band->v < 75) { - // 0 1 8 - ch = 'u'; - } else if (band->v < 80) { - // 1 8 - ch = 't'; - } else { - ch = '1'; - } + 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) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else { - ch = '1'; - } + if (band->v < 45) + c = '0'; + else if (band->v < 75) + c = 'y'; // 0 1 + else + c = '1'; } else if (band->s < 200) { - ch = '0'; + c = '0'; } else { - ch = '6'; + c = '6'; } } else if (band->h < 120) { // 0 1 6 7 if (band->s < 40) { - ch = '1'; + c = '1'; } else if (band->s < 90) { // 0 1 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else { - ch = '1'; - } + 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) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else if (band->v < 120) { - ch = '1'; - } else { - ch = '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) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else { - ch = '1'; - } + if (band->v < 45) + c = '0'; + else if (band->v < 75) + c = 'y'; // 0 1 + else + c = '1'; } else if (band->s < 200) { - ch = '0'; + c = '0'; } else { - ch = '6'; + c = '6'; } } else if (band->h < 130) { // 0 1 7 if (band->s < 40) { - ch = '1'; + c = '1'; } else if (band->s < 90) { // 0 1 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else { - ch = '1'; - } + 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) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else if (band->v < 120) { - ch = '1'; - } else { - ch = '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) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else { - ch = '1'; - } + if (band->v < 45) + c = '0'; + else if (band->v < 75) + c = 'y'; // 0 1 + else + c = '1'; } else { - ch = '0'; + c = '0'; } } else if (band->h < 140) { // 0 1 if (band->s < 40) { - ch = '1'; + c = '1'; } else if (band->s < 140) { // 0 1 - if (band->v < 45) { - ch = '0'; - } else if (band->v < 75) { - // 0 1 - ch = 'y'; - } else { - ch = '1'; - } + if (band->v < 45) + c = '0'; + else if (band->v < 75) + c = 'y'; // 0 1 + else + c = '1'; } else { - ch = '0'; + c = '0'; } } else if (band->h < 150) { - ch = '0'; + c = '0'; } else { - ch = '2'; + c = '2'; } - return ch; + return c; } static void bands_code_deduce_0 (void) { + char txt[LOG_LINE_LEN]; + /* * Not able to segmentate: * q = 1 2 @@ -1090,26 +940,22 @@ static void bands_code_deduce_0 (void) break; } - /* Write bands' code into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Code: \"%s\"", - code); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; + 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 */ @@ -1290,18 +1136,13 @@ static void bands_code_deduce_1 (void) break; } - /* Write bands' code into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Code: \"%s\"", - code); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; + snprintf(txt, LOG_LINE_LEN, "Code: \"%s\"", code); + user_iface_log_write(0, txt); } static int bands_code_deduce_no (void) { - int status; - int i; + char txt[LOG_LINE_LEN]; /* * Not able to segmentate: @@ -1314,7 +1155,7 @@ static int bands_code_deduce_no (void) * u = 0 1 8 */ - for (i = 0; i < 5; i++) { + for (ptrdiff_t i = 0; i < 5; i++) { switch (code[i]) { case 'q': case 'w': @@ -1324,26 +1165,18 @@ static int bands_code_deduce_no (void) case 'y': case 'u': code[i] = '?'; - break; } } - for (i = 0; i < 5; i++) { - if (code[i] == '?') { - status = RESISTOR_NOK_COLOR; - return status; - } + for (ptrdiff_t i = 0; i < 5; i++) { + if (code[i] == '?') + return RESISTOR_NOK_COLOR; } - /* Write bands' code into log */ - snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "Code: \"%s\"", - code); - user_iface_log.lvl[user_iface_log.len] = 0; - (user_iface_log.len)++; + snprintf(txt, LOG_LINE_LEN, "Code: \"%s\"", code); + user_iface_log_write(0, txt); - status = RESISTOR_OK; - return status; + return 0; } static void resistor_value (void) @@ -1352,30 +1185,26 @@ static void resistor_value (void) /* Base value */ base = code[2] - '0'; - if (code[1] != 'n') { + if (code[1] != 'n') base += (code[1] - '0') * 10; - } - if (code[0] != 'n') { + if (code[0] != 'n') base += (code[0] - '0') * 100; - } /* Calculate resistance */ - if ((code[3] > '0') && (code[3] < '9')) { + if ((code[3] > '0') && (code[3] < '9')) power = code[3] - '0'; - } else if (code[3] == 'g') { + else if (code[3] == 'g') power = -1; - } else if (code[3] == 's') { + else if (code[3] == 's') power = -2; - } else { - // error + else return; - } + resistance = base * pow(10, power); } static int resistor_tolerance (void) { - int status; if (bands_n != 1) { switch (code[4]) { @@ -1394,56 +1223,54 @@ static int resistor_tolerance (void) tolerance = 10; break; default: - status = RESISTOR_NOK_TOLERANCE; - return status; + return RESISTOR_NOK_TOLERANCE; } } - status = RESISTOR_OK; - return status; + 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) { - int status; /* Check that base value is a standard value */ int std_values_10 [12] = {10,12,15,18,22,27,33,39,47,56,68,82}; int std_values_5 [12] = {11,13,16,20,24,30,36,43,51,62,75,91}; - bool std_value_nok = true; - int i; - if (bands_n != 1) { - for (i = 0; i < 12; i++) { - if (base == std_values_10[i]) { - std_value_nok = false; - } - if (base == (std_values_10[i] * 10)) { - std_value_nok = false; - } - } - if (tolerance <= 5) { - for (i = 0; i < 12; i++) { - if (base == std_values_5[i]) { - std_value_nok = false; - } - if (base == (std_values_5[i] * 10)) { - std_value_nok = false; - } - } - } - } else { - if (base == 0) { - std_value_nok = false; - } + if (bands_n == 1) { + if (base) + return RESISTOR_NOK_STD_VALUE; + return 0; } - if (std_value_nok) { - status = RESISTOR_NOK_STD_VALUE; - return status; + 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; + } } - status = RESISTOR_OK; - return status; + return RESISTOR_NOK_STD_VALUE; } diff --git a/modules/save/src/save.cpp b/src/save/save.cpp index 30d3376..cbe039d 100644 --- a/modules/save/src/save.cpp +++ b/src/save/save.cpp @@ -7,39 +7,60 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <cerrno> - #include <cstdio> - #include <cstdlib> -/* Linux ---------------------------------------------------------------------*/ - /* mkdir */ - #include <sys/stat.h> -/* Packages ------------------------------------------------------------------*/ - #include <opencv2/opencv.hpp> -/* Project -------------------------------------------------------------------*/ - #include "user_iface.hpp" -/* Module --------------------------------------------------------------------*/ - #include "save.hpp" +#include "vision-artificial/save/save.hpp" + +#include <cerrno> +#include <cstdio> +#include <cstdlib> + +#include <sys/stat.h> + +#include <opencv2/opencv.hpp> + +#include "libalx/base/errno/errno_str.hpp" +#include "libalx/base/stddef/restrict.hpp" + +#include "vision-artificial/user/iface.hpp" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ /****************************************************************************** ******* variables ************************************************************ ******************************************************************************/ class cv::Mat image; - char home_path [FILENAME_MAX]; - char user_prog_path [FILENAME_MAX]; - char saved_path [FILENAME_MAX]; - char labels_path [FILENAME_MAX]; - char labels_fail_path [FILENAME_MAX]; - char lighters_path [FILENAME_MAX]; - char lighters_fail_path [FILENAME_MAX]; - char objects_path [FILENAME_MAX]; - char objects_fail_path [FILENAME_MAX]; - char coins_path [FILENAME_MAX]; - char coins_fail_path [FILENAME_MAX]; - char resistors_path [FILENAME_MAX]; - char resistors_fail_path [FILENAME_MAX]; - char saved_name [FILENAME_MAX]; + char home_path[FILENAME_MAX]; + char user_prog_path[FILENAME_MAX]; + char saved_path[FILENAME_MAX]; + char labels_path[FILENAME_MAX]; + char labels_fail_path[FILENAME_MAX]; + char lighters_path[FILENAME_MAX]; + char lighters_fail_path[FILENAME_MAX]; + char objects_path[FILENAME_MAX]; + char objects_fail_path[FILENAME_MAX]; + char coins_path[FILENAME_MAX]; + char coins_fail_path[FILENAME_MAX]; + char resistors_path[FILENAME_MAX]; + char resistors_fail_path[FILENAME_MAX]; + char saved_name[FILENAME_MAX]; + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** + ******************************************************************************/ /****************************************************************************** @@ -47,93 +68,81 @@ ******************************************************************************/ void save_init (void) { - int err; if (snprintf(home_path, FILENAME_MAX, "%s/", getenv(ENV_HOME)) >= FILENAME_MAX) { - goto err_path; + goto err; } if (snprintf(user_prog_path, FILENAME_MAX, "%s/%s/", home_path, USER_PROG_DIR) >= FILENAME_MAX) { - goto err_path; + goto err; } if (snprintf(saved_path, FILENAME_MAX, "%s/%s/", home_path, USER_SAVED_DIR) >= FILENAME_MAX) { - goto err_path; + goto err; } if (snprintf(labels_path, FILENAME_MAX, "%s/%s/", home_path, USER_LABELS_DIR) >= FILENAME_MAX) { - goto err_path; + goto err; } if (snprintf(labels_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_LABELS_FAIL_DIR) >= FILENAME_MAX) { - goto err_path; + goto err; } if (snprintf(lighters_path, FILENAME_MAX, "%s/%s/", home_path, USER_LIGHTERS_DIR) >= FILENAME_MAX) { - goto err_path; + goto err; } if (snprintf(lighters_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_LIGHTERS_FAIL_DIR) >= FILENAME_MAX) { - goto err_path; + goto err; } if (snprintf(objects_path, FILENAME_MAX, "%s/%s/", home_path, USER_OBJECTS_DIR) >= FILENAME_MAX) { - goto err_path; + goto err; } if (snprintf(objects_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_OBJECTS_FAIL_DIR) >= FILENAME_MAX) { - goto err_path; + goto err; } if (snprintf(coins_path, FILENAME_MAX, "%s/%s/", home_path, USER_COINS_DIR) >= FILENAME_MAX) { - goto err_path; + goto err; } if (snprintf(coins_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_COINS_FAIL_DIR) >= FILENAME_MAX) { - goto err_path; + goto err; } if (snprintf(resistors_path, FILENAME_MAX, "%s/%s/", home_path, USER_RESISTORS_DIR) >= FILENAME_MAX) { - goto err_path; + goto err; } if (snprintf(resistors_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_RESISTORS_FAIL_DIR) >= FILENAME_MAX) { - goto err_path; + goto err; } saved_name[0] = '\0'; - err = mkdir(user_prog_path, 0700); - - if (!err) { - ; - } else { - + if (mkdir(user_prog_path, 0700)) { switch (errno) { - case EACCES: - printf("err = EACCES"); -// exit(EXIT_FAILURE); - break; - case EEXIST: /* OK */ break; - default: - printf("WTF?!"); -// exit(EXIT_FAILURE); + printf("%s: %s\n", errno_str[errno][0], + errno_str[errno][1]); } } @@ -142,54 +151,46 @@ void save_init (void) mkdir(labels_fail_path, 0700); return; - - -err_path: +err: printf("Path is too large and has been truncated\n"); - exit(EXIT_FAILURE); } -void save_clr (void) +void save_reset_fpath(void) { if (snprintf(saved_path, FILENAME_MAX, "%s/%s/", home_path, USER_SAVED_DIR) >= FILENAME_MAX) { - goto err_path; + goto err; } return; - - -err_path: +err: printf("Path is too large and has been truncated\n"); - exit(EXIT_FAILURE); } -void load_image_file (const char *fpath, const char *fname) +void load_image_file (const char *restrict fpath, + const char *restrict fname) { - char file_path [FILENAME_MAX]; - char file_name [FILENAME_MAX]; + char file_path[FILENAME_MAX]; + char file_name[FILENAME_MAX]; - /* Free old image */ image.release(); /* Set file_path */ if (!fpath) { /* Default path */ - save_clr(); + save_reset_fpath(); snprintf(file_path, FILENAME_MAX, "%s", saved_path); } else { snprintf(file_path, FILENAME_MAX, "%s", fpath); } /* Set file_name */ - if (!fname) { - /* Request file name */ + if (!fname) user_iface_fname(file_path, saved_name); - } else { + else snprintf(saved_name, FILENAME_MAX, "%s", fname); - } /* File name */ if (snprintf(file_name, FILENAME_MAX, "%s/%s", @@ -198,21 +199,16 @@ void load_image_file (const char *fpath, const char *fname) goto err_path; } - /* Load image */ image = cv::imread(file_name, CV_LOAD_IMAGE_COLOR); - - /* Manage load error */ - if (image.empty()) { - printf("Could not load file: %s\n", file_name); -// exit(0); - } + if (image.empty()) + goto err_img; return; - - +err_img: + printf("Could not load file: %s\n", file_name); + return; err_path: printf("Path is too large and has been truncated\n"); - exit(EXIT_FAILURE); } void save_cleanup (void) @@ -221,16 +217,17 @@ void save_cleanup (void) image.release(); } -void save_image_file (const char *fpath, const char *save_as) +void save_image_file (const char *restrict fpath, + const char *restrict save_as) { - char file_path [FILENAME_MAX]; - char file_name [FILENAME_MAX]; + char file_path[FILENAME_MAX]; + char file_name[FILENAME_MAX]; FILE *fp; /* Set file_path */ if (!fpath) { /* Default path */ - save_clr(); + save_reset_fpath(); snprintf(file_path, FILENAME_MAX, "%s", saved_path); } else { snprintf(file_path, FILENAME_MAX, "%s", fpath); @@ -238,9 +235,7 @@ void save_image_file (const char *fpath, const char *save_as) /* Set file_name */ if (!save_as) { - /* Default name */ snprintf(saved_name, FILENAME_MAX, "%s", SAVED_NAME_DEFAULT); - /* Request file name */ user_iface_fname(saved_path, saved_name); } else { snprintf(saved_name, FILENAME_MAX, "%s", save_as); @@ -248,8 +243,8 @@ void save_image_file (const char *fpath, const char *save_as) /* Prepend the path */ if (snprintf(file_name, FILENAME_MAX, "%s/%s", - file_path, - saved_name) >= FILENAME_MAX) { + file_path, + saved_name) >= FILENAME_MAX) { goto err_path; } @@ -259,31 +254,27 @@ void save_image_file (const char *fpath, const char *save_as) fclose(fp); user_iface_fname(saved_path, saved_name); if (snprintf(file_name, FILENAME_MAX, "%s/%s", - file_path, - saved_name) >= FILENAME_MAX) { + file_path, + saved_name) >= FILENAME_MAX) { goto err_path; } } - /* Write into log */ - (void)snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, - "%s", saved_name); - user_iface_log.lvl[user_iface_log.len] = 2; - (user_iface_log.len)++; - + user_iface_log_write(2, saved_name); - /* Write to a new file */ cv::imwrite(file_name, image); 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/modules/user/src/user_clui.c b/src/user/clui.c index bcd44c8..8c3c7ec 100644 --- a/modules/user/src/user_clui.c +++ b/src/user/clui.c @@ -7,70 +7,72 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ - #include <stdio.h> +#include "vision-artificial/user/clui.h" - #include "libalx/io/alx_input.h" +#include <stdio.h> +#include <string.h> - #include "img_iface.h" - #include "user_iface.h" +#include "libalx/base/stddef/size.h" +#include "libalx/base/stdio/get.h" +#include "libalx/base/stdio/wait.h" - #include "user_clui.h" +#include "vision-artificial/image/iface.h" +#include "vision-artificial/user/iface.h" /****************************************************************************** ******* macros *************************************************************** ******************************************************************************/ - # define BUFF_SIZE (1024) +#define BUFF_SIZE (0xFFF) /****************************************************************************** - ******* static variables ***************************************************** + ******* enums **************************************************************** ******************************************************************************/ -static int log_pos; /****************************************************************************** - ******* static functions ***************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* variables ************************************************************ + ******************************************************************************/ +/* Global --------------------------------------------------------------------*/ +/* Static --------------------------------------------------------------------*/ + + +/****************************************************************************** + ******* static functions (prototypes) **************************************** ******************************************************************************/ - /* Log */ static void log_loop (void); - /* Input */ static int usr_input (void); - /* Help */ static void show_help (void); /****************************************************************************** - ******* main ***************************************************************** + ******* global functions ***************************************************** ******************************************************************************/ -void user_clui_init (void) +int user_clui (const char *restrict title, + const char *restrict subtitle) { - log_pos = 0; -} - -int user_clui (const char *title, const char *subtitle) -{ - int action; - - /* User action */ show_help(); user_clui_show_log(title, subtitle); - action = usr_input(); - - return action; + return usr_input(); } -void user_clui_fname (const char *filepath, char *filename) +void user_clui_fname (const char *restrict fpath, + char *restrict fname) { - printf("File name:\n"); - printf("Valid extensions: .bmp .dib .jpeg .png .pbm .pgm .ppm .tiff\n"); - fgets(filename, FILENAME_MAX, stdin); - alx_sscan_fname(filepath, filename, false, filename); + alx_get_fname(fpath, fname, false, "File name:", "Valid extensions: .bmp .dib .jpeg .png .pbm .pgm .ppm .tiff", + 2); } -void user_clui_show_log (const char *title, const char *subtitle) +void user_clui_show_log (const char *restrict title, + const char *restrict subtitle) { printf("________________________________________________________________________________\n"); @@ -80,38 +82,40 @@ void user_clui_show_log (const char *title, const char *subtitle) } +void user_clui_show_ocr (void) +{ + + printf("%s", img_ocr_text); + alx_wait4enter(); +} + /****************************************************************************** - ******* static functions ***************************************************** + ******* static functions (definitions) *************************************** ******************************************************************************/ -/* Log -----------------------------------------------------------------------*/ static void log_loop (void) { - int lvl; + const char *txt; putchar('\n'); - for (; log_pos < user_iface_log.len; log_pos++) { - if (user_iface_log.lvl[log_pos] <= user_iface_log.visible) { - for (lvl = 0; lvl < user_iface_log.lvl[log_pos]; lvl++) - printf("\t"); - printf("%s\n", user_iface_log.line[log_pos]); - } + for (;;) { + txt = user_iface_log_read(); + if (!txt) + break; + for (int i = 0; i < user_iface_log.lvl[user_iface_log.pos]; i++) + printf("\t"); + printf("%s\n", txt); } - putchar('\n'); + printf("\n"); } -/* Input ---------------------------------------------------------------------*/ static int usr_input (void) { - int action; - char buff [BUFF_SIZE]; + char buff[BUFF_SIZE]; char ch [10]; - int i; - for (i = 0; i < 10; i++) - ch[i] = '\0'; + memset(ch, 0, ARRAY_SIZE(ch)); buff[0] = '\0'; - action = USER_IFACE_ACT_FOO; if (!fgets(buff, BUFF_SIZE, stdin)) goto err_fgets; @@ -120,13 +124,9 @@ static int usr_input (void) switch (ch[0]) { case '+': - action = USER_IFACE_ACT_APPLY; - break; - + return USER_IFACE_ACT_APPLY; case '-': - action = USER_IFACE_ACT_DISCARD; - break; - + return USER_IFACE_ACT_DISCARD; case 'e': /* Exercises from class */ switch (ch[1]) { @@ -134,43 +134,37 @@ static int usr_input (void) /* Label */ switch (ch[2]) { case '1': - action = USER_IFACE_ACT_PROC_LABEL_SERIES; - break; + return USER_IFACE_ACT_PROC_LABEL_SERIES; } break; case '2': /* Objects */ switch (ch[2]) { case '0': - action = USER_IFACE_ACT_PROC_OBJECTS_CALIB; - break; + return USER_IFACE_ACT_PROC_OBJECTS_CALIB; case '1': - action = USER_IFACE_ACT_PROC_OBJECTS_SERIES; - break; + return USER_IFACE_ACT_PROC_OBJECTS_SERIES; } break; case '3': /* Coins */ switch (ch[2]) { case '1': - action = USER_IFACE_ACT_PROC_COINS_SERIES; - break; + return USER_IFACE_ACT_PROC_COINS_SERIES; } break; case '4': /* Resistor */ switch (ch[2]) { case '1': - action = USER_IFACE_ACT_PROC_RESISTOR_SERIES; - break; + return USER_IFACE_ACT_PROC_RESISTOR_SERIES; } break; case '5': /* Lighters */ switch (ch[2]) { case '1': - action = USER_IFACE_ACT_PROC_LIGHTERS_SERIES; - break; + return USER_IFACE_ACT_PROC_LIGHTERS_SERIES; } break; } @@ -186,39 +180,31 @@ static int usr_input (void) /* Distance transform postprocessing */ switch (ch[3]) { case '0': - action = USER_IFACE_ACT_LOCAL_MAX; - break; + return USER_IFACE_ACT_LOCAL_MAX; case '1': - action = USER_IFACE_ACT_SKELETON; - break; + return USER_IFACE_ACT_SKELETON; } break; case '1': /* Lines */ switch (ch[3]) { case '0': - action = USER_IFACE_ACT_LINES_HORIZONTAL; - break; + return USER_IFACE_ACT_LINES_HORIZONTAL; case '1': - action = USER_IFACE_ACT_LINES_VERTICAL; - break; + return USER_IFACE_ACT_LINES_VERTICAL; } break; case '2': /* Smooth */ switch (ch[3]) { case '0': - action = USER_IFACE_ACT_MEAN_HORIZONTAL; - break; + return USER_IFACE_ACT_MEAN_HORIZONTAL; case '1': - action = USER_IFACE_ACT_MEAN_VERTICAL; - break; + return USER_IFACE_ACT_MEAN_VERTICAL; case '2': - action = USER_IFACE_ACT_MEDIAN_HORIZONTAL; - break; + return USER_IFACE_ACT_MEDIAN_HORIZONTAL; case '3': - action = USER_IFACE_ACT_MEDIAN_VERTICAL; - break; + return USER_IFACE_ACT_MEDIAN_VERTICAL; } break; } @@ -233,39 +219,31 @@ static int usr_input (void) /* Pixel */ switch (ch[4]) { case '0': - action = USER_IFACE_ACT_PIXEL_GET; - break; + return USER_IFACE_ACT_PIXEL_GET; case '1': - action = USER_IFACE_ACT_PIXEL_SET; - break; + return USER_IFACE_ACT_PIXEL_SET; } break; case '1': /* ROI */ switch (ch[4]) { case '0': - action = USER_IFACE_ACT_SET_ROI; - break; + return USER_IFACE_ACT_SET_ROI; case '1': - action = USER_IFACE_ACT_SET_ROI_2RECT; - break; + return USER_IFACE_ACT_SET_ROI_2RECT; } break; case '2': /* Operations on Arrays */ switch (ch[4]) { case '0': - action = USER_IFACE_ACT_AND_2REF; - break; + return USER_IFACE_ACT_AND_2REF; case '1': - action = USER_IFACE_ACT_NOT; - break; + return USER_IFACE_ACT_NOT; case '2': - action = USER_IFACE_ACT_OR_2REF; - break; + return USER_IFACE_ACT_OR_2REF; case '3': - action = USER_IFACE_ACT_COMPONENT; - break; + return USER_IFACE_ACT_COMPONENT; } break; } @@ -277,99 +255,76 @@ static int usr_input (void) /* Image filtering */ switch (ch[4]) { case '0': - action = USER_IFACE_ACT_DILATE; - break; + return USER_IFACE_ACT_DILATE; case '1': - action = USER_IFACE_ACT_ERODE; - break; + return USER_IFACE_ACT_ERODE; case '2': - action = USER_IFACE_ACT_DILATE_ERODE; - break; + return USER_IFACE_ACT_DILATE_ERODE; case '3': - action = USER_IFACE_ACT_ERODE_DILATE; - break; + return USER_IFACE_ACT_ERODE_DILATE; case '4': - action = USER_IFACE_ACT_SMOOTH; - break; + return USER_IFACE_ACT_SMOOTH; case '5': - action = USER_IFACE_ACT_SOBEL; - break; + return USER_IFACE_ACT_SOBEL; case '6': - action = USER_IFACE_ACT_BORDER; - break; + return USER_IFACE_ACT_BORDER; } break; case '1': /* Geometric image transformations */ switch (ch[4]) { case '0': - action = USER_IFACE_ACT_MIRROR; - break; + return USER_IFACE_ACT_MIRROR; case '1': - action = USER_IFACE_ACT_ROTATE_ORTO; - break; + return USER_IFACE_ACT_ROTATE_ORTO; case '2': - action = USER_IFACE_ACT_ROTATE; - break; + return USER_IFACE_ACT_ROTATE; case '3': - action = USER_IFACE_ACT_ROTATE_2RECT; - break; + return USER_IFACE_ACT_ROTATE_2RECT; } break; case '2': /* Miscellaneous image transformations */ switch (ch[4]) { case '0': - action = USER_IFACE_ACT_ADAPTIVE_THRESHOLD; - break; + return USER_IFACE_ACT_ADAPTIVE_THRESHOLD; case '1': - action = USER_IFACE_ACT_CVT_COLOR; - break; + return USER_IFACE_ACT_CVT_COLOR; case '2': - action = USER_IFACE_ACT_DISTANCE_TRANSFORM; - break; + return USER_IFACE_ACT_DISTANCE_TRANSFORM; case '3': - action = USER_IFACE_ACT_THRESHOLD; - break; + return USER_IFACE_ACT_THRESHOLD; } break; case '3': /* Histograms */ switch (ch[4]) { case '0': - action = USER_IFACE_ACT_HISTOGRAM; - break; + return USER_IFACE_ACT_HISTOGRAM; case '1': - action = USER_IFACE_ACT_HISTOGRAM_C3; - break; + return USER_IFACE_ACT_HISTOGRAM_C3; } break; case '4': /* Structural analysis and shape descriptors */ switch (ch[4]) { case '0': - action = USER_IFACE_ACT_CONTOURS; - break; + return USER_IFACE_ACT_CONTOURS; case '1': - action = USER_IFACE_ACT_CONTOURS_SIZE; - break; + return USER_IFACE_ACT_CONTOURS_SIZE; case '2': - action = USER_IFACE_ACT_BOUNDING_RECT; - break; + return USER_IFACE_ACT_BOUNDING_RECT; case '3': - action = USER_IFACE_ACT_FIT_ELLIPSE; - break; + return USER_IFACE_ACT_FIT_ELLIPSE; case '4': - action = USER_IFACE_ACT_MIN_AREA_RECT; - break; + return USER_IFACE_ACT_MIN_AREA_RECT; } break; case '5': /* Feature detection */ switch (ch[4]) { case '0': - action = USER_IFACE_ACT_HOUGH_CIRCLES; - break; + return USER_IFACE_ACT_HOUGH_CIRCLES; } break; } @@ -380,76 +335,58 @@ static int usr_input (void) /* img_orb */ switch (ch[2]) { case '0': - action = USER_IFACE_ACT_ALIGN; - break; + return USER_IFACE_ACT_ALIGN; } break; case '3': /* img_calib3d */ switch (ch[2]) { case '0': - action = USER_IFACE_ACT_CALIBRATE; - break; + return USER_IFACE_ACT_CALIBRATE; case '1': - action = USER_IFACE_ACT_UNDISTORT; - break; + return USER_IFACE_ACT_UNDISTORT; } break; case '4': /* img_zbar */ switch (ch[2]) { case '0': - action = USER_IFACE_ACT_DECODE; - break; + return USER_IFACE_ACT_DECODE; } break; case '5': /* img_ocr */ switch (ch[2]) { case '0': - action = USER_IFACE_ACT_READ; - break; + return USER_IFACE_ACT_READ; } break; } break; - case 'l': - action = USER_IFACE_ACT_LOAD_MEM; - break; - + return USER_IFACE_ACT_LOAD_MEM; case 'm': - action = USER_IFACE_ACT_SAVE_MEM; - break; - + return USER_IFACE_ACT_SAVE_MEM; case 'q': - action = USER_IFACE_ACT_QUIT; - break; - + return USER_IFACE_ACT_QUIT; case 'r': - action = USER_IFACE_ACT_SAVE_REF; - break; - + return USER_IFACE_ACT_SAVE_REF; case 's': - action = USER_IFACE_ACT_SAVE_FILE; - break; - + return USER_IFACE_ACT_SAVE_FILE; case 'u': /* User iface actions */ switch (ch[1]) { case '1': - action = USER_IFACE_ACT_SHOW_OCR; - break; + return USER_IFACE_ACT_SHOW_OCR; } break; - case 'x': /* Special sequence "xyzzy" */ if (ch[1] == 'y') { if (ch[2] == 'z') { if (ch[3] == 'z') { if (ch[4] == 'y') { - action = USER_IFACE_ACT_FOO; + return USER_IFACE_ACT_FOO; } } } @@ -459,12 +396,9 @@ static int usr_input (void) err_fgets: err_sscanf: - return action; + return USER_IFACE_ACT_FOO; } -/* * * * * * * * * * - * * * Help * * * * * * * - * * * * * * * * * */ static void show_help (void) { diff --git a/modules/user/src/user_iface.c b/src/user/iface.c index 84aedfb..75da415 100644 --- a/modules/user/src/user_iface.c +++ b/src/user/iface.c @@ -7,51 +7,64 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ -/* Standard C ----------------------------------------------------------------*/ - #include <stdint.h> - #include <stdio.h> -/* Project -------------------------------------------------------------------*/ - #include "img_iface.h" - #include "proc_iface.h" -/* Module --------------------------------------------------------------------*/ - #include "user_clui.h" - #include "user_tui.h" +#include "vision-artificial/user/iface.h" - #include "user_iface.h" +#include <stddef.h> +#include <stdint.h> +#include <stdio.h> + +#include "libalx/base/stdio/get.h" + +#include "vision-artificial/image/iface.h" +#include "vision-artificial/proc/iface.h" +#include "vision-artificial/user/clui.h" +#include "vision-artificial/user/tui.h" /****************************************************************************** ******* macros *************************************************************** ******************************************************************************/ - # define TITLE_SIZE (20) +#define TITLE_SIZE (80) + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ /****************************************************************************** ******* variables ************************************************************ ******************************************************************************/ -int user_iface_mode; -struct User_Iface_Log user_iface_log; +/* Global --------------------------------------------------------------------*/ + int user_iface_mode; + struct User_Iface_Log user_iface_log; +/* Static --------------------------------------------------------------------*/ /****************************************************************************** - ******* static functions ***************************************************** + ******* static functions (prototypes) **************************************** ******************************************************************************/ static void user_iface_act (int action); static void user_iface_show_ocr (void); /****************************************************************************** - ******* main ***************************************************************** + ******* global functions ***************************************************** ******************************************************************************/ void user_iface_init (void) { + user_iface_log.len = 0; + user_iface_log.pos = -1; switch (user_iface_mode) { case USER_IFACE_CLUI: - user_clui_init(); break; - case USER_IFACE_TUI: user_tui_init(); break; @@ -60,15 +73,14 @@ void user_iface_init (void) void user_iface_cleanup (void) { + switch (user_iface_mode) { case USER_IFACE_CLUI: break; - case USER_IFACE_TUI: user_tui_cleanup(); break; } - fflush(stdout); } @@ -82,107 +94,111 @@ void user_iface (void) snprintf(subtitle, TITLE_SIZE, "Subtitle"); do { - /* Display image */ img_iface_show_img(); - /* Request user action */ switch (user_iface_mode) { case USER_IFACE_CLUI: user_action = user_clui(title, subtitle); break; - case USER_IFACE_TUI: user_action = user_tui(title, subtitle); break; - default: user_action = USER_IFACE_ACT_FOO; - break; } - - /* Do action */ user_iface_act(user_action); } while (user_action != USER_IFACE_ACT_QUIT); } -void user_iface_show_log (const char *title, const char *subtitle) +void user_iface_show_log (const char *restrict title, + const char *restrict subtitle) { + switch (user_iface_mode) { case USER_IFACE_CLUI: user_clui_show_log(title, subtitle); break; - case USER_IFACE_TUI: user_tui_show_log(title, subtitle); break; } } -void user_iface_fname (const char *filepath, char *filename) +void user_iface_fname (const char *restrict filepath, + char *restrict filename) { + switch (user_iface_mode) { case USER_IFACE_CLUI: user_clui_fname(filepath, filename); break; - case USER_IFACE_TUI: user_tui_fname(filepath, filename); break; } } -int64_t user_iface_getint (double m, int64_t def, double M, - const char *title, const char *help) +double user_iface_getdbl (double m, double def, double M, + const char *restrict title, + const char *restrict help) { - int64_t i; switch (user_iface_mode) { case USER_IFACE_CLUI: - // FIXME - i = 1; - break; - + return alx_get_int(m, def, M, title, help, 2); case USER_IFACE_TUI: - i = user_tui_getint(m, def, M, title, help); - break; - + return user_tui_getint(m, def, M, title, help); default: - i = 1; - break; + return 1; } - - return i; } -double user_iface_getdbl (double m, double def, double M, - const char *title, const char *help) +int user_iface_getint (double m, int64_t def, double M, + const char *restrict title, + const char *restrict help) { - int64_t i; switch (user_iface_mode) { case USER_IFACE_CLUI: - // FIXME - i = 1; - break; - + return alx_get_dbl(m, def, M, title, help, 2); case USER_IFACE_TUI: - i = user_tui_getdbl(m, def, M, title, help); - break; - + return user_tui_getdbl(m, def, M, title, help); default: - i = 1; - break; + return 1.0; } +} + +void user_iface_log_write (ptrdiff_t lvl, const char *restrict msg) +{ - return i; + snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "%s", + msg); + user_iface_log.lvl[user_iface_log.len] = lvl; + user_iface_log.len++; +} + +const char *user_iface_log_read (void) +{ + + user_iface_log.pos++; + for (; user_iface_log.pos < user_iface_log.len; user_iface_log.pos++) { + if (user_iface_log.lvl[user_iface_log.pos] <= + user_iface_log.visible) { + break; + } + } + if (user_iface_log.pos == user_iface_log.len) + return NULL; + return &user_iface_log.line[user_iface_log.pos][0]; } /****************************************************************************** - ******* static functions ***************************************************** + ******* static functions (definitions) *************************************** ******************************************************************************/ static void user_iface_act (int action) { + if (action & USER_IFACE_ACT_USRI) { switch (action) { case USER_IFACE_ACT_SHOW_OCR: @@ -192,22 +208,20 @@ 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_nodata(action); + img_iface_act(action, NULL); } } static void user_iface_show_ocr (void) { + switch (user_iface_mode) { case USER_IFACE_CLUI: - // FIXME + user_clui_show_ocr(); break; - case USER_IFACE_TUI: user_tui_show_ocr(); break; diff --git a/modules/user/src/user_tui.c b/src/user/tui.c index 9b0285b..bad2574 100644 --- a/modules/user/src/user_tui.c +++ b/src/user/tui.c @@ -7,15 +7,32 @@ /****************************************************************************** ******* headers ************************************************************** ******************************************************************************/ - #include <inttypes.h> - #include <ncurses.h> +#include "vision-artificial/user/tui.h" - #include "libalx/curses/alx_ncur.h" +#include <inttypes.h> +#include <ncurses.h> - #include "img_iface.h" - #include "user_iface.h" +#include "libalx/base/stdio/wait.h" +#include "libalx/extra/ncurses/common.h" +#include "libalx/extra/ncurses/get.h" - #include "user_tui.h" +#include "vision-artificial/image/iface.h" +#include "vision-artificial/user/iface.h" + + +/****************************************************************************** + ******* macros *************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* enums **************************************************************** + ******************************************************************************/ + + +/****************************************************************************** + ******* structs / unions ***************************************************** + ******************************************************************************/ /****************************************************************************** @@ -26,32 +43,22 @@ static WINDOW *win_help; /****************************************************************************** - ******* static functions ***************************************************** + ******* static functions (prototypes) **************************************** ******************************************************************************/ - /* Log */ static void log_loop (void); - /* Input */ static int usr_input (void); - /* Help */ static void show_help (void); /****************************************************************************** - ******* main ***************************************************************** + ******* global functions ***************************************************** ******************************************************************************/ void user_tui_init (void) { - int h1; - int w1; - int r1; - int c1; - int h2; - int w2; - int r2; - int c2; - - /* Use curses mode */ - alx_resume_curses(); + int_fast8_t h1, w1, r1, c1; + int_fast8_t h2, w2, r2, c2; + + alx_ncurses_resume(); /* Dimensions: log */ h1 = 54; @@ -76,111 +83,90 @@ void user_tui_cleanup (void) { /* Del wins & return to terminal mode */ - alx_win_del(win_log); - alx_win_del(win_help); - alx_pause_curses(); + alx_ncurses_delwin(win_log); + alx_ncurses_delwin(win_help); + alx_ncurses_pause(); } -int user_tui (const char *title, const char *subtitle) +int user_tui (const char *restrict title, + const char *restrict subtitle) { - int action; show_help(); user_tui_show_log(title, subtitle); - action = usr_input(); - - return action; + return usr_input(); } -void user_tui_fname (const char *filepath, char *filename) +void user_tui_fname (const char *restrict fpath, + char *restrict fname) { - int w; - int r; + int w, r; - /* Input box */ w = 75; r = 10; - /* Request name */ - alx_w_getfname(filepath, filename, false, w, r, "File name:", - "Valid extensions: .bmp .dib .jpeg .png .pbm .pgm .ppm .tiff"); + alx_w_get_fname(fpath, fname, false, w, r, "File name:", "Valid extensions: .bmp .dib .jpeg .png .pbm .pgm .ppm .tiff", + 2); } -void user_tui_show_log (const char *title, const char *subtitle) +void user_tui_show_log (const char *restrict title, + const char *restrict subtitle) { - /* Clear & box */ werase(win_log); box(win_log, 0, 0); - /* Title */ - alx_ncur_prn_title(win_log, title); - /* Subtitle */ - alx_ncur_prn_subtitle(win_log, subtitle); + alx_ncurses_title(win_log, title); + alx_ncurses_subtitle(win_log, subtitle); - /* Log */ log_loop(); - - /* Refresh */ wrefresh(win_log); } double user_tui_getdbl (double m, double def, double M, - const char *title, const char *help) + const char *restrict title, + const char *restrict help) { - int w; - int r; - double R; + int w, r; - /* Input box */ w = 75; r = 10; - /* Request int */ - R = alx_w_getdbl(w, r, title, m, def, M, help); - - return R; + return alx_w_get_dbl(m, def, M, w, r, title, help, 2); } -int64_t user_tui_getint (double m, int64_t def, double M, - const char *title, const char *help) +int user_tui_getint (int m, int def, int M, + const char *restrict title, + const char *restrict help) { - /* Input box */ - int w; - int r; - int64_t i; + int w, r; w = 75; r = 10; - /* Request int */ - i = alx_w_getint(w, r, title, m, def, M, help); - - return i; + return alx_w_get_int(m, def, M, w, r, title, help, 2); } void user_tui_show_ocr (void) { - alx_pause_curses(); + alx_ncurses_pause(); printf("%s", img_ocr_text); - getchar(); + alx_wait4enter(); - alx_resume_curses(); + alx_ncurses_resume(); } /****************************************************************************** - ******* static functions ***************************************************** + ******* static functions (definitions) *************************************** ******************************************************************************/ -/* Log -----------------------------------------------------------------------*/ static void log_loop (void) { - int i; - int i_0; - int l; - int l_0; + ptrdiff_t i_0; + int_fast8_t l_0; + int_fast8_t l; if (user_iface_log.len > 51) { i_0 = user_iface_log.len - 51; @@ -191,327 +177,273 @@ static void log_loop (void) l_0 = 0; } - l = l_0; - for (i = i_0; i < user_iface_log.len; i++) { + l = l_0 + 1; + for (ptrdiff_t i = i_0; i < user_iface_log.len; i++) { if (user_iface_log.lvl[i] <= user_iface_log.visible) { - mvwprintw(win_log, (1 + l), - (1 + 4 * user_iface_log.lvl[i]), - "%.*s", - 40 - 2 - 4 * user_iface_log.lvl[i], - user_iface_log.line[i]); + mvwprintw(win_log, l, (1 + 4 * user_iface_log.lvl[i]), + "%.*s", + 40 - 2 - 4 * user_iface_log.lvl[i], + user_iface_log.line[i]); l++; } } } -/* Input ---------------------------------------------------------------------*/ static int usr_input (void) { - int action; - wchar_t ch; + int c; - action = USER_IFACE_ACT_FOO; - ch = wgetch(win_log); - switch (ch) { + c = wgetch(win_log); + switch (c) { case ' ': - action = USER_IFACE_ACT_APPLY; - break; - - /* ASCII 0x08 is BS */ + return USER_IFACE_ACT_APPLY; case KEY_BACKSPACE: + /* ASCII 0x08 is BS */ case 0x08: - action = USER_IFACE_ACT_DISCARD; - break; - + return USER_IFACE_ACT_DISCARD; case 'e': /* Exercises from class */ - ch = wgetch(win_log); + c = wgetch(win_log); - switch (ch) { + switch (c) { case '1': /* Label */ - ch = wgetch(win_log); + c = wgetch(win_log); - switch (ch) { + switch (c) { case '1': - action = USER_IFACE_ACT_PROC_LABEL_SERIES; - break; + return USER_IFACE_ACT_PROC_LABEL_SERIES; } break; case '2': /* Objects */ - ch = wgetch(win_log); + c = wgetch(win_log); - switch (ch) { + switch (c) { case '0': - action = USER_IFACE_ACT_PROC_OBJECTS_CALIB; - break; + return USER_IFACE_ACT_PROC_OBJECTS_CALIB; case '1': - action = USER_IFACE_ACT_PROC_OBJECTS_SERIES; - break; + return USER_IFACE_ACT_PROC_OBJECTS_SERIES; } break; case '3': /* Coins */ - ch = wgetch(win_log); + c = wgetch(win_log); - switch (ch) { + switch (c) { case '1': - action = USER_IFACE_ACT_PROC_COINS_SERIES; - break; + return USER_IFACE_ACT_PROC_COINS_SERIES; } break; case '4': /* Resistor */ - ch = wgetch(win_log); + c = wgetch(win_log); - switch (ch) { + switch (c) { case '1': - action = USER_IFACE_ACT_PROC_RESISTOR_SERIES; - break; + return USER_IFACE_ACT_PROC_RESISTOR_SERIES; } break; case '5': /* Lighters */ - ch = wgetch(win_log); + c = wgetch(win_log); - switch (ch) { + switch (c) { case '1': - action = USER_IFACE_ACT_PROC_LIGHTERS_SERIES; - break; + return USER_IFACE_ACT_PROC_LIGHTERS_SERIES; } break; } break; - case 'f': /* Use simple funtions */ - ch = wgetch(win_log); + c = wgetch(win_log); - switch (ch) { + switch (c) { case '0': /* img_alx */ - ch = wgetch(win_log); + c = wgetch(win_log); - switch (ch) { + switch (c) { case '0': /* Distance transform postprocessing */ - ch = wgetch(win_log); + c = wgetch(win_log); - switch (ch) { + switch (c) { case '0': - action = USER_IFACE_ACT_LOCAL_MAX; - break; + return USER_IFACE_ACT_LOCAL_MAX; case '1': - action = USER_IFACE_ACT_SKELETON; - break; + return USER_IFACE_ACT_SKELETON; } break; case '1': /* Lines */ - ch = wgetch(win_log); + c = wgetch(win_log); - switch (ch) { + switch (c) { case '0': - action = USER_IFACE_ACT_LINES_HORIZONTAL; - break; + return USER_IFACE_ACT_LINES_HORIZONTAL; case '1': - action = USER_IFACE_ACT_LINES_VERTICAL; - break; + return USER_IFACE_ACT_LINES_VERTICAL; } break; case '2': /* Smooth */ - ch = wgetch(win_log); + c = wgetch(win_log); - switch (ch) { + switch (c) { case '0': - action = USER_IFACE_ACT_MEAN_HORIZONTAL; - break; + return USER_IFACE_ACT_MEAN_HORIZONTAL; case '1': - action = USER_IFACE_ACT_MEAN_VERTICAL; - break; + return USER_IFACE_ACT_MEAN_VERTICAL; case '2': - action = USER_IFACE_ACT_MEDIAN_HORIZONTAL; - break; + return USER_IFACE_ACT_MEDIAN_HORIZONTAL; case '3': - action = USER_IFACE_ACT_MEDIAN_VERTICAL; - break; + return USER_IFACE_ACT_MEDIAN_VERTICAL; } break; } break; case '1': /* img_cv */ - ch = wgetch(win_log); + c = wgetch(win_log); - switch (ch) { + switch (c) { case '0': /* Core: The core functionality */ - ch = wgetch(win_log); + c = wgetch(win_log); - switch (ch) { + switch (c) { case '0': /* Pixel */ - ch = wgetch(win_log); + c = wgetch(win_log); - switch (ch) { + switch (c) { case '0': - action = USER_IFACE_ACT_PIXEL_GET; - break; + return USER_IFACE_ACT_PIXEL_GET; case '1': - action = USER_IFACE_ACT_PIXEL_SET; - break; + return USER_IFACE_ACT_PIXEL_SET; } break; case '1': /* ROI */ - ch = wgetch(win_log); + c = wgetch(win_log); - switch (ch) { + switch (c) { case '0': - action = USER_IFACE_ACT_SET_ROI; - break; + return USER_IFACE_ACT_SET_ROI; case '1': - action = USER_IFACE_ACT_SET_ROI_2RECT; - break; + return USER_IFACE_ACT_SET_ROI_2RECT; } break; case '2': /* Operations on Arrays */ - ch = wgetch(win_log); + c = wgetch(win_log); - switch (ch) { + switch (c) { case '0': - action = USER_IFACE_ACT_AND_2REF; - break; + return USER_IFACE_ACT_AND_2REF; case '1': - action = USER_IFACE_ACT_NOT; - break; + return USER_IFACE_ACT_NOT; case '2': - action = USER_IFACE_ACT_OR_2REF; - break; + return USER_IFACE_ACT_OR_2REF; case '3': - action = USER_IFACE_ACT_COMPONENT; - break; + return USER_IFACE_ACT_COMPONENT; } break; } break; case '1': /* Imgproc: Image processing */ - ch = wgetch(win_log); + c = wgetch(win_log); - switch (ch) { + switch (c) { case '0': /* Image filtering */ - ch = wgetch(win_log); + c = wgetch(win_log); - switch (ch) { + switch (c) { case '0': - action = USER_IFACE_ACT_DILATE; - break; + return USER_IFACE_ACT_DILATE; case '1': - action = USER_IFACE_ACT_ERODE; - break; + return USER_IFACE_ACT_ERODE; case '2': - action = USER_IFACE_ACT_DILATE_ERODE; - break; + return USER_IFACE_ACT_DILATE_ERODE; case '3': - action = USER_IFACE_ACT_ERODE_DILATE; - break; + return USER_IFACE_ACT_ERODE_DILATE; case '4': - action = USER_IFACE_ACT_SMOOTH; - break; + return USER_IFACE_ACT_SMOOTH; case '5': - action = USER_IFACE_ACT_SOBEL; - break; + return USER_IFACE_ACT_SOBEL; case '6': - action = USER_IFACE_ACT_BORDER; - break; + return USER_IFACE_ACT_BORDER; } break; case '1': /* Geometric image transformations */ - ch = wgetch(win_log); + c = wgetch(win_log); - switch (ch) { + switch (c) { case '0': - action = USER_IFACE_ACT_MIRROR; - break; + return USER_IFACE_ACT_MIRROR; case '1': - action = USER_IFACE_ACT_ROTATE_ORTO; - break; + return USER_IFACE_ACT_ROTATE_ORTO; case '2': - action = USER_IFACE_ACT_ROTATE; - break; + return USER_IFACE_ACT_ROTATE; case '3': - action = USER_IFACE_ACT_ROTATE_2RECT; - break; + return USER_IFACE_ACT_ROTATE_2RECT; } break; case '2': /* Miscellaneous image transformations */ - ch = wgetch(win_log); + c = wgetch(win_log); - switch (ch) { + switch (c) { case '0': - action = USER_IFACE_ACT_ADAPTIVE_THRESHOLD; - break; + return USER_IFACE_ACT_ADAPTIVE_THRESHOLD; case '1': - action = USER_IFACE_ACT_CVT_COLOR; - break; + return USER_IFACE_ACT_CVT_COLOR; case '2': - action = USER_IFACE_ACT_DISTANCE_TRANSFORM; - break; + return USER_IFACE_ACT_DISTANCE_TRANSFORM; case '3': - action = USER_IFACE_ACT_THRESHOLD; - break; + return USER_IFACE_ACT_THRESHOLD; } break; case '3': /* Histograms */ - ch = wgetch(win_log); + c = wgetch(win_log); - switch (ch) { + switch (c) { case '0': - action = USER_IFACE_ACT_HISTOGRAM; - break; + return USER_IFACE_ACT_HISTOGRAM; case '1': - action = USER_IFACE_ACT_HISTOGRAM_C3; - break; + return USER_IFACE_ACT_HISTOGRAM_C3; } break; case '4': /* Structural analysis and shape descriptors */ - ch = wgetch(win_log); + c = wgetch(win_log); - switch (ch) { + switch (c) { case '0': - action = USER_IFACE_ACT_CONTOURS; - break; + return USER_IFACE_ACT_CONTOURS; case '1': - action = USER_IFACE_ACT_CONTOURS_SIZE; - break; + return USER_IFACE_ACT_CONTOURS_SIZE; case '2': - action = USER_IFACE_ACT_BOUNDING_RECT; - break; + return USER_IFACE_ACT_BOUNDING_RECT; case '3': - action = USER_IFACE_ACT_FIT_ELLIPSE; - break; + return USER_IFACE_ACT_FIT_ELLIPSE; case '4': - action = USER_IFACE_ACT_MIN_AREA_RECT; - break; + return USER_IFACE_ACT_MIN_AREA_RECT; } break; case '5': /* Feature detection */ - ch = wgetch(win_log); + c = wgetch(win_log); - switch (ch) { + switch (c) { case '0': - action = USER_IFACE_ACT_HOUGH_CIRCLES; - break; + return USER_IFACE_ACT_HOUGH_CIRCLES; } break; } @@ -520,96 +452,78 @@ static int usr_input (void) break; case '2': /* img_orb */ - ch = wgetch(win_log); + c = wgetch(win_log); - switch (ch) { + switch (c) { case '0': - action = USER_IFACE_ACT_ALIGN; - break; + return USER_IFACE_ACT_ALIGN; } break; case '3': /* img_calib3d */ - ch = wgetch(win_log); + c = wgetch(win_log); - switch (ch) { + switch (c) { case '0': - action = USER_IFACE_ACT_CALIBRATE; - break; + return USER_IFACE_ACT_CALIBRATE; case '1': - action = USER_IFACE_ACT_UNDISTORT; - break; + return USER_IFACE_ACT_UNDISTORT; } break; case '4': /* img_zbar */ - ch = wgetch(win_log); + c = wgetch(win_log); - switch (ch) { + switch (c) { case '0': - action = USER_IFACE_ACT_DECODE; - break; + return USER_IFACE_ACT_DECODE; } break; case '5': /* img_ocr */ - ch = wgetch(win_log); + c = wgetch(win_log); - switch (ch) { + switch (c) { case '0': - action = USER_IFACE_ACT_READ; - break; + return USER_IFACE_ACT_READ; } break; } break; - case 'l': - action = USER_IFACE_ACT_LOAD_MEM; - break; - + return USER_IFACE_ACT_LOAD_MEM; case 'm': - action = USER_IFACE_ACT_SAVE_MEM; - break; - + return USER_IFACE_ACT_SAVE_MEM; case 'q': - action = USER_IFACE_ACT_QUIT; - break; - + return USER_IFACE_ACT_QUIT; case 'r': - action = USER_IFACE_ACT_SAVE_REF; - break; - + return USER_IFACE_ACT_SAVE_REF; case 's': - action = USER_IFACE_ACT_SAVE_FILE; - break; - + return USER_IFACE_ACT_SAVE_FILE; case 'u': /* User iface actions */ - ch = wgetch(win_log); + c = wgetch(win_log); - switch (ch) { + switch (c) { case '1': - action = USER_IFACE_ACT_SHOW_OCR; - break; + return USER_IFACE_ACT_SHOW_OCR; } break; case 'x': - action = USER_IFACE_ACT_FOO; /* Special sequence "xyzzy" */ - ch = wgetch(win_log); - if (ch == 'y') { - ch = wgetch(win_log); - if (ch == 'z') { + c = wgetch(win_log); + if (c == 'y') { + c = wgetch(win_log); + if (c == 'z') { - ch = wgetch(win_log); - if (ch == 'z') { + c = wgetch(win_log); + if (c == 'z') { - ch = wgetch(win_log); - if (ch == 'y') { - action = USER_IFACE_ACT_FOO; + c = wgetch(win_log); + if (c == 'y') { + return USER_IFACE_ACT_FOO; } } } @@ -617,20 +531,14 @@ static int usr_input (void) break; } - return action; + return USER_IFACE_ACT_FOO; } -/* * * * * * * * * * - * * * Help * * * * * * * - * * * * * * * * * */ static void show_help (void) { - int r; - int c; + int r, c; - /* Clear */ werase(win_help); - r = 0; c = 0; mvwprintw(win_help, r++, c, "Apply: %s", "Space"); @@ -694,8 +602,6 @@ static void show_help (void) mvwprintw(win_help, r++, c, "Other:"); mvwprintw(win_help, r++, c, " - Show OCR: %s", "u1"); mvwprintw(win_help, r++, c, "Quit: %c", 'q'); - - /* Refresh */ wrefresh(win_help); } diff --git a/tmp/Makefile b/tmp/Makefile index a49f078..cd48349 100644 --- a/tmp/Makefile +++ b/tmp/Makefile @@ -1,74 +1,88 @@ -# -*- MakeFile -*- +#! /usr/bin/make -f -# MACRO = substitute with this +################################################################################ +# 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" +################################################################################ -# directories +################################################################################ +# dependencies -LIBALX_INC_DIR = $(LIBALX_DIR)/inc/ +OBJ = \ + main.o -ABOUT_DIR = $(MODULES_DIR)/about/ -ABOUT_INC_DIR = $(ABOUT_DIR)/inc/ +MAIN_INC = \ + $(LIBALX_INC_DIR)/libalx/base/stdio/wait.hpp \ + $(LIBALX_INC_DIR)/libalx/extra/ncurses/common.hpp \ + $(INC_DIR)/vision-artificial/about/about.hpp \ + $(INC_DIR)/vision-artificial/image/iface.h \ + $(INC_DIR)/vision-artificial/menu/iface.h \ + $(INC_DIR)/vision-artificial/menu/parse.h \ + $(INC_DIR)/vision-artificial/user/iface.h \ + $(INC_DIR)/vision-artificial/save/save.h +MAIN_SRC = \ + $(SRC_DIR)/main.cpp -CTRL_DIR = $(MODULES_DIR)/ctrl/ -CTRL_INC_DIR = $(CTRL_DIR)/inc/ -IMG_DIR = $(MODULES_DIR)/image/ -IMG_INC_DIR = $(IMG_DIR)/inc/ +# target: dependencies +# action -MENU_DIR = $(MODULES_DIR)/menu/ -MENU_INC_DIR = $(MENU_DIR)/inc/ +PHONY := all +all: $(OBJ) about ctrl image menu proc save user -SAVE_DIR = $(MODULES_DIR)/save/ -SAVE_INC_DIR = $(SAVE_DIR)/inc/ -USR_DIR = $(MODULES_DIR)/user/ -USR_INC_DIR = $(USR_DIR)/inc/ +PHONY += about +about: + @echo " MAKE tmp/about" + $(Q)$(MAKE) -C $(TMP_DIR)/about/ -SRC_DIR = $(MAIN_DIR)/src/ +PHONY += ctrl +ctrl: + @echo " MAKE tmp/ctrl" + $(Q)$(MAKE) -C $(TMP_DIR)/ctrl/ -# dependencies +PHONY += image +image: + @echo " MAKE tmp/image" + $(Q)$(MAKE) -C $(TMP_DIR)/image/ -ALL = main.o - -MAIN_INC_LIBALX = libalx/curses/alx_ncur.hpp -MAIN_INC_ABOUT = about.hpp -MAIN_INC_IMG = img_iface.hpp -MAIN_INC_MENU = parser.hpp menu_iface.hpp -MAIN_INC_SAVE = save.hpp -MAIN_INC_USR = user_iface.hpp -MAIN_DEPS = $(SRC_DIR)/main.cpp \ - $(patsubst %,$(LIBALX_INC_DIR)/%,$(MAIN_INC_LIBALX)) \ - $(patsubst %,$(ABOUT_INC_DIR)/%,$(MAIN_INC_ABOUT)) \ - $(patsubst %,$(IMG_INC_DIR)/%,$(MAIN_INC_IMG)) \ - $(patsubst %,$(MENU_INC_DIR)/%,$(MAIN_INC_MENU)) \ - $(patsubst %,$(SAVE_INC_DIR)/%,$(MAIN_INC_SAVE)) \ - $(patsubst %,$(USR_INC_DIR)/%,$(MAIN_INC_USR)) -MAIN_INC_DIRS = -I $(LIBALX_INC_DIR) \ - -I $(ABOUT_INC_DIR) \ - -I $(IMG_INC_DIR) \ - -I $(MENU_INC_DIR) \ - -I $(SAVE_INC_DIR) \ - -I $(USR_INC_DIR) +PHONY += menu +menu: + @echo " MAKE tmp/menu" + $(Q)$(MAKE) -C $(TMP_DIR)/menu/ +PHONY += proc +proc: + @echo " MAKE tmp/proc" + $(Q)$(MAKE) -C $(TMP_DIR)/proc/ -# target: dependencies -# action +PHONY += save +save: + @echo " MAKE tmp/save" + $(Q)$(MAKE) -C $(TMP_DIR)/save/ + +PHONY += user +user: + @echo " MAKE tmp/user" + $(Q)$(MAKE) -C $(TMP_DIR)/user/ -PHONY := all -all: $(ALL) -main.s: $(MAIN_DEPS) - @echo " CXX $@" - $(Q)$(CXX) $(CXXFLAGS) $(MAIN_INC_DIRS) -S $< -o $@ +main.s: $(MAIN_SRC) $(MAIN_INC) + @echo " CXX vision-artificial/tmp/$@" + $(Q)$(CXX) $(CXXFLAGS) -I $(INC_DIR) -S $< -o $@ main.o: main.s - @echo " AS $@" + @echo " AS vision-artificial/tmp/$@" $(Q)$(AS) $< -o $@ PHONY += clean clean: @echo " RM *.o *.s" - $(Q)rm -f *.o *.s + $(Q)rm -f *.o *.s ################################################################################ # Declare the contents of the .PHONY variable as phony. diff --git a/tmp/about/Makefile b/tmp/about/Makefile new file mode 100644 index 0000000..36f47a2 --- /dev/null +++ b/tmp/about/Makefile @@ -0,0 +1,53 @@ +#! /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 = \ + about.o + +ABOUT_INC = \ + $(INC_DIR)/vision-artificial/about/about.h \ + $(LIBALX_INC_DIR)/libalx/base/errno/errno_str.h \ + $(LIBALX_INC_DIR)/libalx/base/stdio/sprint_file.h +ABOUT_SRC = \ + $(SRC_DIR)/about/about.c + +################################################################################ +# target: dependencies +# action + +PHONY := all +all: $(OBJ) + + +about.s: $(ABOUT_SRC) $(ABOUT_INC) + @echo " CC vision-artificial/about/$@" + $(Q)$(CC) $(CFLAGS) -I $(INC_DIR) -S $< -o $@ +about.o: about.s + @echo " AS vision-artificial/about/$@" + $(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/ctrl/Makefile b/tmp/ctrl/Makefile new file mode 100644 index 0000000..da57c66 --- /dev/null +++ b/tmp/ctrl/Makefile @@ -0,0 +1,54 @@ +#! /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 = \ + start.o + +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 = \ + $(SRC_DIR)/ctrl/start.c + +################################################################################ +# target: dependencies +# action + +PHONY := all +all: $(OBJ) + + +start.s: $(START_SRC) $(START_INC) + @echo " CC vision-artificial/ctrl/$@" + $(Q)$(CC) $(CFLAGS) -I $(INC_DIR) -S $< -o $@ +start.o: start.s + @echo " AS vision-artificial/ctrl/$@" + $(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/image/Makefile b/tmp/image/Makefile new file mode 100644 index 0000000..951f7db --- /dev/null +++ b/tmp/image/Makefile @@ -0,0 +1,145 @@ +#! /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 = \ + alx.o \ + calib3d.o \ + cv.o \ + iface.o \ + ocr.o \ + orb.o \ + zbar.o + +ALX_INC = \ + $(INC_DIR)/vision-artificial/image/alx.hpp \ + $(LIBALX_INC_DIR)/libalx/base/math/arithmetic_mean.hpp \ + $(LIBALX_INC_DIR)/libalx/base/math/median.hpp \ + $(INC_DIR)/vision-artificial/image/iface.hpp +ALX_SRC = \ + $(SRC_DIR)/image/alx.cpp + +CALIB3D_INC = \ + $(INC_DIR)/vision-artificial/image/calib3d.hpp \ + $(INC_DIR)/vision-artificial/image/iface.hpp +CALIB3D_SRC = \ + $(SRC_DIR)/image/calib3d.cpp + +CV_INC = \ + $(INC_DIR)/vision-artificial/image/cv.hpp \ + $(INC_DIR)/vision-artificial/image/iface.hpp +CV_SRC = \ + $(SRC_DIR)/image/cv.cpp + +IFACE_INC = \ + $(INC_DIR)/vision-artificial/image/iface.hpp \ + $(INC_DIR)/vision-artificial/image/alx.hpp \ + $(INC_DIR)/vision-artificial/image/calib3d.hpp \ + $(INC_DIR)/vision-artificial/image/cv.hpp \ + $(INC_DIR)/vision-artificial/image/ocr.hpp \ + $(INC_DIR)/vision-artificial/image/orb.hpp \ + $(INC_DIR)/vision-artificial/image/zbar.hpp \ + $(INC_DIR)/vision-artificial/save/save.hpp \ + $(INC_DIR)/vision-artificial/user/iface.hpp +IFACE_SRC = \ + $(SRC_DIR)/image/iface.cpp + +OCR_INC = \ + $(INC_DIR)/vision-artificial/image/ocr.h \ + $(INC_DIR)/vision-artificial/about/about.h \ + $(INC_DIR)/vision-artificial/image/iface.h +OCR_SRC = \ + $(SRC_DIR)/image/ocr.c + +ORB_INC = \ + $(INC_DIR)/vision-artificial/image/orb.hpp +ORB_SRC = \ + $(SRC_DIR)/image/orb.cpp + +ZBAR_INC = \ + $(INC_DIR)/vision-artificial/image/zbar.hpp \ + $(INC_DIR)/vision-artificial/image/iface.hpp +ZBAR_SRC = \ + $(SRC_DIR)/image/zbar.cpp + +################################################################################ +# target: dependencies +# action + +PHONY := all +all: $(OBJ) + + +alx.s: $(ALX_SRC) $(ALX_INC) + @echo " CXX vision-artificial/image/$@" + $(Q)$(CXX) $(CXXFLAGS) -I $(INC_DIR) -S $< -o $@ +alx.o: alx.s + @echo " AS vision-artificial/image/$@" + $(Q)$(AS) $< -o $@ + +calib3d.s: $(CALIB3D_SRC) $(CALIB3D_INC) + @echo " CXX vision-artificial/image/$@" + $(Q)$(CXX) $(CXXFLAGS) -I $(INC_DIR) -S $< -o $@ +calib3d.o: calib3d.s + @echo " AS vision-artificial/image/$@" + $(Q)$(AS) $< -o $@ + +cv.s: $(CV_SRC) $(CV_INC) + @echo " CXX vision-artificial/image/$@" + $(Q)$(CXX) $(CXXFLAGS) -I $(INC_DIR) -S $< -o $@ +cv.o: cv.s + @echo " AS vision-artificial/image/$@" + $(Q)$(AS) $< -o $@ + +iface.s: $(IFACE_SRC) $(IFACE_INC) + @echo " CXX vision-artificial/image/$@" + $(Q)$(CXX) $(CXXFLAGS) -I $(INC_DIR) -S $< -o $@ +iface.o: iface.s + @echo " AS vision-artificial/image/$@" + $(Q)$(AS) $< -o $@ + +ocr.s: $(OCR_SRC) $(OCR_INC) + @echo " CC vision-artificial/image/$@" + $(Q)$(CC) $(CFLAGS) -I $(INC_DIR) -S $< -o $@ +ocr.o: ocr.s + @echo " AS vision-artificial/image/$@" + $(Q)$(AS) $< -o $@ + +orb.s: $(ORB_SRC) $(ORB_INC) + @echo " CXX vision-artificial/image/$@" + $(Q)$(CXX) $(CXXFLAGS) -I $(INC_DIR) -S $< -o $@ +orb.o: orb.s + @echo " AS vision-artificial/image/$@" + $(Q)$(AS) $< -o $@ + +zbar.s: $(ZBAR_SRC) $(ZBAR_INC) + @echo " CXX vision-artificial/image/$@" + $(Q)$(CXX) $(CXXFLAGS) -I $(INC_DIR) -S $< -o $@ +zbar.o: zbar.s + @echo " AS vision-artificial/image/$@" + $(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/menu/Makefile b/tmp/menu/Makefile new file mode 100644 index 0000000..31849bb --- /dev/null +++ b/tmp/menu/Makefile @@ -0,0 +1,110 @@ +#! /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 = \ + clui.o \ + iface.o \ + parse.o \ + tui.o + +CLUI_INC = \ + $(INC_DIR)/vision-artificial/menu/clui.h \ + $(LIBALX_INC_DIR)/libalx/base/stdio/get.h \ + $(INC_DIR)/vision-artificial/about/about.h \ + $(INC_DIR)/vision-artificial/ctrl/start.h +CLUI_SRC = \ + $(SRC_DIR)/menu/clui.c + +IFACE_INC = \ + $(INC_DIR)/vision-artificial/menu/iface.h \ + $(INC_DIR)/vision-artificial/menu/clui.h \ + $(INC_DIR)/vision-artificial/menu/tui.h +IFACE_SRC = \ + $(SRC_DIR)/menu/iface.c + +PARSE_INC = \ + $(INC_DIR)/vision-artificial/menu/parse.h \ + $(LIBALX_INC_DIR)/libalx/base/stdio/sscan.h \ + $(INC_DIR)/vision-artificial/about/about.h \ + $(INC_DIR)/vision-artificial/menu/iface.h \ + $(INC_DIR)/vision-artificial/save/save.h \ + $(INC_DIR)/vision-artificial/user/iface.h +PARSE_SRC = \ + $(SRC_DIR)/menu/parse.c + +TUI_INC = \ + $(INC_DIR)/vision-artificial/menu/tui.h \ + $(LIBALX_INC_DIR)/libalx/base/stddef/size.h \ + $(LIBALX_INC_DIR)/libalx/base/stdio/wait.h \ + $(LIBALX_INC_DIR)/libalx/extra/ncurses/common.h \ + $(LIBALX_INC_DIR)/libalx/extra/ncurses/get.h \ + $(LIBALX_INC_DIR)/libalx/extra/ncurses/menu.h \ + $(INC_DIR)/vision-artificial/about/about.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/user/iface.h +TUI_SRC = \ + $(SRC_DIR)/menu/tui.c + +################################################################################ +# target: dependencies +# action + +PHONY := all +all: $(OBJ) + + +clui.s: $(CLUI_SRC) $(CLUI_INC) + @echo " CC vision-artificial/menu/$@" + $(Q)$(CC) $(CFLAGS) -I $(INC_DIR) -S $< -o $@ +clui.o: clui.s + @echo " AS vision-artificial/menu/$@" + $(Q)$(AS) $< -o $@ + +iface.s: $(IFACE_SRC) $(IFACE_INC) + @echo " CXX vision-artificial/menu/$@" + $(Q)$(CC) $(CFLAGS) -I $(INC_DIR) -S $< -o $@ +iface.o: iface.s + @echo " AS vision-artificial/menu/$@" + $(Q)$(AS) $< -o $@ + +parse.s: $(PARSE_SRC) $(PARSE_INC) + @echo " CC vision-artificial/menu/$@" + $(Q)$(CC) $(CFLAGS) -I $(INC_DIR) -S $< -o $@ +parse.o: parse.s + @echo " AS vision-artificial/menu/$@" + $(Q)$(AS) $< -o $@ + +tui.s: $(TUI_SRC) $(TUI_INC) + @echo " CC vision-artificial/menu/$@" + $(Q)$(CC) $(CFLAGS) -I $(INC_DIR) -S $< -o $@ +tui.o: tui.s + @echo " AS vision-artificial/menu/$@" + $(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/proc/Makefile b/tmp/proc/Makefile new file mode 100644 index 0000000..b5e9577 --- /dev/null +++ b/tmp/proc/Makefile @@ -0,0 +1,167 @@ +#! /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 = \ + coins.o \ + common.o \ + iface.o \ + label.o \ + lighters.o \ + objects.o \ + resistor.o + +COINS_INC = \ + $(INC_DIR)/vision-artificial/proc/coins.hpp \ + $(LIBALX_INC_DIR)/libalx/base/math/arithmetic_mean.hpp \ + $(LIBALX_INC_DIR)/libalx/base/stddef/size.hpp \ + $(LIBALX_INC_DIR)/libalx/base/stdlib/maximum.hpp \ + $(INC_DIR)/vision-artificial/image/iface.hpp \ + $(INC_DIR)/vision-artificial/proc/common.hpp \ + $(INC_DIR)/vision-artificial/user/iface.hpp +COINS_SRC = \ + $(SRC_DIR)/proc/coins.cpp + +COMMON_INC = \ + $(INC_DIR)/vision-artificial/proc/common.hpp \ + $(LIBALX_INC_DIR)/libalx/base/stdio/wait.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/stddef/size.h \ + $(LIBALX_INC_DIR)/libalx/base/stdio/sscan.h \ + $(LIBALX_INC_DIR)/libalx/base/stdio/wait.h \ + $(INC_DIR)/vision-artificial/image/iface.h \ + $(INC_DIR)/vision-artificial/proc/coins.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/base/math/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/stddef/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/save/Makefile b/tmp/save/Makefile new file mode 100644 index 0000000..50546a5 --- /dev/null +++ b/tmp/save/Makefile @@ -0,0 +1,54 @@ +#! /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 = \ + save.o + +SAVE_INC = \ + $(INC_DIR)/vision-artificial/save/save.hpp \ + $(LIBALX_INC_DIR)/libalx/base/errno/errno_str.hpp \ + $(LIBALX_INC_DIR)/libalx/base/stddef/restrict.hpp \ + $(INC_DIR)/vision-artificial/user/iface.hpp +SAVE_SRC = \ + $(SRC_DIR)/save/save.cpp + +################################################################################ +# target: dependencies +# action + +PHONY := all +all: $(OBJ) + + +save.s: $(SAVE_SRC) $(SAVE_INC) + @echo " CC vision-artificial/save/$@" + $(Q)$(CXX) $(CXXFLAGS) -I $(INC_DIR) -S $< -o $@ +save.o: save.s + @echo " AS vision-artificial/save/$@" + $(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 new file mode 100644 index 0000000..e06b3db --- /dev/null +++ b/tmp/user/Makefile @@ -0,0 +1,92 @@ +#! /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 = \ + clui.o \ + iface.o \ + tui.o + +CLUI_INC = \ + $(INC_DIR)/vision-artificial/user/clui.h \ + $(LIBALX_INC_DIR)/libalx/base/stdlib/swap.h \ + $(LIBALX_INC_DIR)/libalx/base/stdio/get.h \ + $(LIBALX_INC_DIR)/libalx/base/stdio/wait.h \ + $(INC_DIR)/vision-artificial/image/iface.h \ + $(INC_DIR)/vision-artificial/user/iface.h +CLUI_SRC = \ + $(SRC_DIR)/user/clui.c + +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/clui.h \ + $(INC_DIR)/vision-artificial/user/tui.h +IFACE_SRC = \ + $(SRC_DIR)/user/iface.c + +TUI_INC = \ + $(INC_DIR)/vision-artificial/user/tui.h \ + $(LIBALX_INC_DIR)/libalx/base/stdio/wait.h \ + $(LIBALX_INC_DIR)/libalx/extra/ncurses/common.h \ + $(LIBALX_INC_DIR)/libalx/extra/ncurses/get.h \ + $(INC_DIR)/vision-artificial/image/iface.h \ + $(INC_DIR)/vision-artificial/user/iface.h +TUI_SRC = \ + $(SRC_DIR)/user/tui.c + +################################################################################ +# target: dependencies +# action + +PHONY := all +all: $(OBJ) + + +clui.s: $(CLUI_SRC) $(CLUI_INC) + @echo " CC vision-artificial/user/$@" + $(Q)$(CC) $(CFLAGS) -I $(INC_DIR) -S $< -o $@ +clui.o: clui.s + @echo " AS vision-artificial/user/$@" + $(Q)$(AS) $< -o $@ + +iface.s: $(IFACE_SRC) $(IFACE_INC) + @echo " CC vision-artificial/user/$@" + $(Q)$(CC) $(CFLAGS) -I $(INC_DIR) -S $< -o $@ +iface.o: iface.s + @echo " AS vision-artificial/user/$@" + $(Q)$(AS) $< -o $@ + +tui.s: $(TUI_SRC) $(TUI_INC) + @echo " CC vision-artificial/user/$@" + $(Q)$(CC) $(CFLAGS) -I $(INC_DIR) -S $< -o $@ +tui.o: tui.s + @echo " AS vision-artificial/user/$@" + $(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 ########################################################### +################################################################################ |