summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex <colomar.6.4.3@gmail.com>2019-04-07 19:08:33 +0100
committerAlex <colomar.6.4.3@gmail.com>2019-04-07 19:08:33 +0100
commite04ff83a5a25f7537bb452280d515c1a356a8f19 (patch)
treec8c416b35c56d11c9899c414f6bf6b8826578e1c
parentaffb9f327c0b4469d0c4acae9680f713021cf6be (diff)
parent667ea210f5423a3ccc7fb806087688df24271a2f (diff)
Merge branch 'master' into 2v2.12
-rw-r--r--.gitignore2
-rw-r--r--.gitmodules2
-rw-r--r--COPYING.txt10
-rwxr-xr-xCheckstyle/checkpatch.pl6720
-rwxr-xr-xCheckstyle/checkstyle52
-rw-r--r--Checkstyle/spelling.txt1344
-rw-r--r--Makefile188
-rw-r--r--bin/Makefile79
-rw-r--r--inc/vision-artificial/about/about.h79
-rw-r--r--inc/vision-artificial/about/about.hpp84
-rw-r--r--inc/vision-artificial/ctrl/start.h (renamed from modules/proc/inc/proc_resistor.hpp)126
-rw-r--r--inc/vision-artificial/image/alx.hpp77
-rw-r--r--inc/vision-artificial/image/calib3d.hpp71
-rw-r--r--inc/vision-artificial/image/cv.hpp (renamed from modules/image/inc/img_alx.hpp)122
-rw-r--r--inc/vision-artificial/image/iface.h191
-rw-r--r--inc/vision-artificial/image/iface.hpp333
-rw-r--r--inc/vision-artificial/image/ocr.h64
-rw-r--r--inc/vision-artificial/image/ocr.hpp (renamed from modules/proc/inc/proc_iface.hpp)138
-rw-r--r--inc/vision-artificial/image/orb.hpp71
-rw-r--r--inc/vision-artificial/image/zbar.hpp70
-rw-r--r--inc/vision-artificial/menu/clui.h63
-rw-r--r--inc/vision-artificial/menu/iface.h (renamed from modules/about/inc/about.hpp)144
-rw-r--r--inc/vision-artificial/menu/iface.hpp72
-rw-r--r--inc/vision-artificial/menu/parse.h63
-rw-r--r--inc/vision-artificial/menu/parse.hpp66
-rw-r--r--inc/vision-artificial/menu/tui.h63
-rw-r--r--inc/vision-artificial/proc/coins.h69
-rw-r--r--inc/vision-artificial/proc/coins.hpp72
-rw-r--r--inc/vision-artificial/proc/common.h65
-rw-r--r--inc/vision-artificial/proc/common.hpp127
-rw-r--r--inc/vision-artificial/proc/iface.h88
-rw-r--r--inc/vision-artificial/proc/iface.hpp91
-rw-r--r--inc/vision-artificial/proc/label.h71
-rw-r--r--inc/vision-artificial/proc/label.hpp74
-rw-r--r--inc/vision-artificial/proc/lighters.h68
-rw-r--r--inc/vision-artificial/proc/lighters.hpp71
-rw-r--r--inc/vision-artificial/proc/objects.h70
-rw-r--r--inc/vision-artificial/proc/objects.hpp73
-rw-r--r--inc/vision-artificial/proc/resistor.h71
-rw-r--r--inc/vision-artificial/proc/resistor.hpp74
-rw-r--r--inc/vision-artificial/save/save.h99
-rw-r--r--inc/vision-artificial/save/save.hpp (renamed from modules/save/inc/save.hpp)192
-rw-r--r--inc/vision-artificial/user/clui.h (renamed from modules/proc/inc/proc_label.hpp)121
-rw-r--r--inc/vision-artificial/user/iface.h182
-rw-r--r--inc/vision-artificial/user/iface.hpp187
-rw-r--r--inc/vision-artificial/user/tui.h67
m---------libalx0
-rw-r--r--modules/Makefile49
-rw-r--r--modules/about/Makefile20
-rw-r--r--modules/about/inc/about.h63
-rw-r--r--modules/about/src/about.c88
-rw-r--r--modules/about/tmp/Makefile50
-rw-r--r--modules/ctrl/Makefile24
-rw-r--r--modules/ctrl/inc/start.h43
-rw-r--r--modules/ctrl/tmp/Makefile58
-rw-r--r--modules/image/Makefile20
-rw-r--r--modules/image/inc/img_cv.hpp68
-rw-r--r--modules/image/inc/img_iface.h170
-rw-r--r--modules/image/inc/img_iface.hpp295
-rw-r--r--modules/image/inc/img_ocr.h38
-rw-r--r--modules/image/inc/img_ocr.hpp50
-rw-r--r--modules/image/inc/img_orb.hpp58
-rw-r--r--modules/image/inc/img_zbar.hpp46
-rw-r--r--modules/image/src/img_alx.cpp298
-rw-r--r--modules/image/src/img_cv.cpp792
-rw-r--r--modules/image/src/img_iface.cpp1776
-rw-r--r--modules/image/src/img_zbar.cpp101
-rw-r--r--modules/image/tmp/Makefile120
-rw-r--r--modules/menu/Makefile24
-rw-r--r--modules/menu/inc/menu_clui.h27
-rw-r--r--modules/menu/inc/menu_iface.h43
-rw-r--r--modules/menu/inc/menu_iface.hpp55
-rw-r--r--modules/menu/inc/menu_tui.h27
-rw-r--r--modules/menu/inc/parser.h27
-rw-r--r--modules/menu/inc/parser.hpp39
-rw-r--r--modules/menu/src/menu_clui.c116
-rw-r--r--modules/menu/src/menu_iface.c45
-rw-r--r--modules/menu/src/menu_tui.c331
-rw-r--r--modules/menu/tmp/Makefile124
-rw-r--r--modules/proc/Makefile20
-rw-r--r--modules/proc/inc/proc_coins.h47
-rw-r--r--modules/proc/inc/proc_common.h45
-rw-r--r--modules/proc/inc/proc_common.hpp108
-rw-r--r--modules/proc/inc/proc_iface.h60
-rw-r--r--modules/proc/inc/proc_label.h50
-rw-r--r--modules/proc/inc/proc_resistor.h50
-rw-r--r--modules/proc/src/proc_coins.cpp137
-rw-r--r--modules/proc/src/proc_common.cpp381
-rw-r--r--modules/proc/src/proc_iface.c185
-rw-r--r--modules/proc/src/proc_label.cpp386
-rw-r--r--modules/proc/tmp/Makefile131
-rw-r--r--modules/save/Makefile24
-rw-r--r--modules/save/inc/save.h70
-rw-r--r--modules/save/src/save.cpp190
-rw-r--r--modules/save/tmp/Makefile46
-rw-r--r--modules/tmp/Makefile47
-rw-r--r--modules/user/Makefile20
-rw-r--r--modules/user/inc/user_clui.h30
-rw-r--r--modules/user/inc/user_iface.h150
-rw-r--r--modules/user/inc/user_iface.hpp162
-rw-r--r--modules/user/inc/user_tui.h36
-rw-r--r--modules/user/src/user_clui.c563
-rw-r--r--modules/user/src/user_tui.c706
-rw-r--r--modules/user/tmp/Makefile90
-rw-r--r--share/vision-artificial/COPYRIGHT.txt (renamed from share/COPYRIGHT.txt)0
-rw-r--r--share/vision-artificial/DISCLAIMER.txt (renamed from share/DISCLAIMER.txt)0
-rw-r--r--share/vision-artificial/HELP.txt (renamed from share/HELP.txt)0
-rw-r--r--share/vision-artificial/LICENSE.txt (renamed from share/LICENSE.txt)10
-rw-r--r--share/vision-artificial/README.txt (renamed from share/README.txt)0
-rw-r--r--share/vision-artificial/USAGE.txt (renamed from share/USAGE.txt)0
-rw-r--r--share/vision-artificial/price (renamed from share/price)0
-rw-r--r--src/about/about.c144
-rw-r--r--src/ctrl/start.c (renamed from modules/ctrl/src/start.c)204
-rw-r--r--src/image/alx.cpp430
-rw-r--r--src/image/calib3d.cpp125
-rw-r--r--src/image/cv.cpp802
-rw-r--r--src/image/iface.cpp1489
-rw-r--r--src/image/ocr.c (renamed from modules/image/src/img_ocr.c)272
-rw-r--r--src/image/orb.cpp (renamed from modules/image/src/img_orb.cpp)262
-rw-r--r--src/image/zbar.cpp122
-rw-r--r--src/main.cpp168
-rw-r--r--src/menu/clui.c125
-rw-r--r--src/menu/iface.c (renamed from modules/proc/inc/proc_coins.hpp)127
-rw-r--r--src/menu/parse.c (renamed from modules/menu/src/parser.c)292
-rw-r--r--src/menu/tui.c315
-rw-r--r--src/proc/coins.cpp291
-rw-r--r--src/proc/common.cpp461
-rw-r--r--src/proc/iface.c224
-rw-r--r--src/proc/label.cpp295
-rw-r--r--src/proc/lighters.cpp426
-rw-r--r--src/proc/objects.cpp550
-rw-r--r--src/proc/resistor.cpp (renamed from modules/proc/src/proc_resistor.cpp)2696
-rw-r--r--src/save/save.cpp280
-rw-r--r--src/user/clui.c471
-rw-r--r--src/user/iface.c (renamed from modules/user/src/user_iface.c)452
-rw-r--r--src/user/tui.c611
-rw-r--r--tmp/Makefile122
-rw-r--r--tmp/about/Makefile53
-rw-r--r--tmp/ctrl/Makefile54
-rw-r--r--tmp/image/Makefile145
-rw-r--r--tmp/menu/Makefile110
-rw-r--r--tmp/proc/Makefile167
-rw-r--r--tmp/save/Makefile54
-rw-r--r--tmp/user/Makefile92
144 files changed, 21814 insertions, 11672 deletions
diff --git a/.gitignore b/.gitignore
index 40bf91d..f04b795 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,4 @@
*.o
*.s
*.a
-bin/vision-artificial2
+bin/vision-artificial*
diff --git a/.gitmodules b/.gitmodules
index ed38291..3f28722 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,3 +1,3 @@
[submodule "libalx"]
path = libalx
- url = https://github.com/AlejandroColomar/libalx
+ url = https://github.com/alejandro-colomar/libalx
diff --git a/COPYING.txt b/COPYING.txt
index 9e98b13..0776f74 100644
--- a/COPYING.txt
+++ b/COPYING.txt
@@ -67,7 +67,7 @@ patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
-
+
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
@@ -122,7 +122,7 @@ above, provided that you also meet all of these conditions:
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
-
+
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
@@ -180,7 +180,7 @@ access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
-
+
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
@@ -237,7 +237,7 @@ impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
-
+
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
@@ -290,7 +290,7 @@ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
-
+
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
diff --git a/Checkstyle/checkpatch.pl b/Checkstyle/checkpatch.pl
new file mode 100755
index 0000000..b737ca9
--- /dev/null
+++ b/Checkstyle/checkpatch.pl
@@ -0,0 +1,6720 @@
+#!/usr/bin/env perl
+# SPDX-License-Identifier: GPL-2.0
+#
+# (c) 2001, Dave Jones. (the file handling bit)
+# (c) 2005, Joel Schopp <jschopp@austin.ibm.com> (the ugly bit)
+# (c) 2007,2008, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test suite)
+# (c) 2008-2010 Andy Whitcroft <apw@canonical.com>
+# (c) 2010-2018 Joe Perches <joe@perches.com>
+
+use strict;
+use warnings;
+use POSIX;
+use File::Basename;
+use Cwd 'abs_path';
+use Term::ANSIColor qw(:constants);
+use Encode qw(decode encode);
+
+my $P = $0;
+my $D = dirname(abs_path($P));
+
+my $V = '0.32';
+
+use Getopt::Long qw(:config no_auto_abbrev);
+
+my $quiet = 0;
+my $tree = 1;
+my $chk_signoff = 1;
+my $chk_patch = 1;
+my $tst_only;
+my $emacs = 0;
+my $terse = 0;
+my $showfile = 0;
+my $file = 0;
+my $git = 0;
+my %git_commits = ();
+my $check = 0;
+my $check_orig = 0;
+my $summary = 1;
+my $mailback = 0;
+my $summary_file = 0;
+my $show_types = 0;
+my $list_types = 0;
+my $fix = 0;
+my $fix_inplace = 0;
+my $root;
+my %debug;
+my %camelcase = ();
+my %use_type = ();
+my @use = ();
+my %ignore_type = ();
+my @ignore = ();
+my $help = 0;
+my $configuration_file = ".checkpatch.conf";
+my $max_line_length = 80;
+my $ignore_perl_version = 0;
+my $minimum_perl_version = 5.10.0;
+my $min_conf_desc_length = 4;
+my $spelling_file = "$D/spelling.txt";
+my $codespell = 0;
+my $codespellfile = "/usr/share/codespell/dictionary.txt";
+my $conststructsfile = "$D/const_structs.checkpatch";
+my $typedefsfile = "";
+my $color = "auto";
+my $allow_c99_comments = 1;
+
+sub help {
+ my ($exitcode) = @_;
+
+ print << "EOM";
+Usage: $P [OPTION]... [FILE]...
+Version: $V
+
+Options:
+ -q, --quiet quiet
+ --no-tree run without a kernel tree
+ --no-signoff do not check for 'Signed-off-by' line
+ --patch treat FILE as patchfile (default)
+ --emacs emacs compile window format
+ --terse one line per report
+ --showfile emit diffed file position, not input file position
+ -g, --git treat FILE as a single commit or git revision range
+ single git commit with:
+ <rev>
+ <rev>^
+ <rev>~n
+ multiple git commits with:
+ <rev1>..<rev2>
+ <rev1>...<rev2>
+ <rev>-<count>
+ git merges are ignored
+ -f, --file treat FILE as regular source file
+ --subjective, --strict enable more subjective tests
+ --list-types list the possible message types
+ --types TYPE(,TYPE2...) show only these comma separated message types
+ --ignore TYPE(,TYPE2...) ignore various comma separated message types
+ --show-types show the specific message type in the output
+ --max-line-length=n set the maximum line length, if exceeded, warn
+ --min-conf-desc-length=n set the min description length, if shorter, warn
+ --root=PATH PATH to the kernel tree root
+ --no-summary suppress the per-file summary
+ --mailback only produce a report in case of warnings/errors
+ --summary-file include the filename in summary
+ --debug KEY=[0|1] turn on/off debugging of KEY, where KEY is one of
+ 'values', 'possible', 'type', and 'attr' (default
+ is all off)
+ --test-only=WORD report only warnings/errors containing WORD
+ literally
+ --fix EXPERIMENTAL - may create horrible results
+ If correctable single-line errors exist, create
+ "<inputfile>.EXPERIMENTAL-checkpatch-fixes"
+ with potential errors corrected to the preferred
+ checkpatch style
+ --fix-inplace EXPERIMENTAL - may create horrible results
+ Is the same as --fix, but overwrites the input
+ file. It's your fault if there's no backup or git
+ --ignore-perl-version override checking of perl version. expect
+ runtime errors.
+ --codespell Use the codespell dictionary for spelling/typos
+ (default:/usr/share/codespell/dictionary.txt)
+ --codespellfile Use this codespell dictionary
+ --typedefsfile Read additional types from this file
+ --color[=WHEN] Use colors 'always', 'never', or only when output
+ is a terminal ('auto'). Default is 'auto'.
+ -h, --help, --version display this help and exit
+
+When FILE is - read standard input.
+EOM
+
+ exit($exitcode);
+}
+
+sub uniq {
+ my %seen;
+ return grep { !$seen{$_}++ } @_;
+}
+
+sub list_types {
+ my ($exitcode) = @_;
+
+ my $count = 0;
+
+ local $/ = undef;
+
+ open(my $script, '<', abs_path($P)) or
+ die "$P: Can't read '$P' $!\n";
+
+ my $text = <$script>;
+ close($script);
+
+ my @types = ();
+ # Also catch when type or level is passed through a variable
+ for ($text =~ /(?:(?:\bCHK|\bWARN|\bERROR|&\{\$msg_level})\s*\(|\$msg_type\s*=)\s*"([^"]+)"/g) {
+ push (@types, $_);
+ }
+ @types = sort(uniq(@types));
+ print("#\tMessage type\n\n");
+ foreach my $type (@types) {
+ print(++$count . "\t" . $type . "\n");
+ }
+
+ exit($exitcode);
+}
+
+my $conf = which_conf($configuration_file);
+if (-f $conf) {
+ my @conf_args;
+ open(my $conffile, '<', "$conf")
+ or warn "$P: Can't find a readable $configuration_file file $!\n";
+
+ while (<$conffile>) {
+ my $line = $_;
+
+ $line =~ s/\s*\n?$//g;
+ $line =~ s/^\s*//g;
+ $line =~ s/\s+/ /g;
+
+ next if ($line =~ m/^\s*#/);
+ next if ($line =~ m/^\s*$/);
+
+ my @words = split(" ", $line);
+ foreach my $word (@words) {
+ last if ($word =~ m/^#/);
+ push (@conf_args, $word);
+ }
+ }
+ close($conffile);
+ unshift(@ARGV, @conf_args) if @conf_args;
+}
+
+# Perl's Getopt::Long allows options to take optional arguments after a space.
+# Prevent --color by itself from consuming other arguments
+foreach (@ARGV) {
+ if ($_ eq "--color" || $_ eq "-color") {
+ $_ = "--color=$color";
+ }
+}
+
+GetOptions(
+ 'q|quiet+' => \$quiet,
+ 'tree!' => \$tree,
+ 'signoff!' => \$chk_signoff,
+ 'patch!' => \$chk_patch,
+ 'emacs!' => \$emacs,
+ 'terse!' => \$terse,
+ 'showfile!' => \$showfile,
+ 'f|file!' => \$file,
+ 'g|git!' => \$git,
+ 'subjective!' => \$check,
+ 'strict!' => \$check,
+ 'ignore=s' => \@ignore,
+ 'types=s' => \@use,
+ 'show-types!' => \$show_types,
+ 'list-types!' => \$list_types,
+ 'max-line-length=i' => \$max_line_length,
+ 'min-conf-desc-length=i' => \$min_conf_desc_length,
+ 'root=s' => \$root,
+ 'summary!' => \$summary,
+ 'mailback!' => \$mailback,
+ 'summary-file!' => \$summary_file,
+ 'fix!' => \$fix,
+ 'fix-inplace!' => \$fix_inplace,
+ 'ignore-perl-version!' => \$ignore_perl_version,
+ 'debug=s' => \%debug,
+ 'test-only=s' => \$tst_only,
+ 'codespell!' => \$codespell,
+ 'codespellfile=s' => \$codespellfile,
+ 'typedefsfile=s' => \$typedefsfile,
+ 'color=s' => \$color,
+ 'no-color' => \$color, #keep old behaviors of -nocolor
+ 'nocolor' => \$color, #keep old behaviors of -nocolor
+ 'h|help' => \$help,
+ 'version' => \$help
+) or help(1);
+
+help(0) if ($help);
+
+list_types(0) if ($list_types);
+
+$fix = 1 if ($fix_inplace);
+$check_orig = $check;
+
+my $exit = 0;
+
+my $perl_version_ok = 1;
+if ($^V && $^V lt $minimum_perl_version) {
+ $perl_version_ok = 0;
+ printf "$P: requires at least perl version %vd\n", $minimum_perl_version;
+ exit(1) if (!$ignore_perl_version);
+}
+
+#if no filenames are given, push '-' to read patch from stdin
+if ($#ARGV < 0) {
+ push(@ARGV, '-');
+}
+
+if ($color =~ /^[01]$/) {
+ $color = !$color;
+} elsif ($color =~ /^always$/i) {
+ $color = 1;
+} elsif ($color =~ /^never$/i) {
+ $color = 0;
+} elsif ($color =~ /^auto$/i) {
+ $color = (-t STDOUT);
+} else {
+ die "Invalid color mode: $color\n";
+}
+
+sub hash_save_array_words {
+ my ($hashRef, $arrayRef) = @_;
+
+ my @array = split(/,/, join(',', @$arrayRef));
+ foreach my $word (@array) {
+ $word =~ s/\s*\n?$//g;
+ $word =~ s/^\s*//g;
+ $word =~ s/\s+/ /g;
+ $word =~ tr/[a-z]/[A-Z]/;
+
+ next if ($word =~ m/^\s*#/);
+ next if ($word =~ m/^\s*$/);
+
+ $hashRef->{$word}++;
+ }
+}
+
+sub hash_show_words {
+ my ($hashRef, $prefix) = @_;
+
+ if (keys %$hashRef) {
+ print "\nNOTE: $prefix message types:";
+ foreach my $word (sort keys %$hashRef) {
+ print " $word";
+ }
+ print "\n";
+ }
+}
+
+hash_save_array_words(\%ignore_type, \@ignore);
+hash_save_array_words(\%use_type, \@use);
+
+my $dbg_values = 0;
+my $dbg_possible = 0;
+my $dbg_type = 0;
+my $dbg_attr = 0;
+for my $key (keys %debug) {
+ ## no critic
+ eval "\${dbg_$key} = '$debug{$key}';";
+ die "$@" if ($@);
+}
+
+my $rpt_cleaners = 0;
+
+if ($terse) {
+ $emacs = 1;
+ $quiet++;
+}
+
+if ($tree) {
+ if (defined $root) {
+ if (!top_of_kernel_tree($root)) {
+ die "$P: $root: --root does not point at a valid tree\n";
+ }
+ } else {
+ if (top_of_kernel_tree('.')) {
+ $root = '.';
+ } elsif ($0 =~ m@(.*)/scripts/[^/]*$@ &&
+ top_of_kernel_tree($1)) {
+ $root = $1;
+ }
+ }
+
+ if (!defined $root) {
+ print "Must be run from the top-level dir. of a kernel tree\n";
+ exit(2);
+ }
+}
+
+my $emitted_corrupt = 0;
+
+our $Ident = qr{
+ [A-Za-z_][A-Za-z\d_]*
+ (?:\s*\#\#\s*[A-Za-z_][A-Za-z\d_]*)*
+ }x;
+our $Storage = qr{extern|static|asmlinkage};
+our $Sparse = qr{
+ __user|
+ __kernel|
+ __force|
+ __iomem|
+ __must_check|
+ __kprobes|
+ __ref|
+ __refconst|
+ __refdata|
+ __rcu|
+ __private
+ }x;
+our $InitAttributePrefix = qr{__(?:mem|cpu|dev|net_|)};
+our $InitAttributeData = qr{$InitAttributePrefix(?:initdata\b)};
+our $InitAttributeConst = qr{$InitAttributePrefix(?:initconst\b)};
+our $InitAttributeInit = qr{$InitAttributePrefix(?:init\b)};
+our $InitAttribute = qr{$InitAttributeData|$InitAttributeConst|$InitAttributeInit};
+
+# Notes to $Attribute:
+# We need \b after 'init' otherwise 'initconst' will cause a false positive in a check
+our $Attribute = qr{
+ const|
+ __percpu|
+ __nocast|
+ __safe|
+ __bitwise|
+ __packed__|
+ __packed2__|
+ __naked|
+ __maybe_unused|
+ __always_unused|
+ __noreturn|
+ __used|
+ __cold|
+ __pure|
+ __noclone|
+ __deprecated|
+ __read_mostly|
+ __ro_after_init|
+ __kprobes|
+ $InitAttribute|
+ ____cacheline_aligned|
+ ____cacheline_aligned_in_smp|
+ ____cacheline_internodealigned_in_smp|
+ __weak
+ }x;
+our $Modifier;
+our $Inline = qr{inline|__always_inline|noinline|__inline|__inline__};
+our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]};
+our $Lval = qr{$Ident(?:$Member)*};
+
+our $Int_type = qr{(?i)llu|ull|ll|lu|ul|l|u};
+our $Binary = qr{(?i)0b[01]+$Int_type?};
+our $Hex = qr{(?i)0x[0-9a-f]+$Int_type?};
+our $Int = qr{[0-9]+$Int_type?};
+our $Octal = qr{0[0-7]+$Int_type?};
+our $String = qr{"[X\t]*"};
+our $Float_hex = qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?};
+our $Float_dec = qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?};
+our $Float_int = qr{(?i)[0-9]+e-?[0-9]+[fl]?};
+our $Float = qr{$Float_hex|$Float_dec|$Float_int};
+our $Constant = qr{$Float|$Binary|$Octal|$Hex|$Int};
+our $Assignment = qr{\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=};
+our $Compare = qr{<=|>=|==|!=|<|(?<!-)>};
+our $Arithmetic = qr{\+|-|\*|\/|%};
+our $Operators = qr{
+ <=|>=|==|!=|
+ =>|->|<<|>>|<|>|!|~|
+ &&|\|\||,|\^|\+\+|--|&|\||$Arithmetic
+ }x;
+
+our $c90_Keywords = qr{do|for|while|if|else|return|goto|continue|switch|default|case|break}x;
+
+our $BasicType;
+our $NonptrType;
+our $NonptrTypeMisordered;
+our $NonptrTypeWithAttr;
+our $Type;
+our $TypeMisordered;
+our $Declare;
+our $DeclareMisordered;
+
+our $NON_ASCII_UTF8 = qr{
+ [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
+ | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
+ | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
+ | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
+ | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
+ | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
+ | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
+}x;
+
+our $UTF8 = qr{
+ [\x09\x0A\x0D\x20-\x7E] # ASCII
+ | $NON_ASCII_UTF8
+}x;
+
+our $typeC99Typedefs = qr{(?:__)?(?:[us]_?)?int_?(?:8|16|32|64)_t};
+our $typeOtherOSTypedefs = qr{(?x:
+ u_(?:char|short|int|long) | # bsd
+ u(?:nchar|short|int|long) # sysv
+)};
+our $typeKernelTypedefs = qr{(?x:
+ (?:__)?(?:u|s|be|le)(?:8|16|32|64)|
+ atomic_t
+)};
+our $typeTypedefs = qr{(?x:
+ $typeC99Typedefs\b|
+ $typeOtherOSTypedefs\b|
+ $typeKernelTypedefs\b
+)};
+
+our $zero_initializer = qr{(?:(?:0[xX])?0+$Int_type?|NULL|false)\b};
+
+our $logFunctions = qr{(?x:
+ printk(?:_ratelimited|_once|_deferred_once|_deferred|)|
+ (?:[a-z0-9]+_){1,2}(?:printk|emerg|alert|crit|err|warning|warn|notice|info|debug|dbg|vdbg|devel|cont|WARN)(?:_ratelimited|_once|)|
+ TP_printk|
+ WARN(?:_RATELIMIT|_ONCE|)|
+ panic|
+ MODULE_[A-Z_]+|
+ seq_vprintf|seq_printf|seq_puts
+)};
+
+our $signature_tags = qr{(?xi:
+ Signed-off-by:|
+ Co-developed-by:|
+ Acked-by:|
+ Tested-by:|
+ Reviewed-by:|
+ Reported-by:|
+ Suggested-by:|
+ To:|
+ Cc:
+)};
+
+our @typeListMisordered = (
+ qr{char\s+(?:un)?signed},
+ qr{int\s+(?:(?:un)?signed\s+)?short\s},
+ qr{int\s+short(?:\s+(?:un)?signed)},
+ qr{short\s+int(?:\s+(?:un)?signed)},
+ qr{(?:un)?signed\s+int\s+short},
+ qr{short\s+(?:un)?signed},
+ qr{long\s+int\s+(?:un)?signed},
+ qr{int\s+long\s+(?:un)?signed},
+ qr{long\s+(?:un)?signed\s+int},
+ qr{int\s+(?:un)?signed\s+long},
+ qr{int\s+(?:un)?signed},
+ qr{int\s+long\s+long\s+(?:un)?signed},
+ qr{long\s+long\s+int\s+(?:un)?signed},
+ qr{long\s+long\s+(?:un)?signed\s+int},
+ qr{long\s+long\s+(?:un)?signed},
+ qr{long\s+(?:un)?signed},
+);
+
+our @typeList = (
+ qr{void},
+ qr{(?:(?:un)?signed\s+)?char},
+ qr{(?:(?:un)?signed\s+)?short\s+int},
+ qr{(?:(?:un)?signed\s+)?short},
+ qr{(?:(?:un)?signed\s+)?int},
+ qr{(?:(?:un)?signed\s+)?long\s+int},
+ qr{(?:(?:un)?signed\s+)?long\s+long\s+int},
+ qr{(?:(?:un)?signed\s+)?long\s+long},
+ qr{(?:(?:un)?signed\s+)?long},
+ qr{(?:un)?signed},
+ qr{float},
+ qr{double},
+ qr{bool},
+ qr{struct\s+$Ident},
+ qr{union\s+$Ident},
+ qr{enum\s+$Ident},
+ qr{${Ident}_t},
+ qr{${Ident}_handler},
+ qr{${Ident}_handler_fn},
+ @typeListMisordered,
+);
+
+our $C90_int_types = qr{(?x:
+ long\s+long\s+int\s+(?:un)?signed|
+ long\s+long\s+(?:un)?signed\s+int|
+ long\s+long\s+(?:un)?signed|
+ (?:(?:un)?signed\s+)?long\s+long\s+int|
+ (?:(?:un)?signed\s+)?long\s+long|
+ int\s+long\s+long\s+(?:un)?signed|
+ int\s+(?:(?:un)?signed\s+)?long\s+long|
+
+ long\s+int\s+(?:un)?signed|
+ long\s+(?:un)?signed\s+int|
+ long\s+(?:un)?signed|
+ (?:(?:un)?signed\s+)?long\s+int|
+ (?:(?:un)?signed\s+)?long|
+ int\s+long\s+(?:un)?signed|
+ int\s+(?:(?:un)?signed\s+)?long|
+
+ int\s+(?:un)?signed|
+ (?:(?:un)?signed\s+)?int
+)};
+
+our @typeListFile = ();
+our @typeListWithAttr = (
+ @typeList,
+ qr{struct\s+$InitAttribute\s+$Ident},
+ qr{union\s+$InitAttribute\s+$Ident},
+);
+
+our @modifierList = (
+ qr{fastcall},
+);
+our @modifierListFile = ();
+
+our @mode_permission_funcs = (
+ ["module_param", 3],
+ ["module_param_(?:array|named|string)", 4],
+ ["module_param_array_named", 5],
+ ["debugfs_create_(?:file|u8|u16|u32|u64|x8|x16|x32|x64|size_t|atomic_t|bool|blob|regset32|u32_array)", 2],
+ ["proc_create(?:_data|)", 2],
+ ["(?:CLASS|DEVICE|SENSOR|SENSOR_DEVICE|IIO_DEVICE)_ATTR", 2],
+ ["IIO_DEV_ATTR_[A-Z_]+", 1],
+ ["SENSOR_(?:DEVICE_|)ATTR_2", 2],
+ ["SENSOR_TEMPLATE(?:_2|)", 3],
+ ["__ATTR", 2],
+);
+
+#Create a search pattern for all these functions to speed up a loop below
+our $mode_perms_search = "";
+foreach my $entry (@mode_permission_funcs) {
+ $mode_perms_search .= '|' if ($mode_perms_search ne "");
+ $mode_perms_search .= $entry->[0];
+}
+$mode_perms_search = "(?:${mode_perms_search})";
+
+our %deprecated_apis = (
+ "synchronize_rcu_bh" => "synchronize_rcu",
+ "synchronize_rcu_bh_expedited" => "synchronize_rcu_expedited",
+ "call_rcu_bh" => "call_rcu",
+ "rcu_barrier_bh" => "rcu_barrier",
+ "synchronize_sched" => "synchronize_rcu",
+ "synchronize_sched_expedited" => "synchronize_rcu_expedited",
+ "call_rcu_sched" => "call_rcu",
+ "rcu_barrier_sched" => "rcu_barrier",
+ "get_state_synchronize_sched" => "get_state_synchronize_rcu",
+ "cond_synchronize_sched" => "cond_synchronize_rcu",
+);
+
+#Create a search pattern for all these strings to speed up a loop below
+our $deprecated_apis_search = "";
+foreach my $entry (keys %deprecated_apis) {
+ $deprecated_apis_search .= '|' if ($deprecated_apis_search ne "");
+ $deprecated_apis_search .= $entry;
+}
+$deprecated_apis_search = "(?:${deprecated_apis_search})";
+
+our $mode_perms_world_writable = qr{
+ S_IWUGO |
+ S_IWOTH |
+ S_IRWXUGO |
+ S_IALLUGO |
+ 0[0-7][0-7][2367]
+}x;
+
+our %mode_permission_string_types = (
+ "S_IRWXU" => 0700,
+ "S_IRUSR" => 0400,
+ "S_IWUSR" => 0200,
+ "S_IXUSR" => 0100,
+ "S_IRWXG" => 0070,
+ "S_IRGRP" => 0040,
+ "S_IWGRP" => 0020,
+ "S_IXGRP" => 0010,
+ "S_IRWXO" => 0007,
+ "S_IROTH" => 0004,
+ "S_IWOTH" => 0002,
+ "S_IXOTH" => 0001,
+ "S_IRWXUGO" => 0777,
+ "S_IRUGO" => 0444,
+ "S_IWUGO" => 0222,
+ "S_IXUGO" => 0111,
+);
+
+#Create a search pattern for all these strings to speed up a loop below
+our $mode_perms_string_search = "";
+foreach my $entry (keys %mode_permission_string_types) {
+ $mode_perms_string_search .= '|' if ($mode_perms_string_search ne "");
+ $mode_perms_string_search .= $entry;
+}
+our $single_mode_perms_string_search = "(?:${mode_perms_string_search})";
+our $multi_mode_perms_string_search = qr{
+ ${single_mode_perms_string_search}
+ (?:\s*\|\s*${single_mode_perms_string_search})*
+}x;
+
+sub perms_to_octal {
+ my ($string) = @_;
+
+ return trim($string) if ($string =~ /^\s*0[0-7]{3,3}\s*$/);
+
+ my $val = "";
+ my $oval = "";
+ my $to = 0;
+ my $curpos = 0;
+ my $lastpos = 0;
+ while ($string =~ /\b(($single_mode_perms_string_search)\b(?:\s*\|\s*)?\s*)/g) {
+ $curpos = pos($string);
+ my $match = $2;
+ my $omatch = $1;
+ last if ($lastpos > 0 && ($curpos - length($omatch) != $lastpos));
+ $lastpos = $curpos;
+ $to |= $mode_permission_string_types{$match};
+ $val .= '\s*\|\s*' if ($val ne "");
+ $val .= $match;
+ $oval .= $omatch;
+ }
+ $oval =~ s/^\s*\|\s*//;
+ $oval =~ s/\s*\|\s*$//;
+ return sprintf("%04o", $to);
+}
+
+our $allowed_asm_includes = qr{(?x:
+ irq|
+ memory|
+ time|
+ reboot
+)};
+# memory.h: ARM has a custom one
+
+# Load common spelling mistakes and build regular expression list.
+my $misspellings;
+my %spelling_fix;
+
+if (open(my $spelling, '<', $spelling_file)) {
+ while (<$spelling>) {
+ my $line = $_;
+
+ $line =~ s/\s*\n?$//g;
+ $line =~ s/^\s*//g;
+
+ next if ($line =~ m/^\s*#/);
+ next if ($line =~ m/^\s*$/);
+
+ my ($suspect, $fix) = split(/\|\|/, $line);
+
+ $spelling_fix{$suspect} = $fix;
+ }
+ close($spelling);
+} else {
+ warn "No typos will be found - file '$spelling_file': $!\n";
+}
+
+if ($codespell) {
+ if (open(my $spelling, '<', $codespellfile)) {
+ while (<$spelling>) {
+ my $line = $_;
+
+ $line =~ s/\s*\n?$//g;
+ $line =~ s/^\s*//g;
+
+ next if ($line =~ m/^\s*#/);
+ next if ($line =~ m/^\s*$/);
+ next if ($line =~ m/, disabled/i);
+
+ $line =~ s/,.*$//;
+
+ my ($suspect, $fix) = split(/->/, $line);
+
+ $spelling_fix{$suspect} = $fix;
+ }
+ close($spelling);
+ } else {
+ warn "No codespell typos will be found - file '$codespellfile': $!\n";
+ }
+}
+
+$misspellings = join("|", sort keys %spelling_fix) if keys %spelling_fix;
+
+sub read_words {
+ my ($wordsRef, $file) = @_;
+
+ if (open(my $words, '<', $file)) {
+ while (<$words>) {
+ my $line = $_;
+
+ $line =~ s/\s*\n?$//g;
+ $line =~ s/^\s*//g;
+
+ next if ($line =~ m/^\s*#/);
+ next if ($line =~ m/^\s*$/);
+ if ($line =~ /\s/) {
+ print("$file: '$line' invalid - ignored\n");
+ next;
+ }
+
+ $$wordsRef .= '|' if ($$wordsRef ne "");
+ $$wordsRef .= $line;
+ }
+ close($file);
+ return 1;
+ }
+
+ return 0;
+}
+
+my $const_structs = "";
+read_words(\$const_structs, $conststructsfile)
+ or warn "No structs that should be const will be found - file '$conststructsfile': $!\n";
+
+my $typeOtherTypedefs = "";
+if (length($typedefsfile)) {
+ read_words(\$typeOtherTypedefs, $typedefsfile)
+ or warn "No additional types will be considered - file '$typedefsfile': $!\n";
+}
+$typeTypedefs .= '|' . $typeOtherTypedefs if ($typeOtherTypedefs ne "");
+
+sub build_types {
+ my $mods = "(?x: \n" . join("|\n ", (@modifierList, @modifierListFile)) . "\n)";
+ my $all = "(?x: \n" . join("|\n ", (@typeList, @typeListFile)) . "\n)";
+ my $Misordered = "(?x: \n" . join("|\n ", @typeListMisordered) . "\n)";
+ my $allWithAttr = "(?x: \n" . join("|\n ", @typeListWithAttr) . "\n)";
+ $Modifier = qr{(?:$Attribute|$Sparse|$mods)};
+ $BasicType = qr{
+ (?:$typeTypedefs\b)|
+ (?:${all}\b)
+ }x;
+ $NonptrType = qr{
+ (?:$Modifier\s+|const\s+)*
+ (?:
+ (?:typeof|__typeof__)\s*\([^\)]*\)|
+ (?:$typeTypedefs\b)|
+ (?:${all}\b)
+ )
+ (?:\s+$Modifier|\s+const)*
+ }x;
+ $NonptrTypeMisordered = qr{
+ (?:$Modifier\s+|const\s+)*
+ (?:
+ (?:${Misordered}\b)
+ )
+ (?:\s+$Modifier|\s+const)*
+ }x;
+ $NonptrTypeWithAttr = qr{
+ (?:$Modifier\s+|const\s+)*
+ (?:
+ (?:typeof|__typeof__)\s*\([^\)]*\)|
+ (?:$typeTypedefs\b)|
+ (?:${allWithAttr}\b)
+ )
+ (?:\s+$Modifier|\s+const)*
+ }x;
+ $Type = qr{
+ $NonptrType
+ (?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+)?
+ (?:\s+$Inline|\s+$Modifier)*
+ }x;
+ $TypeMisordered = qr{
+ $NonptrTypeMisordered
+ (?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+)?
+ (?:\s+$Inline|\s+$Modifier)*
+ }x;
+ $Declare = qr{(?:$Storage\s+(?:$Inline\s+)?)?$Type};
+ $DeclareMisordered = qr{(?:$Storage\s+(?:$Inline\s+)?)?$TypeMisordered};
+}
+build_types();
+
+our $Typecast = qr{\s*(\(\s*$NonptrType\s*\)){0,1}\s*};
+
+# Using $balanced_parens, $LvalOrFunc, or $FuncArg
+# requires at least perl version v5.10.0
+# Any use must be runtime checked with $^V
+
+our $balanced_parens = qr/(\((?:[^\(\)]++|(?-1))*\))/;
+our $LvalOrFunc = qr{((?:[\&\*]\s*)?$Lval)\s*($balanced_parens{0,1})\s*};
+our $FuncArg = qr{$Typecast{0,1}($LvalOrFunc|$Constant|$String)};
+
+our $declaration_macros = qr{(?x:
+ (?:$Storage\s+)?(?:[A-Z_][A-Z0-9]*_){0,2}(?:DEFINE|DECLARE)(?:_[A-Z0-9]+){1,6}\s*\(|
+ (?:$Storage\s+)?[HLP]?LIST_HEAD\s*\(|
+ (?:$Storage\s+)?${Type}\s+uninitialized_var\s*\(|
+ (?:SKCIPHER_REQUEST|SHASH_DESC|AHASH_REQUEST)_ON_STACK\s*\(
+)};
+
+sub deparenthesize {
+ my ($string) = @_;
+ return "" if (!defined($string));
+
+ while ($string =~ /^\s*\(.*\)\s*$/) {
+ $string =~ s@^\s*\(\s*@@;
+ $string =~ s@\s*\)\s*$@@;
+ }
+
+ $string =~ s@\s+@ @g;
+
+ return $string;
+}
+
+sub seed_camelcase_file {
+ my ($file) = @_;
+
+ return if (!(-f $file));
+
+ local $/;
+
+ open(my $include_file, '<', "$file")
+ or warn "$P: Can't read '$file' $!\n";
+ my $text = <$include_file>;
+ close($include_file);
+
+ my @lines = split('\n', $text);
+
+ foreach my $line (@lines) {
+ next if ($line !~ /(?:[A-Z][a-z]|[a-z][A-Z])/);
+ if ($line =~ /^[ \t]*(?:#[ \t]*define|typedef\s+$Type)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)/) {
+ $camelcase{$1} = 1;
+ } elsif ($line =~ /^\s*$Declare\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[\(\[,;]/) {
+ $camelcase{$1} = 1;
+ } elsif ($line =~ /^\s*(?:union|struct|enum)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[;\{]/) {
+ $camelcase{$1} = 1;
+ }
+ }
+}
+
+sub is_maintained_obsolete {
+ my ($filename) = @_;
+
+ return 0 if (!$tree || !(-e "$root/scripts/get_maintainer.pl"));
+
+ my $status = `perl $root/scripts/get_maintainer.pl --status --nom --nol --nogit --nogit-fallback -f $filename 2>&1`;
+
+ return $status =~ /obsolete/i;
+}
+
+sub is_SPDX_License_valid {
+ my ($license) = @_;
+
+ return 1 if (!$tree || which("python") eq "" || !(-e "$root/scripts/spdxcheck.py") || !(-e "$root/.git"));
+
+ my $root_path = abs_path($root);
+ my $status = `cd "$root_path"; echo "$license" | python scripts/spdxcheck.py -`;
+ return 0 if ($status ne "");
+ return 1;
+}
+
+my $camelcase_seeded = 0;
+sub seed_camelcase_includes {
+ return if ($camelcase_seeded);
+
+ my $files;
+ my $camelcase_cache = "";
+ my @include_files = ();
+
+ $camelcase_seeded = 1;
+
+ if (-e ".git") {
+ my $git_last_include_commit = `git log --no-merges --pretty=format:"%h%n" -1 -- include`;
+ chomp $git_last_include_commit;
+ $camelcase_cache = ".checkpatch-camelcase.git.$git_last_include_commit";
+ } else {
+ my $last_mod_date = 0;
+ $files = `find $root/include -name "*.h"`;
+ @include_files = split('\n', $files);
+ foreach my $file (@include_files) {
+ my $date = POSIX::strftime("%Y%m%d%H%M",
+ localtime((stat $file)[9]));
+ $last_mod_date = $date if ($last_mod_date < $date);
+ }
+ $camelcase_cache = ".checkpatch-camelcase.date.$last_mod_date";
+ }
+
+ if ($camelcase_cache ne "" && -f $camelcase_cache) {
+ open(my $camelcase_file, '<', "$camelcase_cache")
+ or warn "$P: Can't read '$camelcase_cache' $!\n";
+ while (<$camelcase_file>) {
+ chomp;
+ $camelcase{$_} = 1;
+ }
+ close($camelcase_file);
+
+ return;
+ }
+
+ if (-e ".git") {
+ $files = `git ls-files "include/*.h"`;
+ @include_files = split('\n', $files);
+ }
+
+ foreach my $file (@include_files) {
+ seed_camelcase_file($file);
+ }
+
+ if ($camelcase_cache ne "") {
+ unlink glob ".checkpatch-camelcase.*";
+ open(my $camelcase_file, '>', "$camelcase_cache")
+ or warn "$P: Can't write '$camelcase_cache' $!\n";
+ foreach (sort { lc($a) cmp lc($b) } keys(%camelcase)) {
+ print $camelcase_file ("$_\n");
+ }
+ close($camelcase_file);
+ }
+}
+
+sub git_commit_info {
+ my ($commit, $id, $desc) = @_;
+
+ return ($id, $desc) if ((which("git") eq "") || !(-e ".git"));
+
+ my $output = `git log --no-color --format='%H %s' -1 $commit 2>&1`;
+ $output =~ s/^\s*//gm;
+ my @lines = split("\n", $output);
+
+ return ($id, $desc) if ($#lines < 0);
+
+ if ($lines[0] =~ /^error: short SHA1 $commit is ambiguous\./) {
+# Maybe one day convert this block of bash into something that returns
+# all matching commit ids, but it's very slow...
+#
+# echo "checking commits $1..."
+# git rev-list --remotes | grep -i "^$1" |
+# while read line ; do
+# git log --format='%H %s' -1 $line |
+# echo "commit $(cut -c 1-12,41-)"
+# done
+ } elsif ($lines[0] =~ /^fatal: ambiguous argument '$commit': unknown revision or path not in the working tree\./) {
+ $id = undef;
+ } else {
+ $id = substr($lines[0], 0, 12);
+ $desc = substr($lines[0], 41);
+ }
+
+ return ($id, $desc);
+}
+
+$chk_signoff = 0 if ($file);
+
+my @rawlines = ();
+my @lines = ();
+my @fixed = ();
+my @fixed_inserted = ();
+my @fixed_deleted = ();
+my $fixlinenr = -1;
+
+# If input is git commits, extract all commits from the commit expressions.
+# For example, HEAD-3 means we need check 'HEAD, HEAD~1, HEAD~2'.
+die "$P: No git repository found\n" if ($git && !-e ".git");
+
+if ($git) {
+ my @commits = ();
+ foreach my $commit_expr (@ARGV) {
+ my $git_range;
+ if ($commit_expr =~ m/^(.*)-(\d+)$/) {
+ $git_range = "-$2 $1";
+ } elsif ($commit_expr =~ m/\.\./) {
+ $git_range = "$commit_expr";
+ } else {
+ $git_range = "-1 $commit_expr";
+ }
+ my $lines = `git log --no-color --no-merges --pretty=format:'%H %s' $git_range`;
+ foreach my $line (split(/\n/, $lines)) {
+ $line =~ /^([0-9a-fA-F]{40,40}) (.*)$/;
+ next if (!defined($1) || !defined($2));
+ my $sha1 = $1;
+ my $subject = $2;
+ unshift(@commits, $sha1);
+ $git_commits{$sha1} = $subject;
+ }
+ }
+ die "$P: no git commits after extraction!\n" if (@commits == 0);
+ @ARGV = @commits;
+}
+
+my $vname;
+for my $filename (@ARGV) {
+ my $FILE;
+ if ($git) {
+ open($FILE, '-|', "git format-patch -M --stdout -1 $filename") ||
+ die "$P: $filename: git format-patch failed - $!\n";
+ } elsif ($file) {
+ open($FILE, '-|', "diff -u /dev/null $filename") ||
+ die "$P: $filename: diff failed - $!\n";
+ } elsif ($filename eq '-') {
+ open($FILE, '<&STDIN');
+ } else {
+ open($FILE, '<', "$filename") ||
+ die "$P: $filename: open failed - $!\n";
+ }
+ if ($filename eq '-') {
+ $vname = 'Your patch';
+ } elsif ($git) {
+ $vname = "Commit " . substr($filename, 0, 12) . ' ("' . $git_commits{$filename} . '")';
+ } else {
+ $vname = $filename;
+ }
+ while (<$FILE>) {
+ chomp;
+ push(@rawlines, $_);
+ }
+ close($FILE);
+
+ if ($#ARGV > 0 && $quiet == 0) {
+ print '-' x length($vname) . "\n";
+ print "$vname\n";
+ print '-' x length($vname) . "\n";
+ }
+
+ if (!process($filename)) {
+ $exit = 1;
+ }
+ @rawlines = ();
+ @lines = ();
+ @fixed = ();
+ @fixed_inserted = ();
+ @fixed_deleted = ();
+ $fixlinenr = -1;
+ @modifierListFile = ();
+ @typeListFile = ();
+ build_types();
+}
+
+if (!$quiet) {
+ hash_show_words(\%use_type, "Used");
+ hash_show_words(\%ignore_type, "Ignored");
+
+ if (!$perl_version_ok) {
+ print << "EOM"
+
+NOTE: perl $^V is not modern enough to detect all possible issues.
+ An upgrade to at least perl $minimum_perl_version is suggested.
+EOM
+ }
+ if ($exit) {
+ print << "EOM"
+
+NOTE: If any of the errors are false positives, please report
+ them to the maintainer, see CHECKPATCH in MAINTAINERS.
+EOM
+ }
+}
+
+exit($exit);
+
+sub top_of_kernel_tree {
+ my ($root) = @_;
+
+ my @tree_check = (
+ "COPYING", "CREDITS", "Kbuild", "MAINTAINERS", "Makefile",
+ "README", "Documentation", "arch", "include", "drivers",
+ "fs", "init", "ipc", "kernel", "lib", "scripts",
+ );
+
+ foreach my $check (@tree_check) {
+ if (! -e $root . '/' . $check) {
+ return 0;
+ }
+ }
+ return 1;
+}
+
+sub parse_email {
+ my ($formatted_email) = @_;
+
+ my $name = "";
+ my $address = "";
+ my $comment = "";
+
+ if ($formatted_email =~ /^(.*)<(\S+\@\S+)>(.*)$/) {
+ $name = $1;
+ $address = $2;
+ $comment = $3 if defined $3;
+ } elsif ($formatted_email =~ /^\s*<(\S+\@\S+)>(.*)$/) {
+ $address = $1;
+ $comment = $2 if defined $2;
+ } elsif ($formatted_email =~ /(\S+\@\S+)(.*)$/) {
+ $address = $1;
+ $comment = $2 if defined $2;
+ $formatted_email =~ s/\Q$address\E.*$//;
+ $name = $formatted_email;
+ $name = trim($name);
+ $name =~ s/^\"|\"$//g;
+ # If there's a name left after stripping spaces and
+ # leading quotes, and the address doesn't have both
+ # leading and trailing angle brackets, the address
+ # is invalid. ie:
+ # "joe smith joe@smith.com" bad
+ # "joe smith <joe@smith.com" bad
+ if ($name ne "" && $address !~ /^<[^>]+>$/) {
+ $name = "";
+ $address = "";
+ $comment = "";
+ }
+ }
+
+ $name = trim($name);
+ $name =~ s/^\"|\"$//g;
+ $address = trim($address);
+ $address =~ s/^\<|\>$//g;
+
+ if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
+ $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
+ $name = "\"$name\"";
+ }
+
+ return ($name, $address, $comment);
+}
+
+sub format_email {
+ my ($name, $address) = @_;
+
+ my $formatted_email;
+
+ $name = trim($name);
+ $name =~ s/^\"|\"$//g;
+ $address = trim($address);
+
+ if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
+ $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
+ $name = "\"$name\"";
+ }
+
+ if ("$name" eq "") {
+ $formatted_email = "$address";
+ } else {
+ $formatted_email = "$name <$address>";
+ }
+
+ return $formatted_email;
+}
+
+sub which {
+ my ($bin) = @_;
+
+ foreach my $path (split(/:/, $ENV{PATH})) {
+ if (-e "$path/$bin") {
+ return "$path/$bin";
+ }
+ }
+
+ return "";
+}
+
+sub which_conf {
+ my ($conf) = @_;
+
+ foreach my $path (split(/:/, ".:$ENV{HOME}:.scripts")) {
+ if (-e "$path/$conf") {
+ return "$path/$conf";
+ }
+ }
+
+ return "";
+}
+
+sub expand_tabs {
+ my ($str) = @_;
+
+ my $res = '';
+ my $n = 0;
+ for my $c (split(//, $str)) {
+ if ($c eq "\t") {
+ $res .= ' ';
+ $n++;
+ for (; ($n % 8) != 0; $n++) {
+ $res .= ' ';
+ }
+ next;
+ }
+ $res .= $c;
+ $n++;
+ }
+
+ return $res;
+}
+sub copy_spacing {
+ (my $res = shift) =~ tr/\t/ /c;
+ return $res;
+}
+
+sub line_stats {
+ my ($line) = @_;
+
+ # Drop the diff line leader and expand tabs
+ $line =~ s/^.//;
+ $line = expand_tabs($line);
+
+ # Pick the indent from the front of the line.
+ my ($white) = ($line =~ /^(\s*)/);
+
+ return (length($line), length($white));
+}
+
+my $sanitise_quote = '';
+
+sub sanitise_line_reset {
+ my ($in_comment) = @_;
+
+ if ($in_comment) {
+ $sanitise_quote = '*/';
+ } else {
+ $sanitise_quote = '';
+ }
+}
+sub sanitise_line {
+ my ($line) = @_;
+
+ my $res = '';
+ my $l = '';
+
+ my $qlen = 0;
+ my $off = 0;
+ my $c;
+
+ # Always copy over the diff marker.
+ $res = substr($line, 0, 1);
+
+ for ($off = 1; $off < length($line); $off++) {
+ $c = substr($line, $off, 1);
+
+ # Comments we are whacking completely including the begin
+ # and end, all to $;.
+ if ($sanitise_quote eq '' && substr($line, $off, 2) eq '/*') {
+ $sanitise_quote = '*/';
+
+ substr($res, $off, 2, "$;$;");
+ $off++;
+ next;
+ }
+ if ($sanitise_quote eq '*/' && substr($line, $off, 2) eq '*/') {
+ $sanitise_quote = '';
+ substr($res, $off, 2, "$;$;");
+ $off++;
+ next;
+ }
+ if ($sanitise_quote eq '' && substr($line, $off, 2) eq '//') {
+ $sanitise_quote = '//';
+
+ substr($res, $off, 2, $sanitise_quote);
+ $off++;
+ next;
+ }
+
+ # A \ in a string means ignore the next character.
+ if (($sanitise_quote eq "'" || $sanitise_quote eq '"') &&
+ $c eq "\\") {
+ substr($res, $off, 2, 'XX');
+ $off++;
+ next;
+ }
+ # Regular quotes.
+ if ($c eq "'" || $c eq '"') {
+ if ($sanitise_quote eq '') {
+ $sanitise_quote = $c;
+
+ substr($res, $off, 1, $c);
+ next;
+ } elsif ($sanitise_quote eq $c) {
+ $sanitise_quote = '';
+ }
+ }
+
+ #print "c<$c> SQ<$sanitise_quote>\n";
+ if ($off != 0 && $sanitise_quote eq '*/' && $c ne "\t") {
+ substr($res, $off, 1, $;);
+ } elsif ($off != 0 && $sanitise_quote eq '//' && $c ne "\t") {
+ substr($res, $off, 1, $;);
+ } elsif ($off != 0 && $sanitise_quote && $c ne "\t") {
+ substr($res, $off, 1, 'X');
+ } else {
+ substr($res, $off, 1, $c);
+ }
+ }
+
+ if ($sanitise_quote eq '//') {
+ $sanitise_quote = '';
+ }
+
+ # The pathname on a #include may be surrounded by '<' and '>'.
+ if ($res =~ /^.\s*\#\s*include\s+\<(.*)\>/) {
+ my $clean = 'X' x length($1);
+ $res =~ s@\<.*\>@<$clean>@;
+
+ # The whole of a #error is a string.
+ } elsif ($res =~ /^.\s*\#\s*(?:error|warning)\s+(.*)\b/) {
+ my $clean = 'X' x length($1);
+ $res =~ s@(\#\s*(?:error|warning)\s+).*@$1$clean@;
+ }
+
+ if ($allow_c99_comments && $res =~ m@(//.*$)@) {
+ my $match = $1;
+ $res =~ s/\Q$match\E/"$;" x length($match)/e;
+ }
+
+ return $res;
+}
+
+sub get_quoted_string {
+ my ($line, $rawline) = @_;
+
+ return "" if (!defined($line) || !defined($rawline));
+ return "" if ($line !~ m/($String)/g);
+ return substr($rawline, $-[0], $+[0] - $-[0]);
+}
+
+sub ctx_statement_block {
+ my ($linenr, $remain, $off) = @_;
+ my $line = $linenr - 1;
+ my $blk = '';
+ my $soff = $off;
+ my $coff = $off - 1;
+ my $coff_set = 0;
+
+ my $loff = 0;
+
+ my $type = '';
+ my $level = 0;
+ my @stack = ();
+ my $p;
+ my $c;
+ my $len = 0;
+
+ my $remainder;
+ while (1) {
+ @stack = (['', 0]) if ($#stack == -1);
+
+ #warn "CSB: blk<$blk> remain<$remain>\n";
+ # If we are about to drop off the end, pull in more
+ # context.
+ if ($off >= $len) {
+ for (; $remain > 0; $line++) {
+ last if (!defined $lines[$line]);
+ next if ($lines[$line] =~ /^-/);
+ $remain--;
+ $loff = $len;
+ $blk .= $lines[$line] . "\n";
+ $len = length($blk);
+ $line++;
+ last;
+ }
+ # Bail if there is no further context.
+ #warn "CSB: blk<$blk> off<$off> len<$len>\n";
+ if ($off >= $len) {
+ last;
+ }
+ if ($level == 0 && substr($blk, $off) =~ /^.\s*#\s*define/) {
+ $level++;
+ $type = '#';
+ }
+ }
+ $p = $c;
+ $c = substr($blk, $off, 1);
+ $remainder = substr($blk, $off);
+
+ #warn "CSB: c<$c> type<$type> level<$level> remainder<$remainder> coff_set<$coff_set>\n";
+
+ # Handle nested #if/#else.
+ if ($remainder =~ /^#\s*(?:ifndef|ifdef|if)\s/) {
+ push(@stack, [ $type, $level ]);
+ } elsif ($remainder =~ /^#\s*(?:else|elif)\b/) {
+ ($type, $level) = @{$stack[$#stack - 1]};
+ } elsif ($remainder =~ /^#\s*endif\b/) {
+ ($type, $level) = @{pop(@stack)};
+ }
+
+ # Statement ends at the ';' or a close '}' at the
+ # outermost level.
+ if ($level == 0 && $c eq ';') {
+ last;
+ }
+
+ # An else is really a conditional as long as its not else if
+ if ($level == 0 && $coff_set == 0 &&
+ (!defined($p) || $p =~ /(?:\s|\}|\+)/) &&
+ $remainder =~ /^(else)(?:\s|{)/ &&
+ $remainder !~ /^else\s+if\b/) {
+ $coff = $off + length($1) - 1;
+ $coff_set = 1;
+ #warn "CSB: mark coff<$coff> soff<$soff> 1<$1>\n";
+ #warn "[" . substr($blk, $soff, $coff - $soff + 1) . "]\n";
+ }
+
+ if (($type eq '' || $type eq '(') && $c eq '(') {
+ $level++;
+ $type = '(';
+ }
+ if ($type eq '(' && $c eq ')') {
+ $level--;
+ $type = ($level != 0)? '(' : '';
+
+ if ($level == 0 && $coff < $soff) {
+ $coff = $off;
+ $coff_set = 1;
+ #warn "CSB: mark coff<$coff>\n";
+ }
+ }
+ if (($type eq '' || $type eq '{') && $c eq '{') {
+ $level++;
+ $type = '{';
+ }
+ if ($type eq '{' && $c eq '}') {
+ $level--;
+ $type = ($level != 0)? '{' : '';
+
+ if ($level == 0) {
+ if (substr($blk, $off + 1, 1) eq ';') {
+ $off++;
+ }
+ last;
+ }
+ }
+ # Preprocessor commands end at the newline unless escaped.
+ if ($type eq '#' && $c eq "\n" && $p ne "\\") {
+ $level--;
+ $type = '';
+ $off++;
+ last;
+ }
+ $off++;
+ }
+ # We are truly at the end, so shuffle to the next line.
+ if ($off == $len) {
+ $loff = $len + 1;
+ $line++;
+ $remain--;
+ }
+
+ my $statement = substr($blk, $soff, $off - $soff + 1);
+ my $condition = substr($blk, $soff, $coff - $soff + 1);
+
+ #warn "STATEMENT<$statement>\n";
+ #warn "CONDITION<$condition>\n";
+
+ #print "coff<$coff> soff<$off> loff<$loff>\n";
+
+ return ($statement, $condition,
+ $line, $remain + 1, $off - $loff + 1, $level);
+}
+
+sub statement_lines {
+ my ($stmt) = @_;
+
+ # Strip the diff line prefixes and rip blank lines at start and end.
+ $stmt =~ s/(^|\n)./$1/g;
+ $stmt =~ s/^\s*//;
+ $stmt =~ s/\s*$//;
+
+ my @stmt_lines = ($stmt =~ /\n/g);
+
+ return $#stmt_lines + 2;
+}
+
+sub statement_rawlines {
+ my ($stmt) = @_;
+
+ my @stmt_lines = ($stmt =~ /\n/g);
+
+ return $#stmt_lines + 2;
+}
+
+sub statement_block_size {
+ my ($stmt) = @_;
+
+ $stmt =~ s/(^|\n)./$1/g;
+ $stmt =~ s/^\s*{//;
+ $stmt =~ s/}\s*$//;
+ $stmt =~ s/^\s*//;
+ $stmt =~ s/\s*$//;
+
+ my @stmt_lines = ($stmt =~ /\n/g);
+ my @stmt_statements = ($stmt =~ /;/g);
+
+ my $stmt_lines = $#stmt_lines + 2;
+ my $stmt_statements = $#stmt_statements + 1;
+
+ if ($stmt_lines > $stmt_statements) {
+ return $stmt_lines;
+ } else {
+ return $stmt_statements;
+ }
+}
+
+sub ctx_statement_full {
+ my ($linenr, $remain, $off) = @_;
+ my ($statement, $condition, $level);
+
+ my (@chunks);
+
+ # Grab the first conditional/block pair.
+ ($statement, $condition, $linenr, $remain, $off, $level) =
+ ctx_statement_block($linenr, $remain, $off);
+ #print "F: c<$condition> s<$statement> remain<$remain>\n";
+ push(@chunks, [ $condition, $statement ]);
+ if (!($remain > 0 && $condition =~ /^\s*(?:\n[+-])?\s*(?:if|else|do)\b/s)) {
+ return ($level, $linenr, @chunks);
+ }
+
+ # Pull in the following conditional/block pairs and see if they
+ # could continue the statement.
+ for (;;) {
+ ($statement, $condition, $linenr, $remain, $off, $level) =
+ ctx_statement_block($linenr, $remain, $off);
+ #print "C: c<$condition> s<$statement> remain<$remain>\n";
+ last if (!($remain > 0 && $condition =~ /^(?:\s*\n[+-])*\s*(?:else|do)\b/s));
+ #print "C: push\n";
+ push(@chunks, [ $condition, $statement ]);
+ }
+
+ return ($level, $linenr, @chunks);
+}
+
+sub ctx_block_get {
+ my ($linenr, $remain, $outer, $open, $close, $off) = @_;
+ my $line;
+ my $start = $linenr - 1;
+ my $blk = '';
+ my @o;
+ my @c;
+ my @res = ();
+
+ my $level = 0;
+ my @stack = ($level);
+ for ($line = $start; $remain > 0; $line++) {
+ next if ($rawlines[$line] =~ /^-/);
+ $remain--;
+
+ $blk .= $rawlines[$line];
+
+ # Handle nested #if/#else.
+ if ($lines[$line] =~ /^.\s*#\s*(?:ifndef|ifdef|if)\s/) {
+ push(@stack, $level);
+ } elsif ($lines[$line] =~ /^.\s*#\s*(?:else|elif)\b/) {
+ $level = $stack[$#stack - 1];
+ } elsif ($lines[$line] =~ /^.\s*#\s*endif\b/) {
+ $level = pop(@stack);
+ }
+
+ foreach my $c (split(//, $lines[$line])) {
+ ##print "C<$c>L<$level><$open$close>O<$off>\n";
+ if ($off > 0) {
+ $off--;
+ next;
+ }
+
+ if ($c eq $close && $level > 0) {
+ $level--;
+ last if ($level == 0);
+ } elsif ($c eq $open) {
+ $level++;
+ }
+ }
+
+ if (!$outer || $level <= 1) {
+ push(@res, $rawlines[$line]);
+ }
+
+ last if ($level == 0);
+ }
+
+ return ($level, @res);
+}
+sub ctx_block_outer {
+ my ($linenr, $remain) = @_;
+
+ my ($level, @r) = ctx_block_get($linenr, $remain, 1, '{', '}', 0);
+ return @r;
+}
+sub ctx_block {
+ my ($linenr, $remain) = @_;
+
+ my ($level, @r) = ctx_block_get($linenr, $remain, 0, '{', '}', 0);
+ return @r;
+}
+sub ctx_statement {
+ my ($linenr, $remain, $off) = @_;
+
+ my ($level, @r) = ctx_block_get($linenr, $remain, 0, '(', ')', $off);
+ return @r;
+}
+sub ctx_block_level {
+ my ($linenr, $remain) = @_;
+
+ return ctx_block_get($linenr, $remain, 0, '{', '}', 0);
+}
+sub ctx_statement_level {
+ my ($linenr, $remain, $off) = @_;
+
+ return ctx_block_get($linenr, $remain, 0, '(', ')', $off);
+}
+
+sub ctx_locate_comment {
+ my ($first_line, $end_line) = @_;
+
+ # Catch a comment on the end of the line itself.
+ my ($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*(?:\\\s*)?$@);
+ return $current_comment if (defined $current_comment);
+
+ # Look through the context and try and figure out if there is a
+ # comment.
+ my $in_comment = 0;
+ $current_comment = '';
+ for (my $linenr = $first_line; $linenr < $end_line; $linenr++) {
+ my $line = $rawlines[$linenr - 1];
+ #warn " $line\n";
+ if ($linenr == $first_line and $line =~ m@^.\s*\*@) {
+ $in_comment = 1;
+ }
+ if ($line =~ m@/\*@) {
+ $in_comment = 1;
+ }
+ if (!$in_comment && $current_comment ne '') {
+ $current_comment = '';
+ }
+ $current_comment .= $line . "\n" if ($in_comment);
+ if ($line =~ m@\*/@) {
+ $in_comment = 0;
+ }
+ }
+
+ chomp($current_comment);
+ return($current_comment);
+}
+sub ctx_has_comment {
+ my ($first_line, $end_line) = @_;
+ my $cmt = ctx_locate_comment($first_line, $end_line);
+
+ ##print "LINE: $rawlines[$end_line - 1 ]\n";
+ ##print "CMMT: $cmt\n";
+
+ return ($cmt ne '');
+}
+
+sub raw_line {
+ my ($linenr, $cnt) = @_;
+
+ my $offset = $linenr - 1;
+ $cnt++;
+
+ my $line;
+ while ($cnt) {
+ $line = $rawlines[$offset++];
+ next if (defined($line) && $line =~ /^-/);
+ $cnt--;
+ }
+
+ return $line;
+}
+
+sub get_stat_real {
+ my ($linenr, $lc) = @_;
+
+ my $stat_real = raw_line($linenr, 0);
+ for (my $count = $linenr + 1; $count <= $lc; $count++) {
+ $stat_real = $stat_real . "\n" . raw_line($count, 0);
+ }
+
+ return $stat_real;
+}
+
+sub get_stat_here {
+ my ($linenr, $cnt, $here) = @_;
+
+ my $herectx = $here . "\n";
+ for (my $n = 0; $n < $cnt; $n++) {
+ $herectx .= raw_line($linenr, $n) . "\n";
+ }
+
+ return $herectx;
+}
+
+sub cat_vet {
+ my ($vet) = @_;
+ my ($res, $coded);
+
+ $res = '';
+ while ($vet =~ /([^[:cntrl:]]*)([[:cntrl:]]|$)/g) {
+ $res .= $1;
+ if ($2 ne '') {
+ $coded = sprintf("^%c", unpack('C', $2) + 64);
+ $res .= $coded;
+ }
+ }
+ $res =~ s/$/\$/;
+
+ return $res;
+}
+
+my $av_preprocessor = 0;
+my $av_pending;
+my @av_paren_type;
+my $av_pend_colon;
+
+sub annotate_reset {
+ $av_preprocessor = 0;
+ $av_pending = '_';
+ @av_paren_type = ('E');
+ $av_pend_colon = 'O';
+}
+
+sub annotate_values {
+ my ($stream, $type) = @_;
+
+ my $res;
+ my $var = '_' x length($stream);
+ my $cur = $stream;
+
+ print "$stream\n" if ($dbg_values > 1);
+
+ while (length($cur)) {
+ @av_paren_type = ('E') if ($#av_paren_type < 0);
+ print " <" . join('', @av_paren_type) .
+ "> <$type> <$av_pending>" if ($dbg_values > 1);
+ if ($cur =~ /^(\s+)/o) {
+ print "WS($1)\n" if ($dbg_values > 1);
+ if ($1 =~ /\n/ && $av_preprocessor) {
+ $type = pop(@av_paren_type);
+ $av_preprocessor = 0;
+ }
+
+ } elsif ($cur =~ /^(\(\s*$Type\s*)\)/ && $av_pending eq '_') {
+ print "CAST($1)\n" if ($dbg_values > 1);
+ push(@av_paren_type, $type);
+ $type = 'c';
+
+ } elsif ($cur =~ /^($Type)\s*(?:$Ident|,|\)|\(|\s*$)/) {
+ print "DECLARE($1)\n" if ($dbg_values > 1);
+ $type = 'T';
+
+ } elsif ($cur =~ /^($Modifier)\s*/) {
+ print "MODIFIER($1)\n" if ($dbg_values > 1);
+ $type = 'T';
+
+ } elsif ($cur =~ /^(\#\s*define\s*$Ident)(\(?)/o) {
+ print "DEFINE($1,$2)\n" if ($dbg_values > 1);
+ $av_preprocessor = 1;
+ push(@av_paren_type, $type);
+ if ($2 ne '') {
+ $av_pending = 'N';
+ }
+ $type = 'E';
+
+ } elsif ($cur =~ /^(\#\s*(?:undef\s*$Ident|include\b))/o) {
+ print "UNDEF($1)\n" if ($dbg_values > 1);
+ $av_preprocessor = 1;
+ push(@av_paren_type, $type);
+
+ } elsif ($cur =~ /^(\#\s*(?:ifdef|ifndef|if))/o) {
+ print "PRE_START($1)\n" if ($dbg_values > 1);
+ $av_preprocessor = 1;
+
+ push(@av_paren_type, $type);
+ push(@av_paren_type, $type);
+ $type = 'E';
+
+ } elsif ($cur =~ /^(\#\s*(?:else|elif))/o) {
+ print "PRE_RESTART($1)\n" if ($dbg_values > 1);
+ $av_preprocessor = 1;
+
+ push(@av_paren_type, $av_paren_type[$#av_paren_type]);
+
+ $type = 'E';
+
+ } elsif ($cur =~ /^(\#\s*(?:endif))/o) {
+ print "PRE_END($1)\n" if ($dbg_values > 1);
+
+ $av_preprocessor = 1;
+
+ # Assume all arms of the conditional end as this
+ # one does, and continue as if the #endif was not here.
+ pop(@av_paren_type);
+ push(@av_paren_type, $type);
+ $type = 'E';
+
+ } elsif ($cur =~ /^(\\\n)/o) {
+ print "PRECONT($1)\n" if ($dbg_values > 1);
+
+ } elsif ($cur =~ /^(__attribute__)\s*\(?/o) {
+ print "ATTR($1)\n" if ($dbg_values > 1);
+ $av_pending = $type;
+ $type = 'N';
+
+ } elsif ($cur =~ /^(sizeof)\s*(\()?/o) {
+ print "SIZEOF($1)\n" if ($dbg_values > 1);
+ if (defined $2) {
+ $av_pending = 'V';
+ }
+ $type = 'N';
+
+ } elsif ($cur =~ /^(if|while|for)\b/o) {
+ print "COND($1)\n" if ($dbg_values > 1);
+ $av_pending = 'E';
+ $type = 'N';
+
+ } elsif ($cur =~/^(case)/o) {
+ print "CASE($1)\n" if ($dbg_values > 1);
+ $av_pend_colon = 'C';
+ $type = 'N';
+
+ } elsif ($cur =~/^(return|else|goto|typeof|__typeof__)\b/o) {
+ print "KEYWORD($1)\n" if ($dbg_values > 1);
+ $type = 'N';
+
+ } elsif ($cur =~ /^(\()/o) {
+ print "PAREN('$1')\n" if ($dbg_values > 1);
+ push(@av_paren_type, $av_pending);
+ $av_pending = '_';
+ $type = 'N';
+
+ } elsif ($cur =~ /^(\))/o) {
+ my $new_type = pop(@av_paren_type);
+ if ($new_type ne '_') {
+ $type = $new_type;
+ print "PAREN('$1') -> $type\n"
+ if ($dbg_values > 1);
+ } else {
+ print "PAREN('$1')\n" if ($dbg_values > 1);
+ }
+
+ } elsif ($cur =~ /^($Ident)\s*\(/o) {
+ print "FUNC($1)\n" if ($dbg_values > 1);
+ $type = 'V';
+ $av_pending = 'V';
+
+ } elsif ($cur =~ /^($Ident\s*):(?:\s*\d+\s*(,|=|;))?/) {
+ if (defined $2 && $type eq 'C' || $type eq 'T') {
+ $av_pend_colon = 'B';
+ } elsif ($type eq 'E') {
+ $av_pend_colon = 'L';
+ }
+ print "IDENT_COLON($1,$type>$av_pend_colon)\n" if ($dbg_values > 1);
+ $type = 'V';
+
+ } elsif ($cur =~ /^($Ident|$Constant)/o) {
+ print "IDENT($1)\n" if ($dbg_values > 1);
+ $type = 'V';
+
+ } elsif ($cur =~ /^($Assignment)/o) {
+ print "ASSIGN($1)\n" if ($dbg_values > 1);
+ $type = 'N';
+
+ } elsif ($cur =~/^(;|{|})/) {
+ print "END($1)\n" if ($dbg_values > 1);
+ $type = 'E';
+ $av_pend_colon = 'O';
+
+ } elsif ($cur =~/^(,)/) {
+ print "COMMA($1)\n" if ($dbg_values > 1);
+ $type = 'C';
+
+ } elsif ($cur =~ /^(\?)/o) {
+ print "QUESTION($1)\n" if ($dbg_values > 1);
+ $type = 'N';
+
+ } elsif ($cur =~ /^(:)/o) {
+ print "COLON($1,$av_pend_colon)\n" if ($dbg_values > 1);
+
+ substr($var, length($res), 1, $av_pend_colon);
+ if ($av_pend_colon eq 'C' || $av_pend_colon eq 'L') {
+ $type = 'E';
+ } else {
+ $type = 'N';
+ }
+ $av_pend_colon = 'O';
+
+ } elsif ($cur =~ /^(\[)/o) {
+ print "CLOSE($1)\n" if ($dbg_values > 1);
+ $type = 'N';
+
+ } elsif ($cur =~ /^(-(?![->])|\+(?!\+)|\*|\&\&|\&)/o) {
+ my $variant;
+
+ print "OPV($1)\n" if ($dbg_values > 1);
+ if ($type eq 'V') {
+ $variant = 'B';
+ } else {
+ $variant = 'U';
+ }
+
+ substr($var, length($res), 1, $variant);
+ $type = 'N';
+
+ } elsif ($cur =~ /^($Operators)/o) {
+ print "OP($1)\n" if ($dbg_values > 1);
+ if ($1 ne '++' && $1 ne '--') {
+ $type = 'N';
+ }
+
+ } elsif ($cur =~ /(^.)/o) {
+ print "C($1)\n" if ($dbg_values > 1);
+ }
+ if (defined $1) {
+ $cur = substr($cur, length($1));
+ $res .= $type x length($1);
+ }
+ }
+
+ return ($res, $var);
+}
+
+sub possible {
+ my ($possible, $line) = @_;
+ my $notPermitted = qr{(?:
+ ^(?:
+ $Modifier|
+ $Storage|
+ $Type|
+ DEFINE_\S+
+ )$|
+ ^(?:
+ goto|
+ return|
+ case|
+ else|
+ asm|__asm__|
+ do|
+ \#|
+ \#\#|
+ )(?:\s|$)|
+ ^(?:typedef|struct|enum)\b
+ )}x;
+ warn "CHECK<$possible> ($line)\n" if ($dbg_possible > 2);
+ if ($possible !~ $notPermitted) {
+ # Check for modifiers.
+ $possible =~ s/\s*$Storage\s*//g;
+ $possible =~ s/\s*$Sparse\s*//g;
+ if ($possible =~ /^\s*$/) {
+
+ } elsif ($possible =~ /\s/) {
+ $possible =~ s/\s*$Type\s*//g;
+ for my $modifier (split(' ', $possible)) {
+ if ($modifier !~ $notPermitted) {
+ warn "MODIFIER: $modifier ($possible) ($line)\n" if ($dbg_possible);
+ push(@modifierListFile, $modifier);
+ }
+ }
+
+ } else {
+ warn "POSSIBLE: $possible ($line)\n" if ($dbg_possible);
+ push(@typeListFile, $possible);
+ }
+ build_types();
+ } else {
+ warn "NOTPOSS: $possible ($line)\n" if ($dbg_possible > 1);
+ }
+}
+
+my $prefix = '';
+
+sub show_type {
+ my ($type) = @_;
+
+ $type =~ tr/[a-z]/[A-Z]/;
+
+ return defined $use_type{$type} if (scalar keys %use_type > 0);
+
+ return !defined $ignore_type{$type};
+}
+
+sub report {
+ my ($level, $type, $msg) = @_;
+
+ if (!show_type($type) ||
+ (defined $tst_only && $msg !~ /\Q$tst_only\E/)) {
+ return 0;
+ }
+ my $output = '';
+ if ($color) {
+ if ($level eq 'ERROR') {
+ $output .= RED;
+ } elsif ($level eq 'WARNING') {
+ $output .= YELLOW;
+ } else {
+ $output .= GREEN;
+ }
+ }
+ $output .= $prefix . $level . ':';
+ if ($show_types) {
+ $output .= BLUE if ($color);
+ $output .= "$type:";
+ }
+ $output .= RESET if ($color);
+ $output .= ' ' . $msg . "\n";
+
+ if ($showfile) {
+ my @lines = split("\n", $output, -1);
+ splice(@lines, 1, 1);
+ $output = join("\n", @lines);
+ }
+ $output = (split('\n', $output))[0] . "\n" if ($terse);
+
+ push(our @report, $output);
+
+ return 1;
+}
+
+sub report_dump {
+ our @report;
+}
+
+sub fixup_current_range {
+ my ($lineRef, $offset, $length) = @_;
+
+ if ($$lineRef =~ /^\@\@ -\d+,\d+ \+(\d+),(\d+) \@\@/) {
+ my $o = $1;
+ my $l = $2;
+ my $no = $o + $offset;
+ my $nl = $l + $length;
+ $$lineRef =~ s/\+$o,$l \@\@/\+$no,$nl \@\@/;
+ }
+}
+
+sub fix_inserted_deleted_lines {
+ my ($linesRef, $insertedRef, $deletedRef) = @_;
+
+ my $range_last_linenr = 0;
+ my $delta_offset = 0;
+
+ my $old_linenr = 0;
+ my $new_linenr = 0;
+
+ my $next_insert = 0;
+ my $next_delete = 0;
+
+ my @lines = ();
+
+ my $inserted = @{$insertedRef}[$next_insert++];
+ my $deleted = @{$deletedRef}[$next_delete++];
+
+ foreach my $old_line (@{$linesRef}) {
+ my $save_line = 1;
+ my $line = $old_line; #don't modify the array
+ if ($line =~ /^(?:\+\+\+|\-\-\-)\s+\S+/) { #new filename
+ $delta_offset = 0;
+ } elsif ($line =~ /^\@\@ -\d+,\d+ \+\d+,\d+ \@\@/) { #new hunk
+ $range_last_linenr = $new_linenr;
+ fixup_current_range(\$line, $delta_offset, 0);
+ }
+
+ while (defined($deleted) && ${$deleted}{'LINENR'} == $old_linenr) {
+ $deleted = @{$deletedRef}[$next_delete++];
+ $save_line = 0;
+ fixup_current_range(\$lines[$range_last_linenr], $delta_offset--, -1);
+ }
+
+ while (defined($inserted) && ${$inserted}{'LINENR'} == $old_linenr) {
+ push(@lines, ${$inserted}{'LINE'});
+ $inserted = @{$insertedRef}[$next_insert++];
+ $new_linenr++;
+ fixup_current_range(\$lines[$range_last_linenr], $delta_offset++, 1);
+ }
+
+ if ($save_line) {
+ push(@lines, $line);
+ $new_linenr++;
+ }
+
+ $old_linenr++;
+ }
+
+ return @lines;
+}
+
+sub fix_insert_line {
+ my ($linenr, $line) = @_;
+
+ my $inserted = {
+ LINENR => $linenr,
+ LINE => $line,
+ };
+ push(@fixed_inserted, $inserted);
+}
+
+sub fix_delete_line {
+ my ($linenr, $line) = @_;
+
+ my $deleted = {
+ LINENR => $linenr,
+ LINE => $line,
+ };
+
+ push(@fixed_deleted, $deleted);
+}
+
+sub ERROR {
+ my ($type, $msg) = @_;
+
+ if (report("ERROR", $type, $msg)) {
+ our $clean = 0;
+ our $cnt_error++;
+ return 1;
+ }
+ return 0;
+}
+sub WARN {
+ my ($type, $msg) = @_;
+
+ if (report("WARNING", $type, $msg)) {
+ our $clean = 0;
+ our $cnt_warn++;
+ return 1;
+ }
+ return 0;
+}
+sub CHK {
+ my ($type, $msg) = @_;
+
+ if ($check && report("CHECK", $type, $msg)) {
+ our $clean = 0;
+ our $cnt_chk++;
+ return 1;
+ }
+ return 0;
+}
+
+sub check_absolute_file {
+ my ($absolute, $herecurr) = @_;
+ my $file = $absolute;
+
+ ##print "absolute<$absolute>\n";
+
+ # See if any suffix of this path is a path within the tree.
+ while ($file =~ s@^[^/]*/@@) {
+ if (-f "$root/$file") {
+ ##print "file<$file>\n";
+ last;
+ }
+ }
+ if (! -f _) {
+ return 0;
+ }
+
+ # It is, so see if the prefix is acceptable.
+ my $prefix = $absolute;
+ substr($prefix, -length($file)) = '';
+
+ ##print "prefix<$prefix>\n";
+ if ($prefix ne ".../") {
+ WARN("USE_RELATIVE_PATH",
+ "use relative pathname instead of absolute in changelog text\n" . $herecurr);
+ }
+}
+
+sub trim {
+ my ($string) = @_;
+
+ $string =~ s/^\s+|\s+$//g;
+
+ return $string;
+}
+
+sub ltrim {
+ my ($string) = @_;
+
+ $string =~ s/^\s+//;
+
+ return $string;
+}
+
+sub rtrim {
+ my ($string) = @_;
+
+ $string =~ s/\s+$//;
+
+ return $string;
+}
+
+sub string_find_replace {
+ my ($string, $find, $replace) = @_;
+
+ $string =~ s/$find/$replace/g;
+
+ return $string;
+}
+
+sub tabify {
+ my ($leading) = @_;
+
+ my $source_indent = 8;
+ my $max_spaces_before_tab = $source_indent - 1;
+ my $spaces_to_tab = " " x $source_indent;
+
+ #convert leading spaces to tabs
+ 1 while $leading =~ s@^([\t]*)$spaces_to_tab@$1\t@g;
+ #Remove spaces before a tab
+ 1 while $leading =~ s@^([\t]*)( {1,$max_spaces_before_tab})\t@$1\t@g;
+
+ return "$leading";
+}
+
+sub pos_last_openparen {
+ my ($line) = @_;
+
+ my $pos = 0;
+
+ my $opens = $line =~ tr/\(/\(/;
+ my $closes = $line =~ tr/\)/\)/;
+
+ my $last_openparen = 0;
+
+ if (($opens == 0) || ($closes >= $opens)) {
+ return -1;
+ }
+
+ my $len = length($line);
+
+ for ($pos = 0; $pos < $len; $pos++) {
+ my $string = substr($line, $pos);
+ if ($string =~ /^($FuncArg|$balanced_parens)/) {
+ $pos += length($1) - 1;
+ } elsif (substr($line, $pos, 1) eq '(') {
+ $last_openparen = $pos;
+ } elsif (index($string, '(') == -1) {
+ last;
+ }
+ }
+
+ return length(expand_tabs(substr($line, 0, $last_openparen))) + 1;
+}
+
+sub process {
+ my $filename = shift;
+
+ my $linenr=0;
+ my $prevline="";
+ my $prevrawline="";
+ my $stashline="";
+ my $stashrawline="";
+
+ my $length;
+ my $indent;
+ my $previndent=0;
+ my $stashindent=0;
+
+ our $clean = 1;
+ my $signoff = 0;
+ my $author = '';
+ my $authorsignoff = 0;
+ my $is_patch = 0;
+ my $is_binding_patch = -1;
+ my $in_header_lines = $file ? 0 : 1;
+ my $in_commit_log = 0; #Scanning lines before patch
+ my $has_commit_log = 0; #Encountered lines before patch
+ my $commit_log_lines = 0; #Number of commit log lines
+ my $commit_log_possible_stack_dump = 0;
+ my $commit_log_long_line = 0;
+ my $commit_log_has_diff = 0;
+ my $reported_maintainer_file = 0;
+ my $non_utf8_charset = 0;
+
+ my $last_blank_line = 0;
+ my $last_coalesced_string_linenr = -1;
+
+ our @report = ();
+ our $cnt_lines = 0;
+ our $cnt_error = 0;
+ our $cnt_warn = 0;
+ our $cnt_chk = 0;
+
+ # Trace the real file/line as we go.
+ my $realfile = '';
+ my $realline = 0;
+ my $realcnt = 0;
+ my $here = '';
+ my $context_function; #undef'd unless there's a known function
+ my $in_comment = 0;
+ my $comment_edge = 0;
+ my $first_line = 0;
+ my $p1_prefix = '';
+
+ my $prev_values = 'E';
+
+ # suppression flags
+ my %suppress_ifbraces;
+ my %suppress_whiletrailers;
+ my %suppress_export;
+ my $suppress_statement = 0;
+
+ my %signatures = ();
+
+ # Pre-scan the patch sanitizing the lines.
+ # Pre-scan the patch looking for any __setup documentation.
+ #
+ my @setup_docs = ();
+ my $setup_docs = 0;
+
+ my $camelcase_file_seeded = 0;
+
+ my $checklicenseline = 1;
+
+ sanitise_line_reset();
+ my $line;
+ foreach my $rawline (@rawlines) {
+ $linenr++;
+ $line = $rawline;
+
+ push(@fixed, $rawline) if ($fix);
+
+ if ($rawline=~/^\+\+\+\s+(\S+)/) {
+ $setup_docs = 0;
+ if ($1 =~ m@Documentation/admin-guide/kernel-parameters.rst$@) {
+ $setup_docs = 1;
+ }
+ #next;
+ }
+ if ($rawline =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
+ $realline=$1-1;
+ if (defined $2) {
+ $realcnt=$3+1;
+ } else {
+ $realcnt=1+1;
+ }
+ $in_comment = 0;
+
+ # Guestimate if this is a continuing comment. Run
+ # the context looking for a comment "edge". If this
+ # edge is a close comment then we must be in a comment
+ # at context start.
+ my $edge;
+ my $cnt = $realcnt;
+ for (my $ln = $linenr + 1; $cnt > 0; $ln++) {
+ next if (defined $rawlines[$ln - 1] &&
+ $rawlines[$ln - 1] =~ /^-/);
+ $cnt--;
+ #print "RAW<$rawlines[$ln - 1]>\n";
+ last if (!defined $rawlines[$ln - 1]);
+ if ($rawlines[$ln - 1] =~ m@(/\*|\*/)@ &&
+ $rawlines[$ln - 1] !~ m@"[^"]*(?:/\*|\*/)[^"]*"@) {
+ ($edge) = $1;
+ last;
+ }
+ }
+ if (defined $edge && $edge eq '*/') {
+ $in_comment = 1;
+ }
+
+ # Guestimate if this is a continuing comment. If this
+ # is the start of a diff block and this line starts
+ # ' *' then it is very likely a comment.
+ if (!defined $edge &&
+ $rawlines[$linenr] =~ m@^.\s*(?:\*\*+| \*)(?:\s|$)@)
+ {
+ $in_comment = 1;
+ }
+
+ ##print "COMMENT:$in_comment edge<$edge> $rawline\n";
+ sanitise_line_reset($in_comment);
+
+ } elsif ($realcnt && $rawline =~ /^(?:\+| |$)/) {
+ # Standardise the strings and chars within the input to
+ # simplify matching -- only bother with positive lines.
+ $line = sanitise_line($rawline);
+ }
+ push(@lines, $line);
+
+ if ($realcnt > 1) {
+ $realcnt-- if ($line =~ /^(?:\+| |$)/);
+ } else {
+ $realcnt = 0;
+ }
+
+ #print "==>$rawline\n";
+ #print "-->$line\n";
+
+ if ($setup_docs && $line =~ /^\+/) {
+ push(@setup_docs, $line);
+ }
+ }
+
+ $prefix = '';
+
+ $realcnt = 0;
+ $linenr = 0;
+ $fixlinenr = -1;
+ foreach my $line (@lines) {
+ $linenr++;
+ $fixlinenr++;
+ my $sline = $line; #copy of $line
+ $sline =~ s/$;/ /g; #with comments as spaces
+
+ my $rawline = $rawlines[$linenr - 1];
+
+# check if it's a mode change, rename or start of a patch
+ if (!$in_commit_log &&
+ ($line =~ /^ mode change [0-7]+ => [0-7]+ \S+\s*$/ ||
+ ($line =~ /^rename (?:from|to) \S+\s*$/ ||
+ $line =~ /^diff --git a\/[\w\/\.\_\-]+ b\/\S+\s*$/))) {
+ $is_patch = 1;
+ }
+
+#extract the line range in the file after the patch is applied
+ if (!$in_commit_log &&
+ $line =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@(.*)/) {
+ my $context = $4;
+ $is_patch = 1;
+ $first_line = $linenr + 1;
+ $realline=$1-1;
+ if (defined $2) {
+ $realcnt=$3+1;
+ } else {
+ $realcnt=1+1;
+ }
+ annotate_reset();
+ $prev_values = 'E';
+
+ %suppress_ifbraces = ();
+ %suppress_whiletrailers = ();
+ %suppress_export = ();
+ $suppress_statement = 0;
+ if ($context =~ /\b(\w+)\s*\(/) {
+ $context_function = $1;
+ } else {
+ undef $context_function;
+ }
+ next;
+
+# track the line number as we move through the hunk, note that
+# new versions of GNU diff omit the leading space on completely
+# blank context lines so we need to count that too.
+ } elsif ($line =~ /^( |\+|$)/) {
+ $realline++;
+ $realcnt-- if ($realcnt != 0);
+
+ # Measure the line length and indent.
+ ($length, $indent) = line_stats($rawline);
+
+ # Track the previous line.
+ ($prevline, $stashline) = ($stashline, $line);
+ ($previndent, $stashindent) = ($stashindent, $indent);
+ ($prevrawline, $stashrawline) = ($stashrawline, $rawline);
+
+ #warn "line<$line>\n";
+
+ } elsif ($realcnt == 1) {
+ $realcnt--;
+ }
+
+ my $hunk_line = ($realcnt != 0);
+
+ $here = "#$linenr: " if (!$file);
+ $here = "#$realline: " if ($file);
+
+ my $found_file = 0;
+ # extract the filename as it passes
+ if ($line =~ /^diff --git.*?(\S+)$/) {
+ $realfile = $1;
+ $realfile =~ s@^([^/]*)/@@ if (!$file);
+ $in_commit_log = 0;
+ $found_file = 1;
+ } elsif ($line =~ /^\+\+\+\s+(\S+)/) {
+ $realfile = $1;
+ $realfile =~ s@^([^/]*)/@@ if (!$file);
+ $in_commit_log = 0;
+
+ $p1_prefix = $1;
+ if (!$file && $tree && $p1_prefix ne '' &&
+ -e "$root/$p1_prefix") {
+ WARN("PATCH_PREFIX",
+ "patch prefix '$p1_prefix' exists, appears to be a -p0 patch\n");
+ }
+
+ if ($realfile =~ m@^include/asm/@) {
+ ERROR("MODIFIED_INCLUDE_ASM",
+ "do not modify files in include/asm, change architecture specific files in include/asm-<architecture>\n" . "$here$rawline\n");
+ }
+ $found_file = 1;
+ }
+
+#make up the handle for any error we report on this line
+ if ($showfile) {
+ $prefix = "$realfile:$realline: "
+ } elsif ($emacs) {
+ if ($file) {
+ $prefix = "$filename:$realline: ";
+ } else {
+ $prefix = "$filename:$linenr: ";
+ }
+ }
+
+ if ($found_file) {
+ if (is_maintained_obsolete($realfile)) {
+ WARN("OBSOLETE",
+ "$realfile is marked as 'obsolete' in the MAINTAINERS hierarchy. No unnecessary modifications please.\n");
+ }
+ if ($realfile =~ m@^(?:drivers/net/|net/|drivers/staging/)@) {
+ $check = 1;
+ } else {
+ $check = $check_orig;
+ }
+ $checklicenseline = 1;
+
+ if ($realfile !~ /^MAINTAINERS/) {
+ my $last_binding_patch = $is_binding_patch;
+
+ $is_binding_patch = () = $realfile =~ m@^(?:Documentation/devicetree/|include/dt-bindings/)@;
+
+ if (($last_binding_patch != -1) &&
+ ($last_binding_patch ^ $is_binding_patch)) {
+ WARN("DT_SPLIT_BINDING_PATCH",
+ "DT binding docs and includes should be a separate patch. See: Documentation/devicetree/bindings/submitting-patches.txt\n");
+ }
+ }
+
+ next;
+ }
+
+ $here .= "FILE: $realfile:$realline:" if ($realcnt != 0);
+
+ my $hereline = "$here\n$rawline\n";
+ my $herecurr = "$here\n$rawline\n";
+ my $hereprev = "$here\n$prevrawline\n$rawline\n";
+
+ $cnt_lines++ if ($realcnt != 0);
+
+# Verify the existence of a commit log if appropriate
+# 2 is used because a $signature is counted in $commit_log_lines
+ if ($in_commit_log) {
+ if ($line !~ /^\s*$/) {
+ $commit_log_lines++; #could be a $signature
+ }
+ } elsif ($has_commit_log && $commit_log_lines < 2) {
+ WARN("COMMIT_MESSAGE",
+ "Missing commit description - Add an appropriate one\n");
+ $commit_log_lines = 2; #warn only once
+ }
+
+# Check if the commit log has what seems like a diff which can confuse patch
+ if ($in_commit_log && !$commit_log_has_diff &&
+ (($line =~ m@^\s+diff\b.*a/[\w/]+@ &&
+ $line =~ m@^\s+diff\b.*a/([\w/]+)\s+b/$1\b@) ||
+ $line =~ m@^\s*(?:\-\-\-\s+a/|\+\+\+\s+b/)@ ||
+ $line =~ m/^\s*\@\@ \-\d+,\d+ \+\d+,\d+ \@\@/)) {
+ ERROR("DIFF_IN_COMMIT_MSG",
+ "Avoid using diff content in the commit message - patch(1) might not work\n" . $herecurr);
+ $commit_log_has_diff = 1;
+ }
+
+# Check for incorrect file permissions
+ if ($line =~ /^new (file )?mode.*[7531]\d{0,2}$/) {
+ my $permhere = $here . "FILE: $realfile\n";
+ if ($realfile !~ m@scripts/@ &&
+ $realfile !~ /\.(py|pl|awk|sh)$/) {
+ ERROR("EXECUTE_PERMISSIONS",
+ "do not set execute permissions for source files\n" . $permhere);
+ }
+ }
+
+# Check the patch for a From:
+ if (decode("MIME-Header", $line) =~ /^From:\s*(.*)/) {
+ $author = $1;
+ $author = encode("utf8", $author) if ($line =~ /=\?utf-8\?/i);
+ $author =~ s/"//g;
+ }
+
+# Check the patch for a signoff:
+ if ($line =~ /^\s*signed-off-by:/i) {
+ $signoff++;
+ $in_commit_log = 0;
+ if ($author ne '') {
+ my $l = $line;
+ $l =~ s/"//g;
+ if ($l =~ /^\s*signed-off-by:\s*\Q$author\E/i) {
+ $authorsignoff = 1;
+ }
+ }
+ }
+
+# Check if MAINTAINERS is being updated. If so, there's probably no need to
+# emit the "does MAINTAINERS need updating?" message on file add/move/delete
+ if ($line =~ /^\s*MAINTAINERS\s*\|/) {
+ $reported_maintainer_file = 1;
+ }
+
+# Check signature styles
+ if (!$in_header_lines &&
+ $line =~ /^(\s*)([a-z0-9_-]+by:|$signature_tags)(\s*)(.*)/i) {
+ my $space_before = $1;
+ my $sign_off = $2;
+ my $space_after = $3;
+ my $email = $4;
+ my $ucfirst_sign_off = ucfirst(lc($sign_off));
+
+ if ($sign_off !~ /$signature_tags/) {
+ WARN("BAD_SIGN_OFF",
+ "Non-standard signature: $sign_off\n" . $herecurr);
+ }
+ if (defined $space_before && $space_before ne "") {
+ if (WARN("BAD_SIGN_OFF",
+ "Do not use whitespace before $ucfirst_sign_off\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =
+ "$ucfirst_sign_off $email";
+ }
+ }
+ if ($sign_off =~ /-by:$/i && $sign_off ne $ucfirst_sign_off) {
+ if (WARN("BAD_SIGN_OFF",
+ "'$ucfirst_sign_off' is the preferred signature form\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =
+ "$ucfirst_sign_off $email";
+ }
+
+ }
+ if (!defined $space_after || $space_after ne " ") {
+ if (WARN("BAD_SIGN_OFF",
+ "Use a single space after $ucfirst_sign_off\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =
+ "$ucfirst_sign_off $email";
+ }
+ }
+
+ my ($email_name, $email_address, $comment) = parse_email($email);
+ my $suggested_email = format_email(($email_name, $email_address));
+ if ($suggested_email eq "") {
+ ERROR("BAD_SIGN_OFF",
+ "Unrecognized email address: '$email'\n" . $herecurr);
+ } else {
+ my $dequoted = $suggested_email;
+ $dequoted =~ s/^"//;
+ $dequoted =~ s/" </ </;
+ # Don't force email to have quotes
+ # Allow just an angle bracketed address
+ if ("$dequoted$comment" ne $email &&
+ "<$email_address>$comment" ne $email &&
+ "$suggested_email$comment" ne $email) {
+ WARN("BAD_SIGN_OFF",
+ "email address '$email' might be better as '$suggested_email$comment'\n" . $herecurr);
+ }
+ }
+
+# Check for duplicate signatures
+ my $sig_nospace = $line;
+ $sig_nospace =~ s/\s//g;
+ $sig_nospace = lc($sig_nospace);
+ if (defined $signatures{$sig_nospace}) {
+ WARN("BAD_SIGN_OFF",
+ "Duplicate signature\n" . $herecurr);
+ } else {
+ $signatures{$sig_nospace} = 1;
+ }
+ }
+
+# Check email subject for common tools that don't need to be mentioned
+ if ($in_header_lines &&
+ $line =~ /^Subject:.*\b(?:checkpatch|sparse|smatch)\b[^:]/i) {
+ WARN("EMAIL_SUBJECT",
+ "A patch subject line should describe the change not the tool that found it\n" . $herecurr);
+ }
+
+# Check for unwanted Gerrit info
+ if ($in_commit_log && $line =~ /^\s*change-id:/i) {
+ ERROR("GERRIT_CHANGE_ID",
+ "Remove Gerrit Change-Id's before submitting upstream.\n" . $herecurr);
+ }
+
+# Check if the commit log is in a possible stack dump
+ if ($in_commit_log && !$commit_log_possible_stack_dump &&
+ ($line =~ /^\s*(?:WARNING:|BUG:)/ ||
+ $line =~ /^\s*\[\s*\d+\.\d{6,6}\s*\]/ ||
+ # timestamp
+ $line =~ /^\s*\[\<[0-9a-fA-F]{8,}\>\]/)) {
+ # stack dump address
+ $commit_log_possible_stack_dump = 1;
+ }
+
+# Check for line lengths > 75 in commit log, warn once
+ if ($in_commit_log && !$commit_log_long_line &&
+ length($line) > 75 &&
+ !($line =~ /^\s*[a-zA-Z0-9_\/\.]+\s+\|\s+\d+/ ||
+ # file delta changes
+ $line =~ /^\s*(?:[\w\.\-]+\/)++[\w\.\-]+:/ ||
+ # filename then :
+ $line =~ /^\s*(?:Fixes:|Link:)/i ||
+ # A Fixes: or Link: line
+ $commit_log_possible_stack_dump)) {
+ WARN("COMMIT_LOG_LONG_LINE",
+ "Possible unwrapped commit description (prefer a maximum 75 chars per line)\n" . $herecurr);
+ $commit_log_long_line = 1;
+ }
+
+# Reset possible stack dump if a blank line is found
+ if ($in_commit_log && $commit_log_possible_stack_dump &&
+ $line =~ /^\s*$/) {
+ $commit_log_possible_stack_dump = 0;
+ }
+
+# Check for git id commit length and improperly formed commit descriptions
+ if ($in_commit_log && !$commit_log_possible_stack_dump &&
+ $line !~ /^\s*(?:Link|Patchwork|http|https|BugLink):/i &&
+ $line !~ /^This reverts commit [0-9a-f]{7,40}/ &&
+ ($line =~ /\bcommit\s+[0-9a-f]{5,}\b/i ||
+ ($line =~ /(?:\s|^)[0-9a-f]{12,40}(?:[\s"'\(\[]|$)/i &&
+ $line !~ /[\<\[][0-9a-f]{12,40}[\>\]]/i &&
+ $line !~ /\bfixes:\s*[0-9a-f]{12,40}/i))) {
+ my $init_char = "c";
+ my $orig_commit = "";
+ my $short = 1;
+ my $long = 0;
+ my $case = 1;
+ my $space = 1;
+ my $hasdesc = 0;
+ my $hasparens = 0;
+ my $id = '0123456789ab';
+ my $orig_desc = "commit description";
+ my $description = "";
+
+ if ($line =~ /\b(c)ommit\s+([0-9a-f]{5,})\b/i) {
+ $init_char = $1;
+ $orig_commit = lc($2);
+ } elsif ($line =~ /\b([0-9a-f]{12,40})\b/i) {
+ $orig_commit = lc($1);
+ }
+
+ $short = 0 if ($line =~ /\bcommit\s+[0-9a-f]{12,40}/i);
+ $long = 1 if ($line =~ /\bcommit\s+[0-9a-f]{41,}/i);
+ $space = 0 if ($line =~ /\bcommit [0-9a-f]/i);
+ $case = 0 if ($line =~ /\b[Cc]ommit\s+[0-9a-f]{5,40}[^A-F]/);
+ if ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)"\)/i) {
+ $orig_desc = $1;
+ $hasparens = 1;
+ } elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s*$/i &&
+ defined $rawlines[$linenr] &&
+ $rawlines[$linenr] =~ /^\s*\("([^"]+)"\)/) {
+ $orig_desc = $1;
+ $hasparens = 1;
+ } elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("[^"]+$/i &&
+ defined $rawlines[$linenr] &&
+ $rawlines[$linenr] =~ /^\s*[^"]+"\)/) {
+ $line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)$/i;
+ $orig_desc = $1;
+ $rawlines[$linenr] =~ /^\s*([^"]+)"\)/;
+ $orig_desc .= " " . $1;
+ $hasparens = 1;
+ }
+
+ ($id, $description) = git_commit_info($orig_commit,
+ $id, $orig_desc);
+
+ if (defined($id) &&
+ ($short || $long || $space || $case || ($orig_desc ne $description) || !$hasparens)) {
+ ERROR("GIT_COMMIT_ID",
+ "Please use git commit description style 'commit <12+ chars of sha1> (\"<title line>\")' - ie: '${init_char}ommit $id (\"$description\")'\n" . $herecurr);
+ }
+ }
+
+# Check for added, moved or deleted files
+ if (!$reported_maintainer_file && !$in_commit_log &&
+ ($line =~ /^(?:new|deleted) file mode\s*\d+\s*$/ ||
+ $line =~ /^rename (?:from|to) [\w\/\.\-]+\s*$/ ||
+ ($line =~ /\{\s*([\w\/\.\-]*)\s*\=\>\s*([\w\/\.\-]*)\s*\}/ &&
+ (defined($1) || defined($2))))) {
+ $is_patch = 1;
+ $reported_maintainer_file = 1;
+ WARN("FILE_PATH_CHANGES",
+ "added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr);
+ }
+
+# Check for wrappage within a valid hunk of the file
+ if ($realcnt != 0 && $line !~ m{^(?:\+|-| |\\ No newline|$)}) {
+ ERROR("CORRUPTED_PATCH",
+ "patch seems to be corrupt (line wrapped?)\n" .
+ $herecurr) if (!$emitted_corrupt++);
+ }
+
+# UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php
+ if (($realfile =~ /^$/ || $line =~ /^\+/) &&
+ $rawline !~ m/^$UTF8*$/) {
+ my ($utf8_prefix) = ($rawline =~ /^($UTF8*)/);
+
+ my $blank = copy_spacing($rawline);
+ my $ptr = substr($blank, 0, length($utf8_prefix)) . "^";
+ my $hereptr = "$hereline$ptr\n";
+
+ CHK("INVALID_UTF8",
+ "Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr);
+ }
+
+# Check if it's the start of a commit log
+# (not a header line and we haven't seen the patch filename)
+ if ($in_header_lines && $realfile =~ /^$/ &&
+ !($rawline =~ /^\s+(?:\S|$)/ ||
+ $rawline =~ /^(?:commit\b|from\b|[\w-]+:)/i)) {
+ $in_header_lines = 0;
+ $in_commit_log = 1;
+ $has_commit_log = 1;
+ }
+
+# Check if there is UTF-8 in a commit log when a mail header has explicitly
+# declined it, i.e defined some charset where it is missing.
+ if ($in_header_lines &&
+ $rawline =~ /^Content-Type:.+charset="(.+)".*$/ &&
+ $1 !~ /utf-8/i) {
+ $non_utf8_charset = 1;
+ }
+
+ if ($in_commit_log && $non_utf8_charset && $realfile =~ /^$/ &&
+ $rawline =~ /$NON_ASCII_UTF8/) {
+ WARN("UTF8_BEFORE_PATCH",
+ "8-bit UTF-8 used in possible commit log\n" . $herecurr);
+ }
+
+# Check for absolute kernel paths in commit message
+ if ($tree && $in_commit_log) {
+ while ($line =~ m{(?:^|\s)(/\S*)}g) {
+ my $file = $1;
+
+ if ($file =~ m{^(.*?)(?::\d+)+:?$} &&
+ check_absolute_file($1, $herecurr)) {
+ #
+ } else {
+ check_absolute_file($file, $herecurr);
+ }
+ }
+ }
+
+# Check for various typo / spelling mistakes
+ if (defined($misspellings) &&
+ ($in_commit_log || $line =~ /^(?:\+|Subject:)/i)) {
+ while ($rawline =~ /(?:^|[^a-z@])($misspellings)(?:\b|$|[^a-z@])/gi) {
+ my $typo = $1;
+ my $typo_fix = $spelling_fix{lc($typo)};
+ $typo_fix = ucfirst($typo_fix) if ($typo =~ /^[A-Z]/);
+ $typo_fix = uc($typo_fix) if ($typo =~ /^[A-Z]+$/);
+ my $msg_level = \&WARN;
+ $msg_level = \&CHK if ($file);
+ if (&{$msg_level}("TYPO_SPELLING",
+ "'$typo' may be misspelled - perhaps '$typo_fix'?\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/(^|[^A-Za-z@])($typo)($|[^A-Za-z@])/$1$typo_fix$3/;
+ }
+ }
+ }
+
+# ignore non-hunk lines and lines being removed
+ next if (!$hunk_line || $line =~ /^-/);
+
+#trailing whitespace
+ if ($line =~ /^\+.*\015/) {
+ my $herevet = "$here\n" . cat_vet($rawline) . "\n";
+ if (ERROR("DOS_LINE_ENDINGS",
+ "DOS line endings\n" . $herevet) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/[\s\015]+$//;
+ }
+ } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) {
+ my $herevet = "$here\n" . cat_vet($rawline) . "\n";
+ if (ERROR("TRAILING_WHITESPACE",
+ "trailing whitespace\n" . $herevet) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/\s+$//;
+ }
+
+ $rpt_cleaners = 1;
+ }
+
+# Check for FSF mailing addresses.
+ if ($rawline =~ /\bwrite to the Free/i ||
+ $rawline =~ /\b675\s+Mass\s+Ave/i ||
+ $rawline =~ /\b59\s+Temple\s+Pl/i ||
+ $rawline =~ /\b51\s+Franklin\s+St/i) {
+ my $herevet = "$here\n" . cat_vet($rawline) . "\n";
+ my $msg_level = \&ERROR;
+ $msg_level = \&CHK if ($file);
+ &{$msg_level}("FSF_MAILING_ADDRESS",
+ "Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.\n" . $herevet)
+ }
+
+# check for Kconfig help text having a real description
+# Only applies when adding the entry originally, after that we do not have
+# sufficient context to determine whether it is indeed long enough.
+ if ($realfile =~ /Kconfig/ &&
+ # 'choice' is usually the last thing on the line (though
+ # Kconfig supports named choices), so use a word boundary
+ # (\b) rather than a whitespace character (\s)
+ $line =~ /^\+\s*(?:config|menuconfig|choice)\b/) {
+ my $length = 0;
+ my $cnt = $realcnt;
+ my $ln = $linenr + 1;
+ my $f;
+ my $is_start = 0;
+ my $is_end = 0;
+ for (; $cnt > 0 && defined $lines[$ln - 1]; $ln++) {
+ $f = $lines[$ln - 1];
+ $cnt-- if ($lines[$ln - 1] !~ /^-/);
+ $is_end = $lines[$ln - 1] =~ /^\+/;
+
+ next if ($f =~ /^-/);
+ last if (!$file && $f =~ /^\@\@/);
+
+ if ($lines[$ln - 1] =~ /^\+\s*(?:bool|tristate|prompt)\s*["']/) {
+ $is_start = 1;
+ } elsif ($lines[$ln - 1] =~ /^\+\s*(?:help|---help---)\s*$/) {
+ if ($lines[$ln - 1] =~ "---help---") {
+ WARN("CONFIG_DESCRIPTION",
+ "prefer 'help' over '---help---' for new help texts\n" . $herecurr);
+ }
+ $length = -1;
+ }
+
+ $f =~ s/^.//;
+ $f =~ s/#.*//;
+ $f =~ s/^\s+//;
+ next if ($f =~ /^$/);
+
+ # This only checks context lines in the patch
+ # and so hopefully shouldn't trigger false
+ # positives, even though some of these are
+ # common words in help texts
+ if ($f =~ /^\s*(?:config|menuconfig|choice|endchoice|
+ if|endif|menu|endmenu|source)\b/x) {
+ $is_end = 1;
+ last;
+ }
+ $length++;
+ }
+ if ($is_start && $is_end && $length < $min_conf_desc_length) {
+ WARN("CONFIG_DESCRIPTION",
+ "please write a paragraph that describes the config symbol fully\n" . $herecurr);
+ }
+ #print "is_start<$is_start> is_end<$is_end> length<$length>\n";
+ }
+
+# check for MAINTAINERS entries that don't have the right form
+ if ($realfile =~ /^MAINTAINERS$/ &&
+ $rawline =~ /^\+[A-Z]:/ &&
+ $rawline !~ /^\+[A-Z]:\t\S/) {
+ if (WARN("MAINTAINERS_STYLE",
+ "MAINTAINERS entries use one tab after TYPE:\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/^(\+[A-Z]):\s*/$1:\t/;
+ }
+ }
+
+# discourage the use of boolean for type definition attributes of Kconfig options
+ if ($realfile =~ /Kconfig/ &&
+ $line =~ /^\+\s*\bboolean\b/) {
+ WARN("CONFIG_TYPE_BOOLEAN",
+ "Use of boolean is deprecated, please use bool instead.\n" . $herecurr);
+ }
+
+ if (($realfile =~ /Makefile.*/ || $realfile =~ /Kbuild.*/) &&
+ ($line =~ /\+(EXTRA_[A-Z]+FLAGS).*/)) {
+ my $flag = $1;
+ my $replacement = {
+ 'EXTRA_AFLAGS' => 'asflags-y',
+ 'EXTRA_CFLAGS' => 'ccflags-y',
+ 'EXTRA_CPPFLAGS' => 'cppflags-y',
+ 'EXTRA_LDFLAGS' => 'ldflags-y',
+ };
+
+ WARN("DEPRECATED_VARIABLE",
+ "Use of $flag is deprecated, please use \`$replacement->{$flag} instead.\n" . $herecurr) if ($replacement->{$flag});
+ }
+
+# check for DT compatible documentation
+ if (defined $root &&
+ (($realfile =~ /\.dtsi?$/ && $line =~ /^\+\s*compatible\s*=\s*\"/) ||
+ ($realfile =~ /\.[ch]$/ && $line =~ /^\+.*\.compatible\s*=\s*\"/))) {
+
+ my @compats = $rawline =~ /\"([a-zA-Z0-9\-\,\.\+_]+)\"/g;
+
+ my $dt_path = $root . "/Documentation/devicetree/bindings/";
+ my $vp_file = $dt_path . "vendor-prefixes.txt";
+
+ foreach my $compat (@compats) {
+ my $compat2 = $compat;
+ $compat2 =~ s/\,[a-zA-Z0-9]*\-/\,<\.\*>\-/;
+ my $compat3 = $compat;
+ $compat3 =~ s/\,([a-z]*)[0-9]*\-/\,$1<\.\*>\-/;
+ `grep -Erq "$compat|$compat2|$compat3" $dt_path`;
+ if ( $? >> 8 ) {
+ WARN("UNDOCUMENTED_DT_STRING",
+ "DT compatible string \"$compat\" appears un-documented -- check $dt_path\n" . $herecurr);
+ }
+
+ next if $compat !~ /^([a-zA-Z0-9\-]+)\,/;
+ my $vendor = $1;
+ `grep -Eq "^$vendor\\b" $vp_file`;
+ if ( $? >> 8 ) {
+ WARN("UNDOCUMENTED_DT_STRING",
+ "DT compatible string vendor \"$vendor\" appears un-documented -- check $vp_file\n" . $herecurr);
+ }
+ }
+ }
+
+# check for using SPDX license tag at beginning of files
+ if ($realline == $checklicenseline) {
+ if ($rawline =~ /^[ \+]\s*\#\!\s*\//) {
+ $checklicenseline = 2;
+ } elsif ($rawline =~ /^\+/) {
+ my $comment = "";
+ if ($realfile =~ /\.(h|s|S)$/) {
+ $comment = '/*';
+ } elsif ($realfile =~ /\.(c|dts|dtsi)$/) {
+ $comment = '//';
+ } elsif (($checklicenseline == 2) || $realfile =~ /\.(sh|pl|py|awk|tc)$/) {
+ $comment = '#';
+ } elsif ($realfile =~ /\.rst$/) {
+ $comment = '..';
+ }
+
+ if ($comment !~ /^$/ &&
+ $rawline !~ /^\+\Q$comment\E SPDX-License-Identifier: /) {
+ WARN("SPDX_LICENSE_TAG",
+ "Missing or malformed SPDX-License-Identifier tag in line $checklicenseline\n" . $herecurr);
+ } elsif ($rawline =~ /(SPDX-License-Identifier: .*)/) {
+ my $spdx_license = $1;
+ if (!is_SPDX_License_valid($spdx_license)) {
+ WARN("SPDX_LICENSE_TAG",
+ "'$spdx_license' is not supported in LICENSES/...\n" . $herecurr);
+ }
+ }
+ }
+ }
+
+# check we are in a valid source file if not then ignore this hunk
+ next if ($realfile !~ /\.(h|c|s|S|sh|dtsi|dts)$/);
+
+# line length limit (with some exclusions)
+#
+# There are a few types of lines that may extend beyond $max_line_length:
+# logging functions like pr_info that end in a string
+# lines with a single string
+# #defines that are a single string
+# lines with an RFC3986 like URL
+#
+# There are 3 different line length message types:
+# LONG_LINE_COMMENT a comment starts before but extends beyond $max_line_length
+# LONG_LINE_STRING a string starts before but extends beyond $max_line_length
+# LONG_LINE all other lines longer than $max_line_length
+#
+# if LONG_LINE is ignored, the other 2 types are also ignored
+#
+
+ if ($line =~ /^\+/ && $length > $max_line_length) {
+ my $msg_type = "LONG_LINE";
+
+ # Check the allowed long line types first
+
+ # logging functions that end in a string that starts
+ # before $max_line_length
+ if ($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(?:KERN_\S+\s*|[^"]*))?($String\s*(?:|,|\)\s*;)\s*)$/ &&
+ length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
+ $msg_type = "";
+
+ # lines with only strings (w/ possible termination)
+ # #defines with only strings
+ } elsif ($line =~ /^\+\s*$String\s*(?:\s*|,|\)\s*;)\s*$/ ||
+ $line =~ /^\+\s*#\s*define\s+\w+\s+$String$/) {
+ $msg_type = "";
+
+ # More special cases
+ } elsif ($line =~ /^\+.*\bEFI_GUID\s*\(/ ||
+ $line =~ /^\+\s*(?:\w+)?\s*DEFINE_PER_CPU/) {
+ $msg_type = "";
+
+ # URL ($rawline is used in case the URL is in a comment)
+ } elsif ($rawline =~ /^\+.*\b[a-z][\w\.\+\-]*:\/\/\S+/i) {
+ $msg_type = "";
+
+ # Otherwise set the alternate message types
+
+ # a comment starts before $max_line_length
+ } elsif ($line =~ /($;[\s$;]*)$/ &&
+ length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
+ $msg_type = "LONG_LINE_COMMENT"
+
+ # a quoted string starts before $max_line_length
+ } elsif ($sline =~ /\s*($String(?:\s*(?:\\|,\s*|\)\s*;\s*))?)$/ &&
+ length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
+ $msg_type = "LONG_LINE_STRING"
+ }
+
+ if ($msg_type ne "" &&
+ (show_type("LONG_LINE") || show_type($msg_type))) {
+ WARN($msg_type,
+ "line over $max_line_length characters\n" . $herecurr);
+ }
+ }
+
+# check for adding lines without a newline.
+ if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) {
+ WARN("MISSING_EOF_NEWLINE",
+ "adding a line without newline at end of file\n" . $herecurr);
+ }
+
+# check we are in a valid source file C or perl if not then ignore this hunk
+ next if ($realfile !~ /\.(h|c|pl|dtsi|dts)$/);
+
+# at the beginning of a line any tabs must come first and anything
+# more than 8 must use tabs.
+ if ($rawline =~ /^\+\s* \t\s*\S/ ||
+ $rawline =~ /^\+\s* \s*/) {
+ my $herevet = "$here\n" . cat_vet($rawline) . "\n";
+ $rpt_cleaners = 1;
+ if (ERROR("CODE_INDENT",
+ "code indent should use tabs where possible\n" . $herevet) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/^\+([ \t]+)/"\+" . tabify($1)/e;
+ }
+ }
+
+# check for space before tabs.
+ if ($rawline =~ /^\+/ && $rawline =~ / \t/) {
+ my $herevet = "$here\n" . cat_vet($rawline) . "\n";
+ if (WARN("SPACE_BEFORE_TAB",
+ "please, no space before tabs\n" . $herevet) &&
+ $fix) {
+ while ($fixed[$fixlinenr] =~
+ s/(^\+.*) {8,8}\t/$1\t\t/) {}
+ while ($fixed[$fixlinenr] =~
+ s/(^\+.*) +\t/$1\t/) {}
+ }
+ }
+
+# check for assignments on the start of a line
+ if ($sline =~ /^\+\s+($Assignment)[^=]/) {
+ CHK("ASSIGNMENT_CONTINUATIONS",
+ "Assignment operator '$1' should be on the previous line\n" . $hereprev);
+ }
+
+# check for && or || at the start of a line
+ if ($rawline =~ /^\+\s*(&&|\|\|)/) {
+ CHK("LOGICAL_CONTINUATIONS",
+ "Logical continuations should be on the previous line\n" . $hereprev);
+ }
+
+# check indentation starts on a tab stop
+ if ($perl_version_ok &&
+ $sline =~ /^\+\t+( +)(?:$c90_Keywords\b|\{\s*$|\}\s*(?:else\b|while\b|\s*$)|$Declare\s*$Ident\s*[;=])/) {
+ my $indent = length($1);
+ if ($indent % 8) {
+ if (WARN("TABSTOP",
+ "Statements should start on a tabstop\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s@(^\+\t+) +@$1 . "\t" x ($indent/8)@e;
+ }
+ }
+ }
+
+# check multi-line statement indentation matches previous line
+ if ($perl_version_ok &&
+ $prevline =~ /^\+([ \t]*)((?:$c90_Keywords(?:\s+if)\s*)|(?:$Declare\s*)?(?:$Ident|\(\s*\*\s*$Ident\s*\))\s*|(?:\*\s*)*$Lval\s*=\s*$Ident\s*)\(.*(\&\&|\|\||,)\s*$/) {
+ $prevline =~ /^\+(\t*)(.*)$/;
+ my $oldindent = $1;
+ my $rest = $2;
+
+ my $pos = pos_last_openparen($rest);
+ if ($pos >= 0) {
+ $line =~ /^(\+| )([ \t]*)/;
+ my $newindent = $2;
+
+ my $goodtabindent = $oldindent .
+ "\t" x ($pos / 8) .
+ " " x ($pos % 8);
+ my $goodspaceindent = $oldindent . " " x $pos;
+
+ if ($newindent ne $goodtabindent &&
+ $newindent ne $goodspaceindent) {
+
+ if (CHK("PARENTHESIS_ALIGNMENT",
+ "Alignment should match open parenthesis\n" . $hereprev) &&
+ $fix && $line =~ /^\+/) {
+ $fixed[$fixlinenr] =~
+ s/^\+[ \t]*/\+$goodtabindent/;
+ }
+ }
+ }
+ }
+
+# check for space after cast like "(int) foo" or "(struct foo) bar"
+# avoid checking a few false positives:
+# "sizeof(<type>)" or "__alignof__(<type>)"
+# function pointer declarations like "(*foo)(int) = bar;"
+# structure definitions like "(struct foo) { 0 };"
+# multiline macros that define functions
+# known attributes or the __attribute__ keyword
+ if ($line =~ /^\+(.*)\(\s*$Type\s*\)([ \t]++)((?![={]|\\$|$Attribute|__attribute__))/ &&
+ (!defined($1) || $1 !~ /\b(?:sizeof|__alignof__)\s*$/)) {
+ if (CHK("SPACING",
+ "No space is necessary after a cast\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~
+ s/(\(\s*$Type\s*\))[ \t]+/$1/;
+ }
+ }
+
+# Block comment styles
+# Networking with an initial /*
+ if ($realfile =~ m@^(drivers/net/|net/)@ &&
+ $prevrawline =~ /^\+[ \t]*\/\*[ \t]*$/ &&
+ $rawline =~ /^\+[ \t]*\*/ &&
+ $realline > 2) {
+ WARN("NETWORKING_BLOCK_COMMENT_STYLE",
+ "networking block comments don't use an empty /* line, use /* Comment...\n" . $hereprev);
+ }
+
+# Block comments use * on subsequent lines
+ if ($prevline =~ /$;[ \t]*$/ && #ends in comment
+ $prevrawline =~ /^\+.*?\/\*/ && #starting /*
+ $prevrawline !~ /\*\/[ \t]*$/ && #no trailing */
+ $rawline =~ /^\+/ && #line is new
+ $rawline !~ /^\+[ \t]*\*/) { #no leading *
+ WARN("BLOCK_COMMENT_STYLE",
+ "Block comments use * on subsequent lines\n" . $hereprev);
+ }
+
+# Block comments use */ on trailing lines
+ if ($rawline !~ m@^\+[ \t]*\*/[ \t]*$@ && #trailing */
+ $rawline !~ m@^\+.*/\*.*\*/[ \t]*$@ && #inline /*...*/
+ $rawline !~ m@^\+.*\*{2,}/[ \t]*$@ && #trailing **/
+ $rawline =~ m@^\+[ \t]*.+\*\/[ \t]*$@) { #non blank */
+ WARN("BLOCK_COMMENT_STYLE",
+ "Block comments use a trailing */ on a separate line\n" . $herecurr);
+ }
+
+# Block comment * alignment
+ if ($prevline =~ /$;[ \t]*$/ && #ends in comment
+ $line =~ /^\+[ \t]*$;/ && #leading comment
+ $rawline =~ /^\+[ \t]*\*/ && #leading *
+ (($prevrawline =~ /^\+.*?\/\*/ && #leading /*
+ $prevrawline !~ /\*\/[ \t]*$/) || #no trailing */
+ $prevrawline =~ /^\+[ \t]*\*/)) { #leading *
+ my $oldindent;
+ $prevrawline =~ m@^\+([ \t]*/?)\*@;
+ if (defined($1)) {
+ $oldindent = expand_tabs($1);
+ } else {
+ $prevrawline =~ m@^\+(.*/?)\*@;
+ $oldindent = expand_tabs($1);
+ }
+ $rawline =~ m@^\+([ \t]*)\*@;
+ my $newindent = $1;
+ $newindent = expand_tabs($newindent);
+ if (length($oldindent) ne length($newindent)) {
+ WARN("BLOCK_COMMENT_STYLE",
+ "Block comments should align the * on each line\n" . $hereprev);
+ }
+ }
+
+# check for missing blank lines after struct/union declarations
+# with exceptions for various attributes and macros
+ if ($prevline =~ /^[\+ ]};?\s*$/ &&
+ $line =~ /^\+/ &&
+ !($line =~ /^\+\s*$/ ||
+ $line =~ /^\+\s*EXPORT_SYMBOL/ ||
+ $line =~ /^\+\s*MODULE_/i ||
+ $line =~ /^\+\s*\#\s*(?:end|elif|else)/ ||
+ $line =~ /^\+[a-z_]*init/ ||
+ $line =~ /^\+\s*(?:static\s+)?[A-Z_]*ATTR/ ||
+ $line =~ /^\+\s*DECLARE/ ||
+ $line =~ /^\+\s*builtin_[\w_]*driver/ ||
+ $line =~ /^\+\s*__setup/)) {
+ if (CHK("LINE_SPACING",
+ "Please use a blank line after function/struct/union/enum declarations\n" . $hereprev) &&
+ $fix) {
+ fix_insert_line($fixlinenr, "\+");
+ }
+ }
+
+# check for multiple consecutive blank lines
+ if ($prevline =~ /^[\+ ]\s*$/ &&
+ $line =~ /^\+\s*$/ &&
+ $last_blank_line != ($linenr - 1)) {
+ if (CHK("LINE_SPACING",
+ "Please don't use multiple blank lines\n" . $hereprev) &&
+ $fix) {
+ fix_delete_line($fixlinenr, $rawline);
+ }
+
+ $last_blank_line = $linenr;
+ }
+
+# check for missing blank lines after declarations
+ if ($sline =~ /^\+\s+\S/ && #Not at char 1
+ # actual declarations
+ ($prevline =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ ||
+ # function pointer declarations
+ $prevline =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ ||
+ # foo bar; where foo is some local typedef or #define
+ $prevline =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
+ # known declaration macros
+ $prevline =~ /^\+\s+$declaration_macros/) &&
+ # for "else if" which can look like "$Ident $Ident"
+ !($prevline =~ /^\+\s+$c90_Keywords\b/ ||
+ # other possible extensions of declaration lines
+ $prevline =~ /(?:$Compare|$Assignment|$Operators)\s*$/ ||
+ # not starting a section or a macro "\" extended line
+ $prevline =~ /(?:\{\s*|\\)$/) &&
+ # looks like a declaration
+ !($sline =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ ||
+ # function pointer declarations
+ $sline =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ ||
+ # foo bar; where foo is some local typedef or #define
+ $sline =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
+ # known declaration macros
+ $sline =~ /^\+\s+$declaration_macros/ ||
+ # start of struct or union or enum
+ $sline =~ /^\+\s+(?:static\s+)?(?:const\s+)?(?:union|struct|enum|typedef)\b/ ||
+ # start or end of block or continuation of declaration
+ $sline =~ /^\+\s+(?:$|[\{\}\.\#\"\?\:\(\[])/ ||
+ # bitfield continuation
+ $sline =~ /^\+\s+$Ident\s*:\s*\d+\s*[,;]/ ||
+ # other possible extensions of declaration lines
+ $sline =~ /^\+\s+\(?\s*(?:$Compare|$Assignment|$Operators)/) &&
+ # indentation of previous and current line are the same
+ (($prevline =~ /\+(\s+)\S/) && $sline =~ /^\+$1\S/)) {
+ if (WARN("LINE_SPACING",
+ "Missing a blank line after declarations\n" . $hereprev) &&
+ $fix) {
+ fix_insert_line($fixlinenr, "\+");
+ }
+ }
+
+# check for spaces at the beginning of a line.
+# Exceptions:
+# 1) within comments
+# 2) indented preprocessor commands
+# 3) hanging labels
+ if ($rawline =~ /^\+ / && $line !~ /^\+ *(?:$;|#|$Ident:)/) {
+ my $herevet = "$here\n" . cat_vet($rawline) . "\n";
+ if (WARN("LEADING_SPACE",
+ "please, no spaces at the start of a line\n" . $herevet) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/^\+([ \t]+)/"\+" . tabify($1)/e;
+ }
+ }
+
+# check we are in a valid C source file if not then ignore this hunk
+ next if ($realfile !~ /\.(h|c)$/);
+
+# check for unusual line ending [ or (
+ if ($line =~ /^\+.*([\[\(])\s*$/) {
+ CHK("OPEN_ENDED_LINE",
+ "Lines should not end with a '$1'\n" . $herecurr);
+ }
+
+# check if this appears to be the start function declaration, save the name
+ if ($sline =~ /^\+\{\s*$/ &&
+ $prevline =~ /^\+(?:(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*)?($Ident)\(/) {
+ $context_function = $1;
+ }
+
+# check if this appears to be the end of function declaration
+ if ($sline =~ /^\+\}\s*$/) {
+ undef $context_function;
+ }
+
+# check indentation of any line with a bare else
+# (but not if it is a multiple line "if (foo) return bar; else return baz;")
+# if the previous line is a break or return and is indented 1 tab more...
+ if ($sline =~ /^\+([\t]+)(?:}[ \t]*)?else(?:[ \t]*{)?\s*$/) {
+ my $tabs = length($1) + 1;
+ if ($prevline =~ /^\+\t{$tabs,$tabs}break\b/ ||
+ ($prevline =~ /^\+\t{$tabs,$tabs}return\b/ &&
+ defined $lines[$linenr] &&
+ $lines[$linenr] !~ /^[ \+]\t{$tabs,$tabs}return/)) {
+ WARN("UNNECESSARY_ELSE",
+ "else is not generally useful after a break or return\n" . $hereprev);
+ }
+ }
+
+# check indentation of a line with a break;
+# if the previous line is a goto or return and is indented the same # of tabs
+ if ($sline =~ /^\+([\t]+)break\s*;\s*$/) {
+ my $tabs = $1;
+ if ($prevline =~ /^\+$tabs(?:goto|return)\b/) {
+ WARN("UNNECESSARY_BREAK",
+ "break is not useful after a goto or return\n" . $hereprev);
+ }
+ }
+
+# check for RCS/CVS revision markers
+ if ($rawline =~ /^\+.*\$(Revision|Log|Id)(?:\$|)/) {
+ WARN("CVS_KEYWORD",
+ "CVS style keyword markers, these will _not_ be updated\n". $herecurr);
+ }
+
+# check for old HOTPLUG __dev<foo> section markings
+ if ($line =~ /\b(__dev(init|exit)(data|const|))\b/) {
+ WARN("HOTPLUG_SECTION",
+ "Using $1 is unnecessary\n" . $herecurr);
+ }
+
+# Check for potential 'bare' types
+ my ($stat, $cond, $line_nr_next, $remain_next, $off_next,
+ $realline_next);
+#print "LINE<$line>\n";
+ if ($linenr > $suppress_statement &&
+ $realcnt && $sline =~ /.\s*\S/) {
+ ($stat, $cond, $line_nr_next, $remain_next, $off_next) =
+ ctx_statement_block($linenr, $realcnt, 0);
+ $stat =~ s/\n./\n /g;
+ $cond =~ s/\n./\n /g;
+
+#print "linenr<$linenr> <$stat>\n";
+ # If this statement has no statement boundaries within
+ # it there is no point in retrying a statement scan
+ # until we hit end of it.
+ my $frag = $stat; $frag =~ s/;+\s*$//;
+ if ($frag !~ /(?:{|;)/) {
+#print "skip<$line_nr_next>\n";
+ $suppress_statement = $line_nr_next;
+ }
+
+ # Find the real next line.
+ $realline_next = $line_nr_next;
+ if (defined $realline_next &&
+ (!defined $lines[$realline_next - 1] ||
+ substr($lines[$realline_next - 1], $off_next) =~ /^\s*$/)) {
+ $realline_next++;
+ }
+
+ my $s = $stat;
+ $s =~ s/{.*$//s;
+
+ # Ignore goto labels.
+ if ($s =~ /$Ident:\*$/s) {
+
+ # Ignore functions being called
+ } elsif ($s =~ /^.\s*$Ident\s*\(/s) {
+
+ } elsif ($s =~ /^.\s*else\b/s) {
+
+ # declarations always start with types
+ } elsif ($prev_values eq 'E' && $s =~ /^.\s*(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?((?:\s*$Ident)+?)\b(?:\s+$Sparse)?\s*\**\s*(?:$Ident|\(\*[^\)]*\))(?:\s*$Modifier)?\s*(?:;|=|,|\()/s) {
+ my $type = $1;
+ $type =~ s/\s+/ /g;
+ possible($type, "A:" . $s);
+
+ # definitions in global scope can only start with types
+ } elsif ($s =~ /^.(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?($Ident)\b\s*(?!:)/s) {
+ possible($1, "B:" . $s);
+ }
+
+ # any (foo ... *) is a pointer cast, and foo is a type
+ while ($s =~ /\(($Ident)(?:\s+$Sparse)*[\s\*]+\s*\)/sg) {
+ possible($1, "C:" . $s);
+ }
+
+ # Check for any sort of function declaration.
+ # int foo(something bar, other baz);
+ # void (*store_gdt)(x86_descr_ptr *);
+ if ($prev_values eq 'E' && $s =~ /^(.(?:typedef\s*)?(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*(?:\b$Ident|\(\*\s*$Ident\))\s*)\(/s) {
+ my ($name_len) = length($1);
+
+ my $ctx = $s;
+ substr($ctx, 0, $name_len + 1, '');
+ $ctx =~ s/\)[^\)]*$//;
+
+ for my $arg (split(/\s*,\s*/, $ctx)) {
+ if ($arg =~ /^(?:const\s+)?($Ident)(?:\s+$Sparse)*\s*\**\s*(:?\b$Ident)?$/s || $arg =~ /^($Ident)$/s) {
+
+ possible($1, "D:" . $s);
+ }
+ }
+ }
+
+ }
+
+#
+# Checks which may be anchored in the context.
+#
+
+# Check for switch () and associated case and default
+# statements should be at the same indent.
+ if ($line=~/\bswitch\s*\(.*\)/) {
+ my $err = '';
+ my $sep = '';
+ my @ctx = ctx_block_outer($linenr, $realcnt);
+ shift(@ctx);
+ for my $ctx (@ctx) {
+ my ($clen, $cindent) = line_stats($ctx);
+ if ($ctx =~ /^\+\s*(case\s+|default:)/ &&
+ $indent != $cindent) {
+ $err .= "$sep$ctx\n";
+ $sep = '';
+ } else {
+ $sep = "[...]\n";
+ }
+ }
+ if ($err ne '') {
+ ERROR("SWITCH_CASE_INDENT_LEVEL",
+ "switch and case should be at the same indent\n$hereline$err");
+ }
+ }
+
+# if/while/etc brace do not go on next line, unless defining a do while loop,
+# or if that brace on the next line is for something else
+ if ($line =~ /(.*)\b((?:if|while|for|switch|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|do\b|else\b)/ && $line !~ /^.\s*\#/) {
+ my $pre_ctx = "$1$2";
+
+ my ($level, @ctx) = ctx_statement_level($linenr, $realcnt, 0);
+
+ if ($line =~ /^\+\t{6,}/) {
+ WARN("DEEP_INDENTATION",
+ "Too many leading tabs - consider code refactoring\n" . $herecurr);
+ }
+
+ my $ctx_cnt = $realcnt - $#ctx - 1;
+ my $ctx = join("\n", @ctx);
+
+ my $ctx_ln = $linenr;
+ my $ctx_skip = $realcnt;
+
+ while ($ctx_skip > $ctx_cnt || ($ctx_skip == $ctx_cnt &&
+ defined $lines[$ctx_ln - 1] &&
+ $lines[$ctx_ln - 1] =~ /^-/)) {
+ ##print "SKIP<$ctx_skip> CNT<$ctx_cnt>\n";
+ $ctx_skip-- if (!defined $lines[$ctx_ln - 1] || $lines[$ctx_ln - 1] !~ /^-/);
+ $ctx_ln++;
+ }
+
+ #print "realcnt<$realcnt> ctx_cnt<$ctx_cnt>\n";
+ #print "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n";
+
+ if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln - 1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) {
+ ERROR("OPEN_BRACE",
+ "that open brace { should be on the previous line\n" .
+ "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
+ }
+ if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ &&
+ $ctx =~ /\)\s*\;\s*$/ &&
+ defined $lines[$ctx_ln - 1])
+ {
+ my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]);
+ if ($nindent > $indent) {
+ WARN("TRAILING_SEMICOLON",
+ "trailing semicolon indicates no statements, indent implies otherwise\n" .
+ "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
+ }
+ }
+ }
+
+# Check relative indent for conditionals and blocks.
+ if ($line =~ /\b(?:(?:if|while|for|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|(?:do|else)\b)/ && $line !~ /^.\s*#/ && $line !~ /\}\s*while\s*/) {
+ ($stat, $cond, $line_nr_next, $remain_next, $off_next) =
+ ctx_statement_block($linenr, $realcnt, 0)
+ if (!defined $stat);
+ my ($s, $c) = ($stat, $cond);
+
+ substr($s, 0, length($c), '');
+
+ # remove inline comments
+ $s =~ s/$;/ /g;
+ $c =~ s/$;/ /g;
+
+ # Find out how long the conditional actually is.
+ my @newlines = ($c =~ /\n/gs);
+ my $cond_lines = 1 + $#newlines;
+
+ # Make sure we remove the line prefixes as we have
+ # none on the first line, and are going to readd them
+ # where necessary.
+ $s =~ s/\n./\n/gs;
+ while ($s =~ /\n\s+\\\n/) {
+ $cond_lines += $s =~ s/\n\s+\\\n/\n/g;
+ }
+
+ # We want to check the first line inside the block
+ # starting at the end of the conditional, so remove:
+ # 1) any blank line termination
+ # 2) any opening brace { on end of the line
+ # 3) any do (...) {
+ my $continuation = 0;
+ my $check = 0;
+ $s =~ s/^.*\bdo\b//;
+ $s =~ s/^\s*{//;
+ if ($s =~ s/^\s*\\//) {
+ $continuation = 1;
+ }
+ if ($s =~ s/^\s*?\n//) {
+ $check = 1;
+ $cond_lines++;
+ }
+
+ # Also ignore a loop construct at the end of a
+ # preprocessor statement.
+ if (($prevline =~ /^.\s*#\s*define\s/ ||
+ $prevline =~ /\\\s*$/) && $continuation == 0) {
+ $check = 0;
+ }
+
+ my $cond_ptr = -1;
+ $continuation = 0;
+ while ($cond_ptr != $cond_lines) {
+ $cond_ptr = $cond_lines;
+
+ # If we see an #else/#elif then the code
+ # is not linear.
+ if ($s =~ /^\s*\#\s*(?:else|elif)/) {
+ $check = 0;
+ }
+
+ # Ignore:
+ # 1) blank lines, they should be at 0,
+ # 2) preprocessor lines, and
+ # 3) labels.
+ if ($continuation ||
+ $s =~ /^\s*?\n/ ||
+ $s =~ /^\s*#\s*?/ ||
+ $s =~ /^\s*$Ident\s*:/) {
+ $continuation = ($s =~ /^.*?\\\n/) ? 1 : 0;
+ if ($s =~ s/^.*?\n//) {
+ $cond_lines++;
+ }
+ }
+ }
+
+ my (undef, $sindent) = line_stats("+" . $s);
+ my $stat_real = raw_line($linenr, $cond_lines);
+
+ # Check if either of these lines are modified, else
+ # this is not this patch's fault.
+ if (!defined($stat_real) ||
+ $stat !~ /^\+/ && $stat_real !~ /^\+/) {
+ $check = 0;
+ }
+ if (defined($stat_real) && $cond_lines > 1) {
+ $stat_real = "[...]\n$stat_real";
+ }
+
+ #print "line<$line> prevline<$prevline> indent<$indent> sindent<$sindent> check<$check> continuation<$continuation> s<$s> cond_lines<$cond_lines> stat_real<$stat_real> stat<$stat>\n";
+
+ if ($check && $s ne '' &&
+ (($sindent % 8) != 0 ||
+ ($sindent < $indent) ||
+ ($sindent == $indent &&
+ ($s !~ /^\s*(?:\}|\{|else\b)/)) ||
+ ($sindent > $indent + 8))) {
+ WARN("SUSPECT_CODE_INDENT",
+ "suspect code indent for conditional statements ($indent, $sindent)\n" . $herecurr . "$stat_real\n");
+ }
+ }
+
+ # Track the 'values' across context and added lines.
+ my $opline = $line; $opline =~ s/^./ /;
+ my ($curr_values, $curr_vars) =
+ annotate_values($opline . "\n", $prev_values);
+ $curr_values = $prev_values . $curr_values;
+ if ($dbg_values) {
+ my $outline = $opline; $outline =~ s/\t/ /g;
+ print "$linenr > .$outline\n";
+ print "$linenr > $curr_values\n";
+ print "$linenr > $curr_vars\n";
+ }
+ $prev_values = substr($curr_values, -1);
+
+#ignore lines not being added
+ next if ($line =~ /^[^\+]/);
+
+# check for dereferences that span multiple lines
+ if ($prevline =~ /^\+.*$Lval\s*(?:\.|->)\s*$/ &&
+ $line =~ /^\+\s*(?!\#\s*(?!define\s+|if))\s*$Lval/) {
+ $prevline =~ /($Lval\s*(?:\.|->))\s*$/;
+ my $ref = $1;
+ $line =~ /^.\s*($Lval)/;
+ $ref .= $1;
+ $ref =~ s/\s//g;
+ WARN("MULTILINE_DEREFERENCE",
+ "Avoid multiple line dereference - prefer '$ref'\n" . $hereprev);
+ }
+
+# check for declarations of signed or unsigned without int
+ while ($line =~ m{\b($Declare)\s*(?!char\b|short\b|int\b|long\b)\s*($Ident)?\s*[=,;\[\)\(]}g) {
+ my $type = $1;
+ my $var = $2;
+ $var = "" if (!defined $var);
+ if ($type =~ /^(?:(?:$Storage|$Inline|$Attribute)\s+)*((?:un)?signed)((?:\s*\*)*)\s*$/) {
+ my $sign = $1;
+ my $pointer = $2;
+
+ $pointer = "" if (!defined $pointer);
+
+ if (WARN("UNSPECIFIED_INT",
+ "Prefer '" . trim($sign) . " int" . rtrim($pointer) . "' to bare use of '$sign" . rtrim($pointer) . "'\n" . $herecurr) &&
+ $fix) {
+ my $decl = trim($sign) . " int ";
+ my $comp_pointer = $pointer;
+ $comp_pointer =~ s/\s//g;
+ $decl .= $comp_pointer;
+ $decl = rtrim($decl) if ($var eq "");
+ $fixed[$fixlinenr] =~ s@\b$sign\s*\Q$pointer\E\s*$var\b@$decl$var@;
+ }
+ }
+ }
+
+# TEST: allow direct testing of the type matcher.
+ if ($dbg_type) {
+ if ($line =~ /^.\s*$Declare\s*$/) {
+ ERROR("TEST_TYPE",
+ "TEST: is type\n" . $herecurr);
+ } elsif ($dbg_type > 1 && $line =~ /^.+($Declare)/) {
+ ERROR("TEST_NOT_TYPE",
+ "TEST: is not type ($1 is)\n". $herecurr);
+ }
+ next;
+ }
+# TEST: allow direct testing of the attribute matcher.
+ if ($dbg_attr) {
+ if ($line =~ /^.\s*$Modifier\s*$/) {
+ ERROR("TEST_ATTR",
+ "TEST: is attr\n" . $herecurr);
+ } elsif ($dbg_attr > 1 && $line =~ /^.+($Modifier)/) {
+ ERROR("TEST_NOT_ATTR",
+ "TEST: is not attr ($1 is)\n". $herecurr);
+ }
+ next;
+ }
+
+# check for initialisation to aggregates open brace on the next line
+ if ($line =~ /^.\s*{/ &&
+ $prevline =~ /(?:^|[^=])=\s*$/) {
+ if (ERROR("OPEN_BRACE",
+ "that open brace { should be on the previous line\n" . $hereprev) &&
+ $fix && $prevline =~ /^\+/ && $line =~ /^\+/) {
+ fix_delete_line($fixlinenr - 1, $prevrawline);
+ fix_delete_line($fixlinenr, $rawline);
+ my $fixedline = $prevrawline;
+ $fixedline =~ s/\s*=\s*$/ = {/;
+ fix_insert_line($fixlinenr, $fixedline);
+ $fixedline = $line;
+ $fixedline =~ s/^(.\s*)\{\s*/$1/;
+ fix_insert_line($fixlinenr, $fixedline);
+ }
+ }
+
+#
+# Checks which are anchored on the added line.
+#
+
+# check for malformed paths in #include statements (uses RAW line)
+ if ($rawline =~ m{^.\s*\#\s*include\s+[<"](.*)[">]}) {
+ my $path = $1;
+ if ($path =~ m{//}) {
+ ERROR("MALFORMED_INCLUDE",
+ "malformed #include filename\n" . $herecurr);
+ }
+ if ($path =~ "^uapi/" && $realfile =~ m@\binclude/uapi/@) {
+ ERROR("UAPI_INCLUDE",
+ "No #include in ...include/uapi/... should use a uapi/ path prefix\n" . $herecurr);
+ }
+ }
+
+# no C99 // comments
+ if ($line =~ m{//}) {
+ if (ERROR("C99_COMMENTS",
+ "do not use C99 // comments\n" . $herecurr) &&
+ $fix) {
+ my $line = $fixed[$fixlinenr];
+ if ($line =~ /\/\/(.*)$/) {
+ my $comment = trim($1);
+ $fixed[$fixlinenr] =~ s@\/\/(.*)$@/\* $comment \*/@;
+ }
+ }
+ }
+ # Remove C99 comments.
+ $line =~ s@//.*@@;
+ $opline =~ s@//.*@@;
+
+# EXPORT_SYMBOL should immediately follow the thing it is exporting, consider
+# the whole statement.
+#print "APW <$lines[$realline_next - 1]>\n";
+ if (defined $realline_next &&
+ exists $lines[$realline_next - 1] &&
+ !defined $suppress_export{$realline_next} &&
+ ($lines[$realline_next - 1] =~ /EXPORT_SYMBOL.*\((.*)\)/ ||
+ $lines[$realline_next - 1] =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) {
+ # Handle definitions which produce identifiers with
+ # a prefix:
+ # XXX(foo);
+ # EXPORT_SYMBOL(something_foo);
+ my $name = $1;
+ if ($stat =~ /^(?:.\s*}\s*\n)?.([A-Z_]+)\s*\(\s*($Ident)/ &&
+ $name =~ /^${Ident}_$2/) {
+#print "FOO C name<$name>\n";
+ $suppress_export{$realline_next} = 1;
+
+ } elsif ($stat !~ /(?:
+ \n.}\s*$|
+ ^.DEFINE_$Ident\(\Q$name\E\)|
+ ^.DECLARE_$Ident\(\Q$name\E\)|
+ ^.LIST_HEAD\(\Q$name\E\)|
+ ^.(?:$Storage\s+)?$Type\s*\(\s*\*\s*\Q$name\E\s*\)\s*\(|
+ \b\Q$name\E(?:\s+$Attribute)*\s*(?:;|=|\[|\()
+ )/x) {
+#print "FOO A<$lines[$realline_next - 1]> stat<$stat> name<$name>\n";
+ $suppress_export{$realline_next} = 2;
+ } else {
+ $suppress_export{$realline_next} = 1;
+ }
+ }
+ if (!defined $suppress_export{$linenr} &&
+ $prevline =~ /^.\s*$/ &&
+ ($line =~ /EXPORT_SYMBOL.*\((.*)\)/ ||
+ $line =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) {
+#print "FOO B <$lines[$linenr - 1]>\n";
+ $suppress_export{$linenr} = 2;
+ }
+ if (defined $suppress_export{$linenr} &&
+ $suppress_export{$linenr} == 2) {
+ WARN("EXPORT_SYMBOL",
+ "EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr);
+ }
+
+# check for global initialisers.
+ if ($line =~ /^\+$Type\s*$Ident(?:\s+$Modifier)*\s*=\s*($zero_initializer)\s*;/) {
+ if (ERROR("GLOBAL_INITIALISERS",
+ "do not initialise globals to $1\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/(^.$Type\s*$Ident(?:\s+$Modifier)*)\s*=\s*$zero_initializer\s*;/$1;/;
+ }
+ }
+# check for static initialisers.
+ if ($line =~ /^\+.*\bstatic\s.*=\s*($zero_initializer)\s*;/) {
+ if (ERROR("INITIALISED_STATIC",
+ "do not initialise statics to $1\n" .
+ $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/(\bstatic\s.*?)\s*=\s*$zero_initializer\s*;/$1;/;
+ }
+ }
+
+# check for misordered declarations of char/short/int/long with signed/unsigned
+ while ($sline =~ m{(\b$TypeMisordered\b)}g) {
+ my $tmp = trim($1);
+ WARN("MISORDERED_TYPE",
+ "type '$tmp' should be specified in [[un]signed] [short|int|long|long long] order\n" . $herecurr);
+ }
+
+# check for unnecessary <signed> int declarations of short/long/long long
+ while ($sline =~ m{\b($TypeMisordered(\s*\*)*|$C90_int_types)\b}g) {
+ my $type = trim($1);
+ next if ($type !~ /\bint\b/);
+ next if ($type !~ /\b(?:short|long\s+long|long)\b/);
+ my $new_type = $type;
+ $new_type =~ s/\b\s*int\s*\b/ /;
+ $new_type =~ s/\b\s*(?:un)?signed\b\s*/ /;
+ $new_type =~ s/^const\s+//;
+ $new_type = "unsigned $new_type" if ($type =~ /\bunsigned\b/);
+ $new_type = "const $new_type" if ($type =~ /^const\b/);
+ $new_type =~ s/\s+/ /g;
+ $new_type = trim($new_type);
+ if (WARN("UNNECESSARY_INT",
+ "Prefer '$new_type' over '$type' as the int is unnecessary\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/\b\Q$type\E\b/$new_type/;
+ }
+ }
+
+# check for static const char * arrays.
+ if ($line =~ /\bstatic\s+const\s+char\s*\*\s*(\w+)\s*\[\s*\]\s*=\s*/) {
+ WARN("STATIC_CONST_CHAR_ARRAY",
+ "static const char * array should probably be static const char * const\n" .
+ $herecurr);
+ }
+
+# check for initialized const char arrays that should be static const
+ if ($line =~ /^\+\s*const\s+(char|unsigned\s+char|_*u8|(?:[us]_)?int8_t)\s+\w+\s*\[\s*(?:\w+\s*)?\]\s*=\s*"/) {
+ if (WARN("STATIC_CONST_CHAR_ARRAY",
+ "const array should probably be static const\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/(^.\s*)const\b/${1}static const/;
+ }
+ }
+
+# check for static char foo[] = "bar" declarations.
+ if ($line =~ /\bstatic\s+char\s+(\w+)\s*\[\s*\]\s*=\s*"/) {
+ WARN("STATIC_CONST_CHAR_ARRAY",
+ "static char array declaration should probably be static const char\n" .
+ $herecurr);
+ }
+
+# check for const <foo> const where <foo> is not a pointer or array type
+ if ($sline =~ /\bconst\s+($BasicType)\s+const\b/) {
+ my $found = $1;
+ if ($sline =~ /\bconst\s+\Q$found\E\s+const\b\s*\*/) {
+ WARN("CONST_CONST",
+ "'const $found const *' should probably be 'const $found * const'\n" . $herecurr);
+ } elsif ($sline !~ /\bconst\s+\Q$found\E\s+const\s+\w+\s*\[/) {
+ WARN("CONST_CONST",
+ "'const $found const' should probably be 'const $found'\n" . $herecurr);
+ }
+ }
+
+# check for non-global char *foo[] = {"bar", ...} declarations.
+ if ($line =~ /^.\s+(?:static\s+|const\s+)?char\s+\*\s*\w+\s*\[\s*\]\s*=\s*\{/) {
+ WARN("STATIC_CONST_CHAR_ARRAY",
+ "char * array declaration might be better as static const\n" .
+ $herecurr);
+ }
+
+# check for sizeof(foo)/sizeof(foo[0]) that could be ARRAY_SIZE(foo)
+ if ($line =~ m@\bsizeof\s*\(\s*($Lval)\s*\)@) {
+ my $array = $1;
+ if ($line =~ m@\b(sizeof\s*\(\s*\Q$array\E\s*\)\s*/\s*sizeof\s*\(\s*\Q$array\E\s*\[\s*0\s*\]\s*\))@) {
+ my $array_div = $1;
+ if (WARN("ARRAY_SIZE",
+ "Prefer ARRAY_SIZE($array)\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/\Q$array_div\E/ARRAY_SIZE($array)/;
+ }
+ }
+ }
+
+# check for function declarations without arguments like "int foo()"
+ if ($line =~ /(\b$Type\s+$Ident)\s*\(\s*\)/) {
+ if (ERROR("FUNCTION_WITHOUT_ARGS",
+ "Bad function definition - $1() should probably be $1(void)\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/(\b($Type)\s+($Ident))\s*\(\s*\)/$2 $3(void)/;
+ }
+ }
+
+# check for new typedefs, only function parameters and sparse annotations
+# make sense.
+ if ($line =~ /\btypedef\s/ &&
+ $line !~ /\btypedef\s+$Type\s*\(\s*\*?$Ident\s*\)\s*\(/ &&
+ $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ &&
+ $line !~ /\b$typeTypedefs\b/ &&
+ $line !~ /\b__bitwise\b/) {
+ WARN("NEW_TYPEDEFS",
+ "do not add new typedefs\n" . $herecurr);
+ }
+
+# * goes on variable not on type
+ # (char*[ const])
+ while ($line =~ m{(\($NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)\))}g) {
+ #print "AA<$1>\n";
+ my ($ident, $from, $to) = ($1, $2, $2);
+
+ # Should start with a space.
+ $to =~ s/^(\S)/ $1/;
+ # Should not end with a space.
+ $to =~ s/\s+$//;
+ # '*'s should not have spaces between.
+ while ($to =~ s/\*\s+\*/\*\*/) {
+ }
+
+## print "1: from<$from> to<$to> ident<$ident>\n";
+ if ($from ne $to) {
+ if (ERROR("POINTER_LOCATION",
+ "\"(foo$from)\" should be \"(foo$to)\"\n" . $herecurr) &&
+ $fix) {
+ my $sub_from = $ident;
+ my $sub_to = $ident;
+ $sub_to =~ s/\Q$from\E/$to/;
+ $fixed[$fixlinenr] =~
+ s@\Q$sub_from\E@$sub_to@;
+ }
+ }
+ }
+ while ($line =~ m{(\b$NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)($Ident))}g) {
+ #print "BB<$1>\n";
+ my ($match, $from, $to, $ident) = ($1, $2, $2, $3);
+
+ # Should start with a space.
+ $to =~ s/^(\S)/ $1/;
+ # Should not end with a space.
+ $to =~ s/\s+$//;
+ # '*'s should not have spaces between.
+ while ($to =~ s/\*\s+\*/\*\*/) {
+ }
+ # Modifiers should have spaces.
+ $to =~ s/(\b$Modifier$)/$1 /;
+
+## print "2: from<$from> to<$to> ident<$ident>\n";
+ if ($from ne $to && $ident !~ /^$Modifier$/) {
+ if (ERROR("POINTER_LOCATION",
+ "\"foo${from}bar\" should be \"foo${to}bar\"\n" . $herecurr) &&
+ $fix) {
+
+ my $sub_from = $match;
+ my $sub_to = $match;
+ $sub_to =~ s/\Q$from\E/$to/;
+ $fixed[$fixlinenr] =~
+ s@\Q$sub_from\E@$sub_to@;
+ }
+ }
+ }
+
+# avoid BUG() or BUG_ON()
+ if ($line =~ /\b(?:BUG|BUG_ON)\b/) {
+ my $msg_level = \&WARN;
+ $msg_level = \&CHK if ($file);
+ &{$msg_level}("AVOID_BUG",
+ "Avoid crashing the kernel - try using WARN_ON & recovery code rather than BUG() or BUG_ON()\n" . $herecurr);
+ }
+
+# avoid LINUX_VERSION_CODE
+ if ($line =~ /\bLINUX_VERSION_CODE\b/) {
+ WARN("LINUX_VERSION_CODE",
+ "LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged\n" . $herecurr);
+ }
+
+# check for uses of printk_ratelimit
+ if ($line =~ /\bprintk_ratelimit\s*\(/) {
+ WARN("PRINTK_RATELIMITED",
+ "Prefer printk_ratelimited or pr_<level>_ratelimited to printk_ratelimit\n" . $herecurr);
+ }
+
+# printk should use KERN_* levels
+ if ($line =~ /\bprintk\s*\(\s*(?!KERN_[A-Z]+\b)/) {
+ WARN("PRINTK_WITHOUT_KERN_LEVEL",
+ "printk() should include KERN_<LEVEL> facility level\n" . $herecurr);
+ }
+
+ if ($line =~ /\bprintk\s*\(\s*KERN_([A-Z]+)/) {
+ my $orig = $1;
+ my $level = lc($orig);
+ $level = "warn" if ($level eq "warning");
+ my $level2 = $level;
+ $level2 = "dbg" if ($level eq "debug");
+ WARN("PREFER_PR_LEVEL",
+ "Prefer [subsystem eg: netdev]_$level2([subsystem]dev, ... then dev_$level2(dev, ... then pr_$level(... to printk(KERN_$orig ...\n" . $herecurr);
+ }
+
+ if ($line =~ /\bpr_warning\s*\(/) {
+ if (WARN("PREFER_PR_LEVEL",
+ "Prefer pr_warn(... to pr_warning(...\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~
+ s/\bpr_warning\b/pr_warn/;
+ }
+ }
+
+ if ($line =~ /\bdev_printk\s*\(\s*KERN_([A-Z]+)/) {
+ my $orig = $1;
+ my $level = lc($orig);
+ $level = "warn" if ($level eq "warning");
+ $level = "dbg" if ($level eq "debug");
+ WARN("PREFER_DEV_LEVEL",
+ "Prefer dev_$level(... to dev_printk(KERN_$orig, ...\n" . $herecurr);
+ }
+
+# ENOSYS means "bad syscall nr" and nothing else. This will have a small
+# number of false positives, but assembly files are not checked, so at
+# least the arch entry code will not trigger this warning.
+ if ($line =~ /\bENOSYS\b/) {
+ WARN("ENOSYS",
+ "ENOSYS means 'invalid syscall nr' and nothing else\n" . $herecurr);
+ }
+
+# function brace can't be on same line, except for #defines of do while,
+# or if closed on same line
+ if ($perl_version_ok &&
+ $sline =~ /$Type\s*$Ident\s*$balanced_parens\s*\{/ &&
+ $sline !~ /\#\s*define\b.*do\s*\{/ &&
+ $sline !~ /}/) {
+ if (ERROR("OPEN_BRACE",
+ "open brace '{' following function definitions go on the next line\n" . $herecurr) &&
+ $fix) {
+ fix_delete_line($fixlinenr, $rawline);
+ my $fixed_line = $rawline;
+ $fixed_line =~ /(^..*$Type\s*$Ident\(.*\)\s*){(.*)$/;
+ my $line1 = $1;
+ my $line2 = $2;
+ fix_insert_line($fixlinenr, ltrim($line1));
+ fix_insert_line($fixlinenr, "\+{");
+ if ($line2 !~ /^\s*$/) {
+ fix_insert_line($fixlinenr, "\+\t" . trim($line2));
+ }
+ }
+ }
+
+# open braces for enum, union and struct go on the same line.
+ if ($line =~ /^.\s*{/ &&
+ $prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) {
+ if (ERROR("OPEN_BRACE",
+ "open brace '{' following $1 go on the same line\n" . $hereprev) &&
+ $fix && $prevline =~ /^\+/ && $line =~ /^\+/) {
+ fix_delete_line($fixlinenr - 1, $prevrawline);
+ fix_delete_line($fixlinenr, $rawline);
+ my $fixedline = rtrim($prevrawline) . " {";
+ fix_insert_line($fixlinenr, $fixedline);
+ $fixedline = $rawline;
+ $fixedline =~ s/^(.\s*)\{\s*/$1\t/;
+ if ($fixedline !~ /^\+\s*$/) {
+ fix_insert_line($fixlinenr, $fixedline);
+ }
+ }
+ }
+
+# missing space after union, struct or enum definition
+ if ($line =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident){1,2}[=\{]/) {
+ if (WARN("SPACING",
+ "missing space after $1 definition\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~
+ s/^(.\s*(?:typedef\s+)?(?:enum|union|struct)(?:\s+$Ident){1,2})([=\{])/$1 $2/;
+ }
+ }
+
+# Function pointer declarations
+# check spacing between type, funcptr, and args
+# canonical declaration is "type (*funcptr)(args...)"
+ if ($line =~ /^.\s*($Declare)\((\s*)\*(\s*)($Ident)(\s*)\)(\s*)\(/) {
+ my $declare = $1;
+ my $pre_pointer_space = $2;
+ my $post_pointer_space = $3;
+ my $funcname = $4;
+ my $post_funcname_space = $5;
+ my $pre_args_space = $6;
+
+# the $Declare variable will capture all spaces after the type
+# so check it for a missing trailing missing space but pointer return types
+# don't need a space so don't warn for those.
+ my $post_declare_space = "";
+ if ($declare =~ /(\s+)$/) {
+ $post_declare_space = $1;
+ $declare = rtrim($declare);
+ }
+ if ($declare !~ /\*$/ && $post_declare_space =~ /^$/) {
+ WARN("SPACING",
+ "missing space after return type\n" . $herecurr);
+ $post_declare_space = " ";
+ }
+
+# unnecessary space "type (*funcptr)(args...)"
+# This test is not currently implemented because these declarations are
+# equivalent to
+# int foo(int bar, ...)
+# and this is form shouldn't/doesn't generate a checkpatch warning.
+#
+# elsif ($declare =~ /\s{2,}$/) {
+# WARN("SPACING",
+# "Multiple spaces after return type\n" . $herecurr);
+# }
+
+# unnecessary space "type ( *funcptr)(args...)"
+ if (defined $pre_pointer_space &&
+ $pre_pointer_space =~ /^\s/) {
+ WARN("SPACING",
+ "Unnecessary space after function pointer open parenthesis\n" . $herecurr);
+ }
+
+# unnecessary space "type (* funcptr)(args...)"
+ if (defined $post_pointer_space &&
+ $post_pointer_space =~ /^\s/) {
+ WARN("SPACING",
+ "Unnecessary space before function pointer name\n" . $herecurr);
+ }
+
+# unnecessary space "type (*funcptr )(args...)"
+ if (defined $post_funcname_space &&
+ $post_funcname_space =~ /^\s/) {
+ WARN("SPACING",
+ "Unnecessary space after function pointer name\n" . $herecurr);
+ }
+
+# unnecessary space "type (*funcptr) (args...)"
+ if (defined $pre_args_space &&
+ $pre_args_space =~ /^\s/) {
+ WARN("SPACING",
+ "Unnecessary space before function pointer arguments\n" . $herecurr);
+ }
+
+ if (show_type("SPACING") && $fix) {
+ $fixed[$fixlinenr] =~
+ s/^(.\s*)$Declare\s*\(\s*\*\s*$Ident\s*\)\s*\(/$1 . $declare . $post_declare_space . '(*' . $funcname . ')('/ex;
+ }
+ }
+
+# check for spacing round square brackets; allowed:
+# 1. with a type on the left -- int [] a;
+# 2. at the beginning of a line for slice initialisers -- [0...10] = 5,
+# 3. inside a curly brace -- = { [0...10] = 5 }
+ while ($line =~ /(.*?\s)\[/g) {
+ my ($where, $prefix) = ($-[1], $1);
+ if ($prefix !~ /$Type\s+$/ &&
+ ($where != 0 || $prefix !~ /^.\s+$/) &&
+ $prefix !~ /[{,:]\s+$/) {
+ if (ERROR("BRACKET_SPACE",
+ "space prohibited before open square bracket '['\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~
+ s/^(\+.*?)\s+\[/$1\[/;
+ }
+ }
+ }
+
+# check for spaces between functions and their parentheses.
+ while ($line =~ /($Ident)\s+\(/g) {
+ my $name = $1;
+ my $ctx_before = substr($line, 0, $-[1]);
+ my $ctx = "$ctx_before$name";
+
+ # Ignore those directives where spaces _are_ permitted.
+ if ($name =~ /^(?:
+ if|for|while|switch|return|case|
+ volatile|__volatile__|
+ __attribute__|format|__extension__|
+ asm|__asm__)$/x)
+ {
+ # cpp #define statements have non-optional spaces, ie
+ # if there is a space between the name and the open
+ # parenthesis it is simply not a parameter group.
+ } elsif ($ctx_before =~ /^.\s*\#\s*define\s*$/) {
+
+ # cpp #elif statement condition may start with a (
+ } elsif ($ctx =~ /^.\s*\#\s*elif\s*$/) {
+
+ # If this whole things ends with a type its most
+ # likely a typedef for a function.
+ } elsif ($ctx =~ /$Type$/) {
+
+ } else {
+ if (WARN("SPACING",
+ "space prohibited between function name and open parenthesis '('\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~
+ s/\b$name\s+\(/$name\(/;
+ }
+ }
+ }
+
+# Check operator spacing.
+ if (!($line=~/\#\s*include/)) {
+ my $fixed_line = "";
+ my $line_fixed = 0;
+
+ my $ops = qr{
+ <<=|>>=|<=|>=|==|!=|
+ \+=|-=|\*=|\/=|%=|\^=|\|=|&=|
+ =>|->|<<|>>|<|>|=|!|~|
+ &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|%|
+ \?:|\?|:
+ }x;
+ my @elements = split(/($ops|;)/, $opline);
+
+## print("element count: <" . $#elements . ">\n");
+## foreach my $el (@elements) {
+## print("el: <$el>\n");
+## }
+
+ my @fix_elements = ();
+ my $off = 0;
+
+ foreach my $el (@elements) {
+ push(@fix_elements, substr($rawline, $off, length($el)));
+ $off += length($el);
+ }
+
+ $off = 0;
+
+ my $blank = copy_spacing($opline);
+ my $last_after = -1;
+
+ for (my $n = 0; $n < $#elements; $n += 2) {
+
+ my $good = $fix_elements[$n] . $fix_elements[$n + 1];
+
+## print("n: <$n> good: <$good>\n");
+
+ $off += length($elements[$n]);
+
+ # Pick up the preceding and succeeding characters.
+ my $ca = substr($opline, 0, $off);
+ my $cc = '';
+ if (length($opline) >= ($off + length($elements[$n + 1]))) {
+ $cc = substr($opline, $off + length($elements[$n + 1]));
+ }
+ my $cb = "$ca$;$cc";
+
+ my $a = '';
+ $a = 'V' if ($elements[$n] ne '');
+ $a = 'W' if ($elements[$n] =~ /\s$/);
+ $a = 'C' if ($elements[$n] =~ /$;$/);
+ $a = 'B' if ($elements[$n] =~ /(\[|\()$/);
+ $a = 'O' if ($elements[$n] eq '');
+ $a = 'E' if ($ca =~ /^\s*$/);
+
+ my $op = $elements[$n + 1];
+
+ my $c = '';
+ if (defined $elements[$n + 2]) {
+ $c = 'V' if ($elements[$n + 2] ne '');
+ $c = 'W' if ($elements[$n + 2] =~ /^\s/);
+ $c = 'C' if ($elements[$n + 2] =~ /^$;/);
+ $c = 'B' if ($elements[$n + 2] =~ /^(\)|\]|;)/);
+ $c = 'O' if ($elements[$n + 2] eq '');
+ $c = 'E' if ($elements[$n + 2] =~ /^\s*\\$/);
+ } else {
+ $c = 'E';
+ }
+
+ my $ctx = "${a}x${c}";
+
+ my $at = "(ctx:$ctx)";
+
+ my $ptr = substr($blank, 0, $off) . "^";
+ my $hereptr = "$hereline$ptr\n";
+
+ # Pull out the value of this operator.
+ my $op_type = substr($curr_values, $off + 1, 1);
+
+ # Get the full operator variant.
+ my $opv = $op . substr($curr_vars, $off, 1);
+
+ # Ignore operators passed as parameters.
+ if ($op_type ne 'V' &&
+ $ca =~ /\s$/ && $cc =~ /^\s*[,\)]/) {
+
+# # Ignore comments
+# } elsif ($op =~ /^$;+$/) {
+
+ # ; should have either the end of line or a space or \ after it
+ } elsif ($op eq ';') {
+ if ($ctx !~ /.x[WEBC]/ &&
+ $cc !~ /^\\/ && $cc !~ /^;/) {
+ if (ERROR("SPACING",
+ "space required after that '$op' $at\n" . $hereptr)) {
+ $good = $fix_elements[$n] . trim($fix_elements[$n + 1]) . " ";
+ $line_fixed = 1;
+ }
+ }
+
+ # // is a comment
+ } elsif ($op eq '//') {
+
+ # : when part of a bitfield
+ } elsif ($opv eq ':B') {
+ # skip the bitfield test for now
+
+ # No spaces for:
+ # ->
+ } elsif ($op eq '->') {
+ if ($ctx =~ /Wx.|.xW/) {
+ if (ERROR("SPACING",
+ "spaces prohibited around that '$op' $at\n" . $hereptr)) {
+ $good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
+ if (defined $fix_elements[$n + 2]) {
+ $fix_elements[$n + 2] =~ s/^\s+//;
+ }
+ $line_fixed = 1;
+ }
+ }
+
+ # , must not have a space before and must have a space on the right.
+ } elsif ($op eq ',') {
+ my $rtrim_before = 0;
+ my $space_after = 0;
+ if ($ctx =~ /Wx./) {
+ if (ERROR("SPACING",
+ "space prohibited before that '$op' $at\n" . $hereptr)) {
+ $line_fixed = 1;
+ $rtrim_before = 1;
+ }
+ }
+ if ($ctx !~ /.x[WEC]/ && $cc !~ /^}/) {
+ if (ERROR("SPACING",
+ "space required after that '$op' $at\n" . $hereptr)) {
+ $line_fixed = 1;
+ $last_after = $n;
+ $space_after = 1;
+ }
+ }
+ if ($rtrim_before || $space_after) {
+ if ($rtrim_before) {
+ $good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
+ } else {
+ $good = $fix_elements[$n] . trim($fix_elements[$n + 1]);
+ }
+ if ($space_after) {
+ $good .= " ";
+ }
+ }
+
+ # '*' as part of a type definition -- reported already.
+ } elsif ($opv eq '*_') {
+ #warn "'*' is part of type\n";
+
+ # unary operators should have a space before and
+ # none after. May be left adjacent to another
+ # unary operator, or a cast
+ } elsif ($op eq '!' || $op eq '~' ||
+ $opv eq '*U' || $opv eq '-U' ||
+ $opv eq '&U' || $opv eq '&&U') {
+ if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) {
+ if (ERROR("SPACING",
+ "space required before that '$op' $at\n" . $hereptr)) {
+ if ($n != $last_after + 2) {
+ $good = $fix_elements[$n] . " " . ltrim($fix_elements[$n + 1]);
+ $line_fixed = 1;
+ }
+ }
+ }
+ if ($op eq '*' && $cc =~/\s*$Modifier\b/) {
+ # A unary '*' may be const
+
+ } elsif ($ctx =~ /.xW/) {
+ if (ERROR("SPACING",
+ "space prohibited after that '$op' $at\n" . $hereptr)) {
+ $good = $fix_elements[$n] . rtrim($fix_elements[$n + 1]);
+ if (defined $fix_elements[$n + 2]) {
+ $fix_elements[$n + 2] =~ s/^\s+//;
+ }
+ $line_fixed = 1;
+ }
+ }
+
+ # unary ++ and unary -- are allowed no space on one side.
+ } elsif ($op eq '++' or $op eq '--') {
+ if ($ctx !~ /[WEOBC]x[^W]/ && $ctx !~ /[^W]x[WOBEC]/) {
+ if (ERROR("SPACING",
+ "space required one side of that '$op' $at\n" . $hereptr)) {
+ $good = $fix_elements[$n] . trim($fix_elements[$n + 1]) . " ";
+ $line_fixed = 1;
+ }
+ }
+ if ($ctx =~ /Wx[BE]/ ||
+ ($ctx =~ /Wx./ && $cc =~ /^;/)) {
+ if (ERROR("SPACING",
+ "space prohibited before that '$op' $at\n" . $hereptr)) {
+ $good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
+ $line_fixed = 1;
+ }
+ }
+ if ($ctx =~ /ExW/) {
+ if (ERROR("SPACING",
+ "space prohibited after that '$op' $at\n" . $hereptr)) {
+ $good = $fix_elements[$n] . trim($fix_elements[$n + 1]);
+ if (defined $fix_elements[$n + 2]) {
+ $fix_elements[$n + 2] =~ s/^\s+//;
+ }
+ $line_fixed = 1;
+ }
+ }
+
+ # << and >> may either have or not have spaces both sides
+ } elsif ($op eq '<<' or $op eq '>>' or
+ $op eq '&' or $op eq '^' or $op eq '|' or
+ $op eq '+' or $op eq '-' or
+ $op eq '*' or $op eq '/' or
+ $op eq '%')
+ {
+ if ($check) {
+ if (defined $fix_elements[$n + 2] && $ctx !~ /[EW]x[EW]/) {
+ if (CHK("SPACING",
+ "spaces preferred around that '$op' $at\n" . $hereptr)) {
+ $good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
+ $fix_elements[$n + 2] =~ s/^\s+//;
+ $line_fixed = 1;
+ }
+ } elsif (!defined $fix_elements[$n + 2] && $ctx !~ /Wx[OE]/) {
+ if (CHK("SPACING",
+ "space preferred before that '$op' $at\n" . $hereptr)) {
+ $good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]);
+ $line_fixed = 1;
+ }
+ }
+ } elsif ($ctx =~ /Wx[^WCE]|[^WCE]xW/) {
+ if (ERROR("SPACING",
+ "need consistent spacing around '$op' $at\n" . $hereptr)) {
+ $good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
+ if (defined $fix_elements[$n + 2]) {
+ $fix_elements[$n + 2] =~ s/^\s+//;
+ }
+ $line_fixed = 1;
+ }
+ }
+
+ # A colon needs no spaces before when it is
+ # terminating a case value or a label.
+ } elsif ($opv eq ':C' || $opv eq ':L') {
+ if ($ctx =~ /Wx./) {
+ if (ERROR("SPACING",
+ "space prohibited before that '$op' $at\n" . $hereptr)) {
+ $good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
+ $line_fixed = 1;
+ }
+ }
+
+ # All the others need spaces both sides.
+ } elsif ($ctx !~ /[EWC]x[CWE]/) {
+ my $ok = 0;
+
+ # Ignore email addresses <foo@bar>
+ if (($op eq '<' &&
+ $cc =~ /^\S+\@\S+>/) ||
+ ($op eq '>' &&
+ $ca =~ /<\S+\@\S+$/))
+ {
+ $ok = 1;
+ }
+
+ # for asm volatile statements
+ # ignore a colon with another
+ # colon immediately before or after
+ if (($op eq ':') &&
+ ($ca =~ /:$/ || $cc =~ /^:/)) {
+ $ok = 1;
+ }
+
+ # messages are ERROR, but ?: are CHK
+ if ($ok == 0) {
+ my $msg_level = \&ERROR;
+ $msg_level = \&CHK if (($op eq '?:' || $op eq '?' || $op eq ':') && $ctx =~ /VxV/);
+
+ if (&{$msg_level}("SPACING",
+ "spaces required around that '$op' $at\n" . $hereptr)) {
+ $good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
+ if (defined $fix_elements[$n + 2]) {
+ $fix_elements[$n + 2] =~ s/^\s+//;
+ }
+ $line_fixed = 1;
+ }
+ }
+ }
+ $off += length($elements[$n + 1]);
+
+## print("n: <$n> GOOD: <$good>\n");
+
+ $fixed_line = $fixed_line . $good;
+ }
+
+ if (($#elements % 2) == 0) {
+ $fixed_line = $fixed_line . $fix_elements[$#elements];
+ }
+
+ if ($fix && $line_fixed && $fixed_line ne $fixed[$fixlinenr]) {
+ $fixed[$fixlinenr] = $fixed_line;
+ }
+
+
+ }
+
+# check for whitespace before a non-naked semicolon
+ if ($line =~ /^\+.*\S\s+;\s*$/) {
+ if (WARN("SPACING",
+ "space prohibited before semicolon\n" . $herecurr) &&
+ $fix) {
+ 1 while $fixed[$fixlinenr] =~
+ s/^(\+.*\S)\s+;/$1;/;
+ }
+ }
+
+# check for multiple assignments
+ if ($line =~ /^.\s*$Lval\s*=\s*$Lval\s*=(?!=)/) {
+ CHK("MULTIPLE_ASSIGNMENTS",
+ "multiple assignments should be avoided\n" . $herecurr);
+ }
+
+## # check for multiple declarations, allowing for a function declaration
+## # continuation.
+## if ($line =~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Ident.*/ &&
+## $line !~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Type\s*$Ident.*/) {
+##
+## # Remove any bracketed sections to ensure we do not
+## # falsly report the parameters of functions.
+## my $ln = $line;
+## while ($ln =~ s/\([^\(\)]*\)//g) {
+## }
+## if ($ln =~ /,/) {
+## WARN("MULTIPLE_DECLARATION",
+## "declaring multiple variables together should be avoided\n" . $herecurr);
+## }
+## }
+
+#need space before brace following if, while, etc
+ if (($line =~ /\(.*\)\{/ && $line !~ /\($Type\)\{/) ||
+ $line =~ /\b(?:else|do)\{/) {
+ if (ERROR("SPACING",
+ "space required before the open brace '{'\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/^(\+.*(?:do|else|\)))\{/$1 {/;
+ }
+ }
+
+## # check for blank lines before declarations
+## if ($line =~ /^.\t+$Type\s+$Ident(?:\s*=.*)?;/ &&
+## $prevrawline =~ /^.\s*$/) {
+## WARN("SPACING",
+## "No blank lines before declarations\n" . $hereprev);
+## }
+##
+
+# closing brace should have a space following it when it has anything
+# on the line
+ if ($line =~ /}(?!(?:,|;|\)))\S/) {
+ if (ERROR("SPACING",
+ "space required after that close brace '}'\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~
+ s/}((?!(?:,|;|\)))\S)/} $1/;
+ }
+ }
+
+# check spacing on square brackets
+ if ($line =~ /\[\s/ && $line !~ /\[\s*$/) {
+ if (ERROR("SPACING",
+ "space prohibited after that open square bracket '['\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~
+ s/\[\s+/\[/;
+ }
+ }
+ if ($line =~ /\s\]/) {
+ if (ERROR("SPACING",
+ "space prohibited before that close square bracket ']'\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~
+ s/\s+\]/\]/;
+ }
+ }
+
+# check spacing on parentheses
+ if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ &&
+ $line !~ /for\s*\(\s+;/) {
+ if (ERROR("SPACING",
+ "space prohibited after that open parenthesis '('\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~
+ s/\(\s+/\(/;
+ }
+ }
+ if ($line =~ /(\s+)\)/ && $line !~ /^.\s*\)/ &&
+ $line !~ /for\s*\(.*;\s+\)/ &&
+ $line !~ /:\s+\)/) {
+ if (ERROR("SPACING",
+ "space prohibited before that close parenthesis ')'\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~
+ s/\s+\)/\)/;
+ }
+ }
+
+# check unnecessary parentheses around addressof/dereference single $Lvals
+# ie: &(foo->bar) should be &foo->bar and *(foo->bar) should be *foo->bar
+
+ while ($line =~ /(?:[^&]&\s*|\*)\(\s*($Ident\s*(?:$Member\s*)+)\s*\)/g) {
+ my $var = $1;
+ if (CHK("UNNECESSARY_PARENTHESES",
+ "Unnecessary parentheses around $var\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/\(\s*\Q$var\E\s*\)/$var/;
+ }
+ }
+
+# check for unnecessary parentheses around function pointer uses
+# ie: (foo->bar)(); should be foo->bar();
+# but not "if (foo->bar) (" to avoid some false positives
+ if ($line =~ /(\bif\s*|)(\(\s*$Ident\s*(?:$Member\s*)+\))[ \t]*\(/ && $1 !~ /^if/) {
+ my $var = $2;
+ if (CHK("UNNECESSARY_PARENTHESES",
+ "Unnecessary parentheses around function pointer $var\n" . $herecurr) &&
+ $fix) {
+ my $var2 = deparenthesize($var);
+ $var2 =~ s/\s//g;
+ $fixed[$fixlinenr] =~ s/\Q$var\E/$var2/;
+ }
+ }
+
+# check for unnecessary parentheses around comparisons in if uses
+# when !drivers/staging or command-line uses --strict
+ if (($realfile !~ m@^(?:drivers/staging/)@ || $check_orig) &&
+ $perl_version_ok && defined($stat) &&
+ $stat =~ /(^.\s*if\s*($balanced_parens))/) {
+ my $if_stat = $1;
+ my $test = substr($2, 1, -1);
+ my $herectx;
+ while ($test =~ /(?:^|[^\w\&\!\~])+\s*\(\s*([\&\!\~]?\s*$Lval\s*(?:$Compare\s*$FuncArg)?)\s*\)/g) {
+ my $match = $1;
+ # avoid parentheses around potential macro args
+ next if ($match =~ /^\s*\w+\s*$/);
+ if (!defined($herectx)) {
+ $herectx = $here . "\n";
+ my $cnt = statement_rawlines($if_stat);
+ for (my $n = 0; $n < $cnt; $n++) {
+ my $rl = raw_line($linenr, $n);
+ $herectx .= $rl . "\n";
+ last if $rl =~ /^[ \+].*\{/;
+ }
+ }
+ CHK("UNNECESSARY_PARENTHESES",
+ "Unnecessary parentheses around '$match'\n" . $herectx);
+ }
+ }
+
+#goto labels aren't indented, allow a single space however
+ if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and
+ !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) {
+ if (WARN("INDENTED_LABEL",
+ "labels should not be indented\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~
+ s/^(.)\s+/$1/;
+ }
+ }
+
+# return is not a function
+ if (defined($stat) && $stat =~ /^.\s*return(\s*)\(/s) {
+ my $spacing = $1;
+ if ($perl_version_ok &&
+ $stat =~ /^.\s*return\s*($balanced_parens)\s*;\s*$/) {
+ my $value = $1;
+ $value = deparenthesize($value);
+ if ($value =~ m/^\s*$FuncArg\s*(?:\?|$)/) {
+ ERROR("RETURN_PARENTHESES",
+ "return is not a function, parentheses are not required\n" . $herecurr);
+ }
+ } elsif ($spacing !~ /\s+/) {
+ ERROR("SPACING",
+ "space required before the open parenthesis '('\n" . $herecurr);
+ }
+ }
+
+# unnecessary return in a void function
+# at end-of-function, with the previous line a single leading tab, then return;
+# and the line before that not a goto label target like "out:"
+ if ($sline =~ /^[ \+]}\s*$/ &&
+ $prevline =~ /^\+\treturn\s*;\s*$/ &&
+ $linenr >= 3 &&
+ $lines[$linenr - 3] =~ /^[ +]/ &&
+ $lines[$linenr - 3] !~ /^[ +]\s*$Ident\s*:/) {
+ WARN("RETURN_VOID",
+ "void function return statements are not generally useful\n" . $hereprev);
+ }
+
+# if statements using unnecessary parentheses - ie: if ((foo == bar))
+ if ($perl_version_ok &&
+ $line =~ /\bif\s*((?:\(\s*){2,})/) {
+ my $openparens = $1;
+ my $count = $openparens =~ tr@\(@\(@;
+ my $msg = "";
+ if ($line =~ /\bif\s*(?:\(\s*){$count,$count}$LvalOrFunc\s*($Compare)\s*$LvalOrFunc(?:\s*\)){$count,$count}/) {
+ my $comp = $4; #Not $1 because of $LvalOrFunc
+ $msg = " - maybe == should be = ?" if ($comp eq "==");
+ WARN("UNNECESSARY_PARENTHESES",
+ "Unnecessary parentheses$msg\n" . $herecurr);
+ }
+ }
+
+# comparisons with a constant or upper case identifier on the left
+# avoid cases like "foo + BAR < baz"
+# only fix matches surrounded by parentheses to avoid incorrect
+# conversions like "FOO < baz() + 5" being "misfixed" to "baz() > FOO + 5"
+ if ($perl_version_ok &&
+ $line =~ /^\+(.*)\b($Constant|[A-Z_][A-Z0-9_]*)\s*($Compare)\s*($LvalOrFunc)/) {
+ my $lead = $1;
+ my $const = $2;
+ my $comp = $3;
+ my $to = $4;
+ my $newcomp = $comp;
+ if ($lead !~ /(?:$Operators|\.)\s*$/ &&
+ $to !~ /^(?:Constant|[A-Z_][A-Z0-9_]*)$/ &&
+ WARN("CONSTANT_COMPARISON",
+ "Comparisons should place the constant on the right side of the test\n" . $herecurr) &&
+ $fix) {
+ if ($comp eq "<") {
+ $newcomp = ">";
+ } elsif ($comp eq "<=") {
+ $newcomp = ">=";
+ } elsif ($comp eq ">") {
+ $newcomp = "<";
+ } elsif ($comp eq ">=") {
+ $newcomp = "<=";
+ }
+ $fixed[$fixlinenr] =~ s/\(\s*\Q$const\E\s*$Compare\s*\Q$to\E\s*\)/($to $newcomp $const)/;
+ }
+ }
+
+# Return of what appears to be an errno should normally be negative
+ if ($sline =~ /\breturn(?:\s*\(+\s*|\s+)(E[A-Z]+)(?:\s*\)+\s*|\s*)[;:,]/) {
+ my $name = $1;
+ if ($name ne 'EOF' && $name ne 'ERROR') {
+ WARN("USE_NEGATIVE_ERRNO",
+ "return of an errno should typically be negative (ie: return -$1)\n" . $herecurr);
+ }
+ }
+
+# Need a space before open parenthesis after if, while etc
+ if ($line =~ /\b(if|while|for|switch)\(/) {
+ if (ERROR("SPACING",
+ "space required before the open parenthesis '('\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~
+ s/\b(if|while|for|switch)\(/$1 \(/;
+ }
+ }
+
+# Check for illegal assignment in if conditional -- and check for trailing
+# statements after the conditional.
+ if ($line =~ /do\s*(?!{)/) {
+ ($stat, $cond, $line_nr_next, $remain_next, $off_next) =
+ ctx_statement_block($linenr, $realcnt, 0)
+ if (!defined $stat);
+ my ($stat_next) = ctx_statement_block($line_nr_next,
+ $remain_next, $off_next);
+ $stat_next =~ s/\n./\n /g;
+ ##print "stat<$stat> stat_next<$stat_next>\n";
+
+ if ($stat_next =~ /^\s*while\b/) {
+ # If the statement carries leading newlines,
+ # then count those as offsets.
+ my ($whitespace) =
+ ($stat_next =~ /^((?:\s*\n[+-])*\s*)/s);
+ my $offset =
+ statement_rawlines($whitespace) - 1;
+
+ $suppress_whiletrailers{$line_nr_next +
+ $offset} = 1;
+ }
+ }
+ if (!defined $suppress_whiletrailers{$linenr} &&
+ defined($stat) && defined($cond) &&
+ $line =~ /\b(?:if|while|for)\s*\(/ && $line !~ /^.\s*#/) {
+ my ($s, $c) = ($stat, $cond);
+
+ if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/s) {
+ ERROR("ASSIGN_IN_IF",
+ "do not use assignment in if condition\n" . $herecurr);
+ }
+
+ # Find out what is on the end of the line after the
+ # conditional.
+ substr($s, 0, length($c), '');
+ $s =~ s/\n.*//g;
+ $s =~ s/$;//g; # Remove any comments
+ if (length($c) && $s !~ /^\s*{?\s*\\*\s*$/ &&
+ $c !~ /}\s*while\s*/)
+ {
+ # Find out how long the conditional actually is.
+ my @newlines = ($c =~ /\n/gs);
+ my $cond_lines = 1 + $#newlines;
+ my $stat_real = '';
+
+ $stat_real = raw_line($linenr, $cond_lines)
+ . "\n" if ($cond_lines);
+ if (defined($stat_real) && $cond_lines > 1) {
+ $stat_real = "[...]\n$stat_real";
+ }
+
+ ERROR("TRAILING_STATEMENTS",
+ "trailing statements should be on next line\n" . $herecurr . $stat_real);
+ }
+ }
+
+# Check for bitwise tests written as boolean
+ if ($line =~ /
+ (?:
+ (?:\[|\(|\&\&|\|\|)
+ \s*0[xX][0-9]+\s*
+ (?:\&\&|\|\|)
+ |
+ (?:\&\&|\|\|)
+ \s*0[xX][0-9]+\s*
+ (?:\&\&|\|\||\)|\])
+ )/x)
+ {
+ WARN("HEXADECIMAL_BOOLEAN_TEST",
+ "boolean test with hexadecimal, perhaps just 1 \& or \|?\n" . $herecurr);
+ }
+
+# if and else should not have general statements after it
+ if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/) {
+ my $s = $1;
+ $s =~ s/$;//g; # Remove any comments
+ if ($s !~ /^\s*(?:\sif|(?:{|)\s*\\?\s*$)/) {
+ ERROR("TRAILING_STATEMENTS",
+ "trailing statements should be on next line\n" . $herecurr);
+ }
+ }
+# if should not continue a brace
+ if ($line =~ /}\s*if\b/) {
+ ERROR("TRAILING_STATEMENTS",
+ "trailing statements should be on next line (or did you mean 'else if'?)\n" .
+ $herecurr);
+ }
+# case and default should not have general statements after them
+ if ($line =~ /^.\s*(?:case\s*.*|default\s*):/g &&
+ $line !~ /\G(?:
+ (?:\s*$;*)(?:\s*{)?(?:\s*$;*)(?:\s*\\)?\s*$|
+ \s*return\s+
+ )/xg)
+ {
+ ERROR("TRAILING_STATEMENTS",
+ "trailing statements should be on next line\n" . $herecurr);
+ }
+
+ # Check for }<nl>else {, these must be at the same
+ # indent level to be relevant to each other.
+ if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ &&
+ $previndent == $indent) {
+ if (ERROR("ELSE_AFTER_BRACE",
+ "else should follow close brace '}'\n" . $hereprev) &&
+ $fix && $prevline =~ /^\+/ && $line =~ /^\+/) {
+ fix_delete_line($fixlinenr - 1, $prevrawline);
+ fix_delete_line($fixlinenr, $rawline);
+ my $fixedline = $prevrawline;
+ $fixedline =~ s/}\s*$//;
+ if ($fixedline !~ /^\+\s*$/) {
+ fix_insert_line($fixlinenr, $fixedline);
+ }
+ $fixedline = $rawline;
+ $fixedline =~ s/^(.\s*)else/$1} else/;
+ fix_insert_line($fixlinenr, $fixedline);
+ }
+ }
+
+ if ($prevline=~/}\s*$/ and $line=~/^.\s*while\s*/ &&
+ $previndent == $indent) {
+ my ($s, $c) = ctx_statement_block($linenr, $realcnt, 0);
+
+ # Find out what is on the end of the line after the
+ # conditional.
+ substr($s, 0, length($c), '');
+ $s =~ s/\n.*//g;
+
+ if ($s =~ /^\s*;/) {
+ if (ERROR("WHILE_AFTER_BRACE",
+ "while should follow close brace '}'\n" . $hereprev) &&
+ $fix && $prevline =~ /^\+/ && $line =~ /^\+/) {
+ fix_delete_line($fixlinenr - 1, $prevrawline);
+ fix_delete_line($fixlinenr, $rawline);
+ my $fixedline = $prevrawline;
+ my $trailing = $rawline;
+ $trailing =~ s/^\+//;
+ $trailing = trim($trailing);
+ $fixedline =~ s/}\s*$/} $trailing/;
+ fix_insert_line($fixlinenr, $fixedline);
+ }
+ }
+ }
+
+#Specific variable tests
+ while ($line =~ m{($Constant|$Lval)}g) {
+ my $var = $1;
+
+#CamelCase
+ if ($var !~ /^$Constant$/ &&
+ $var =~ /[A-Z][a-z]|[a-z][A-Z]/ &&
+#Ignore Page<foo> variants
+ $var !~ /^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ &&
+#Ignore SI style variants like nS, mV and dB (ie: max_uV, regulator_min_uA_show)
+ $var !~ /^(?:[a-z_]*?)_?[a-z][A-Z](?:_[a-z_]+)?$/ &&
+#Ignore some three character SI units explicitly, like MiB and KHz
+ $var !~ /^(?:[a-z_]*?)_?(?:[KMGT]iB|[KMGT]?Hz)(?:_[a-z_]+)?$/) {
+ while ($var =~ m{($Ident)}g) {
+ my $word = $1;
+ next if ($word !~ /[A-Z][a-z]|[a-z][A-Z]/);
+ if ($check) {
+ seed_camelcase_includes();
+ if (!$file && !$camelcase_file_seeded) {
+ seed_camelcase_file($realfile);
+ $camelcase_file_seeded = 1;
+ }
+ }
+ if (!defined $camelcase{$word}) {
+ $camelcase{$word} = 1;
+ CHK("CAMELCASE",
+ "Avoid CamelCase: <$word>\n" . $herecurr);
+ }
+ }
+ }
+ }
+
+#no spaces allowed after \ in define
+ if ($line =~ /\#\s*define.*\\\s+$/) {
+ if (WARN("WHITESPACE_AFTER_LINE_CONTINUATION",
+ "Whitespace after \\ makes next lines useless\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/\s+$//;
+ }
+ }
+
+# warn if <asm/foo.h> is #included and <linux/foo.h> is available and includes
+# itself <asm/foo.h> (uses RAW line)
+ if ($tree && $rawline =~ m{^.\s*\#\s*include\s*\<asm\/(.*)\.h\>}) {
+ my $file = "$1.h";
+ my $checkfile = "include/linux/$file";
+ if (-f "$root/$checkfile" &&
+ $realfile ne $checkfile &&
+ $1 !~ /$allowed_asm_includes/)
+ {
+ my $asminclude = `grep -Ec "#include\\s+<asm/$file>" $root/$checkfile`;
+ if ($asminclude > 0) {
+ if ($realfile =~ m{^arch/}) {
+ CHK("ARCH_INCLUDE_LINUX",
+ "Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
+ } else {
+ WARN("INCLUDE_LINUX",
+ "Use #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
+ }
+ }
+ }
+ }
+
+# multi-statement macros should be enclosed in a do while loop, grab the
+# first statement and ensure its the whole macro if its not enclosed
+# in a known good container
+ if ($realfile !~ m@/vmlinux.lds.h$@ &&
+ $line =~ /^.\s*\#\s*define\s*$Ident(\()?/) {
+ my $ln = $linenr;
+ my $cnt = $realcnt;
+ my ($off, $dstat, $dcond, $rest);
+ my $ctx = '';
+ my $has_flow_statement = 0;
+ my $has_arg_concat = 0;
+ ($dstat, $dcond, $ln, $cnt, $off) =
+ ctx_statement_block($linenr, $realcnt, 0);
+ $ctx = $dstat;
+ #print "dstat<$dstat> dcond<$dcond> cnt<$cnt> off<$off>\n";
+ #print "LINE<$lines[$ln-1]> len<" . length($lines[$ln-1]) . "\n";
+
+ $has_flow_statement = 1 if ($ctx =~ /\b(goto|return)\b/);
+ $has_arg_concat = 1 if ($ctx =~ /\#\#/ && $ctx !~ /\#\#\s*(?:__VA_ARGS__|args)\b/);
+
+ $dstat =~ s/^.\s*\#\s*define\s+$Ident(\([^\)]*\))?\s*//;
+ my $define_args = $1;
+ my $define_stmt = $dstat;
+ my @def_args = ();
+
+ if (defined $define_args && $define_args ne "") {
+ $define_args = substr($define_args, 1, length($define_args) - 2);
+ $define_args =~ s/\s*//g;
+ $define_args =~ s/\\\+?//g;
+ @def_args = split(",", $define_args);
+ }
+
+ $dstat =~ s/$;//g;
+ $dstat =~ s/\\\n.//g;
+ $dstat =~ s/^\s*//s;
+ $dstat =~ s/\s*$//s;
+
+ # Flatten any parentheses and braces
+ while ($dstat =~ s/\([^\(\)]*\)/1/ ||
+ $dstat =~ s/\{[^\{\}]*\}/1/ ||
+ $dstat =~ s/.\[[^\[\]]*\]/1/)
+ {
+ }
+
+ # Flatten any obvious string concatentation.
+ while ($dstat =~ s/($String)\s*$Ident/$1/ ||
+ $dstat =~ s/$Ident\s*($String)/$1/)
+ {
+ }
+
+ # Make asm volatile uses seem like a generic function
+ $dstat =~ s/\b_*asm_*\s+_*volatile_*\b/asm_volatile/g;
+
+ my $exceptions = qr{
+ $Declare|
+ module_param_named|
+ MODULE_PARM_DESC|
+ DECLARE_PER_CPU|
+ DEFINE_PER_CPU|
+ __typeof__\(|
+ union|
+ struct|
+ \.$Ident\s*=\s*|
+ ^\"|\"$|
+ ^\[
+ }x;
+ #print "REST<$rest> dstat<$dstat> ctx<$ctx>\n";
+
+ $ctx =~ s/\n*$//;
+ my $stmt_cnt = statement_rawlines($ctx);
+ my $herectx = get_stat_here($linenr, $stmt_cnt, $here);
+
+ if ($dstat ne '' &&
+ $dstat !~ /^(?:$Ident|-?$Constant),$/ && # 10, // foo(),
+ $dstat !~ /^(?:$Ident|-?$Constant);$/ && # foo();
+ $dstat !~ /^[!~-]?(?:$Lval|$Constant)$/ && # 10 // foo() // !foo // ~foo // -foo // foo->bar // foo.bar->baz
+ $dstat !~ /^'X'$/ && $dstat !~ /^'XX'$/ && # character constants
+ $dstat !~ /$exceptions/ &&
+ $dstat !~ /^\.$Ident\s*=/ && # .foo =
+ $dstat !~ /^(?:\#\s*$Ident|\#\s*$Constant)\s*$/ && # stringification #foo
+ $dstat !~ /^do\s*$Constant\s*while\s*$Constant;?$/ && # do {...} while (...); // do {...} while (...)
+ $dstat !~ /^for\s*$Constant$/ && # for (...)
+ $dstat !~ /^for\s*$Constant\s+(?:$Ident|-?$Constant)$/ && # for (...) bar()
+ $dstat !~ /^do\s*{/ && # do {...
+ $dstat !~ /^\(\{/ && # ({...
+ $ctx !~ /^.\s*#\s*define\s+TRACE_(?:SYSTEM|INCLUDE_FILE|INCLUDE_PATH)\b/)
+ {
+ if ($dstat =~ /^\s*if\b/) {
+ ERROR("MULTISTATEMENT_MACRO_USE_DO_WHILE",
+ "Macros starting with if should be enclosed by a do - while loop to avoid possible if/else logic defects\n" . "$herectx");
+ } elsif ($dstat =~ /;/) {
+ ERROR("MULTISTATEMENT_MACRO_USE_DO_WHILE",
+ "Macros with multiple statements should be enclosed in a do - while loop\n" . "$herectx");
+ } else {
+ ERROR("COMPLEX_MACRO",
+ "Macros with complex values should be enclosed in parentheses\n" . "$herectx");
+ }
+
+ }
+
+ # Make $define_stmt single line, comment-free, etc
+ my @stmt_array = split('\n', $define_stmt);
+ my $first = 1;
+ $define_stmt = "";
+ foreach my $l (@stmt_array) {
+ $l =~ s/\\$//;
+ if ($first) {
+ $define_stmt = $l;
+ $first = 0;
+ } elsif ($l =~ /^[\+ ]/) {
+ $define_stmt .= substr($l, 1);
+ }
+ }
+ $define_stmt =~ s/$;//g;
+ $define_stmt =~ s/\s+/ /g;
+ $define_stmt = trim($define_stmt);
+
+# check if any macro arguments are reused (ignore '...' and 'type')
+ foreach my $arg (@def_args) {
+ next if ($arg =~ /\.\.\./);
+ next if ($arg =~ /^type$/i);
+ my $tmp_stmt = $define_stmt;
+ $tmp_stmt =~ s/\b(typeof|__typeof__|__builtin\w+|typecheck\s*\(\s*$Type\s*,|\#+)\s*\(*\s*$arg\s*\)*\b//g;
+ $tmp_stmt =~ s/\#+\s*$arg\b//g;
+ $tmp_stmt =~ s/\b$arg\s*\#\#//g;
+ my $use_cnt = () = $tmp_stmt =~ /\b$arg\b/g;
+ if ($use_cnt > 1) {
+ CHK("MACRO_ARG_REUSE",
+ "Macro argument reuse '$arg' - possible side-effects?\n" . "$herectx");
+ }
+# check if any macro arguments may have other precedence issues
+ if ($tmp_stmt =~ m/($Operators)?\s*\b$arg\b\s*($Operators)?/m &&
+ ((defined($1) && $1 ne ',') ||
+ (defined($2) && $2 ne ','))) {
+ CHK("MACRO_ARG_PRECEDENCE",
+ "Macro argument '$arg' may be better as '($arg)' to avoid precedence issues\n" . "$herectx");
+ }
+ }
+
+# check for macros with flow control, but without ## concatenation
+# ## concatenation is commonly a macro that defines a function so ignore those
+ if ($has_flow_statement && !$has_arg_concat) {
+ my $cnt = statement_rawlines($ctx);
+ my $herectx = get_stat_here($linenr, $cnt, $here);
+
+ WARN("MACRO_WITH_FLOW_CONTROL",
+ "Macros with flow control statements should be avoided\n" . "$herectx");
+ }
+
+# check for line continuations outside of #defines, preprocessor #, and asm
+
+ } else {
+ if ($prevline !~ /^..*\\$/ &&
+ $line !~ /^\+\s*\#.*\\$/ && # preprocessor
+ $line !~ /^\+.*\b(__asm__|asm)\b.*\\$/ && # asm
+ $line =~ /^\+.*\\$/) {
+ WARN("LINE_CONTINUATIONS",
+ "Avoid unnecessary line continuations\n" . $herecurr);
+ }
+ }
+
+# do {} while (0) macro tests:
+# single-statement macros do not need to be enclosed in do while (0) loop,
+# macro should not end with a semicolon
+ if ($perl_version_ok &&
+ $realfile !~ m@/vmlinux.lds.h$@ &&
+ $line =~ /^.\s*\#\s*define\s+$Ident(\()?/) {
+ my $ln = $linenr;
+ my $cnt = $realcnt;
+ my ($off, $dstat, $dcond, $rest);
+ my $ctx = '';
+ ($dstat, $dcond, $ln, $cnt, $off) =
+ ctx_statement_block($linenr, $realcnt, 0);
+ $ctx = $dstat;
+
+ $dstat =~ s/\\\n.//g;
+ $dstat =~ s/$;/ /g;
+
+ if ($dstat =~ /^\+\s*#\s*define\s+$Ident\s*${balanced_parens}\s*do\s*{(.*)\s*}\s*while\s*\(\s*0\s*\)\s*([;\s]*)\s*$/) {
+ my $stmts = $2;
+ my $semis = $3;
+
+ $ctx =~ s/\n*$//;
+ my $cnt = statement_rawlines($ctx);
+ my $herectx = get_stat_here($linenr, $cnt, $here);
+
+ if (($stmts =~ tr/;/;/) == 1 &&
+ $stmts !~ /^\s*(if|while|for|switch)\b/) {
+ WARN("SINGLE_STATEMENT_DO_WHILE_MACRO",
+ "Single statement macros should not use a do {} while (0) loop\n" . "$herectx");
+ }
+ if (defined $semis && $semis ne "") {
+ WARN("DO_WHILE_MACRO_WITH_TRAILING_SEMICOLON",
+ "do {} while (0) macros should not be semicolon terminated\n" . "$herectx");
+ }
+ } elsif ($dstat =~ /^\+\s*#\s*define\s+$Ident.*;\s*$/) {
+ $ctx =~ s/\n*$//;
+ my $cnt = statement_rawlines($ctx);
+ my $herectx = get_stat_here($linenr, $cnt, $here);
+
+ WARN("TRAILING_SEMICOLON",
+ "macros should not use a trailing semicolon\n" . "$herectx");
+ }
+ }
+
+# check for redundant bracing round if etc
+ if ($line =~ /(^.*)\bif\b/ && $1 !~ /else\s*$/) {
+ my ($level, $endln, @chunks) =
+ ctx_statement_full($linenr, $realcnt, 1);
+ #print "chunks<$#chunks> linenr<$linenr> endln<$endln> level<$level>\n";
+ #print "APW: <<$chunks[1][0]>><<$chunks[1][1]>>\n";
+ if ($#chunks > 0 && $level == 0) {
+ my @allowed = ();
+ my $allow = 0;
+ my $seen = 0;
+ my $herectx = $here . "\n";
+ my $ln = $linenr - 1;
+ for my $chunk (@chunks) {
+ my ($cond, $block) = @{$chunk};
+
+ # If the condition carries leading newlines, then count those as offsets.
+ my ($whitespace) = ($cond =~ /^((?:\s*\n[+-])*\s*)/s);
+ my $offset = statement_rawlines($whitespace) - 1;
+
+ $allowed[$allow] = 0;
+ #print "COND<$cond> whitespace<$whitespace> offset<$offset>\n";
+
+ # We have looked at and allowed this specific line.
+ $suppress_ifbraces{$ln + $offset} = 1;
+
+ $herectx .= "$rawlines[$ln + $offset]\n[...]\n";
+ $ln += statement_rawlines($block) - 1;
+
+ substr($block, 0, length($cond), '');
+
+ $seen++ if ($block =~ /^\s*{/);
+
+ #print "cond<$cond> block<$block> allowed<$allowed[$allow]>\n";
+ if (statement_lines($cond) > 1) {
+ #print "APW: ALLOWED: cond<$cond>\n";
+ $allowed[$allow] = 1;
+ }
+ if ($block =~/\b(?:if|for|while)\b/) {
+ #print "APW: ALLOWED: block<$block>\n";
+ $allowed[$allow] = 1;
+ }
+ if (statement_block_size($block) > 1) {
+ #print "APW: ALLOWED: lines block<$block>\n";
+ $allowed[$allow] = 1;
+ }
+ $allow++;
+ }
+ if ($seen) {
+ my $sum_allowed = 0;
+ foreach (@allowed) {
+ $sum_allowed += $_;
+ }
+ if ($sum_allowed == 0) {
+ WARN("BRACES",
+ "braces {} are not necessary for any arm of this statement\n" . $herectx);
+ } elsif ($sum_allowed != $allow &&
+ $seen != $allow) {
+ CHK("BRACES",
+ "braces {} should be used on all arms of this statement\n" . $herectx);
+ }
+ }
+ }
+ }
+ if (!defined $suppress_ifbraces{$linenr - 1} &&
+ $line =~ /\b(if|while|for|else)\b/) {
+ my $allowed = 0;
+
+ # Check the pre-context.
+ if (substr($line, 0, $-[0]) =~ /(\}\s*)$/) {
+ #print "APW: ALLOWED: pre<$1>\n";
+ $allowed = 1;
+ }
+
+ my ($level, $endln, @chunks) =
+ ctx_statement_full($linenr, $realcnt, $-[0]);
+
+ # Check the condition.
+ my ($cond, $block) = @{$chunks[0]};
+ #print "CHECKING<$linenr> cond<$cond> block<$block>\n";
+ if (defined $cond) {
+ substr($block, 0, length($cond), '');
+ }
+ if (statement_lines($cond) > 1) {
+ #print "APW: ALLOWED: cond<$cond>\n";
+ $allowed = 1;
+ }
+ if ($block =~/\b(?:if|for|while)\b/) {
+ #print "APW: ALLOWED: block<$block>\n";
+ $allowed = 1;
+ }
+ if (statement_block_size($block) > 1) {
+ #print "APW: ALLOWED: lines block<$block>\n";
+ $allowed = 1;
+ }
+ # Check the post-context.
+ if (defined $chunks[1]) {
+ my ($cond, $block) = @{$chunks[1]};
+ if (defined $cond) {
+ substr($block, 0, length($cond), '');
+ }
+ if ($block =~ /^\s*\{/) {
+ #print "APW: ALLOWED: chunk-1 block<$block>\n";
+ $allowed = 1;
+ }
+ }
+ if ($level == 0 && $block =~ /^\s*\{/ && !$allowed) {
+ my $cnt = statement_rawlines($block);
+ my $herectx = get_stat_here($linenr, $cnt, $here);
+
+ WARN("BRACES",
+ "braces {} are not necessary for single statement blocks\n" . $herectx);
+ }
+ }
+
+# check for single line unbalanced braces
+ if ($sline =~ /^.\s*\}\s*else\s*$/ ||
+ $sline =~ /^.\s*else\s*\{\s*$/) {
+ CHK("BRACES", "Unbalanced braces around else statement\n" . $herecurr);
+ }
+
+# check for unnecessary blank lines around braces
+ if (($line =~ /^.\s*}\s*$/ && $prevrawline =~ /^.\s*$/)) {
+ if (CHK("BRACES",
+ "Blank lines aren't necessary before a close brace '}'\n" . $hereprev) &&
+ $fix && $prevrawline =~ /^\+/) {
+ fix_delete_line($fixlinenr - 1, $prevrawline);
+ }
+ }
+ if (($rawline =~ /^.\s*$/ && $prevline =~ /^..*{\s*$/)) {
+ if (CHK("BRACES",
+ "Blank lines aren't necessary after an open brace '{'\n" . $hereprev) &&
+ $fix) {
+ fix_delete_line($fixlinenr, $rawline);
+ }
+ }
+
+# no volatiles please
+ my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b};
+ if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) {
+ WARN("VOLATILE",
+ "Use of volatile is usually wrong: see Documentation/process/volatile-considered-harmful.rst\n" . $herecurr);
+ }
+
+# Check for user-visible strings broken across lines, which breaks the ability
+# to grep for the string. Make exceptions when the previous string ends in a
+# newline (multiple lines in one string constant) or '\t', '\r', ';', or '{'
+# (common in inline assembly) or is a octal \123 or hexadecimal \xaf value
+ if ($line =~ /^\+\s*$String/ &&
+ $prevline =~ /"\s*$/ &&
+ $prevrawline !~ /(?:\\(?:[ntr]|[0-7]{1,3}|x[0-9a-fA-F]{1,2})|;\s*|\{\s*)"\s*$/) {
+ if (WARN("SPLIT_STRING",
+ "quoted string split across lines\n" . $hereprev) &&
+ $fix &&
+ $prevrawline =~ /^\+.*"\s*$/ &&
+ $last_coalesced_string_linenr != $linenr - 1) {
+ my $extracted_string = get_quoted_string($line, $rawline);
+ my $comma_close = "";
+ if ($rawline =~ /\Q$extracted_string\E(\s*\)\s*;\s*$|\s*,\s*)/) {
+ $comma_close = $1;
+ }
+
+ fix_delete_line($fixlinenr - 1, $prevrawline);
+ fix_delete_line($fixlinenr, $rawline);
+ my $fixedline = $prevrawline;
+ $fixedline =~ s/"\s*$//;
+ $fixedline .= substr($extracted_string, 1) . trim($comma_close);
+ fix_insert_line($fixlinenr - 1, $fixedline);
+ $fixedline = $rawline;
+ $fixedline =~ s/\Q$extracted_string\E\Q$comma_close\E//;
+ if ($fixedline !~ /\+\s*$/) {
+ fix_insert_line($fixlinenr, $fixedline);
+ }
+ $last_coalesced_string_linenr = $linenr;
+ }
+ }
+
+# check for missing a space in a string concatenation
+ if ($prevrawline =~ /[^\\]\w"$/ && $rawline =~ /^\+[\t ]+"\w/) {
+ WARN('MISSING_SPACE',
+ "break quoted strings at a space character\n" . $hereprev);
+ }
+
+# check for an embedded function name in a string when the function is known
+# This does not work very well for -f --file checking as it depends on patch
+# context providing the function name or a single line form for in-file
+# function declarations
+ if ($line =~ /^\+.*$String/ &&
+ defined($context_function) &&
+ get_quoted_string($line, $rawline) =~ /\b$context_function\b/ &&
+ length(get_quoted_string($line, $rawline)) != (length($context_function) + 2)) {
+ WARN("EMBEDDED_FUNCTION_NAME",
+ "Prefer using '\"%s...\", __func__' to using '$context_function', this function's name, in a string\n" . $herecurr);
+ }
+
+# check for spaces before a quoted newline
+ if ($rawline =~ /^.*\".*\s\\n/) {
+ if (WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE",
+ "unnecessary whitespace before a quoted newline\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/^(\+.*\".*)\s+\\n/$1\\n/;
+ }
+
+ }
+
+# concatenated string without spaces between elements
+ if ($line =~ /$String[A-Za-z0-9_]/ || $line =~ /[A-Za-z0-9_]$String/) {
+ if (CHK("CONCATENATED_STRING",
+ "Concatenated strings should use spaces between elements\n" . $herecurr) &&
+ $fix) {
+ while ($line =~ /($String)/g) {
+ my $extracted_string = substr($rawline, $-[0], $+[0] - $-[0]);
+ $fixed[$fixlinenr] =~ s/\Q$extracted_string\E([A-Za-z0-9_])/$extracted_string $1/;
+ $fixed[$fixlinenr] =~ s/([A-Za-z0-9_])\Q$extracted_string\E/$1 $extracted_string/;
+ }
+ }
+ }
+
+# uncoalesced string fragments
+ if ($line =~ /$String\s*"/) {
+ if (WARN("STRING_FRAGMENTS",
+ "Consecutive strings are generally better as a single string\n" . $herecurr) &&
+ $fix) {
+ while ($line =~ /($String)(?=\s*")/g) {
+ my $extracted_string = substr($rawline, $-[0], $+[0] - $-[0]);
+ $fixed[$fixlinenr] =~ s/\Q$extracted_string\E\s*"/substr($extracted_string, 0, -1)/e;
+ }
+ }
+ }
+
+# check for non-standard and hex prefixed decimal printf formats
+ my $show_L = 1; #don't show the same defect twice
+ my $show_Z = 1;
+ while ($line =~ /(?:^|")([X\t]*)(?:"|$)/g) {
+ my $string = substr($rawline, $-[1], $+[1] - $-[1]);
+ $string =~ s/%%/__/g;
+ # check for %L
+ if ($show_L && $string =~ /%[\*\d\.\$]*L([diouxX])/) {
+ WARN("PRINTF_L",
+ "\%L$1 is non-standard C, use %ll$1\n" . $herecurr);
+ $show_L = 0;
+ }
+ # check for %Z
+ if ($show_Z && $string =~ /%[\*\d\.\$]*Z([diouxX])/) {
+ WARN("PRINTF_Z",
+ "%Z$1 is non-standard C, use %z$1\n" . $herecurr);
+ $show_Z = 0;
+ }
+ # check for 0x<decimal>
+ if ($string =~ /0x%[\*\d\.\$\Llzth]*[diou]/) {
+ ERROR("PRINTF_0XDECIMAL",
+ "Prefixing 0x with decimal output is defective\n" . $herecurr);
+ }
+ }
+
+# check for line continuations in quoted strings with odd counts of "
+ if ($rawline =~ /\\$/ && $sline =~ tr/"/"/ % 2) {
+ WARN("LINE_CONTINUATIONS",
+ "Avoid line continuations in quoted strings\n" . $herecurr);
+ }
+
+# warn about #if 0
+ if ($line =~ /^.\s*\#\s*if\s+0\b/) {
+ WARN("IF_0",
+ "Consider removing the code enclosed by this #if 0 and its #endif\n" . $herecurr);
+ }
+
+# warn about #if 1
+ if ($line =~ /^.\s*\#\s*if\s+1\b/) {
+ WARN("IF_1",
+ "Consider removing the #if 1 and its #endif\n" . $herecurr);
+ }
+
+# check for needless "if (<foo>) fn(<foo>)" uses
+ if ($prevline =~ /\bif\s*\(\s*($Lval)\s*\)/) {
+ my $tested = quotemeta($1);
+ my $expr = '\s*\(\s*' . $tested . '\s*\)\s*;';
+ if ($line =~ /\b(kfree|usb_free_urb|debugfs_remove(?:_recursive)?|(?:kmem_cache|mempool|dma_pool)_destroy)$expr/) {
+ my $func = $1;
+ if (WARN('NEEDLESS_IF',
+ "$func(NULL) is safe and this check is probably not required\n" . $hereprev) &&
+ $fix) {
+ my $do_fix = 1;
+ my $leading_tabs = "";
+ my $new_leading_tabs = "";
+ if ($lines[$linenr - 2] =~ /^\+(\t*)if\s*\(\s*$tested\s*\)\s*$/) {
+ $leading_tabs = $1;
+ } else {
+ $do_fix = 0;
+ }
+ if ($lines[$linenr - 1] =~ /^\+(\t+)$func\s*\(\s*$tested\s*\)\s*;\s*$/) {
+ $new_leading_tabs = $1;
+ if (length($leading_tabs) + 1 ne length($new_leading_tabs)) {
+ $do_fix = 0;
+ }
+ } else {
+ $do_fix = 0;
+ }
+ if ($do_fix) {
+ fix_delete_line($fixlinenr - 1, $prevrawline);
+ $fixed[$fixlinenr] =~ s/^\+$new_leading_tabs/\+$leading_tabs/;
+ }
+ }
+ }
+ }
+
+# check for unnecessary "Out of Memory" messages
+ if ($line =~ /^\+.*\b$logFunctions\s*\(/ &&
+ $prevline =~ /^[ \+]\s*if\s*\(\s*(\!\s*|NULL\s*==\s*)?($Lval)(\s*==\s*NULL\s*)?\s*\)/ &&
+ (defined $1 || defined $3) &&
+ $linenr > 3) {
+ my $testval = $2;
+ my $testline = $lines[$linenr - 3];
+
+ my ($s, $c) = ctx_statement_block($linenr - 3, $realcnt, 0);
+# print("line: <$line>\nprevline: <$prevline>\ns: <$s>\nc: <$c>\n\n\n");
+
+ if ($s =~ /(?:^|\n)[ \+]\s*(?:$Type\s*)?\Q$testval\E\s*=\s*(?:\([^\)]*\)\s*)?\s*(?:devm_)?(?:[kv][czm]alloc(?:_node|_array)?\b|kstrdup|kmemdup|(?:dev_)?alloc_skb)/) {
+ WARN("OOM_MESSAGE",
+ "Possible unnecessary 'out of memory' message\n" . $hereprev);
+ }
+ }
+
+# check for logging functions with KERN_<LEVEL>
+ if ($line !~ /printk(?:_ratelimited|_once)?\s*\(/ &&
+ $line =~ /\b$logFunctions\s*\(.*\b(KERN_[A-Z]+)\b/) {
+ my $level = $1;
+ if (WARN("UNNECESSARY_KERN_LEVEL",
+ "Possible unnecessary $level\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/\s*$level\s*//;
+ }
+ }
+
+# check for logging continuations
+ if ($line =~ /\bprintk\s*\(\s*KERN_CONT\b|\bpr_cont\s*\(/) {
+ WARN("LOGGING_CONTINUATION",
+ "Avoid logging continuation uses where feasible\n" . $herecurr);
+ }
+
+# check for mask then right shift without a parentheses
+ if ($perl_version_ok &&
+ $line =~ /$LvalOrFunc\s*\&\s*($LvalOrFunc)\s*>>/ &&
+ $4 !~ /^\&/) { # $LvalOrFunc may be &foo, ignore if so
+ WARN("MASK_THEN_SHIFT",
+ "Possible precedence defect with mask then right shift - may need parentheses\n" . $herecurr);
+ }
+
+# check for pointer comparisons to NULL
+ if ($perl_version_ok) {
+ while ($line =~ /\b$LvalOrFunc\s*(==|\!=)\s*NULL\b/g) {
+ my $val = $1;
+ my $equal = "!";
+ $equal = "" if ($4 eq "!=");
+ if (CHK("COMPARISON_TO_NULL",
+ "Comparison to NULL could be written \"${equal}${val}\"\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/\b\Q$val\E\s*(?:==|\!=)\s*NULL\b/$equal$val/;
+ }
+ }
+ }
+
+# check for bad placement of section $InitAttribute (e.g.: __initdata)
+ if ($line =~ /(\b$InitAttribute\b)/) {
+ my $attr = $1;
+ if ($line =~ /^\+\s*static\s+(?:const\s+)?(?:$attr\s+)?($NonptrTypeWithAttr)\s+(?:$attr\s+)?($Ident(?:\[[^]]*\])?)\s*[=;]/) {
+ my $ptr = $1;
+ my $var = $2;
+ if ((($ptr =~ /\b(union|struct)\s+$attr\b/ &&
+ ERROR("MISPLACED_INIT",
+ "$attr should be placed after $var\n" . $herecurr)) ||
+ ($ptr !~ /\b(union|struct)\s+$attr\b/ &&
+ WARN("MISPLACED_INIT",
+ "$attr should be placed after $var\n" . $herecurr))) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/(\bstatic\s+(?:const\s+)?)(?:$attr\s+)?($NonptrTypeWithAttr)\s+(?:$attr\s+)?($Ident(?:\[[^]]*\])?)\s*([=;])\s*/"$1" . trim(string_find_replace($2, "\\s*$attr\\s*", " ")) . " " . trim(string_find_replace($3, "\\s*$attr\\s*", "")) . " $attr" . ("$4" eq ";" ? ";" : " = ")/e;
+ }
+ }
+ }
+
+# check for $InitAttributeData (ie: __initdata) with const
+ if ($line =~ /\bconst\b/ && $line =~ /($InitAttributeData)/) {
+ my $attr = $1;
+ $attr =~ /($InitAttributePrefix)(.*)/;
+ my $attr_prefix = $1;
+ my $attr_type = $2;
+ if (ERROR("INIT_ATTRIBUTE",
+ "Use of const init definition must use ${attr_prefix}initconst\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~
+ s/$InitAttributeData/${attr_prefix}initconst/;
+ }
+ }
+
+# check for $InitAttributeConst (ie: __initconst) without const
+ if ($line !~ /\bconst\b/ && $line =~ /($InitAttributeConst)/) {
+ my $attr = $1;
+ if (ERROR("INIT_ATTRIBUTE",
+ "Use of $attr requires a separate use of const\n" . $herecurr) &&
+ $fix) {
+ my $lead = $fixed[$fixlinenr] =~
+ /(^\+\s*(?:static\s+))/;
+ $lead = rtrim($1);
+ $lead = "$lead " if ($lead !~ /^\+$/);
+ $lead = "${lead}const ";
+ $fixed[$fixlinenr] =~ s/(^\+\s*(?:static\s+))/$lead/;
+ }
+ }
+
+# check for __read_mostly with const non-pointer (should just be const)
+ if ($line =~ /\b__read_mostly\b/ &&
+ $line =~ /($Type)\s*$Ident/ && $1 !~ /\*\s*$/ && $1 =~ /\bconst\b/) {
+ if (ERROR("CONST_READ_MOSTLY",
+ "Invalid use of __read_mostly with const type\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/\s+__read_mostly\b//;
+ }
+ }
+
+# don't use __constant_<foo> functions outside of include/uapi/
+ if ($realfile !~ m@^include/uapi/@ &&
+ $line =~ /(__constant_(?:htons|ntohs|[bl]e(?:16|32|64)_to_cpu|cpu_to_[bl]e(?:16|32|64)))\s*\(/) {
+ my $constant_func = $1;
+ my $func = $constant_func;
+ $func =~ s/^__constant_//;
+ if (WARN("CONSTANT_CONVERSION",
+ "$constant_func should be $func\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/\b$constant_func\b/$func/g;
+ }
+ }
+
+# prefer usleep_range over udelay
+ if ($line =~ /\budelay\s*\(\s*(\d+)\s*\)/) {
+ my $delay = $1;
+ # ignore udelay's < 10, however
+ if (! ($delay < 10) ) {
+ CHK("USLEEP_RANGE",
+ "usleep_range is preferred over udelay; see Documentation/timers/timers-howto.txt\n" . $herecurr);
+ }
+ if ($delay > 2000) {
+ WARN("LONG_UDELAY",
+ "long udelay - prefer mdelay; see arch/arm/include/asm/delay.h\n" . $herecurr);
+ }
+ }
+
+# warn about unexpectedly long msleep's
+ if ($line =~ /\bmsleep\s*\((\d+)\);/) {
+ if ($1 < 20) {
+ WARN("MSLEEP",
+ "msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.txt\n" . $herecurr);
+ }
+ }
+
+# check for comparisons of jiffies
+ if ($line =~ /\bjiffies\s*$Compare|$Compare\s*jiffies\b/) {
+ WARN("JIFFIES_COMPARISON",
+ "Comparing jiffies is almost always wrong; prefer time_after, time_before and friends\n" . $herecurr);
+ }
+
+# check for comparisons of get_jiffies_64()
+ if ($line =~ /\bget_jiffies_64\s*\(\s*\)\s*$Compare|$Compare\s*get_jiffies_64\s*\(\s*\)/) {
+ WARN("JIFFIES_COMPARISON",
+ "Comparing get_jiffies_64() is almost always wrong; prefer time_after64, time_before64 and friends\n" . $herecurr);
+ }
+
+# warn about #ifdefs in C files
+# if ($line =~ /^.\s*\#\s*if(|n)def/ && ($realfile =~ /\.c$/)) {
+# print "#ifdef in C files should be avoided\n";
+# print "$herecurr";
+# $clean = 0;
+# }
+
+# warn about spacing in #ifdefs
+ if ($line =~ /^.\s*\#\s*(ifdef|ifndef|elif)\s\s+/) {
+ if (ERROR("SPACING",
+ "exactly one space required after that #$1\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~
+ s/^(.\s*\#\s*(ifdef|ifndef|elif))\s{2,}/$1 /;
+ }
+
+ }
+
+# check for spinlock_t definitions without a comment.
+ if ($line =~ /^.\s*(struct\s+mutex|spinlock_t)\s+\S+;/ ||
+ $line =~ /^.\s*(DEFINE_MUTEX)\s*\(/) {
+ my $which = $1;
+ if (!ctx_has_comment($first_line, $linenr)) {
+ CHK("UNCOMMENTED_DEFINITION",
+ "$1 definition without comment\n" . $herecurr);
+ }
+ }
+# check for memory barriers without a comment.
+
+ my $barriers = qr{
+ mb|
+ rmb|
+ wmb|
+ read_barrier_depends
+ }x;
+ my $barrier_stems = qr{
+ mb__before_atomic|
+ mb__after_atomic|
+ store_release|
+ load_acquire|
+ store_mb|
+ (?:$barriers)
+ }x;
+ my $all_barriers = qr{
+ (?:$barriers)|
+ smp_(?:$barrier_stems)|
+ virt_(?:$barrier_stems)
+ }x;
+
+ if ($line =~ /\b(?:$all_barriers)\s*\(/) {
+ if (!ctx_has_comment($first_line, $linenr)) {
+ WARN("MEMORY_BARRIER",
+ "memory barrier without comment\n" . $herecurr);
+ }
+ }
+
+ my $underscore_smp_barriers = qr{__smp_(?:$barrier_stems)}x;
+
+ if ($realfile !~ m@^include/asm-generic/@ &&
+ $realfile !~ m@/barrier\.h$@ &&
+ $line =~ m/\b(?:$underscore_smp_barriers)\s*\(/ &&
+ $line !~ m/^.\s*\#\s*define\s+(?:$underscore_smp_barriers)\s*\(/) {
+ WARN("MEMORY_BARRIER",
+ "__smp memory barriers shouldn't be used outside barrier.h and asm-generic\n" . $herecurr);
+ }
+
+# check for waitqueue_active without a comment.
+ if ($line =~ /\bwaitqueue_active\s*\(/) {
+ if (!ctx_has_comment($first_line, $linenr)) {
+ WARN("WAITQUEUE_ACTIVE",
+ "waitqueue_active without comment\n" . $herecurr);
+ }
+ }
+
+# check for smp_read_barrier_depends and read_barrier_depends
+ if (!$file && $line =~ /\b(smp_|)read_barrier_depends\s*\(/) {
+ WARN("READ_BARRIER_DEPENDS",
+ "$1read_barrier_depends should only be used in READ_ONCE or DEC Alpha code\n" . $herecurr);
+ }
+
+# check of hardware specific defines
+ if ($line =~ m@^.\s*\#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@include/asm-@) {
+ CHK("ARCH_DEFINES",
+ "architecture specific defines should be avoided\n" . $herecurr);
+ }
+
+# check that the storage class is not after a type
+ if ($line =~ /\b($Type)\s+($Storage)\b/) {
+ WARN("STORAGE_CLASS",
+ "storage class '$2' should be located before type '$1'\n" . $herecurr);
+ }
+# Check that the storage class is at the beginning of a declaration
+ if ($line =~ /\b$Storage\b/ &&
+ $line !~ /^.\s*$Storage/ &&
+ $line =~ /^.\s*(.+?)\$Storage\s/ &&
+ $1 !~ /[\,\)]\s*$/) {
+ WARN("STORAGE_CLASS",
+ "storage class should be at the beginning of the declaration\n" . $herecurr);
+ }
+
+# check the location of the inline attribute, that it is between
+# storage class and type.
+ if ($line =~ /\b$Type\s+$Inline\b/ ||
+ $line =~ /\b$Inline\s+$Storage\b/) {
+ ERROR("INLINE_LOCATION",
+ "inline keyword should sit between storage class and type\n" . $herecurr);
+ }
+
+# Check for __inline__ and __inline, prefer inline
+ if ($realfile !~ m@\binclude/uapi/@ &&
+ $line =~ /\b(__inline__|__inline)\b/) {
+ if (WARN("INLINE",
+ "plain inline is preferred over $1\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/\b(__inline__|__inline)\b/inline/;
+
+ }
+ }
+
+# Check for __attribute__ packed, prefer __packed
+ if ($realfile !~ m@\binclude/uapi/@ &&
+ $line =~ /\b__attribute__\s*\(\s*\(.*\bpacked\b/) {
+ WARN("PREFER_PACKED",
+ "__packed is preferred over __attribute__((packed))\n" . $herecurr);
+ }
+
+# Check for __attribute__ aligned, prefer __aligned
+ if ($realfile !~ m@\binclude/uapi/@ &&
+ $line =~ /\b__attribute__\s*\(\s*\(.*aligned/) {
+ WARN("PREFER_ALIGNED",
+ "__aligned(size) is preferred over __attribute__((aligned(size)))\n" . $herecurr);
+ }
+
+# Check for __attribute__ format(printf, prefer __printf
+ if ($realfile !~ m@\binclude/uapi/@ &&
+ $line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf/) {
+ if (WARN("PREFER_PRINTF",
+ "__printf(string-index, first-to-check) is preferred over __attribute__((format(printf, string-index, first-to-check)))\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf\s*,\s*(.*)\)\s*\)\s*\)/"__printf(" . trim($1) . ")"/ex;
+
+ }
+ }
+
+# Check for __attribute__ format(scanf, prefer __scanf
+ if ($realfile !~ m@\binclude/uapi/@ &&
+ $line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\b/) {
+ if (WARN("PREFER_SCANF",
+ "__scanf(string-index, first-to-check) is preferred over __attribute__((format(scanf, string-index, first-to-check)))\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\s*,\s*(.*)\)\s*\)\s*\)/"__scanf(" . trim($1) . ")"/ex;
+ }
+ }
+
+# Check for __attribute__ weak, or __weak declarations (may have link issues)
+ if ($perl_version_ok &&
+ $line =~ /(?:$Declare|$DeclareMisordered)\s*$Ident\s*$balanced_parens\s*(?:$Attribute)?\s*;/ &&
+ ($line =~ /\b__attribute__\s*\(\s*\(.*\bweak\b/ ||
+ $line =~ /\b__weak\b/)) {
+ ERROR("WEAK_DECLARATION",
+ "Using weak declarations can have unintended link defects\n" . $herecurr);
+ }
+
+# check for c99 types like uint8_t used outside of uapi/ and tools/
+ if ($realfile !~ m@\binclude/uapi/@ &&
+ $realfile !~ m@\btools/@ &&
+ $line =~ /\b($Declare)\s*$Ident\s*[=;,\[]/) {
+ my $type = $1;
+ if ($type =~ /\b($typeC99Typedefs)\b/) {
+ $type = $1;
+ my $kernel_type = 'u';
+ $kernel_type = 's' if ($type =~ /^_*[si]/);
+ $type =~ /(\d+)/;
+ $kernel_type .= $1;
+ if (CHK("PREFER_KERNEL_TYPES",
+ "Prefer kernel type '$kernel_type' over '$type'\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/\b$type\b/$kernel_type/;
+ }
+ }
+ }
+
+# check for cast of C90 native int or longer types constants
+ if ($line =~ /(\(\s*$C90_int_types\s*\)\s*)($Constant)\b/) {
+ my $cast = $1;
+ my $const = $2;
+ if (WARN("TYPECAST_INT_CONSTANT",
+ "Unnecessary typecast of c90 int constant\n" . $herecurr) &&
+ $fix) {
+ my $suffix = "";
+ my $newconst = $const;
+ $newconst =~ s/${Int_type}$//;
+ $suffix .= 'U' if ($cast =~ /\bunsigned\b/);
+ if ($cast =~ /\blong\s+long\b/) {
+ $suffix .= 'LL';
+ } elsif ($cast =~ /\blong\b/) {
+ $suffix .= 'L';
+ }
+ $fixed[$fixlinenr] =~ s/\Q$cast\E$const\b/$newconst$suffix/;
+ }
+ }
+
+# check for sizeof(&)
+ if ($line =~ /\bsizeof\s*\(\s*\&/) {
+ WARN("SIZEOF_ADDRESS",
+ "sizeof(& should be avoided\n" . $herecurr);
+ }
+
+# check for sizeof without parenthesis
+ if ($line =~ /\bsizeof\s+((?:\*\s*|)$Lval|$Type(?:\s+$Lval|))/) {
+ if (WARN("SIZEOF_PARENTHESIS",
+ "sizeof $1 should be sizeof($1)\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/\bsizeof\s+((?:\*\s*|)$Lval|$Type(?:\s+$Lval|))/"sizeof(" . trim($1) . ")"/ex;
+ }
+ }
+
+# check for struct spinlock declarations
+ if ($line =~ /^.\s*\bstruct\s+spinlock\s+\w+\s*;/) {
+ WARN("USE_SPINLOCK_T",
+ "struct spinlock should be spinlock_t\n" . $herecurr);
+ }
+
+# check for seq_printf uses that could be seq_puts
+ if ($sline =~ /\bseq_printf\s*\(.*"\s*\)\s*;\s*$/) {
+ my $fmt = get_quoted_string($line, $rawline);
+ $fmt =~ s/%%//g;
+ if ($fmt !~ /%/) {
+ if (WARN("PREFER_SEQ_PUTS",
+ "Prefer seq_puts to seq_printf\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/\bseq_printf\b/seq_puts/;
+ }
+ }
+ }
+
+# check for vsprintf extension %p<foo> misuses
+ if ($perl_version_ok &&
+ defined $stat &&
+ $stat =~ /^\+(?![^\{]*\{\s*).*\b(\w+)\s*\(.*$String\s*,/s &&
+ $1 !~ /^_*volatile_*$/) {
+ my $stat_real;
+
+ my $lc = $stat =~ tr@\n@@;
+ $lc = $lc + $linenr;
+ for (my $count = $linenr; $count <= $lc; $count++) {
+ my $specifier;
+ my $extension;
+ my $bad_specifier = "";
+ my $fmt = get_quoted_string($lines[$count - 1], raw_line($count, 0));
+ $fmt =~ s/%%//g;
+
+ while ($fmt =~ /(\%[\*\d\.]*p(\w))/g) {
+ $specifier = $1;
+ $extension = $2;
+ if ($extension !~ /[SsBKRraEhMmIiUDdgVCbGNOx]/) {
+ $bad_specifier = $specifier;
+ last;
+ }
+ if ($extension eq "x" && !defined($stat_real)) {
+ if (!defined($stat_real)) {
+ $stat_real = get_stat_real($linenr, $lc);
+ }
+ WARN("VSPRINTF_SPECIFIER_PX",
+ "Using vsprintf specifier '\%px' potentially exposes the kernel memory layout, if you don't really need the address please consider using '\%p'.\n" . "$here\n$stat_real\n");
+ }
+ }
+ if ($bad_specifier ne "") {
+ my $stat_real = get_stat_real($linenr, $lc);
+ my $ext_type = "Invalid";
+ my $use = "";
+ if ($bad_specifier =~ /p[Ff]/) {
+ $ext_type = "Deprecated";
+ $use = " - use %pS instead";
+ $use =~ s/pS/ps/ if ($bad_specifier =~ /pf/);
+ }
+
+ WARN("VSPRINTF_POINTER_EXTENSION",
+ "$ext_type vsprintf pointer extension '$bad_specifier'$use\n" . "$here\n$stat_real\n");
+ }
+ }
+ }
+
+# Check for misused memsets
+ if ($perl_version_ok &&
+ defined $stat &&
+ $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*$FuncArg\s*\)/) {
+
+ my $ms_addr = $2;
+ my $ms_val = $7;
+ my $ms_size = $12;
+
+ if ($ms_size =~ /^(0x|)0$/i) {
+ ERROR("MEMSET",
+ "memset to 0's uses 0 as the 2nd argument, not the 3rd\n" . "$here\n$stat\n");
+ } elsif ($ms_size =~ /^(0x|)1$/i) {
+ WARN("MEMSET",
+ "single byte memset is suspicious. Swapped 2nd/3rd argument?\n" . "$here\n$stat\n");
+ }
+ }
+
+# Check for memcpy(foo, bar, ETH_ALEN) that could be ether_addr_copy(foo, bar)
+# if ($perl_version_ok &&
+# defined $stat &&
+# $stat =~ /^\+(?:.*?)\bmemcpy\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) {
+# if (WARN("PREFER_ETHER_ADDR_COPY",
+# "Prefer ether_addr_copy() over memcpy() if the Ethernet addresses are __aligned(2)\n" . "$here\n$stat\n") &&
+# $fix) {
+# $fixed[$fixlinenr] =~ s/\bmemcpy\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/ether_addr_copy($2, $7)/;
+# }
+# }
+
+# Check for memcmp(foo, bar, ETH_ALEN) that could be ether_addr_equal*(foo, bar)
+# if ($perl_version_ok &&
+# defined $stat &&
+# $stat =~ /^\+(?:.*?)\bmemcmp\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) {
+# WARN("PREFER_ETHER_ADDR_EQUAL",
+# "Prefer ether_addr_equal() or ether_addr_equal_unaligned() over memcmp()\n" . "$here\n$stat\n")
+# }
+
+# check for memset(foo, 0x0, ETH_ALEN) that could be eth_zero_addr
+# check for memset(foo, 0xFF, ETH_ALEN) that could be eth_broadcast_addr
+# if ($perl_version_ok &&
+# defined $stat &&
+# $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) {
+#
+# my $ms_val = $7;
+#
+# if ($ms_val =~ /^(?:0x|)0+$/i) {
+# if (WARN("PREFER_ETH_ZERO_ADDR",
+# "Prefer eth_zero_addr over memset()\n" . "$here\n$stat\n") &&
+# $fix) {
+# $fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*,\s*ETH_ALEN\s*\)/eth_zero_addr($2)/;
+# }
+# } elsif ($ms_val =~ /^(?:0xff|255)$/i) {
+# if (WARN("PREFER_ETH_BROADCAST_ADDR",
+# "Prefer eth_broadcast_addr() over memset()\n" . "$here\n$stat\n") &&
+# $fix) {
+# $fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*,\s*ETH_ALEN\s*\)/eth_broadcast_addr($2)/;
+# }
+# }
+# }
+
+# typecasts on min/max could be min_t/max_t
+ if ($perl_version_ok &&
+ defined $stat &&
+ $stat =~ /^\+(?:.*?)\b(min|max)\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\)/) {
+ if (defined $2 || defined $7) {
+ my $call = $1;
+ my $cast1 = deparenthesize($2);
+ my $arg1 = $3;
+ my $cast2 = deparenthesize($7);
+ my $arg2 = $8;
+ my $cast;
+
+ if ($cast1 ne "" && $cast2 ne "" && $cast1 ne $cast2) {
+ $cast = "$cast1 or $cast2";
+ } elsif ($cast1 ne "") {
+ $cast = $cast1;
+ } else {
+ $cast = $cast2;
+ }
+ WARN("MINMAX",
+ "$call() should probably be ${call}_t($cast, $arg1, $arg2)\n" . "$here\n$stat\n");
+ }
+ }
+
+# check usleep_range arguments
+ if ($perl_version_ok &&
+ defined $stat &&
+ $stat =~ /^\+(?:.*?)\busleep_range\s*\(\s*($FuncArg)\s*,\s*($FuncArg)\s*\)/) {
+ my $min = $1;
+ my $max = $7;
+ if ($min eq $max) {
+ WARN("USLEEP_RANGE",
+ "usleep_range should not use min == max args; see Documentation/timers/timers-howto.txt\n" . "$here\n$stat\n");
+ } elsif ($min =~ /^\d+$/ && $max =~ /^\d+$/ &&
+ $min > $max) {
+ WARN("USLEEP_RANGE",
+ "usleep_range args reversed, use min then max; see Documentation/timers/timers-howto.txt\n" . "$here\n$stat\n");
+ }
+ }
+
+# check for naked sscanf
+ if ($perl_version_ok &&
+ defined $stat &&
+ $line =~ /\bsscanf\b/ &&
+ ($stat !~ /$Ident\s*=\s*sscanf\s*$balanced_parens/ &&
+ $stat !~ /\bsscanf\s*$balanced_parens\s*(?:$Compare)/ &&
+ $stat !~ /(?:$Compare)\s*\bsscanf\s*$balanced_parens/)) {
+ my $lc = $stat =~ tr@\n@@;
+ $lc = $lc + $linenr;
+ my $stat_real = get_stat_real($linenr, $lc);
+ WARN("NAKED_SSCANF",
+ "unchecked sscanf return value\n" . "$here\n$stat_real\n");
+ }
+
+# check for simple sscanf that should be kstrto<foo>
+ if ($perl_version_ok &&
+ defined $stat &&
+ $line =~ /\bsscanf\b/) {
+ my $lc = $stat =~ tr@\n@@;
+ $lc = $lc + $linenr;
+ my $stat_real = get_stat_real($linenr, $lc);
+ if ($stat_real =~ /\bsscanf\b\s*\(\s*$FuncArg\s*,\s*("[^"]+")/) {
+ my $format = $6;
+ my $count = $format =~ tr@%@%@;
+ if ($count == 1 &&
+ $format =~ /^"\%(?i:ll[udxi]|[udxi]ll|ll|[hl]h?[udxi]|[udxi][hl]h?|[hl]h?|[udxi])"$/) {
+ WARN("SSCANF_TO_KSTRTO",
+ "Prefer kstrto<type> to single variable sscanf\n" . "$here\n$stat_real\n");
+ }
+ }
+ }
+
+# check for new externs in .h files.
+ if ($realfile =~ /\.h$/ &&
+ $line =~ /^\+\s*(extern\s+)$Type\s*$Ident\s*\(/s) {
+ if (CHK("AVOID_EXTERNS",
+ "extern prototypes should be avoided in .h files\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/(.*)\bextern\b\s*(.*)/$1$2/;
+ }
+ }
+
+# check for new externs in .c files.
+ if ($realfile =~ /\.c$/ && defined $stat &&
+ $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s)
+ {
+ my $function_name = $1;
+ my $paren_space = $2;
+
+ my $s = $stat;
+ if (defined $cond) {
+ substr($s, 0, length($cond), '');
+ }
+ if ($s =~ /^\s*;/ &&
+ $function_name ne 'uninitialized_var')
+ {
+ WARN("AVOID_EXTERNS",
+ "externs should be avoided in .c files\n" . $herecurr);
+ }
+
+ if ($paren_space =~ /\n/) {
+ WARN("FUNCTION_ARGUMENTS",
+ "arguments for function declarations should follow identifier\n" . $herecurr);
+ }
+
+ } elsif ($realfile =~ /\.c$/ && defined $stat &&
+ $stat =~ /^.\s*extern\s+/)
+ {
+ WARN("AVOID_EXTERNS",
+ "externs should be avoided in .c files\n" . $herecurr);
+ }
+
+# check for function declarations that have arguments without identifier names
+ if (defined $stat &&
+ $stat =~ /^.\s*(?:extern\s+)?$Type\s*(?:$Ident|\(\s*\*\s*$Ident\s*\))\s*\(\s*([^{]+)\s*\)\s*;/s &&
+ $1 ne "void") {
+ my $args = trim($1);
+ while ($args =~ m/\s*($Type\s*(?:$Ident|\(\s*\*\s*$Ident?\s*\)\s*$balanced_parens)?)/g) {
+ my $arg = trim($1);
+ if ($arg =~ /^$Type$/ && $arg !~ /enum\s+$Ident$/) {
+ WARN("FUNCTION_ARGUMENTS",
+ "function definition argument '$arg' should also have an identifier name\n" . $herecurr);
+ }
+ }
+ }
+
+# check for function definitions
+ if ($perl_version_ok &&
+ defined $stat &&
+ $stat =~ /^.\s*(?:$Storage\s+)?$Type\s*($Ident)\s*$balanced_parens\s*{/s) {
+ $context_function = $1;
+
+# check for multiline function definition with misplaced open brace
+ my $ok = 0;
+ my $cnt = statement_rawlines($stat);
+ my $herectx = $here . "\n";
+ for (my $n = 0; $n < $cnt; $n++) {
+ my $rl = raw_line($linenr, $n);
+ $herectx .= $rl . "\n";
+ $ok = 1 if ($rl =~ /^[ \+]\{/);
+ $ok = 1 if ($rl =~ /\{/ && $n == 0);
+ last if $rl =~ /^[ \+].*\{/;
+ }
+ if (!$ok) {
+ ERROR("OPEN_BRACE",
+ "open brace '{' following function definitions go on the next line\n" . $herectx);
+ }
+ }
+
+# checks for new __setup's
+ if ($rawline =~ /\b__setup\("([^"]*)"/) {
+ my $name = $1;
+
+ if (!grep(/$name/, @setup_docs)) {
+ CHK("UNDOCUMENTED_SETUP",
+ "__setup appears un-documented -- check Documentation/admin-guide/kernel-parameters.rst\n" . $herecurr);
+ }
+ }
+
+# check for pointless casting of kmalloc return
+ if ($line =~ /\*\s*\)\s*[kv][czm]alloc(_node){0,1}\b/) {
+ WARN("UNNECESSARY_CASTS",
+ "unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
+ }
+
+# alloc style
+# p = alloc(sizeof(struct foo), ...) should be p = alloc(sizeof(*p), ...)
+ if ($perl_version_ok &&
+ $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*([kv][mz]alloc(?:_node)?)\s*\(\s*(sizeof\s*\(\s*struct\s+$Lval\s*\))/) {
+ CHK("ALLOC_SIZEOF_STRUCT",
+ "Prefer $3(sizeof(*$1)...) over $3($4...)\n" . $herecurr);
+ }
+
+# check for k[mz]alloc with multiplies that could be kmalloc_array/kcalloc
+ if ($perl_version_ok &&
+ defined $stat &&
+ $stat =~ /^\+\s*($Lval)\s*\=\s*(?:$balanced_parens)?\s*(k[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)\s*,/) {
+ my $oldfunc = $3;
+ my $a1 = $4;
+ my $a2 = $10;
+ my $newfunc = "kmalloc_array";
+ $newfunc = "kcalloc" if ($oldfunc eq "kzalloc");
+ my $r1 = $a1;
+ my $r2 = $a2;
+ if ($a1 =~ /^sizeof\s*\S/) {
+ $r1 = $a2;
+ $r2 = $a1;
+ }
+ if ($r1 !~ /^sizeof\b/ && $r2 =~ /^sizeof\s*\S/ &&
+ !($r1 =~ /^$Constant$/ || $r1 =~ /^[A-Z_][A-Z0-9_]*$/)) {
+ my $cnt = statement_rawlines($stat);
+ my $herectx = get_stat_here($linenr, $cnt, $here);
+
+ if (WARN("ALLOC_WITH_MULTIPLY",
+ "Prefer $newfunc over $oldfunc with multiply\n" . $herectx) &&
+ $cnt == 1 &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*(k[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)/$1 . ' = ' . "$newfunc(" . trim($r1) . ', ' . trim($r2)/e;
+ }
+ }
+ }
+
+# check for krealloc arg reuse
+ if ($perl_version_ok &&
+ $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*krealloc\s*\(\s*($Lval)\s*,/ &&
+ $1 eq $3) {
+ WARN("KREALLOC_ARG_REUSE",
+ "Reusing the krealloc arg is almost always a bug\n" . $herecurr);
+ }
+
+# check for alloc argument mismatch
+ if ($line =~ /\b(kcalloc|kmalloc_array)\s*\(\s*sizeof\b/) {
+ WARN("ALLOC_ARRAY_ARGS",
+ "$1 uses number as first arg, sizeof is generally wrong\n" . $herecurr);
+ }
+
+# check for multiple semicolons
+ if ($line =~ /;\s*;\s*$/) {
+ if (WARN("ONE_SEMICOLON",
+ "Statements terminations use 1 semicolon\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/(\s*;\s*){2,}$/;/g;
+ }
+ }
+
+# check for #defines like: 1 << <digit> that could be BIT(digit), it is not exported to uapi
+ if ($realfile !~ m@^include/uapi/@ &&
+ $line =~ /#\s*define\s+\w+\s+\(?\s*1\s*([ulUL]*)\s*\<\<\s*(?:\d+|$Ident)\s*\)?/) {
+ my $ull = "";
+ $ull = "_ULL" if (defined($1) && $1 =~ /ll/i);
+ if (CHK("BIT_MACRO",
+ "Prefer using the BIT$ull macro\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/\(?\s*1\s*[ulUL]*\s*<<\s*(\d+|$Ident)\s*\)?/BIT${ull}($1)/;
+ }
+ }
+
+# check for #if defined CONFIG_<FOO> || defined CONFIG_<FOO>_MODULE
+ if ($line =~ /^\+\s*#\s*if\s+defined(?:\s*\(?\s*|\s+)(CONFIG_[A-Z_]+)\s*\)?\s*\|\|\s*defined(?:\s*\(?\s*|\s+)\1_MODULE\s*\)?\s*$/) {
+ my $config = $1;
+ if (WARN("PREFER_IS_ENABLED",
+ "Prefer IS_ENABLED(<FOO>) to CONFIG_<FOO> || CONFIG_<FOO>_MODULE\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] = "\+#if IS_ENABLED($config)";
+ }
+ }
+
+# check for case / default statements not preceded by break/fallthrough/switch
+ if ($line =~ /^.\s*(?:case\s+(?:$Ident|$Constant)\s*|default):/) {
+ my $has_break = 0;
+ my $has_statement = 0;
+ my $count = 0;
+ my $prevline = $linenr;
+ while ($prevline > 1 && ($file || $count < 3) && !$has_break) {
+ $prevline--;
+ my $rline = $rawlines[$prevline - 1];
+ my $fline = $lines[$prevline - 1];
+ last if ($fline =~ /^\@\@/);
+ next if ($fline =~ /^\-/);
+ next if ($fline =~ /^.(?:\s*(?:case\s+(?:$Ident|$Constant)[\s$;]*|default):[\s$;]*)*$/);
+ $has_break = 1 if ($rline =~ /fall[\s_-]*(through|thru)/i);
+ next if ($fline =~ /^.[\s$;]*$/);
+ $has_statement = 1;
+ $count++;
+ $has_break = 1 if ($fline =~ /\bswitch\b|\b(?:break\s*;[\s$;]*$|exit\s*\(\b|return\b|goto\b|continue\b)/);
+ }
+ if (!$has_break && $has_statement) {
+ WARN("MISSING_BREAK",
+ "Possible switch case/default not preceded by break or fallthrough comment\n" . $herecurr);
+ }
+ }
+
+# check for switch/default statements without a break;
+ if ($perl_version_ok &&
+ defined $stat &&
+ $stat =~ /^\+[$;\s]*(?:case[$;\s]+\w+[$;\s]*:[$;\s]*|)*[$;\s]*\bdefault[$;\s]*:[$;\s]*;/g) {
+ my $cnt = statement_rawlines($stat);
+ my $herectx = get_stat_here($linenr, $cnt, $here);
+
+ WARN("DEFAULT_NO_BREAK",
+ "switch default: should use break\n" . $herectx);
+ }
+
+# check for gcc specific __FUNCTION__
+ if ($line =~ /\b__FUNCTION__\b/) {
+ if (WARN("USE_FUNC",
+ "__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/\b__FUNCTION__\b/__func__/g;
+ }
+ }
+
+# check for uses of __DATE__, __TIME__, __TIMESTAMP__
+ while ($line =~ /\b(__(?:DATE|TIME|TIMESTAMP)__)\b/g) {
+ ERROR("DATE_TIME",
+ "Use of the '$1' macro makes the build non-deterministic\n" . $herecurr);
+ }
+
+# check for use of yield()
+ if ($line =~ /\byield\s*\(\s*\)/) {
+ WARN("YIELD",
+ "Using yield() is generally wrong. See yield() kernel-doc (sched/core.c)\n" . $herecurr);
+ }
+
+# check for comparisons against true and false
+ if ($line =~ /\+\s*(.*?)\b(true|false|$Lval)\s*(==|\!=)\s*(true|false|$Lval)\b(.*)$/i) {
+ my $lead = $1;
+ my $arg = $2;
+ my $test = $3;
+ my $otype = $4;
+ my $trail = $5;
+ my $op = "!";
+
+ ($arg, $otype) = ($otype, $arg) if ($arg =~ /^(?:true|false)$/i);
+
+ my $type = lc($otype);
+ if ($type =~ /^(?:true|false)$/) {
+ if (("$test" eq "==" && "$type" eq "true") ||
+ ("$test" eq "!=" && "$type" eq "false")) {
+ $op = "";
+ }
+
+ CHK("BOOL_COMPARISON",
+ "Using comparison to $otype is error prone\n" . $herecurr);
+
+## maybe suggesting a correct construct would better
+## "Using comparison to $otype is error prone. Perhaps use '${lead}${op}${arg}${trail}'\n" . $herecurr);
+
+ }
+ }
+
+# check for bool bitfields
+ if ($sline =~ /^.\s+bool\s*$Ident\s*:\s*\d+\s*;/) {
+ WARN("BOOL_BITFIELD",
+ "Avoid using bool as bitfield. Prefer bool bitfields as unsigned int or u<8|16|32>\n" . $herecurr);
+ }
+
+# check for bool use in .h files
+ if ($realfile =~ /\.h$/ &&
+ $sline =~ /^.\s+bool\s*$Ident\s*(?::\s*d+\s*)?;/) {
+ CHK("BOOL_MEMBER",
+ "Avoid using bool structure members because of possible alignment issues - see: https://lkml.org/lkml/2017/11/21/384\n" . $herecurr);
+ }
+
+# check for semaphores initialized locked
+ if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) {
+ WARN("CONSIDER_COMPLETION",
+ "consider using a completion\n" . $herecurr);
+ }
+
+# recommend kstrto* over simple_strto* and strict_strto*
+ if ($line =~ /\b((simple|strict)_(strto(l|ll|ul|ull)))\s*\(/) {
+ WARN("CONSIDER_KSTRTO",
+ "$1 is obsolete, use k$3 instead\n" . $herecurr);
+ }
+
+# check for __initcall(), use device_initcall() explicitly or more appropriate function please
+ if ($line =~ /^.\s*__initcall\s*\(/) {
+ WARN("USE_DEVICE_INITCALL",
+ "please use device_initcall() or more appropriate function instead of __initcall() (see include/linux/init.h)\n" . $herecurr);
+ }
+
+# check for spin_is_locked(), suggest lockdep instead
+ if ($line =~ /\bspin_is_locked\(/) {
+ WARN("USE_LOCKDEP",
+ "Where possible, use lockdep_assert_held instead of assertions based on spin_is_locked\n" . $herecurr);
+ }
+
+# check for deprecated apis
+ if ($line =~ /\b($deprecated_apis_search)\b\s*\(/) {
+ my $deprecated_api = $1;
+ my $new_api = $deprecated_apis{$deprecated_api};
+ WARN("DEPRECATED_API",
+ "Deprecated use of '$deprecated_api', prefer '$new_api' instead\n" . $herecurr);
+ }
+
+# check for various structs that are normally const (ops, kgdb, device_tree)
+# and avoid what seem like struct definitions 'struct foo {'
+ if ($line !~ /\bconst\b/ &&
+ $line =~ /\bstruct\s+($const_structs)\b(?!\s*\{)/) {
+ WARN("CONST_STRUCT",
+ "struct $1 should normally be const\n" . $herecurr);
+ }
+
+# use of NR_CPUS is usually wrong
+# ignore definitions of NR_CPUS and usage to define arrays as likely right
+ if ($line =~ /\bNR_CPUS\b/ &&
+ $line !~ /^.\s*\s*#\s*if\b.*\bNR_CPUS\b/ &&
+ $line !~ /^.\s*\s*#\s*define\b.*\bNR_CPUS\b/ &&
+ $line !~ /^.\s*$Declare\s.*\[[^\]]*NR_CPUS[^\]]*\]/ &&
+ $line !~ /\[[^\]]*\.\.\.[^\]]*NR_CPUS[^\]]*\]/ &&
+ $line !~ /\[[^\]]*NR_CPUS[^\]]*\.\.\.[^\]]*\]/)
+ {
+ WARN("NR_CPUS",
+ "usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_possible_cpu(), etc\n" . $herecurr);
+ }
+
+# Use of __ARCH_HAS_<FOO> or ARCH_HAVE_<BAR> is wrong.
+ if ($line =~ /\+\s*#\s*define\s+((?:__)?ARCH_(?:HAS|HAVE)\w*)\b/) {
+ ERROR("DEFINE_ARCH_HAS",
+ "#define of '$1' is wrong - use Kconfig variables or standard guards instead\n" . $herecurr);
+ }
+
+# likely/unlikely comparisons similar to "(likely(foo) > 0)"
+ if ($perl_version_ok &&
+ $line =~ /\b((?:un)?likely)\s*\(\s*$FuncArg\s*\)\s*$Compare/) {
+ WARN("LIKELY_MISUSE",
+ "Using $1 should generally have parentheses around the comparison\n" . $herecurr);
+ }
+
+# whine mightly about in_atomic
+ if ($line =~ /\bin_atomic\s*\(/) {
+ if ($realfile =~ m@^drivers/@) {
+ ERROR("IN_ATOMIC",
+ "do not use in_atomic in drivers\n" . $herecurr);
+ } elsif ($realfile !~ m@^kernel/@) {
+ WARN("IN_ATOMIC",
+ "use of in_atomic() is incorrect outside core kernel code\n" . $herecurr);
+ }
+ }
+
+# check for mutex_trylock_recursive usage
+ if ($line =~ /mutex_trylock_recursive/) {
+ ERROR("LOCKING",
+ "recursive locking is bad, do not use this ever.\n" . $herecurr);
+ }
+
+# check for lockdep_set_novalidate_class
+ if ($line =~ /^.\s*lockdep_set_novalidate_class\s*\(/ ||
+ $line =~ /__lockdep_no_validate__\s*\)/ ) {
+ if ($realfile !~ m@^kernel/lockdep@ &&
+ $realfile !~ m@^include/linux/lockdep@ &&
+ $realfile !~ m@^drivers/base/core@) {
+ ERROR("LOCKDEP",
+ "lockdep_no_validate class is reserved for device->mutex.\n" . $herecurr);
+ }
+ }
+
+ if ($line =~ /debugfs_create_\w+.*\b$mode_perms_world_writable\b/ ||
+ $line =~ /DEVICE_ATTR.*\b$mode_perms_world_writable\b/) {
+ WARN("EXPORTED_WORLD_WRITABLE",
+ "Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr);
+ }
+
+# check for DEVICE_ATTR uses that could be DEVICE_ATTR_<FOO>
+# and whether or not function naming is typical and if
+# DEVICE_ATTR permissions uses are unusual too
+ if ($perl_version_ok &&
+ defined $stat &&
+ $stat =~ /\bDEVICE_ATTR\s*\(\s*(\w+)\s*,\s*\(?\s*(\s*(?:${multi_mode_perms_string_search}|0[0-7]{3,3})\s*)\s*\)?\s*,\s*(\w+)\s*,\s*(\w+)\s*\)/) {
+ my $var = $1;
+ my $perms = $2;
+ my $show = $3;
+ my $store = $4;
+ my $octal_perms = perms_to_octal($perms);
+ if ($show =~ /^${var}_show$/ &&
+ $store =~ /^${var}_store$/ &&
+ $octal_perms eq "0644") {
+ if (WARN("DEVICE_ATTR_RW",
+ "Use DEVICE_ATTR_RW\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/\bDEVICE_ATTR\s*\(\s*$var\s*,\s*\Q$perms\E\s*,\s*$show\s*,\s*$store\s*\)/DEVICE_ATTR_RW(${var})/;
+ }
+ } elsif ($show =~ /^${var}_show$/ &&
+ $store =~ /^NULL$/ &&
+ $octal_perms eq "0444") {
+ if (WARN("DEVICE_ATTR_RO",
+ "Use DEVICE_ATTR_RO\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/\bDEVICE_ATTR\s*\(\s*$var\s*,\s*\Q$perms\E\s*,\s*$show\s*,\s*NULL\s*\)/DEVICE_ATTR_RO(${var})/;
+ }
+ } elsif ($show =~ /^NULL$/ &&
+ $store =~ /^${var}_store$/ &&
+ $octal_perms eq "0200") {
+ if (WARN("DEVICE_ATTR_WO",
+ "Use DEVICE_ATTR_WO\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/\bDEVICE_ATTR\s*\(\s*$var\s*,\s*\Q$perms\E\s*,\s*NULL\s*,\s*$store\s*\)/DEVICE_ATTR_WO(${var})/;
+ }
+ } elsif ($octal_perms eq "0644" ||
+ $octal_perms eq "0444" ||
+ $octal_perms eq "0200") {
+ my $newshow = "$show";
+ $newshow = "${var}_show" if ($show ne "NULL" && $show ne "${var}_show");
+ my $newstore = $store;
+ $newstore = "${var}_store" if ($store ne "NULL" && $store ne "${var}_store");
+ my $rename = "";
+ if ($show ne $newshow) {
+ $rename .= " '$show' to '$newshow'";
+ }
+ if ($store ne $newstore) {
+ $rename .= " '$store' to '$newstore'";
+ }
+ WARN("DEVICE_ATTR_FUNCTIONS",
+ "Consider renaming function(s)$rename\n" . $herecurr);
+ } else {
+ WARN("DEVICE_ATTR_PERMS",
+ "DEVICE_ATTR unusual permissions '$perms' used\n" . $herecurr);
+ }
+ }
+
+# Mode permission misuses where it seems decimal should be octal
+# This uses a shortcut match to avoid unnecessary uses of a slow foreach loop
+# o Ignore module_param*(...) uses with a decimal 0 permission as that has a
+# specific definition of not visible in sysfs.
+# o Ignore proc_create*(...) uses with a decimal 0 permission as that means
+# use the default permissions
+ if ($perl_version_ok &&
+ defined $stat &&
+ $line =~ /$mode_perms_search/) {
+ foreach my $entry (@mode_permission_funcs) {
+ my $func = $entry->[0];
+ my $arg_pos = $entry->[1];
+
+ my $lc = $stat =~ tr@\n@@;
+ $lc = $lc + $linenr;
+ my $stat_real = get_stat_real($linenr, $lc);
+
+ my $skip_args = "";
+ if ($arg_pos > 1) {
+ $arg_pos--;
+ $skip_args = "(?:\\s*$FuncArg\\s*,\\s*){$arg_pos,$arg_pos}";
+ }
+ my $test = "\\b$func\\s*\\(${skip_args}($FuncArg(?:\\|\\s*$FuncArg)*)\\s*[,\\)]";
+ if ($stat =~ /$test/) {
+ my $val = $1;
+ $val = $6 if ($skip_args ne "");
+ if (!($func =~ /^(?:module_param|proc_create)/ && $val eq "0") &&
+ (($val =~ /^$Int$/ && $val !~ /^$Octal$/) ||
+ ($val =~ /^$Octal$/ && length($val) ne 4))) {
+ ERROR("NON_OCTAL_PERMISSIONS",
+ "Use 4 digit octal (0777) not decimal permissions\n" . "$here\n" . $stat_real);
+ }
+ if ($val =~ /^$Octal$/ && (oct($val) & 02)) {
+ ERROR("EXPORTED_WORLD_WRITABLE",
+ "Exporting writable files is usually an error. Consider more restrictive permissions.\n" . "$here\n" . $stat_real);
+ }
+ }
+ }
+ }
+
+# check for uses of S_<PERMS> that could be octal for readability
+ while ($line =~ m{\b($multi_mode_perms_string_search)\b}g) {
+ my $oval = $1;
+ my $octal = perms_to_octal($oval);
+ if (WARN("SYMBOLIC_PERMS",
+ "Symbolic permissions '$oval' are not preferred. Consider using octal permissions '$octal'.\n" . $herecurr) &&
+ $fix) {
+ $fixed[$fixlinenr] =~ s/\Q$oval\E/$octal/;
+ }
+ }
+
+# validate content of MODULE_LICENSE against list from include/linux/module.h
+ if ($line =~ /\bMODULE_LICENSE\s*\(\s*($String)\s*\)/) {
+ my $extracted_string = get_quoted_string($line, $rawline);
+ my $valid_licenses = qr{
+ GPL|
+ GPL\ v2|
+ GPL\ and\ additional\ rights|
+ Dual\ BSD/GPL|
+ Dual\ MIT/GPL|
+ Dual\ MPL/GPL|
+ Proprietary
+ }x;
+ if ($extracted_string !~ /^"(?:$valid_licenses)"$/x) {
+ WARN("MODULE_LICENSE",
+ "unknown module license " . $extracted_string . "\n" . $herecurr);
+ }
+ }
+ }
+
+ # If we have no input at all, then there is nothing to report on
+ # so just keep quiet.
+ if ($#rawlines == -1) {
+ exit(0);
+ }
+
+ # In mailback mode only produce a report in the negative, for
+ # things that appear to be patches.
+ if ($mailback && ($clean == 1 || !$is_patch)) {
+ exit(0);
+ }
+
+ # This is not a patch, and we are are in 'no-patch' mode so
+ # just keep quiet.
+ if (!$chk_patch && !$is_patch) {
+ exit(0);
+ }
+
+ if (!$is_patch && $filename !~ /cover-letter\.patch$/) {
+ ERROR("NOT_UNIFIED_DIFF",
+ "Does not appear to be a unified-diff format patch\n");
+ }
+ if ($is_patch && $has_commit_log && $chk_signoff) {
+ if ($signoff == 0) {
+ ERROR("MISSING_SIGN_OFF",
+ "Missing Signed-off-by: line(s)\n");
+ } elsif (!$authorsignoff) {
+ WARN("NO_AUTHOR_SIGN_OFF",
+ "Missing Signed-off-by: line by nominal patch author '$author'\n");
+ }
+ }
+
+ print report_dump();
+ if ($summary && !($clean == 1 && $quiet == 1)) {
+ print "$filename " if ($summary_file);
+ print "total: $cnt_error errors, $cnt_warn warnings, " .
+ (($check)? "$cnt_chk checks, " : "") .
+ "$cnt_lines lines checked\n";
+ }
+
+ if ($quiet == 0) {
+ # If there were any defects found and not already fixing them
+ if (!$clean and !$fix) {
+ print << "EOM"
+
+NOTE: For some of the reported defects, checkpatch may be able to
+ mechanically convert to the typical style using --fix or --fix-inplace.
+EOM
+ }
+ # If there were whitespace errors which cleanpatch can fix
+ # then suggest that.
+ if ($rpt_cleaners) {
+ $rpt_cleaners = 0;
+ print << "EOM"
+
+NOTE: Whitespace errors detected.
+ You may wish to use scripts/cleanpatch or scripts/cleanfile
+EOM
+ }
+ }
+
+ if ($clean == 0 && $fix &&
+ ("@rawlines" ne "@fixed" ||
+ $#fixed_inserted >= 0 || $#fixed_deleted >= 0)) {
+ my $newfile = $filename;
+ $newfile .= ".EXPERIMENTAL-checkpatch-fixes" if (!$fix_inplace);
+ my $linecount = 0;
+ my $f;
+
+ @fixed = fix_inserted_deleted_lines(\@fixed, \@fixed_inserted, \@fixed_deleted);
+
+ open($f, '>', $newfile)
+ or die "$P: Can't open $newfile for write\n";
+ foreach my $fixed_line (@fixed) {
+ $linecount++;
+ if ($file) {
+ if ($linecount > 3) {
+ $fixed_line =~ s/^\+//;
+ print $f $fixed_line . "\n";
+ }
+ } else {
+ print $f $fixed_line . "\n";
+ }
+ }
+ close($f);
+
+ if (!$quiet) {
+ print << "EOM";
+
+Wrote EXPERIMENTAL --fix correction(s) to '$newfile'
+
+Do _NOT_ trust the results written to this file.
+Do _NOT_ submit these changes without inspecting them for correctness.
+
+This EXPERIMENTAL file is simply a convenience to help rewrite patches.
+No warranties, expressed or implied...
+EOM
+ }
+ }
+
+ if ($quiet == 0) {
+ print "\n";
+ if ($clean == 1) {
+ print "$vname has no obvious style problems and is ready for submission.\n";
+ } else {
+ print "$vname has style problems, please review.\n";
+ }
+ }
+ return $clean;
+}
diff --git a/Checkstyle/checkstyle b/Checkstyle/checkstyle
new file mode 100755
index 0000000..02cfad2
--- /dev/null
+++ b/Checkstyle/checkstyle
@@ -0,0 +1,52 @@
+#!/bin/bash
+################################################################################
+#
+# Author: Alejandro Colomar Andrés
+#
+# This script checks the style in all files of type (.c .cpp .h .hpp) in the
+# selected dirs.
+#
+
+
+################################################################################
+# variables #
+################################################################################
+dirs=(
+ ../
+)
+
+
+################################################################################
+# functions #
+################################################################################
+check_style()
+{
+
+ ./checkpatch.pl --show-types --no-tree -f $1 \
+ --ignore SPDX_LICENSE_TAG,IF_0,SPACING,BRACKET_SPACE
+}
+
+find_source_files()
+{
+
+ source_files=$(find $1 -type f \( -iname \*.c -o -iname \*.h -o -iname \*.cpp -o -iname \*.hpp \))
+}
+
+
+################################################################################
+# main #
+################################################################################
+for i in ${dirs[*]}
+do
+ find_source_files ${i}
+
+ for j in ${source_files}
+ do
+ check_style ${j}
+ done
+done
+
+
+################################################################################
+# end of file #
+################################################################################
diff --git a/Checkstyle/spelling.txt b/Checkstyle/spelling.txt
new file mode 100644
index 0000000..517d0c3
--- /dev/null
+++ b/Checkstyle/spelling.txt
@@ -0,0 +1,1344 @@
+# Originally from Debian's Lintian tool. Various false positives have been
+# removed, and various additions have been made as they've been discovered
+# in the kernel source.
+#
+# License: GPLv2
+#
+# The format of each line is:
+# mistake||correction
+#
+abandonning||abandoning
+abigious||ambiguous
+abitrate||arbitrate
+abord||abort
+aboslute||absolute
+abov||above
+abreviated||abbreviated
+absense||absence
+absolut||absolute
+absoulte||absolute
+acccess||access
+acceess||access
+acceleratoin||acceleration
+accelleration||acceleration
+accesing||accessing
+accesnt||accent
+accessable||accessible
+accesss||access
+accidentaly||accidentally
+accidentually||accidentally
+acclerated||accelerated
+accoding||according
+accomodate||accommodate
+accomodates||accommodates
+accordign||according
+accoring||according
+accout||account
+accquire||acquire
+accquired||acquired
+accross||across
+acessable||accessible
+acess||access
+achitecture||architecture
+acient||ancient
+acitions||actions
+acitve||active
+acknowldegement||acknowledgment
+acknowledgement||acknowledgment
+ackowledge||acknowledge
+ackowledged||acknowledged
+acording||according
+activete||activate
+actived||activated
+actualy||actually
+acumulating||accumulating
+acumulator||accumulator
+adapater||adapter
+addional||additional
+additionaly||additionally
+additonal||additional
+addres||address
+adddress||address
+addreses||addresses
+addresss||address
+addrress||address
+aditional||additional
+aditionally||additionally
+aditionaly||additionally
+adminstrative||administrative
+adress||address
+adresses||addresses
+adrresses||addresses
+advertisment||advertisement
+adviced||advised
+afecting||affecting
+againt||against
+agaist||against
+aggreataon||aggregation
+aggreation||aggregation
+albumns||albums
+alegorical||allegorical
+algined||aligned
+algorith||algorithm
+algorithmical||algorithmically
+algoritm||algorithm
+algoritms||algorithms
+algorrithm||algorithm
+algorritm||algorithm
+aligment||alignment
+alignement||alignment
+allign||align
+alligned||aligned
+alllocate||allocate
+alloated||allocated
+allocatote||allocate
+allocatrd||allocated
+allocte||allocate
+allpication||application
+alocate||allocate
+alogirhtms||algorithms
+alogrithm||algorithm
+alot||a lot
+alow||allow
+alows||allows
+altough||although
+alue||value
+ambigious||ambiguous
+amoung||among
+amout||amount
+amplifer||amplifier
+an union||a union
+an user||a user
+an userspace||a userspace
+an one||a one
+analysator||analyzer
+ang||and
+anniversery||anniversary
+annoucement||announcement
+anomolies||anomalies
+anomoly||anomaly
+anway||anyway
+aplication||application
+appearence||appearance
+applicaion||application
+appliction||application
+applictions||applications
+applys||applies
+appplications||applications
+appropiate||appropriate
+appropriatly||appropriately
+approriate||appropriate
+approriately||appropriately
+apropriate||appropriate
+aquainted||acquainted
+aquired||acquired
+aquisition||acquisition
+arbitary||arbitrary
+architechture||architecture
+arguement||argument
+arguements||arguments
+aritmetic||arithmetic
+arne't||aren't
+arraival||arrival
+artifical||artificial
+artillary||artillery
+asign||assign
+asser||assert
+assertation||assertion
+assiged||assigned
+assigment||assignment
+assigments||assignments
+assistent||assistant
+assocation||association
+associcated||associated
+assotiated||associated
+asssert||assert
+assum||assume
+assumtpion||assumption
+asuming||assuming
+asycronous||asynchronous
+asynchnous||asynchronous
+asynchromous||asynchronous
+asymetric||asymmetric
+asymmeric||asymmetric
+atomatically||automatically
+atomicly||atomically
+atempt||attempt
+attachement||attachment
+attched||attached
+attemps||attempts
+attemping||attempting
+attruibutes||attributes
+authentification||authentication
+automaticaly||automatically
+automaticly||automatically
+automatize||automate
+automatized||automated
+automatizes||automates
+autonymous||autonomous
+auxillary||auxiliary
+auxilliary||auxiliary
+avaiable||available
+avaible||available
+availabe||available
+availabled||available
+availablity||availability
+availaible||available
+availale||available
+availavility||availability
+availble||available
+availiable||available
+availible||available
+avalable||available
+avaliable||available
+aysnc||async
+backgroud||background
+backword||backward
+backwords||backwards
+bahavior||behavior
+bakup||backup
+baloon||balloon
+baloons||balloons
+bandwith||bandwidth
+banlance||balance
+batery||battery
+beacuse||because
+becasue||because
+becomming||becoming
+becuase||because
+beeing||being
+befor||before
+begining||beginning
+beter||better
+betweeen||between
+bianries||binaries
+bitmast||bitmask
+boardcast||broadcast
+borad||board
+boundry||boundary
+brievely||briefly
+broadcat||broadcast
+bufufer||buffer
+cacluated||calculated
+caculate||calculate
+caculation||calculation
+cadidate||candidate
+calender||calendar
+calescing||coalescing
+calle||called
+callibration||calibration
+calucate||calculate
+calulate||calculate
+cancelation||cancellation
+cancle||cancel
+capabilites||capabilities
+capabilty||capability
+capabitilies||capabilities
+capatibilities||capabilities
+capapbilities||capabilities
+caputure||capture
+carefuly||carefully
+cariage||carriage
+catagory||category
+cehck||check
+challange||challenge
+challanges||challenges
+chache||cache
+chanell||channel
+changable||changeable
+chanined||chained
+channle||channel
+channnel||channel
+charachter||character
+charachters||characters
+charactor||character
+charater||character
+charaters||characters
+charcter||character
+chcek||check
+chck||check
+checksumed||checksummed
+checksuming||checksumming
+childern||children
+childs||children
+chiled||child
+chked||checked
+chnage||change
+chnages||changes
+chnnel||channel
+choosen||chosen
+chouse||chose
+circumvernt||circumvent
+claread||cleared
+clared||cleared
+closeing||closing
+clustred||clustered
+coexistance||coexistence
+collapsable||collapsible
+colorfull||colorful
+comand||command
+comit||commit
+commerical||commercial
+comming||coming
+comminucation||communication
+commited||committed
+commiting||committing
+committ||commit
+commoditiy||commodity
+comsume||consume
+comsumer||consumer
+comsuming||consuming
+compability||compatibility
+compaibility||compatibility
+compatability||compatibility
+compatable||compatible
+compatibiliy||compatibility
+compatibilty||compatibility
+compatiblity||compatibility
+competion||completion
+compilant||compliant
+compleatly||completely
+completition||completion
+completly||completely
+complient||compliant
+componnents||components
+compoment||component
+compres||compress
+compresion||compression
+comression||compression
+comunication||communication
+conbination||combination
+conditionaly||conditionally
+conected||connected
+conector||connector
+connecetd||connected
+configuartion||configuration
+configuation||configuration
+configuratoin||configuration
+configuraton||configuration
+configuretion||configuration
+configutation||configuration
+conider||consider
+conjuction||conjunction
+connectinos||connections
+connnection||connection
+connnections||connections
+consistancy||consistency
+consistant||consistent
+containes||contains
+containts||contains
+contaisn||contains
+contant||contact
+contence||contents
+continious||continuous
+continous||continuous
+continously||continuously
+continueing||continuing
+contraints||constraints
+contruct||construct
+contol||control
+contoller||controller
+controled||controlled
+controler||controller
+controll||control
+contruction||construction
+contry||country
+conuntry||country
+convertion||conversion
+convertor||converter
+convienient||convenient
+convinient||convenient
+corected||corrected
+correponding||corresponding
+correponds||corresponds
+correspoding||corresponding
+cotrol||control
+cound||could
+couter||counter
+coutner||counter
+cryptocraphic||cryptographic
+cunter||counter
+curently||currently
+cylic||cyclic
+dafault||default
+deafult||default
+deamon||daemon
+decompres||decompress
+decsribed||described
+decription||description
+dectected||detected
+defailt||default
+defferred||deferred
+definate||definite
+definately||definitely
+defintion||definition
+defintions||definitions
+defualt||default
+defult||default
+deintializing||deinitializing
+deintialize||deinitialize
+deintialized||deinitialized
+deivce||device
+delared||declared
+delare||declare
+delares||declares
+delaring||declaring
+delemiter||delimiter
+demodualtor||demodulator
+demension||dimension
+dependancies||dependencies
+dependancy||dependency
+dependant||dependent
+depreacted||deprecated
+depreacte||deprecate
+desactivate||deactivate
+desciptor||descriptor
+desciptors||descriptors
+descripton||description
+descrition||description
+descritptor||descriptor
+desctiptor||descriptor
+desriptor||descriptor
+desriptors||descriptors
+destionation||destination
+destoried||destroyed
+destory||destroy
+destoryed||destroyed
+destorys||destroys
+destroied||destroyed
+detabase||database
+deteced||detected
+develope||develop
+developement||development
+developped||developed
+developpement||development
+developper||developer
+developpment||development
+deveolpment||development
+devided||divided
+deviece||device
+diable||disable
+dictionnary||dictionary
+didnt||didn't
+diferent||different
+differrence||difference
+diffrent||different
+differenciate||differentiate
+diffrentiate||differentiate
+difinition||definition
+dimesions||dimensions
+diplay||display
+directon||direction
+direectly||directly
+diregard||disregard
+disassocation||disassociation
+disapear||disappear
+disapeared||disappeared
+disappared||disappeared
+disbale||disable
+disbaled||disabled
+disble||disable
+disbled||disabled
+disconnet||disconnect
+discontinous||discontinuous
+disharge||discharge
+dispertion||dispersion
+dissapears||disappears
+distiction||distinction
+divisable||divisible
+divsiors||divisors
+docuentation||documentation
+documantation||documentation
+documentaion||documentation
+documment||document
+doesnt||doesn't
+dorp||drop
+dosen||doesn
+downlad||download
+downlads||downloads
+druing||during
+dynmaic||dynamic
+eanable||enable
+easilly||easily
+ecspecially||especially
+edditable||editable
+editting||editing
+efective||effective
+efficently||efficiently
+ehther||ether
+eigth||eight
+elementry||elementary
+eletronic||electronic
+embeded||embedded
+enabledi||enabled
+enchanced||enhanced
+encorporating||incorporating
+encrupted||encrypted
+encrypiton||encryption
+encryptio||encryption
+endianess||endianness
+enhaced||enhanced
+enlightnment||enlightenment
+entrys||entries
+enocded||encoded
+enterily||entirely
+enviroiment||environment
+enviroment||environment
+environement||environment
+environent||environment
+eqivalent||equivalent
+equiped||equipped
+equivelant||equivalent
+equivilant||equivalent
+eror||error
+errorr||error
+estbalishment||establishment
+etsablishment||establishment
+etsbalishment||establishment
+excecutable||executable
+exceded||exceeded
+excellant||excellent
+exeed||exceed
+existance||existence
+existant||existent
+exixt||exist
+exlcude||exclude
+exlcusive||exclusive
+exmaple||example
+expecially||especially
+explicite||explicit
+explicitely||explicitly
+explict||explicit
+explictely||explicitly
+explictly||explicitly
+expresion||expression
+exprimental||experimental
+extened||extended
+extensability||extensibility
+extention||extension
+extenstion||extension
+extracter||extractor
+faield||failed
+falied||failed
+faild||failed
+failer||failure
+faill||fail
+failied||failed
+faillure||failure
+failue||failure
+failuer||failure
+failng||failing
+faireness||fairness
+falied||failed
+faliure||failure
+fallbck||fallback
+familar||familiar
+fatser||faster
+feauture||feature
+feautures||features
+fetaure||feature
+fetaures||features
+fileystem||filesystem
+fimware||firmware
+firware||firmware
+finanize||finalize
+findn||find
+finilizes||finalizes
+finsih||finish
+flusing||flushing
+folloing||following
+followign||following
+followings||following
+follwing||following
+fonud||found
+forseeable||foreseeable
+forse||force
+fortan||fortran
+forwardig||forwarding
+frambuffer||framebuffer
+framming||framing
+framwork||framework
+frequncy||frequency
+frome||from
+fucntion||function
+fuction||function
+fuctions||functions
+funcation||function
+funcion||function
+functionallity||functionality
+functionaly||functionally
+functionnality||functionality
+functonality||functionality
+funtion||function
+funtions||functions
+furthur||further
+futhermore||furthermore
+futrue||future
+gaurenteed||guaranteed
+generiously||generously
+genereate||generate
+genereted||generated
+genric||generic
+globel||global
+grabing||grabbing
+grahical||graphical
+grahpical||graphical
+grapic||graphic
+grranted||granted
+guage||gauge
+guarenteed||guaranteed
+guarentee||guarantee
+halfs||halves
+hander||handler
+handfull||handful
+hanlde||handle
+hanled||handled
+happend||happened
+harware||hardware
+heirarchically||hierarchically
+helpfull||helpful
+hybernate||hibernate
+hierachy||hierarchy
+hierarchie||hierarchy
+homogenous||homogeneous
+howver||however
+hsould||should
+hypervior||hypervisor
+hypter||hyper
+identidier||identifier
+iligal||illegal
+illigal||illegal
+illgal||illegal
+iomaped||iomapped
+imblance||imbalance
+immeadiately||immediately
+immedaite||immediate
+immediatelly||immediately
+immediatly||immediately
+immidiate||immediate
+impelentation||implementation
+impementated||implemented
+implemantation||implementation
+implemenation||implementation
+implementaiton||implementation
+implementated||implemented
+implemention||implementation
+implementd||implemented
+implemetation||implementation
+implemntation||implementation
+implentation||implementation
+implmentation||implementation
+implmenting||implementing
+incative||inactive
+incomming||incoming
+incompatabilities||incompatibilities
+incompatable||incompatible
+inconsistant||inconsistent
+increas||increase
+incremeted||incremented
+incrment||increment
+indendation||indentation
+indended||intended
+independant||independent
+independantly||independently
+independed||independent
+indiate||indicate
+indicat||indicate
+inexpect||inexpected
+infomation||information
+informatiom||information
+informations||information
+informtion||information
+infromation||information
+ingore||ignore
+inital||initial
+initalized||initialized
+initalised||initialized
+initalise||initialize
+initalize||initialize
+initation||initiation
+initators||initiators
+initialiazation||initialization
+initializiation||initialization
+initialze||initialize
+initialzed||initialized
+initilization||initialization
+initilize||initialize
+inofficial||unofficial
+inrerface||interface
+insititute||institute
+instal||install
+instanciate||instantiate
+instanciated||instantiated
+inteface||interface
+integreated||integrated
+integrety||integrity
+integrey||integrity
+intendet||intended
+intented||intended
+interanl||internal
+interchangable||interchangeable
+interferring||interfering
+interger||integer
+intermittant||intermittent
+internel||internal
+interoprability||interoperability
+interuupt||interrupt
+interrface||interface
+interrrupt||interrupt
+interrup||interrupt
+interrups||interrupts
+interruptted||interrupted
+interupted||interrupted
+interupt||interrupt
+intial||initial
+intialisation||initialisation
+intialised||initialised
+intialise||initialise
+intialization||initialization
+intialized||initialized
+intialize||initialize
+intregral||integral
+intrrupt||interrupt
+intterrupt||interrupt
+intuative||intuitive
+inavlid||invalid
+invaid||invalid
+invald||invalid
+invalde||invalid
+invalide||invalid
+invalidiate||invalidate
+invalud||invalid
+invididual||individual
+invokation||invocation
+invokations||invocations
+irrelevent||irrelevant
+isnt||isn't
+isssue||issue
+iternations||iterations
+itertation||iteration
+itslef||itself
+jave||java
+jeffies||jiffies
+juse||just
+jus||just
+kown||known
+langage||language
+langauage||language
+langauge||language
+langugage||language
+lauch||launch
+layed||laid
+legnth||length
+leightweight||lightweight
+lengh||length
+lenght||length
+lenth||length
+lesstiff||lesstif
+libaries||libraries
+libary||library
+librairies||libraries
+libraris||libraries
+licenceing||licencing
+loggging||logging
+loggin||login
+logile||logfile
+loobpack||loopback
+loosing||losing
+losted||lost
+machinary||machinery
+maintainance||maintenance
+maintainence||maintenance
+maintan||maintain
+makeing||making
+mailformed||malformed
+malplaced||misplaced
+malplace||misplace
+managable||manageable
+managment||management
+mangement||management
+manoeuvering||maneuvering
+mappping||mapping
+matchs||matches
+mathimatical||mathematical
+mathimatic||mathematic
+mathimatics||mathematics
+maxium||maximum
+mechamism||mechanism
+meetign||meeting
+ment||meant
+mergable||mergeable
+mesage||message
+messags||messages
+messgaes||messages
+messsage||message
+messsages||messages
+micropone||microphone
+microprocesspr||microprocessor
+migrateable||migratable
+milliseonds||milliseconds
+minium||minimum
+minimam||minimum
+minumum||minimum
+misalinged||misaligned
+miscelleneous||miscellaneous
+misformed||malformed
+mispelled||misspelled
+mispelt||misspelt
+mising||missing
+mismactch||mismatch
+missmanaged||mismanaged
+missmatch||mismatch
+miximum||maximum
+mmnemonic||mnemonic
+mnay||many
+modfiy||modify
+modulues||modules
+momery||memory
+memomry||memory
+monochorome||monochrome
+monochromo||monochrome
+monocrome||monochrome
+mopdule||module
+mroe||more
+mulitplied||multiplied
+multidimensionnal||multidimensional
+multple||multiple
+mumber||number
+muticast||multicast
+mutilcast||multicast
+mutiple||multiple
+mutli||multi
+nams||names
+navagating||navigating
+nead||need
+neccecary||necessary
+neccesary||necessary
+neccessary||necessary
+necesary||necessary
+neded||needed
+negaive||negative
+negoitation||negotiation
+negotation||negotiation
+nerver||never
+nescessary||necessary
+nessessary||necessary
+noticable||noticeable
+notications||notifications
+notifed||notified
+numebr||number
+numner||number
+obtaion||obtain
+obusing||abusing
+occassionally||occasionally
+occationally||occasionally
+occurance||occurrence
+occurances||occurrences
+occured||occurred
+occurence||occurrence
+occure||occurred
+occured||occurred
+occuring||occurring
+offet||offset
+offloded||offloaded
+omited||omitted
+omiting||omitting
+omitt||omit
+ommiting||omitting
+ommitted||omitted
+onself||oneself
+ony||only
+operatione||operation
+opertaions||operations
+optionnal||optional
+optmizations||optimizations
+orientatied||orientated
+orientied||oriented
+orignal||original
+otherise||otherwise
+ouput||output
+oustanding||outstanding
+overaall||overall
+overhread||overhead
+overlaping||overlapping
+overide||override
+overrided||overridden
+overriden||overridden
+overun||overrun
+overwritting||overwriting
+overwriten||overwritten
+pacakge||package
+pachage||package
+packacge||package
+packege||package
+packge||package
+packtes||packets
+pakage||package
+pallette||palette
+paln||plan
+paramameters||parameters
+paramaters||parameters
+paramater||parameter
+parametes||parameters
+parametised||parametrised
+paramter||parameter
+paramters||parameters
+parmaters||parameters
+particuarly||particularly
+particularily||particularly
+partiton||partition
+pased||passed
+passin||passing
+pathes||paths
+pecularities||peculiarities
+peformance||performance
+peforming||performing
+peice||piece
+pendantic||pedantic
+peprocessor||preprocessor
+perfoming||performing
+permissons||permissions
+peroid||period
+persistance||persistence
+persistant||persistent
+plalform||platform
+platfoem||platform
+platfrom||platform
+plattform||platform
+pleaes||please
+ploting||plotting
+plugable||pluggable
+poinnter||pointer
+pointeur||pointer
+poiter||pointer
+posible||possible
+positon||position
+possibilites||possibilities
+powerfull||powerful
+preamle||preamble
+preample||preamble
+preapre||prepare
+preceeded||preceded
+preceeding||preceding
+preceed||precede
+precendence||precedence
+precission||precision
+preemptable||preemptible
+prefered||preferred
+prefferably||preferably
+premption||preemption
+prepaired||prepared
+preperation||preparation
+pressre||pressure
+primative||primitive
+princliple||principle
+priorty||priority
+privilaged||privileged
+privilage||privilege
+priviledge||privilege
+priviledges||privileges
+probaly||probably
+procceed||proceed
+proccesors||processors
+procesed||processed
+proces||process
+procesing||processing
+processessing||processing
+processess||processes
+processpr||processor
+processsed||processed
+processsing||processing
+procteted||protected
+prodecure||procedure
+progams||programs
+progess||progress
+programers||programmers
+programm||program
+programms||programs
+progresss||progress
+promiscous||promiscuous
+promps||prompts
+pronnounced||pronounced
+prononciation||pronunciation
+pronouce||pronounce
+pronunce||pronounce
+propery||property
+propigate||propagate
+propigation||propagation
+propogate||propagate
+prosess||process
+protable||portable
+protcol||protocol
+protecion||protection
+protocoll||protocol
+promixity||proximity
+psudo||pseudo
+psuedo||pseudo
+psychadelic||psychedelic
+pwoer||power
+quering||querying
+randomally||randomly
+raoming||roaming
+reasearcher||researcher
+reasearchers||researchers
+reasearch||research
+recepient||recipient
+receving||receiving
+recieved||received
+recieve||receive
+reciever||receiver
+recieves||receives
+recogniced||recognised
+recognizeable||recognizable
+recommanded||recommended
+recyle||recycle
+redircet||redirect
+redirectrion||redirection
+redundacy||redundancy
+reename||rename
+refcounf||refcount
+refence||reference
+refered||referred
+referenace||reference
+refering||referring
+refernces||references
+refernnce||reference
+refrence||reference
+registerd||registered
+registeration||registration
+registeresd||registered
+registerred||registered
+registes||registers
+registraration||registration
+regsiter||register
+regster||register
+regualar||regular
+reguator||regulator
+regulamentations||regulations
+reigstration||registration
+releated||related
+relevent||relevant
+remoote||remote
+remore||remote
+removeable||removable
+repectively||respectively
+replacable||replaceable
+replacments||replacements
+replys||replies
+reponse||response
+representaion||representation
+reqeust||request
+requestied||requested
+requiere||require
+requirment||requirement
+requred||required
+requried||required
+requst||request
+reregisteration||reregistration
+reseting||resetting
+reseverd||reserved
+resizeable||resizable
+resouce||resource
+resouces||resources
+resoures||resources
+responce||response
+ressizes||resizes
+ressource||resource
+ressources||resources
+restesting||retesting
+retransmited||retransmitted
+retreived||retrieved
+retreive||retrieve
+retrive||retrieve
+retuned||returned
+reudce||reduce
+reuest||request
+reuqest||request
+reutnred||returned
+revsion||revision
+rmeoved||removed
+rmeove||remove
+rmeoves||removes
+rountine||routine
+routins||routines
+rquest||request
+runing||running
+runned||ran
+runnning||running
+runtine||runtime
+sacrifying||sacrificing
+safly||safely
+safty||safety
+savable||saveable
+scaleing||scaling
+scaned||scanned
+scaning||scanning
+scarch||search
+seach||search
+searchs||searches
+secquence||sequence
+secund||second
+segement||segment
+semaphone||semaphore
+senario||scenario
+senarios||scenarios
+sentivite||sensitive
+separatly||separately
+sepcify||specify
+sepc||spec
+seperated||separated
+seperately||separately
+seperate||separate
+seperatly||separately
+seperator||separator
+sepperate||separate
+seqeunce||sequence
+seqeuncer||sequencer
+seqeuencer||sequencer
+sequece||sequence
+sequencial||sequential
+serveral||several
+servive||service
+setts||sets
+settting||setting
+shotdown||shutdown
+shoud||should
+shouldnt||shouldn't
+shoule||should
+shrinked||shrunk
+siginificantly||significantly
+signabl||signal
+similary||similarly
+similiar||similar
+simlar||similar
+simliar||similar
+simpified||simplified
+singaled||signaled
+singal||signal
+singed||signed
+sleeped||slept
+softwares||software
+speach||speech
+specfic||specific
+speciefied||specified
+specifc||specific
+specifed||specified
+specificatin||specification
+specificaton||specification
+specifing||specifying
+specifiying||specifying
+speficied||specified
+speicify||specify
+speling||spelling
+spinlcok||spinlock
+spinock||spinlock
+splitted||split
+spreaded||spread
+spurrious||spurious
+sructure||structure
+stablilization||stabilization
+staically||statically
+staion||station
+standardss||standards
+standartization||standardization
+standart||standard
+staticly||statically
+stoped||stopped
+stoping||stopping
+stoppped||stopped
+straming||streaming
+struc||struct
+structres||structures
+stuct||struct
+strucuture||structure
+stucture||structure
+sturcture||structure
+subdirectoires||subdirectories
+suble||subtle
+substract||subtract
+submition||submission
+suceed||succeed
+succesfully||successfully
+succesful||successful
+successed||succeeded
+successfull||successful
+successfuly||successfully
+sucessfully||successfully
+sucess||success
+superflous||superfluous
+superseeded||superseded
+suplied||supplied
+suported||supported
+suport||support
+supportet||supported
+suppored||supported
+supportin||supporting
+suppoted||supported
+suppported||supported
+suppport||support
+supress||suppress
+surpressed||suppressed
+surpresses||suppresses
+susbsystem||subsystem
+suspeneded||suspended
+suspsend||suspend
+suspicously||suspiciously
+swaping||swapping
+switchs||switches
+swith||switch
+swithable||switchable
+swithc||switch
+swithced||switched
+swithcing||switching
+swithed||switched
+swithing||switching
+swtich||switch
+symetric||symmetric
+synax||syntax
+synchonized||synchronized
+synchronuously||synchronously
+syncronize||synchronize
+syncronized||synchronized
+syncronizing||synchronizing
+syncronus||synchronous
+syste||system
+sytem||system
+sythesis||synthesis
+taht||that
+tansmit||transmit
+targetted||targeted
+targetting||targeting
+taskelt||tasklet
+teh||the
+temorary||temporary
+temproarily||temporarily
+thead||thread
+therfore||therefore
+thier||their
+threds||threads
+threshhold||threshold
+thresold||threshold
+throught||through
+troughput||throughput
+thses||these
+tiggers||triggers
+tiggered||triggered
+tipically||typically
+timeing||timing
+timout||timeout
+tmis||this
+torerable||tolerable
+traking||tracking
+tramsmitted||transmitted
+tramsmit||transmit
+tranasction||transaction
+tranfer||transfer
+transciever||transceiver
+transferd||transferred
+transfered||transferred
+transfering||transferring
+transision||transition
+transmittd||transmitted
+transormed||transformed
+trasfer||transfer
+trasmission||transmission
+treshold||threshold
+trigerred||triggered
+trigerring||triggering
+trun||turn
+tunning||tuning
+ture||true
+tyep||type
+udpate||update
+uesd||used
+uknown||unknown
+usupported||unsupported
+uncommited||uncommitted
+unconditionaly||unconditionally
+underun||underrun
+unecessary||unnecessary
+unexecpted||unexpected
+unexepected||unexpected
+unexpcted||unexpected
+unexpectd||unexpected
+unexpeted||unexpected
+unexpexted||unexpected
+unfortunatelly||unfortunately
+unifiy||unify
+uniterrupted||uninterrupted
+unintialized||uninitialized
+unkmown||unknown
+unknonw||unknown
+unknow||unknown
+unkown||unknown
+unamed||unnamed
+uneeded||unneeded
+unneded||unneeded
+unneccecary||unnecessary
+unneccesary||unnecessary
+unneccessary||unnecessary
+unnecesary||unnecessary
+unneedingly||unnecessarily
+unnsupported||unsupported
+unmached||unmatched
+unregester||unregister
+unresgister||unregister
+unrgesiter||unregister
+unsinged||unsigned
+unstabel||unstable
+unsolicitied||unsolicited
+unsuccessfull||unsuccessful
+unsuported||unsupported
+untill||until
+unuseful||useless
+upate||update
+usefule||useful
+usefull||useful
+usege||usage
+usera||users
+usualy||usually
+usupported||unsupported
+utilites||utilities
+utillities||utilities
+utilties||utilities
+utiltity||utility
+utitity||utility
+utitlty||utility
+vaid||valid
+vaild||valid
+valide||valid
+variantions||variations
+varible||variable
+varient||variant
+vaule||value
+verbse||verbose
+verisons||versions
+verison||version
+verson||version
+vicefersa||vice-versa
+virtal||virtual
+virtaul||virtual
+virtiual||virtual
+visiters||visitors
+vitual||virtual
+vunerable||vulnerable
+wakeus||wakeups
+wathdog||watchdog
+wating||waiting
+wiat||wait
+wether||whether
+whataver||whatever
+whcih||which
+whenver||whenever
+wheter||whether
+whe||when
+wierd||weird
+wiil||will
+wirte||write
+withing||within
+wnat||want
+workarould||workaround
+writeing||writing
+writting||writing
+zombe||zombie
+zomebie||zombie
diff --git a/Makefile b/Makefile
index e6b1aaa..f3bf5a4 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
-#!/usr/bin/make -f
+#! /usr/bin/make -f
VERSION = 2
-PATCHLEVEL = ~b5
-SUBLEVEL =
+PATCHLEVEL = 1
+SUBLEVEL = 0
EXTRAVERSION =
NAME =
@@ -66,7 +66,7 @@ export BUILD_VERBOSE
MAKEFLAGS += --no-print-directory
################################################################################
-PROGRAMVERSION = $(VERSION)$(if $(PATCHLEVEL),$(PATCHLEVEL)$(if $(SUBLEVEL),$(SUBLEVEL)))$(EXTRAVERSION)
+PROGRAMVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
export PROGRAMVERSION
################################################################################
@@ -75,68 +75,76 @@ export PROGRAMVERSION
MAIN_DIR = $(CURDIR)
LIBALX_DIR = $(CURDIR)/libalx/
-MODULES_DIR = $(CURDIR)/modules/
-TMP_DIR = $(CURDIR)/tmp/
+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 MODULES_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/
-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
-
-export BIN_NAME
################################################################################
# Make variables (CC, etc...)
- CC = gcc
- CXX = g++
- AS = as
- LD = ld
+ CC = gcc
+ CXX = g++
+ AS = as
+ AR = ar
+ LD = ld
+ SZ = size
export CC
export CXX
export AS
+export AR
export LD
+export SZ
################################################################################
# cflags
-CFLAGS_STD = -std=c11
+CFLAGS_STD = -std=c17
+CFLAGS_STD += -Wpedantic
CFLAGS_OPT = -O3
CFLAGS_OPT += -march=native
-CFLAGS_W = -Wno-format-truncation
-CFLAGS_W += -Wno-format-zero-length
+CFLAGS_W = -Wall
+CFLAGS_W += -Wextra
+CFLAGS_W += -Wstrict-prototypes
+CFLAGS_W += -Werror
+#CFLAGS_W += -Wno-error=format-truncation
+#CFLAGS_W += -Wno-error=unused-function
+#CFLAGS_W += -Wno-error=unused-parameter
CFLAGS_PKG = `pkg-config --cflags ncurses`
CFLAGS_PKG += `pkg-config --cflags opencv`
CFLAGS_PKG += `pkg-config --cflags zbar`
CFLAGS_PKG += `pkg-config --cflags tesseract`
CFLAGS_PKG += `pkg-config --cflags lept`
+CFLAGS_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_D = -D PROG_VERSION=\"$(PROGRAMVERSION)\"
+CFLAGS_D += -D INSTALL_SHARE_DIR=\"$(INSTALL_SHARE_DIR)\"
+CFLAGS_D += -D INSTALL_VAR_DIR=\"$(INSTALL_VAR_DIR)\"
CFLAGS = $(CFLAGS_STD)
CFLAGS += $(CFLAGS_OPT)
@@ -153,20 +161,23 @@ CXXFLAGS_STD = -std=c++17
CXXFLAGS_OPT = -O3
CXXFLAGS_OPT += -march=native
-CXXFLAGS_W = -Wno-format-truncation
-CXXFLAGS_W += -Wno-format-zero-length
+CXXFLAGS_W = -Wall
+CXXFLAGS_W += -Wextra
+CXXFLAGS_W += -Werror
+CXXFLAGS_W += -Wno-error=format-truncation
+CXXFLAGS_W += -Wno-error=unused-function
+CXXFLAGS_W += -Wno-error=unused-parameter
CXXFLAGS_PKG = `pkg-config --cflags ncurses`
CXXFLAGS_PKG += `pkg-config --cflags opencv`
CXXFLAGS_PKG += `pkg-config --cflags zbar`
CXXFLAGS_PKG += `pkg-config --cflags tesseract`
CXXFLAGS_PKG += `pkg-config --cflags lept`
+CXXFLAGS_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_D = -D PROG_VERSION=\"$(PROGRAMVERSION)\"
+CXXFLAGS_D += -D INSTALL_SHARE_DIR=\"$(INSTALL_SHARE_DIR)\"
+CXXFLAGS_D += -D INSTALL_VAR_DIR=\"$(INSTALL_VAR_DIR)\"
CXXFLAGS = $(CXXFLAGS_STD)
CXXFLAGS += $(CXXFLAGS_OPT)
@@ -189,77 +200,98 @@ LIBS = $(LIBS_PKG)
export LIBS
################################################################################
+# executables
+
+BIN_NAME = vision-artificial2
+
+export BIN_NAME
+
+################################################################################
# target: dependencies
# action
# That's the default target when none is given on the command line
PHONY := all
-all: binary
+all: bin
PHONY += libalx
libalx:
- $(Q)cd $(LIBALX_DIR) && $(MAKE) && cd ..
-
-PHONY += modules
-modules: libalx
- $(Q)cd $(MODULES_DIR) && $(MAKE) && cd ..
-
-PHONY += object
-object: modules libalx
- $(Q)cd $(TMP_DIR) && $(MAKE) && cd ..
-
-PHONY += binary
-binary: object
- $(Q)cd $(BIN_DIR) && $(MAKE) && cd ..
+ @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 += tmp
+tmp:
+ @echo " MAKE $@"
+ $(Q)$(MAKE) -C $(TMP_DIR)
+ @echo
+
+PHONY += bin
+bin: tmp libalx
+ @echo " MAKE $@"
+ $(Q)$(MAKE) -C $(BIN_DIR)
+ @echo
PHONY += install
install: uninstall
- @echo "Create $(INSTALL_BIN_DIR)/"
+ @echo " Install:"
+ @echo " MKDIR $(INSTALL_BIN_DIR)/"
$(Q)mkdir -p $(DESTDIR)/$(INSTALL_BIN_DIR)/
- @echo "Copy $(BIN_NAME)"
- $(Q)cp $(BIN_DIR)/$(BIN_NAME) $(DESTDIR)/$(INSTALL_BIN_DIR)/
- @echo ""
-
- @echo "Create $(INSTALL_SHARE_DIR)/$(SHARE_DIR)/"
- $(Q)mkdir -p $(DESTDIR)/$(INSTALL_SHARE_DIR)/$(SHARE_DIR)/
- @echo "Copy share/*"
- $(Q)cp -r ./share/* $(DESTDIR)/$(INSTALL_SHARE_DIR)/$(SHARE_DIR)/
- @echo ""
-
- @echo "Done"
- @echo ""
+ @echo " CP $(BIN_NAME)"
+ $(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
PHONY += uninstall
uninstall:
- $(Q)rm -f $(DESTDIR)/$(INSTALL_BIN_DIR)/$(BIN_NAME)
- $(Q)rm -f -r $(DESTDIR)/$(INSTALL_SHARE_DIR)/$(SHARE_DIR)/
- @echo "Clean old installations"
- @echo ""
+ @echo " Clean old installations:"
+ @echo " RM bin"
+ $(Q)rm -f $(DESTDIR)/$(INSTALL_BIN_DIR)/$(BIN_NAME)
+ @echo " RM -r $(INSTALL_SHARE_DIR)/vision-artificial/"
+ $(Q)rm -f -r $(DESTDIR)/$(INSTALL_SHARE_DIR)/vision-artificial/
+ @echo " Done"
+ @echo
PHONY += clean
clean:
- $(Q)cd $(LIBALX_DIR) && $(MAKE) clean && cd ..
- $(Q)cd $(MODULES_DIR) && $(MAKE) clean && cd ..
- $(Q)cd $(TMP_DIR) && $(MAKE) clean && cd ..
- $(Q)cd $(BIN_DIR) && $(MAKE) clean && cd ..
+ @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 += distclean
+distclean: clean
+ @echo " CLEAN libalx"
+ $(Q)$(MAKE) clean -C $(LIBALX_DIR)
+ @echo
PHONY += help
help:
@echo 'Cleaning targets:'
@echo ' clean - Remove all generated files'
- @echo ''
+ @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 ''
+ @echo
@echo ' make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build'
- @echo ''
+ @echo
@echo 'Execute "make" or "make all" to build all targets marked with [*] '
@echo 'For further info see the ./README file'
@@ -268,8 +300,6 @@ help:
.PHONY: $(PHONY)
-
-
################################################################################
######## End of file ###########################################################
################################################################################
diff --git a/bin/Makefile b/bin/Makefile
index 25156a9..d0b2d7b 100644
--- a/bin/Makefile
+++ b/bin/Makefile
@@ -1,42 +1,77 @@
-# -*- 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)
-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
+
+ALL = $(BIN_NAME) size
# static libs
-MAIN_LIB_LIBALX = -L $(LIBALX_LIB_DIR) -l alx
-STATIC_LIBS = $(MAIN_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)
- $(Q)$(CXX) $^ -o $@ $(STATIC_LIBS) $(LIBS)
- @echo " CXX $@"
- @echo ""
+$(BIN_NAME): $(OBJS) $(DEPS_LIBS)
+ @echo " CXX $@"
+ $(Q)$(CXX) $(OBJS) -o $@ $(STATIC_LIBS) $(LIBS)
+
+size: $(BIN_NAME)
+ @echo " SZ $(BIN_NAME)"
+ $(Q)$(SZ) $(BIN_NAME)
clean:
- $(Q)rm -f $(ALL)
- @echo "Clean binaries"
+ @echo " RM $(ALL)"
+ $(Q)rm -f $(ALL)
+
+################################################################################
+# Declare the contents of the .PHONY variable as phony.
+.PHONY: $(PHONY)
################################################################################
######## End of file ###########################################################
diff --git a/inc/vision-artificial/about/about.h b/inc/vision-artificial/about/about.h
new file mode 100644
index 0000000..4faa574
--- /dev/null
+++ b/inc/vision-artificial/about/about.h
@@ -0,0 +1,79 @@
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+#ifndef VA_ABOUT_ABOUT_H
+#define VA_ABOUT_ABOUT_H
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+#include <stddef.h>
+#include <stdio.h>
+
+
+/******************************************************************************
+ ******* macros ***************************************************************
+ ******************************************************************************/
+#define PROG_NAME "vision-artificial"
+#define PROG_YEAR "2018"
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+enum Share_File {
+ SHARE_COPYRIGHT,
+ SHARE_DISCLAIMER,
+ SHARE_HELP,
+ SHARE_LICENSE,
+ SHARE_USAGE
+};
+
+
+/******************************************************************************
+ ******* structs / unions *****************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+extern char share_path [FILENAME_MAX];
+
+
+/******************************************************************************
+ ******* extern functions *****************************************************
+ ******************************************************************************/
+void about_init (void);
+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 /* vision-artificial/about/about.h */
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/inc/vision-artificial/about/about.hpp b/inc/vision-artificial/about/about.hpp
new file mode 100644
index 0000000..1970a2b
--- /dev/null
+++ b/inc/vision-artificial/about/about.hpp
@@ -0,0 +1,84 @@
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+#ifndef VA_ABOUT_ABOUT_HPP
+#define VA_ABOUT_ABOUT_HPP
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+#include <cstddef>
+#include <cstdio>
+
+#include "libalx/base/stddef/restrict.hpp"
+
+
+/******************************************************************************
+ ******* macros ***************************************************************
+ ******************************************************************************/
+#define PROG_NAME "vision-artificial"
+#define PROG_YEAR "2018"
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+enum Share_File {
+ SHARE_COPYRIGHT,
+ SHARE_DISCLAIMER,
+ SHARE_HELP,
+ SHARE_LICENSE,
+ SHARE_USAGE
+};
+
+
+/******************************************************************************
+ ******* structs / unions *****************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+extern char share_path [FILENAME_MAX];
+
+
+/******************************************************************************
+ ******* extern functions *****************************************************
+ ******************************************************************************/
+extern "C"
+{
+void about_init (void);
+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) *********************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* static inline functions (definitions) ********************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+#endif /* vision-artificial/about/about.hpp */
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/modules/proc/inc/proc_resistor.hpp b/inc/vision-artificial/ctrl/start.h
index 9982e6f..c7daeff 100644
--- a/modules/proc/inc/proc_resistor.hpp
+++ b/inc/vision-artificial/ctrl/start.h
@@ -1,62 +1,64 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_PROC_RESISTOR_HPP
- # define VA_PROC_RESISTOR_HPP
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Proc_Resistor {
- RESISTOR_OK,
- RESISTOR_NOK_RESISTOR,
- RESISTOR_NOK_BANDS,
- RESISTOR_NOK_COLOR,
- RESISTOR_NOK_STD_VALUE,
- RESISTOR_NOK_TOLERANCE
- };
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-extern "C" {
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- int proc_resistor (void);
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-} /* extern "C" */
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* proc_resistor.hpp */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+#ifndef VA_CTRL_START_H
+#define VA_CTRL_START_H
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+enum Start_Mode {
+ START_FOO = 0,
+ START_SINGLE,
+ START_SERIES
+};
+
+
+/******************************************************************************
+ ******* structs / unions *****************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+extern int start_mode;
+
+
+/******************************************************************************
+ ******* extern functions *****************************************************
+ ******************************************************************************/
+void start_switch (void);
+
+
+/******************************************************************************
+ ******* static inline functions (prototypes) *********************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* static inline functions (definitions) ********************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+#endif /* vision-artificial/ctrl/start.h */
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
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_alx.hpp b/inc/vision-artificial/image/cv.hpp
index fd20a09..681497a 100644
--- a/modules/image/inc/img_alx.hpp
+++ b/inc/vision-artificial/image/cv.hpp
@@ -1,51 +1,71 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_IMG_ALX_H
- # define VA_IMG_ALX_H
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
- /* openCV */
- #include <opencv2/opencv.hpp>
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Img_Alx_Action {
- IMG_ALX_ACT_FOO = 0,
-
- IMG_ALX_ACT_ALX = 0x0010,
- IMG_ALX_ACT_LOCAL_MAX,
- IMG_ALX_ACT_LINES_HORIZONTAL,
- IMG_ALX_ACT_LINES_VERTICAL,
- IMG_ALX_ACT_MEAN_HORIZONTAL,
- IMG_ALX_ACT_MEAN_VERTICAL,
- IMG_ALX_ACT_MEDIAN_HORIZONTAL,
- IMG_ALX_ACT_MEDIAN_VERTICAL
- };
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
-void img_alx_act (class cv::Mat *imgptr, int action, void *data);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* img_alx.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+#ifndef VA_IMAGE_CV_H
+#define VA_IMAGE_CV_H
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+#include <opencv2/opencv.hpp>
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+enum Img_Cv_Action {
+ IMG_CV_ACT_FOO = 0x000000u,
+
+ IMG_CV_ACT_CV = 0x000100u,
+ IMG_CV_ACT_PIXEL_GET,
+ IMG_CV_ACT_PIXEL_SET,
+ IMG_CV_ACT_SET_ROI,
+ IMG_CV_ACT_AND_2REF,
+ IMG_CV_ACT_NOT,
+ IMG_CV_ACT_OR_2REF,
+ IMG_CV_ACT_COMPONENT,
+ IMG_CV_ACT_DILATE,
+ IMG_CV_ACT_ERODE,
+ IMG_CV_ACT_SMOOTH,
+ IMG_CV_ACT_SOBEL,
+ IMG_CV_ACT_BORDER,
+ IMG_CV_ACT_MIRROR,
+ IMG_CV_ACT_ROTATE_ORTO,
+ IMG_CV_ACT_ROTATE,
+ IMG_CV_ACT_ADAPTIVE_THRESHOLD,
+ IMG_CV_ACT_CVT_COLOR,
+ IMG_CV_ACT_DISTANCE_TRANSFORM,
+ IMG_CV_ACT_THRESHOLD,
+ IMG_CV_ACT_HISTOGRAM,
+ IMG_CV_ACT_HISTOGRAM_C3,
+ IMG_CV_ACT_CONTOURS,
+ IMG_CV_ACT_CONTOURS_SIZE,
+ IMG_CV_ACT_BOUNDING_RECT,
+ IMG_CV_ACT_FIT_ELLIPSE,
+ IMG_CV_ACT_MIN_AREA_RECT,
+ IMG_CV_ACT_HOUGH_CIRCLES
+};
+
+
+/******************************************************************************
+ ******* functions ************************************************************
+ ******************************************************************************/
+void img_cv_act (class cv::Mat *imgptr, int action, const void *data);
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+#endif /* vision-artificial/image/cv.h */
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
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_iface.hpp b/inc/vision-artificial/image/ocr.hpp
index f4345a8..7984152 100644
--- a/modules/proc/inc/proc_iface.hpp
+++ b/inc/vision-artificial/image/ocr.hpp
@@ -1,72 +1,66 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_PROC_IFACE_H
- # define VA_PROC_IFACE_H
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Proc_Mode {
- PROC_MODE_FOO,
-
- PROC_MODE = 0x4000,
- PROC_MODE_LABEL,
- PROC_MODE_COINS,
- PROC_MODE_RESISTOR
- };
-
- enum Proc_DBG {
- PROC_DBG_NO,
- PROC_DBG_STOP_ITEM,
- PROC_DBG_DELAY_STEP,
- PROC_DBG_STOP_STEP
- };
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-extern "C" {
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
- extern int proc_debug;
- extern int proc_mode;
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- int proc_iface_single (int action);
- void proc_iface_series (void);
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-} /* extern "C" */
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* proc_iface.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+#ifndef VA_IMG_OCR_HPP
+#define VA_IMG_OCR_HPP
+
+
+/******************************************************************************
+ ******* 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 *****************************************************
+ ******************************************************************************/
+extern "C" {
+void img_ocr_act (int action, const void *data);
+}
+
+
+/******************************************************************************
+ ******* static inline functions (prototypes) *********************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* static inline functions (definitions) ********************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+#endif /* vision-artificial/image/ocr.hpp */
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
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/about/inc/about.hpp b/inc/vision-artificial/menu/iface.h
index 50180ba..e671c8d 100644
--- a/modules/about/inc/about.hpp
+++ b/inc/vision-artificial/menu/iface.h
@@ -1,75 +1,69 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_ABOUT_HPP
- # define VA_ABOUT_HPP
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* FILENAME_MAX */
- #include <cstdio>
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-extern "C" {
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
- # define PROG_NAME "vision-artificial"
- # define PROG_YEAR "2018"
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Share_File {
- SHARE_COPYRIGHT,
- SHARE_DISCLAIMER,
- SHARE_HELP,
- SHARE_LICENSE,
- SHARE_USAGE
- };
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
- extern char share_path [FILENAME_MAX];
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- void about_init (void);
- void snprint_share_file (char *dest, int destsize, int share_file);
- void print_share_file (int share_file);
- void print_version (void);
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-} /* extern "C" */
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* about.hpp */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+#ifndef VA_MENU_IFACE_H
+#define VA_MENU_IFACE_H
+
+
+/******************************************************************************
+ ******* 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 *****************************************************
+ ******************************************************************************/
+void menu_iface (void);
+
+
+/******************************************************************************
+ ******* static inline functions (prototypes) *********************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* static inline functions (definitions) ********************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+#endif /* vision-artificial/menu/iface.h */
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
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/inc/vision-artificial/proc/common.hpp b/inc/vision-artificial/proc/common.hpp
new file mode 100644
index 0000000..0b65f05
--- /dev/null
+++ b/inc/vision-artificial/proc/common.hpp
@@ -0,0 +1,127 @@
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+#ifndef VA_PROC_COMMON_HPP
+#define VA_PROC_COMMON_HPP
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+#include <cstdbool>
+
+#include <vector>
+
+#include <opencv2/opencv.hpp>
+
+
+/******************************************************************************
+ ******* macros ***************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* structs / unions *****************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* extern functions *****************************************************
+ ******************************************************************************/
+extern "C"
+{
+void proc_apply (void);
+void proc_save_mem (ptrdiff_t n);
+void proc_load_mem (ptrdiff_t n);
+void proc_save_ref (void);
+void proc_save_file (void);
+void proc_save_update (void);
+
+void proc_local_max (void);
+void proc_skeleton (void);
+void proc_lines_vertical (void);
+void proc_median_horizontal (void);
+void proc_median_vertical (void);
+
+void proc_pixel_get (ptrdiff_t x, ptrdiff_t y, unsigned char *val);
+void proc_pixel_set (ptrdiff_t x, ptrdiff_t y, unsigned char val);
+void proc_ROI (int x, int y, int w, int h);
+void proc_and_2ref (void);
+void proc_not (void);
+void proc_or_2ref (void);
+void proc_cmp (int cmp);
+void proc_dilate (int size);
+void proc_erode (int size);
+void proc_dilate_erode (int size);
+void proc_erode_dilate (int size);
+void proc_smooth (int method, int ksize);
+void proc_border (int size);
+void proc_rotate (float center_x, float center_y, double angle);
+void proc_adaptive_threshold (int method, int type, int ksize);
+void proc_cvt_color (int method);
+void proc_distance_transform (void);
+void proc_threshold (int type, int ksize);
+void proc_contours (
+ class std::vector <class std::vector <class cv::Point_ <int>>> *contours,
+ class cv::Mat *hierarchy);
+void proc_contours_size (
+ const class std::vector <class std::vector <class cv::Point_ <int>>> *contours,
+ double *area,
+ double *perimeter);
+void proc_bounding_rect (
+ const class std::vector <class cv::Point_ <int>> *contour,
+ class cv::Rect_ <int> *rect,
+ bool show);
+void proc_fit_ellipse (
+ const class std::vector <class cv::Point_ <int>> *contour,
+ class cv::RotatedRect *rect,
+ bool show);
+void proc_min_area_rect (
+ const class std::vector <class cv::Point_ <int>> *contour,
+ class cv::RotatedRect *rect,
+ bool show);
+
+void proc_OCR (int lang, int conf);
+void proc_zbar (int type);
+
+void proc_show_img (void);
+void clock_start (void);
+void clock_stop (const char *txt);
+}
+
+
+/******************************************************************************
+ ******* static inline functions (prototypes) *********************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* static inline functions (definitions) ********************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+#endif /* vision-artificial/proc/common.hpp */
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/inc/vision-artificial/proc/iface.h b/inc/vision-artificial/proc/iface.h
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/inc/vision-artificial/proc/resistor.h b/inc/vision-artificial/proc/resistor.h
new file mode 100644
index 0000000..51dd735
--- /dev/null
+++ b/inc/vision-artificial/proc/resistor.h
@@ -0,0 +1,71 @@
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+#ifndef VA_PROC_RESISTOR_H
+#define VA_PROC_RESISTOR_H
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* macros ***************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+enum Proc_Resistor {
+ RESISTOR_OK,
+ RESISTOR_NOK_RESISTOR,
+ RESISTOR_NOK_BANDS,
+ RESISTOR_NOK_COLOR,
+ RESISTOR_NOK_STD_VALUE,
+ RESISTOR_NOK_TOLERANCE
+};
+
+
+/******************************************************************************
+ ******* structs / unions *****************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* extern functions *****************************************************
+ ******************************************************************************/
+int proc_resistor (void);
+
+
+/******************************************************************************
+ ******* static inline functions (prototypes) *********************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* static inline functions (definitions) ********************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+#endif /* vision-artificial/proc/resistor.h */
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/inc/vision-artificial/proc/resistor.hpp b/inc/vision-artificial/proc/resistor.hpp
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/inc/vision-artificial/save/save.h b/inc/vision-artificial/save/save.h
new file mode 100644
index 0000000..87bddae
--- /dev/null
+++ b/inc/vision-artificial/save/save.h
@@ -0,0 +1,99 @@
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+#ifndef VA_SAVE_SAVE_H
+#define VA_SAVE_SAVE_H
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+#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"
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* structs / unions *****************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+extern char home_path [FILENAME_MAX];
+extern char user_prog_path [FILENAME_MAX];
+extern char saved_path [FILENAME_MAX];
+extern char labels_path [FILENAME_MAX];
+extern char labels_fail_path [FILENAME_MAX];
+extern char lighters_path [FILENAME_MAX];
+extern char lighters_fail_path [FILENAME_MAX];
+extern char objects_path [FILENAME_MAX];
+extern char objects_fail_path [FILENAME_MAX];
+extern char coins_path [FILENAME_MAX];
+extern char coins_fail_path [FILENAME_MAX];
+extern char resistors_path [FILENAME_MAX];
+extern char resistors_fail_path [FILENAME_MAX];
+extern char saved_name [FILENAME_MAX];
+
+
+/******************************************************************************
+ ******* extern functions *****************************************************
+ ******************************************************************************/
+void save_init (void);
+void save_cleanup (void);
+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 /* vision-artificial/save/save.h */
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/modules/save/inc/save.hpp b/inc/vision-artificial/save/save.hpp
index 41a79fb..aa05474 100644
--- a/modules/save/inc/save.hpp
+++ b/inc/vision-artificial/save/save.hpp
@@ -1,87 +1,105 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_SAVE_HPP
- # define VA_SAVE_HPP
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* FILENAME_MAX */
- #include <cstdio>
-
-/* Project -------------------------------------------------------------------*/
- /* opencv */
- #include <opencv2/opencv.hpp>
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-extern "C" {
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
- # define ENV_HOME "HOME"
-
- # define USER_PROG_DIR "vision-artificial/"
- # define USER_SAVED_DIR "vision-artificial/saved/"
- # define USER_LABELS_DIR "vision-artificial/labels/"
- # define USER_LABELS_FAIL_DIR "vision-artificial/labels/fail"
- # define USER_COINS_DIR "vision-artificial/coins/"
- # define USER_COINS_FAIL_DIR "vision-artificial/coins/fail"
- # define USER_RESISTORS_DIR "vision-artificial/resistors/"
- # define USER_RESISTORS_FAIL_DIR "vision-artificial/resistors/fail"
- # define SAVED_NAME_DEFAULT "saved"
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
- extern class cv::Mat image;
- extern char home_path [FILENAME_MAX];
- extern char user_prog_path [FILENAME_MAX];
- extern char saved_path [FILENAME_MAX];
- extern char labels_path [FILENAME_MAX];
- extern char labels_fail_path [FILENAME_MAX];
- extern char coins_path [FILENAME_MAX];
- extern char coins_fail_path [FILENAME_MAX];
- extern char resistors_path [FILENAME_MAX];
- extern char resistors_fail_path [FILENAME_MAX];
- extern char saved_name [FILENAME_MAX];
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- void save_init (void);
- void save_cleanup (void);
- void save_clr (void);
- void load_image_file (const char *fpath, const char *fname);
- void save_image_file (const char *fpath, const char *save_as);
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-} /* extern "C" */
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* save.hpp */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+#ifndef VA_SAVE_SAVE_HPP
+#define VA_SAVE_SAVE_HPP
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+#include <cstdio>
+
+#include <opencv2/opencv.hpp>
+
+#include "libalx/base/stddef/restrict.hpp"
+
+
+/******************************************************************************
+ ******* 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"
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* structs / unions *****************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+extern class cv::Mat image;
+extern char home_path [FILENAME_MAX];
+extern char user_prog_path [FILENAME_MAX];
+extern char saved_path [FILENAME_MAX];
+extern char labels_path [FILENAME_MAX];
+extern char labels_fail_path [FILENAME_MAX];
+extern char lighters_path [FILENAME_MAX];
+extern char lighters_fail_path [FILENAME_MAX];
+extern char objects_path [FILENAME_MAX];
+extern char objects_fail_path [FILENAME_MAX];
+extern char coins_path [FILENAME_MAX];
+extern char coins_fail_path [FILENAME_MAX];
+extern char resistors_path [FILENAME_MAX];
+extern char resistors_fail_path [FILENAME_MAX];
+extern char saved_name [FILENAME_MAX];
+
+
+/******************************************************************************
+ ******* extern functions *****************************************************
+ ******************************************************************************/
+extern "C"
+{
+void save_init (void);
+void save_cleanup (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) *********************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* static inline functions (definitions) ********************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+#endif /* vision-artificial/save/save.hpp */
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/modules/proc/inc/proc_label.hpp b/inc/vision-artificial/user/clui.h
index eb5dd66..158c019 100644
--- a/modules/proc/inc/proc_label.hpp
+++ b/inc/vision-artificial/user/clui.h
@@ -1,62 +1,59 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_PROC_LABEL_HPP
- # define VA_PROC_LABEL_HPP
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Proc_Label {
- LABEL_OK,
- LABEL_NOK_LABEL,
- LABEL_NOK_CERDO,
- LABEL_NOK_BCODE,
- LABEL_NOK_PRODUCT,
- LABEL_NOK_PRICE
- };
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-extern "C" {
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- int proc_label (void);
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-} /* extern "C" */
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* proc_label.hpp */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* include guard ********************************************************
+ ******************************************************************************/
+#ifndef VA_USER_CLUI_H
+#define VA_USER_CLUI_H
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* macros ***************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* structs / unions *****************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* extern functions *****************************************************
+ ******************************************************************************/
+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 /* vision-artificial/user/clui.h */
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
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 09e8b872f29a29ac26f8233370e398b041bdf4a
+Subproject d95dd760ac01bd2000f0a38d0a1cc9fa2c1125f
diff --git a/modules/Makefile b/modules/Makefile
deleted file mode 100644
index fbf9bc1..0000000
--- a/modules/Makefile
+++ /dev/null
@@ -1,49 +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
-
-all:
- $(Q)cd $(ABOUT_DIR) && $(MAKE) && cd ..
- $(Q)cd $(CTRL_DIR) && $(MAKE) && cd ..
- $(Q)cd $(IMG_DIR) && $(MAKE) && cd ..
- $(Q)cd $(MENU_DIR) && $(MAKE) && cd ..
- $(Q)cd $(PROC_DIR) && $(MAKE) && cd ..
- $(Q)cd $(SAVE_DIR) && $(MAKE) && cd ..
- $(Q)cd $(USR_DIR) && $(MAKE) && cd ..
- $(Q)cd $(TMP_DIR) && $(MAKE) && cd ..
-
-
-clean:
- $(Q)find . -type f -name '*.o' -exec rm '{}' '+'
- $(Q)find . -type f -name '*.s' -exec rm '{}' '+'
- @echo "Clean modules"
-
-################################################################################
-######## 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/inc/about.h b/modules/about/inc/about.h
deleted file mode 100644
index 5122d14..0000000
--- a/modules/about/inc/about.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_ABOUT_H
- # define VA_ABOUT_H
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* FILENAME_MAX */
- #include <stdio.h>
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
- # define PROG_NAME "vision-artificial"
- # define PROG_YEAR "2018"
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Share_File {
- SHARE_COPYRIGHT,
- SHARE_DISCLAIMER,
- SHARE_HELP,
- SHARE_LICENSE,
- SHARE_USAGE
- };
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
- extern char share_path [FILENAME_MAX];
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- void about_init (void);
- void snprint_share_file (char *dest, int destsize, int share_file);
- void print_share_file (int share_file);
- void print_version (void);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* about.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/about/src/about.c b/modules/about/src/about.c
deleted file mode 100644
index d443e1d..0000000
--- a/modules/about/src/about.c
+++ /dev/null
@@ -1,88 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* printf() */
- #include <stdio.h>
-
-/* libalx --------------------------------------------------------------------*/
- /* alx_snprint_file() */
- #include "alx_file.h"
-
-/* Module --------------------------------------------------------------------*/
- #include "about.h"
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
- # define BUFF_SIZE_TEXT (1048576)
-
- # define BEGINNING "\n┌──────────────────────────────────────────────────────────────────────────────┐\n"
- # define ENDING "└──────────────────────────────────────────────────────────────────────────────┘\n\n"
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-char share_path [FILENAME_MAX];
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void about_init (void)
-{
- snprintf(share_path, FILENAME_MAX, "%s/%s/", INSTALL_SHARE_DIR, SHARE_DIR);
-}
-
-void snprint_share_file (char *dest, int destsize, int share_file)
-{
- char file_name [FILENAME_MAX];
-
- switch (share_file) {
- case SHARE_COPYRIGHT:
- snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "COPYRIGHT.txt");
- break;
- case SHARE_DISCLAIMER:
- snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "DISCLAIMER.txt");
- break;
- case SHARE_HELP:
- snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "HELP.txt");
- break;
- case SHARE_LICENSE:
- snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "LICENSE.txt");
- break;
- case SHARE_USAGE:
- snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "USAGE.txt");
- break;
- }
-
- alx_snprint_file(dest, destsize, file_name);
-}
-
-void print_share_file (int share_file)
-{
- char str [BUFF_SIZE_TEXT];
-
- snprint_share_file(str, BUFF_SIZE_TEXT, share_file);
-
- printf(BEGINNING);
- printf("%s", str);
- printf(ENDING);
-}
-
-void print_version (void)
-{
- printf("" PROG_NAME " " PROG_VERSION "\n\n");
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/about/tmp/Makefile b/modules/about/tmp/Makefile
deleted file mode 100644
index c415744..0000000
--- a/modules/about/tmp/Makefile
+++ /dev/null
@@ -1,50 +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 = 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)
- $(Q)$(LD) -r $^ -o $@
- @echo " LD $@"
- @echo ""
-
-
-about.s: $(ABOU_DEPS)
- $(Q)$(CC) $(CFLAGS) $(ABOU_INC_DIRS) -S $< -o $@
- @echo " CC $@"
-about.o: about.s
- $(Q)$(AS) $< -o $@
- @echo " AS $@"
-
-
-clean:
- $(Q)rm -f *.o *.s
-
-################################################################################
-######## End of file ###########################################################
-################################################################################
diff --git a/modules/ctrl/Makefile b/modules/ctrl/Makefile
deleted file mode 100644
index 60d7283..0000000
--- a/modules/ctrl/Makefile
+++ /dev/null
@@ -1,24 +0,0 @@
-# -*- MakeFile -*-
-
-# MACRO = substitute with this
-
-# directories
-
-TMP_DIR = $(CTRL_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/ctrl/inc/start.h b/modules/ctrl/inc/start.h
deleted file mode 100644
index 9b79302..0000000
--- a/modules/ctrl/inc/start.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_START_H
- # define VA_START_H
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Start_Mode {
- START_FOO = 0,
- START_SINGLE,
- START_SERIES
- };
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
- extern int start_mode;
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- void start_switch (void);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* start.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/ctrl/tmp/Makefile b/modules/ctrl/tmp/Makefile
deleted file mode 100644
index c11f389..0000000
--- a/modules/ctrl/tmp/Makefile
+++ /dev/null
@@ -1,58 +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
-
-all: $(ALL)
-
-
-ctrl_mod.o: $(_ALL)
- $(Q)$(LD) -r $^ -o $@
- @echo " LD $@"
- @echo ""
-
-
-start.s: $(STRT_DEPS)
- $(Q)$(CC) $(CFLAGS) $(STRT_INC_DIRS) -S $< -o $@
- @echo " CC $@"
-start.o: start.s
- $(Q)$(AS) $< -o $@
- @echo " AS $@"
-
-
-clean:
- $(Q)rm -f *.o *.s
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_cv.hpp b/modules/image/inc/img_cv.hpp
deleted file mode 100644
index 38e2fb1..0000000
--- a/modules/image/inc/img_cv.hpp
+++ /dev/null
@@ -1,68 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_IMG_CV_H
- # define VA_IMG_CV_H
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
- /* openCV */
- #include <opencv2/opencv.hpp>
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Img_Cv_Action {
- IMG_CV_ACT_FOO = 0,
-
- IMG_CV_ACT_CV = 0x0100,
- IMG_CV_ACT_PIXEL_VALUE,
- 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_ROTATE_ORTO,
- IMG_CV_ACT_ROTATE,
- IMG_CV_ACT_ADAPTIVE_THRESHOLD,
- IMG_CV_ACT_CVT_COLOR,
- IMG_CV_ACT_DISTANCE_TRANSFORM,
- IMG_CV_ACT_THRESHOLD,
- IMG_CV_ACT_HISTOGRAM,
- IMG_CV_ACT_HISTOGRAM_C3,
- IMG_CV_ACT_CONTOURS,
- IMG_CV_ACT_CONTOURS_SIZE,
- IMG_CV_ACT_BOUNDING_RECT,
- IMG_CV_ACT_FIT_ELLIPSE,
- IMG_CV_ACT_MIN_AREA_RECT,
- IMG_CV_ACT_HOUGH_CIRCLES
- };
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
-void img_cv_act (class cv::Mat *imgptr, int action, void *data);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* img_cv.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/image/inc/img_iface.h b/modules/image/inc/img_iface.h
deleted file mode 100644
index 8bb023f..0000000
--- a/modules/image/inc/img_iface.h
+++ /dev/null
@@ -1,170 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_IMG_IFACE_H
- # define VA_IMG_IFACE_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 = 0,
-
- IMG_IFACE_ACT_ALX = 0x0010,
- IMG_IFACE_ACT_LOCAL_MAX,
- 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 = 0x0100,
- IMG_IFACE_ACT_PIXEL_VALUE,
- 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_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_ZB = 0x0200,
- IMG_IFACE_ACT_DECODE,
-
- IMG_IFACE_ACT_OCR = 0x0400,
- IMG_IFACE_ACT_READ,
-
- IMG_IFACE_ACT_ORB = 0x0800,
- IMG_IFACE_ACT_ALIGN,
-
- IMG_IFACE_ACT_IMGI = 0x1000,
- IMG_IFACE_ACT_APPLY,
- IMG_IFACE_ACT_DISCARD,
- IMG_IFACE_ACT_SAVE_MEM,
- IMG_IFACE_ACT_LOAD_MEM,
- IMG_IFACE_ACT_SAVE_REF,
-
- IMG_IFACE_ACT_SAVE = 0x2000,
- IMG_IFACE_ACT_SAVE_FILE,
- 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);
- /* data should *always* be NULL */
- void img_iface_act (int action, void *data);
- void img_iface_show_img (void);
- void img_iface_show_hist_c1 (void);
- void img_iface_show_hist_c3 (void);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* img_iface.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/image/inc/img_iface.hpp b/modules/image/inc/img_iface.hpp
deleted file mode 100644
index 0cb858b..0000000
--- a/modules/image/inc/img_iface.hpp
+++ /dev/null
@@ -1,295 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_IMG_IFACE_HPP
- # define VA_IMG_IFACE_HPP
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* 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)
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Img_Iface_Action {
- IMG_IFACE_ACT_FOO = 0,
-
- IMG_IFACE_ACT_ALX = 0x0010,
- IMG_IFACE_ACT_LOCAL_MAX,
- 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 = 0x0100,
- IMG_IFACE_ACT_PIXEL_VALUE,
- 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_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_ZB = 0x0200,
- IMG_IFACE_ACT_DECODE,
-
- IMG_IFACE_ACT_OCR = 0x0400,
- IMG_IFACE_ACT_READ,
-
- IMG_IFACE_ACT_ORB = 0x0800,
- IMG_IFACE_ACT_ALIGN,
-
- IMG_IFACE_ACT_IMGI = 0x1000,
- IMG_IFACE_ACT_APPLY,
- IMG_IFACE_ACT_DISCARD,
- IMG_IFACE_ACT_SAVE_MEM,
- IMG_IFACE_ACT_LOAD_MEM,
- IMG_IFACE_ACT_SAVE_REF,
-
- IMG_IFACE_ACT_SAVE = 0x2000,
- IMG_IFACE_ACT_SAVE_FILE,
- 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_Value {
- 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_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 {
- std::vector <std::vector <class cv::Point_ <int>>> *contours;
- class cv::Mat *hierarchy;
- };
-
- struct Img_Iface_Data_Contours_Size {
- std::vector <std::vector <class cv::Point_ <int>>> *contours;
- double *area;
- double *perimeter;
- };
-
- struct Img_Iface_Data_Bounding_Rect {
- std::vector <class cv::Point_ <int>> *contour;
- class cv::Rect_ <int> *rect;
- bool show;
- };
-
- struct Img_Iface_Data_MinARect {
- std::vector <class cv::Point_ <int>> *contour;
- class cv::RotatedRect *rect;
- bool show;
- };
-
- struct Img_Iface_Data_Hough_Circles {
- std::vector <class cv::Vec <float, 3>> *circles;
- double dist_min;
- double param_1;
- double param_2;
- int radius_min;
- int radius_max;
- };
-
-/* img_zbar -------------------------------------------------------------------*/
- struct Img_Iface_Data_Decode {
- enum zbar::zbar_symbol_type_e code_type;
- };
-
- struct Img_Iface_ZB_Codes {
- int n;
- struct {
- enum zbar::zbar_symbol_type_e type;
- char sym_name [80];
- char data [ZBAR_LEN_MAX];
- } arr [ZB_CODES_MAX];
- };
-
-/* img_ocr -------------------------------------------------------------------*/
- struct Img_Iface_Data_Read {
- int lang;
- int conf;
- struct {
- void *data;
- int width;
- int height;
- int B_per_pix;
- int B_per_line;
- } img;
- };
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-extern "C" {
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
- extern char img_ocr_text [OCR_TEXT_MAX];
- extern struct Img_Iface_ZB_Codes zb_codes;
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- void img_iface_cleanup_main (void);
- void img_iface_load (const char *fpath, const char *fname);
- void img_iface_cleanup (void);
- void img_iface_act (int action, void *data);
- void img_iface_show_img (void);
- void img_iface_show_hist_c1 (void);
- void img_iface_show_hist_c3 (void);
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-} /* extern "C" */
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* img_iface.hpp */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/image/inc/img_ocr.h b/modules/image/inc/img_ocr.h
deleted file mode 100644
index 2c216ad..0000000
--- a/modules/image/inc/img_ocr.h
+++ /dev/null
@@ -1,38 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_IMG_OCR_H
- # define VA_IMG_OCR_H
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Img_OCR_Action {
- IMG_OCR_ACT_FOO = 0,
-
- IMG_OCR_ACT_OCR = 0x0400,
- IMG_OCR_ACT_READ
- };
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
-void img_ocr_act (int action, void *data);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* img_ocr.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/image/inc/img_ocr.hpp b/modules/image/inc/img_ocr.hpp
deleted file mode 100644
index 723588e..0000000
--- a/modules/image/inc/img_ocr.hpp
+++ /dev/null
@@ -1,50 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_IMG_OCR_HPP
- # define VA_IMG_OCR_HPP
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Img_OCR_Action {
- IMG_OCR_ACT_FOO = 0,
-
- IMG_OCR_ACT_OCR = 0x0400,
- IMG_OCR_ACT_READ
- };
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-extern "C" {
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- void img_ocr_act (int action, void *data);
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-} /* extern "C" */
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* img_ocr.hpp */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/image/inc/img_orb.hpp b/modules/image/inc/img_orb.hpp
deleted file mode 100644
index 6138a04..0000000
--- a/modules/image/inc/img_orb.hpp
+++ /dev/null
@@ -1,58 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_IMG_ORB_HPP
- # define VA_IMG_ORB_HPP
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
- /* openCV */
- #include <opencv2/opencv.hpp>
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-extern "C" {
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Img_ORB_Action {
- IMG_ORB_ACT_FOO = 0,
-
- IMG_ORB_ACT_ORB = 0x0800,
- IMG_ORB_ACT_ALIGN
- };
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- void img_orb_act (class cv::Mat *pattern,
- class cv::Mat *imgptr, int action);
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-} /* extern "C" */
-
-
-/******************************************************************************
- ******* 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 3132175..0000000
--- a/modules/image/inc/img_zbar.hpp
+++ /dev/null
@@ -1,46 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_IMG_ZBAR_H
- # define VA_IMG_ZBAR_H
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Packages ------------------------------------------------------------------*/
- /* openCV */
- #include <opencv2/opencv.hpp>
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Img_ZB_Action {
- IMG_ZB_ACT_FOO = 0,
-
- IMG_ZB_ACT_ZB = 0x0200,
- IMG_ZB_ACT_DECODE
- };
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
-void img_zb_act (class cv::Mat *imgptr, int action, void *data);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* img_zbar.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/image/src/img_alx.cpp b/modules/image/src/img_alx.cpp
deleted file mode 100644
index f1f0b93..0000000
--- a/modules/image/src/img_alx.cpp
+++ /dev/null
@@ -1,298 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* true & false */
- #include <cstdbool>
- /* snprintf() */
- #include <cstdio>
-
-/* Packages ------------------------------------------------------------------*/
- /* opencv */
- #include <opencv2/opencv.hpp>
-
-/* libalx --------------------------------------------------------------------*/
- /* alx_median_uint8() */
- #include "alx_math.hpp"
-
-/* Module --------------------------------------------------------------------*/
- /* data */
- #include "img_iface.hpp"
-
- #include "img_alx.hpp"
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void img_alx_local_max (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);
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void img_alx_act (class cv::Mat *imgptr, int action, void *data)
-{
- switch (action) {
- case IMG_ALX_ACT_LOCAL_MAX:
- img_alx_local_max(imgptr);
- break;
-
- case IMG_ALX_ACT_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 *****************************************************
- ******************************************************************************/
-static void img_alx_local_max (class cv::Mat *imgptr)
-{
- int i;
- int j;
- int k;
- int l;
- bool local_max;
- int dist_min;
- int val_min;
- 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);
- /* Minimum distance between local maxima */
- dist_min = 16;
- /* Minimum value of local maxima */
- val_min = 16;
-
- 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;
- local_max = true;
-
- if (*img_pix < val_min) {
- local_max = false;
- }
-
- for (k = i - dist_min; (k < i + dist_min+1) && local_max; k++) {
- for (l = j - dist_min; (l < j + dist_min+1) && local_max; 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) {
- local_max = false;
- }
- }
- }
- }
- }
-
- if (local_max) {
- *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_uint8(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_uint8(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_cv.cpp b/modules/image/src/img_cv.cpp
deleted file mode 100644
index 2359218..0000000
--- a/modules/image/src/img_cv.cpp
+++ /dev/null
@@ -1,792 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* fabs */
- #include <cmath>
- /* true & false */
- #include <cstdbool>
- /* snprintf() */
- #include <cstdio>
-
-/* Packages ------------------------------------------------------------------*/
- /* opencv */
- #include <opencv2/opencv.hpp>
-
-/* Module --------------------------------------------------------------------*/
- /* data */
- #include "img_iface.hpp"
-
- #include "img_cv.hpp"
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
- /* Core: The core functionality */
- /* Pixel */
-static void img_cv_pixel_value (class cv::Mat *imgptr, void *data);
- /* ROI */
-static void img_cv_set_ROI (class cv::Mat *imgptr, void *data);
- /* Operations on Arrays */
-static void img_cv_and_2ref (class cv::Mat *imgptr, void *data);
-static void img_cv_not (class cv::Mat *imgptr);
-static void img_cv_or_2ref (class cv::Mat *imgptr, void *data);
-static void img_cv_component (class cv::Mat *imgptr, void *data);
- /* Imgproc: Image processing */
- /* Image filtering */
-static void img_cv_dilate (class cv::Mat *imgptr, void *data);
-static void img_cv_erode (class cv::Mat *imgptr, void *data);
-static void img_cv_smooth (class cv::Mat *imgptr, void *data);
-static void img_cv_sobel (class cv::Mat *imgptr, void *data);
- /* Geometric image transformations */
-static void img_cv_rotate_orto (class cv::Mat *imgptr, void *data);
-static void img_cv_rotate (class cv::Mat *imgptr, void *data);
- /* Miscellaneous image transformations */
-static void img_cv_adaptive_thr (class cv::Mat *imgptr, void *data);
-static void img_cv_cvt_color (class cv::Mat *imgptr, void *data);
-static void img_cv_distance_transform (class cv::Mat *imgptr);
-static void img_cv_threshold (class cv::Mat *imgptr, void *data);
- /* Histograms */
-static void img_cv_histogram (class cv::Mat *imgptr, void *data);
-static void img_cv_histogram_c3 (class cv::Mat *imgptr, void *data);
- /* Structural analysis and shape descriptors */
-static void img_cv_contours (class cv::Mat *imgptr, void *data);
-static void img_cv_contours_size (void *data);
-static void img_cv_bounding_rect (class cv::Mat *imgptr, void *data);
-static void img_cv_fit_ellipse (class cv::Mat *imgptr, void *data);
-static void img_cv_min_area_rect (class cv::Mat *imgptr, void *data);
- /* Feature detection */
-static void img_cv_hough_circles (class cv::Mat *imgptr, void *data);
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void img_cv_act (class cv::Mat *imgptr, int action, void *data)
-{
- switch (action) {
- case IMG_CV_ACT_PIXEL_VALUE:
- img_cv_pixel_value(imgptr, data);
- break;
-
- case IMG_CV_ACT_SET_ROI:
- img_cv_set_ROI(imgptr, data);
- break;
-
- case IMG_CV_ACT_AND_2REF:
- img_cv_and_2ref(imgptr, data);
- break;
- case IMG_CV_ACT_NOT:
- img_cv_not(imgptr);
- break;
- case IMG_CV_ACT_OR_2REF:
- img_cv_or_2ref(imgptr, data);
- break;
- case IMG_CV_ACT_COMPONENT:
- img_cv_component(imgptr, data);
- break;
-
- case IMG_CV_ACT_DILATE:
- img_cv_dilate(imgptr, data);
- break;
- case IMG_CV_ACT_ERODE:
- img_cv_erode(imgptr, data);
- break;
- case IMG_CV_ACT_SMOOTH:
- img_cv_smooth(imgptr, data);
- break;
- case IMG_CV_ACT_SOBEL:
- img_cv_sobel(imgptr, data);
- break;
-
- case IMG_CV_ACT_ROTATE_ORTO:
- img_cv_rotate_orto(imgptr, data);
- break;
- case IMG_CV_ACT_ROTATE:
- img_cv_rotate(imgptr, data);
- break;
-
- case IMG_CV_ACT_ADAPTIVE_THRESHOLD:
- img_cv_adaptive_thr(imgptr, data);
- break;
- case IMG_CV_ACT_CVT_COLOR:
- img_cv_cvt_color(imgptr, data);
- break;
- case IMG_CV_ACT_DISTANCE_TRANSFORM:
- img_cv_distance_transform(imgptr);
- break;
- case IMG_CV_ACT_THRESHOLD:
- img_cv_threshold(imgptr, data);
- break;
-
- case IMG_CV_ACT_HISTOGRAM:
- img_cv_histogram(imgptr, data);
- break;
- case IMG_CV_ACT_HISTOGRAM_C3:
- img_cv_histogram_c3(imgptr, data);
- break;
-
- case IMG_CV_ACT_CONTOURS:
- img_cv_contours(imgptr, data);
- break;
- case IMG_CV_ACT_CONTOURS_SIZE:
- img_cv_contours_size(data);
- break;
- case IMG_CV_ACT_BOUNDING_RECT:
- img_cv_bounding_rect(imgptr, data);
- break;
- case IMG_CV_ACT_FIT_ELLIPSE:
- img_cv_fit_ellipse(imgptr, data);
- break;
- case IMG_CV_ACT_MIN_AREA_RECT:
- img_cv_min_area_rect(imgptr, data);
- break;
-
- case IMG_CV_ACT_HOUGH_CIRCLES:
- img_cv_hough_circles(imgptr, data);
- break;
- }
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-/* Core: The core functionality */
-/* ----- Pixel */
-static void img_cv_pixel_value (class cv::Mat *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_Pixel_Value *data_cast;
- data_cast = (struct Img_Iface_Data_Pixel_Value *)data;
-
- /* Value */
- unsigned char *val;
- val = data_cast->val;
- /* Position */
- int x;
- x = data_cast->x;
- int y;
- y = data_cast->y;
-
- /* Get value */
- *val = imgptr->at<unsigned char>(y, x);
-}
-
-/* ----- ROI */
-static void img_cv_set_ROI (class cv::Mat *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_SetROI *data_cast;
- data_cast = (struct Img_Iface_Data_SetROI *)data;
-
- /* Rectangle */
- class cv::Rect_ <int> *rect;
- rect = &(data_cast->rect);
-
- /* Set ROI */
- *imgptr = (*imgptr)(*rect);
-}
-
-/* ----- Operations on arrays */
-static void img_cv_and_2ref (class cv::Mat *imgptr, void *data)
-{
- class cv::Mat *img_ref;
- img_ref = (class cv::Mat *)data;
-
- cv::bitwise_and(*imgptr, *img_ref, *imgptr);
-}
-
-static void img_cv_not (class cv::Mat *imgptr)
-{
- cv::bitwise_not(*imgptr, *imgptr);
-}
-
-static void img_cv_or_2ref (class cv::Mat *imgptr, void *data)
-{
- class cv::Mat *img_ref;
- img_ref = (class cv::Mat *)data;
-
- cv::bitwise_or(*imgptr, *img_ref, *imgptr);
-}
-
-static void img_cv_component (class cv::Mat *imgptr, void *data)
-{
- class cv::Mat cmp_img[3];
-
- /* Data */
- struct Img_Iface_Data_Component *data_cast;
- data_cast = (struct Img_Iface_Data_Component *)data;
-
- /* Color component */
- int cmp;
- cmp = data_cast->cmp;
-
- /* Write components into cmp_img[] */
- cv::split(*imgptr, cmp_img);
-
- /* Write tmp into imgptr */
- imgptr->release();
- cmp_img[cmp].copyTo(*imgptr);
-
- /* clean up */
- cmp_img[0].release();
- cmp_img[1].release();
- cmp_img[2].release();
-}
-
-/* Imgproc: Image processing */
-/* ----- Image filtering */
-static void img_cv_dilate (class cv::Mat *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_Dilate_Erode *data_cast;
- data_cast = (struct Img_Iface_Data_Dilate_Erode *)data;
-
- /* Iterations */
- int i;
- i = data_cast->i;
-
- /* Dilate */
- cv::dilate(*imgptr, *imgptr, cv::Mat(), cv::Point(-1,-1), i,
- cv::BORDER_REPLICATE);
-}
-
-static void img_cv_erode (class cv::Mat *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_Dilate_Erode *data_cast;
- data_cast = (struct Img_Iface_Data_Dilate_Erode *)data;
-
- /* Iterations */
- int i;
- i = data_cast->i;
-
- /* Erode */
- cv::erode(*imgptr, *imgptr, cv::Mat(), cv::Point(-1,-1), i,
- cv::BORDER_REPLICATE);
-}
-
-static void img_cv_smooth (class cv::Mat *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_Smooth *data_cast;
- data_cast = (struct Img_Iface_Data_Smooth *)data;
-
- /* Smoothing method */
- int method;
- method = data_cast->method;
- /* Kernel size */
- int ksize;
- ksize = data_cast->ksize;
- if (!(ksize % 2)) {
- ksize++;
- }
-
- switch (method) {
- case IMGI_SMOOTH_MEAN:
- cv::blur(*imgptr, *imgptr, cv::Size(ksize, ksize),
- cv::Point(-1,-1), cv::BORDER_DEFAULT);
- break;
- case IMGI_SMOOTH_GAUSS:
- cv::GaussianBlur(*imgptr, *imgptr, cv::Size(ksize, ksize),
- 0, 0, cv::BORDER_DEFAULT);
- break;
- case IMGI_SMOOTH_MEDIAN:
- cv::medianBlur(*imgptr, *imgptr, ksize);
- break;
- }
-}
-
-static void img_cv_sobel (class cv::Mat *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_Sobel *data_cast;
- data_cast = (struct Img_Iface_Data_Sobel *)data;
-
- /* Order of the derivative x */
- int dx;
- dx = data_cast->dx;
- /* Order of the derivative y */
- int dy;
- dy = data_cast->dy;
- /* Size of the extended Sobel kernel */
- int ksize;
- ksize = data_cast->ksize;
- if (!(ksize % 2)) {
- ksize++;
- }
-
- cv::Sobel(*imgptr, *imgptr, -1, dx, dy, ksize, 1, 0,
- cv::BORDER_DEFAULT);
-}
-
-/* ----- Geometric image transformations */
-static void img_cv_rotate_orto (class cv::Mat *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_Rotate_Orto *data_cast;
- data_cast = (struct Img_Iface_Data_Rotate_Orto *)data;
-
- /* Rotate n * pi/2 rad */
- int n;
- n = data_cast->n;
-
- switch (n) {
- case 1:
- /* Rotate: transpose and flip around horizontal axis: flip_mode=0 */
- cv::transpose(*imgptr, *imgptr);
- cv::flip(*imgptr, *imgptr, 0);
- break;
-
- case 2:
- /* Rotate: Flip both axises: flip_mode=-1 */
- cv::flip(*imgptr, *imgptr, -1);
- break;
-
- case 3:
- /* Rotate: transpose and flip around vertical axis: flip_mode=1 */
- cv::transpose(*imgptr, *imgptr);
- cv::flip(*imgptr, *imgptr, 1);
- break;
- }
-}
-
-static void img_cv_rotate (class cv::Mat *imgptr, void *data)
-{
- class cv::Mat map_matrix;
-
- /* Data */
- struct Img_Iface_Data_Rotate *data_cast;
- data_cast = (struct Img_Iface_Data_Rotate *)data;
-
- /* Angle of rotation */
- class cv::Point_ <float> *center;
- center = &(data_cast->center);
- double angle;
- angle = data_cast->angle;
-
- /* Don't rotate if angle is negligible */
- if (fabs(angle) > 1.0) {
- /* Get map_matrix */
- map_matrix = cv::getRotationMatrix2D(*center, angle, 1);
-
- /* Rotate */
- cv::warpAffine(*imgptr, *imgptr, map_matrix, imgptr->size(),
- cv::INTER_LINEAR, cv::BORDER_CONSTANT,
- cv::Scalar(0, 0, 0));
- }
-
- /* clean up */
- map_matrix.release();
-}
-
-/* ----- Miscellaneous image transformations */
-static void img_cv_adaptive_thr (class cv::Mat *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_Adaptive_Thr *data_cast;
- data_cast = (struct Img_Iface_Data_Adaptive_Thr *)data;
-
- /* Threshold method */
- int method;
- method = data_cast->method;
- /* Threshold type */
- int thr_typ;
- thr_typ = data_cast->thr_typ;
- /* Neighbourhood size */
- int ksize;
- ksize = data_cast->ksize;
- if (!(ksize % 2)) {
- ksize++;
- }
-
- /* Apply adaptive threshold */
- cv::adaptiveThreshold(*imgptr, *imgptr, 255, method, thr_typ, ksize,
- 0);
-}
-
-static void img_cv_cvt_color (class cv::Mat *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_Cvt_Color *data_cast;
- data_cast = (struct Img_Iface_Data_Cvt_Color *)data;
-
- /* Conversion method */
- int method;
- method = data_cast->method;
-
- cv::cvtColor(*imgptr, *imgptr, method, 0);
-}
-
-static void img_cv_distance_transform (class cv::Mat *imgptr)
-{
- class cv::Mat imgtmp;
-
- /* Get transform */
- cv::distanceTransform(*imgptr, imgtmp, CV_DIST_L2, CV_DIST_MASK_PRECISE);
-
- /* DistanceTransform gives CV_32F image */
- imgtmp.convertTo(*imgptr, CV_8U);
-
- /* Cleanup */
- imgtmp.release();
-}
-
-static void img_cv_threshold (class cv::Mat *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_Threshold *data_cast;
- data_cast = (struct Img_Iface_Data_Threshold *)data;
-
- /* Threshold type */
- int thr_typ;
- thr_typ = data_cast->thr_typ;
- /* Threshold value */
- int thr_val;
- thr_val = data_cast->thr_val;
- if (thr_val == -1) {
- thr_typ |= cv::THRESH_OTSU;
- }
-
- /* Threshold */
- cv::threshold(*imgptr, *imgptr, thr_val, 0xFF, thr_typ);
-}
-
-/* ----- Histograms */
-static void img_cv_histogram (class cv::Mat *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_Histogram *data_cast;
- data_cast = (struct Img_Iface_Data_Histogram *)data;
-
- /* Contours */
- class cv::Mat *hist;
- hist = data_cast->hist_c0;
- class cv::Mat *hist_img;
- hist_img = data_cast->hist_img;
-
- /* Write components into cmp_img[] */
- int h_size = 256;
- float h_range_arr[] = {0.0, 256.0};
- const float *h_range = {h_range_arr};
- cv::calcHist(imgptr, 1, 0, cv::Mat(), *hist, 1, &h_size, &h_range,
- true, false);
-
- /* Init */
- hist_img->setTo(cv::Scalar(0));
-
- /* Normalize the result to [0, hist_img->rows - 1] */
- cv::normalize(*hist, *hist, 0, hist_img->rows - 1, cv::NORM_MINMAX, -1,
- cv::Mat());
-
- /* Draw hist into hist_img */
- int i;
- for(i = 0; i < 256; i++ ) {
- cv::line(*hist_img, cv::Point(i, hist_img->rows - 0),
- cv::Point(i, hist_img->rows - hist->at<float>(i)),
- cv::Scalar(255, 0, 0), 1, 8, 0);
- }
-
- /* Show histogram */
- img_iface_show_hist_c1();
-}
-
-static void img_cv_histogram_c3 (class cv::Mat *imgptr, void *data)
-{
- class cv::Mat cmp_img[3];
-
- /* Write components into cmp_img[] */
- cv::split(*imgptr, cmp_img);
-
- /* Data */
- struct Img_Iface_Data_Histogram *data_cast;
- data_cast = (struct Img_Iface_Data_Histogram *)data;
-
- /* Contours */
- class cv::Mat *hist_c0;
- hist_c0 = data_cast->hist_c0;
- class cv::Mat *hist_c1;
- hist_c1 = data_cast->hist_c1;
- class cv::Mat *hist_c2;
- hist_c2 = data_cast->hist_c2;
- class cv::Mat *hist_img;
- hist_img = data_cast->hist_img;
-
- /* Write components into cmp_img[] */
- int h_size = 256;
- float h_range_arr[] = {0.0, 256.0};
- const float *h_range = {h_range_arr};
- cv::calcHist(&cmp_img[0], 1, 0, cv::Mat(), *hist_c0, 1, &h_size,
- &h_range, true, false);
- cv::calcHist(&cmp_img[1], 1, 0, cv::Mat(), *hist_c1, 1, &h_size,
- &h_range, true, false);
- cv::calcHist(&cmp_img[2], 1, 0, cv::Mat(), *hist_c2, 1, &h_size,
- &h_range, true, false);
-
- /* Init */
- hist_img->setTo(cv::Scalar(0));
-
- /* Normalize the result to [0, hist_img->rows - 1] */
- cv::normalize(*hist_c0, *hist_c0, 0, hist_img->rows - 1,
- cv::NORM_MINMAX, -1, cv::Mat());
- cv::normalize(*hist_c1, *hist_c1, 0, hist_img->rows - 1,
- cv::NORM_MINMAX, -1, cv::Mat());
- cv::normalize(*hist_c2, *hist_c2, 0, hist_img->rows - 1,
- cv::NORM_MINMAX, -1, cv::Mat());
-
- /* Draw hist into hist_img */
- int i;
- int j;
- for(i = 0; i < 256; i++ ) {
- cv::line(*hist_img, cv::Point(3*i, hist_img->rows - 0),
- cv::Point(3*i,
- hist_img->rows - hist_c0->at<float>(i)),
- cv::Scalar(255, 0, 0), 1, 8, 0);
- }
- for(i = 0; i < 256; i++ ) {
- cv::line(*hist_img, cv::Point(3*i + 1, hist_img->rows - 0),
- cv::Point(3*i+1,
- hist_img->rows - hist_c1->at<float>(i)),
- cv::Scalar(0, 255, 0), 1, 8, 0);
- }
- for(i = 0; i < 256; i++ ) {
- cv::line(*hist_img, cv::Point(3*i + 2, hist_img->rows - 0),
- cv::Point(3*i + 2,
- hist_img->rows - hist_c2->at<float>(i)),
- cv::Scalar(0, 0, 255), 1, 8, 0);
- }
-
- /* Show histogram */
- img_iface_show_hist_c3();
-
- /* Cleanup */
- cmp_img[0].release();
- cmp_img[1].release();
- cmp_img[2].release();
-}
-
-/* ----- Structural analysis and shape descriptors */
-static void img_cv_contours (class cv::Mat *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_Contours *data_cast;
- data_cast = (struct Img_Iface_Data_Contours *)data;
-
- /* Contours */
- std::vector <std::vector <class cv::Point_ <int>>> *contours;
- contours = data_cast->contours;
- class cv::Mat *hierarchy;
- hierarchy = data_cast->hierarchy;
-
- /* Get contours */
- cv::findContours(*imgptr, *contours, *hierarchy, CV_RETR_EXTERNAL,
- CV_CHAIN_APPROX_SIMPLE);
-
- /* Set image to black */
- imgptr->setTo(cv::Scalar(0));
-
- /* Draw contours in color */
- cv::drawContours(*imgptr, *contours, -1, cv::Scalar(255), 1, 8,
- *hierarchy, 1, cvPoint(0, 0));
-}
-
-static void img_cv_contours_size (void *data)
-{
- /* Data */
- struct Img_Iface_Data_Contours_Size *data_cast;
- data_cast = (struct Img_Iface_Data_Contours_Size *)data;
-
- /* Contours */
- std::vector <std::vector <class cv::Point_ <int>>> *contours;
- contours = data_cast->contours;
-
- /* Get area and perimeter */
- int i;
- for (i = 0; i < contours->size(); i++) {
- data_cast->area[i] = cv::contourArea(
- (*contours)[i], false);
- data_cast->perimeter[i] = cv::arcLength(
- (*contours)[i], true);
- }
-}
-
-static void img_cv_bounding_rect (class cv::Mat *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_Bounding_Rect *data_cast;
- data_cast = (struct Img_Iface_Data_Bounding_Rect *)data;
-
- /* Contours */
- std::vector <class cv::Point_ <int>> *contour;
- contour = data_cast->contour;
- /* Rotated rectangle */
- class cv::Rect_ <int> *rect;
- rect = data_cast->rect;
- /* Show rectangle ? */
- bool show;
- show = data_cast->show;
-
- /* Get rectangle */
- *rect = cv::boundingRect(*contour);
-
- /* Draw rectangle */
- class cv::Point_<float> vertices[4];
- if (show) {
- vertices[0].x = rect->x;
- vertices[0].y = rect->y;
- vertices[1].x = rect->x + rect->width;
- vertices[1].y = rect->y;
- vertices[2].x = rect->x + rect->width;
- vertices[2].y = rect->y + rect->height;
- vertices[3].x = rect->x;
- vertices[3].y = rect->y + rect->height;
- cv::line(*imgptr, cv::Point(vertices[0].x, vertices[0].y),
- cv::Point(vertices[1].x, vertices[1].y),
- CV_RGB(0, 0, 255), 1, 8, 0);
- cv::line(*imgptr, cv::Point(vertices[1].x, vertices[1].y),
- cv::Point(vertices[2].x, vertices[2].y),
- CV_RGB(0, 0, 255), 1, 8, 0);
- cv::line(*imgptr, cv::Point(vertices[2].x, vertices[2].y),
- cv::Point(vertices[3].x, vertices[3].y),
- CV_RGB(0, 0, 255), 1, 8, 0);
- cv::line(*imgptr, cv::Point(vertices[3].x, vertices[3].y),
- cv::Point(vertices[0].x, vertices[0].y),
- CV_RGB(0, 0, 255), 1, 8, 0);
- }
-}
-
-static void img_cv_fit_ellipse (class cv::Mat *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_MinARect *data_cast;
- data_cast = (struct Img_Iface_Data_MinARect *)data;
-
- /* Contours */
- std::vector <class cv::Point_ <int>> *contour;
- contour = data_cast->contour;
- /* Rotated rectangle */
- class cv::RotatedRect *rect;
- rect = data_cast->rect;
- /* Show rectangle ? */
- bool show;
- show = data_cast->show;
-
- /* Get rectangle */
- *rect = cv::fitEllipse(*contour);
-
- /* Draw rectangle */
- class cv::Point_<float> vertices[4];
- if (show) {
- rect->points(vertices);
- cv::line(*imgptr, cv::Point(vertices[0].x, vertices[0].y),
- cv::Point(vertices[1].x, vertices[1].y),
- CV_RGB(0, 0, 255), 1, 8, 0);
- cv::line(*imgptr, cv::Point(vertices[1].x, vertices[1].y),
- cv::Point(vertices[2].x, vertices[2].y),
- CV_RGB(0, 0, 255), 1, 8, 0);
- cv::line(*imgptr, cv::Point(vertices[2].x, vertices[2].y),
- cv::Point(vertices[3].x, vertices[3].y),
- CV_RGB(0, 0, 255), 1, 8, 0);
- cv::line(*imgptr, cv::Point(vertices[3].x, vertices[3].y),
- cv::Point(vertices[0].x, vertices[0].y),
- CV_RGB(0, 0, 255), 1, 8, 0);
- }
-}
-
-static void img_cv_min_area_rect (class cv::Mat *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_MinARect *data_cast;
- data_cast = (struct Img_Iface_Data_MinARect *)data;
-
- /* Contours */
- std::vector <class cv::Point_ <int>> *contour;
- contour = data_cast->contour;
- /* Rotated rectangle */
- class cv::RotatedRect *rect;
- rect = data_cast->rect;
- /* Show rectangle ? */
- bool show;
- show = data_cast->show;
-
- /* Get rectangle */
- *rect = cv::minAreaRect(*contour);
-
- /* Draw rectangle */
- class cv::Point_<float> vertices[4];
- if (show) {
- rect->points(vertices);
- cv::line(*imgptr, cv::Point(vertices[0].x, vertices[0].y),
- cv::Point(vertices[1].x, vertices[1].y),
- CV_RGB(0, 0, 255), 1, 8, 0);
- cv::line(*imgptr, cv::Point(vertices[1].x, vertices[1].y),
- cv::Point(vertices[2].x, vertices[2].y),
- CV_RGB(0, 0, 255), 1, 8, 0);
- cv::line(*imgptr, cv::Point(vertices[2].x, vertices[2].y),
- cv::Point(vertices[3].x, vertices[3].y),
- CV_RGB(0, 0, 255), 1, 8, 0);
- cv::line(*imgptr, cv::Point(vertices[3].x, vertices[3].y),
- cv::Point(vertices[0].x, vertices[0].y),
- CV_RGB(0, 0, 255), 1, 8, 0);
- }
-}
-
-/* ----- Feature detection */
-static void img_cv_hough_circles (class cv::Mat *imgptr, void *data)
-{
- /* Data */
- struct Img_Iface_Data_Hough_Circles *data_cast;
- data_cast = (struct Img_Iface_Data_Hough_Circles *)data;
-
- /* Contours */
- std::vector <class cv::Vec <float, 3>> *circles;
- circles = data_cast->circles;
- /* Parameters */
- double dist_min;
- double param_1;
- double param_2;
- int radius_min;
- int radius_max;
- dist_min = data_cast->dist_min;
- param_1 = data_cast->param_1;
- param_2 = data_cast->param_2;
- radius_min = data_cast->radius_min;
- radius_max = data_cast->radius_max;
-
- /* Get circles */
- cv::HoughCircles(*imgptr, *circles, CV_HOUGH_GRADIENT, 1, dist_min,
- param_1, param_2, radius_min, radius_max);
-
- /* Set image to black */
- imgptr->setTo(cv::Scalar(0));
-
- /* Draw circles */
- class cv::Point_ <int> center;
- int radius;
- int i;
- for (i = 0; i < circles->size(); i++) {
- center.x = cvRound((*circles)[i][0]);
- center.y = cvRound((*circles)[i][1]);
- radius = cvRound((*circles)[i][2]);
-
- /* Draw the circle center */
-/* cv::circle(*imgptr, center, 3,
- cv::Scalar(0, 255, 0), -1, 8, 0);*/
-
- /* Draw the circle outline */
- cv::circle(*imgptr, center, radius,
- cv::Scalar(250), 1, 8, 0);
- }
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/image/src/img_iface.cpp b/modules/image/src/img_iface.cpp
deleted file mode 100644
index e13449a..0000000
--- a/modules/image/src/img_iface.cpp
+++ /dev/null
@@ -1,1776 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* errno */
- #include <cerrno>
- /* INFINITY */
- #include <cmath>
- /* snprintf() */
- #include <cstdio>
-
-/* Packages ------------------------------------------------------------------*/
- /* openCV */
- #include <opencv2/opencv.hpp>
-
-/* Project -------------------------------------------------------------------*/
- /* load_image_file() */
- #include "save.hpp"
- /* user_iface_log */
- #include "user_iface.hpp"
-
-/* Module --------------------------------------------------------------------*/
- /* img_alx_act() */
- #include "img_alx.hpp"
- /* img_cv_act() */
- #include "img_cv.hpp"
- /* img_zb_act() */
- #include "img_zbar.hpp"
- /* OCR */
- #include "img_ocr.hpp"
- /* ORB */
- #include "img_orb.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 std::vector <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 std::vector <class cv::Vec <float, 3>> circles;
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
- /* img_alx */
-static void img_iface_local_max (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_value (void *data);
- /* ROI */
-static void img_iface_set_ROI (void *data);
-static void img_iface_set_ROI_2rect (void *data);
- /* Operations on Arrays */
-static void img_iface_and_2ref (void);
-static void img_iface_not (void);
-static void img_iface_or_2ref (void);
-static void img_iface_component (void *data);
- /* Imgproc: Image processing */
- /* Image filtering */
-static void img_iface_dilate (void *data);
-static void img_iface_erode (void *data);
-static void img_iface_dilate_erode (void *data);
-static void img_iface_erode_dilate (void *data);
-static void img_iface_smooth (void *data);
-static void img_iface_sobel (void *data);
- /* Geometric image transformations */
-static void img_iface_rotate_orto (void *data);
-static void img_iface_rotate (void *data);
-static void img_iface_rotate_2rect (void *data);
- /* Miscellaneous image transformations */
-static void img_iface_adaptive_thr (void *data);
-static void img_iface_cvt_color (void *data);
-static void img_iface_distance_transform (void);
-static void img_iface_threshold (void *data);
- /* Histograms */
-static void img_iface_histogram (void *data);
-static void img_iface_histogram_c3 (void *data);
- /* Structural analysis and shape descriptors */
-static void img_iface_contours (void *data);
-static void img_iface_contours_size (void *data);
-static void img_iface_bounding_rect (void *data);
-static void img_iface_fit_ellipse (void *data);
-static void img_iface_min_area_rect (void *data);
- /* Feature detection */
-static void img_iface_hough_circles (void *data);
-
- /* img_zbar */
-static void img_iface_decode (void *data);
- /* img_ocr */
-static void img_iface_read (void *data);
- /* img_orb */
-static void img_iface_align (void);
- /* img_iface */
-static void img_iface_apply (void);
-static void img_iface_discard (void);
-static void img_iface_save_mem (void *data);
-static void img_iface_load_mem (void *data);
-static void img_iface_save_ref (void);
- /* save */
-static void img_iface_save_file (void);
-static void img_iface_save_update (void);
-
-
-/******************************************************************************
- ******* global functions *****************************************************
- ******************************************************************************/
-void img_iface_init (void)
-{
- cv::namedWindow(WIN_NAME_HIST, cv::WINDOW_NORMAL);
- cv::namedWindow(WIN_NAME_IMG, cv::WINDOW_NORMAL);
-
- hist_img_c1.release();
- hist_img_c1 = cv::Mat::zeros(cv::Size(256, 100), CV_8UC3);
- hist_img_c3.release();
- hist_img_c3 = cv::Mat::zeros(cv::Size(256 * 3, 100), CV_8UC3);
-}
-
-void img_iface_cleanup_main (void)
-{
- int i;
-
- for (i = 0; i < IMG_MEM_SIZE; i++) {
- image_mem[i].release();
- }
- image_ref.release();
-
- cv::destroyAllWindows();
-}
-
-void img_iface_load (const char *fpath, const char *fname)
-{
- char file_path [FILENAME_MAX];
- char file_name [FILENAME_MAX];
-
- /* Init */
- img_iface_init();
-
- /* Set file_path */
- if (!fpath) {
- snprintf(file_path, FILENAME_MAX, "%s", saved_path);
- } else {
- snprintf(file_path, FILENAME_MAX, "%s", fpath);
- }
-
- /* Set file_name */
- if (!fname) {
- /* Request file name */
- user_iface_fname(file_path, file_name);
- } else {
- snprintf(file_name, FILENAME_MAX, "%s", fname);
- }
-
- /* Load file */
- errno = 0;
- load_image_file(file_path, file_name);
-
- if (!errno) {
- /* Make a static copy of image */
- image.copyTo(image_copy_old);
- image.copyTo(image_copy_tmp);
- }
-}
-
-void img_iface_cleanup (void)
-{
- image_copy_old.release();
- image_copy_tmp.release();
- histogram_c0.release();
- histogram_c1.release();
- histogram_c2.release();
- hist_img_c1.release();
- hist_img_c3.release();
-}
-
-void img_iface_act (int action, void *data)
-{
- switch (action) {
- /* img_alx */
- case IMG_IFACE_ACT_LOCAL_MAX:
- img_iface_local_max();
- break;
- case IMG_IFACE_ACT_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_VALUE:
- img_iface_pixel_value(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;
- /* Geometric image transformations */
- 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_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_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_value (void *data)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Data */
- struct Img_Iface_Data_Pixel_Value data_tmp;
- unsigned char val;
- if (!data) {
- data_tmp.val = &val;
-
- /* Ask user */
- char title [80];
- snprintf(title, 80, "x:");
- data_tmp.x = user_iface_getint(0, 0,
- image_copy_tmp.cols,
- title, NULL);
-
- snprintf(title, 80, "y:");
- data_tmp.y = user_iface_getint(0, 0,
- image_copy_tmp.rows,
- title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Contours size */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_PIXEL_VALUE, data);
-
- /* Write into log */
- struct Img_Iface_Data_Pixel_Value *data_cast;
- data_cast = (struct Img_Iface_Data_Pixel_Value *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Pixel value: (%i, %i): %i",
- data_cast->x,
- data_cast->y,
- *(data_cast->val));
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-}
-
-/* ----- ------- ROI */
-static void img_iface_set_ROI (void *data)
-{
- /* Data */
- struct Img_Iface_Data_SetROI data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Origin: x:");
- data_tmp.rect.x = user_iface_getint(0, 0,
- image_copy_tmp.cols,
- title, NULL);
-
- snprintf(title, 80, "Origin: y:");
- data_tmp.rect.y = user_iface_getint(0, 0,
- image_copy_tmp.rows,
- title, NULL);
-
- snprintf(title, 80, "Width:");
- data_tmp.rect.width = user_iface_getint(1,
- image_copy_tmp.cols - data_tmp.rect.x,
- image_copy_tmp.cols - data_tmp.rect.x,
- title, NULL);
-
- snprintf(title, 80, "Height:");
- data_tmp.rect.height = user_iface_getint(1,
- image_copy_tmp.rows - data_tmp.rect.y,
- image_copy_tmp.rows - data_tmp.rect.y,
- title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_SetROI *data_cast;
- data_cast = (struct Img_Iface_Data_SetROI *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "ROI: (%i,%i) w=%i,h=%i",
- data_cast->rect.x,
- data_cast->rect.y,
- data_cast->rect.width,
- data_cast->rect.height);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Set ROI */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_SET_ROI, data);
-}
-
-static void img_iface_set_ROI_2rect (void *data)
-{
- /* Data */
- struct Img_Iface_Data_SetROI data_tmp;
- if (!data) {
- data_tmp.rect.x = rectangle.x;
- data_tmp.rect.y = rectangle.y;
- data_tmp.rect.width = rectangle.width;
- data_tmp.rect.height = rectangle.height;
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_SetROI *data_cast;
- data_cast = (struct Img_Iface_Data_SetROI *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "ROI: (%i,%i) w=%i,h=%i",
- data_cast->rect.x,
- data_cast->rect.y,
- data_cast->rect.width,
- data_cast->rect.height);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Set ROI */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_SET_ROI, data);
-}
-
-/* ----- ------- Operations on arrays */
-static void img_iface_and_2ref (void)
-{
- /* Must have same channels */
- if (image_copy_tmp.channels() != image_ref.channels()) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Bitwise AND");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Bitwise AND to reference */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_AND_2REF, (void *)&image_ref);
-}
-
-static void img_iface_not (void)
-{
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Invert color");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Bitwise NOT */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_NOT, NULL);
-}
-
-static void img_iface_or_2ref (void)
-{
- /* Must have same channels */
- if (image_copy_tmp.channels() != image_ref.channels()) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Bitwise OR");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Bitwise OR to reference */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_OR_2REF, (void *)&image_ref);
-}
-
-static void img_iface_component (void *data)
-{
- /* Must have at least 3 channels */
- if (image_copy_tmp.channels() < 3) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Data */
- struct Img_Iface_Data_Component data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Component:");
- data_tmp.cmp = user_iface_getint(0, 0,
- image_copy_tmp.channels() - 1,
- title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Component *data_cast;
- data_cast = (struct Img_Iface_Data_Component *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Component %i",
- data_cast->cmp);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Filter: extract component */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_COMPONENT, data);
-}
-
-/* ----- Imgproc: Image processing */
-/* ----- ------- Image filtering */
-static void img_iface_dilate (void *data)
-{
- /* Data */
- struct Img_Iface_Data_Dilate_Erode data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Iterations:");
- data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Dilate_Erode *data_cast;
- data_cast = (struct Img_Iface_Data_Dilate_Erode *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Dilate i=%i",
- data_cast->i);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Dilate */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data);
-}
-
-static void img_iface_erode (void *data)
-{
- /* Data */
- struct Img_Iface_Data_Dilate_Erode data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Iterations:");
- data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Dilate_Erode *data_cast;
- data_cast = (struct Img_Iface_Data_Dilate_Erode *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Erode i=%i",
- data_cast->i);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Erode */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data);
-}
-
-static void img_iface_dilate_erode (void *data)
-{
- /* Data */
- struct Img_Iface_Data_Dilate_Erode data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Iterations:");
- data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Dilate_Erode *data_cast;
- data_cast = (struct Img_Iface_Data_Dilate_Erode *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Dilate-erode i=%i",
- data_cast->i);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Dilate */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data);
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data);
-}
-
-static void img_iface_erode_dilate (void *data)
-{
- /* Data */
- struct Img_Iface_Data_Dilate_Erode data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Iterations:");
- data_tmp.i = user_iface_getint(1, 1, INFINITY, title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Dilate_Erode *data_cast;
- data_cast = (struct Img_Iface_Data_Dilate_Erode *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Erode-dilate i=%i",
- data_cast->i);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Dilate */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_ERODE, data);
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_DILATE, data);
-}
-
-static void img_iface_smooth (void *data)
-{
- /* Data */
- struct Img_Iface_Data_Smooth data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Method: MEAN=1, GAUSS=2, MEDIAN=3");
- data_tmp.method = user_iface_getint(1, 3, 3, title, NULL);
-
- snprintf(title, 80, "Kernel size: 3, 5, 7, ...");
- data_tmp.ksize = user_iface_getint(3, 3, INFINITY, title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Smooth *data_cast;
- data_cast = (struct Img_Iface_Data_Smooth *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Smooth mth=%i [%ix%i]",
- data_cast->method,
- data_cast->ksize,
- data_cast->ksize);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Filter: smooth */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_SMOOTH, data);
-}
-
-static void img_iface_sobel (void *data)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Data */
- struct Img_Iface_Data_Sobel data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Order of the derivative x");
- data_tmp.dx = user_iface_getint(0, 1, 10, title, NULL);
-
- snprintf(title, 80, "Order of the derivative y");
- data_tmp.dy = user_iface_getint(0, 1, 10, title, NULL);
-
- snprintf(title, 80, "Size of the extended Sobel kernel (-1 -> Scharr");
- data_tmp.ksize = user_iface_getint(-1, 3, 7, title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Sobel *data_cast;
- data_cast = (struct Img_Iface_Data_Sobel *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Sobel dx=%i;dy=%i [ks=%i]",
- data_cast->dx,
- data_cast->dy,
- data_cast->ksize);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Filter: sobel */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_SOBEL, data);
-}
-
-/* ----- ------- Geometric image transformations */
-static void img_iface_rotate_orto (void *data)
-{
- /* Data */
- struct Img_Iface_Data_Rotate_Orto data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Rotate (counterclockwise) n * pi/2 rad; n:");
- data_tmp.n = user_iface_getint(1, 1, 3, title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Rotate_Orto *data_cast;
- data_cast = (struct Img_Iface_Data_Rotate_Orto *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Rotate %i * pi/2 rad",
- data_cast->n);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Rotate ortogonally */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE_ORTO, data);
-}
-
-static void img_iface_rotate (void *data)
-{
- /* Data */
- struct Img_Iface_Data_Rotate data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Center: x:");
- data_tmp.center.x = user_iface_getdbl(0, 0, INFINITY, title, NULL);
-
- snprintf(title, 80, "Center: y:");
- data_tmp.center.y = user_iface_getdbl(0, 0, INFINITY, title, NULL);
-
- snprintf(title, 80, "Angle: (deg)");
- data_tmp.angle = user_iface_getdbl(-INFINITY, 0, INFINITY, title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Rotate *data_cast;
- data_cast = (struct Img_Iface_Data_Rotate *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Rotate (%.2f,%.2f) %lfº",
- data_cast->center.x,
- data_cast->center.y,
- data_cast->angle);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Rotate ortogonally */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE, data);
-}
-
-static void img_iface_rotate_2rect (void *data)
-{
- /* Data */
- struct Img_Iface_Data_Rotate data_tmp;
- if (!data) {
- data_tmp.center.x = rectangle_rot.center.x;
- data_tmp.center.y = rectangle_rot.center.y;
- data_tmp.angle = rectangle_rot.angle;
-
- /* If angle is < -45º, it is taking into acount the incorrect side */
- if (data_tmp.angle < -45.0) {
- data_tmp.angle += 90.0;
- }
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Rotate *data_cast;
- data_cast = (struct Img_Iface_Data_Rotate *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Rotate to rectangle");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Rotate ortogonally */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_ROTATE, data);
-}
-
-/* ----- ------- Miscellaneous image transformations */
-static void img_iface_adaptive_thr (void *data)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Data */
- struct Img_Iface_Data_Adaptive_Thr data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Method: MEAN=0, GAUSS=1");
- data_tmp.method = user_iface_getint(0, 1, 1, title, NULL);
-
- snprintf(title, 80, "Type: BIN=0, BIN_INV=1");
- data_tmp.thr_typ = user_iface_getint(0, 0, 1, title, NULL);
-
- snprintf(title, 80, "Kernel size: 3, 5, 7, ...");
- data_tmp.ksize = user_iface_getint(3, 3, INFINITY, title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Adaptive_Thr *data_cast;
- data_cast = (struct Img_Iface_Data_Adaptive_Thr *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Threshold mth=%i, typ=%i, ks=%i",
- data_cast->method,
- data_cast->thr_typ,
- data_cast->ksize);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Filter: adaptive threshold */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_ADAPTIVE_THRESHOLD, data);
-}
-
-static void img_iface_cvt_color (void *data)
-{
- /* Must have at least 3 channels */
- if (image_copy_tmp.channels() < 3) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Data */
- struct Img_Iface_Data_Cvt_Color data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Method: BGR2GRAY = 6, BGR2HSV = 40");
- data_tmp.method = user_iface_getint(0, 0,
- cv::COLOR_COLORCVT_MAX,
- title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Cvt_Color *data_cast;
- data_cast = (struct Img_Iface_Data_Cvt_Color *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Convert color %i",
- data_cast->method);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Filter: BGR to gray */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_CVT_COLOR, data);
-}
-
-static void img_iface_distance_transform (void)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Distance transform");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Distance transform */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_DISTANCE_TRANSFORM, NULL);
-}
-
-static void img_iface_threshold (void *data)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Data */
- struct Img_Iface_Data_Threshold data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Type: BIN=0, BIN_INV=1, TRUNC=2, TOZ=3, TOZ_INV=4");
- data_tmp.thr_typ = user_iface_getint(0, 0, 4, title, NULL);
-
- snprintf(title, 80, "Value: 0 to 255 (or -1 for Otsu's algorithm)");
- data_tmp.thr_val = user_iface_getint(-1, 0, 255, title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Threshold *data_cast;
- data_cast = (struct Img_Iface_Data_Threshold *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Threshold typ=%i, val=%i",
- data_cast->thr_typ,
- data_cast->thr_val);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Filter: threshold */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_THRESHOLD, data);
-}
-
-/* ----- ------- Histograms */
-static void img_iface_histogram (void *data)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Data */
- struct Img_Iface_Data_Histogram data_tmp;
- if (!data) {
- data_tmp.hist_c0 = &histogram_c0;
- data_tmp.hist_img = &hist_img_c1;
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Histogram");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Histogram */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_HISTOGRAM, data);
-}
-
-static void img_iface_histogram_c3 (void *data)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 3) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Data */
- struct Img_Iface_Data_Histogram data_tmp;
- if (!data) {
- data_tmp.hist_c0 = &histogram_c0;
- data_tmp.hist_c1 = &histogram_c1;
- data_tmp.hist_c2 = &histogram_c2;
- data_tmp.hist_img = &hist_img_c3;
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Histogram (3 channels)");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Histogram */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_HISTOGRAM_C3, data);
-}
-
-/* ----- ------- Structural analysis and shape descriptors */
-static void img_iface_contours (void *data)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Data */
- struct Img_Iface_Data_Contours data_tmp;
- if (!data) {
- data_tmp.contours = &contours;
- data_tmp.hierarchy = &hierarchy;
-
- data = (void *)&data_tmp;
- }
-
- /* Contours */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_CONTOURS, data);
-
- /* Write into log */
- struct Img_Iface_Data_Contours *data_cast;
- data_cast = (struct Img_Iface_Data_Contours *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Contours n=%i",
- (int)data_cast->contours->size());
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-}
-
-static void img_iface_contours_size (void *data)
-{
- /* Data */
- struct Img_Iface_Data_Contours_Size data_tmp;
- if (!data) {
- data_tmp.contours = &contours;
- data_tmp.area = area;
- data_tmp.perimeter = perimeter;
-
- data = (void *)&data_tmp;
- }
-
- /* Contours size */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_CONTOURS_SIZE, data);
-
- /* Write into log */
- struct Img_Iface_Data_Contours_Size *data_cast;
- data_cast = (struct Img_Iface_Data_Contours_Size *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Contours size:");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
- int i;
- for (i = 0; i < data_cast->contours->size(); i++) {
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "cnt[%i]: A=%lf; P=%lf;",
- i,
- data_cast->area[i],
- data_cast->perimeter[i]);
- user_iface_log.lvl[user_iface_log.len] = 2;
- (user_iface_log.len)++;
- }
-}
-
-static void img_iface_bounding_rect (void *data)
-{
- /* Data */
- struct Img_Iface_Data_Bounding_Rect data_tmp;
- if (!data) {
- if(!contours.size()) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len],
- LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
- data_tmp.contour = &(contours[0]);
- data_tmp.rect = &rectangle;
- data_tmp.show = true;
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Bounding rectangle");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Enclosing rectangle */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_BOUNDING_RECT, data);
-}
-
-static void img_iface_fit_ellipse (void *data)
-{
- /* Data */
- struct Img_Iface_Data_MinARect data_tmp;
- if (!data) {
- if(!contours.size()) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len],
- LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
- data_tmp.contour = &(contours[0]);
-
- data_tmp.rect = &rectangle_rot;
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Fit ellipse");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Enclosing rectangle */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_FIT_ELLIPSE, data);
-}
-
-static void img_iface_min_area_rect (void *data)
-{
- /* Data */
- struct Img_Iface_Data_MinARect data_tmp;
- if (!data) {
- if(!contours.size()) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len],
- LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
- data_tmp.contour = &(contours[0]);
- data_tmp.rect = &rectangle_rot;
- data_tmp.show = true;
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Min area rectangle");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Enclosing rectangle */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_MIN_AREA_RECT, data);
-}
-
-/* ----- ------- Feature detection */
-static void img_iface_hough_circles (void *data)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Data */
- struct Img_Iface_Data_Hough_Circles data_tmp;
- if (!data) {
- data_tmp.circles = &circles;
-
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Minimum distance:");
- data_tmp.dist_min = user_iface_getdbl(0, 5, INFINITY, title, NULL);
-
- snprintf(title, 80, "param 1:");
- data_tmp.param_1 = user_iface_getdbl(0, 200, INFINITY, title, NULL);
-
- snprintf(title, 80, "param 2:");
- data_tmp.param_2 = user_iface_getdbl(0, 100, INFINITY, title, NULL);
-
- snprintf(title, 80, "Minimum radius");
- data_tmp.radius_min = user_iface_getint(0, 10, INFINITY, title, NULL);
-
- snprintf(title, 80, "Maximum radius");
- data_tmp.radius_max = user_iface_getint(0, 0, INFINITY, title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Circles */
- img_cv_act(&image_copy_tmp, IMG_CV_ACT_HOUGH_CIRCLES, data);
-
- /* Write into log */
- struct Img_Iface_Data_Hough_Circles *data_cast;
- data_cast = (struct Img_Iface_Data_Hough_Circles *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Circles n=%i",
- (int)data_cast->circles->size());
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-}
-
-/* img_zbar ------------------------------------------------------------------*/
-static void img_iface_decode (void *data)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Data */
- struct Img_Iface_Data_Decode data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Type of code: (0 for all)");
- data_tmp.code_type = (enum zbar::zbar_symbol_type_e)
- user_iface_getint(0, 0, INT_MAX,
- title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Decode *data_cast;
- data_cast = (struct Img_Iface_Data_Decode *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Detect codes c=%i",
- data_cast->code_type);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Decode */
- img_zb_act(&image_copy_tmp, IMG_ZB_ACT_DECODE, data);
-
- /* Results */
- if (!zb_codes.n) {
- /* No text found */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! No code detected");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
- } else {
- /* Write results into log */
- int i;
- for (i = 0; i < zb_codes.n; i++) {
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "%s -- '%s'",
- zb_codes.arr[i].sym_name,
- zb_codes.arr[i].data);
- user_iface_log.lvl[user_iface_log.len] = 2;
- (user_iface_log.len)++;
- }
- }
-}
-
-/* img_ocr -------------------------------------------------------------------*/
-static void img_iface_read (void *data)
-{
- /* Must have 1 channel */
- if (image_copy_tmp.channels() != 1) {
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! Invalid input");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- return;
- }
-
- /* Data */
- struct Img_Iface_Data_Read data_tmp;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "Language: ENG = 0, SPA = 1, CAT = 2");
- data_tmp.lang = user_iface_getint(0, 1, 2, title, NULL);
-
- snprintf(title, 80, "Config: none = 0, Price = 1");
- data_tmp.conf = user_iface_getint(0, 1, 2, title, NULL);
-
- data = (void *)&data_tmp;
- }
-
- /* Write into log */
- struct Img_Iface_Data_Read *data_cast;
- data_cast = (struct Img_Iface_Data_Read *)data;
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "OCR (lang=%i) [c=%i]",
- data_cast->lang,
- data_cast->conf);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Adapt image data */
- data_cast->img.data = image_copy_tmp.data;
- data_cast->img.width = image_copy_tmp.size().width;
- data_cast->img.height = image_copy_tmp.size().height;
- data_cast->img.B_per_pix = image_copy_tmp.channels();
- data_cast->img.B_per_line = image_copy_tmp.step1();
-
- /* OCR */
- img_ocr_act(IMG_OCR_ACT_READ, data);
-
- /* Results */
- if (img_ocr_text[0] == '\0') {
- /* No text found */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "! No text detected");
- user_iface_log.lvl[user_iface_log.len] = 2;
- (user_iface_log.len)++;
- }
-}
-
-/* img_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_iface -----------------------------------------------------------------*/
-static void img_iface_apply (void)
-{
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Apply changes");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Write tmp into old */
- image_copy_old.release();
- image_copy_tmp.copyTo(image_copy_old);
-}
-
-static void img_iface_discard (void)
-{
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Discard changes");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Discard tmp image copy */
- image_copy_tmp.release();
- image_copy_old.copyTo(image_copy_tmp);
-}
-
-static void img_iface_save_mem (void *data)
-{
- /* Which memory to use */
- int x;
- if (!data) {
- /* Ask user */
- char title [80];
- snprintf(title, 80, "mem_X; X:");
- x = user_iface_getint(0, 0, IMG_MEM_SIZE - 1, title, NULL);
- } else {
- x = *(int *)data;
- }
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Save to mem_%i", x);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Write into mem */
- image_mem[x].release();
- image_copy_tmp.copyTo(image_mem[x]);
-}
-
-static void img_iface_load_mem (void *data)
-{
- /* Which memory to use */
- int x;
- if (!data) {
- /* Ask user which memory to use */
- char title [80];
- snprintf(title, 80, "mem_X; X:");
- x = user_iface_getint(0, 0, IMG_MEM_SIZE - 1, title, NULL);
- } else {
- x = *(int *)data;
- }
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Load from mem_%i", x);
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- if (!image_mem[x].empty()) {
- /* Discard tmp image copy */
- image_copy_tmp.release();
-
- /* Load from mem */
- image_mem[x].copyTo(image_copy_tmp);
- }
-}
-
-static void img_iface_save_ref (void)
-{
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Save to reference");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Write into ref */
- image_ref.release();
- image_copy_tmp.copyTo(image_ref);
- image_ref = image_copy_tmp;
-}
-
-/* save ----------------------------------------------------------------------*/
-static void img_iface_save_file (void)
-{
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Save as...");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Write into image struct (save.c) */
- image.release();
- image_copy_tmp.copyTo(image);
-
- /* Save into file */
- save_image_file(NULL, NULL);
-}
-
-static void img_iface_save_update (void)
-{
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Save: update img");
- user_iface_log.lvl[user_iface_log.len] = 1;
- (user_iface_log.len)++;
-
- /* Write into image struct (save.c) */
- image.release();
- image_copy_tmp.copyTo(image);
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/image/src/img_zbar.cpp b/modules/image/src/img_zbar.cpp
deleted file mode 100644
index 1c9b412..0000000
--- a/modules/image/src/img_zbar.cpp
+++ /dev/null
@@ -1,101 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* INT_MAX */
- #include <climits>
- /* snprintf() */
- #include <cstdio>
-
-/* Packages ------------------------------------------------------------------*/
- /* opencv */
- #include <opencv2/opencv.hpp>
- /* zbar */
- #include <zbar.h>
-
-/* Module --------------------------------------------------------------------*/
- /* data & zb_codes */
- #include "img_iface.hpp"
-
- #include "img_zbar.hpp"
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void img_zb_decode (class cv::Mat *imgptr, void *data);
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void img_zb_act (class cv::Mat *imgptr, int action, void *data)
-{
- switch (action) {
- case IMG_ZB_ACT_DECODE:
- img_zb_decode(imgptr, data);
- break;
- }
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void img_zb_decode (class cv::Mat *imgptr, void *data)
-{
- struct zbar::zbar_image_scanner_s *scanner;
- struct zbar::zbar_image_s *image_zb;
- const struct zbar::zbar_symbol_s *symbol;
-
- /* Type of code to scan */
- enum zbar::zbar_symbol_type_e code_type;
- code_type = ((struct Img_Iface_Data_Decode *)data)->code_type;
-
- /* create & configure a reader */
- scanner = zbar::zbar_image_scanner_create();
- zbar::zbar_image_scanner_set_config(scanner, code_type,
- zbar::ZBAR_CFG_ENABLE, 1);
-
- /* wrap image data */
- image_zb = zbar::zbar_image_create();
- zbar::zbar_image_set_format(image_zb, *(int*)"GREY");
- zbar::zbar_image_set_size(image_zb, imgptr->cols, imgptr->rows);
- zbar::zbar_image_set_data(image_zb, (void *)(imgptr->data),
- (imgptr->cols * imgptr->rows),
- NULL);
-
- /* scan the image for barcodes */
- int i;
- zb_codes.n = zbar::zbar_scan_image(scanner, image_zb);
- if (zb_codes.n) {
- /* extract results */
- symbol = zbar::zbar_image_first_symbol(image_zb);
- for (i = 0; i < ZB_CODES_MAX && symbol; i++) {
- /* Write results into array */
- zb_codes.arr[i].type = zbar::zbar_symbol_get_type(symbol);
- snprintf(zb_codes.arr[i].sym_name, 80, "%s",
- zbar::zbar_get_symbol_name(
- zb_codes.arr[i].type));
- snprintf(zb_codes.arr[i].data, ZBAR_LEN_MAX, "%s",
- zbar::zbar_symbol_get_data(symbol));
-
- /* Load next symbol */
- symbol = zbar::zbar_symbol_next(symbol);
- }
- }
-
- /* clean up */
- zbar::zbar_image_destroy(image_zb);
- zbar::zbar_image_scanner_destroy(scanner);
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/image/tmp/Makefile b/modules/image/tmp/Makefile
deleted file mode 100644
index 56cafec..0000000
--- a/modules/image/tmp/Makefile
+++ /dev/null
@@ -1,120 +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_zbar.o img_ocr.o img_orb.o img_iface.o
-ALL = $(_ALL) img_mod.o
-
-IMGALX_INC_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)
-
-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)
-
-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)
-
-IMGI_INC_SAVE = save.hpp
-IMGI_INC_USR = user_iface.hpp
-IMGI_INC = img_iface.hpp img_alx.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
-
-all: $(ALL)
-
-
-img_mod.o: $(_ALL)
- $(Q)$(LD) -r $^ -o $@
- @echo " LD $@"
- @echo ""
-
-
-img_alx.s: $(IMGALX_DEPS)
- $(Q)$(CXX) $(CXXFLAGS) $(IMGALX_INC_DIRS) -S $< -o $@
- @echo " CXX $@"
-img_alx.o: img_alx.s
- $(Q)$(AS) $< -o $@
- @echo " AS $@"
-
-img_cv.s: $(IMGCV_DEPS)
- $(Q)$(CXX) $(CXXFLAGS) $(IMGCV_INC_DIRS) -S $< -o $@
- @echo " CXX $@"
-img_cv.o: img_cv.s
- $(Q)$(AS) $< -o $@
- @echo " AS $@"
-
-img_zbar.s: $(IMGZB_DEPS)
- $(Q)$(CXX) $(CXXFLAGS) $(IMGZB_INC_DIRS) -S $< -o $@
- @echo " CXX $@"
-img_zbar.o: img_zbar.s
- $(Q)$(AS) $< -o $@
- @echo " AS $@"
-
-img_ocr.s: $(IMGOCR_DEPS)
- $(Q)$(CC) $(CFLAGS) $(IMGOCR_INC_DIRS) -S $< -o $@
- @echo " CC $@"
-img_ocr.o: img_ocr.s
- $(Q)$(AS) $< -o $@
- @echo " AS $@"
-
-img_orb.s: $(IMGORB_DEPS)
- $(Q)$(CXX) $(CXXFLAGS) $(IMGORB_INC_DIRS) -S $< -o $@
- @echo " CXX $@"
-img_orb.o: img_orb.s
- $(Q)$(AS) $< -o $@
- @echo " AS $@"
-
-img_iface.s: $(IMGI_DEPS)
- $(Q)$(CXX) $(CXXFLAGS) $(IMGI_INC_DIRS) -S $< -o $@
- @echo " CXX $@"
-img_iface.o: img_iface.s
- $(Q)$(AS) $< -o $@
- @echo " AS $@"
-
-################################################################################
-######## 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 ae982a8..0000000
--- a/modules/menu/inc/menu_clui.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_MENU_CLUI_H
- # define VA_MENU_CLUI_H
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- void menu_clui (void);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* menu_clui.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/menu/inc/menu_iface.h b/modules/menu/inc/menu_iface.h
deleted file mode 100644
index 320cbd4..0000000
--- a/modules/menu/inc/menu_iface.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_MENU_IFACE_H
- # define VA_MENU_IFACE_H
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Menu_Iface_Mode {
- MENU_IFACE_FOO = 0,
- MENU_IFACE_CLUI,
- MENU_IFACE_TUI
- };
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-extern int menu_iface_mode;
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
-void menu_iface (void);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* menu_iface.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/menu/inc/menu_iface.hpp b/modules/menu/inc/menu_iface.hpp
deleted file mode 100644
index a1fbb25..0000000
--- a/modules/menu/inc/menu_iface.hpp
+++ /dev/null
@@ -1,55 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_MENU_IFACE_HPP
- # define VA_MENU_IFACE_HPP
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-extern "C" {
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Menu_Iface_Mode {
- MENU_IFACE_FOO = 0,
- MENU_IFACE_CLUI,
- MENU_IFACE_TUI
- };
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
- extern int menu_iface_mode;
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- void menu_iface (void);
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-} /* extern "C" */
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* menu_iface.hpp */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/menu/inc/menu_tui.h b/modules/menu/inc/menu_tui.h
deleted file mode 100644
index 5ccaebd..0000000
--- a/modules/menu/inc/menu_tui.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_MENU_TUI_H
- # define VA_MENU_TUI_H
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- void menu_tui (void);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* menu_tui.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/menu/inc/parser.h b/modules/menu/inc/parser.h
deleted file mode 100644
index 836385c..0000000
--- a/modules/menu/inc/parser.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_PARSER_H
- # define VA_PARSER_H
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
-void parser (int argc, char *argv[]);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* parser.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/menu/inc/parser.hpp b/modules/menu/inc/parser.hpp
deleted file mode 100644
index ff40d1f..0000000
--- a/modules/menu/inc/parser.hpp
+++ /dev/null
@@ -1,39 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_PARSER_HPP
- # define VA_PARSER_HPP
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-extern "C" {
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- void parser (int argc, char *argv[]);
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-} /* extern "C" */
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* parser.hpp */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/menu/src/menu_clui.c b/modules/menu/src/menu_clui.c
deleted file mode 100644
index 0e8ea31..0000000
--- a/modules/menu/src/menu_clui.c
+++ /dev/null
@@ -1,116 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
- #include "alx_input.h"
-
- #include "about.h"
-// #include "save.h"
- /* start_switch() */
- #include "start.h"
-
- #include "menu_clui.h"
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
- # define BUFF_SIZE (1024)
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void menu_clui_rand (void);
-static void menu_clui_custom (void);
-static void menu_clui_load (void);
-static void menu_clui_start (void);
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void menu_clui (void)
-{
- char buff [BUFF_SIZE];
- char ch;
-
- ch = 'n';
- printf("Read 'Disclaimer of warranty'? (yes/NO): ");
- fgets(buff, BUFF_SIZE, stdin);
- sscanf(buff, " %c", &ch);
- if (ch == 'y' || ch == 'Y') {
- puts (" >yes");
- print_share_file(SHARE_DISCLAIMER);
- } else {
- puts (" >NO");
- }
-
- ch = 'n';
- printf("Read 'License'? (yes/NO): ");
- fgets(buff, BUFF_SIZE, stdin);
- sscanf(buff, " %c", &ch);
- if (ch == 'y' || ch == 'Y') {
- puts (" >yes");
- print_share_file(SHARE_LICENSE);
- } else {
- puts (" >NO");
- }
-#if 0
- printf("Game interface? (NCURSES/text): ");
- scanf(" %c%*s ", &ch);
- if (ch == 't' || ch == 'T') {
- puts (" >text");
- // FIXME
- } else {
- puts (" >NCURSES");
- // FIXME
- }
-#endif
- menu_clui_load();
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void menu_clui_load (void)
-{
-#if 0
- /* File name */ // FIXME
- alx_w_getfname(USER_SAVED_DIR, saved_name, "File name:", saved_name, NULL);
-#endif
- menu_clui_start();
-}
-
-static void menu_clui_start (void)
-{
- puts(" >>START:");
- start_switch();
-
- char buff [BUFF_SIZE];
- char ch;
-
- ch = 'm';
- printf("Load again? (MENU/load/exit): ");
- fgets(buff, BUFF_SIZE, stdin);
- sscanf(buff, " %c", &ch);
- if (ch == 'p' || ch == 'P') {
- puts (" >load");
- menu_clui_start();
- } else if (ch == 'e' || ch == 'E') {
- puts (" >exit!");
- } else {
- puts (" >MENU");
- menu_clui();
- }
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/menu/src/menu_iface.c b/modules/menu/src/menu_iface.c
deleted file mode 100644
index 1a00c29..0000000
--- a/modules/menu/src/menu_iface.c
+++ /dev/null
@@ -1,45 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
- /* menu_clui() */
- #include "menu_clui.h"
- /* menu_tui() */
- #include "menu_tui.h"
-
- #include "menu_iface.h"
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-int menu_iface_mode;
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void menu_iface (void)
-{
- switch (menu_iface_mode) {
- case MENU_IFACE_FOO:
- break;
-
- case MENU_IFACE_CLUI:
- menu_clui();
- break;
-
- case MENU_IFACE_TUI:
- menu_tui();
- break;
- }
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/menu/src/menu_tui.c b/modules/menu/src/menu_tui.c
deleted file mode 100644
index 64e460a..0000000
--- a/modules/menu/src/menu_tui.c
+++ /dev/null
@@ -1,331 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- #include <ncurses.h>
- #include <stdbool.h>
-
-/* libalx --------------------------------------------------------------------*/
- #include "alx_ncur.h"
-
-/* Project -------------------------------------------------------------------*/
- /* printf_share_file() */
- #include "about.h"
- /* proc_debug */
- #include "proc_iface.h"
- /* saved_name */
- #include "save.h"
- /* start_switch() */
- #include "start.h"
- /* user_iface_log */
- #include "user_iface.h"
-
-/* Module --------------------------------------------------------------------*/
- #include "menu_tui.h"
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void menu_tui_continue (void);
-static void menu_tui_select (void);
-static void menu_tui_series (void);
-static void menu_tui_devel (void);
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void menu_tui (void)
-{
- alx_resume_curses();
-
- /* Menu dimensions & options */
- int h;
- int w;
- h = 23;
- w = 80;
- int N;
- N = 4;
- struct Alx_Menu mnu[4] = {
- {7, 4, "[0] Exit program"},
- {2, 4, "[1] Continue"},
- {4, 4, "[2] Disclaimer of warranty"},
- {5, 4, "[3] Terms and conditions"}
- };
-
- /* Menu */
- bool wh;
- int sw;
- wh = true;
- while (wh) {
- /* Menu loop */
- sw = alx_menu(h, w, N, mnu, "MENU:");
-
- /* Selection */
- switch (sw) {
- case 0:
- wh = false;
- break;
-
- case 1:
- menu_tui_continue();
- break;
-
- case 2:
- alx_pause_curses();
- print_share_file(SHARE_DISCLAIMER);
- getchar();
- alx_resume_curses();
- break;
-
- case 3:
- alx_pause_curses();
- print_share_file(SHARE_LICENSE);
- getchar();
- alx_resume_curses();
- break;
- }
- }
-
- alx_pause_curses();
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void menu_tui_continue (void)
-{
- /* Menu dimensions & options */
- WINDOW *win;
- int h;
- int w;
- int r;
- int c;
- h = 23;
- w = 80;
- r = 1;
- c = (80 - w) / 2;
- int N;
- N = 6;
- struct Alx_Menu mnu[6] = {
- {8, 4, "[0] Back"},
- {2, 4, "[1] Start"},
- {3, 4, "[2] Select"},
- {4, 4, "[3] Series"},
- {5, 4, "[4] Change file name"},
- {6, 4, "[5] DEVEL"}
- };
-
- /* Input box */
- int w2;
- int r2;
- w2 = w - 8;
- r2 = r + h - 5;
- char *txt[] = {"File name:"};
-
- /* Menu */
- bool wh;
- int sw;
- wh = true;
- while (wh) {
- /* Menu loop */
- win = newwin(h, w, r, c);
- mvwprintw(win, mnu[1].r, mnu[1].c, "%s (File: \"%s\")",
- mnu[1].t, saved_name);
- wrefresh(win);
- sw = alx_menu_2(win, N, mnu, "CONTINUE:");
-
- /* Selection */
- switch (sw) {
- case 0:
- wh = false;
- break;
-
- case 1:
- alx_win_del(win);
- alx_pause_curses();
- start_switch();
- alx_resume_curses();
- break;
-
- case 2:
- alx_win_del(win);
- menu_tui_select();
- break;
-
- case 3:
- alx_win_del(win);
- menu_tui_series();
- break;
-
- case 4:
- save_clr();
- alx_w_getfname(saved_path, saved_name, true, w2, r2,
- txt[0], NULL);
- alx_win_del(win);
- break;
-
- case 5:
- alx_win_del(win);
- menu_tui_devel();
- break;
- }
- }
-
- /* Cleanup */
- alx_win_del(win);
-}
-
-static void menu_tui_select (void)
-{
- /* Menu dimensions & options */
- WINDOW *win;
- int h;
- int w;
- int r;
- int c;
- h = 23;
- w = 80;
- r = 1;
- c = (80 - w) / 2;
- int N;
- N = 3;
- struct Alx_Menu mnu[3] = {
- {6, 4, "[0] Back"},
- {2, 4, "[1] Single image"},
- {4, 4, "[2] Series"}
- };
-
- /* Menu loop */
- int sw;
- sw = alx_menu(h, w, N, mnu, "SELECT MODE:");
-
- /* Selection */
- switch (sw) {
- case 1:
- start_mode = START_SINGLE;
- break;
-
- case 2:
- start_mode = START_SERIES;
- break;
- }
-
-}
-
-static void menu_tui_series (void)
-{
- /* Menu dimensions & options */
- WINDOW *win;
- int h;
- int w;
- h = 23;
- w = 80;
- int N;
- N = 4;
- struct Alx_Menu mnu[4] = {
- {6, 4, "[0] Back"},
- {2, 4, "[1] Label"},
- {3, 4, "[-] -"},
- {4, 4, "[2] Resistor"}
- };
-
- /* Menu loop */
- int sw;
- sw = alx_menu(h, w, N, mnu, "SELECT LEVEL:");
-
- /* Selection */
- switch (sw) {
- case 1:
- proc_mode = PROC_MODE_LABEL;
- break;
- case 2:
- proc_mode = PROC_MODE_FOO;
- break;
- case 3:
- proc_mode = PROC_MODE_RESISTOR;
- break;
- }
-
-}
-
-static void menu_tui_devel (void)
-{
- WINDOW *win;
- int h;
- int w;
- int r;
- int c;
- h = 23;
- w = 80;
- r = 1;
- c = (80 - w) / 2;
- int N;
- N = 4;
- struct Alx_Menu mnu[4] = {
- {6, 4, "[0] Back"},
- {2, 4, "[1] Change process mode"},
- {3, 4, "[2] Change log mode"},
- {4, 4, "[3] Change user iface mode"}
- };
-
- /* Input box */
- int w2;
- int r2;
- w2 = w - 8;
- r2 = r + h - 5;
- char *txt[] = {
- "Modes: 0=Auto; 1=Stop@prod; 2=Delay@step; 3=Stop@step",
- "Modes: 0=Results; 1=Operations; 2=All",
- "Modes: 1=CLUI; 2=TUI"
- };
-
- /* Menu */
- win = newwin(h, w, r, c);
-
- /* Menu loop */
- bool wh;
- int sw;
- wh = true;
- while (wh) {
- /* Selection */
- sw = alx_menu_2(win, N, mnu, "DEVELOPER OPTIONS:");
-
- switch (sw) {
- case 0:
- wh = false;
- break;
-
- case 1:
- proc_debug = alx_w_getint(w2, r2, txt[0],
- PROC_DBG_NO, 0, PROC_DBG_STOP_STEP,
- NULL);
- break;
-
- case 2:
- user_iface_log.visible = alx_w_getint(w2, r2, txt[1],
- 0, 2, 2, NULL);
- break;
-
- case 3:
- user_iface_mode = alx_w_getint(w2, r2, txt[2],
- 1, 2, 2, NULL);
- break;
- }
- }
-
- /* Cleanup */
- alx_win_del(win);
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/menu/tmp/Makefile b/modules/menu/tmp/Makefile
deleted file mode 100644
index 3acc26e..0000000
--- a/modules/menu/tmp/Makefile
+++ /dev/null
@@ -1,124 +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 = 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 = 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 $@"
- @echo ""
-
-
-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 68d15a2..0000000
--- a/modules/proc/inc/proc_coins.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_PROC_COINS_H
- # define VA_PROC_COINS_H
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Proc_Coins {
- COINS_OK,
- COINS_NOK_COINS,
- COINS_NOK_OVERLAP
- };
-
-
-/******************************************************************************
- ******* 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 e0a6e36..0000000
--- a/modules/proc/inc/proc_common.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_PROC_COMMON_H
- # define VA_PROC_COMMON_H
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- void proc_show_img (void);
-
- void clock_start (void);
- void clock_stop (const char *txt);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* proc_common.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/proc/inc/proc_common.hpp b/modules/proc/inc/proc_common.hpp
deleted file mode 100644
index f21e530..0000000
--- a/modules/proc/inc/proc_common.hpp
+++ /dev/null
@@ -1,108 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_PROC_COMMON_HPP
- # define VA_PROC_COMMON_HPP
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-extern "C" {
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- void proc_apply (void);
- void proc_save_mem (int n);
- void proc_load_mem (int n);
- void proc_save_ref (void);
- void proc_save_file (void);
- void proc_save_update (void);
-
- void proc_local_max (void);
- void proc_lines_vertical (void);
- void proc_median_horizontal (void);
- void proc_median_vertical (void);
-
- void proc_pixel_value (int x, int y, unsigned char *val);
- void proc_ROI (int x, int y, int w, int h);
- void proc_and_2ref (void);
- void proc_not (void);
- void proc_or_2ref (void);
- void proc_cmp (int cmp);
- void proc_dilate (int size);
- void proc_erode (int size);
- void proc_dilate_erode (int size);
- void proc_erode_dilate (int size);
- void proc_smooth (int method, int ksize);
- void proc_rotate (class cv::RotatedRect *rect);
- void proc_adaptive_threshold (int method, int type, int ksize);
- void proc_cvt_color (int method);
- void proc_distance_transform (void);
- void proc_threshold (int type, int ksize);
- void proc_contours (
- std::vector <std::vector <class cv::Point_ <int>>> *contours,
- class cv::Mat *hierarchy);
- void proc_contours_size (
- std::vector <std::vector <class cv::Point_ <int>>> *contours,
- double *area,
- double *perimeter);
- void proc_bounding_rect (
- std::vector <class cv::Point_ <int>> *contour,
- class cv::Rect_ <int> *rect,
- bool show);
- void proc_fit_ellipse (
- std::vector <class cv::Point_ <int>> *contour,
- class cv::RotatedRect *rect,
- bool show);
- void proc_min_area_rect (
- std::vector <class cv::Point_ <int>> *contour,
- class cv::RotatedRect *rect,
- bool show);
-
- void proc_OCR (int lang, int conf);
- void proc_zbar (int type);
-
- void proc_show_img (void);
-
- void clock_start (void);
- void clock_stop (const char *txt);
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-} /* extern "C" */
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* proc_common.hpp */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/proc/inc/proc_iface.h b/modules/proc/inc/proc_iface.h
deleted file mode 100644
index 847eca3..0000000
--- a/modules/proc/inc/proc_iface.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_PROC_IFACE_H
- # define VA_PROC_IFACE_H
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Proc_Mode {
- PROC_MODE_FOO,
-
- PROC_MODE = 0x4000,
- PROC_MODE_LABEL,
- PROC_MODE_COINS,
- PROC_MODE_RESISTOR
- };
-
- 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 1792e43..0000000
--- a/modules/proc/inc/proc_label.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_PROC_LABEL_H
- # define VA_PROC_LABEL_H
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Proc_Label {
- LABEL_OK,
- LABEL_NOK_LABEL,
- LABEL_NOK_CERDO,
- LABEL_NOK_BCODE,
- LABEL_NOK_PRODUCT,
- LABEL_NOK_PRICE
- };
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- int proc_label (void);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* proc_label.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/proc/inc/proc_resistor.h b/modules/proc/inc/proc_resistor.h
deleted file mode 100644
index 7784ebb..0000000
--- a/modules/proc/inc/proc_resistor.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_PROC_RESISTOR_H
- # define VA_PROC_RESISTOR_H
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Proc_Resistor {
- RESISTOR_OK,
- RESISTOR_NOK_RESISTOR,
- RESISTOR_NOK_BANDS,
- RESISTOR_NOK_COLOR,
- RESISTOR_NOK_STD_VALUE,
- RESISTOR_NOK_TOLERANCE
- };
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- int proc_resistor (void);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* proc_resistor.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/proc/src/proc_coins.cpp b/modules/proc/src/proc_coins.cpp
deleted file mode 100644
index 676e214..0000000
--- a/modules/proc/src/proc_coins.cpp
+++ /dev/null
@@ -1,137 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* snprintf() & fflush() */
- #include <cstdio>
-
-/* Packages ------------------------------------------------------------------*/
- /* openCV */
- #include <opencv2/opencv.hpp>
-
-/* Project -------------------------------------------------------------------*/
- /* constants */
- #include "img_iface.hpp"
- /* user_iface_log */
- #include "user_iface.hpp"
-
-/* Module --------------------------------------------------------------------*/
- #include "proc_common.hpp"
-
- #include "proc_coins.hpp"
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-/* Global --------------------------------------------------------------------*/
-
-/* Static --------------------------------------------------------------------*/
-static std::vector <std::vector <cv::Point_ <int>>> contours;
-static class cv::Mat hierarchy;
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void result_coins (int status);
-
-static int coins_find (void);
-
-
-/******************************************************************************
- ******* global functions *****************************************************
- ******************************************************************************/
-int proc_coins (void)
-{
- int status;
-
- proc_save_mem(0);
- /* Find coins */
- {
- /* Measure time */
- clock_start();
-
- status = coins_find();
- if (status) {
- result_coins(status);
- return status;
- }
-
- /* Measure time */
- clock_stop("Find coins");
- }
-
- status = COINS_OK;
- result_coins(status);
- return status;
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void result_coins (int status)
-{
- /* Cleanup */
-
- /* Write result into log */
- char result [LOG_LINE_LEN];
- 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;
- case COINS_NOK_OVERLAP:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Coin: NOK_OVERLAP");
- 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 int coins_find (void)
-{
- int status;
-
- proc_load_mem(0);
-
- proc_cmp(IMG_IFACE_CMP_BLUE);
-// proc_smooth(IMGI_SMOOTH_MEDIAN, 11);
- proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU);
-// proc_threshold(cv::THRESH_BINARY_INV, 100);
- proc_distance_transform();
- proc_local_max();
- proc_dilate(8);
- proc_save_mem(1);
-
- proc_contours(&contours, &hierarchy);
-
- /* If no contour is found, error: NOK_COINS */
- if (!contours.size()) {
- status = COINS_NOK_COINS;
- return status;
- }
-
- status = COINS_OK;
- return status;
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/proc/src/proc_common.cpp b/modules/proc/src/proc_common.cpp
deleted file mode 100644
index 048c2d7..0000000
--- a/modules/proc/src/proc_common.cpp
+++ /dev/null
@@ -1,381 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* snprintf() & fflush() */
- #include <cstdio>
- /* clock_t & clock() & CLOCKS_PER_SEC */
- #include <ctime>
-
-/* Packages ------------------------------------------------------------------*/
- /* openCV */
- #include <opencv2/opencv.hpp>
- /* enum zbar::zbar_symbol_type_e */
- #include <zbar.h>
-
-/* Project -------------------------------------------------------------------*/
- /* img_iface_act() */
- #include "img_iface.hpp"
- /* user_iface_log */
- #include "user_iface.hpp"
-
-/* Module --------------------------------------------------------------------*/
- /* enum Proc_DBG */
- #include "proc_iface.hpp"
-
- #include "proc_common.hpp"
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-/* Global --------------------------------------------------------------------*/
-
-/* Static --------------------------------------------------------------------*/
-static clock_t clock_0;
-static clock_t clock_1;
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* global functions *****************************************************
- ******************************************************************************/
-void proc_apply (void)
-{
- img_iface_act(IMG_IFACE_ACT_APPLY, NULL);
-}
-
-void proc_save_mem (int n)
-{
- img_iface_act(IMG_IFACE_ACT_SAVE_MEM, (void *)&n);
-}
-
-void proc_load_mem (int n)
-{
- img_iface_act(IMG_IFACE_ACT_LOAD_MEM, (void *)&n);
-
- proc_show_img();
-}
-
-void proc_save_ref (void)
-{
- img_iface_act(IMG_IFACE_ACT_SAVE_REF, NULL);
-}
-
-void proc_save_file (void)
-{
- img_iface_act(IMG_IFACE_ACT_SAVE_FILE, NULL);
-}
-
-void proc_save_update (void)
-{
- img_iface_act(IMG_IFACE_ACT_SAVE_UPDT, NULL);
-}
-
-void proc_local_max (void)
-{
- img_iface_act(IMG_IFACE_ACT_LOCAL_MAX, NULL);
-
- proc_show_img();
-}
-
-void proc_lines_vertical (void)
-{
- img_iface_act(IMG_IFACE_ACT_LINES_VERTICAL, NULL);
-
- proc_show_img();
-}
-
-void proc_median_horizontal (void)
-{
- img_iface_act(IMG_IFACE_ACT_MEDIAN_HORIZONTAL, NULL);
-
- proc_show_img();
-}
-
-void proc_median_vertical (void)
-{
- img_iface_act(IMG_IFACE_ACT_MEDIAN_VERTICAL, NULL);
-
- proc_show_img();
-}
-
-void proc_pixel_value (int x, int y, unsigned char *val)
-{
- struct Img_Iface_Data_Pixel_Value data;
- data.x = x;
- data.y = y;
- data.val = val;
- img_iface_act(IMG_IFACE_ACT_PIXEL_VALUE, (void *)&data);
-}
-
-void proc_ROI (int x, int y, int w, int h)
-{
- struct Img_Iface_Data_SetROI data;
- data.rect.x = x;
- data.rect.y = y;
- data.rect.width = w;
- data.rect.height = h;
- img_iface_act(IMG_IFACE_ACT_SET_ROI, (void *)&data);
-
- proc_show_img();
-}
-
-void proc_and_2ref (void)
-{
- img_iface_act(USER_IFACE_ACT_AND_2REF, NULL);
-
- proc_show_img();
-}
-
-void proc_not (void)
-{
- img_iface_act(USER_IFACE_ACT_NOT, NULL);
-
- proc_show_img();
-}
-
-void proc_or_2ref (void)
-{
- img_iface_act(USER_IFACE_ACT_OR_2REF, NULL);
-
- proc_show_img();
-}
-
-void proc_cmp (int cmp)
-{
- struct Img_Iface_Data_Component data;
- data.cmp = cmp;
- img_iface_act(IMG_IFACE_ACT_COMPONENT, (void *)&data);
-
- proc_show_img();
-}
-
-void proc_dilate (int size)
-{
- struct Img_Iface_Data_Dilate_Erode data;
- data.i = size;
- img_iface_act(IMG_IFACE_ACT_DILATE, (void *)&data);
-
- proc_show_img();
-}
-
-void proc_erode (int size)
-{
- struct Img_Iface_Data_Dilate_Erode data;
- data.i = size;
- img_iface_act(IMG_IFACE_ACT_ERODE, (void *)&data);
-
- proc_show_img();
-}
-
-void proc_dilate_erode (int size)
-{
- struct Img_Iface_Data_Dilate_Erode data;
- data.i = size;
- img_iface_act(IMG_IFACE_ACT_DILATE_ERODE, (void *)&data);
-
- proc_show_img();
-}
-
-void proc_erode_dilate (int size)
-{
- struct Img_Iface_Data_Dilate_Erode data;
- data.i = size;
- img_iface_act(IMG_IFACE_ACT_ERODE_DILATE, (void *)&data);
-
- proc_show_img();
-}
-
-void proc_smooth (int method, int ksize)
-{
- struct Img_Iface_Data_Smooth data;
- data.method = method;
- data.ksize = ksize;
- img_iface_act(IMG_IFACE_ACT_SMOOTH, (void *)&data);
-
- proc_show_img();
-}
-
-void proc_rotate (class cv::RotatedRect *rect)
-{
- struct Img_Iface_Data_Rotate data;
- data.center.x = rect->center.x;
- data.center.y = rect->center.y;
- data.angle = rect->angle;
- img_iface_act(IMG_IFACE_ACT_ROTATE, (void *)&data);
-
- proc_show_img();
-}
-
-void proc_adaptive_threshold (int method, int type, int ksize)
-{
- struct Img_Iface_Data_Adaptive_Thr data;
- data.method = method;
- data.thr_typ = type;
- data.ksize = ksize;
- img_iface_act(USER_IFACE_ACT_ADAPTIVE_THRESHOLD, (void *)&data);
-
- proc_show_img();
-}
-
-void proc_cvt_color (int method)
-{
- struct Img_Iface_Data_Cvt_Color data;
- data.method = method;
- img_iface_act(IMG_IFACE_ACT_CVT_COLOR, (void *)&data);
-
- proc_show_img();
-}
-
-void proc_threshold (int type, int size)
-{
- struct Img_Iface_Data_Threshold data;
- data.thr_typ = type;
- data.thr_val = size;
- img_iface_act(IMG_IFACE_ACT_THRESHOLD, (void *)&data);
-
- proc_show_img();
-}
-
-void proc_distance_transform (void)
-{
- img_iface_act(IMG_IFACE_ACT_DISTANCE_TRANSFORM, NULL);
-
- proc_show_img();
-}
-
-void proc_contours (
- std::vector <std::vector <class cv::Point_ <int>>> *contours,
- class cv::Mat *hierarchy)
-{
- struct Img_Iface_Data_Contours data;
- data.contours = contours;
- data.hierarchy = hierarchy;
- img_iface_act(IMG_IFACE_ACT_CONTOURS, (void *)&data);
-
- proc_show_img();
-}
-
-void proc_contours_size (
- std::vector <std::vector <class cv::Point_ <int>>> *contours,
- double *area,
- double *perimeter)
-{
- struct Img_Iface_Data_Contours_Size data;
- data.contours = contours;
- data.area = area;
- data.perimeter = perimeter;
- img_iface_act(IMG_IFACE_ACT_CONTOURS_SIZE, (void *)&data);
-}
-
-void proc_bounding_rect (
- std::vector <class cv::Point_ <int>> *contour,
- class cv::Rect_ <int> *rect,
- bool show)
-{
- struct Img_Iface_Data_Bounding_Rect data;
- data.contour = contour;
- data.rect = rect;
- data.show = show;
- img_iface_act(IMG_IFACE_ACT_BOUNDING_RECT, (void *)&data);
-
- if (show) {
- proc_show_img();
- }
-}
-
-void proc_fit_ellipse (
- std::vector <class cv::Point_ <int>> *contour,
- class cv::RotatedRect *rect,
- bool show)
-{
- struct Img_Iface_Data_MinARect data;
- data.contour = contour;
- data.rect = rect;
- data.show = show;
- img_iface_act(IMG_IFACE_ACT_FIT_ELLIPSE, (void *)&data);
-
-
- if (show) {
- proc_show_img();
- }
-}
-
-void proc_min_area_rect (
- std::vector <class cv::Point_ <int>> *contour,
- class cv::RotatedRect *rect,
- bool show)
-{
- struct Img_Iface_Data_MinARect data;
- data.contour = contour;
- data.rect = rect;
- data.show = show;
- img_iface_act(IMG_IFACE_ACT_MIN_AREA_RECT, (void *)&data);
-
- if (show) {
- proc_show_img();
- }
-}
-
-void proc_OCR (int lang, int conf)
-{
- struct Img_Iface_Data_Read data;
- data.lang = lang; /* eng=0, spa=1, cat=2 */
- data.conf = conf; /* none=0, price=1 */
- img_iface_act(IMG_IFACE_ACT_READ, (void *)&data);
-}
-
-void proc_zbar (int type)
-{
- struct Img_Iface_Data_Decode data;
- data.code_type = (enum zbar::zbar_symbol_type_e)type;
- img_iface_act(IMG_IFACE_ACT_DECODE, (void *)&data);
-}
-
-void proc_show_img (void)
-{
- if (proc_debug >= PROC_DBG_DELAY_STEP) {
- img_iface_show_img();
-
- if (proc_debug >= PROC_DBG_STOP_STEP) {
- getchar();
- }
- }
-}
-
-void clock_start (void)
-{
- clock_0 = clock();
-}
-
-void clock_stop (const char *txt)
-{
- clock_t clock_diff;
- double time_diff;
-
- clock_1 = clock();
- clock_diff = clock_1 - clock_0;
- time_diff = (double)clock_diff / (double)CLOCKS_PER_SEC;
-
- /* Write time_diff into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Time: %.3lf (%s)",
- txt, time_diff);
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/proc/src/proc_iface.c b/modules/proc/src/proc_iface.c
deleted file mode 100644
index d6108a5..0000000
--- a/modules/proc/src/proc_iface.c
+++ /dev/null
@@ -1,185 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* errno */
- #include <errno.h>
- /* snprintf() & fflush() */
- #include <stdio.h>
- /* clock_t & clock() & CLOCKS_PER_SEC */
- #include <time.h>
-
-/* libalx -------------------------------------------------------------------*/
- /* alx_sscan_fname() */
- #include "alx_input.h"
-
-/* Project -------------------------------------------------------------------*/
- /* img_iface_load() */
- #include "img_iface.h"
- /* user_iface_log */
- #include "user_iface.h"
- /* saved_path */
- #include "save.h"
-
-/* Module --------------------------------------------------------------------*/
- #include "proc_label.h"
- #include "proc_coins.h"
- #include "proc_resistor.h"
- #include "proc_common.h"
-
- #include "proc_iface.h"
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-/* Global --------------------------------------------------------------------*/
- int proc_debug;
- int proc_mode;
-
-/* Static --------------------------------------------------------------------*/
-static char proc_path [FILENAME_MAX];
-static char proc_fail_path [FILENAME_MAX];
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* global functions *****************************************************
- ******************************************************************************/
-int proc_iface_single (int action)
-{
- int error;
- clock_t time_0;
- clock_t time_1;
- double time_tot;
-
- /* Init timer */
- time_0 = clock();
-
- /* Process */
- switch (action) {
- case PROC_MODE_LABEL:
- error = proc_label();
- break;
- case PROC_MODE_COINS:
- error = proc_coins();
- break;
- case PROC_MODE_RESISTOR:
- error = proc_resistor();
- break;
- }
-
- /* End timer */
- time_1 = clock();
-
- /* Calculate time in seconds */
- time_tot = ((double) time_1 - time_0) / CLOCKS_PER_SEC;
-
- /* Write time into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Item total time: %.3lf",
- time_tot);
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-
- return error;
-}
-
-void proc_iface_series (void)
-{
- bool file_error;
- int num_len;
- char file_basename [FILENAME_MAX];
- char file_ext [80];
- char file_name [FILENAME_MAX];
- bool proc_error;
- char save_error_as [FILENAME_MAX];
-
- switch (proc_mode) {
- case PROC_MODE_LABEL:
- snprintf(proc_path, FILENAME_MAX, "%s", labels_path);
- snprintf(proc_fail_path, FILENAME_MAX, "%s", labels_fail_path);
- snprintf(file_basename, 80, "b");
- num_len = 4;
- snprintf(file_ext, 80, ".BMP");
- break;
- case PROC_MODE_COINS:
- snprintf(proc_path, FILENAME_MAX, "%s", coins_path);
- snprintf(proc_fail_path, FILENAME_MAX, "%s", coins_fail_path);
- snprintf(file_basename, 80, "c");
- num_len = 4;
- snprintf(file_ext, 80, ".png");
- break;
- case PROC_MODE_RESISTOR:
- snprintf(proc_path, FILENAME_MAX, "%s", resistors_path);
- snprintf(proc_fail_path, FILENAME_MAX, "%s", resistors_fail_path);
- snprintf(file_basename, 80, "r");
- num_len = 4;
- snprintf(file_ext, 80, ".png");
- break;
- }
-
- bool wh;
- int i;
- wh = true;
- for (i = 0; wh; i++) {
- snprintf(file_name, FILENAME_MAX, "%s%04i%s",
- file_basename, i, file_ext);
-
- file_error = alx_sscan_fname(proc_path, file_name,
- true, file_name);
-
- if (file_error) {
- wh = false;
- } else {
- errno = 0;
- img_iface_load(proc_path, file_name);
-
- if (!errno) {
- /* Process */
- proc_error = proc_iface_single(proc_mode);
-
- if (proc_error) {
- /* Save failed image into file */
- proc_show_img();
- snprintf(save_error_as, FILENAME_MAX,
- "%s%04i_err%s",
- file_basename, i,
- file_ext);
- save_image_file(proc_fail_path,
- save_error_as);
- }
-
- /* Show log */
- char txt_tmp [80];
- snprintf(txt_tmp, 80, "%04i", i);
- user_iface_show_log(txt_tmp, "Item");
-
- if (proc_debug >= PROC_DBG_STOP_ITEM) {
- getchar();
- }
- } else {
- printf("errno:%i\n", errno);
- }
- }
- }
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/proc/src/proc_label.cpp b/modules/proc/src/proc_label.cpp
deleted file mode 100644
index 765856d..0000000
--- a/modules/proc/src/proc_label.cpp
+++ /dev/null
@@ -1,386 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* snprintf() */
- #include <cstdio>
- /* strcmp() */
- #include <cstring>
-
-/* Packages ------------------------------------------------------------------*/
- /* openCV */
- #include <opencv2/opencv.hpp>
- /* zbar::ZBAR_EAN13 */
- #include <zbar.h>
-
-/* Project -------------------------------------------------------------------*/
- /* zb_codes */
- #include "img_iface.hpp"
- /* user_iface_log */
- #include "user_iface.hpp"
-
-/* Module --------------------------------------------------------------------*/
- #include "proc_common.hpp"
-
- #include "proc_label.hpp"
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-/* Global --------------------------------------------------------------------*/
-
-/* Static --------------------------------------------------------------------*/
-static std::vector <std::vector <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 */
- char result [LOG_LINE_LEN];
- 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;
-
- 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) {
- int tmp;
- 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);
- proc_cmp(IMG_IFACE_CMP_GREEN);
- proc_save_mem(1);
-}
-
-static int find_cerdo (void)
-{
- int status;
-
- proc_load_mem(1);
-
- int x;
- int y;
- int w;
- int h;
- 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". */
- bool cerdo_nok;
- 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)
-{
- proc_load_mem(1);
-
- int x;
- int y;
- int w;
- int h;
- 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];
-
- /* 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 */
- bool price_nok;
- 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 fa5c159..0000000
--- a/modules/proc/tmp/Makefile
+++ /dev/null
@@ -1,131 +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_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_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))
-PROC_COIN_INC_DIRS = -I $(INC_DIR) \
- -I $(IMG_INC_DIR) \
- -I $(USR_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_IMG = img_iface.h
-PROC_IFACE_INC_LIBALX = alx_input.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 $@"
- @echo ""
-
-
-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_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/inc/save.h b/modules/save/inc/save.h
deleted file mode 100644
index 1badd38..0000000
--- a/modules/save/inc/save.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_SAVE_H
- # define VA_SAVE_H
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* FILENAME_MAX */
- #include <stdio.h>
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
- # define ENV_HOME "HOME"
-
- # define USER_PROG_DIR "vision-artificial/"
- # define USER_SAVED_DIR "vision-artificial/saved/"
- # define USER_LABELS_DIR "vision-artificial/labels/"
- # define USER_LABELS_FAIL_DIR "vision-artificial/labels/fail"
- # define USER_COINS_DIR "vision-artificial/coins/"
- # define USER_COINS_FAIL_DIR "vision-artificial/coins/fail"
- # define USER_RESISTORS_DIR "vision-artificial/resistors/"
- # define USER_RESISTORS_FAIL_DIR "vision-artificial/resistors/fail"
- # define SAVED_NAME_DEFAULT "saved"
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
- extern char home_path [FILENAME_MAX];
- extern char user_prog_path [FILENAME_MAX];
- extern char saved_path [FILENAME_MAX];
- extern char labels_path [FILENAME_MAX];
- extern char labels_fail_path [FILENAME_MAX];
- extern char coins_path [FILENAME_MAX];
- extern char coins_fail_path [FILENAME_MAX];
- extern char resistors_path [FILENAME_MAX];
- extern char resistors_fail_path [FILENAME_MAX];
- extern char saved_name [FILENAME_MAX];
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- void save_init (void);
- void save_cleanup (void);
- void save_clr (void);
- void load_image_file (const char *fpath, const char *fname);
- void save_image_file (const char *fpath, const char *save_as);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* save.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/save/src/save.cpp b/modules/save/src/save.cpp
deleted file mode 100644
index ca79250..0000000
--- a/modules/save/src/save.cpp
+++ /dev/null
@@ -1,190 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* errno */
- #include <cerrno>
- /* fscanf() & fprintf() & FILE & FILENAME_MAX & snprintf() */
- #include <cstdio>
- /* getenv() */
- #include <cstdlib>
-
-/* Linux ---------------------------------------------------------------------*/
- /* mkdir */
- #include <sys/stat.h>
-
-/* Packages ------------------------------------------------------------------*/
- /* opencv */
- #include <opencv2/opencv.hpp>
-
-/* Project -------------------------------------------------------------------*/
- /* user_iface_save_name() */
- #include "user_iface.hpp"
-
-/* Module --------------------------------------------------------------------*/
- #include "save.hpp"
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-class cv::Mat image;
-char home_path [FILENAME_MAX];
-char user_prog_path [FILENAME_MAX];
-char saved_path [FILENAME_MAX];
-char labels_path [FILENAME_MAX];
-char labels_fail_path [FILENAME_MAX];
-char coins_path [FILENAME_MAX];
-char coins_fail_path [FILENAME_MAX];
-char resistors_path [FILENAME_MAX];
-char resistors_fail_path [FILENAME_MAX];
-char saved_name [FILENAME_MAX];
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void save_init (void)
-{
- snprintf(home_path, FILENAME_MAX, "%s/", getenv(ENV_HOME));
- snprintf(user_prog_path, FILENAME_MAX, "%s/%s/", home_path, USER_PROG_DIR);
- snprintf(saved_path, FILENAME_MAX, "%s/%s/", home_path, USER_SAVED_DIR);
- snprintf(labels_path, FILENAME_MAX, "%s/%s/", home_path, USER_LABELS_DIR);
- snprintf(labels_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_LABELS_FAIL_DIR);
- snprintf(coins_path, FILENAME_MAX, "%s/%s/", home_path, USER_COINS_DIR);
- snprintf(coins_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_COINS_FAIL_DIR);
- snprintf(resistors_path, FILENAME_MAX, "%s/%s/", home_path, USER_RESISTORS_DIR);
- snprintf(resistors_fail_path, FILENAME_MAX, "%s/%s/", home_path, USER_RESISTORS_FAIL_DIR);
- sprintf(saved_name, "");
-
- int err;
- err = mkdir(user_prog_path, 0700);
-
- if (!err) {
- } else {
-
- switch (errno) {
- case EACCES:
- printf("err = EACCES");
-// exit(EXIT_FAILURE);
- break;
-
- case EEXIST:
- /* OK */
- break;
-
- default:
- printf("WTF?!");
-// exit(EXIT_FAILURE);
- }
- }
-
- mkdir(saved_path, 0700);
- mkdir(labels_path, 0700);
- mkdir(labels_fail_path, 0700);
-}
-
-void save_clr (void)
-{
- snprintf(saved_path, FILENAME_MAX, "%s/%s/", home_path, USER_SAVED_DIR);
-}
-
-void load_image_file (const char *fpath, const char *fname)
-{
- char file_path [FILENAME_MAX];
- char file_name [FILENAME_MAX];
-
- /* Free old image */
- image.release();
-
- /* Set file_path */
- if (!fpath) {
- /* Default path */
- save_clr();
- snprintf(file_path, FILENAME_MAX, "%s", saved_path);
- } else {
- snprintf(file_path, FILENAME_MAX, "%s", fpath);
- }
-
- /* Set file_name */
- if (!fname) {
- /* Request file name */
- user_iface_fname(file_path, saved_name);
- } else {
- snprintf(saved_name, FILENAME_MAX, "%s", fname);
- }
-
- /* File name */
- snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name);
-
- /* Load image */
- image = cv::imread(file_name, CV_LOAD_IMAGE_COLOR);
-
- /* Manage load error */
- if (image.empty()) {
- printf("Could not load file: %s\n", file_name);
-// exit(0);
- }
-}
-
-void save_cleanup (void)
-{
- /* Free old image */
- image.release();
-}
-
-void save_image_file (const char *fpath, const char *save_as)
-{
- char file_path [FILENAME_MAX];
- char file_name [FILENAME_MAX];
- FILE *fp;
-
- /* Set file_path */
- if (!fpath) {
- /* Default path */
- save_clr();
- snprintf(file_path, FILENAME_MAX, "%s", saved_path);
- } else {
- snprintf(file_path, FILENAME_MAX, "%s", fpath);
- }
-
- /* Set file_name */
- if (!save_as) {
- /* Default name */
- snprintf(saved_name, FILENAME_MAX, "%s", SAVED_NAME_DEFAULT);
- /* Request file name */
- user_iface_fname(saved_path, saved_name);
- } else {
- snprintf(saved_name, FILENAME_MAX, "%s", save_as);
- }
-
- /* Prepend the path */
- snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name);
-
- fp = fopen(file_name, "r");
- if (fp) {
- /* Name in use; ask once more */
- fclose(fp);
- user_iface_fname(saved_path, saved_name);
- snprintf(file_name, FILENAME_MAX, "%s/%s", file_path, saved_name);
- }
-
- /* Write into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN, "%s", saved_name);
- user_iface_log.lvl[user_iface_log.len] = 2;
- (user_iface_log.len)++;
-
-
- /* Write to a new file */
- cv::imwrite(file_name, image);
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/save/tmp/Makefile b/modules/save/tmp/Makefile
deleted file mode 100644
index e33755e..0000000
--- a/modules/save/tmp/Makefile
+++ /dev/null
@@ -1,46 +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 $@"
- @echo ""
-
-
-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 1738e4c..0000000
--- a/modules/tmp/Makefile
+++ /dev/null
@@ -1,47 +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 $@"
- @echo ""
-
-
-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 dffc625..0000000
--- a/modules/user/inc/user_clui.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_USER_CLUI_H
- # define VA_USER_CLUI_H
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
-void user_clui_init (void);
-int user_clui (const char *title, const char *subtitle);
-void user_clui_fname (const char *filepath, char *filename);
-void user_clui_show_log (const char *title, const char *subtitle);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* user_clui.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/user/inc/user_iface.h b/modules/user/inc/user_iface.h
deleted file mode 100644
index 2034e22..0000000
--- a/modules/user/inc/user_iface.h
+++ /dev/null
@@ -1,150 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_USER_IFACE_H
- # define VA_USER_IFACE_H
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
- # define LOG_LEN (1048576)
- # define LOG_LINE_LEN (80)
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* intX_t */
- #include <stdint.h>
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Player_Iface_Mode {
- USER_IFACE_FOO,
- USER_IFACE_CLUI,
- USER_IFACE_TUI
- };
-
- enum Player_Iface_Action {
- USER_IFACE_ACT_FOO = 0,
-
- USER_IFACE_ACT_ALX = 0x0010,
- USER_IFACE_ACT_LOCAL_MAX,
- 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 = 0x0100,
- USER_IFACE_ACT_PIXEL_VALUE,
- 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_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_ZB = 0x0200,
- USER_IFACE_ACT_DECODE,
-
- USER_IFACE_ACT_OCR = 0x0400,
- USER_IFACE_ACT_READ,
-
- USER_IFACE_ACT_ORB = 0x0800,
- USER_IFACE_ACT_ALIGN,
-
- USER_IFACE_ACT_IMGI = 0x1000,
- USER_IFACE_ACT_APPLY,
- USER_IFACE_ACT_DISCARD,
- USER_IFACE_ACT_SAVE_MEM,
- USER_IFACE_ACT_LOAD_MEM,
- USER_IFACE_ACT_SAVE_REF,
-
- USER_IFACE_ACT_SAVE = 0x2000,
- USER_IFACE_ACT_SAVE_FILE,
- USER_IFACE_ACT_SAVE_UPDT,
-
- USER_IFACE_ACT_PROC = 0x4000,
- USER_IFACE_ACT_PROC_LABEL,
- USER_IFACE_ACT_PROC_COINS,
- USER_IFACE_ACT_PROC_RESISTOR,
-
- USER_IFACE_ACT_USRI = 0x8000,
- 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 76e16dc..0000000
--- a/modules/user/inc/user_iface.hpp
+++ /dev/null
@@ -1,162 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_USER_IFACE_HPP
- # define VA_USER_IFACE_HPP
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
- # define LOG_LEN (1048576)
- # define LOG_LINE_LEN (80)
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* intX_t */
- #include <cstdint>
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Player_Iface_Mode {
- USER_IFACE_FOO,
- USER_IFACE_CLUI,
- USER_IFACE_TUI
- };
-
- enum Player_Iface_Action {
- USER_IFACE_ACT_FOO = 0,
-
- USER_IFACE_ACT_ALX = 0x0010,
- USER_IFACE_ACT_LOCAL_MAX,
- 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 = 0x0100,
- USER_IFACE_ACT_PIXEL_VALUE,
- 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_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_ZB = 0x0200,
- USER_IFACE_ACT_DECODE,
-
- USER_IFACE_ACT_OCR = 0x0400,
- USER_IFACE_ACT_READ,
-
- USER_IFACE_ACT_ORB = 0x0800,
- USER_IFACE_ACT_ALIGN,
-
- USER_IFACE_ACT_IMGI = 0x1000,
- USER_IFACE_ACT_APPLY,
- USER_IFACE_ACT_DISCARD,
- USER_IFACE_ACT_SAVE_MEM,
- USER_IFACE_ACT_LOAD_MEM,
- USER_IFACE_ACT_SAVE_REF,
-
- USER_IFACE_ACT_SAVE = 0x2000,
- USER_IFACE_ACT_SAVE_FILE,
- USER_IFACE_ACT_SAVE_UPDT,
-
- USER_IFACE_ACT_PROC = 0x4000,
- USER_IFACE_ACT_PROC_LABEL,
- USER_IFACE_ACT_PROC_COINS,
- USER_IFACE_ACT_PROC_RESISTOR,
-
- USER_IFACE_ACT_USRI = 0x8000,
- 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 d8f9a3c..0000000
--- a/modules/user/inc/user_tui.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_USER_TUI_H
- # define VA_USER_TUI_H
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
-void user_tui_init (void);
-void user_tui_cleanup (void);
-int user_tui (const char *title, const char *subtitle);
-void user_tui_show_log (const char *title, const char *subtitle);
-void user_tui_fname (const char *filepath, char *filename);
-double user_tui_getdbl (double m, double def, double M,
- const char *title, const char *help);
-int64_t user_tui_getint (double m, int64_t def, double M,
- const char *title, const char *help);
-void user_tui_show_ocr (void);
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* user_tui.h */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/user/src/user_clui.c b/modules/user/src/user_clui.c
deleted file mode 100644
index fffc79f..0000000
--- a/modules/user/src/user_clui.c
+++ /dev/null
@@ -1,563 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* printf() & fgets() & sscanf() */
- #include <stdio.h>
-
-/* Project -------------------------------------------------------------------*/
- /*img_ocr_text */
- #include "img_iface.h"
-
-/* libalx --------------------------------------------------------------------*/
- /* alx_sscan_fname() */
- #include "alx_input.h"
-
-/* Module --------------------------------------------------------------------*/
- /* user_iface_log */
- #include "user_iface.h"
-
- #include "user_clui.h"
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
- # define BUFF_SIZE (1024)
-
-
-/******************************************************************************
- ******* static variables *****************************************************
- ******************************************************************************/
-static int log_pos;
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
- /* Log */
-static void log_loop (void);
- /* Input */
-static int usr_input (void);
- /* Help */
-static void show_help (void);
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void user_clui_init (void)
-{
- log_pos = 0;
-}
-
-int user_clui (const char *title, const char *subtitle)
-{
- int action;
-
- /* User action */
- show_help();
- user_clui_show_log(title, subtitle);
- action = usr_input();
-
- return action;
-}
-
-void user_clui_fname (const char *filepath, char *filename)
-{
- puts("File name:");
- puts("Valid extensions: .bmp .dib .jpeg .png .pbm .pgm .ppm .tiff");
- fgets(filename, FILENAME_MAX, stdin);
- alx_sscan_fname(filepath, filename, false, filename);
-}
-
-void user_clui_show_log (const char *title, const char *subtitle)
-{
- puts("________________________________________________________________________________");
-
- /* Board */
- log_loop();
-
- /* Subtitle & title */
- printf("%s - %s\n", subtitle, title);
- puts("--------------------------------------------------------------------------------");
-
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-/* Log -----------------------------------------------------------------------*/
-static void log_loop (void)
-{
- int lvl;
-
- putchar('\n');
- for (; log_pos < user_iface_log.len; log_pos++) {
- if (user_iface_log.lvl[log_pos] <= user_iface_log.visible) {
- for (lvl = 0; lvl < user_iface_log.lvl[log_pos]; lvl++) {
- printf("\t");
- }
- printf("%s\n", user_iface_log.line[log_pos]);
- }
- }
- putchar('\n');
-}
-
-/* Input ---------------------------------------------------------------------*/
-static int usr_input (void)
-{
- int action;
-
- char buff [BUFF_SIZE];
- char ch [10];
-
- int i;
- for (i = 0; i < 10; i++) {
- ch[i] = '\0';
- }
- buff[0] = '\0';
-
- /* Wait for input */
- fgets(buff, BUFF_SIZE, stdin);
-
- /* Interpret input */
- sscanf(buff, " %c%c%c%c%c", &ch[0], &ch[1], &ch[2], &ch[3], &ch[4]);
- switch (ch[0]) {
- case '+':
- action = USER_IFACE_ACT_APPLY;
- break;
-
- case '-':
- action = USER_IFACE_ACT_DISCARD;
- break;
-
- case 'e':
- /* Exercises from class */
- switch (ch[1]) {
- case '1':
- switch (ch[2]) {
- case '0':
- action = USER_IFACE_ACT_PROC_LABEL;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '3':
- switch (ch[2]) {
- case '0':
- action = USER_IFACE_ACT_PROC_COINS;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '4':
- switch (ch[2]) {
- case '0':
- action = USER_IFACE_ACT_PROC_RESISTOR;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
-
- case 'f':
- /* Use simple funtions */
- switch (ch[1]) {
- case '0':
- /* img_alx */
- switch (ch[2]) {
- case '0':
- action = USER_IFACE_ACT_LOCAL_MAX;
- break;
- case '1':
- /* Lines */
- switch (ch[3]) {
- case '0':
- action = USER_IFACE_ACT_LINES_HORIZONTAL;
- break;
- case '1':
- action = USER_IFACE_ACT_LINES_VERTICAL;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '2':
- /* Smooth */
- switch (ch[3]) {
- case '0':
- action = USER_IFACE_ACT_MEAN_HORIZONTAL;
- break;
- case '1':
- action = USER_IFACE_ACT_MEAN_VERTICAL;
- break;
- case '2':
- action = USER_IFACE_ACT_MEDIAN_HORIZONTAL;
- break;
- case '3':
- action = USER_IFACE_ACT_MEDIAN_VERTICAL;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '1':
- /* img_cv */
- switch (ch[2]) {
- case '0':
- /* Core: The core functionality */
- switch (ch[3]) {
- case '0':
- /* Pixel */
- switch (ch[4]) {
- case '0':
- action = USER_IFACE_ACT_PIXEL_VALUE;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '1':
- /* ROI */
- switch (ch[4]) {
- case '0':
- action = USER_IFACE_ACT_SET_ROI;
- break;
- case '1':
- action = USER_IFACE_ACT_SET_ROI_2RECT;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '2':
- /* Operations on Arrays */
- switch (ch[4]) {
- case '0':
- action = USER_IFACE_ACT_AND_2REF;
- break;
- case '1':
- action = USER_IFACE_ACT_NOT;
- break;
- case '2':
- action = USER_IFACE_ACT_OR_2REF;
- break;
- case '3':
- action = USER_IFACE_ACT_COMPONENT;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '1':
- /* Imgproc: Image processing */
- switch (ch[3]) {
- case '0':
- /* Image filtering */
- switch (ch[4]) {
- case '0':
- action = USER_IFACE_ACT_DILATE;
- break;
- case '1':
- action = USER_IFACE_ACT_ERODE;
- break;
- case '2':
- action = USER_IFACE_ACT_DILATE_ERODE;
- break;
- case '3':
- action = USER_IFACE_ACT_ERODE_DILATE;
- break;
- case '4':
- action = USER_IFACE_ACT_SMOOTH;
- break;
- case '5':
- action = USER_IFACE_ACT_SOBEL;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '1':
- /* Geometric image transformations */
- switch (ch[4]) {
- case '0':
- action = USER_IFACE_ACT_ROTATE_ORTO;
- break;
- case '1':
- action = USER_IFACE_ACT_ROTATE;
- break;
- case '2':
- action = USER_IFACE_ACT_ROTATE_2RECT;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '2':
- /* Miscellaneous image transformations */
- switch (ch[4]) {
- case '0':
- action = USER_IFACE_ACT_ADAPTIVE_THRESHOLD;
- break;
- case '1':
- action = USER_IFACE_ACT_CVT_COLOR;
- break;
- case '2':
- action = USER_IFACE_ACT_DISTANCE_TRANSFORM;
- break;
- case '3':
- action = USER_IFACE_ACT_THRESHOLD;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '3':
- /* Histograms */
- switch (ch[4]) {
- case '0':
- action = USER_IFACE_ACT_HISTOGRAM;
- break;
- case '1':
- action = USER_IFACE_ACT_HISTOGRAM_C3;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '4':
- /* Structural analysis and shape descriptors */
- switch (ch[4]) {
- case '0':
- action = USER_IFACE_ACT_CONTOURS;
- break;
- case '1':
- action = USER_IFACE_ACT_CONTOURS_SIZE;
- break;
- case '2':
- action = USER_IFACE_ACT_BOUNDING_RECT;
- break;
- case '3':
- action = USER_IFACE_ACT_FIT_ELLIPSE;
- break;
- case '4':
- action = USER_IFACE_ACT_MIN_AREA_RECT;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '5':
- /* Feature detection */
- switch (ch[4]) {
- case '0':
- action = USER_IFACE_ACT_HOUGH_CIRCLES;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '2':
- /* img_orb */
- switch (ch[2]) {
- case '0':
- action = USER_IFACE_ACT_ALIGN;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '3':
- /* img_zbar */
- switch (ch[2]) {
- case '0':
- action = USER_IFACE_ACT_DECODE;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '4':
- /* img_ocr */
- switch (ch[2]) {
- case '0':
- action = USER_IFACE_ACT_READ;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
-
- case 'l':
- action = USER_IFACE_ACT_LOAD_MEM;
- break;
-
- case 'm':
- action = USER_IFACE_ACT_SAVE_MEM;
- break;
-
- case 'q':
- action = USER_IFACE_ACT_QUIT;
- break;
-
- case 'r':
- action = USER_IFACE_ACT_SAVE_REF;
- break;
-
- case 's':
- action = USER_IFACE_ACT_SAVE_FILE;
- break;
-
- case 'u':
- /* User iface actions */
- switch (ch[1]) {
- case '1':
- action = USER_IFACE_ACT_SHOW_OCR;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
-
- case 'x':
- /* Special sequence "xyzzy" */
- if (ch[1] == 'y') {
- if (ch[2] == 'z') {
- if (ch[3] == 'z') {
- if (ch[4] == 'y') {
- action = USER_IFACE_ACT_FOO;
- }
- }
- }
- }
- break;
-
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
-
- return action;
-}
-
-/* * * * * * * * * *
- * * * Help * * * * * * *
- * * * * * * * * * */
-static void show_help (void)
-{
- // FIXME
- printf("Apply: %s\n", "Space");
- printf("Discard: %s\n", "Backspace");
- printf("Save to mem: %c\n", 'm');
- printf("Load from mem: %c\n", 'l');
- printf("Save to ref: %c\n", 'r');
- printf("Save to file: %c\n", 's');
- printf("Functions:\n");
- printf(" - Local maxima: %s\n", "f00");
- printf(" - Horizontal lines: %s\n", "f010");
- printf(" - Vertical lines: %s\n", "f011");
- printf(" - Horizontal mean: %s\n", "f020");
- printf(" - Vertical mean: %s\n", "f021");
- printf(" - Horizontal median: %s\n", "f022");
- printf(" - Vertical median: %s\n", "f023");
- printf(" - Pixel value: %s\n", "f1000");
- printf(" - Set ROI: %s\n", "f1010");
- printf(" - Set ROI 2rect: %s\n", "f1011");
- printf(" - Bitwise AND 2ref: %s\n", "f1020");
- printf(" - Bitwise NOT: %s\n", "f1021");
- printf(" - Bitwise OR 2ref: %s\n", "f1022");
- printf(" - Component: %s\n", "f1023");
- printf(" - Dilate: %s\n", "f1100");
- printf(" - Erode: %s\n", "f1101");
- printf(" - D-E: %s\n", "f1102");
- printf(" - E-D: %s\n", "f1103");
- printf(" - Smooth: %s\n", "f1104");
- printf(" - Sobel: %s\n", "f1105");
- printf(" - Rotate ortogonally: %s\n", "f1110");
- printf(" - Rotate: %s\n", "f1111");
- printf(" - Rotate 2rect_rot: %s\n", "f1112");
- printf(" - Adaptive threshold: %s\n", "f1120");
- printf(" - Cvt color: %s\n", "f1121");
- printf(" - Distance transform: %s\n", "f1122");
- printf(" - Threshold: %s\n", "f1123");
- printf(" - Histogram: %s\n", "f1130");
- printf(" - Histogram (3 chan): %s\n", "f1131");
- printf(" - Contours: %s\n", "f1140");
- printf(" - Contours size: %s\n", "f1141");
- printf(" - Bounding rectangle: %s\n", "f1142");
- printf(" - Fit ellipse: %s\n", "f1143");
- printf(" - Min. area rectangle: %s\n", "f1144");
- printf(" - Hough circles: %s\n", "f1150");
- printf(" - Align 2ref (ORB): %s\n", "f20");
- printf(" - Scan codes (ZBAR): %s\n", "f30");
- printf(" - Scan text (OCR): %s\n", "f40");
- printf("Exercises:\n");
- printf(" - Label: %s\n", "e10");
- printf(" - Coins: %s\n", "e30");
- printf(" - Resistor: %s\n", "e40");
- printf("Other:\n");
- printf(" - Show OCR text: %s\n", "u1");
- printf("Quit: %c\n", 'q');
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/user/src/user_tui.c b/modules/user/src/user_tui.c
deleted file mode 100644
index e664da2..0000000
--- a/modules/user/src/user_tui.c
+++ /dev/null
@@ -1,706 +0,0 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- #include <inttypes.h>
- /* WINDOW & wgetch() & KEY_... & ... */
- #include <ncurses.h>
-
-/* libalx --------------------------------------------------------------------*/
- /* alx_..._curses() & alx_ncur_prn_...() */
- #include "alx_ncur.h"
-
-/* Project -------------------------------------------------------------------*/
- /*img_ocr_text */
- #include "img_iface.h"
-
-/* Module --------------------------------------------------------------------*/
- /* user_iface_log */
- #include "user_iface.h"
-
- #include "user_tui.h"
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-static WINDOW *win_log;
-static WINDOW *win_help;
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
- /* Log */
-static void log_loop (void);
- /* Input */
-static int usr_input (void);
- /* Help */
-static void show_help (void);
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void user_tui_init (void)
-{
- /* Use curses mode */
- alx_resume_curses();
-
- /* Dimensions: log */
- const int h1 = 54;
- const int w1 = 40;
- const int r1 = 0;
- const int c1 = 30;
- win_log = newwin(h1, w1, r1, c1);
-
- /* Dimensions: help */
- const int h2 = 54;
- const int w2 = 40;
- const int r2 = 0;
- const int c2 = 0;
- win_help = newwin(h2, w2, r2, c2);
-
- /* Activate keypad, don't echo input */
- keypad(win_log, true);
- noecho();
-}
-
-void user_tui_cleanup (void)
-{
- /* Del wins & return to terminal mode */
- alx_win_del(win_log);
- alx_win_del(win_help);
- alx_pause_curses();
-}
-
-int user_tui (const char *title, const char *subtitle)
-{
- int action;
-
- show_help();
- user_tui_show_log(title, subtitle);
- action = usr_input();
-
- return action;
-}
-
-void user_tui_fname (const char *filepath, char *filename)
-{
- /* Input box */
- int w;
- int r;
- w = 75;
- r = 10;
-
- /* Request name */
- alx_w_getfname(filepath, filename, false, w, r, "File name:",
- "Valid extensions: .bmp .dib .jpeg .png .pbm .pgm .ppm .tiff");
-}
-
-void user_tui_show_log (const char *title, const char *subtitle)
-{
- /* Clear & box */
- werase(win_log);
- box(win_log, 0, 0);
-
- /* Title */
- alx_ncur_prn_title(win_log, title);
- /* Subtitle */
- alx_ncur_prn_subtitle(win_log, subtitle);
-
- /* Log */
- log_loop();
-
- /* Refresh */
- wrefresh(win_log);
-}
-
-double user_tui_getdbl (double m, double def, double M,
- const char *title, const char *help)
-{
- /* Input box */
- int w;
- int r;
- w = 75;
- r = 10;
-
- /* Request int */
- double R;
- R = alx_w_getdbl(w, r, title, m, def, M, help);
- return R;
-}
-
-int64_t user_tui_getint (double m, int64_t def, double M,
- const char *title, const char *help)
-{
- /* Input box */
- int w;
- int r;
- w = 75;
- r = 10;
-
- /* Request int */
- int64_t i;
- i = alx_w_getint(w, r, title, m, def, M, help);
- return i;
-}
-
-void user_tui_show_ocr (void)
-{
- alx_pause_curses();
-
- printf("%s", img_ocr_text);
- getchar();
-
- alx_resume_curses();
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-/* Log -----------------------------------------------------------------------*/
-static void log_loop (void)
-{
- int i;
- int i_0;
- int l;
- int l_0;
-
- if (user_iface_log.len > 51) {
- i_0 = user_iface_log.len - 51;
- l_0 = 1;
- mvwprintw(win_log, 1, 10, "...");
- } else {
- i_0 = 0;
- l_0 = 0;
- }
-
- l = l_0;
- for (i = i_0; i < user_iface_log.len; i++) {
- if (user_iface_log.lvl[i] <= user_iface_log.visible) {
- mvwprintw(win_log, (1 + l),
- (1 + 4 * user_iface_log.lvl[i]),
- "%.*s",
- 40 - 2 - 4 * user_iface_log.lvl[i],
- user_iface_log.line[i]);
- l++;
- }
- }
-}
-
-/* Input ---------------------------------------------------------------------*/
-static int usr_input (void)
-{
- int action;
- wchar_t ch;
-
- /* Interpret input */
- ch = wgetch(win_log);
- switch (ch) {
- case ' ':
- action = USER_IFACE_ACT_APPLY;
- break;
-
- /* ASCII 0x08 is BS */
- case KEY_BACKSPACE:
- case 0x08:
- action = USER_IFACE_ACT_DISCARD;
- break;
-
- case 'e':
- /* Exercises from class */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '1':
- /* Label */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_PROC_LABEL;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '3':
- /* Resistor */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_PROC_COINS;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '4':
- /* Resistor */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_PROC_RESISTOR;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
-
- case 'f':
- /* Use simple funtions */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- /* img_alx */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_LOCAL_MAX;
- break;
- case '1':
- /* Lines */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_LINES_HORIZONTAL;
- break;
- case '1':
- action = USER_IFACE_ACT_LINES_VERTICAL;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '2':
- /* Smooth */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_MEAN_HORIZONTAL;
- break;
- case '1':
- action = USER_IFACE_ACT_MEAN_VERTICAL;
- break;
- case '2':
- action = USER_IFACE_ACT_MEDIAN_HORIZONTAL;
- break;
- case '3':
- action = USER_IFACE_ACT_MEDIAN_VERTICAL;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '1':
- /* img_cv */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- /* Core: The core functionality */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- /* Pixel */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_PIXEL_VALUE;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '1':
- /* ROI */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_SET_ROI;
- break;
- case '1':
- action = USER_IFACE_ACT_SET_ROI_2RECT;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '2':
- /* Operations on Arrays */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_AND_2REF;
- break;
- case '1':
- action = USER_IFACE_ACT_NOT;
- break;
- case '2':
- action = USER_IFACE_ACT_OR_2REF;
- break;
- case '3':
- action = USER_IFACE_ACT_COMPONENT;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '1':
- /* Imgproc: Image processing */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- /* Image filtering */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_DILATE;
- break;
- case '1':
- action = USER_IFACE_ACT_ERODE;
- break;
- case '2':
- action = USER_IFACE_ACT_DILATE_ERODE;
- break;
- case '3':
- action = USER_IFACE_ACT_ERODE_DILATE;
- break;
- case '4':
- action = USER_IFACE_ACT_SMOOTH;
- break;
- case '5':
- action = USER_IFACE_ACT_SOBEL;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '1':
- /* Geometric image transformations */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_ROTATE_ORTO;
- break;
- case '1':
- action = USER_IFACE_ACT_ROTATE;
- break;
- case '2':
- action = USER_IFACE_ACT_ROTATE_2RECT;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '2':
- /* Miscellaneous image transformations */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_ADAPTIVE_THRESHOLD;
- break;
- case '1':
- action = USER_IFACE_ACT_CVT_COLOR;
- break;
- case '2':
- action = USER_IFACE_ACT_DISTANCE_TRANSFORM;
- break;
- case '3':
- action = USER_IFACE_ACT_THRESHOLD;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '3':
- /* Histograms */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_HISTOGRAM;
- break;
- case '1':
- action = USER_IFACE_ACT_HISTOGRAM_C3;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '4':
- /* Structural analysis and shape descriptors */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_CONTOURS;
- break;
- case '1':
- action = USER_IFACE_ACT_CONTOURS_SIZE;
- break;
- case '2':
- action = USER_IFACE_ACT_BOUNDING_RECT;
- break;
- case '3':
- action = USER_IFACE_ACT_FIT_ELLIPSE;
- break;
- case '4':
- action = USER_IFACE_ACT_MIN_AREA_RECT;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '5':
- /* Feature detection */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_HOUGH_CIRCLES;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '2':
- /* img_orb */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_ALIGN;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '3':
- /* img_zbar */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_DECODE;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- case '4':
- /* img_ocr */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '0':
- action = USER_IFACE_ACT_READ;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
-
- case 'l':
- action = USER_IFACE_ACT_LOAD_MEM;
- break;
-
- case 'm':
- action = USER_IFACE_ACT_SAVE_MEM;
- break;
-
- case 'q':
- action = USER_IFACE_ACT_QUIT;
- break;
-
- case 'r':
- action = USER_IFACE_ACT_SAVE_REF;
- break;
-
- case 's':
- action = USER_IFACE_ACT_SAVE_FILE;
- break;
-
- case 'u':
- /* User iface actions */
- ch = wgetch(win_log);
-
- switch (ch) {
- case '1':
- action = USER_IFACE_ACT_SHOW_OCR;
- break;
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
- break;
-
- case 'x':
- /* Special sequence "xyzzy" */
- ch = wgetch(win_log);
- if (ch == 'y') {
- ch = wgetch(win_log);
- if (ch == 'z') {
-
- ch = wgetch(win_log);
- if (ch == 'z') {
-
- ch = wgetch(win_log);
- if (ch == 'y') {
- action = USER_IFACE_ACT_FOO;
- }
- }
- }
- }
- break;
-
- default:
- action = USER_IFACE_ACT_FOO;
- break;
- }
-
- return action;
-}
-
-/* * * * * * * * * *
- * * * Help * * * * * * *
- * * * * * * * * * */
-static void show_help (void)
-{
- /* Clear */
- werase(win_help);
-
- int r;
- int c;
-
- r = 0;
- c = 0;
- mvwprintw(win_help, r++, c, "Apply: %s", "Space");
- mvwprintw(win_help, r++, c, "Discard: %s", "BS");
- mvwprintw(win_help, r++, c, "Save to mem: %c", 'm');
- mvwprintw(win_help, r++, c, "Load from mem: %c", 'l');
- mvwprintw(win_help, r++, c, "Save to ref: %c", 'r');
- mvwprintw(win_help, r++, c, "Save to file: %c", 's');
- mvwprintw(win_help, r++, c, "Functions:");
- mvwprintw(win_help, r++, c, " - Local maxima: %s", "f00");
- mvwprintw(win_help, r++, c, " - Horizontal lines: %s", "f010");
- mvwprintw(win_help, r++, c, " - Vertical lines: %s", "f011");
- mvwprintw(win_help, r++, c, " - Horizontal mean: %s", "f020");
- mvwprintw(win_help, r++, c, " - Vertical mean: %s", "f021");
- mvwprintw(win_help, r++, c, " - Horizontal median: %s", "f022");
- mvwprintw(win_help, r++, c, " - Vertical median: %s", "f023");
- mvwprintw(win_help, r++, c, " - Pixel value: %s", "f1000");
- mvwprintw(win_help, r++, c, " - Set ROI: %s", "f1010");
- mvwprintw(win_help, r++, c, " - Set ROI 2rect: %s", "f1011");
- mvwprintw(win_help, r++, c, " - Bitwise AND 2ref: %s", "f1020");
- mvwprintw(win_help, r++, c, " - Bitwise NOT: %s", "f1021");
- mvwprintw(win_help, r++, c, " - Bitwise OR 2ref: %s", "f1022");
- mvwprintw(win_help, r++, c, " - Component: %s", "f1023");
- mvwprintw(win_help, r++, c, " - Dilate: %s", "f1100");
- mvwprintw(win_help, r++, c, " - Erode: %s", "f1101");
- mvwprintw(win_help, r++, c, " - D-E: %s", "f1102");
- mvwprintw(win_help, r++, c, " - E-D: %s", "f1103");
- mvwprintw(win_help, r++, c, " - Smooth: %s", "f1104");
- mvwprintw(win_help, r++, c, " - Sobel: %s", "f1105");
- mvwprintw(win_help, r++, c, " - Rotate ortogonally: %s", "f1110");
- mvwprintw(win_help, r++, c, " - Rotate: %s", "f1111");
- mvwprintw(win_help, r++, c, " - Rotate 2rect_rot: %s", "f1112");
- mvwprintw(win_help, r++, c, " - Adaptive threshold: %s", "f1120");
- mvwprintw(win_help, r++, c, " - Cvt color: %s", "f1121");
- mvwprintw(win_help, r++, c, " - Distance transform: %s", "f1122");
- mvwprintw(win_help, r++, c, " - Threshold: %s", "f1123");
- mvwprintw(win_help, r++, c, " - Histogram: %s", "f1130");
- mvwprintw(win_help, r++, c, " - Histogram (3 chan): %s", "f1131");
- mvwprintw(win_help, r++, c, " - Contours: %s", "f1140");
- mvwprintw(win_help, r++, c, " - Contours size: %s", "f1141");
- mvwprintw(win_help, r++, c, " - Bounding rectangle: %s", "f1142");
- mvwprintw(win_help, r++, c, " - Fit ellipse: %s", "f1143");
- mvwprintw(win_help, r++, c, " - Min. area rectangle: %s", "f1144");
- mvwprintw(win_help, r++, c, " - Hough circles: %s", "f1150");
- mvwprintw(win_help, r++, c, " - Align 2ref (ORB): %s", "f20");
- mvwprintw(win_help, r++, c, " - Scan codes (ZBAR): %s", "f30");
- mvwprintw(win_help, r++, c, " - Scan text (OCR): %s", "f40");
- mvwprintw(win_help, r++, c, "Exercises:");
- mvwprintw(win_help, r++, c, " - Label: %s", "e10");
- mvwprintw(win_help, r++, c, " - Coins: %s", "e30");
- mvwprintw(win_help, r++, c, " - Resistor: %s", "e40");
- mvwprintw(win_help, r++, c, "Other:");
- mvwprintw(win_help, r++, c, " - Show OCR: %s", "u1");
- mvwprintw(win_help, r++, c, "Quit: %c", 'q');
-
- /* Refresh */
- wrefresh(win_help);
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
diff --git a/modules/user/tmp/Makefile b/modules/user/tmp/Makefile
deleted file mode 100644
index 2dc948f..0000000
--- a/modules/user/tmp/Makefile
+++ /dev/null
@@ -1,90 +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 = 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 = 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 $@"
- @echo ""
-
-
-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 9e98b13..0776f74 100644
--- a/share/LICENSE.txt
+++ b/share/vision-artificial/LICENSE.txt
@@ -67,7 +67,7 @@ patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
-
+
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
@@ -122,7 +122,7 @@ above, provided that you also meet all of these conditions:
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
-
+
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
@@ -180,7 +180,7 @@ access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
-
+
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
@@ -237,7 +237,7 @@ impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
-
+
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
@@ -290,7 +290,7 @@ PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
-
+
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
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/src/about/about.c b/src/about/about.c
new file mode 100644
index 0000000..60f5104
--- /dev/null
+++ b/src/about/about.c
@@ -0,0 +1,144 @@
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+#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 (0xFFFF) /* 64 KiB */
+#define BEGINNING "\n┌──────────────────────────────────────────────────────────────────────────────┐\n"
+#define ENDING "└──────────────────────────────────────────────────────────────────────────────┘\n\n"
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* structs / unions *****************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+char share_path [FILENAME_MAX];
+
+
+/******************************************************************************
+ ******* static functions (prototypes) ****************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* global functions *****************************************************
+ ******************************************************************************/
+void about_init (void)
+{
+
+ if (snprintf(share_path, FILENAME_MAX, "%s/estadistica/",
+ INSTALL_SHARE_DIR) >= FILENAME_MAX) {
+ goto err;
+ }
+ return;
+err:
+ printf("Path is too large and has been truncated\n");
+ exit(EXIT_FAILURE);
+}
+
+void snprint_share_file (ptrdiff_t size, char buff[restrict size],
+ int file)
+{
+ char fname [FILENAME_MAX];
+
+ switch (file) {
+ case SHARE_COPYRIGHT:
+ if (snprintf(fname, FILENAME_MAX, "%s/%s",
+ share_path,
+ "COPYRIGHT.txt") >= FILENAME_MAX) {
+ goto err;
+ }
+ break;
+ case SHARE_DISCLAIMER:
+ if (snprintf(fname, FILENAME_MAX, "%s/%s",
+ share_path,
+ "DISCLAIMER.txt") >= FILENAME_MAX) {
+ goto err;
+ }
+ break;
+ case SHARE_HELP:
+ if (snprintf(fname, FILENAME_MAX, "%s/%s",
+ share_path,
+ "HELP.txt") >= FILENAME_MAX) {
+ goto err;
+ }
+ break;
+ case SHARE_LICENSE:
+ if (snprintf(fname, FILENAME_MAX, "%s/%s",
+ share_path,
+ "LICENSE.txt") >= FILENAME_MAX) {
+ goto err;
+ }
+ break;
+ case SHARE_USAGE:
+ if (snprintf(fname, FILENAME_MAX, "%s/%s",
+ share_path,
+ "USAGE.txt") >= FILENAME_MAX) {
+ goto err;
+ }
+ break;
+ }
+
+ if (alx_snprint_file(size, buff, fname) < 0)
+ printf("%s: %s\n", errno_str[errno][0], errno_str[errno][1]);
+
+ return;
+
+err:
+ printf("Path is too large and has been truncated\n");
+ printf("File could not be shown!\n");
+}
+
+void print_share_file (int file)
+{
+ char str [BUFF_SIZE_TEXT];
+
+ snprint_share_file(BUFF_SIZE_TEXT, str, file);
+
+ printf(BEGINNING);
+ printf("%s", str);
+ printf(ENDING);
+}
+
+void print_version (void)
+{
+
+ 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 2a4c18f..5562503 100644
--- a/modules/ctrl/src/start.c
+++ b/src/ctrl/start.c
@@ -1,104 +1,100 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* errno */
- #include <errno.h>
- /* printf() */
- #include <stdio.h>
-
-/* Project -------------------------------------------------------------------*/
- /* img_iface_load() */
- #include "img_iface.h"
- /* proc_iface_series() */
- #include "proc_iface.h"
- /* saved_name*/
- #include "save.h"
- /* user_iface() */
- #include "user_iface.h"
-
-/* Module --------------------------------------------------------------------*/
- #include "start.h"
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-int start_mode;
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void start_foo (void);
-static void start_single (void);
-static void start_series (void);
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void start_switch (void)
-{
- switch (start_mode) {
- case START_FOO:
- start_foo();
- break;
-
- case START_SINGLE:
- start_single();
- break;
-
- case START_SERIES:
- start_series();
- break;
- }
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void start_foo (void)
-{
- /* empty */
-}
-
-static void start_single (void)
-{
- errno = 0;
- img_iface_load(NULL, saved_name);
-
- if (!errno) {
- user_iface_init();
- user_iface();
- user_iface_cleanup();
- } else {
- printf("errno:%i\n", errno);
- }
-
- img_iface_cleanup();
-}
-
-static void start_series (void)
-{
- int tmp;
- tmp = user_iface_mode;
- user_iface_mode = USER_IFACE_CLUI;
-
- user_iface_init();
- proc_iface_series();
- user_iface_cleanup();
-
- user_iface_mode = tmp;
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+#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"
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+int start_mode;
+
+
+/******************************************************************************
+ ******* static functions *****************************************************
+ ******************************************************************************/
+static void start_foo (void);
+static void start_single (void);
+static void start_series (void);
+
+
+/******************************************************************************
+ ******* main *****************************************************************
+ ******************************************************************************/
+void start_switch (void)
+{
+
+ switch (start_mode) {
+ case START_FOO:
+ start_foo();
+ break;
+
+ case START_SINGLE:
+ start_single();
+ break;
+
+ case START_SERIES:
+ start_series();
+ break;
+ }
+}
+
+
+/******************************************************************************
+ ******* static functions *****************************************************
+ ******************************************************************************/
+static void start_foo (void)
+{
+}
+
+static void start_single (void)
+{
+
+ img_iface_init();
+ errno = 0;
+ img_iface_load(NULL, saved_name);
+
+ if (!errno) {
+ user_iface_init();
+ user_iface();
+ user_iface_cleanup();
+ } else {
+ printf("errno:%i\n", errno);
+ }
+
+ img_iface_cleanup();
+}
+
+static void start_series (void)
+{
+ int tmp;
+
+ tmp = user_iface_mode;
+ user_iface_mode = USER_IFACE_CLUI;
+
+ user_iface_init();
+ proc_iface_series();
+ user_iface_cleanup();
+
+ user_iface_mode = tmp;
+}
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/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/src/image/calib3d.cpp b/src/image/calib3d.cpp
new file mode 100644
index 0000000..43fa360
--- /dev/null
+++ b/src/image/calib3d.cpp
@@ -0,0 +1,125 @@
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+#include "vision-artificial/image/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)
+
+
+/******************************************************************************
+ ******* 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);
+
+
+/******************************************************************************
+ ******* main *****************************************************************
+ ******************************************************************************/
+void img_calib3d_act(class cv::Mat *imgptr, int action, const void *data)
+{
+ switch (action) {
+ case IMG_CALIB3D_ACT_CALIBRATE:
+ img_calib3d_calibrate(imgptr, data);
+ break;
+
+ case IMG_CALIB3D_ACT_UNDISTORT:
+ img_calib3d_undistort(imgptr, data);
+ break;
+ }
+}
+
+
+/******************************************************************************
+ ******* static functions *****************************************************
+ ******************************************************************************/
+static void img_calib3d_calibrate(class cv::Mat *imgptr, const void *data)
+{
+ const struct Img_Iface_Data_Calibrate *data_cast;
+ class cv::Mat *intrinsic_mat;
+ class cv::Mat *dist_coefs;
+ class std::vector <class cv::Mat> *rvecs;
+ class std::vector <class cv::Mat> *tvecs;
+
+ class cv::Size_ <int> pattern_size;
+ class std::vector <class std::vector <class cv::Point3_ <float>>> object_points;
+ class std::vector <class std::vector <class cv::Point_ <float>>> image_points;
+ class std::vector <class cv::Point_ <float>> corners;
+ class std::vector <class cv::Point3_ <float>> obj;
+ bool found;
+
+ data_cast = (const struct Img_Iface_Data_Calibrate *)data;
+ intrinsic_mat = data_cast->intrinsic_mat;
+ dist_coefs = data_cast->dist_coefs;
+ rvecs = data_cast->rvecs;
+ tvecs = data_cast->tvecs;
+
+ pattern_size = cv::Size(CORNERS_HOR, CORNERS_VER);
+ *intrinsic_mat = cv::Mat(3, 3, CV_32FC1);
+ (*intrinsic_mat).ptr<float>(0)[0] = 1;
+ (*intrinsic_mat).ptr<float>(1)[1] = 1;
+
+ for (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,
+ CV_CALIB_CB_ADAPTIVE_THRESH |
+ CV_CALIB_CB_FILTER_QUADS);
+
+ cv::cornerSubPix(*imgptr, corners, cv::Size(11, 11),
+ cv::Size(-1, -1),
+ cv::TermCriteria(CV_TERMCRIT_EPS |
+ CV_TERMCRIT_ITER, 30, 0.1));
+ cv::drawChessboardCorners(*imgptr, pattern_size, corners, found);
+
+ image_points.push_back(corners);
+ object_points.push_back(obj);
+
+ cv::calibrateCamera(object_points, image_points, imgptr->size(),
+ *intrinsic_mat, *dist_coefs, *rvecs, *tvecs);
+}
+
+static void img_calib3d_undistort(class cv::Mat *imgptr, const void *data)
+{
+ class cv::Mat imgtmp;
+ const struct Img_Iface_Data_Undistort *data_cast;
+ const class cv::Mat *intrinsic_mat;
+ const class cv::Mat *dist_coefs;
+
+ data_cast = (const struct Img_Iface_Data_Undistort *)data;
+ intrinsic_mat = data_cast->intrinsic_mat;
+ dist_coefs = data_cast->dist_coefs;
+
+ cv::undistort(*imgptr, imgtmp, *intrinsic_mat, *dist_coefs);
+
+ imgptr->release();
+ imgtmp.copyTo(*imgptr);
+}
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/src/image/cv.cpp b/src/image/cv.cpp
new file mode 100644
index 0000000..b5d4877
--- /dev/null
+++ b/src/image/cv.cpp
@@ -0,0 +1,802 @@
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+#include "vision-artificial/image/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 *****************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* static functions (prototypes) ****************************************
+ ******************************************************************************/
+ /* Core: The core functionality */
+ /* Pixel */
+static void img_cv_pixel_get (const class cv::Mat *imgptr, const void *data);
+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);
+ /* Operations on Arrays */
+static void img_cv_and_2ref (class cv::Mat *imgptr, const void *data);
+static void img_cv_not (class cv::Mat *imgptr);
+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);
+ /* Imgproc: Image processing */
+ /* Image filtering */
+static void img_cv_dilate (class cv::Mat *imgptr, const void *data);
+static void img_cv_erode (class cv::Mat *imgptr, const void *data);
+static void img_cv_smooth (class cv::Mat *imgptr, const void *data);
+static void img_cv_sobel (class cv::Mat *imgptr, const void *data);
+static void img_cv_border (class cv::Mat *imgptr, const void *data);
+ /* Geometric image transformations */
+static void img_cv_mirror (class cv::Mat *imgptr, const void *data);
+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);
+ /* 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_threshold (class cv::Mat *imgptr, const void *data);
+ /* Histograms */
+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);
+ /* Structural analysis and shape descriptors */
+static void img_cv_contours (class cv::Mat *imgptr, const void *data);
+static void img_cv_contours_size (const void *data);
+static void img_cv_bounding_rect (class cv::Mat *imgptr, const void *data);
+static void img_cv_fit_ellipse (class cv::Mat *imgptr, const void *data);
+static void img_cv_min_area_rect (class cv::Mat *imgptr, const void *data);
+ /* Feature detection */
+static void img_cv_hough_circles (class cv::Mat *imgptr, const void *data);
+
+
+/******************************************************************************
+ ******* global functions *****************************************************
+ ******************************************************************************/
+void img_cv_act (class cv::Mat *imgptr, int action, const void *data)
+{
+ switch (action) {
+ case IMG_CV_ACT_PIXEL_GET:
+ img_cv_pixel_get(imgptr, data);
+ break;
+ case IMG_CV_ACT_PIXEL_SET:
+ img_cv_pixel_set(imgptr, data);
+ break;
+
+ case IMG_CV_ACT_SET_ROI:
+ img_cv_set_ROI(imgptr, data);
+ break;
+
+ case IMG_CV_ACT_AND_2REF:
+ img_cv_and_2ref(imgptr, data);
+ break;
+ case IMG_CV_ACT_NOT:
+ img_cv_not(imgptr);
+ break;
+ case IMG_CV_ACT_OR_2REF:
+ img_cv_or_2ref(imgptr, data);
+ break;
+ case IMG_CV_ACT_COMPONENT:
+ img_cv_component(imgptr, data);
+ break;
+
+ case IMG_CV_ACT_DILATE:
+ img_cv_dilate(imgptr, data);
+ break;
+ case IMG_CV_ACT_ERODE:
+ img_cv_erode(imgptr, data);
+ break;
+ case IMG_CV_ACT_SMOOTH:
+ img_cv_smooth(imgptr, data);
+ break;
+ case IMG_CV_ACT_SOBEL:
+ img_cv_sobel(imgptr, data);
+ break;
+ case IMG_CV_ACT_BORDER:
+ img_cv_border(imgptr, data);
+ break;
+
+ case IMG_CV_ACT_MIRROR:
+ img_cv_mirror(imgptr, data);
+ break;
+ case IMG_CV_ACT_ROTATE_ORTO:
+ img_cv_rotate_orto(imgptr, data);
+ break;
+ case IMG_CV_ACT_ROTATE:
+ img_cv_rotate(imgptr, data);
+ break;
+
+ case IMG_CV_ACT_ADAPTIVE_THRESHOLD:
+ img_cv_adaptive_thr(imgptr, data);
+ break;
+ case IMG_CV_ACT_CVT_COLOR:
+ img_cv_cvt_color(imgptr, data);
+ break;
+ case IMG_CV_ACT_DISTANCE_TRANSFORM:
+ img_cv_distance_transform(imgptr);
+ break;
+ case IMG_CV_ACT_THRESHOLD:
+ img_cv_threshold(imgptr, data);
+ break;
+
+ case IMG_CV_ACT_HISTOGRAM:
+ img_cv_histogram(imgptr, data);
+ break;
+ case IMG_CV_ACT_HISTOGRAM_C3:
+ img_cv_histogram_c3(imgptr, data);
+ break;
+
+ case IMG_CV_ACT_CONTOURS:
+ img_cv_contours(imgptr, data);
+ break;
+ case IMG_CV_ACT_CONTOURS_SIZE:
+ img_cv_contours_size(data);
+ break;
+ case IMG_CV_ACT_BOUNDING_RECT:
+ img_cv_bounding_rect(imgptr, data);
+ break;
+ case IMG_CV_ACT_FIT_ELLIPSE:
+ img_cv_fit_ellipse(imgptr, data);
+ break;
+ case IMG_CV_ACT_MIN_AREA_RECT:
+ img_cv_min_area_rect(imgptr, data);
+ break;
+
+ case IMG_CV_ACT_HOUGH_CIRCLES:
+ img_cv_hough_circles(imgptr, data);
+ break;
+ }
+}
+
+
+/******************************************************************************
+ ******* static functions (definitions) ***************************************
+ ******************************************************************************/
+/* Core: The core functionality */
+/* ----- Pixel */
+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;
+ ptrdiff_t x;
+ ptrdiff_t y;
+
+ data_cast = (const struct Img_Iface_Data_Pixel_Get *)data;
+ val = data_cast->val;
+ x = data_cast->x;
+ y = data_cast->y;
+
+ *val = imgptr->at<unsigned char>(y, x);
+}
+
+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;
+ 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;
+
+ imgptr->at<unsigned char>(y, x) = val;
+}
+
+/* ----- ROI */
+static void img_cv_set_ROI (class cv::Mat *imgptr, const void *data)
+{
+ 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);
+
+ (*imgptr)(*rect).copyTo(imgtmp);
+ imgtmp.copyTo(*imgptr);
+
+ imgptr->release();
+ imgtmp.copyTo(*imgptr);
+
+ imgtmp.release();
+}
+
+/* ----- Operations on arrays */
+static void img_cv_and_2ref (class cv::Mat *imgptr, const void *data)
+{
+ const class cv::Mat *img_ref;
+
+ img_ref = (const class cv::Mat *)data;
+
+ cv::bitwise_and(*imgptr, *img_ref, *imgptr);
+}
+
+static void img_cv_not (class cv::Mat *imgptr)
+{
+
+ cv::bitwise_not(*imgptr, *imgptr);
+}
+
+static void img_cv_or_2ref (class cv::Mat *imgptr, const void *data)
+{
+ const class cv::Mat *img_ref;
+
+ img_ref = (const class cv::Mat *)data;
+
+ cv::bitwise_or(*imgptr, *img_ref, *imgptr);
+}
+
+static void img_cv_component (class cv::Mat *imgptr, const void *data)
+{
+ const struct Img_Iface_Data_Component *data_cast;
+ class cv::Mat cmp_img[3];
+ int cmp;
+
+ data_cast = (const struct Img_Iface_Data_Component *)data;
+ cmp = data_cast->cmp;
+
+ cv::split(*imgptr, cmp_img);
+
+ imgptr->release();
+ cmp_img[cmp].copyTo(*imgptr);
+
+ cmp_img[0].release();
+ cmp_img[1].release();
+ cmp_img[2].release();
+}
+
+/* Imgproc: Image processing */
+/* ----- Image filtering */
+static void img_cv_dilate (class cv::Mat *imgptr, const void *data)
+{
+ const struct Img_Iface_Data_Dilate_Erode *data_cast;
+ int i;
+
+ data_cast = (const struct Img_Iface_Data_Dilate_Erode *)data;
+ i = data_cast->i;
+
+ cv::dilate(*imgptr, *imgptr, cv::Mat(), cv::Point(-1,-1), i,
+ cv::BORDER_CONSTANT, cv::Scalar(0));
+}
+
+static void img_cv_erode (class cv::Mat *imgptr, const void *data)
+{
+ const struct Img_Iface_Data_Dilate_Erode *data_cast;
+ int i;
+
+ data_cast = (const struct Img_Iface_Data_Dilate_Erode *)data;
+ i = data_cast->i;
+
+ cv::erode(*imgptr, *imgptr, cv::Mat(), cv::Point(-1,-1), i,
+ cv::BORDER_CONSTANT, cv::Scalar(0));
+}
+
+static void img_cv_smooth (class cv::Mat *imgptr, const void *data)
+{
+ const struct Img_Iface_Data_Smooth *data_cast;
+ int method;
+ int ksize;
+
+ data_cast = (const struct Img_Iface_Data_Smooth *)data;
+ method = data_cast->method;
+ ksize = data_cast->ksize;
+ if (!(ksize % 2))
+ ksize++;
+
+ switch (method) {
+ case IMGI_SMOOTH_MEAN:
+ cv::blur(*imgptr, *imgptr, cv::Size(ksize, ksize),
+ cv::Point(-1,-1), cv::BORDER_DEFAULT);
+ break;
+ case IMGI_SMOOTH_GAUSS:
+ cv::GaussianBlur(*imgptr, *imgptr, cv::Size(ksize, ksize),
+ 0, 0, cv::BORDER_DEFAULT);
+ break;
+ case IMGI_SMOOTH_MEDIAN:
+ cv::medianBlur(*imgptr, *imgptr, ksize);
+ break;
+ }
+}
+
+static void img_cv_sobel (class cv::Mat *imgptr, const void *data)
+{
+ const struct Img_Iface_Data_Sobel *data_cast;
+ int dx;
+ int dy;
+ 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))
+ ksize++;
+
+ cv::Sobel(*imgptr, *imgptr, -1, dx, dy, ksize, 1, 0,
+ cv::BORDER_DEFAULT);
+}
+
+static void img_cv_border (class cv::Mat *imgptr, const void *data)
+{
+ const struct Img_Iface_Data_Border *data_cast;
+ class cv::Mat imgtmp;
+ ptrdiff_t size;
+ ptrdiff_t rows;
+ ptrdiff_t cols;
+
+ /* Data */
+ data_cast = (struct Img_Iface_Data_Border *)data;
+ size = data_cast->size;
+ rows = imgptr->rows;
+ cols = imgptr->cols;
+
+ imgtmp = cv::Mat(cv::Size(cols + size, rows + size), CV_8U);
+
+ cv::copyMakeBorder(*imgptr, imgtmp, size, size, size, size,
+ cv::BORDER_CONSTANT, cv::Scalar(0));
+
+ imgtmp.copyTo(*imgptr);
+
+ imgtmp.release();
+}
+
+/* ----- Geometric image transformations */
+static void img_cv_mirror (class cv::Mat *imgptr, const void *data)
+{
+ const struct Img_Iface_Data_Mirror *data_cast;
+ int axis;
+
+ data_cast = (const struct Img_Iface_Data_Mirror *)data;
+ axis = data_cast->axis;
+
+ cv::flip(*imgptr, *imgptr, axis);
+}
+
+static void img_cv_rotate_orto (class cv::Mat *imgptr, const void *data)
+{
+ const struct Img_Iface_Data_Rotate_Orto *data_cast;
+ int n;
+
+ data_cast = (struct Img_Iface_Data_Rotate_Orto *)data;
+ n = data_cast->n;
+
+ switch (n) {
+ case 1:
+ /* Rotate: transpose and flip around horizontal axis: flip_mode=0 */
+ cv::transpose(*imgptr, *imgptr);
+ cv::flip(*imgptr, *imgptr, 0);
+ break;
+
+ case 2:
+ /* Rotate: Flip both axises: flip_mode=-1 */
+ cv::flip(*imgptr, *imgptr, -1);
+ break;
+
+ case 3:
+ /* Rotate: transpose and flip around vertical axis: flip_mode=1 */
+ cv::transpose(*imgptr, *imgptr);
+ cv::flip(*imgptr, *imgptr, 1);
+ break;
+ }
+}
+
+static void img_cv_rotate (class cv::Mat *imgptr, const void *data)
+{
+ const struct Img_Iface_Data_Rotate *data_cast;
+ const class cv::Point_ <float> *center;
+ 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, size, cv::INTER_LINEAR,
+ cv::BORDER_CONSTANT, cv::Scalar(0, 0, 0));
+
+ map_matrix.release();
+}
+
+/* ----- Miscellaneous image transformations */
+static void img_cv_adaptive_thr (class cv::Mat *imgptr, const void *data)
+{
+ const struct Img_Iface_Data_Adaptive_Thr *data_cast;
+ int method;
+ int thr_typ;
+ 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))
+ ksize++;
+
+ cv::adaptiveThreshold(*imgptr, *imgptr, UINT8_MAX, method, thr_typ,
+ ksize, 0);
+}
+
+static void img_cv_cvt_color (class cv::Mat *imgptr, const void *data)
+{
+ const struct Img_Iface_Data_Cvt_Color *data_cast;
+ int method;
+
+ data_cast = (const struct Img_Iface_Data_Cvt_Color *)data;
+ method = data_cast->method;
+
+ cv::cvtColor(*imgptr, *imgptr, method, 0);
+}
+
+static void img_cv_distance_transform(class cv::Mat *imgptr)
+{
+ class cv::Mat imgtmp;
+
+ cv::distanceTransform(*imgptr,imgtmp, CV_DIST_L2, CV_DIST_MASK_PRECISE);
+
+ /* DistanceTransform gives CV_32F image */
+ imgtmp.convertTo(*imgptr, CV_8U);
+
+ imgtmp.release();
+}
+
+static void img_cv_threshold (class cv::Mat *imgptr, const void *data)
+{
+ const struct Img_Iface_Data_Threshold *data_cast;
+ int thr_typ;
+ int thr_val;
+
+ 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)
+ thr_typ |= cv::THRESH_OTSU;
+
+ 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;
+ const int h_size = 256;
+ const float h_range_arr[] = {0.0, 256.0};
+ const float *h_range = {h_range_arr};
+ 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,
+ true, false);
+
+ /* Init */
+ hist_img->setTo(cv::Scalar(0));
+
+ /* 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 (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 */
+ img_iface_show_hist_c1();
+}
+
+static void img_cv_histogram_c3 (class cv::Mat *imgptr, const void *data)
+{
+ const struct Img_Iface_Data_Histogram *data_cast;
+ const int h_size = 256;
+ const float h_range_arr[] = {0.0, 256.0};
+ const float *h_range = {h_range_arr};
+ 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);
+
+ /* Write components into cmp_img[] */
+ cv::calcHist(&cmp_img[0], 1, 0, cv::Mat(), *hist_c0, 1, &h_size,
+ &h_range, true, false);
+ cv::calcHist(&cmp_img[1], 1, 0, cv::Mat(), *hist_c1, 1, &h_size,
+ &h_range, true, false);
+ cv::calcHist(&cmp_img[2], 1, 0, cv::Mat(), *hist_c2, 1, &h_size,
+ &h_range, true, false);
+
+ /* Init */
+ hist_img->setTo(cv::Scalar(0));
+
+ /* Normalize the result to [0, hist_img->rows - 1] */
+ cv::normalize(*hist_c0, *hist_c0, 0, 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 (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();
+
+ cmp_img[0].release();
+ cmp_img[1].release();
+ cmp_img[2].release();
+}
+
+/* ----- Structural analysis and shape descriptors */
+static void img_cv_contours (class cv::Mat *imgptr, 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;
+
+ data_cast = (const struct Img_Iface_Data_Contours *)data;
+ contours = data_cast->contours;
+ hierarchy = data_cast->hierarchy;
+
+ 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(UINT8_MAX), 1, 8,
+ *hierarchy, 1, cvPoint(0, 0));
+}
+
+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;
+ 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 (ptrdiff_t i = 0; i < size; i++)
+ data_cast->area[i] = cv::contourArea((*contours)[i],
+ false);
+ }
+ if (data_cast->perimeter) {
+ 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)
+{
+ const struct Img_Iface_Data_Bounding_Rect *data_cast;
+ const class std::vector <class cv::Point_ <int>> *contour;
+ 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;
+ rect = data_cast->rect;
+ 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 */
+ 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)
+{
+ const struct Img_Iface_Data_MinARect *data_cast;
+ const class std::vector <class cv::Point_ <int>> *contour;
+ 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;
+
+ *rect = cv::fitEllipse(*contour);
+
+ if (!show)
+ return;
+ /* Draw rectangle */
+ 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)
+{
+ const struct Img_Iface_Data_MinARect *data_cast;
+ const class std::vector <class cv::Point_ <int>> *contour;
+ 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;
+
+ *rect = cv::minAreaRect(*contour);
+
+ if (!show)
+ return;
+ /* Draw rectangle */
+ 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)
+{
+ const struct Img_Iface_Data_Hough_Circles *data_cast;
+ class std::vector <class cv::Vec <float, 3>> *circles;
+ 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;
+ dist_min = data_cast->dist_min;
+ param_1 = data_cast->param_1;
+ param_2 = data_cast->param_2;
+ radius_min = data_cast->radius_min;
+ radius_max = data_cast->radius_max;
+
+ /* Get circles */
+ cv::HoughCircles(*imgptr, *circles, CV_HOUGH_GRADIENT, 1, dist_min,
+ param_1, param_2, radius_min, radius_max);
+
+ /* Set image to black */
+ imgptr->setTo(cv::Scalar(0));
+
+ /* Draw circles */
+ 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);*/
+
+ /* Draw the circle outline */
+ cv::circle(*imgptr, center, radius, cv::Scalar(250), 1, 8, 0);
+ }
+}
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
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 2eea9c9..4f6d3de 100644
--- a/modules/image/src/img_ocr.c
+++ b/src/image/ocr.c
@@ -1,127 +1,145 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* INT_MAX */
- #include <limits.h>
- /* snprintf() & FILENAME_MAX */
- #include <stdio.h>
-
-/* Packages ------------------------------------------------------------------*/
- /* OCR Tesseract */
- #include <tesseract/capi.h>
-
-/* Project -------------------------------------------------------------------*/
- /* share_path */
- #include "about.h"
-
-/* Module --------------------------------------------------------------------*/
- /* data & img_ocr_text & OCR_TEXT_MAX */
- #include "img_iface.h"
-
- #include "img_ocr.h"
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void img_ocr_read (void *data);
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void img_ocr_act (int action, void *data)
-{
- switch (action) {
- case IMG_OCR_ACT_READ:
- img_ocr_read(data);
- break;
- }
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void img_ocr_read (void *data)
-{
- struct TessBaseAPI *handle_ocr;
-
- /* Data */
- struct Img_Iface_Data_Read *data_cast;
- data_cast = (struct Img_Iface_Data_Read *)data;
-
- /* Language */
- int lang;
- char lang_str [20 + 1];
- lang = data_cast->lang;
- switch (lang) {
- case IMG_IFACE_OCR_LANG_ENG:
- sprintf(lang_str, "eng");
- break;
- case IMG_IFACE_OCR_LANG_SPA:
- sprintf(lang_str, "spa");
- break;
- case IMG_IFACE_OCR_LANG_CAT:
- sprintf(lang_str, "cat");
- break;
- case IMG_IFACE_OCR_LANG_DIGITS:
- sprintf(lang_str, "digits");
- break;
- case IMG_IFACE_OCR_LANG_DIGITS_COMMA:
- sprintf(lang_str, "digits_comma");
- break;
- }
-
- /* Config file */
- int conf;
- char conf_str [FILENAME_MAX];
- conf = data_cast->conf;
- switch (conf) {
- case IMG_IFACE_OCR_CONF_PRICE:
- sprintf(conf_str, "%s/%s", share_path, "price");
- break;
- }
-
- /* init OCR */
- handle_ocr = TessBaseAPICreate();
- TessBaseAPIInit2(handle_ocr, NULL, lang_str,
-#ifdef OEM_LSTM_ONLY
- OEM_LSTM_ONLY);
-#else
- OEM_DEFAULT);
-#endif
-// OEM_TESSERACT_LSTM_COMBINED);
- if (conf) {
- /* Configure OCR (whitelist chars) */
- TessBaseAPIReadConfigFile(handle_ocr, conf_str);
- }
-
- /* scan image for text */
- TessBaseAPISetImage(handle_ocr, data_cast->img.data,
- data_cast->img.width, data_cast->img.height,
- data_cast->img.B_per_pix,
- data_cast->img.B_per_line);
- TessBaseAPIRecognize(handle_ocr, NULL);
- char *txt;
- txt = TessBaseAPIGetUTF8Text(handle_ocr);
-
- /* Copy text to global variable */
- snprintf(img_ocr_text, OCR_TEXT_MAX, "%s", txt);
-
- /* cleanup */
- TessDeleteText(txt);
- TessBaseAPIEnd(handle_ocr);
- TessBaseAPIDelete(handle_ocr);
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+#include "vision-artificial/image/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 ***************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* structs / unions *****************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* static functions (prototypes) ****************************************
+ ******************************************************************************/
+static void img_ocr_read (const void *data);
+
+
+/******************************************************************************
+ ******* global functions *****************************************************
+ ******************************************************************************/
+void img_ocr_act (int action, const void *data)
+{
+
+ switch (action) {
+ case IMG_OCR_ACT_READ:
+ img_ocr_read(data);
+ break;
+ }
+}
+
+
+/******************************************************************************
+ ******* static functions (definitions) ***************************************
+ ******************************************************************************/
+static void img_ocr_read (const void *data)
+{
+ const struct Img_Iface_Data_Read *data_cast;
+ struct TessBaseAPI *handle_ocr;
+ int lang;
+ char lang_str[FILENAME_MAX];
+ int conf;
+ char conf_str[FILENAME_MAX];
+ char *txt;
+
+ /* Data */
+ data_cast = (const struct Img_Iface_Data_Read *)data;
+
+ /* Language */
+ lang = data_cast->lang;
+ switch (lang) {
+ case IMG_IFACE_OCR_LANG_ENG:
+ sprintf(lang_str, "eng");
+ break;
+ case IMG_IFACE_OCR_LANG_SPA:
+ sprintf(lang_str, "spa");
+ break;
+ case IMG_IFACE_OCR_LANG_CAT:
+ sprintf(lang_str, "cat");
+ break;
+ case IMG_IFACE_OCR_LANG_DIGITS:
+ sprintf(lang_str, "digits");
+ break;
+ case IMG_IFACE_OCR_LANG_DIGITS_COMMA:
+ sprintf(lang_str, "digits_comma");
+ break;
+ }
+
+ /* Config file */
+ conf = data_cast->conf;
+ switch (conf) {
+ case IMG_IFACE_OCR_CONF_PRICE:
+ if (snprintf(conf_str, FILENAME_MAX, "%s/%s",
+ share_path,
+ "price") >= FILENAME_MAX) {
+ printf("Path is too large and has been truncated\n");
+ printf("Price configuration was not possible!\n");
+ conf = IMG_IFACE_OCR_CONF_NONE;
+ }
+ break;
+ }
+
+ /* init OCR */
+ handle_ocr = TessBaseAPICreate();
+#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);*/
+
+ /* Configure OCR (whitelist chars) */
+ if (conf)
+ TessBaseAPIReadConfigFile(handle_ocr, conf_str);
+
+ /* scan image for text */
+ TessBaseAPISetImage(handle_ocr, data_cast->img.data,
+ data_cast->img.width, data_cast->img.height,
+ data_cast->img.B_per_pix,
+ data_cast->img.B_per_line);
+ TessBaseAPIRecognize(handle_ocr, NULL);
+ txt = TessBaseAPIGetUTF8Text(handle_ocr);
+
+ /* Copy text to global variable */
+ snprintf(img_ocr_text, OCR_TEXT_MAX, "%s", txt);
+
+ /* cleanup */
+ TessDeleteText(txt);
+ TessBaseAPIEnd(handle_ocr);
+ TessBaseAPIDelete(handle_ocr);
+}
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/modules/image/src/img_orb.cpp b/src/image/orb.cpp
index 58d7a4e..708eb3c 100644
--- a/modules/image/src/img_orb.cpp
+++ b/src/image/orb.cpp
@@ -1,126 +1,136 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C++ --------------------------------------------------------------*/
- /* std::vector */
- #include <vector>
-
-/* Standard C ----------------------------------------------------------------*/
- /* snprintf() */
- #include <cstdio>
-
-/* Packages ------------------------------------------------------------------*/
- /* opencv */
- #include <opencv2/opencv.hpp>
- #include <opencv2/features2d/features2d.hpp>
-
-/* Module -------------------------------------------------------------------*/
- #include "img_orb.hpp"
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
- # define MAX_FEATURES (50000)
- # define GOOD_MATCH_P (0.25)
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void img_orb_align (class cv::Mat *img_0,
- class cv::Mat *img_1);
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void img_orb_act (class cv::Mat *img_ref,
- class cv::Mat *imgptr, int action)
-{
- switch (action) {
- case IMG_ORB_ACT_ALIGN:
- img_orb_align(img_ref, imgptr);
- break;
- }
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void img_orb_align (class cv::Mat *img_0,
- class cv::Mat *img_1)
-{
- /* Variables to store keypoints & descriptors */
- std::vector <class cv::KeyPoint> keypoints_0;
- std::vector <class cv::KeyPoint> keypoints_1;
- class cv::Mat descriptors_0;
- class cv::Mat descriptors_1;
-
- /* Detect ORB features & compute descriptors */
-#if 1
- /* OpenCV 2.x */
- class cv::ORB orb;
- orb(*img_0, cv::Mat(), keypoints_0, descriptors_0);
- orb(*img_1, cv::Mat(), keypoints_1, descriptors_1);
-#else
- /* OpenCV 3.x */
- class cv::Ptr <class cv::Feature2D> orb;
- orb = cv::ORB::create(MAX_FEATURES);
- orb->detectAndCompute(*img_0, cv::Mat(), keypoints_0, descriptors_0);
- orb->detectAndCompute(*img_1, cv::Mat(), keypoints_1, descriptors_1);
-#endif
-
-
- /* Match structures */
- std::vector <struct cv::DMatch> matches;
- cv::Ptr <class cv::DescriptorMatcher> matcher;
- matcher = cv::DescriptorMatcher::create("BruteForce-Hamming");
- matcher->match(descriptors_1, descriptors_0, matches, cv::Mat());
-
- /* Sort matches by score */
- std::sort(matches.begin(), matches.end());
-
- /* Remove not so good matches */
- int good_matches;
- good_matches = GOOD_MATCH_P * matches.size();
- matches.erase(matches.begin() + good_matches, matches.end());
-
- /* Draw top matches */
- class cv::Mat img_matches;
- cv::drawMatches(*img_1, keypoints_1, *img_0, keypoints_0, matches,
- img_matches);
- cv::imwrite("matches.jpg", img_matches);
-
- /* Extract location of good matches */
- std::vector <class cv::Point_ <float>> points_0;
- std::vector <class cv::Point_ <float>> points_1;
- int i;
- for (i = 0; i < matches.size(); i++) {
- points_1.push_back(keypoints_1[matches[i].queryIdx].pt);
- points_0.push_back(keypoints_0[matches[i].trainIdx].pt);
- }
-
- /* Find homography */
- class cv::Mat img_hg;
- img_hg = cv::findHomography(points_1, points_0, CV_RANSAC);
-
- /* Use homography to warp image */
- class cv::Mat img_align;
- cv::warpPerspective(*img_1, img_align, img_hg, img_0->size());
-
- /* Write img_align into img_1 */
- *img_1 = img_align;
- img_align.release();
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+#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)
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* structs / unions *****************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* static functions (prototypes) ****************************************
+ ******************************************************************************/
+static void img_orb_align (const class cv::Mat *img_0,
+ class cv::Mat *img_1);
+
+
+/******************************************************************************
+ ******* global functions *****************************************************
+ ******************************************************************************/
+void img_orb_act (const class cv::Mat *img_ref,
+ class cv::Mat *imgptr, int action)
+{
+ switch (action) {
+ case IMG_ORB_ACT_ALIGN:
+ img_orb_align(img_ref, imgptr);
+ break;
+ }
+}
+
+
+/******************************************************************************
+ ******* static functions (definitions) ***************************************
+ ******************************************************************************/
+static void img_orb_align (const class cv::Mat *img_0,
+ class cv::Mat *img_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 (CV_VERSION_EPOCH == 2)
+ orb(*img_0, cv::Mat(), keypoints_0, descriptors_0);
+ orb(*img_1, cv::Mat(), keypoints_1, descriptors_1);
+#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 */
+ matcher = cv::DescriptorMatcher::create("BruteForce-Hamming");
+ matcher->match(descriptors_1, descriptors_0, matches, cv::Mat());
+
+ /* Sort matches by score */
+ std::sort(matches.begin(), matches.end());
+
+ /* Remove not so good matches */
+ good_matches = GOOD_MATCH_P * matches.size();
+ matches.erase(matches.begin() + good_matches, matches.end());
+
+ /* Draw top 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 */
+ 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 */
+ img_hg = cv::findHomography(points_1, points_0, CV_RANSAC);
+
+ /* Use homography to warp image */
+ cv::warpPerspective(*img_1, img_align, img_hg, img_0->size());
+
+ /* Write img_align into img_1 */
+ *img_1 = img_align;
+ img_align.release();
+}
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/src/image/zbar.cpp b/src/image/zbar.cpp
new file mode 100644
index 0000000..f11e751
--- /dev/null
+++ b/src/image/zbar.cpp
@@ -0,0 +1,122 @@
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+#include "vision-artificial/image/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 *****************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* static functions (prototypes) ****************************************
+ ******************************************************************************/
+static void img_zb_decode (class cv::Mat *imgptr, const void *data);
+
+
+/******************************************************************************
+ ******* 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);
+ break;
+ }
+}
+
+
+/******************************************************************************
+ ******* 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;
+ enum zbar::zbar_symbol_type_e code_type;
+ 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 = (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();
+ zbar::zbar_image_scanner_set_config(scanner, code_type,
+ zbar::ZBAR_CFG_ENABLE, 1);
+
+ /* wrap image data */
+ image_zb = zbar::zbar_image_create();
+ zbar::zbar_image_set_format(image_zb, *(int*)"GREY");
+ zbar::zbar_image_set_size(image_zb, 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)
+ 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);
+ }
+
+not_found:
+ /* clean up */
+ zbar::zbar_image_destroy(image_zb);
+ zbar::zbar_image_scanner_destroy(scanner);
+}
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/src/main.cpp b/src/main.cpp
index 875cfbd..1a8f5de 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,88 +1,80 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* getchar() */
- #include <cstdio>
-
-/* libalx --------------------------------------------------------------------*/
- #include "alx_ncur.hpp"
-
-/* Project -------------------------------------------------------------------*/
- /* about_init() & print_cpright() */
- #include "about.hpp"
- #include "img_iface.hpp"
- #include "menu_iface.hpp"
- #include "user_iface.hpp"
- #include "parser.hpp"
- #include "save.hpp"
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void init_all (int *argc, char *(*argv[]));
-static void cleanup (void);
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-int main (int argc, char *argv[])
-{
- init_all(&argc, &argv);
-
- /* Print copyright () and wait for any key to continue */
- print_share_file(SHARE_COPYRIGHT);
- getchar();
-
- /* Menu () */
- menu_iface();
-
- cleanup();
-
- return 0;
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void init_all (int *argc, char *(*argv[]))
-{
- /* Init curses */
- alx_start_curses();
- alx_pause_curses();
-
- /* Init modules */
- about_init();
- save_init();
-
- /* Modes */
- menu_iface_mode = MENU_IFACE_TUI;
- user_iface_mode = USER_IFACE_TUI;
- user_iface_log.visible = 2;
-
- /* Parse command line options */
- parser(*argc, *argv);
-}
-
-static void cleanup (void)
-{
- /* Clean img buffers */
- img_iface_cleanup_main();
-
- /* End curses */
- alx_resume_curses();
- alx_end_curses();
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+#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 (int *argc, char *(*argv[]));
+static void deinit (void);
+
+
+/******************************************************************************
+ ******* main *****************************************************************
+ ******************************************************************************/
+int main (int argc, char *argv[])
+{
+
+ init(&argc, &argv);
+
+ print_share_file(SHARE_COPYRIGHT);
+ alx_wait4enter();
+
+ menu_iface();
+
+ deinit();
+
+ return 0;
+}
+
+
+/******************************************************************************
+ ******* static functions *****************************************************
+ ******************************************************************************/
+static void init (int *argc, char *(*argv[]))
+{
+
+ alx_ncurses_init();
+ alx_ncurses_pause();
+
+ about_init();
+ save_init();
+
+ menu_iface_mode = MENU_IFACE_TUI;
+ user_iface_mode = USER_IFACE_TUI;
+ user_iface_log.visible = 2;
+
+ parse(*argc, *argv);
+}
+
+static void deinit (void)
+{
+
+ img_iface_deinit();
+
+ alx_ncurses_resume();
+ alx_ncurses_deinit();
+}
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/src/menu/clui.c b/src/menu/clui.c
new file mode 100644
index 0000000..5e947b7
--- /dev/null
+++ b/src/menu/clui.c
@@ -0,0 +1,125 @@
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+#include "vision-artificial/menu/clui.h"
+
+#include <ctype.h>
+#include <stdlib.h>
+
+#include "libalx/base/stdio/get.h"
+
+#include "vision-artificial/about/about.h"
+#include "vision-artificial/ctrl/start.h"
+
+
+/******************************************************************************
+ ******* macros ***************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* structs / unions *****************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* static functions (prototypes) ****************************************
+ ******************************************************************************/
+//static void menu_clui_rand (void);
+//static void menu_clui_custom (void);
+static void menu_clui_load (void);
+static void menu_clui_start (void);
+
+
+/******************************************************************************
+ ******* global functions *****************************************************
+ ******************************************************************************/
+void menu_clui (void)
+{
+ 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 = 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
+ c = alx_get_ch("nt", true, true, "Game interface? (NCURSES/text): ",
+ NULL, 1);
+ if (tolower(c) == 't') {
+ printf(" >text\n");
+ // FIXME
+ } else {
+ printf(" >NCURSES\n");
+ // FIXME
+ }
+#endif
+ menu_clui_load();
+}
+
+
+/******************************************************************************
+ ******* 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);
+#endif
+ menu_clui_start();
+}
+
+static void menu_clui_start (void)
+{
+ unsigned char c;
+
+ printf(" >>START:\n");
+ start_switch();
+
+ 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 (tolower(c) == 'e') {
+ printf(" >exit!\n");
+ exit(EXIT_SUCCESS);
+ } else {
+ printf(" >MENU\n");
+ menu_clui();
+ }
+}
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/modules/proc/inc/proc_coins.hpp b/src/menu/iface.c
index 6dbf7b7..4b8bbd7 100644
--- a/modules/proc/inc/proc_coins.hpp
+++ b/src/menu/iface.c
@@ -1,59 +1,68 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# ifndef VA_PROC_COINS_HPP
- # define VA_PROC_COINS_HPP
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* enums ****************************************************************
- ******************************************************************************/
- enum Proc_Coins {
- COINS_OK,
- COINS_NOK_COINS,
- COINS_NOK_OVERLAP
- };
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-extern "C" {
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* functions ************************************************************
- ******************************************************************************/
- int proc_coins (void);
-
-
-/******************************************************************************
- ******* C wrapper ************************************************************
- ******************************************************************************/
-} /* extern "C" */
-
-
-/******************************************************************************
- ******* include guard ********************************************************
- ******************************************************************************/
-# endif /* proc_coins.hpp */
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+#include "vision-artificial/menu/iface.h"
+
+#include "vision-artificial/menu/clui.h"
+#include "vision-artificial/menu/tui.h"
+
+
+/******************************************************************************
+ ******* macros ***************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* structs / unions *****************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+int menu_iface_mode;
+
+
+/******************************************************************************
+ ******* static functions (prototypes) ****************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* global functions *****************************************************
+ ******************************************************************************/
+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;
+ }
+}
+
+
+/******************************************************************************
+ ******* static functions (definitions) ***************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/modules/menu/src/parser.c b/src/menu/parse.c
index 6b03264..959ec5f 100644
--- a/modules/menu/src/parser.c
+++ b/src/menu/parse.c
@@ -1,140 +1,152 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- #include <getopt.h>
- /* FILE & fopen() & snprintf() & FILENAME_MAX */
- #include <stdio.h>
- /* exit() */
- #include <stdlib.h>
-
-/* Project -------------------------------------------------------------------*/
- /* print_share_...() */
- #include "about.h"
- /* user_iface_mode */
- #include "user_iface.h"
- /* saved_name */
- #include "save.h"
-
-/* Module --------------------------------------------------------------------*/
- /* menu_iface_mode */
- #include "menu_iface.h"
-
- #include "parser.h"
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
- # define OPT_LIST "hLuv""f:i:"
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void parse_file (char* argument);
-static void parse_iface (char* argument);
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void parser (int argc, char *argv[])
-{
- int opt = 0;
- int opt_index = 0;
-
- struct option long_options[] = {
- /* Standard */
- {"help", no_argument, 0, 'h'},
- {"license", no_argument, 0, 'L'},
- {"usage", no_argument, 0, 'u'},
- {"version", no_argument, 0, 'v'},
- /* Non-standard */
- {"file", required_argument, 0, 'f'},
- {"iface", required_argument, 0, 'i'},
- /* Null */
- {0, 0, 0, 0}
- };
-
- while ((opt = getopt_long(argc, argv, OPT_LIST, long_options,
- &opt_index)) != -1) {
-
- switch (opt) {
- /* Standard */
- case 'h':
- print_share_file(SHARE_HELP);
- exit(EXIT_SUCCESS);
-
- case 'L':
- print_share_file(SHARE_LICENSE);
- exit(EXIT_SUCCESS);
-
- case 'u':
- print_share_file(SHARE_USAGE);
- exit(EXIT_SUCCESS);
-
- case 'v':
- print_version();
- exit(EXIT_SUCCESS);
-
- /* Non-standard */
- case 'f':
- parse_file(optarg);
- break;
-
- case 'i':
- parse_iface(optarg);
- break;
-
- case '?':
- /* getopt_long already printed an error message. */
-
- default:
- print_share_file(SHARE_USAGE);
- exit(EXIT_FAILURE);
- }
- }
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void parse_file (char* argument)
-{
- // FIXME
- FILE *fp;
- fp = fopen(argument, "r");
- if (!fp) {
- printf("--file argument not valid\n");
- printf("It must be a valid file name (relative to saved dir)\n");
- exit(EXIT_FAILURE);
- } else {
- fclose(fp);
-
- sprintf(saved_path, "");
- snprintf(saved_name, FILENAME_MAX, "%s", argument);
- }
-}
-
-static void parse_iface (char* argument)
-{
- menu_iface_mode = atoi(argument);
- user_iface_mode = menu_iface_mode;
- if (menu_iface_mode < MENU_IFACE_CLUI || menu_iface_mode > MENU_IFACE_TUI) {
- printf("--iface argument not valid\n");
- printf("It must be an integer [%i U %i]\n", MENU_IFACE_CLUI, MENU_IFACE_TUI);
- exit(EXIT_FAILURE);
- }
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+#include "vision-artificial/menu/parse.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:"
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* structs / unions *****************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* 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;
+
+ const struct option long_options[] = {
+ /* Standard */
+ {"help", no_argument, 0, 'h'},
+ {"license", no_argument, 0, 'L'},
+ {"usage", no_argument, 0, 'u'},
+ {"version", no_argument, 0, 'v'},
+ /* Non-standard */
+ {"file", required_argument, 0, 'f'},
+ {"iface", required_argument, 0, 'i'},
+ /* Null */
+ {0, 0, 0, 0}
+ };
+
+ while ((opt = getopt_long(argc, argv, OPT_LIST, long_options,
+ &opt_index)) != -1) {
+
+ switch (opt) {
+ /* Standard */
+ case 'h':
+ print_share_file(SHARE_HELP);
+ exit(EXIT_SUCCESS);
+ case 'L':
+ print_share_file(SHARE_LICENSE);
+ exit(EXIT_SUCCESS);
+ case 'u':
+ print_share_file(SHARE_USAGE);
+ exit(EXIT_SUCCESS);
+ case 'v':
+ print_version();
+ exit(EXIT_SUCCESS);
+ /* Non-standard */
+ case 'f':
+ parse_file(optarg);
+ break;
+ case 'i':
+ parse_iface(optarg);
+ break;
+
+ case '?':
+ /* getopt_long already printed an error message. */
+ default:
+ print_share_file(SHARE_USAGE);
+ exit(EXIT_FAILURE);
+ }
+ }
+}
+
+
+/******************************************************************************
+ ******* static functions (definitions) ***************************************
+ ******************************************************************************/
+static void parse_file (char *arg)
+{
+ FILE *fp;
+
+ /* FIXME */
+ 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 *arg)
+{
+
+ 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);
+}
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
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/src/proc/common.cpp b/src/proc/common.cpp
new file mode 100644
index 0000000..82cb6eb
--- /dev/null
+++ b/src/proc/common.cpp
@@ -0,0 +1,461 @@
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+#include "vision-artificial/proc/common.hpp"
+
+#include <cstddef>
+#include <cstdio>
+#include <ctime>
+
+#include <opencv2/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 (prototypes) ****************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* global functions *****************************************************
+ ******************************************************************************/
+void proc_apply (void)
+{
+ img_iface_act(IMG_IFACE_ACT_APPLY, NULL);
+}
+
+void proc_save_mem (ptrdiff_t n)
+{
+ img_iface_act(IMG_IFACE_ACT_SAVE_MEM, (const void *)&n);
+}
+
+void proc_load_mem (ptrdiff_t n)
+{
+
+ img_iface_act(IMG_IFACE_ACT_LOAD_MEM, (const void *)&n);
+
+ proc_show_img();
+}
+
+void proc_save_ref (void)
+{
+ img_iface_act(IMG_IFACE_ACT_SAVE_REF, NULL);
+}
+
+void proc_save_file (void)
+{
+ img_iface_act(IMG_IFACE_ACT_SAVE_FILE, NULL);
+}
+
+void proc_save_update (void)
+{
+ img_iface_act(IMG_IFACE_ACT_SAVE_UPDT, NULL);
+}
+
+void proc_local_max (void)
+{
+
+ img_iface_act(IMG_IFACE_ACT_LOCAL_MAX, NULL);
+ proc_show_img();
+}
+
+void proc_skeleton (void)
+{
+
+ img_iface_act(IMG_IFACE_ACT_SKELETON, NULL);
+ proc_show_img();
+}
+
+void proc_lines_vertical (void)
+{
+
+ img_iface_act(IMG_IFACE_ACT_LINES_VERTICAL, NULL);
+ proc_show_img();
+}
+
+void proc_median_horizontal (void)
+{
+
+ img_iface_act(IMG_IFACE_ACT_MEDIAN_HORIZONTAL, NULL);
+ proc_show_img();
+}
+
+void proc_median_vertical (void)
+{
+
+ img_iface_act(IMG_IFACE_ACT_MEDIAN_VERTICAL, NULL);
+ proc_show_img();
+}
+
+void proc_pixel_get (ptrdiff_t x, ptrdiff_t y, unsigned char *val)
+{
+ struct Img_Iface_Data_Pixel_Get data;
+
+ 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 (ptrdiff_t x, ptrdiff_t y, unsigned char val)
+{
+ struct Img_Iface_Data_Pixel_Set 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();
+}
+
+void proc_ROI (int x, int y, int w, int h)
+{
+ struct Img_Iface_Data_SetROI data;
+
+ 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();
+}
+
+void proc_and_2ref (void)
+{
+
+ img_iface_act(USER_IFACE_ACT_AND_2REF, NULL);
+ proc_show_img();
+}
+
+void proc_not (void)
+{
+
+ img_iface_act(USER_IFACE_ACT_NOT, NULL);
+ proc_show_img();
+}
+
+void proc_or_2ref (void)
+{
+
+ img_iface_act(USER_IFACE_ACT_OR_2REF, NULL);
+ proc_show_img();
+}
+
+void proc_cmp (int cmp)
+{
+ struct Img_Iface_Data_Component data;
+
+ data = (struct Img_Iface_Data_Component){
+ .cmp = cmp,
+ };
+ img_iface_act(IMG_IFACE_ACT_COMPONENT, (const void *)&data);
+ proc_show_img();
+}
+
+void proc_dilate (int size)
+{
+ struct Img_Iface_Data_Dilate_Erode data;
+
+ data = (struct Img_Iface_Data_Dilate_Erode){
+ .i = size,
+ };
+ img_iface_act(IMG_IFACE_ACT_DILATE, (const void *)&data);
+ proc_show_img();
+}
+
+void proc_erode (int size)
+{
+ struct Img_Iface_Data_Dilate_Erode data;
+
+ data = (struct Img_Iface_Data_Dilate_Erode){
+ .i = size,
+ };
+ img_iface_act(IMG_IFACE_ACT_ERODE, (const void *)&data);
+ proc_show_img();
+}
+
+void proc_dilate_erode (int size)
+{
+ struct Img_Iface_Data_Dilate_Erode data;
+
+ data = (struct Img_Iface_Data_Dilate_Erode){
+ .i = size,
+ };
+ img_iface_act(IMG_IFACE_ACT_DILATE_ERODE, (const void *)&data);
+ proc_show_img();
+}
+
+void proc_erode_dilate (int size)
+{
+ struct Img_Iface_Data_Dilate_Erode data;
+
+ data = (struct Img_Iface_Data_Dilate_Erode){
+ .i = size,
+ };
+ img_iface_act(IMG_IFACE_ACT_ERODE_DILATE, (const void *)&data);
+ proc_show_img();
+}
+
+void proc_smooth (int method, int ksize)
+{
+ struct Img_Iface_Data_Smooth data;
+
+ data = (struct Img_Iface_Data_Smooth){
+ .method = method,
+ .ksize = ksize,
+ };
+ img_iface_act(IMG_IFACE_ACT_SMOOTH, (const void *)&data);
+ proc_show_img();
+}
+
+void proc_border (int size)
+{
+ struct Img_Iface_Data_Border data;
+
+ data = (struct Img_Iface_Data_Border){
+ .size = size,
+ };
+ img_iface_act(IMG_IFACE_ACT_BORDER, (const void *)&data);
+ proc_show_img();
+}
+
+void proc_rotate (float center_x, float center_y, double angle)
+{
+ struct Img_Iface_Data_Rotate data;
+
+ 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();
+}
+
+void proc_adaptive_threshold (int method, int type, int ksize)
+{
+ struct Img_Iface_Data_Adaptive_Thr data;
+
+ 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();
+}
+
+void proc_cvt_color (int method)
+{
+ struct Img_Iface_Data_Cvt_Color data;
+
+ data = (struct Img_Iface_Data_Cvt_Color){
+ .method = method,
+ };
+ img_iface_act(IMG_IFACE_ACT_CVT_COLOR, (const void *)&data);
+ proc_show_img();
+}
+
+void proc_threshold (int type, int size)
+{
+ struct Img_Iface_Data_Threshold data;
+
+ 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();
+}
+
+void proc_distance_transform (void)
+{
+
+ img_iface_act(IMG_IFACE_ACT_DISTANCE_TRANSFORM, NULL);
+ proc_show_img();
+}
+
+void proc_contours(
+ class std::vector <class std::vector <class cv::Point_<int>>> *contours,
+ class cv::Mat *hierarchy)
+{
+ struct Img_Iface_Data_Contours data;
+
+ data = (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)
+{
+ struct Img_Iface_Data_Contours_Size data;
+
+ 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(
+ const class std::vector <class cv::Point_ <int>> *contour,
+ class cv::Rect_ <int> *rect,
+ bool show)
+{
+ struct Img_Iface_Data_Bounding_Rect data;
+
+ 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)
+ proc_show_img();
+}
+
+void proc_fit_ellipse (
+ const class std::vector <class cv::Point_ <int>> *contour,
+ class cv::RotatedRect *rect,
+ bool show
+)
+{
+ struct Img_Iface_Data_MinARect data;
+
+ 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)
+ proc_show_img();
+}
+
+void proc_min_area_rect (
+ const class std::vector <class cv::Point_ <int>> *contour,
+ class cv::RotatedRect *rect,
+ bool show
+)
+{
+ struct Img_Iface_Data_MinARect data;
+
+ 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)
+ proc_show_img();
+}
+
+void proc_OCR (int lang, int conf)
+{
+ struct Img_Iface_Data_Read data;
+
+ data.lang = lang, /* eng=0, spa=1, cat=2 */
+ data.conf = conf, /* none=0, price=1 */
+ img_iface_act(IMG_IFACE_ACT_READ, (const void *)&data);
+}
+
+void proc_zbar (int type)
+{
+ struct Img_Iface_Data_Decode data;
+
+ data = (struct Img_Iface_Data_Decode){
+ .code_type = type,
+ };
+ img_iface_act(IMG_IFACE_ACT_DECODE, (const void *)&data);
+}
+
+void proc_show_img (void)
+{
+
+ if (proc_debug < PROC_DBG_DELAY_STEP)
+ return;
+ img_iface_show_img();
+ if (proc_debug >= PROC_DBG_STOP_STEP)
+ alx_wait4enter();
+}
+
+void clock_start (void)
+{
+ clock_0 = clock();
+}
+
+void clock_stop (const char *txt)
+{
+ clock_t clock_diff;
+ double time_diff;
+ char tmp[LOG_LINE_LEN];
+
+ clock_1 = clock();
+ clock_diff = clock_1 - clock_0;
+ time_diff = (double)clock_diff / (double)CLOCKS_PER_SEC;
+
+ snprintf(tmp, LOG_LINE_LEN, "Time: %.3lf (%s)", time_diff, txt);
+ user_iface_log_write(0, tmp);
+}
+
+
+/******************************************************************************
+ ******* static functions (definitions) ***************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/src/proc/iface.c b/src/proc/iface.c
new file mode 100644
index 0000000..9790e1c
--- /dev/null
+++ b/src/proc/iface.c
@@ -0,0 +1,224 @@
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+#include "vision-artificial/proc/iface.h"
+
+#include <errno.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#include "libalx/base/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 *****************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+/* Global --------------------------------------------------------------------*/
+ int proc_debug;
+ int proc_mode;
+/* Static --------------------------------------------------------------------*/
+static char proc_path [FILENAME_MAX];
+static char proc_fail_path [FILENAME_MAX];
+
+
+/******************************************************************************
+ ******* static functions (prototypes) ****************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* global functions *****************************************************
+ ******************************************************************************/
+int proc_iface_single (int action)
+{
+ int error;
+ clock_t time_0;
+ clock_t time_1;
+ double time_tot;
+ char txt[LOG_LINE_LEN];
+
+ time_0 = clock();
+
+ switch (action) {
+ case PROC_MODE_LABEL_SERIES:
+ error = proc_label();
+ break;
+ case PROC_MODE_OBJECTS_CALIB:
+ error = proc_objects_calibrate();
+ break;
+ case PROC_MODE_OBJECTS_SERIES:
+ error = proc_objects();
+ break;
+ case PROC_MODE_COINS_SERIES:
+ error = proc_coins();
+ break;
+ case PROC_MODE_RESISTOR_SERIES:
+ error = proc_resistor();
+ break;
+ case PROC_MODE_LIGHTERS_SERIES:
+ error = proc_lighter();
+ break;
+ default:
+ error = -1;
+ }
+
+ time_1 = clock();
+ time_tot = ((double) time_1 - time_0) / CLOCKS_PER_SEC;
+ snprintf(txt, LOG_LINE_LEN, "Item total time: %.3lf", time_tot);
+ user_iface_log_write(0, txt);
+
+ return error;
+}
+
+void proc_iface_series (void)
+{
+ int num_len;
+ char file_basename[FILENAME_MAX];
+ char file_ext[FILENAME_MAX];
+ char file_name[FILENAME_MAX];
+ char save_error_as[FILENAME_MAX];
+ /* if i starts being 0, the camera needs calibration */
+ int i;
+ char txt[LOG_LINE_LEN];
+ char tmp[FILENAME_MAX];
+
+ switch (proc_mode) {
+ case PROC_MODE_LABEL_SERIES:
+ snprintf(proc_path, FILENAME_MAX, "%s", labels_path);
+ snprintf(proc_fail_path, FILENAME_MAX, "%s", labels_fail_path);
+ snprintf(file_basename, FILENAME_MAX, "b");
+ num_len = 4;
+ snprintf(file_ext, FILENAME_MAX, ".BMP");
+ i = 1;
+ break;
+ case PROC_MODE_OBJECTS_SERIES:
+ snprintf(proc_path, FILENAME_MAX, "%s", objects_path);
+ snprintf(proc_fail_path, FILENAME_MAX, "%s", objects_fail_path);
+ snprintf(file_basename, FILENAME_MAX, "o");
+ num_len = 4;
+ snprintf(file_ext, FILENAME_MAX, ".jpeg");
+ i = 0;
+ proc_mode++;
+ break;
+ case PROC_MODE_COINS_SERIES:
+ snprintf(proc_path, FILENAME_MAX, "%s", coins_path);
+ snprintf(proc_fail_path, FILENAME_MAX, "%s", coins_fail_path);
+ snprintf(file_basename, FILENAME_MAX, "c");
+ num_len = 4;
+ snprintf(file_ext, FILENAME_MAX, ".jpeg");
+ i = 1;
+ break;
+ case PROC_MODE_RESISTOR_SERIES:
+ snprintf(proc_path, FILENAME_MAX, "%s", resistors_path);
+ snprintf(proc_fail_path, FILENAME_MAX,"%s",resistors_fail_path);
+ snprintf(file_basename, FILENAME_MAX, "r");
+ num_len = 4;
+ snprintf(file_ext, FILENAME_MAX, ".png");
+ i = 1;
+ break;
+ case PROC_MODE_LIGHTERS_SERIES:
+ snprintf(proc_path, FILENAME_MAX, "%s", lighters_path);
+ snprintf(proc_fail_path, FILENAME_MAX, "%s",lighters_fail_path);
+ snprintf(file_basename, FILENAME_MAX, "lighters");
+ num_len = 4;
+ snprintf(file_ext, FILENAME_MAX, ".png");
+ i = 1;
+ break;
+ default:
+ return;
+ }
+
+ for (;; i++) {
+ if (snprintf(file_name, FILENAME_MAX, "%s%04i%s",
+ file_basename,
+ i, file_ext) >= FILENAME_MAX) {
+ goto err_path;
+ }
+
+ memcpy(tmp, file_name, ARRAY_SIZE(file_name));
+ if (alx_sscan_fname(proc_path, file_name, true, tmp))
+ break;
+
+ errno = 0;
+ img_iface_load(proc_path, file_name);
+
+ if (errno) {
+ printf("errno:%i\n", errno);
+ goto err_load;
+ }
+
+ /* Process */
+ if (proc_iface_single(proc_mode)) {
+ /* Save failed image into file */
+ proc_show_img();
+ if (snprintf(save_error_as, FILENAME_MAX,"%s%0*i_err%s",
+ file_basename, num_len, i,
+ file_ext) >= FILENAME_MAX) {
+ goto err_path;
+ }
+ save_image_file(proc_fail_path, save_error_as);
+ }
+
+ /* Show log */
+ snprintf(txt, LOG_LINE_LEN, "%04i", i);
+ user_iface_show_log(txt, "Item");
+
+ if (proc_debug >= PROC_DBG_STOP_ITEM)
+ alx_wait4enter();
+err_load:
+ if (!i)
+ proc_mode--;
+ }
+
+ return;
+
+err_path:
+ printf("Path is too large and has been truncated\n");
+ exit(EXIT_FAILURE);
+}
+
+
+/******************************************************************************
+ ******* static functions (definitions) ***************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/src/proc/label.cpp b/src/proc/label.cpp
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/src/proc/lighters.cpp b/src/proc/lighters.cpp
new file mode 100644
index 0000000..6eb9441
--- /dev/null
+++ b/src/proc/lighters.cpp
@@ -0,0 +1,426 @@
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+#include "vision-artificial/proc/lighters.hpp"
+
+#include <cstddef>
+#include <cstdio>
+
+#include <opencv2/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"
+
+
+/******************************************************************************
+ ******* macros ***************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+enum Lighter_Hood {
+ HOOD_OK,
+ HOOD_NOT_PRESENT,
+ HOOD_NOT_OK
+};
+
+
+/******************************************************************************
+ ******* structs / unions *****************************************************
+ ******************************************************************************/
+struct Point {
+ uint16_t x;
+ uint16_t y;
+};
+
+struct Size {
+ uint16_t h;
+ uint16_t w;
+};
+
+struct Lighter_Properties {
+ struct Point pos;
+ struct Size size;
+ double angle;
+
+ bool fork;
+ bool valve;
+ int hood_;
+ bool hood;
+ bool wheel;
+
+ bool ok;
+};
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+/* Global --------------------------------------------------------------------*/
+/* Static --------------------------------------------------------------------*/
+static class std::vector <class std::vector <class cv::Point_ <int>>> contours_all;
+static class std::vector <class std::vector <class cv::Point_ <int>>> contours_one;
+static class cv::Mat hierarchy;
+static class cv::RotatedRect rect_rot[CONTOURS_MAX];
+static class cv::Rect_ <int> rect;
+static struct Lighter_Properties lighter[CONTOURS_MAX];
+static ptrdiff_t lighters_n;
+
+
+/******************************************************************************
+ ******* static functions (prototypes) ****************************************
+ ******************************************************************************/
+static void result_lighter (int status);
+
+static void lighters_bgr2gray (void);
+static void lighters_segment_full (void);
+static int lighters_find (void);
+static void lighter_segment_body (int i);
+static void lighter_rm_body (int i);
+static void lighter_crop_head (int i);
+static void lighter_chk_hood (int i);
+static void lighter_rm_hood (void);
+static void lighter_chk_fork (int i);
+static void lighter_chk_wheel (int i);
+static void lighter_chk_valve (int i);
+static void lighters_log (void);
+
+
+/******************************************************************************
+ ******* global functions *****************************************************
+ ******************************************************************************/
+int proc_lighter (void)
+{
+
+ proc_save_mem(0);
+ /* Segment lighters */
+ clock_start();
+ lighters_bgr2gray();
+ lighters_segment_full();
+ lighters_find();
+ clock_stop("Segment lighters");
+
+ /* Check each lighter */
+ for (ptrdiff_t i = 0; i < lighters_n; i++) {
+ clock_start();
+ lighter[i].ok = true;
+ lighter_segment_body(i);
+ lighter_rm_body(i);
+ lighter_crop_head(i);
+ lighter_chk_hood(i);
+ if (lighter[i].hood_ != HOOD_NOT_PRESENT) {
+ lighter_rm_hood();
+ } else {
+ proc_load_mem(7);
+ proc_save_mem(8);
+ }
+ lighter_chk_fork(i);
+ lighter_chk_wheel(i);
+ lighter_chk_valve(i);
+ clock_stop("Check parts");
+ }
+
+ /* Print results of lighters into log */
+ clock_start();
+ lighters_log();
+ clock_stop("Lighters properties (log)");
+
+ result_lighter(LIGHTER_OK);
+ return 0;
+}
+
+
+/******************************************************************************
+ ******* static functions (definitions) ***************************************
+ ******************************************************************************/
+static void result_lighter (int status)
+{
+
+ switch (status) {
+ case LIGHTER_OK:
+ user_iface_log_write(0, "Coin: OK");
+ break;
+ case LIGHTER_NOK_LIGHTER:
+ user_iface_log_write(0, "Coin: NOK_LIGHTER");
+ break;
+
+ case LIGHTER_NOK_SIZE:
+ user_iface_log_write(0, "Coin: NOK_SIZE");
+ break;
+ default:
+ user_iface_log_write(0, "Coin: NOK");
+ }
+}
+
+/* process -------------------------------------------------------------------*/
+static void lighters_bgr2gray (void)
+{
+
+ proc_load_mem(0);
+
+ proc_cvt_color(cv::COLOR_BGR2GRAY);
+ proc_not();
+ proc_save_mem(1);
+
+ proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU);
+ proc_border(100);
+ proc_save_mem(3);
+
+ proc_load_mem(1);
+ proc_border(100);
+ proc_save_mem(2);
+}
+
+static void lighters_segment_full (void)
+{
+
+ proc_load_mem(3);
+ proc_erode_dilate(1);
+ proc_dilate_erode(2);
+ proc_save_mem(4);
+}
+
+static int lighters_find (void)
+{
+
+ proc_load_mem(4);
+ proc_contours(&contours_all, &hierarchy);
+ lighters_n = contours_all.size();
+ if (!lighters_n)
+ return LIGHTER_NOK_LIGHTER;
+
+ for (ptrdiff_t i = 0; i < lighters_n; i++) {
+ proc_min_area_rect(&contours_all[i], &rect_rot[i], true);
+ /* If width > height,
+ * it is taking into acount the incorrect side */
+ if (rect_rot[i].size.width > rect_rot[i].size.height) {
+ rect_rot[i].angle += 90.0;
+ ALX_SWAP(&rect_rot[i].size.width,
+ &rect_rot[i].size.height);
+ }
+ lighter[i].pos.x = rect_rot[i].center.x;
+ lighter[i].pos.y = rect_rot[i].center.y;
+ lighter[i].angle = -rect_rot[i].angle;
+ lighter[i].size.h = rect_rot[i].size.height;
+ lighter[i].size.w = rect_rot[i].size.width;
+ }
+
+ return 0;
+}
+
+static void lighter_segment_body (int i)
+{
+ int x, y;
+ int w, h;
+
+ proc_load_mem(2);
+
+ proc_rotate(lighter[i].pos.x, lighter[i].pos.y, -lighter[i].angle);
+ w = lighter[i].size.w * 1.25;
+ h = lighter[i].size.h * 1.25;
+ x = lighter[i].pos.x - (w / 2.0);
+ y = lighter[i].pos.y - (h / 2.0);
+ proc_ROI(x, y, w, h);
+ proc_threshold(cv::THRESH_BINARY, UINT8_MAX - 165);
+
+ proc_erode_dilate(1);
+ proc_dilate_erode(1);
+ proc_erode_dilate(lighter[i].size.w * 0.43);
+ proc_save_mem(5);
+
+ proc_contours(&contours_one, &hierarchy);
+ proc_bounding_rect(&contours_one[0], &rect, true);
+}
+
+static void lighter_rm_body (int i)
+{
+ int x, y;
+ int w, h;
+
+ proc_load_mem(5);
+ proc_not();
+ proc_erode(5);
+ proc_save_ref();
+
+ proc_load_mem(3);
+ proc_rotate(lighter[i].pos.x, lighter[i].pos.y, -lighter[i].angle);
+ w = lighter[i].size.w * 1.25;
+ h = lighter[i].size.h * 1.25;
+ x = lighter[i].pos.x - (w / 2.0);
+ y = lighter[i].pos.y - (h / 2.0);
+ proc_ROI(x, y, w, h);
+ proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU);
+ proc_and_2ref();
+ proc_save_mem(6);
+}
+
+static void lighter_crop_head (int i)
+{
+ int x, y;
+ int w, h;
+
+ proc_load_mem(6);
+
+ w = rect.width * 1.15;
+ h = rect.width * 0.65;
+ x = rect.x - rect.width * 0.075;
+ y = rect.y - rect.width * 0.65;
+ proc_ROI(x, y, w, h);
+ rect.x = x;
+ rect.y = y;
+ rect.width = w;
+ rect.height = h;
+ lighter[i].size.w = w;
+ lighter[i].size.h = h;
+ proc_save_mem(7);
+}
+
+static void lighter_chk_hood (int i)
+{
+ uint8_t val1;
+ uint8_t val2;
+ proc_load_mem(7);
+
+ proc_pixel_get(rect.width * 0.2, rect.height * 0.3, &val1);
+ proc_pixel_set(rect.width * 0.2, rect.height * 0.3, UINT8_MAX / 2);
+ proc_save_mem(9);
+
+ if (val1) {
+ proc_pixel_get(rect.width *0.2, rect.height *0.8, &val2);
+ proc_pixel_set(rect.width *0.2, rect.height *0.8, UINT8_MAX /2);
+ if (val2) {
+ lighter[i].hood_ = HOOD_OK;
+ lighter[i].hood = true;
+ } else {
+ lighter[i].hood_ = HOOD_NOT_OK;
+ lighter[i].hood = false;
+ lighter[i].ok = false;
+ }
+ } else {
+ lighter[i].hood_ = HOOD_NOT_PRESENT;
+ lighter[i].hood = false;
+ lighter[i].ok = false;
+ }
+}
+
+static void lighter_rm_hood (void)
+{
+
+ proc_load_mem(7);
+ proc_border(2);
+ proc_save_ref();
+
+ proc_dilate_erode(2);
+ proc_erode_dilate(rect.height * 0.25);
+ proc_dilate(2);
+ proc_not();
+ proc_and_2ref();
+ proc_save_mem(8);
+}
+
+static void lighter_chk_fork (int i)
+{
+ uint8_t val;
+
+ proc_load_mem(8);
+
+ proc_dilate_erode(2);
+ proc_pixel_get(rect.width * 0.8, rect.height * 0.8, &val);
+ proc_pixel_set(rect.width * 0.8, rect.height * 0.8, UINT8_MAX / 2);
+ proc_save_mem(10);
+
+ if (val) {
+ lighter[i].fork = true;
+ } else {
+ lighter[i].fork = false;
+ lighter[i].ok = false;
+ }
+}
+
+static void lighter_chk_wheel (int i)
+{
+ uint8_t val;
+
+ proc_load_mem(8);
+
+ proc_dilate(5);
+ proc_pixel_get(rect.width * 0.58, rect.height * 0.19, &val);
+ proc_pixel_set(rect.width * 0.58, rect.height * 0.19, UINT8_MAX / 2);
+ proc_save_mem(11);
+
+ if (val) {
+ lighter[i].wheel = true;
+ } else {
+ lighter[i].wheel = false;
+ lighter[i].ok = false;
+ }
+}
+
+static void lighter_chk_valve (int i)
+{
+ uint8_t val;
+
+ proc_load_mem(8);
+
+ if (lighter[i].hood_ == HOOD_NOT_PRESENT)
+ proc_dilate(5);
+ else
+ proc_dilate(10);
+ proc_pixel_get(rect.width * 0.07, rect.height * 0.92, &val);
+ proc_pixel_set(rect.width * 0.07, rect.height * 0.92, UINT8_MAX / 2);
+ proc_save_mem(12);
+
+ if (val) {
+ lighter[i].valve = true;
+ } else {
+ lighter[i].valve = false;
+ lighter[i].ok = false;
+ }
+}
+
+static void lighters_log (void)
+{
+ char txt[LOG_LINE_LEN];
+
+ for (ptrdiff_t i = 0; i < lighters_n; i++) {
+ snprintf(txt, LOG_LINE_LEN, "Lighter[%ti]:", i);
+ user_iface_log_write(0, txt);
+ snprintf(txt, LOG_LINE_LEN, " pos: (%i, %i) pix",
+ lighter[i].pos.x, lighter[i].pos.y);
+ user_iface_log_write(0, txt);
+ snprintf(txt, LOG_LINE_LEN, " ang = %.1lf DEG",
+ lighter[i].angle);
+ user_iface_log_write(0, txt);
+ snprintf(txt, LOG_LINE_LEN, " hood = %s",
+ lighter[i].hood ? "ok" : "nok");
+ user_iface_log_write(0, txt);
+ snprintf(txt, LOG_LINE_LEN, " fork = %s",
+ lighter[i].fork ? "ok" : "nok");
+ user_iface_log_write(0, txt);
+ snprintf(txt, LOG_LINE_LEN, " wheel = %s",
+ lighter[i].wheel ? "ok" : "nok");
+ user_iface_log_write(0, txt);
+ snprintf(txt, LOG_LINE_LEN, " valve = %s",
+ lighter[i].valve ? "ok" : "nok");
+ user_iface_log_write(0, txt);
+ snprintf(txt, LOG_LINE_LEN, " RESULT = %s",
+ lighter[i].ok ? "OK" : "NOK");
+ user_iface_log_write(0, txt);
+ }
+}
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/src/proc/objects.cpp b/src/proc/objects.cpp
new file mode 100644
index 0000000..dd00820
--- /dev/null
+++ b/src/proc/objects.cpp
@@ -0,0 +1,550 @@
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+#include "vision-artificial/proc/objects.hpp"
+
+#include <cstddef>
+#include <cstdio>
+
+#include <opencv2/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 (0xFFF)
+#define PATTERN_SQUARE_LEN_MM (10.0)
+
+#define PATTERN_DILATE (2)
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* structs / unions *****************************************************
+ ******************************************************************************/
+struct Point {
+ uint16_t x_pix;
+ uint16_t y_pix;
+
+ double x_mm;
+ double y_mm;
+};
+
+struct Pattern_Square {
+ struct Point pos;
+ uint8_t len;
+};
+
+struct Pattern_Properties {
+ struct Point center;
+ struct Point origin;
+
+ double angle;
+
+ uint16_t height;
+ uint16_t width;
+
+ /* Squares (distance calibration) */
+ struct Pattern_Square square[OBJECTS_MAX];
+};
+
+struct Objects_Properties {
+ struct Point pos;
+
+ double angle;
+
+ double area_pix2;
+ double area_mm2;
+ double perimeter_pix;
+ double perimeter_mm;
+
+ double ratio_p2_a;
+ double area_rect;
+ double ratio_a_arect;
+ double perimeter_rect;
+ double ratio_p_prect;
+};
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+/* Global --------------------------------------------------------------------*/
+/* Static --------------------------------------------------------------------*/
+static class std::vector <class std::vector <class cv::Point_ <int>>> contours;
+static class cv::Mat hierarchy;
+static class cv::RotatedRect rect_rot[OBJECTS_MAX];
+static class cv::Rect_ <int> rect[OBJECTS_MAX];
+static struct Pattern_Properties pattern;
+static ptrdiff_t squares_n;
+static double ratio_mm_pix;
+static ptrdiff_t objects_n;
+static struct Objects_Properties objects[OBJECTS_MAX];
+
+
+/******************************************************************************
+ ******* static functions (prototypes) ****************************************
+ ******************************************************************************/
+static void result_objects (int status);
+
+static void pattern_bgr2gray (void);
+static int pattern_find (void);
+static void pattern_rotation_get (void);
+static void pattern_rotation_fix (void);
+static void pattern_dimensions_get (void);
+static void pattern_dimensions_fix (void);
+static void pattern_squares_find (void);
+static void pattern_squares_pos_get (void);
+static void pattern_squares_len_get (void);
+static void pattern_calib_mm_pix (void);
+
+static void objects_bgr2gray (void);
+static void objects_rotation_fix (void);
+static void objects_dimensions_fix (void);
+static void objects_segment (void);
+static int objects_contours (void);
+static void objects_position_pix (void);
+static void objects_size_pix (void);
+static void objects_shape (void);
+static void objects_position_mm (void);
+static void objects_size_mm (void);
+static void objects_log (void);
+
+
+/******************************************************************************
+ ******* global functions *****************************************************
+ ******************************************************************************/
+int proc_objects_calibrate (void)
+{
+ int status;
+
+ proc_save_mem(0);
+ /* Calibrate angle with the whole pattern */
+ clock_start();
+ pattern_bgr2gray();
+ status = pattern_find();
+ if (status) {
+ result_objects(status);
+ return status;
+ }
+ pattern_rotation_get();
+ pattern_rotation_fix();
+ clock_stop("Calibrate: rotation");
+
+ /* Segmentate pattern squares */
+ clock_start();
+ pattern_dimensions_get();
+ pattern_dimensions_fix();
+ clock_stop("Calibrate: dimensions");
+
+ /* Find squares */
+ clock_start();
+ pattern_squares_find();
+ pattern_squares_pos_get();
+ pattern_squares_len_get();
+ pattern_calib_mm_pix();
+ clock_stop("Calibrate (mm per pix)");
+
+ result_objects(OBJECTS_OK);
+ return 0;
+}
+
+int proc_objects (void)
+{
+ int status;
+
+ proc_save_mem(0);
+ /* Align image */
+ clock_start();
+ objects_bgr2gray();
+ objects_rotation_fix();
+ objects_dimensions_fix();
+ clock_stop("Align image to pattern");
+
+ /* Segment objects */
+ clock_start();
+ objects_segment();
+ clock_stop("Segment objects");
+
+ /* Find objects positions */
+ clock_start();
+ status = objects_contours();
+ if (status) {
+ result_objects(status);
+ return status;
+ }
+ clock_stop("Find objects");
+
+ /* Get objects properties in pixels */
+ clock_start();
+ objects_position_pix();
+ objects_position_mm();
+ clock_stop("Objects positions");
+
+ /* Get objects properties in mm */
+ clock_start();
+ objects_size_pix();
+ objects_size_mm();
+ clock_stop("Objects sizes");
+
+ /* Get objects properties in mm */
+ clock_start();
+ objects_shape();
+ clock_stop("Objects shapes");
+
+ /* Print properties of objects into log */
+ clock_start();
+ objects_log();
+ clock_stop("Objects properties (log)");
+
+ result_objects(OBJECTS_OK);
+ return 0;
+}
+
+
+/******************************************************************************
+ ******* static functions (definitions) ***************************************
+ ******************************************************************************/
+static void result_objects (int status)
+{
+
+ switch (status) {
+ case OBJECTS_OK:
+ user_iface_log_write(0, "Coin: OK");
+ break;
+ case OBJECTS_NOK_OBJECTS:
+ user_iface_log_write(0, "Coin: NOK_OBJECTS");
+ break;
+
+ case OBJECTS_NOK_SIZE:
+ user_iface_log_write(0, "Coin: NOK_SIZE");
+ break;
+ default:
+ user_iface_log_write(0, "Coin: NOK");
+ }
+}
+
+/* calibration ---------------------------------------------------------------*/
+static void pattern_bgr2gray (void)
+{
+
+ proc_load_mem(0);
+
+ proc_cvt_color(cv::COLOR_BGR2GRAY);
+ proc_save_mem(1);
+}
+
+static int pattern_find (void)
+{
+
+ proc_load_mem(1);
+
+ proc_threshold(cv::THRESH_BINARY_INV, IMG_IFACE_THR_OTSU);
+ proc_erode_dilate(16);
+ proc_dilate(2);
+ proc_contours(&contours, &hierarchy);
+ if (contours.size() != 1)
+ return OBJECTS_NOK_PATTERN;
+
+ return 0;
+}
+
+static void pattern_rotation_get (void)
+{
+ char txt[LOG_LINE_LEN];
+
+ proc_min_area_rect(&(contours[0]), &(rect_rot[0]), true);
+
+ /* If angle is < -45º, it is taking into account the incorrect side */
+ if (rect_rot[0].angle < -45.0)
+ rect_rot[0].angle += 90.0;
+ pattern.angle = rect_rot[0].angle;
+ pattern.center.x_pix = rect_rot[0].center.x;
+ pattern.center.y_pix = rect_rot[0].center.y;
+
+ snprintf(txt, LOG_LINE_LEN, "pattern angle = %lf DEG",
+ -pattern.angle);
+ user_iface_log_write(0, txt);
+ snprintf(txt, LOG_LINE_LEN, "pattern center (x) = %i pix",
+ pattern.center.x_pix);
+ user_iface_log_write(0, txt);
+ snprintf(txt, LOG_LINE_LEN, "pattern center (y) = %i pix",
+ pattern.center.y_pix);
+ user_iface_log_write(0, txt);
+}
+
+static void pattern_rotation_fix (void)
+{
+
+ proc_load_mem(1);
+
+ /* invert image before rotation to avoid black bands */
+ proc_not();
+ proc_rotate(pattern.center.x_pix, pattern.center.y_pix, pattern.angle);
+ proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU);
+ proc_save_mem(2);
+}
+
+static void pattern_dimensions_get (void)
+{
+
+ proc_load_mem(2);
+
+ proc_erode_dilate(16);
+ proc_dilate(PATTERN_DILATE);
+ proc_contours(&contours, &hierarchy);
+ proc_bounding_rect(&(contours[0]), &(rect[0]), true);
+}
+
+static void pattern_dimensions_fix (void)
+{
+
+ /* Need to correct also pattern dilatation (pattern_dimensions_get()) */
+ pattern.origin.x_pix = rect[0].x;
+ pattern.origin.y_pix = rect[0].y;
+ pattern.width = rect[0].width;
+ pattern.height = rect[0].height;
+
+ proc_load_mem(2);
+ proc_ROI(pattern.origin.x_pix, pattern.origin.y_pix,
+ pattern.width, pattern.height);
+ proc_save_mem(3);
+}
+
+static void pattern_squares_find (void)
+{
+
+ proc_load_mem(3);
+
+ proc_distance_transform();
+ proc_local_max();
+ proc_dilate(6);
+ proc_save_mem(4);
+
+ proc_contours(&contours, &hierarchy);
+ squares_n = contours.size();
+}
+
+static void pattern_squares_pos_get (void)
+{
+
+ for (ptrdiff_t i = 0; i < squares_n; i++) {
+ proc_bounding_rect(&(contours[i]), &(rect[i]), true);
+ pattern.square[i].pos.x_pix = rect[i].x + rect[i].width/2.0;
+ pattern.square[i].pos.y_pix = rect[i].y + rect[i].height/2.0;
+ }
+}
+
+static void pattern_squares_len_get (void)
+{
+
+ proc_load_mem(4);
+ for (ptrdiff_t i = 0; i < squares_n; i++) {
+ proc_pixel_get(pattern.square[i].pos.x_pix,
+ pattern.square[i].pos.y_pix,
+ &(pattern.square[i].len));
+ pattern.square[i].len *= 2;
+ }
+}
+
+static void pattern_calib_mm_pix (void)
+{
+ uint8_t pattern_len[OBJECTS_MAX];
+ uint8_t median_size;
+ char txt[LOG_LINE_LEN];
+
+ for (ptrdiff_t i = 0; i < squares_n; i++)
+ pattern_len[i] = pattern.square[i].len;
+ median_size = alx_median_u8(squares_n, pattern_len);
+ ratio_mm_pix = PATTERN_SQUARE_LEN_MM / median_size;
+
+ snprintf(txt, LOG_LINE_LEN, "mm/pix = %lf", ratio_mm_pix);
+ user_iface_log_write(0, txt);
+}
+
+/* process -------------------------------------------------------------------*/
+static void objects_bgr2gray (void)
+{
+
+ proc_load_mem(0);
+
+ proc_cvt_color(cv::COLOR_BGR2GRAY);
+ proc_save_mem(1);
+}
+
+static void objects_rotation_fix (void)
+{
+
+ proc_load_mem(1);
+
+ /* invert image before rotation to avoid black bands */
+ proc_not();
+ proc_rotate(pattern.center.x_pix, pattern.center.y_pix, pattern.angle);
+ proc_save_mem(2);
+}
+
+static void objects_dimensions_fix (void)
+{
+
+ /* Need to correct also pattern dilatation (pattern_dimensions_get()) */
+ proc_load_mem(2);
+
+ proc_ROI(pattern.origin.x_pix, pattern.origin.y_pix,
+ pattern.width, pattern.height);
+ proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU);
+ proc_save_mem(3);
+}
+
+static void objects_segment (void)
+{
+
+ proc_load_mem(3);
+
+ proc_dilate_erode(3);
+ proc_erode_dilate(3);
+ proc_save_mem(4);
+
+ proc_distance_transform();
+ proc_threshold(cv::THRESH_BINARY_INV, 30);
+ proc_distance_transform();
+ proc_skeleton();
+ proc_threshold(cv::THRESH_BINARY_INV, 10);
+ proc_save_ref();
+ proc_save_mem(5);
+
+ proc_load_mem(3);
+ proc_and_2ref();
+ proc_distance_transform();
+ proc_threshold(cv::THRESH_BINARY, 10);
+ proc_save_mem(6);
+}
+
+static int objects_contours (void)
+{
+
+ proc_load_mem(6);
+
+ proc_contours(&contours, &hierarchy);
+ objects_n = contours.size();
+ if (!objects_n)
+ return OBJECTS_NOK_OBJECTS;
+
+ return 0;
+}
+
+static void objects_position_pix (void)
+{
+
+ for (ptrdiff_t i = 0; i < objects_n; i++) {
+ proc_fit_ellipse(&(contours[i]), &(rect_rot[i]), true);
+ objects[i].pos.x_pix = rect_rot[i].center.x;
+ objects[i].pos.y_pix = rect_rot[i].center.y;
+ objects[i].angle = -rect_rot[i].angle + 90.0;
+ if (objects[i].angle < 0)
+ objects[i].angle += 180.0;
+ }
+}
+
+static void objects_position_mm (void)
+{
+
+ for (ptrdiff_t i = 0; i < objects_n; i++) {
+ objects[i].pos.x_mm = ratio_mm_pix * objects[i].pos.x_pix;
+ objects[i].pos.y_mm = ratio_mm_pix * objects[i].pos.y_pix;
+ }
+}
+
+static void objects_size_pix (void)
+{
+ double area[OBJECTS_MAX];
+ double perimeter[OBJECTS_MAX];
+
+ proc_contours_size(&contours, area, perimeter);
+ for (ptrdiff_t i = 0; i < objects_n; i++) {
+ objects[i].area_pix2 = area[i];
+ objects[i].perimeter_pix = perimeter[i];
+ }
+}
+
+static void objects_size_mm (void)
+{
+
+ for (ptrdiff_t i = 0; i < objects_n; i++) {
+ objects[i].area_mm2 = pow(ratio_mm_pix, 2) *
+ objects[i].area_pix2;
+ objects[i].perimeter_mm = ratio_mm_pix *
+ objects[i].perimeter_pix;
+ }
+}
+
+static void objects_shape (void)
+{
+
+ for (ptrdiff_t i = 0; i < objects_n; i++) {
+ proc_min_area_rect(&(contours[i]), &(rect_rot[i]), true);
+
+ objects[i].ratio_p2_a = pow(objects[i].perimeter_pix, 2) /
+ objects[i].area_pix2;
+ objects[i].area_rect = rect_rot[i].size.width *
+ rect_rot[i].size.height;
+ objects[i].perimeter_rect = 2.0 * (rect_rot[i].size.width +
+ rect_rot[i].size.height);
+ objects[i].ratio_p_prect = objects[i].perimeter_pix /
+ objects[i].perimeter_rect;
+ objects[i].ratio_a_arect = objects[i].area_pix2 /
+ objects[i].area_rect;
+ }
+}
+
+static void objects_log (void)
+{
+ char txt[LOG_LINE_LEN];
+
+ for (ptrdiff_t i = 0; i < objects_n; i++) {
+ snprintf(txt, LOG_LINE_LEN, "Object[%ti]:", i);
+ user_iface_log_write(0, txt);
+ snprintf(txt, LOG_LINE_LEN, " pos: (%.1lf, %.1lf) mm",
+ objects[i].pos.x_mm,
+ objects[i].pos.y_mm);
+ user_iface_log_write(0, txt);
+ snprintf(txt, LOG_LINE_LEN, " ang = %.1lf DEG",
+ objects[i].angle);
+ user_iface_log_write(0, txt);
+ snprintf(txt, LOG_LINE_LEN, " A = %.1lf mm2",
+ objects[i].area_mm2);
+ user_iface_log_write(0, txt);
+ snprintf(txt, LOG_LINE_LEN, " P = %.1lf mm",
+ objects[i].perimeter_mm);
+ user_iface_log_write(0, txt);
+ snprintf(txt, LOG_LINE_LEN, " p2/A = %.2lf",
+ objects[i].ratio_p2_a);
+ user_iface_log_write(0, txt);
+ snprintf(txt, LOG_LINE_LEN, " p/p_r = %.2lf",
+ objects[i].ratio_p_prect);
+ user_iface_log_write(0, txt);
+ snprintf(txt, LOG_LINE_LEN, " A/A_r = %.2lf",
+ objects[i].ratio_a_arect);
+ user_iface_log_write(0, txt);
+ }
+}
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/modules/proc/src/proc_resistor.cpp b/src/proc/resistor.cpp
index 5ee8e14..5c370e7 100644
--- a/modules/proc/src/proc_resistor.cpp
+++ b/src/proc/resistor.cpp
@@ -1,1417 +1,1279 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* pow() */
- #include <cmath>
- /* snprintf() & fflush() */
- #include <cstdio>
-
-/* Packages ------------------------------------------------------------------*/
- /* openCV */
- #include <opencv2/opencv.hpp>
-
-/* Project -------------------------------------------------------------------*/
- /* CONSTANTS */
- #include "img_iface.hpp"
- /* user_iface_log */
- #include "user_iface.hpp"
-
-/* Module --------------------------------------------------------------------*/
- #include "proc_common.hpp"
-
- #include "proc_resistor.hpp"
-
-
-/******************************************************************************
- ******* structs **************************************************************
- ******************************************************************************/
-struct Resistor_Bands {
- /* position */
- int x;
- int y;
-
- /* value */
- unsigned char h;
- unsigned char s;
- unsigned char v;
-};
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-/* Global --------------------------------------------------------------------*/
-
-/* Static --------------------------------------------------------------------*/
-static std::vector <std::vector <cv::Point_ <int>>> contours;
-static class cv::Mat hierarchy;
-static class cv::RotatedRect rect_rot;
-static class cv::Rect_ <int> rect;
-static int bkgd;
-static int bands_n;
-static struct Resistor_Bands bands [5];
-static char code [6];
-static int base;
-static float resistance;
-static int tolerance;
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void result_resistor (int status);
-
-static int resistor_find (void);
-static void resistor_align (void);
-static void resistor_dimensions_0 (void);
-static void resistor_crop_0 (void);
-static void resistor_bkgd (void);
-static void resistor_dimensions_1 (void);
-static void resistor_crop_1 (void);
-static void separate_bkgd_bands_h (void);
-static void separate_bkgd_bands_s (void);
-static void separate_bkgd_bands_v (void);
-static void bkgd_find (void);
-static int bands_find (void);
-static void bands_colors (void);
-static void bands_code (void);
-static char band_hsv2code (struct Resistor_Bands *band);
-static void bands_code_deduce_0 (void);
-static void bands_code_deduce_1 (void);
-static void resistor_value (void);
-static int resistor_tolerance (void);
-static int chk_std_value (void);
-
-
-/******************************************************************************
- ******* global functions *****************************************************
- ******************************************************************************/
-int proc_resistor (void)
-{
- int status;
-
-
- proc_save_mem(0);
- /* Find resistor (position and angle) */
- {
- /* Measure time */
- clock_start();
-
- status = resistor_find();
- if (status) {
- result_resistor(status);
- return status;
- }
-
- /* Measure time */
- clock_stop("Find resistor");
- }
- /* Align resistor, find its dimensions, and crop */
- {
- /* Measure time */
- clock_start();
-
- resistor_align();
- resistor_dimensions_0();
- resistor_crop_0();
-
- /* Measure time */
- clock_stop("Align, dimensions, & crop");
- }
- /* Find backgroung color */
- {
- /* Measure time */
- clock_start();
-
- resistor_bkgd();
-
- /* Measure time */
- clock_stop("Background color");
- }
- /* Crop more */
- {
- /* Measure time */
- clock_start();
-
- resistor_dimensions_1();
- resistor_crop_1();
-
- /* Measure time */
- clock_stop("Crop more");
- }
- /* Separate background (BK) and lines (WH) */
- {
- /* Measure time */
- clock_start();
-
- separate_bkgd_bands_h();
- separate_bkgd_bands_s();
- separate_bkgd_bands_v();
- bkgd_find();
-
- /* Measure time */
- clock_stop("Separate bkgd from bands");
- }
- /* Find bands: contours -> rectangles */
- {
- /* Measure time */
- clock_start();
-
- status = bands_find();
- if (status) {
- result_resistor(status);
- return status;
- }
-
- /* Measure time */
- clock_stop("Find bands");
- }
- /* Read values on the center of each band */
- {
- /* Measure time */
- clock_start();
-
- bands_colors();
-
- /* Measure time */
- clock_stop("Bands' colors");
- }
- /* Interpret colors */
- {
- /* Measure time */
- clock_start();
-
- bands_code();
- bands_code_deduce_0();
- bands_code_deduce_1();
- int i;
- for (i = 0; i < 5; i++) {
- switch (code[i]) {
- case 'q':
- case 'w':
- case 'e':
- case 'r':
- case 't':
- case 'y':
- case 'u':
- status = RESISTOR_NOK_COLOR;
- result_resistor(status);
- return status;
- }
- }
-
- /* Measure time */
- clock_stop("Interpret colors");
- }
- /* Calculate resistor value & tolerance */
- {
- /* Measure time */
- clock_start();
-
- resistor_value();
- status = resistor_tolerance();
- if (status) {
- result_resistor(status);
- return status;
- }
-
- /* Write resistor value into log */
- if (bands_n != 1) {
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Resistance: %.2E ± %i% Ohm",
- resistance, tolerance);
- } else {
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Resistance: 0 Ohm");
- }
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-
- /* Measure time */
- clock_stop("Calculate resistance & tolerance");
- }
- /* Check STD value */
- {
- /* Measure time */
- clock_start();
-
- status = chk_std_value();
- if (status) {
- result_resistor(status);
- return status;
- }
-
- /* Measure time */
- clock_stop("Chk STD values");
- }
-
- status = RESISTOR_OK;
- result_resistor(status);
- return status;
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-static void result_resistor (int status)
-{
- /* Cleanup */
-
- /* Write result into log */
- char result [LOG_LINE_LEN];
- switch (status) {
- case RESISTOR_OK:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Resistor: OK");
- break;
- case RESISTOR_NOK_RESISTOR:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Resistor: NOK_RESISTOR");
- break;
- case RESISTOR_NOK_BANDS:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Resistor: NOK_BANDS");
- break;
- case RESISTOR_NOK_COLOR:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Resistor: NOK_COLOR");
- break;
- case RESISTOR_NOK_STD_VALUE:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Resistor: NOK_STD_VALUE");
- break;
- case RESISTOR_NOK_TOLERANCE:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Resistor: NOK_TOLERANCE");
- break;
- default:
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Resistor: NOK");
- break;
- }
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-}
-
-static int resistor_find (void)
-{
- int status;
-
- proc_load_mem(0);
-
- /* BGR -> HSV */
- proc_cvt_color(cv::COLOR_BGR2HSV);
- proc_save_mem(19);
-
- proc_cmp(IMG_IFACE_CMP_SATURATION);
- proc_smooth(IMGI_SMOOTH_MEDIAN, 7);
- proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU);
- proc_save_mem(1);
- proc_dilate_erode(10);
- proc_contours(&contours, &hierarchy);
-
- /* If no contour is found, error: NOK_RESISTOR */
- if (!contours.size()) {
- status = RESISTOR_NOK_RESISTOR;
- return status;
- }
-
- proc_min_area_rect(&(contours[0]), &rect_rot, true);
-
- /* If angle is < -45º, it is taking into acount the incorrect side */
- if (rect_rot.angle < -45.0) {
- rect_rot.angle += 90.0;
- }
-
- status = RESISTOR_OK;
- return status;
-}
-
-static void resistor_align (void)
-{
- proc_load_mem(19);
- proc_rotate(&rect_rot);
- proc_save_mem(2);
- proc_load_mem(1);
- proc_rotate(&rect_rot);
- proc_save_mem(3);
-}
-
-static void resistor_dimensions_0 (void)
-{
- proc_load_mem(3);
-
- proc_dilate_erode(10);
- proc_contours(&contours, &hierarchy);
- proc_bounding_rect(&(contours[0]), &rect, true);
-}
-
-static void resistor_crop_0 (void)
-{
- proc_load_mem(2);
-
- int x;
- int y;
- int w;
- int h;
- w = rect.width;
- h = rect.height;
- x = rect.x;
- y = rect.y;
- proc_ROI(x, y, w, h);
- proc_save_mem(4);
-}
-
-static void resistor_bkgd (void)
-{
- /* hue */
- uint8_t bkgd_hue;
- proc_load_mem(4);
- proc_cmp(IMG_IFACE_CMP_HUE);
- proc_median_vertical();
- proc_median_horizontal();
- proc_pixel_value(0, 0, &bkgd_hue);
-
- /* saturation */
- uint8_t bkgd_sat;
- proc_load_mem(4);
- proc_cmp(IMG_IFACE_CMP_SATURATION);
- proc_median_vertical();
- proc_median_horizontal();
- proc_pixel_value(0, 0, &bkgd_sat);
-
- if (bkgd_hue < 50) {
- /* Beige */
- bkgd = 0;
- } else {
- /* Blue */
- if ((bkgd_hue < 90) || (bkgd_sat < 100)) {
- /* Teal blue */
- bkgd = 1;
- } else if (bkgd_hue >= 105) {
- /* Dark blue */
- bkgd = 2;
- } else {
- /* Normal blue */
- bkgd = 3;
- }
- }
-}
-
-static void resistor_dimensions_1 (void)
-{
- proc_load_mem(3);
-
- proc_dilate_erode(10);
- proc_erode_dilate((rect.height * 0.67) / 2);
- proc_contours(&contours, &hierarchy);
- proc_bounding_rect(&(contours[0]), &rect, true);
-}
-
-static void resistor_crop_1 (void)
-{
- proc_load_mem(2);
-
- int x;
- int y;
- int w;
- int h;
- w = rect.width * 0.95;
- h = rect.height * 0.8;
- x = rect.x + w * (1.0 - 0.95) / 2.0;
- y = rect.y + h * (1.0 - 0.8) / 2.0;
- proc_ROI(x, y, w, h);
- proc_save_mem(4);
-}
-
-static void separate_bkgd_bands_h (void)
-{
- proc_load_mem(4);
-
- proc_cmp(IMG_IFACE_CMP_HUE);
- proc_median_vertical();
- proc_save_mem(9);
-
- switch (bkgd) {
- case 0:
- proc_threshold(cv::THRESH_TOZERO_INV, 20);
- proc_threshold(cv::THRESH_TOZERO, 5);
- break;
- case 1:
- proc_threshold(cv::THRESH_TOZERO_INV, 100);
- proc_threshold(cv::THRESH_TOZERO, 70);
- break;
- case 2:
- proc_threshold(cv::THRESH_TOZERO_INV, 115);
- proc_threshold(cv::THRESH_TOZERO, 100);
- break;
- case 3:
- proc_threshold(cv::THRESH_TOZERO_INV, 110);
- proc_threshold(cv::THRESH_TOZERO, 90);
- break;
- }
- proc_threshold(cv::THRESH_BINARY_INV, 1);
- proc_save_mem(5);
-}
-
-static void separate_bkgd_bands_s (void)
-{
- proc_load_mem(4);
-
- proc_cmp(IMG_IFACE_CMP_SATURATION);
- proc_median_vertical();
- proc_save_mem(10);
-
- switch (bkgd) {
-
- case 0:
- proc_threshold(cv::THRESH_TOZERO_INV, 160);
- proc_threshold(cv::THRESH_TOZERO, 110);
- break;
- case 1:
- proc_threshold(cv::THRESH_TOZERO_INV, 180);
- proc_threshold(cv::THRESH_TOZERO, 30);
- break;
- case 2:
- proc_threshold(cv::THRESH_TOZERO_INV, 190);
- proc_threshold(cv::THRESH_TOZERO, 170);
- break;
- case 3:
- proc_threshold(cv::THRESH_TOZERO_INV, 210);
- proc_threshold(cv::THRESH_TOZERO, 120);
- break;
- }
- proc_threshold(cv::THRESH_BINARY_INV, 1);
- proc_save_mem(6);
-}
-
-static void separate_bkgd_bands_v (void)
-{
- proc_load_mem(4);
-
- proc_cmp(IMG_IFACE_CMP_VALUE);
- proc_median_vertical();
- proc_save_mem(11);
-
- switch (bkgd) {
- case 0:
- proc_threshold(cv::THRESH_TOZERO_INV, 170);
- proc_threshold(cv::THRESH_TOZERO, 100);
- break;
-
- case 1:
- proc_threshold(cv::THRESH_TOZERO_INV, 180);
- proc_threshold(cv::THRESH_TOZERO, 100);
- break;
- case 2:
- proc_threshold(cv::THRESH_TOZERO_INV, 180);
- proc_threshold(cv::THRESH_TOZERO, 150);
- break;
- case 3:
- proc_threshold(cv::THRESH_TOZERO_INV, 190);
- proc_threshold(cv::THRESH_TOZERO, 90);
- break;
- }
- proc_threshold(cv::THRESH_BINARY_INV, 1);
- proc_save_mem(7);
-}
-
-static void bkgd_find (void)
-{
- /* Merge the components: H | S | V */
- proc_load_mem(7);
- proc_save_ref();
- proc_load_mem(6);
- proc_or_2ref();
- proc_save_ref();
- proc_load_mem(5);
- proc_or_2ref();
- if (rect.width * 0.95 > 80) {
- proc_dilate_erode(1);
- }
- proc_save_mem(8);
-}
-
-static int bands_find (void)
-{
- int status;
-
- proc_load_mem(8);
-
- /* Contours */
- proc_contours(&contours, &hierarchy);
- if (contours.size() > 5) {
- proc_load_mem(8);
- proc_dilate_erode(1);
- proc_contours(&contours, &hierarchy);
- }
-
- bands_n = contours.size();
- if ((bands_n == 0) || (bands_n == 2) || (bands_n > 5)) {
- status = RESISTOR_NOK_BANDS;
- return status;
- }
-
- /* Band 0 (hundreds) */
- if (bands_n == 5) {
- proc_bounding_rect(&(contours[4]), &rect, true);
- bands[0].x = rect.x + rect.width / 2.0;
- bands[0].y = rect.y + rect.height / 2.0;
- }
-
- /* Band 1 (tens) */
- if (bands_n >= 3) {
- if (bands_n > 3) {
- proc_bounding_rect(&(contours[3]), &rect, true);
- } else {
- proc_bounding_rect(&(contours[2]), &rect, true);
- }
- bands[1].x = rect.x + rect.width / 2.0;
- bands[1].y = rect.y + rect.height / 2.0;
- }
-
- /* Band 2 (units) */
- if (bands_n > 3) {
- proc_bounding_rect(&(contours[2]), &rect, true);
- } else if (bands_n == 3) {
- proc_bounding_rect(&(contours[1]), &rect, true);
- } else { /* bands_n == 1 */
- proc_bounding_rect(&(contours[0]), &rect, true);
- }
- bands[2].x = rect.x + rect.width / 2.0;
- bands[2].y = rect.y + rect.height / 2.0;
-
- /* Band 3 (multiplier) */
- if (bands_n >= 3) {
- if (bands_n > 3) {
- proc_bounding_rect(&(contours[1]), &rect, true);
- } else {
- proc_bounding_rect(&(contours[0]), &rect, true);
- }
- bands[3].x = rect.x + rect.width / 2.0;
- bands[3].y = rect.y + rect.height / 2.0;
- }
-
- /* Band 4 (tolerance) */
- if (bands_n > 3) {
- proc_bounding_rect(&(contours[0]), &rect, true);
- bands[4].x = rect.x + rect.width / 2.0;
- bands[4].y = rect.y + rect.height / 2.0;
- }
-
- status = RESISTOR_OK;
- return status;
-}
-
-static void bands_colors (void)
-{
- /* Hue */
- proc_load_mem(9);
- if (bands_n == 5) {
- proc_pixel_value(bands[0].x, bands[0].y, &(bands[0].h));
- }
- if (bands_n >= 3) {
- proc_pixel_value(bands[1].x, bands[1].y, &(bands[1].h));
- }
- proc_pixel_value(bands[2].x, bands[2].y, &(bands[2].h));
- if (bands_n >= 3) {
- proc_pixel_value(bands[3].x, bands[3].y, &(bands[3].h));
- }
- if (bands_n > 3) {
- proc_pixel_value(bands[4].x, bands[4].y, &(bands[4].h));
- }
-
- /* Saturation */
- proc_load_mem(10);
- if (bands_n == 5) {
- proc_pixel_value(bands[0].x, bands[0].y, &(bands[0].s));
- }
- if (bands_n >= 3) {
- proc_pixel_value(bands[1].x, bands[1].y, &(bands[1].s));
- }
- proc_pixel_value(bands[2].x, bands[2].y, &(bands[2].s));
- if (bands_n >= 3) {
- proc_pixel_value(bands[3].x, bands[3].y, &(bands[3].s));
- }
- if (bands_n > 3) {
- proc_pixel_value(bands[4].x, bands[4].y, &(bands[4].s));
- }
-
- /* Value */
- proc_load_mem(11);
- if (bands_n == 5) {
- proc_pixel_value(bands[0].x, bands[0].y, &(bands[0].v));
- }
- if (bands_n >= 3) {
- proc_pixel_value(bands[1].x, bands[1].y, &(bands[1].v));
- }
- proc_pixel_value(bands[2].x, bands[2].y, &(bands[2].v));
- if (bands_n >= 3) {
- proc_pixel_value(bands[3].x, bands[3].y, &(bands[3].v));
- }
- if (bands_n > 3) {
- proc_pixel_value(bands[4].x, bands[4].y, &(bands[4].v));
- }
-}
-
-static void bands_code (void)
-{
- /* Init to 0 */
- int i;
- for (i = 0; i < 6; i++) {
- code[i] = '\0';
- }
-
- /* Band 0 (hundreds) */
- if (bands_n == 5) {
- code[0] = band_hsv2code(&bands[0]);
- } else {
- code[0] = 'n';
- }
-
-
- /* Band 1 (tens) */
- if (bands_n != 1) {
- code[1] = band_hsv2code(&bands[1]);
- } else {
- code[1] = 'n';
- }
-
- /* Band 2 (units) */
- code[2] = band_hsv2code(&bands[2]);
-
- /* Band 3 (multiplier) */
- if (bands_n != 1) {
- code[3] = band_hsv2code(&bands[3]);
- } else {
- code[3] = 'n';
- }
-
- /* Band 4 (tolerance) */
- if (bands_n > 3) {
- code[4] = band_hsv2code(&bands[4]);
- } else {
- code[4] = 'n';
- }
-
- /* Write bands' code into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Code: \"%s\"",
- code);
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-}
-
-static char band_hsv2code (struct Resistor_Bands *band)
-{
- char ch;
-
- /*
- * Not able to segmentate:
- * q = 1 2
- * w = 2 3
- * e = 3 g
- * r = 3 4
- * t = 1 8
- * y = 0 1
- * u = 0 1 8
- */
-
- if (band->h < 10) {
- // 1 2 3
- if (band->s < 90) {
- // 1 3
- if (band->v < 85) {
- ch = '1';
- } else {
- ch = '3';
- }
- } else if (band->s < 140) {
- // 1 2 3
- if (band->v < 60) {
- ch = '1';
- } else if (band->v < 85) {
- // 1 2
- ch = 'q';
- } else if (band->v < 90) {
- ch = '2';
- } else if (band->v < 150) {
- // 2 3
- ch = 'w';
- } else {
- ch = '3';
- }
- } else if (band->s < 210) {
- // 2 3
- if (band->v < 90) {
- ch = '2';
- } else if (band->v < 150) {
- // 2 3
- ch = 'w';
- } else {
- ch = '3';
- }
- } else {
- ch = '3';
- }
- } else if (band->h < 35) {
- // 1 3 g
- if (band->s < 130) {
- // 1 3
- if (band->v < 85) {
- ch = '1';
- } else {
- ch = '3';
- }
- } else if (band->s < 140) {
- // 1 3 g
- if (band->v < 85) {
- ch = '1';
- } else if (band->v < 120) {
- ch = '3';
- } else {
- // 3 g
- ch = 'e';
- }
- } else if (band->s < 180) {
- // 3 g
- if (band->v < 120) {
- ch = '3';
- } else {
- // 3 g
- ch = 'e';
- }
- } else {
- ch = '3';
- }
- } else if (band->h < 50) {
- // 1 3
- if (band->s < 140) {
- // 1 3
- if (band->v < 85) {
- ch = '1';
- } else {
- ch = '3';
- }
- } else {
- ch = '3';
- }
- } else if (band->h < 60) {
- // 1 3 4
- if (band->s < 140) {
- // 1 3
- if (band->v < 85) {
- ch = '1';
- } else {
- ch = '3';
- }
- } else if (band->s < 160) {
- ch = '3';
- } else if (band->s < 180) {
- // 3 4
- if (band->v < 110) {
- // 3 4
- ch = 'r';
- } else {
- ch = '3';
- }
- } else {
- ch = '3';
- }
- } else if (band->h < 80) {
- // 1 5
- if (band->s < 165) {
- ch = '1';
- } else {
- ch = '5';
- }
- } else if (band->h < 90) {
- ch = '1';
- } else if (band->h < 100) {
- // 0 1 8 9
- if (band->s < 40) {
- // 1 8 9
- if (band->v < 55) {
- ch = '1';
- } else if (band->v < 80) {
- // 1 8
- ch = 't';
- } else if (band->v < 125) {
- ch = '1';
- } else {
- ch = '9';
- }
- } else if (band->s < 70) {
- // 0 1 8 9
- if (band->v < 45) {
- ch = '0';
- } else if (band->v < 55) {
- // 0 1
- ch = 'y';
- } else if (band->v < 75) {
- // 0 1 8
- ch = 'u';
- } else if (band->v < 80) {
- // 1 8
- ch = 't';
- } else if (band->v < 125) {
- ch = '1';
- } else {
- ch = '9';
- }
- } else if (band->s < 100) {
- // 0 1 8
- if (band->v < 45) {
- ch = '0';
- } else if (band->v < 55) {
- // 0 1
- ch = 'y';
- } else if (band->v < 75) {
- // 0 1 8
- ch = 'u';
- } else if (band->v < 80) {
- // 1 8
- ch = 't';
- } else {
- ch = '1';
- }
- } else if (band->s < 140) {
- // 0 1
- if (band->v < 45) {
- ch = '0';
- } else if (band->v < 75) {
- // 0 1
- ch = 'y';
- } else {
- ch = '1';
- }
- } else {
- ch = '0';
- }
- } else if (band->h < 110) {
- // 0 1 6 8
- if (band->s < 40) {
- // 1 8
- if (band->v < 55) {
- ch = '1';
- } else if (band->v < 80) {
- // 1 8
- ch = 't';
- } else {
- ch = '1';
- }
- } else if (band->s < 100) {
- // 0 1 8
- if (band->v < 45) {
- ch = '0';
- } else if (band->v < 55) {
- // 0 1
- ch = 'y';
- } else if (band->v < 75) {
- // 0 1 8
- ch = 'u';
- } else if (band->v < 80) {
- // 1 8
- ch = 't';
- } else {
- ch = '1';
- }
- } else if (band->s < 140) {
- // 0 1
- if (band->v < 45) {
- ch = '0';
- } else if (band->v < 75) {
- // 0 1
- ch = 'y';
- } else {
- ch = '1';
- }
- } else if (band->s < 200) {
- ch = '0';
- } else {
- ch = '6';
- }
- } else if (band->h < 120) {
- // 0 1 6 7
- if (band->s < 40) {
- ch = '1';
- } else if (band->s < 90) {
- // 0 1
- if (band->v < 45) {
- ch = '0';
- } else if (band->v < 75) {
- // 0 1
- ch = 'y';
- } else {
- ch = '1';
- }
- } else if (band->s < 110) {
- // 0 1 7
- if (band->v < 45) {
- ch = '0';
- } else if (band->v < 75) {
- // 0 1
- ch = 'y';
- } else if (band->v < 120) {
- ch = '1';
- } else {
- ch = '7';
- }
- } else if (band->s < 140) {
- // 0 1
- if (band->v < 45) {
- ch = '0';
- } else if (band->v < 75) {
- // 0 1
- ch = 'y';
- } else {
- ch = '1';
- }
- } else if (band->s < 200) {
- ch = '0';
- } else {
- ch = '6';
- }
- } else if (band->h < 130) {
- // 0 1 7
- if (band->s < 40) {
- ch = '1';
- } else if (band->s < 90) {
- // 0 1
- if (band->v < 45) {
- ch = '0';
- } else if (band->v < 75) {
- // 0 1
- ch = 'y';
- } else {
- ch = '1';
- }
- } else if (band->s < 110) {
- // 0 1 7
- if (band->v < 45) {
- ch = '0';
- } else if (band->v < 75) {
- // 0 1
- ch = 'y';
- } else if (band->v < 120) {
- ch = '1';
- } else {
- ch = '7';
- }
- } else if (band->s < 140) {
- // 0 1
- if (band->v < 45) {
- ch = '0';
- } else if (band->v < 75) {
- // 0 1
- ch = 'y';
- } else {
- ch = '1';
- }
- } else {
- ch = '0';
- }
- } else if (band->h < 140) {
- // 0 1
- if (band->s < 40) {
- ch = '1';
- } else if (band->s < 140) {
- // 0 1
- if (band->v < 45) {
- ch = '0';
- } else if (band->v < 75) {
- // 0 1
- ch = 'y';
- } else {
- ch = '1';
- }
- } else {
- ch = '0';
- }
- } else if (band->h < 150) {
- ch = '0';
- } else {
- ch = '2';
- }
-
- return ch;
-}
-
-static void bands_code_deduce_0 (void)
-{
- /*
- * Not able to segmentate:
- * q = 1 2
- * w = 2 3
- * e = 3 g
- * r = 3 4
- * t = 1 8
- * y = 0 1
- * u = 0 1 8
- */
-
- /* Band 0 (hundreds) */
- switch (code[0]) {
- case 'e':
- code[0] = '3';
- break;
- case 'y':
- code[0] = '1';
- break;
- case 'u':
- code[0] = 't';
- break;
- }
-
- /* Band 2 (units) */
- switch (code[2]) {
- case 'e':
- code[2] = '3';
- break;
- }
-
- /* Band 3 (multiplier) */
- switch (code[3]) {
- case 't':
- code[3] = '1';
- break;
- case 'u':
- code[3] = 'y';
- break;
- }
-
- /* Band 4 (tolerance) */
- switch (code[4]) {
- case 'w':
- code[4] = '2';
- break;
- case 'e':
- code[4] = 'g';
- break;
- case 't':
- code[4] = '1';
- break;
- case 'y':
- code[4] = '1';
- break;
- case 'u':
- code[4] = '1';
- break;
- }
-
- /* Write bands' code into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Code: \"%s\"",
- code);
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-}
-
-static void bands_code_deduce_1 (void)
-{
- /*
- * Not able to segmentate:
- * q = 1 2
- * w = 2 3
- * e = 3 g
- * r = 3 4
- * t = 1 8
- * y = 0 1
- * u = 0 1 8
- */
-
- /* Band 0 (hundreds) */
- switch (code[0]) {
- case 'q':
- switch (code[1]) {
- case '1':
- case '3':
- case '5':
- case '6':
- case '8':
- code[0] = '1';
- break;
- case '2':
- case '4':
- case '7':
- code[0] = '2';
- break;
- case '0':
- // q
- break;
- }
- break;
- case 'w':
- switch (code[1]) {
- case '2':
- case '4':
- case '7':
- code[0] = '2';
- break;
- case '3':
- case '6':
- case '9':
- code[0] = '3';
- break;
- case '0':
- // w
- break;
- }
- break;
- case 'r':
- switch (code[1]) {
- case '0':
- case '6':
- case '9':
- code[0] = '3';
- break;
- case '7':
- code[0] = '4';
- break;
- case '3':
- // r
- break;
- }
- break;
- case 't':
- switch (code[1]) {
- case '0':
- case '1':
- case '3':
- case '5':
- case '6':
- case '8':
- code[0] = '1';
- break;
- case '2':
- // t
- break;
- }
- break;
- }
-
- /* Band 1 (tens) */
- switch (code[1]) {
- case 'q':
- switch (code[0]) {
- case '5':
- case '9':
- code[1] = '1';
- break;
- case '2':
- case '6':
- case '8':
- code[1] = '2';
- break;
- case '1':
- // q
- break;
- }
- break;
- case 'w':
- switch (code[0]) {
- case '2':
- case '6':
- case '8':
- code[1] = '2';
- break;
- case '3':
- case '4':
- code[1] = '3';
- break;
- case '1':
- // w
- break;
- }
- break;
- case 't':
- switch (code[0]) {
- case '5':
- case '9':
- code[1] = '1';
- break;
- case '6':
- code[1] = '8';
- break;
- case '1':
- // t
- break;
- }
- break;
- case 'y':
- switch (code[0]) {
- case '2':
- case '3':
- code[1] = '0';
- break;
- case '5':
- case '9':
- code[1] = '1';
- break;
- case '1':
- // y
- break;
- }
- break;
- case 'u':
- switch (code[0]) {
- case '2':
- case '3':
- code[1] = '0';
- break;
- case '5':
- case '9':
- code[1] = '1';
- break;
- case '6':
- code[1] = '8';
- break;
- case '1':
- // u
- break;
- }
- break;
- }
-
- /* Band 2 (units) */
- switch (code[2]) {
- case 'y':
- code[2] = '0';
- break;
- case 'u':
- code[2] = '0';
- break;
- }
-
- /* Band 3 (multiplier) */
- switch (code[3]) {
- case 'y':
- code[3] = '0';
- break;
- }
-
- /* Band 4 (tolerance) */
- switch (code[4]) {
- case 'q':
- code[4] = '2';
- break;
- }
-
- /* Write bands' code into log */
- snprintf(user_iface_log.line[user_iface_log.len], LOG_LINE_LEN,
- "Code: \"%s\"",
- code);
- user_iface_log.lvl[user_iface_log.len] = 0;
- (user_iface_log.len)++;
-}
-
-static void resistor_value (void)
-{
- /* Base value */
- base = code[2] - '0';
- if (code[1] != 'n') {
- base += (code[1] - '0') * 10;
- }
- if (code[0] != 'n') {
- base += (code[0] - '0') * 100;
- }
-
- /* Calculate resistance */
- int power;
- if ((code[3] > '0') && (code[3] < '9')) {
- power = code[3] - '0';
- } else if (code[3] == 'g') {
- power = -1;
- } else if (code[3] == 's') {
- power = -2;
- }
- resistance = base * pow(10, power);
-}
-
-static int resistor_tolerance (void)
-{
- int status;
-
- if (bands_n != 1) {
- switch (code[4]) {
- case '1':
- tolerance = 1;
- break;
- case '2':
- tolerance = 2;
- break;
- case '4':
- case 'g':
- case 'n':
- tolerance = 5;
- break;
- case '8':
- tolerance = 10;
- break;
- default:
- status = RESISTOR_NOK_TOLERANCE;
- return status;
- }
- }
-
- status = RESISTOR_OK;
- return status;
-}
-
-static int chk_std_value (void)
-{
- int status;
-
- /* Check that base value is a standard value */
- int std_values_10 [12] = {10,12,15,18,22,27,33,39,47,56,68,82};
- int std_values_5 [12] = {11,13,16,20,24,30,36,43,51,62,75,91};
-
- bool std_value_nok;
- std_value_nok = true;
-
- int i;
- if (bands_n != 1) {
- for (i = 0; i < 12; i++) {
- if (base == std_values_10[i]) {
- std_value_nok = false;
- }
- if (base == (std_values_10[i] * 10)) {
- std_value_nok = false;
- }
- }
- if (tolerance <= 5) {
- for (i = 0; i < 12; i++) {
- if (base == std_values_5[i]) {
- std_value_nok = false;
- }
- if (base == (std_values_5[i] * 10)) {
- std_value_nok = false;
- }
- }
- }
- } else {
- if (base == 0) {
- std_value_nok = false;
- }
- }
-
- if (std_value_nok) {
- status = RESISTOR_NOK_STD_VALUE;
- return status;
- }
-
- status = RESISTOR_OK;
- return status;
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+#include "vision-artificial/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 ***************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* structs / unions *****************************************************
+ ******************************************************************************/
+struct Resistor_Bands {
+ int x;
+ int y;
+
+ unsigned char h;
+ unsigned char s;
+ unsigned char v;
+};
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+/* Global --------------------------------------------------------------------*/
+/* Static --------------------------------------------------------------------*/
+static class std::vector <class std::vector <class cv::Point_ <int>>> contours;
+static class cv::Mat hierarchy;
+static class cv::RotatedRect rect_rot;
+static class cv::Rect_ <int> rect;
+static int bkgd;
+static int bands_n;
+static struct Resistor_Bands bands[5];
+static char code[6];
+static int base;
+static float resistance;
+static int tolerance;
+
+
+/******************************************************************************
+ ******* static functions (prototypes) ****************************************
+ ******************************************************************************/
+static void result_resistor (int status);
+
+static int resistor_find (void);
+static void resistor_align (void);
+static void resistor_dimensions_0 (void);
+static void resistor_crop_0 (void);
+static void resistor_bkgd (void);
+static void resistor_dimensions_1 (void);
+static void resistor_crop_1 (void);
+static void separate_bkgd_bands_h (void);
+static void separate_bkgd_bands_s (void);
+static void separate_bkgd_bands_v (void);
+static void bkgd_find (void);
+static int bands_find (void);
+static void bands_colors (void);
+static void bands_code (void);
+static char band_hsv2code (struct Resistor_Bands *band);
+static void bands_code_deduce_0 (void);
+static void bands_code_deduce_1 (void);
+static int bands_code_deduce_no (void);
+static void resistor_value (void);
+static int resistor_tolerance (void);
+static void log_resistance (void);
+static int chk_std_value (void);
+
+
+/******************************************************************************
+ ******* global functions *****************************************************
+ ******************************************************************************/
+int proc_resistor (void)
+{
+ int status;
+
+ proc_save_mem(0);
+ /* Find resistor (position and angle) */
+ clock_start();
+ status = resistor_find();
+ if (status) {
+ result_resistor(status);
+ return status;
+ }
+ clock_stop("Find resistor");
+
+ /* Align resistor, find its dimensions, and crop */
+ clock_start();
+ resistor_align();
+ resistor_dimensions_0();
+ resistor_crop_0();
+ clock_stop("Align, dimensions, & crop");
+
+ /* Find backgroung color */
+ clock_start();
+ resistor_bkgd();
+ clock_stop("Background color");
+
+ /* Crop more */
+ clock_start();
+ resistor_dimensions_1();
+ resistor_crop_1();
+ clock_stop("Crop more");
+
+ /* Separate background (BK) and lines (WH) */
+ clock_start();
+ separate_bkgd_bands_h();
+ separate_bkgd_bands_s();
+ separate_bkgd_bands_v();
+ bkgd_find();
+ clock_stop("Separate bkgd from bands");
+
+ /* Find bands: contours -> rectangles */
+ clock_start();
+ status = bands_find();
+ if (status) {
+ result_resistor(status);
+ return status;
+ }
+ clock_stop("Find bands");
+
+ /* Read values on the center of each band */
+ clock_start();
+ bands_colors();
+ clock_stop("Bands' colors");
+
+ /* Interpret colors */
+ clock_start();
+ bands_code();
+ bands_code_deduce_0();
+ bands_code_deduce_1();
+ status = bands_code_deduce_no();
+ if (status) {
+ result_resistor(status);
+ return status;
+ }
+ clock_stop("Interpret colors");
+
+ /* Calculate resistor value & tolerance */
+ clock_start();
+ resistor_value();
+ status = resistor_tolerance();
+ if (status) {
+ result_resistor(status);
+ return status;
+ }
+ log_resistance();
+ clock_stop("Calculate resistance & tolerance");
+
+ /* Check STD value */
+ clock_start();
+ status = chk_std_value();
+ if (status) {
+ result_resistor(status);
+ return status;
+ }
+ clock_stop("Chk STD values");
+
+ result_resistor(status);
+ return 0;
+}
+
+
+/******************************************************************************
+ ******* static functions (definitions) ***************************************
+ ******************************************************************************/
+static void result_resistor (int status)
+{
+
+ switch (status) {
+ case RESISTOR_OK:
+ user_iface_log_write(0, "Resistor: OK");
+ break;
+ case RESISTOR_NOK_RESISTOR:
+ user_iface_log_write(0, "Resistor: NOK_RESISTOR");
+ break;
+ case RESISTOR_NOK_BANDS:
+ user_iface_log_write(0, "Resistor: NOK_BANDS");
+ break;
+ case RESISTOR_NOK_COLOR:
+ user_iface_log_write(0, "Resistor: NOK_COLOR");
+ break;
+ case RESISTOR_NOK_STD_VALUE:
+ user_iface_log_write(0, "Resistor: NOK_STD_VALUE");
+ break;
+ case RESISTOR_NOK_TOLERANCE:
+ user_iface_log_write(0, "Resistor: NOK_TOLERANCE");
+ break;
+ default:
+ user_iface_log_write(0, "Resistor: NOK");
+ break;
+ }
+}
+
+static int resistor_find (void)
+{
+
+ proc_load_mem(0);
+
+ /* BGR -> HSV */
+ proc_cvt_color(cv::COLOR_BGR2HSV);
+ proc_save_mem(19);
+
+ proc_cmp(IMG_IFACE_CMP_SATURATION);
+ proc_smooth(IMGI_SMOOTH_MEDIAN, 7);
+ proc_threshold(cv::THRESH_BINARY, IMG_IFACE_THR_OTSU);
+ proc_save_mem(1);
+ proc_dilate_erode(10);
+ proc_contours(&contours, &hierarchy);
+ if (!contours.size())
+ return RESISTOR_NOK_RESISTOR;
+
+ proc_min_area_rect(&contours[0], &rect_rot, true);
+ /* If angle is < -45º, it is taking into acount the incorrect side */
+ if (rect_rot.angle < -45.0)
+ rect_rot.angle += 90.0;
+
+ return 0;
+}
+
+static void resistor_align (void)
+{
+
+ proc_load_mem(19);
+ proc_rotate(rect_rot.center.x, rect_rot.center.y, rect_rot.angle);
+ proc_save_mem(2);
+ proc_load_mem(1);
+ proc_rotate(rect_rot.center.x, rect_rot.center.y, rect_rot.angle);
+ proc_save_mem(3);
+}
+
+static void resistor_dimensions_0 (void)
+{
+
+ proc_load_mem(3);
+
+ proc_dilate_erode(10);
+ proc_contours(&contours, &hierarchy);
+ proc_bounding_rect(&(contours[0]), &rect, true);
+}
+
+static void resistor_crop_0 (void)
+{
+ int x, y;
+ int w, h;
+
+ proc_load_mem(2);
+
+ w = rect.width;
+ h = rect.height;
+ x = rect.x;
+ y = rect.y;
+ proc_ROI(x, y, w, h);
+ proc_save_mem(4);
+}
+
+static void resistor_bkgd (void)
+{
+ uint8_t bkgd_hue;
+ uint8_t bkgd_sat;
+
+ /* hue */
+ proc_load_mem(4);
+ proc_cmp(IMG_IFACE_CMP_HUE);
+ proc_median_vertical();
+ proc_median_horizontal();
+ proc_pixel_get(0, 0, &bkgd_hue);
+
+ /* saturation */
+ proc_load_mem(4);
+ proc_cmp(IMG_IFACE_CMP_SATURATION);
+ proc_median_vertical();
+ proc_median_horizontal();
+ proc_pixel_get(0, 0, &bkgd_sat);
+
+ if (bkgd_hue < 50) {
+ /* Beige */
+ bkgd = 0;
+ } else {
+ /* Blue */
+ if ((bkgd_hue < 90) || (bkgd_sat < 100))
+ bkgd = 1; /* Teal blue */
+ else if (bkgd_hue >= 105)
+ bkgd = 2; /* Dark blue */
+ else
+ bkgd = 3; /* Normal blue */
+ }
+}
+
+static void resistor_dimensions_1 (void)
+{
+
+ proc_load_mem(3);
+
+ proc_dilate_erode(10);
+ proc_erode_dilate((rect.height * 0.67) / 2);
+ proc_contours(&contours, &hierarchy);
+ proc_bounding_rect(&contours[0], &rect, true);
+}
+
+static void resistor_crop_1 (void)
+{
+ int x;
+ int y;
+ int w;
+ int h;
+
+ proc_load_mem(2);
+
+ w = rect.width * 0.95;
+ h = rect.height * 0.8;
+ x = rect.x + w * (1.0 - 0.95) / 2.0;
+ y = rect.y + h * (1.0 - 0.8) / 2.0;
+ proc_ROI(x, y, w, h);
+ proc_save_mem(4);
+}
+
+static void separate_bkgd_bands_h (void)
+{
+
+ proc_load_mem(4);
+
+ proc_cmp(IMG_IFACE_CMP_HUE);
+ proc_median_vertical();
+ proc_save_mem(9);
+
+ switch (bkgd) {
+ case 0:
+ proc_threshold(cv::THRESH_TOZERO_INV, 20);
+ proc_threshold(cv::THRESH_TOZERO, 5);
+ break;
+ case 1:
+ proc_threshold(cv::THRESH_TOZERO_INV, 100);
+ proc_threshold(cv::THRESH_TOZERO, 70);
+ break;
+ case 2:
+ proc_threshold(cv::THRESH_TOZERO_INV, 115);
+ proc_threshold(cv::THRESH_TOZERO, 100);
+ break;
+ case 3:
+ proc_threshold(cv::THRESH_TOZERO_INV, 110);
+ proc_threshold(cv::THRESH_TOZERO, 90);
+ break;
+ }
+ proc_threshold(cv::THRESH_BINARY_INV, 1);
+ proc_save_mem(5);
+}
+
+static void separate_bkgd_bands_s (void)
+{
+
+ proc_load_mem(4);
+
+ proc_cmp(IMG_IFACE_CMP_SATURATION);
+ proc_median_vertical();
+ proc_save_mem(10);
+
+ switch (bkgd) {
+ case 0:
+ proc_threshold(cv::THRESH_TOZERO_INV, 160);
+ proc_threshold(cv::THRESH_TOZERO, 110);
+ break;
+ case 1:
+ proc_threshold(cv::THRESH_TOZERO_INV, 180);
+ proc_threshold(cv::THRESH_TOZERO, 30);
+ break;
+ case 2:
+ proc_threshold(cv::THRESH_TOZERO_INV, 190);
+ proc_threshold(cv::THRESH_TOZERO, 170);
+ break;
+ case 3:
+ proc_threshold(cv::THRESH_TOZERO_INV, 210);
+ proc_threshold(cv::THRESH_TOZERO, 120);
+ break;
+ }
+ proc_threshold(cv::THRESH_BINARY_INV, 1);
+ proc_save_mem(6);
+}
+
+static void separate_bkgd_bands_v (void)
+{
+
+ proc_load_mem(4);
+
+ proc_cmp(IMG_IFACE_CMP_VALUE);
+ proc_median_vertical();
+ proc_save_mem(11);
+
+ switch (bkgd) {
+ case 0:
+ proc_threshold(cv::THRESH_TOZERO_INV, 170);
+ proc_threshold(cv::THRESH_TOZERO, 100);
+ break;
+
+ case 1:
+ proc_threshold(cv::THRESH_TOZERO_INV, 180);
+ proc_threshold(cv::THRESH_TOZERO, 100);
+ break;
+ case 2:
+ proc_threshold(cv::THRESH_TOZERO_INV, 180);
+ proc_threshold(cv::THRESH_TOZERO, 150);
+ break;
+ case 3:
+ proc_threshold(cv::THRESH_TOZERO_INV, 190);
+ proc_threshold(cv::THRESH_TOZERO, 90);
+ break;
+ }
+ proc_threshold(cv::THRESH_BINARY_INV, 1);
+ proc_save_mem(7);
+}
+
+static void bkgd_find (void)
+{
+
+ /* Merge the components: H | S | V */
+ proc_load_mem(7);
+ proc_save_ref();
+ proc_load_mem(6);
+ proc_or_2ref();
+ proc_save_ref();
+ proc_load_mem(5);
+ proc_or_2ref();
+ if (rect.width * 0.95 > 80) {
+ proc_dilate_erode(1);
+ }
+ proc_save_mem(8);
+}
+
+static int bands_find (void)
+{
+
+ proc_load_mem(8);
+
+ proc_contours(&contours, &hierarchy);
+ bands_n = contours.size();
+ if (bands_n > 5) {
+ proc_load_mem(8);
+ proc_dilate_erode(1);
+ proc_contours(&contours, &hierarchy);
+ bands_n = contours.size();
+ }
+ if ((bands_n == 0) || (bands_n == 2) || (bands_n > 5))
+ return RESISTOR_NOK_BANDS;
+
+ /* Band 0 (hundreds) */
+ if (bands_n == 5) {
+ proc_bounding_rect(&contours[4], &rect, true);
+ bands[0].x = rect.x + rect.width / 2.0;
+ bands[0].y = rect.y + rect.height / 2.0;
+ }
+
+ /* Band 1 (tens) */
+ if (bands_n >= 3) {
+ if (bands_n > 3)
+ proc_bounding_rect(&contours[3], &rect, true);
+ else
+ proc_bounding_rect(&contours[2], &rect, true);
+ bands[1].x = rect.x + rect.width / 2.0;
+ bands[1].y = rect.y + rect.height / 2.0;
+ }
+
+ /* Band 2 (units) */
+ if (bands_n > 3)
+ proc_bounding_rect(&contours[2], &rect, true);
+ else if (bands_n == 3)
+ proc_bounding_rect(&contours[1], &rect, true);
+ else /* bands_n == 1 */
+ proc_bounding_rect(&contours[0], &rect, true);
+ bands[2].x = rect.x + rect.width / 2.0;
+ bands[2].y = rect.y + rect.height / 2.0;
+
+ /* Band 3 (multiplier) */
+ if (bands_n >= 3) {
+ if (bands_n > 3)
+ proc_bounding_rect(&contours[1], &rect, true);
+ else
+ proc_bounding_rect(&contours[0], &rect, true);
+ bands[3].x = rect.x + rect.width / 2.0;
+ bands[3].y = rect.y + rect.height / 2.0;
+ }
+
+ /* Band 4 (tolerance) */
+ if (bands_n > 3) {
+ proc_bounding_rect(&contours[0], &rect, true);
+ bands[4].x = rect.x + rect.width / 2.0;
+ bands[4].y = rect.y + rect.height / 2.0;
+ }
+
+ return 0;
+}
+
+static void bands_colors (void)
+{
+
+ /* Hue */
+ proc_load_mem(9);
+ if (bands_n == 5)
+ proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].h));
+ if (bands_n >= 3)
+ proc_pixel_get(bands[1].x, bands[1].y, &(bands[1].h));
+ proc_pixel_get(bands[2].x, bands[2].y, &(bands[2].h));
+ if (bands_n >= 3)
+ proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].h));
+ if (bands_n > 3)
+ proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].h));
+
+ /* Saturation */
+ proc_load_mem(10);
+ if (bands_n == 5)
+ proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].s));
+ if (bands_n >= 3)
+ proc_pixel_get(bands[1].x, bands[1].y, &(bands[1].s));
+ proc_pixel_get(bands[2].x, bands[2].y, &(bands[2].s));
+ if (bands_n >= 3)
+ proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].s));
+ if (bands_n > 3)
+ proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].s));
+
+ /* Value */
+ proc_load_mem(11);
+ if (bands_n == 5)
+ proc_pixel_get(bands[0].x, bands[0].y, &(bands[0].v));
+ if (bands_n >= 3)
+ proc_pixel_get(bands[1].x, bands[1].y, &(bands[1].v));
+ proc_pixel_get(bands[2].x, bands[2].y, &(bands[2].v));
+ if (bands_n >= 3)
+ proc_pixel_get(bands[3].x, bands[3].y, &(bands[3].v));
+ if (bands_n > 3)
+ proc_pixel_get(bands[4].x, bands[4].y, &(bands[4].v));
+}
+
+static void bands_code (void)
+{
+ char txt[LOG_LINE_LEN];
+
+ memset(code, 0, ARRAY_SIZE(code));
+
+ /* Band 0 (hundreds) */
+ if (bands_n == 5)
+ code[0] = band_hsv2code(&bands[0]);
+ else
+ code[0] = 'n';
+
+ /* Band 1 (tens) */
+ if (bands_n != 1)
+ code[1] = band_hsv2code(&bands[1]);
+ else
+ code[1] = 'n';
+
+ /* Band 2 (units) */
+ code[2] = band_hsv2code(&bands[2]);
+
+ /* Band 3 (multiplier) */
+ if (bands_n != 1)
+ code[3] = band_hsv2code(&bands[3]);
+ else
+ code[3] = 'n';
+
+ /* Band 4 (tolerance) */
+ if (bands_n > 3)
+ code[4] = band_hsv2code(&bands[4]);
+ else
+ code[4] = 'n';
+
+ snprintf(txt, LOG_LINE_LEN, "Code: \"%s\"", code);
+ user_iface_log_write(0, txt);
+}
+
+static char band_hsv2code (struct Resistor_Bands *band)
+{
+ char c;
+
+ /*
+ * Not able to segmentate:
+ * q = 1 2
+ * w = 2 3
+ * e = 3 g
+ * r = 3 4
+ * t = 1 8
+ * y = 0 1
+ * u = 0 1 8
+ */
+
+ if (band->h < 10) {
+ // 1 2 3
+ if (band->s < 90) {
+ // 1 3
+ if (band->v < 85)
+ c = '1';
+ else
+ c = '3';
+ } else if (band->s < 140) {
+ // 1 2 3
+ if (band->v < 60)
+ c = '1';
+ else if (band->v < 85)
+ c = 'q'; // 1 2
+ else if (band->v < 90)
+ c = '2';
+ else if (band->v < 150)
+ c = 'w'; // 2 3
+ else
+ c = '3';
+ } else if (band->s < 210) {
+ // 2 3
+ if (band->v < 90)
+ c = '2';
+ else if (band->v < 150)
+ c = 'w'; // 2 3
+ else
+ c = '3';
+ } else {
+ c = '3';
+ }
+ } else if (band->h < 35) {
+ // 1 3 g
+ if (band->s < 130) {
+ // 1 3
+ if (band->v < 85)
+ c = '1';
+ else
+ c = '3';
+ } else if (band->s < 140) {
+ // 1 3 g
+ if (band->v < 85)
+ c = '1';
+ else if (band->v < 120)
+ c = '3';
+ else
+ c = 'e'; // 3 g
+ } else if (band->s < 180) {
+ // 3 g
+ if (band->v < 120)
+ c = '3';
+ else
+ c = 'e'; // 3 g
+ } else {
+ c = '3';
+ }
+ } else if (band->h < 50) {
+ // 1 3
+ if (band->s < 140) {
+ // 1 3
+ if (band->v < 85)
+ c = '1';
+ else
+ c = '3';
+ } else {
+ c = '3';
+ }
+ } else if (band->h < 60) {
+ // 1 3 4
+ if (band->s < 140) {
+ // 1 3
+ if (band->v < 85)
+ c = '1';
+ else
+ c = '3';
+ } else if (band->s < 160) {
+ c = '3';
+ } else if (band->s < 180) {
+ // 3 4
+ if (band->v < 110)
+ c = 'r'; // 3 4
+ else
+ c = '3';
+ } else {
+ c = '3';
+ }
+ } else if (band->h < 80) {
+ // 1 5
+ if (band->s < 165)
+ c = '1';
+ else
+ c = '5';
+ } else if (band->h < 90) {
+ c = '1';
+ } else if (band->h < 100) {
+ // 0 1 8 9
+ if (band->s < 40) {
+ // 1 8 9
+ if (band->v < 55)
+ c = '1';
+ else if (band->v < 80)
+ c = 't'; // 1 8
+ else if (band->v < 125)
+ c = '1';
+ else
+ c = '9';
+ } else if (band->s < 70) {
+ // 0 1 8 9
+ if (band->v < 45)
+ c = '0';
+ else if (band->v < 55)
+ c = 'y'; // 0 1
+ else if (band->v < 75)
+ c = 'u'; // 0 1 8
+ else if (band->v < 80)
+ c = 't'; // 1 8
+ else if (band->v < 125)
+ c = '1';
+ else
+ c = '9';
+ } else if (band->s < 100) {
+ // 0 1 8
+ if (band->v < 45)
+ c = '0';
+ else if (band->v < 55)
+ c = 'y'; // 0 1
+ else if (band->v < 75)
+ c = 'u'; // 0 1 8
+ else if (band->v < 80)
+ c = 't'; // 1 8
+ else
+ c = '1';
+ } else if (band->s < 140) {
+ // 0 1
+ if (band->v < 45)
+ c = '0';
+ else if (band->v < 75)
+ c = 'y'; // 0 1
+ else
+ c = '1';
+ } else {
+ c = '0';
+ }
+ } else if (band->h < 110) {
+ // 0 1 6 8
+ if (band->s < 40) {
+ // 1 8
+ if (band->v < 55)
+ c = '1';
+ else if (band->v < 80)
+ c = 't'; // 1 8
+ else
+ c = '1';
+ } else if (band->s < 100) {
+ // 0 1 8
+ if (band->v < 45)
+ c = '0';
+ else if (band->v < 55)
+ c = 'y'; // 0 1
+ else if (band->v < 75)
+ c = 'u'; // 0 1 8
+ else if (band->v < 80)
+ c = 't'; // 1 8
+ else
+ c = '1';
+ } else if (band->s < 140) {
+ // 0 1
+ if (band->v < 45)
+ c = '0';
+ else if (band->v < 75)
+ c = 'y'; // 0 1
+ else
+ c = '1';
+ } else if (band->s < 200) {
+ c = '0';
+ } else {
+ c = '6';
+ }
+ } else if (band->h < 120) {
+ // 0 1 6 7
+ if (band->s < 40) {
+ c = '1';
+ } else if (band->s < 90) {
+ // 0 1
+ if (band->v < 45)
+ c = '0';
+ else if (band->v < 75)
+ c = 'y'; // 0 1
+ else
+ c = '1';
+ } else if (band->s < 110) {
+ // 0 1 7
+ if (band->v < 45)
+ c = '0';
+ else if (band->v < 75)
+ c = 'y'; // 0 1
+ else if (band->v < 120)
+ c = '1';
+ else
+ c = '7';
+ } else if (band->s < 140) {
+ // 0 1
+ if (band->v < 45)
+ c = '0';
+ else if (band->v < 75)
+ c = 'y'; // 0 1
+ else
+ c = '1';
+ } else if (band->s < 200) {
+ c = '0';
+ } else {
+ c = '6';
+ }
+ } else if (band->h < 130) {
+ // 0 1 7
+ if (band->s < 40) {
+ c = '1';
+ } else if (band->s < 90) {
+ // 0 1
+ if (band->v < 45)
+ c = '0';
+ else if (band->v < 75)
+ c = 'y'; // 0 1
+ else
+ c = '1';
+ } else if (band->s < 110) {
+ // 0 1 7
+ if (band->v < 45)
+ c = '0';
+ else if (band->v < 75)
+ c = 'y'; // 0 1
+ else if (band->v < 120)
+ c = '1';
+ else
+ c = '7';
+ } else if (band->s < 140) {
+ // 0 1
+ if (band->v < 45)
+ c = '0';
+ else if (band->v < 75)
+ c = 'y'; // 0 1
+ else
+ c = '1';
+ } else {
+ c = '0';
+ }
+ } else if (band->h < 140) {
+ // 0 1
+ if (band->s < 40) {
+ c = '1';
+ } else if (band->s < 140) {
+ // 0 1
+ if (band->v < 45)
+ c = '0';
+ else if (band->v < 75)
+ c = 'y'; // 0 1
+ else
+ c = '1';
+ } else {
+ c = '0';
+ }
+ } else if (band->h < 150) {
+ c = '0';
+ } else {
+ c = '2';
+ }
+
+ return c;
+}
+
+static void bands_code_deduce_0 (void)
+{
+ char txt[LOG_LINE_LEN];
+
+ /*
+ * Not able to segmentate:
+ * q = 1 2
+ * w = 2 3
+ * e = 3 g
+ * r = 3 4
+ * t = 1 8
+ * y = 0 1
+ * u = 0 1 8
+ */
+
+ /* Band 0 (hundreds) */
+ switch (code[0]) {
+ case 'e':
+ code[0] = '3';
+ break;
+ case 'y':
+ code[0] = '1';
+ break;
+ case 'u':
+ code[0] = 't';
+ break;
+ }
+
+ /* Band 2 (units) */
+ switch (code[2]) {
+ case 'e':
+ code[2] = '3';
+ break;
+ }
+
+ /* Band 3 (multiplier) */
+ switch (code[3]) {
+ case 't':
+ code[3] = '1';
+ break;
+ case 'u':
+ code[3] = 'y';
+ break;
+ }
+
+ /* Band 4 (tolerance) */
+ switch (code[4]) {
+ case 'w':
+ code[4] = '2';
+ break;
+ case 'e':
+ code[4] = 'g';
+ break;
+ case 't':
+ code[4] = '1';
+ break;
+ case 'y':
+ code[4] = '1';
+ break;
+ case 'u':
+ code[4] = '1';
+ break;
+ }
+
+ snprintf(txt, LOG_LINE_LEN, "Code: \"%s\"", code);
+ user_iface_log_write(0, txt);
+}
+
+static void bands_code_deduce_1 (void)
+{
+ char txt[LOG_LINE_LEN];
+
+ /*
+ * Not able to segmentate:
+ * q = 1 2
+ * w = 2 3
+ * e = 3 g
+ * r = 3 4
+ * t = 1 8
+ * y = 0 1
+ * u = 0 1 8
+ */
+
+ /* Band 0 (hundreds) */
+ switch (code[0]) {
+ case 'q':
+ switch (code[1]) {
+ case '1':
+ case '3':
+ case '5':
+ case '6':
+ case '8':
+ code[0] = '1';
+ break;
+ case '2':
+ case '4':
+ case '7':
+ code[0] = '2';
+ break;
+ case '0':
+ // q
+ break;
+ }
+ break;
+ case 'w':
+ switch (code[1]) {
+ case '2':
+ case '4':
+ case '7':
+ code[0] = '2';
+ break;
+ case '3':
+ case '6':
+ case '9':
+ code[0] = '3';
+ break;
+ case '0':
+ // w
+ break;
+ }
+ break;
+ case 'r':
+ switch (code[1]) {
+ case '0':
+ case '6':
+ case '9':
+ code[0] = '3';
+ break;
+ case '7':
+ code[0] = '4';
+ break;
+ case '3':
+ // r
+ break;
+ }
+ break;
+ case 't':
+ switch (code[1]) {
+ case '0':
+ case '1':
+ case '3':
+ case '5':
+ case '6':
+ case '8':
+ code[0] = '1';
+ break;
+ case '2':
+ // t
+ break;
+ }
+ break;
+ }
+
+ /* Band 1 (tens) */
+ switch (code[1]) {
+ case 'q':
+ switch (code[0]) {
+ case '5':
+ case '9':
+ code[1] = '1';
+ break;
+ case '2':
+ case '6':
+ case '8':
+ code[1] = '2';
+ break;
+ case '1':
+ // q
+ break;
+ }
+ break;
+ case 'w':
+ switch (code[0]) {
+ case '2':
+ case '6':
+ case '8':
+ code[1] = '2';
+ break;
+ case '3':
+ case '4':
+ code[1] = '3';
+ break;
+ case '1':
+ // w
+ break;
+ }
+ break;
+ case 't':
+ switch (code[0]) {
+ case '5':
+ case '9':
+ code[1] = '1';
+ break;
+ case '6':
+ code[1] = '8';
+ break;
+ case '1':
+ // t
+ break;
+ }
+ break;
+ case 'y':
+ switch (code[0]) {
+ case '2':
+ case '3':
+ code[1] = '0';
+ break;
+ case '5':
+ case '9':
+ code[1] = '1';
+ break;
+ case '1':
+ // y
+ break;
+ }
+ break;
+ case 'u':
+ switch (code[0]) {
+ case '2':
+ case '3':
+ code[1] = '0';
+ break;
+ case '5':
+ case '9':
+ code[1] = '1';
+ break;
+ case '6':
+ code[1] = '8';
+ break;
+ case '1':
+ // u
+ break;
+ }
+ break;
+ }
+
+ /* Band 2 (units) */
+ switch (code[2]) {
+ case 'y':
+ code[2] = '0';
+ break;
+ case 'u':
+ code[2] = '0';
+ break;
+ }
+
+ /* Band 3 (multiplier) */
+ switch (code[3]) {
+ case 'y':
+ code[3] = '0';
+ break;
+ }
+
+ /* Band 4 (tolerance) */
+ switch (code[4]) {
+ case 'q':
+ code[4] = '2';
+ break;
+ }
+
+ snprintf(txt, LOG_LINE_LEN, "Code: \"%s\"", code);
+ user_iface_log_write(0, txt);
+}
+
+static int bands_code_deduce_no (void)
+{
+ char txt[LOG_LINE_LEN];
+
+ /*
+ * Not able to segmentate:
+ * q = 1 2
+ * w = 2 3
+ * e = 3 g
+ * r = 3 4
+ * t = 1 8
+ * y = 0 1
+ * u = 0 1 8
+ */
+
+ for (ptrdiff_t i = 0; i < 5; i++) {
+ switch (code[i]) {
+ case 'q':
+ case 'w':
+ case 'e':
+ case 'r':
+ case 't':
+ case 'y':
+ case 'u':
+ code[i] = '?';
+ }
+ }
+
+ for (ptrdiff_t i = 0; i < 5; i++) {
+ if (code[i] == '?')
+ return RESISTOR_NOK_COLOR;
+ }
+
+ snprintf(txt, LOG_LINE_LEN, "Code: \"%s\"", code);
+ user_iface_log_write(0, txt);
+
+ return 0;
+}
+
+static void resistor_value (void)
+{
+ int power;
+
+ /* Base value */
+ base = code[2] - '0';
+ if (code[1] != 'n')
+ base += (code[1] - '0') * 10;
+ if (code[0] != 'n')
+ base += (code[0] - '0') * 100;
+
+ /* Calculate resistance */
+ if ((code[3] > '0') && (code[3] < '9'))
+ power = code[3] - '0';
+ else if (code[3] == 'g')
+ power = -1;
+ else if (code[3] == 's')
+ power = -2;
+ else
+ return;
+
+ resistance = base * pow(10, power);
+}
+
+static int resistor_tolerance (void)
+{
+
+ if (bands_n != 1) {
+ switch (code[4]) {
+ case '1':
+ tolerance = 1;
+ break;
+ case '2':
+ tolerance = 2;
+ break;
+ case '4':
+ case 'g':
+ case 'n':
+ tolerance = 5;
+ break;
+ case '8':
+ tolerance = 10;
+ break;
+ default:
+ return RESISTOR_NOK_TOLERANCE;
+ }
+ }
+
+ return 0;
+}
+
+static void log_resistance (void)
+{
+ char txt[LOG_LINE_LEN];
+
+ if (bands_n != 1) {
+ snprintf(txt, LOG_LINE_LEN,"Resistance: %.2E ± %i%% Ohm",
+ resistance, tolerance);
+ user_iface_log_write(0, txt);
+ } else {
+ user_iface_log_write(0, "Resistance: 0 Ohm");
+ }
+}
+
+static int chk_std_value (void)
+{
+ /* Check that base value is a standard value */
+ int std_values_10 [12] = {10,12,15,18,22,27,33,39,47,56,68,82};
+ int std_values_5 [12] = {11,13,16,20,24,30,36,43,51,62,75,91};
+
+ if (bands_n == 1) {
+ if (base)
+ return RESISTOR_NOK_STD_VALUE;
+ return 0;
+ }
+
+ for (ptrdiff_t i = 0; i < 12; i++) {
+ if (base == std_values_10[i])
+ return 0;
+ if (base == (std_values_10[i] * 10))
+ return 0;
+ }
+ if (tolerance <= 5) {
+ for (ptrdiff_t i = 0; i < 12; i++) {
+ if (base == std_values_5[i])
+ return 0;
+ if (base == (std_values_5[i] * 10))
+ return 0;
+ }
+ }
+
+ return RESISTOR_NOK_STD_VALUE;
+}
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/src/save/save.cpp b/src/save/save.cpp
new file mode 100644
index 0000000..cbe039d
--- /dev/null
+++ b/src/save/save.cpp
@@ -0,0 +1,280 @@
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+#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];
+
+
+/******************************************************************************
+ ******* static functions (prototypes) ****************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* global functions *****************************************************
+ ******************************************************************************/
+void save_init (void)
+{
+
+ if (snprintf(home_path, FILENAME_MAX, "%s/",
+ getenv(ENV_HOME)) >= FILENAME_MAX) {
+ goto err;
+ }
+ if (snprintf(user_prog_path, FILENAME_MAX, "%s/%s/",
+ home_path,
+ USER_PROG_DIR) >= FILENAME_MAX) {
+ goto err;
+ }
+ if (snprintf(saved_path, FILENAME_MAX, "%s/%s/",
+ home_path,
+ USER_SAVED_DIR) >= FILENAME_MAX) {
+ goto err;
+ }
+ if (snprintf(labels_path, FILENAME_MAX, "%s/%s/",
+ home_path,
+ USER_LABELS_DIR) >= FILENAME_MAX) {
+ goto err;
+ }
+ if (snprintf(labels_fail_path, FILENAME_MAX, "%s/%s/",
+ home_path,
+ USER_LABELS_FAIL_DIR) >= FILENAME_MAX) {
+ goto err;
+ }
+ if (snprintf(lighters_path, FILENAME_MAX, "%s/%s/",
+ home_path,
+ USER_LIGHTERS_DIR) >= FILENAME_MAX) {
+ goto err;
+ }
+ if (snprintf(lighters_fail_path, FILENAME_MAX, "%s/%s/",
+ home_path,
+ USER_LIGHTERS_FAIL_DIR) >= FILENAME_MAX) {
+ goto err;
+ }
+ if (snprintf(objects_path, FILENAME_MAX, "%s/%s/",
+ home_path,
+ USER_OBJECTS_DIR) >= FILENAME_MAX) {
+ goto err;
+ }
+ if (snprintf(objects_fail_path, FILENAME_MAX, "%s/%s/",
+ home_path,
+ USER_OBJECTS_FAIL_DIR) >= FILENAME_MAX) {
+ goto err;
+ }
+ if (snprintf(coins_path, FILENAME_MAX, "%s/%s/",
+ home_path,
+ USER_COINS_DIR) >= FILENAME_MAX) {
+ goto err;
+ }
+ if (snprintf(coins_fail_path, FILENAME_MAX, "%s/%s/",
+ home_path,
+ USER_COINS_FAIL_DIR) >= FILENAME_MAX) {
+ goto err;
+ }
+ if (snprintf(resistors_path, FILENAME_MAX, "%s/%s/",
+ home_path,
+ USER_RESISTORS_DIR) >= FILENAME_MAX) {
+ goto err;
+ }
+ if (snprintf(resistors_fail_path, FILENAME_MAX, "%s/%s/",
+ home_path,
+ USER_RESISTORS_FAIL_DIR) >= FILENAME_MAX) {
+ goto err;
+ }
+ saved_name[0] = '\0';
+
+ if (mkdir(user_prog_path, 0700)) {
+ switch (errno) {
+ case EEXIST:
+ /* OK */
+ break;
+ default:
+ printf("%s: %s\n", errno_str[errno][0],
+ errno_str[errno][1]);
+ }
+ }
+
+ mkdir(saved_path, 0700);
+ mkdir(labels_path, 0700);
+ mkdir(labels_fail_path, 0700);
+
+ return;
+err:
+ printf("Path is too large and has been truncated\n");
+}
+
+void save_reset_fpath(void)
+{
+
+ if (snprintf(saved_path, FILENAME_MAX, "%s/%s/",
+ home_path,
+ USER_SAVED_DIR) >= FILENAME_MAX) {
+ goto err;
+ }
+
+ return;
+err:
+ printf("Path is too large and has been truncated\n");
+}
+
+void load_image_file (const char *restrict fpath,
+ const char *restrict fname)
+{
+ char file_path[FILENAME_MAX];
+ char file_name[FILENAME_MAX];
+
+ image.release();
+
+ /* Set file_path */
+ if (!fpath) {
+ /* Default path */
+ save_reset_fpath();
+ snprintf(file_path, FILENAME_MAX, "%s", saved_path);
+ } else {
+ snprintf(file_path, FILENAME_MAX, "%s", fpath);
+ }
+
+ /* Set file_name */
+ if (!fname)
+ user_iface_fname(file_path, saved_name);
+ else
+ snprintf(saved_name, FILENAME_MAX, "%s", fname);
+
+ /* File name */
+ if (snprintf(file_name, FILENAME_MAX, "%s/%s",
+ file_path,
+ saved_name) >= FILENAME_MAX) {
+ goto err_path;
+ }
+
+ image = cv::imread(file_name, CV_LOAD_IMAGE_COLOR);
+ 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");
+}
+
+void save_cleanup (void)
+{
+
+ image.release();
+}
+
+void save_image_file (const char *restrict fpath,
+ const char *restrict save_as)
+{
+ char file_path[FILENAME_MAX];
+ char file_name[FILENAME_MAX];
+ FILE *fp;
+
+ /* Set file_path */
+ if (!fpath) {
+ /* Default path */
+ save_reset_fpath();
+ snprintf(file_path, FILENAME_MAX, "%s", saved_path);
+ } else {
+ snprintf(file_path, FILENAME_MAX, "%s", fpath);
+ }
+
+ /* Set file_name */
+ if (!save_as) {
+ snprintf(saved_name, FILENAME_MAX, "%s", SAVED_NAME_DEFAULT);
+ user_iface_fname(saved_path, saved_name);
+ } else {
+ snprintf(saved_name, FILENAME_MAX, "%s", save_as);
+ }
+
+ /* Prepend the path */
+ if (snprintf(file_name, FILENAME_MAX, "%s/%s",
+ file_path,
+ saved_name) >= FILENAME_MAX) {
+ goto err_path;
+ }
+
+ fp = fopen(file_name, "r");
+ if (fp) {
+ /* Name in use; ask once more */
+ fclose(fp);
+ user_iface_fname(saved_path, saved_name);
+ if (snprintf(file_name, FILENAME_MAX, "%s/%s",
+ file_path,
+ saved_name) >= FILENAME_MAX) {
+ goto err_path;
+ }
+ }
+
+ user_iface_log_write(2, saved_name);
+
+ cv::imwrite(file_name, image);
+
+ return;
+err_path:
+ printf("Path is too large and has been truncated\n");
+}
+
+
+/******************************************************************************
+ ******* static functions (definitions) ***************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/src/user/clui.c b/src/user/clui.c
new file mode 100644
index 0000000..8c3c7ec
--- /dev/null
+++ b/src/user/clui.c
@@ -0,0 +1,471 @@
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+#include "vision-artificial/user/clui.h"
+
+#include <stdio.h>
+#include <string.h>
+
+#include "libalx/base/stddef/size.h"
+#include "libalx/base/stdio/get.h"
+#include "libalx/base/stdio/wait.h"
+
+#include "vision-artificial/image/iface.h"
+#include "vision-artificial/user/iface.h"
+
+
+/******************************************************************************
+ ******* macros ***************************************************************
+ ******************************************************************************/
+#define BUFF_SIZE (0xFFF)
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* structs / unions *****************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+/* Global --------------------------------------------------------------------*/
+/* Static --------------------------------------------------------------------*/
+
+
+/******************************************************************************
+ ******* static functions (prototypes) ****************************************
+ ******************************************************************************/
+static void log_loop (void);
+static int usr_input (void);
+static void show_help (void);
+
+
+/******************************************************************************
+ ******* global functions *****************************************************
+ ******************************************************************************/
+int user_clui (const char *restrict title,
+ const char *restrict subtitle)
+{
+
+ show_help();
+ user_clui_show_log(title, subtitle);
+ return usr_input();
+}
+
+void user_clui_fname (const char *restrict fpath,
+ char *restrict fname)
+{
+
+ 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 *restrict title,
+ const char *restrict subtitle)
+{
+
+ printf("________________________________________________________________________________\n");
+ log_loop();
+ printf("%s - %s\n", subtitle, title);
+ printf("--------------------------------------------------------------------------------\n");
+
+}
+
+void user_clui_show_ocr (void)
+{
+
+ printf("%s", img_ocr_text);
+ alx_wait4enter();
+}
+
+
+/******************************************************************************
+ ******* static functions (definitions) ***************************************
+ ******************************************************************************/
+static void log_loop (void)
+{
+ const char *txt;
+
+ putchar('\n');
+ 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);
+ }
+ printf("\n");
+}
+
+static int usr_input (void)
+{
+ char buff[BUFF_SIZE];
+ char ch [10];
+
+ memset(ch, 0, ARRAY_SIZE(ch));
+ buff[0] = '\0';
+
+ if (!fgets(buff, BUFF_SIZE, stdin))
+ goto err_fgets;
+ if (sscanf(buff, " %5c", ch) <= 0)
+ goto err_sscanf;
+
+ switch (ch[0]) {
+ case '+':
+ return USER_IFACE_ACT_APPLY;
+ case '-':
+ return USER_IFACE_ACT_DISCARD;
+ case 'e':
+ /* Exercises from class */
+ switch (ch[1]) {
+ case '1':
+ /* Label */
+ switch (ch[2]) {
+ case '1':
+ return USER_IFACE_ACT_PROC_LABEL_SERIES;
+ }
+ break;
+ case '2':
+ /* Objects */
+ switch (ch[2]) {
+ case '0':
+ return USER_IFACE_ACT_PROC_OBJECTS_CALIB;
+ case '1':
+ return USER_IFACE_ACT_PROC_OBJECTS_SERIES;
+ }
+ break;
+ case '3':
+ /* Coins */
+ switch (ch[2]) {
+ case '1':
+ return USER_IFACE_ACT_PROC_COINS_SERIES;
+ }
+ break;
+ case '4':
+ /* Resistor */
+ switch (ch[2]) {
+ case '1':
+ return USER_IFACE_ACT_PROC_RESISTOR_SERIES;
+ }
+ break;
+ case '5':
+ /* Lighters */
+ switch (ch[2]) {
+ case '1':
+ return USER_IFACE_ACT_PROC_LIGHTERS_SERIES;
+ }
+ break;
+ }
+ break;
+
+ case 'f':
+ /* Use simple funtions */
+ switch (ch[1]) {
+ case '0':
+ /* img_alx */
+ switch (ch[2]) {
+ case '0':
+ /* Distance transform postprocessing */
+ switch (ch[3]) {
+ case '0':
+ return USER_IFACE_ACT_LOCAL_MAX;
+ case '1':
+ return USER_IFACE_ACT_SKELETON;
+ }
+ break;
+ case '1':
+ /* Lines */
+ switch (ch[3]) {
+ case '0':
+ return USER_IFACE_ACT_LINES_HORIZONTAL;
+ case '1':
+ return USER_IFACE_ACT_LINES_VERTICAL;
+ }
+ break;
+ case '2':
+ /* Smooth */
+ switch (ch[3]) {
+ case '0':
+ return USER_IFACE_ACT_MEAN_HORIZONTAL;
+ case '1':
+ return USER_IFACE_ACT_MEAN_VERTICAL;
+ case '2':
+ return USER_IFACE_ACT_MEDIAN_HORIZONTAL;
+ case '3':
+ return USER_IFACE_ACT_MEDIAN_VERTICAL;
+ }
+ break;
+ }
+ break;
+ case '1':
+ /* img_cv */
+ switch (ch[2]) {
+ case '0':
+ /* Core: The core functionality */
+ switch (ch[3]) {
+ case '0':
+ /* Pixel */
+ switch (ch[4]) {
+ case '0':
+ return USER_IFACE_ACT_PIXEL_GET;
+ case '1':
+ return USER_IFACE_ACT_PIXEL_SET;
+ }
+ break;
+ case '1':
+ /* ROI */
+ switch (ch[4]) {
+ case '0':
+ return USER_IFACE_ACT_SET_ROI;
+ case '1':
+ return USER_IFACE_ACT_SET_ROI_2RECT;
+ }
+ break;
+ case '2':
+ /* Operations on Arrays */
+ switch (ch[4]) {
+ case '0':
+ return USER_IFACE_ACT_AND_2REF;
+ case '1':
+ return USER_IFACE_ACT_NOT;
+ case '2':
+ return USER_IFACE_ACT_OR_2REF;
+ case '3':
+ return USER_IFACE_ACT_COMPONENT;
+ }
+ break;
+ }
+ break;
+ case '1':
+ /* Imgproc: Image processing */
+ switch (ch[3]) {
+ case '0':
+ /* Image filtering */
+ switch (ch[4]) {
+ case '0':
+ return USER_IFACE_ACT_DILATE;
+ case '1':
+ return USER_IFACE_ACT_ERODE;
+ case '2':
+ return USER_IFACE_ACT_DILATE_ERODE;
+ case '3':
+ return USER_IFACE_ACT_ERODE_DILATE;
+ case '4':
+ return USER_IFACE_ACT_SMOOTH;
+ case '5':
+ return USER_IFACE_ACT_SOBEL;
+ case '6':
+ return USER_IFACE_ACT_BORDER;
+ }
+ break;
+ case '1':
+ /* Geometric image transformations */
+ switch (ch[4]) {
+ case '0':
+ return USER_IFACE_ACT_MIRROR;
+ case '1':
+ return USER_IFACE_ACT_ROTATE_ORTO;
+ case '2':
+ return USER_IFACE_ACT_ROTATE;
+ case '3':
+ return USER_IFACE_ACT_ROTATE_2RECT;
+ }
+ break;
+ case '2':
+ /* Miscellaneous image transformations */
+ switch (ch[4]) {
+ case '0':
+ return USER_IFACE_ACT_ADAPTIVE_THRESHOLD;
+ case '1':
+ return USER_IFACE_ACT_CVT_COLOR;
+ case '2':
+ return USER_IFACE_ACT_DISTANCE_TRANSFORM;
+ case '3':
+ return USER_IFACE_ACT_THRESHOLD;
+ }
+ break;
+ case '3':
+ /* Histograms */
+ switch (ch[4]) {
+ case '0':
+ return USER_IFACE_ACT_HISTOGRAM;
+ case '1':
+ return USER_IFACE_ACT_HISTOGRAM_C3;
+ }
+ break;
+ case '4':
+ /* Structural analysis and shape descriptors */
+ switch (ch[4]) {
+ case '0':
+ return USER_IFACE_ACT_CONTOURS;
+ case '1':
+ return USER_IFACE_ACT_CONTOURS_SIZE;
+ case '2':
+ return USER_IFACE_ACT_BOUNDING_RECT;
+ case '3':
+ return USER_IFACE_ACT_FIT_ELLIPSE;
+ case '4':
+ return USER_IFACE_ACT_MIN_AREA_RECT;
+ }
+ break;
+ case '5':
+ /* Feature detection */
+ switch (ch[4]) {
+ case '0':
+ return USER_IFACE_ACT_HOUGH_CIRCLES;
+ }
+ break;
+ }
+ break;
+ }
+ break;
+ case '2':
+ /* img_orb */
+ switch (ch[2]) {
+ case '0':
+ return USER_IFACE_ACT_ALIGN;
+ }
+ break;
+ case '3':
+ /* img_calib3d */
+ switch (ch[2]) {
+ case '0':
+ return USER_IFACE_ACT_CALIBRATE;
+ case '1':
+ return USER_IFACE_ACT_UNDISTORT;
+ }
+ break;
+ case '4':
+ /* img_zbar */
+ switch (ch[2]) {
+ case '0':
+ return USER_IFACE_ACT_DECODE;
+ }
+ break;
+ case '5':
+ /* img_ocr */
+ switch (ch[2]) {
+ case '0':
+ return USER_IFACE_ACT_READ;
+ }
+ break;
+ }
+ break;
+ case 'l':
+ return USER_IFACE_ACT_LOAD_MEM;
+ case 'm':
+ return USER_IFACE_ACT_SAVE_MEM;
+ case 'q':
+ return USER_IFACE_ACT_QUIT;
+ case 'r':
+ return USER_IFACE_ACT_SAVE_REF;
+ case 's':
+ return USER_IFACE_ACT_SAVE_FILE;
+ case 'u':
+ /* User iface actions */
+ switch (ch[1]) {
+ case '1':
+ 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') {
+ return USER_IFACE_ACT_FOO;
+ }
+ }
+ }
+ }
+ break;
+ }
+
+err_fgets:
+err_sscanf:
+ return USER_IFACE_ACT_FOO;
+}
+
+static void show_help (void)
+{
+
+ printf("Apply: %s\n", "Space");
+ printf("Discard: %s\n", "Backspace");
+ printf("Save to mem: %c\n", 'm');
+ printf("Load from mem: %c\n", 'l');
+ printf("Save to ref: %c\n", 'r');
+ printf("Save to file: %c\n", 's');
+ printf("Functions:\n");
+ printf(" - Local maxima: %s\n", "f000");
+ printf(" - Skeleton: %s\n", "f001");
+ printf(" - Horizontal lines: %s\n", "f010");
+ printf(" - Vertical lines: %s\n", "f011");
+ printf(" - Horizontal mean: %s\n", "f020");
+ printf(" - Vertical mean: %s\n", "f021");
+ printf(" - Horizontal median: %s\n", "f022");
+ printf(" - Vertical median: %s\n", "f023");
+ printf(" - Pixel get: %s\n", "f1000");
+ printf(" - Pixel set: %s\n", "f1001");
+ printf(" - Set ROI: %s\n", "f1010");
+ printf(" - Set ROI 2rect: %s\n", "f1011");
+ printf(" - Bitwise AND 2ref: %s\n", "f1020");
+ printf(" - Bitwise NOT: %s\n", "f1021");
+ printf(" - Bitwise OR 2ref: %s\n", "f1022");
+ printf(" - Component: %s\n", "f1023");
+ printf(" - Dilate: %s\n", "f1100");
+ printf(" - Erode: %s\n", "f1101");
+ printf(" - D-E: %s\n", "f1102");
+ printf(" - E-D: %s\n", "f1103");
+ printf(" - Smooth: %s\n", "f1104");
+ printf(" - Sobel: %s\n", "f1105");
+ printf(" - Border: %s\n", "f1106");
+ printf(" - Mirror: %s\n", "f1110");
+ printf(" - Rotate ortogonally: %s\n", "f1111");
+ printf(" - Rotate: %s\n", "f1112");
+ printf(" - Rotate 2rect_rot: %s\n", "f1113");
+ printf(" - Adaptive threshold: %s\n", "f1120");
+ printf(" - Cvt color: %s\n", "f1121");
+ printf(" - Distance transform: %s\n", "f1122");
+ printf(" - Threshold: %s\n", "f1123");
+ printf(" - Histogram: %s\n", "f1130");
+ printf(" - Histogram (3 chan): %s\n", "f1131");
+ printf(" - Contours: %s\n", "f1140");
+ printf(" - Contours size: %s\n", "f1141");
+ printf(" - Bounding rectangle: %s\n", "f1142");
+ printf(" - Fit ellipse: %s\n", "f1143");
+ printf(" - Min. area rectangle: %s\n", "f1144");
+ printf(" - Hough circles: %s\n", "f1150");
+ printf(" - Align 2ref (ORB): %s\n", "f20");
+ printf(" - Calibrate (Calib3d): %s\n", "f30");
+ printf(" - Undistort (Calib3d): %s\n", "f31");
+ printf(" - Scan codes (ZBAR): %s\n", "f40");
+ printf(" - Scan text (OCR): %s\n", "f50");
+ printf("Exercises:\n");
+ printf(" - Label: %s\n", "e11");
+ printf(" - Objects (calib): %s\n", "e20");
+ printf(" - Objects: %s\n", "e21");
+ printf(" - Coins: %s\n", "e31");
+ printf(" - Resistor: %s\n", "e41");
+ printf(" - Lighters: %s\n", "e51");
+ printf("Other:\n");
+ printf(" - Show OCR text: %s\n", "u1");
+ printf("Quit: %c\n", 'q');
+}
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/modules/user/src/user_iface.c b/src/user/iface.c
index d196097..75da415 100644
--- a/modules/user/src/user_iface.c
+++ b/src/user/iface.c
@@ -1,218 +1,234 @@
-/******************************************************************************
- * Copyright (C) 2018 Alejandro Colomar Andrés *
- ******************************************************************************/
-
-
-/******************************************************************************
- ******* headers **************************************************************
- ******************************************************************************/
-/* Standard C ----------------------------------------------------------------*/
- /* intX_t */
- #include <stdint.h>
- /* snprintf() & fflush() */
- #include <stdio.h>
-
-/* Project -------------------------------------------------------------------*/
- /* img_iface_act_nodata() */
- #include "img_iface.h"
- /* proc_iface() */
- #include "proc_iface.h"
-
-/* Module --------------------------------------------------------------------*/
- /* user_clui() & ...save_name() */
- #include "user_clui.h"
- /* user_tui() & ...init() & ...cleanup() & ...save_name() */
- #include "user_tui.h"
-
- #include "user_iface.h"
-
-
-/******************************************************************************
- ******* macros ***************************************************************
- ******************************************************************************/
- # define TITLE_SIZE (20)
-
-
-/******************************************************************************
- ******* variables ************************************************************
- ******************************************************************************/
-int user_iface_mode;
-struct User_Iface_Log user_iface_log;
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-void user_iface_act (int action);
-void user_iface_show_ocr (void);
-
-
-/******************************************************************************
- ******* main *****************************************************************
- ******************************************************************************/
-void user_iface_init (void)
-{
- user_iface_log.len = 0;
-
- switch (user_iface_mode) {
- case USER_IFACE_CLUI:
- user_clui_init();
- break;
-
- case USER_IFACE_TUI:
- user_tui_init();
- break;
- }
-}
-
-void user_iface_cleanup (void)
-{
- switch (user_iface_mode) {
- case USER_IFACE_CLUI:
- break;
-
- case USER_IFACE_TUI:
- user_tui_cleanup();
- break;
- }
-
- fflush(stdout);
-}
-
-void user_iface (void)
-{
- char title[TITLE_SIZE];
- char subtitle[TITLE_SIZE];
- int user_action;
-
- snprintf(title, TITLE_SIZE, "Title");
- snprintf(subtitle, TITLE_SIZE, "Subtitle");
-
- do {
- /* Display image */
- img_iface_show_img();
-
- /* Request user action */
- switch (user_iface_mode) {
- case USER_IFACE_CLUI:
- user_action = user_clui(title, subtitle);
- break;
-
- case USER_IFACE_TUI:
- user_action = user_tui(title, subtitle);
- break;
- }
-
- /* Do action */
- switch (user_action & 0xF000) {
- case USER_IFACE_ACT_PROC:
- proc_iface_single(user_action);
- break;
- default:
- user_iface_act(user_action);
- break;
- }
- } while (user_action != USER_IFACE_ACT_QUIT);
-}
-
-void user_iface_show_log (const char *title, const char *subtitle)
-{
- switch (user_iface_mode) {
- case USER_IFACE_CLUI:
- user_clui_show_log(title, subtitle);
- break;
-
- case USER_IFACE_TUI:
- user_tui_show_log(title, subtitle);
- break;
- }
-}
-
-void user_iface_fname (const char *filepath, char *filename)
-{
- switch (user_iface_mode) {
- case USER_IFACE_CLUI:
- user_clui_fname(filepath, filename);
- break;
-
- case USER_IFACE_TUI:
- user_tui_fname(filepath, filename);
- break;
- }
-}
-
-int64_t user_iface_getint (double m, int64_t def, double M,
- const char *title, const char *help)
-{
- int64_t i;
-
- switch (user_iface_mode) {
- case USER_IFACE_CLUI:
- // FIXME
- i = 1;
- break;
-
- case USER_IFACE_TUI:
- i = user_tui_getint(m, def, M, title, help);
- break;
- }
-
- return i;
-}
-
-double user_iface_getdbl (double m, double def, double M,
- const char *title, const char *help)
-{
- int64_t i;
-
- switch (user_iface_mode) {
- case USER_IFACE_CLUI:
- // FIXME
- i = 1;
- break;
-
- case USER_IFACE_TUI:
- i = user_tui_getdbl(m, def, M, title, help);
- break;
- }
-
- return i;
-}
-
-
-/******************************************************************************
- ******* static functions *****************************************************
- ******************************************************************************/
-void user_iface_act (int action)
-{
- if (action & USER_IFACE_ACT_USRI) {
- switch (action) {
- case USER_IFACE_ACT_SHOW_OCR:
- user_iface_show_ocr();
- break;
- case USER_IFACE_ACT_QUIT:
- /* do nothing */
- break;
- }
- } else {
- img_iface_act_nodata(action);
- }
-}
-
-void user_iface_show_ocr (void)
-{
- switch (user_iface_mode) {
- case USER_IFACE_CLUI:
- // FIXME
- break;
-
- case USER_IFACE_TUI:
- user_tui_show_ocr();
- break;
- }
-}
-
-
-/******************************************************************************
- ******* end of file **********************************************************
- ******************************************************************************/
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+#include "vision-artificial/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 (80)
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* structs / unions *****************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+/* Global --------------------------------------------------------------------*/
+ int user_iface_mode;
+ struct User_Iface_Log user_iface_log;
+/* Static --------------------------------------------------------------------*/
+
+
+/******************************************************************************
+ ******* static functions (prototypes) ****************************************
+ ******************************************************************************/
+static void user_iface_act (int action);
+static void user_iface_show_ocr (void);
+
+
+/******************************************************************************
+ ******* 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:
+ break;
+ case USER_IFACE_TUI:
+ user_tui_init();
+ break;
+ }
+}
+
+void user_iface_cleanup (void)
+{
+
+ switch (user_iface_mode) {
+ case USER_IFACE_CLUI:
+ break;
+ case USER_IFACE_TUI:
+ user_tui_cleanup();
+ break;
+ }
+ fflush(stdout);
+}
+
+void user_iface (void)
+{
+ char title[TITLE_SIZE];
+ char subtitle[TITLE_SIZE];
+ int user_action;
+
+ snprintf(title, TITLE_SIZE, "Title");
+ snprintf(subtitle, TITLE_SIZE, "Subtitle");
+
+ do {
+ img_iface_show_img();
+
+ 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;
+ }
+ user_iface_act(user_action);
+ } while (user_action != USER_IFACE_ACT_QUIT);
+}
+
+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 *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;
+ }
+}
+
+double user_iface_getdbl (double m, double def, double M,
+ const char *restrict title,
+ const char *restrict help)
+{
+
+ switch (user_iface_mode) {
+ case USER_IFACE_CLUI:
+ return alx_get_int(m, def, M, title, help, 2);
+ case USER_IFACE_TUI:
+ return user_tui_getint(m, def, M, title, help);
+ default:
+ return 1;
+ }
+}
+
+int user_iface_getint (double m, int64_t def, double M,
+ const char *restrict title,
+ const char *restrict help)
+{
+
+ switch (user_iface_mode) {
+ case USER_IFACE_CLUI:
+ return alx_get_dbl(m, def, M, title, help, 2);
+ case USER_IFACE_TUI:
+ return user_tui_getdbl(m, def, M, title, help);
+ default:
+ return 1.0;
+ }
+}
+
+void user_iface_log_write (ptrdiff_t lvl, const char *restrict msg)
+{
+
+ 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 (definitions) ***************************************
+ ******************************************************************************/
+static void user_iface_act (int action)
+{
+
+ if (action & USER_IFACE_ACT_USRI) {
+ switch (action) {
+ case USER_IFACE_ACT_SHOW_OCR:
+ user_iface_show_ocr();
+ break;
+ case USER_IFACE_ACT_QUIT:
+ /* do nothing */
+ break;
+ }
+ } else if (action & USER_IFACE_ACT_PROC) {
+ proc_iface_single(action);
+ } else {
+ img_iface_act(action, NULL);
+ }
+}
+
+static void user_iface_show_ocr (void)
+{
+
+ switch (user_iface_mode) {
+ case USER_IFACE_CLUI:
+ user_clui_show_ocr();
+ break;
+ case USER_IFACE_TUI:
+ user_tui_show_ocr();
+ break;
+ }
+}
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/src/user/tui.c b/src/user/tui.c
new file mode 100644
index 0000000..bad2574
--- /dev/null
+++ b/src/user/tui.c
@@ -0,0 +1,611 @@
+/******************************************************************************
+ * Copyright (C) 2018 Alejandro Colomar Andrés *
+ * SPDX-License-Identifier: GPL-2.0-only *
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* headers **************************************************************
+ ******************************************************************************/
+#include "vision-artificial/user/tui.h"
+
+#include <inttypes.h>
+#include <ncurses.h>
+
+#include "libalx/base/stdio/wait.h"
+#include "libalx/extra/ncurses/common.h"
+#include "libalx/extra/ncurses/get.h"
+
+#include "vision-artificial/image/iface.h"
+#include "vision-artificial/user/iface.h"
+
+
+/******************************************************************************
+ ******* macros ***************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* enums ****************************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* structs / unions *****************************************************
+ ******************************************************************************/
+
+
+/******************************************************************************
+ ******* variables ************************************************************
+ ******************************************************************************/
+static WINDOW *win_log;
+static WINDOW *win_help;
+
+
+/******************************************************************************
+ ******* static functions (prototypes) ****************************************
+ ******************************************************************************/
+static void log_loop (void);
+static int usr_input (void);
+static void show_help (void);
+
+
+/******************************************************************************
+ ******* global functions *****************************************************
+ ******************************************************************************/
+void user_tui_init (void)
+{
+ int_fast8_t h1, w1, r1, c1;
+ int_fast8_t h2, w2, r2, c2;
+
+ alx_ncurses_resume();
+
+ /* Dimensions: log */
+ h1 = 54;
+ w1 = 40;
+ r1 = 0;
+ c1 = 30;
+ win_log = newwin(h1, w1, r1, c1);
+
+ /* Dimensions: help */
+ h2 = 54;
+ w2 = 40;
+ r2 = 0;
+ c2 = 0;
+ win_help = newwin(h2, w2, r2, c2);
+
+ /* Activate keypad, don't echo input */
+ keypad(win_log, true);
+ noecho();
+}
+
+void user_tui_cleanup (void)
+{
+
+ /* Del wins & return to terminal mode */
+ alx_ncurses_delwin(win_log);
+ alx_ncurses_delwin(win_help);
+ alx_ncurses_pause();
+}
+
+int user_tui (const char *restrict title,
+ const char *restrict subtitle)
+{
+
+ show_help();
+ user_tui_show_log(title, subtitle);
+ return usr_input();
+}
+
+void user_tui_fname (const char *restrict fpath,
+ char *restrict fname)
+{
+ int w, r;
+
+ w = 75;
+ r = 10;
+
+ 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 *restrict title,
+ const char *restrict subtitle)
+{
+
+ werase(win_log);
+ box(win_log, 0, 0);
+
+ alx_ncurses_title(win_log, title);
+ alx_ncurses_subtitle(win_log, subtitle);
+
+ log_loop();
+ wrefresh(win_log);
+}
+
+double user_tui_getdbl (double m, double def, double M,
+ const char *restrict title,
+ const char *restrict help)
+{
+ int w, r;
+
+ w = 75;
+ r = 10;
+
+ return alx_w_get_dbl(m, def, M, w, r, title, help, 2);
+}
+
+int user_tui_getint (int m, int def, int M,
+ const char *restrict title,
+ const char *restrict help)
+{
+ int w, r;
+
+ w = 75;
+ r = 10;
+
+ return alx_w_get_int(m, def, M, w, r, title, help, 2);
+}
+
+void user_tui_show_ocr (void)
+{
+
+ alx_ncurses_pause();
+
+ printf("%s", img_ocr_text);
+ alx_wait4enter();
+
+ alx_ncurses_resume();
+}
+
+
+/******************************************************************************
+ ******* static functions (definitions) ***************************************
+ ******************************************************************************/
+static void log_loop (void)
+{
+ 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;
+ l_0 = 1;
+ mvwprintw(win_log, 1, 10, "...");
+ } else {
+ i_0 = 0;
+ l_0 = 0;
+ }
+
+ 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, l, (1 + 4 * user_iface_log.lvl[i]),
+ "%.*s",
+ 40 - 2 - 4 * user_iface_log.lvl[i],
+ user_iface_log.line[i]);
+ l++;
+ }
+ }
+}
+
+static int usr_input (void)
+{
+ int c;
+
+ c = wgetch(win_log);
+ switch (c) {
+ case ' ':
+ return USER_IFACE_ACT_APPLY;
+ case KEY_BACKSPACE:
+ /* ASCII 0x08 is BS */
+ case 0x08:
+ return USER_IFACE_ACT_DISCARD;
+ case 'e':
+ /* Exercises from class */
+ c = wgetch(win_log);
+
+ switch (c) {
+ case '1':
+ /* Label */
+ c = wgetch(win_log);
+
+ switch (c) {
+ case '1':
+ return USER_IFACE_ACT_PROC_LABEL_SERIES;
+ }
+ break;
+ case '2':
+ /* Objects */
+ c = wgetch(win_log);
+
+ switch (c) {
+ case '0':
+ return USER_IFACE_ACT_PROC_OBJECTS_CALIB;
+ case '1':
+ return USER_IFACE_ACT_PROC_OBJECTS_SERIES;
+ }
+ break;
+ case '3':
+ /* Coins */
+ c = wgetch(win_log);
+
+ switch (c) {
+ case '1':
+ return USER_IFACE_ACT_PROC_COINS_SERIES;
+ }
+ break;
+ case '4':
+ /* Resistor */
+ c = wgetch(win_log);
+
+ switch (c) {
+ case '1':
+ return USER_IFACE_ACT_PROC_RESISTOR_SERIES;
+ }
+ break;
+ case '5':
+ /* Lighters */
+ c = wgetch(win_log);
+
+ switch (c) {
+ case '1':
+ return USER_IFACE_ACT_PROC_LIGHTERS_SERIES;
+ }
+ break;
+ }
+ break;
+ case 'f':
+ /* Use simple funtions */
+ c = wgetch(win_log);
+
+ switch (c) {
+ case '0':
+ /* img_alx */
+ c = wgetch(win_log);
+
+ switch (c) {
+ case '0':
+ /* Distance transform postprocessing */
+ c = wgetch(win_log);
+
+ switch (c) {
+ case '0':
+ return USER_IFACE_ACT_LOCAL_MAX;
+ case '1':
+ return USER_IFACE_ACT_SKELETON;
+ }
+ break;
+ case '1':
+ /* Lines */
+ c = wgetch(win_log);
+
+ switch (c) {
+ case '0':
+ return USER_IFACE_ACT_LINES_HORIZONTAL;
+ case '1':
+ return USER_IFACE_ACT_LINES_VERTICAL;
+ }
+ break;
+ case '2':
+ /* Smooth */
+ c = wgetch(win_log);
+
+ switch (c) {
+ case '0':
+ return USER_IFACE_ACT_MEAN_HORIZONTAL;
+ case '1':
+ return USER_IFACE_ACT_MEAN_VERTICAL;
+ case '2':
+ return USER_IFACE_ACT_MEDIAN_HORIZONTAL;
+ case '3':
+ return USER_IFACE_ACT_MEDIAN_VERTICAL;
+ }
+ break;
+ }
+ break;
+ case '1':
+ /* img_cv */
+ c = wgetch(win_log);
+
+ switch (c) {
+ case '0':
+ /* Core: The core functionality */
+ c = wgetch(win_log);
+
+ switch (c) {
+ case '0':
+ /* Pixel */
+ c = wgetch(win_log);
+
+ switch (c) {
+ case '0':
+ return USER_IFACE_ACT_PIXEL_GET;
+ case '1':
+ return USER_IFACE_ACT_PIXEL_SET;
+ }
+ break;
+ case '1':
+ /* ROI */
+ c = wgetch(win_log);
+
+ switch (c) {
+ case '0':
+ return USER_IFACE_ACT_SET_ROI;
+ case '1':
+ return USER_IFACE_ACT_SET_ROI_2RECT;
+ }
+ break;
+ case '2':
+ /* Operations on Arrays */
+ c = wgetch(win_log);
+
+ switch (c) {
+ case '0':
+ return USER_IFACE_ACT_AND_2REF;
+ case '1':
+ return USER_IFACE_ACT_NOT;
+ case '2':
+ return USER_IFACE_ACT_OR_2REF;
+ case '3':
+ return USER_IFACE_ACT_COMPONENT;
+ }
+ break;
+ }
+ break;
+ case '1':
+ /* Imgproc: Image processing */
+ c = wgetch(win_log);
+
+ switch (c) {
+ case '0':
+ /* Image filtering */
+ c = wgetch(win_log);
+
+ switch (c) {
+ case '0':
+ return USER_IFACE_ACT_DILATE;
+ case '1':
+ return USER_IFACE_ACT_ERODE;
+ case '2':
+ return USER_IFACE_ACT_DILATE_ERODE;
+ case '3':
+ return USER_IFACE_ACT_ERODE_DILATE;
+ case '4':
+ return USER_IFACE_ACT_SMOOTH;
+ case '5':
+ return USER_IFACE_ACT_SOBEL;
+ case '6':
+ return USER_IFACE_ACT_BORDER;
+ }
+ break;
+ case '1':
+ /* Geometric image transformations */
+ c = wgetch(win_log);
+
+ switch (c) {
+ case '0':
+ return USER_IFACE_ACT_MIRROR;
+ case '1':
+ return USER_IFACE_ACT_ROTATE_ORTO;
+ case '2':
+ return USER_IFACE_ACT_ROTATE;
+ case '3':
+ return USER_IFACE_ACT_ROTATE_2RECT;
+ }
+ break;
+ case '2':
+ /* Miscellaneous image transformations */
+ c = wgetch(win_log);
+
+ switch (c) {
+ case '0':
+ return USER_IFACE_ACT_ADAPTIVE_THRESHOLD;
+ case '1':
+ return USER_IFACE_ACT_CVT_COLOR;
+ case '2':
+ return USER_IFACE_ACT_DISTANCE_TRANSFORM;
+ case '3':
+ return USER_IFACE_ACT_THRESHOLD;
+ }
+ break;
+ case '3':
+ /* Histograms */
+ c = wgetch(win_log);
+
+ switch (c) {
+ case '0':
+ return USER_IFACE_ACT_HISTOGRAM;
+ case '1':
+ return USER_IFACE_ACT_HISTOGRAM_C3;
+ }
+ break;
+ case '4':
+ /* Structural analysis and shape descriptors */
+ c = wgetch(win_log);
+
+ switch (c) {
+ case '0':
+ return USER_IFACE_ACT_CONTOURS;
+ case '1':
+ return USER_IFACE_ACT_CONTOURS_SIZE;
+ case '2':
+ return USER_IFACE_ACT_BOUNDING_RECT;
+ case '3':
+ return USER_IFACE_ACT_FIT_ELLIPSE;
+ case '4':
+ return USER_IFACE_ACT_MIN_AREA_RECT;
+ }
+ break;
+ case '5':
+ /* Feature detection */
+ c = wgetch(win_log);
+
+ switch (c) {
+ case '0':
+ return USER_IFACE_ACT_HOUGH_CIRCLES;
+ }
+ break;
+ }
+ break;
+ }
+ break;
+ case '2':
+ /* img_orb */
+ c = wgetch(win_log);
+
+ switch (c) {
+ case '0':
+ return USER_IFACE_ACT_ALIGN;
+ }
+ break;
+ case '3':
+ /* img_calib3d */
+ c = wgetch(win_log);
+
+ switch (c) {
+ case '0':
+ return USER_IFACE_ACT_CALIBRATE;
+ case '1':
+ return USER_IFACE_ACT_UNDISTORT;
+ }
+ break;
+ case '4':
+ /* img_zbar */
+ c = wgetch(win_log);
+
+ switch (c) {
+ case '0':
+ return USER_IFACE_ACT_DECODE;
+ }
+ break;
+ case '5':
+ /* img_ocr */
+ c = wgetch(win_log);
+
+ switch (c) {
+ case '0':
+ return USER_IFACE_ACT_READ;
+ }
+ break;
+ }
+ break;
+ case 'l':
+ return USER_IFACE_ACT_LOAD_MEM;
+ case 'm':
+ return USER_IFACE_ACT_SAVE_MEM;
+ case 'q':
+ return USER_IFACE_ACT_QUIT;
+ case 'r':
+ return USER_IFACE_ACT_SAVE_REF;
+ case 's':
+ return USER_IFACE_ACT_SAVE_FILE;
+ case 'u':
+ /* User iface actions */
+ c = wgetch(win_log);
+
+ switch (c) {
+ case '1':
+ return USER_IFACE_ACT_SHOW_OCR;
+ }
+ break;
+
+ case 'x':
+
+ /* Special sequence "xyzzy" */
+ c = wgetch(win_log);
+ if (c == 'y') {
+ c = wgetch(win_log);
+ if (c == 'z') {
+
+ c = wgetch(win_log);
+ if (c == 'z') {
+
+ c = wgetch(win_log);
+ if (c == 'y') {
+ return USER_IFACE_ACT_FOO;
+ }
+ }
+ }
+ }
+ break;
+ }
+
+ return USER_IFACE_ACT_FOO;
+}
+
+static void show_help (void)
+{
+ int r, c;
+
+ werase(win_help);
+ r = 0;
+ c = 0;
+ mvwprintw(win_help, r++, c, "Apply: %s", "Space");
+ mvwprintw(win_help, r++, c, "Discard: %s", "BS");
+ mvwprintw(win_help, r++, c, "Save to mem: %c", 'm');
+ mvwprintw(win_help, r++, c, "Load from mem: %c", 'l');
+ mvwprintw(win_help, r++, c, "Save to ref: %c", 'r');
+ mvwprintw(win_help, r++, c, "Save to file: %c", 's');
+ mvwprintw(win_help, r++, c, "Functions:");
+ mvwprintw(win_help, r++, c, " - Local maxima: %s", "f000");
+ mvwprintw(win_help, r++, c, " - Skeleton: %s", "f001");
+ mvwprintw(win_help, r++, c, " - Horizontal lines: %s", "f010");
+ mvwprintw(win_help, r++, c, " - Vertical lines: %s", "f011");
+ mvwprintw(win_help, r++, c, " - Horizontal mean: %s", "f020");
+ mvwprintw(win_help, r++, c, " - Vertical mean: %s", "f021");
+ mvwprintw(win_help, r++, c, " - Horizontal median: %s", "f022");
+ mvwprintw(win_help, r++, c, " - Vertical median: %s", "f023");
+ mvwprintw(win_help, r++, c, " - Pixel get: %s", "f1000");
+ mvwprintw(win_help, r++, c, " - Pixel set: %s", "f1001");
+ mvwprintw(win_help, r++, c, " - Set ROI: %s", "f1010");
+ mvwprintw(win_help, r++, c, " - Set ROI 2rect: %s", "f1011");
+ mvwprintw(win_help, r++, c, " - Bitwise AND 2ref: %s", "f1020");
+ mvwprintw(win_help, r++, c, " - Bitwise NOT: %s", "f1021");
+ mvwprintw(win_help, r++, c, " - Bitwise OR 2ref: %s", "f1022");
+ mvwprintw(win_help, r++, c, " - Component: %s", "f1023");
+ mvwprintw(win_help, r++, c, " - Dilate: %s", "f1100");
+ mvwprintw(win_help, r++, c, " - Erode: %s", "f1101");
+ mvwprintw(win_help, r++, c, " - D-E: %s", "f1102");
+ mvwprintw(win_help, r++, c, " - E-D: %s", "f1103");
+ mvwprintw(win_help, r++, c, " - Smooth: %s", "f1104");
+ mvwprintw(win_help, r++, c, " - Sobel: %s", "f1105");
+ mvwprintw(win_help, r++, c, " - Border: %s", "f1106");
+ mvwprintw(win_help, r++, c, " - Mirror: %s", "f1110");
+ mvwprintw(win_help, r++, c, " - Rotate ortogonally: %s", "f1111");
+ mvwprintw(win_help, r++, c, " - Rotate: %s", "f1112");
+ mvwprintw(win_help, r++, c, " - Rotate 2rect_rot: %s", "f1113");
+ mvwprintw(win_help, r++, c, " - Adaptive threshold: %s", "f1120");
+ mvwprintw(win_help, r++, c, " - Cvt color: %s", "f1121");
+ mvwprintw(win_help, r++, c, " - Distance transform: %s", "f1122");
+ mvwprintw(win_help, r++, c, " - Threshold: %s", "f1123");
+ mvwprintw(win_help, r++, c, " - Histogram: %s", "f1130");
+ mvwprintw(win_help, r++, c, " - Histogram (3 chan): %s", "f1131");
+ mvwprintw(win_help, r++, c, " - Contours: %s", "f1140");
+ mvwprintw(win_help, r++, c, " - Contours size: %s", "f1141");
+ mvwprintw(win_help, r++, c, " - Bounding rectangle: %s", "f1142");
+ mvwprintw(win_help, r++, c, " - Fit ellipse: %s", "f1143");
+ mvwprintw(win_help, r++, c, " - Min. area rectangle: %s", "f1144");
+ mvwprintw(win_help, r++, c, " - Hough circles: %s", "f1150");
+ mvwprintw(win_help, r++, c, " - Align 2ref (ORB): %s", "f20");
+ mvwprintw(win_help, r++, c, " - Calibrate (Calib3d): %s", "f30");
+ mvwprintw(win_help, r++, c, " - Undistort (Calib3d): %s", "f31");
+ mvwprintw(win_help, r++, c, " - Scan codes (ZBAR): %s", "f40");
+ mvwprintw(win_help, r++, c, " - Scan text (OCR): %s", "f50");
+ mvwprintw(win_help, r++, c, "Exercises:");
+ mvwprintw(win_help, r++, c, " - Label: %s", "e11");
+ mvwprintw(win_help, r++, c, " - Objects (calib): %s", "e20");
+ mvwprintw(win_help, r++, c, " - Objects: %s", "e21");
+ mvwprintw(win_help, r++, c, " - Coins: %s", "e31");
+ mvwprintw(win_help, r++, c, " - Resistor: %s", "e41");
+ mvwprintw(win_help, r++, c, " - Lighters: %s", "e51");
+ mvwprintw(win_help, r++, c, "Other:");
+ mvwprintw(win_help, r++, c, " - Show OCR: %s", "u1");
+ mvwprintw(win_help, r++, c, "Quit: %c", 'q');
+ wrefresh(win_help);
+}
+
+
+/******************************************************************************
+ ******* end of file **********************************************************
+ ******************************************************************************/
diff --git a/tmp/Makefile b/tmp/Makefile
index 12162dc..cd48349 100644
--- a/tmp/Makefile
+++ b/tmp/Makefile
@@ -1,78 +1,96 @@
-# -*- 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 = 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/
-all: $(ALL)
-main.s: $(MAIN_DEPS)
- $(Q)$(CXX) $(CXXFLAGS) $(MAIN_INC_DIRS) -S $< -o $@
- @echo " CXX $@"
+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 vision-artificial/tmp/$@"
$(Q)$(AS) $< -o $@
- @echo " AS $@"
- @echo ""
+PHONY += clean
clean:
- $(Q)rm -f *.o *.s
- @echo "Clean tmp"
+ @echo " RM *.o *.s"
+ $(Q)rm -f *.o *.s
################################################################################
-######## End of file ###########################################################
-################################################################################
-######## End of file ###########################################################
+# Declare the contents of the .PHONY variable as phony.
+.PHONY: $(PHONY)
+
+
+
+
################################################################################
######## End of file ###########################################################
################################################################################
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 ###########################################################
+################################################################################