From 1402dbf3e3e718a342c03503a2dd717ae138f985 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Wed, 15 Apr 2020 00:24:59 +0200 Subject: Change debug values --- src/dbg.h | 2 +- src/label.c | 2 +- src/symbols.c | 30 +++++++++++++++--------------- src/templates/base.c | 8 ++++---- src/templates/templates.c | 34 +++++++++++++++++++++++++--------- 5 files changed, 46 insertions(+), 30 deletions(-) diff --git a/src/dbg.h b/src/dbg.h index c4a1b47..42d6541 100644 --- a/src/dbg.h +++ b/src/dbg.h @@ -24,7 +24,7 @@ /****************************************************************************** ******* macro **************************************************************** ******************************************************************************/ -#define DBG 0 +#define DBG 3 #define DBG_SHOW_WAIT 0 #define DBG_SHOWTIME(dbg) ( \ { \ diff --git a/src/label.c b/src/label.c index 501a85b..9befdc7 100644 --- a/src/label.c +++ b/src/label.c @@ -121,7 +121,7 @@ int find_symbols_vertically (img_s *img) alx_cv_and_2ref(bkgd, tmp); dbg_show(3, bkgd); alx_cv_invert(tmp); dbg_show(3, tmp); alx_cv_and_2ref(clean, tmp); dbg_show(3, clean); - alx_cv_or_2ref(clean, bkgd); dbg_show(2, clean); + alx_cv_or_2ref(clean, bkgd); dbg_show(3, clean); /* Find syms */ status--; diff --git a/src/symbols.c b/src/symbols.c index 655f4a3..bf2be17 100644 --- a/src/symbols.c +++ b/src/symbols.c @@ -103,8 +103,8 @@ int extract_symbols (img_s *restrict img) alx_cv_adaptive_thr(tmp, ALX_CV_ADAPTIVE_THRESH_GAUSSIAN, ALX_CV_THRESH_BINARY_INV, h / 2, 5); dbg_show(3, tmp); alx_cv_holes_fill(tmp); - alx_cv_erode_dilate(tmp, h / 15); dbg_show(2, tmp); - alx_cv_dilate_erode(tmp, h / 15); dbg_show(2, tmp); + alx_cv_erode_dilate(tmp, h / 15); dbg_show(3, tmp); + alx_cv_dilate_erode(tmp, h / 15); dbg_show(3, tmp); alx_cv_contours(tmp, conts); alx_cv_sort_conts_lr(conts); if (alx_cv_extract_conts(conts, NULL, &nsyms)) @@ -180,31 +180,31 @@ int clean_symbol (img_s *img) alx_cv_threshold(mask, ALX_CV_THRESH_BINARY_INV, ALX_CV_THR_OTSU); dbg_show(3, mask); alx_cv_dilate(mask, 2); dbg_show(3, mask); - alx_cv_holes_fill(mask); dbg_show(2, mask); + alx_cv_holes_fill(mask); dbg_show(3, mask); alx_cv_contours(mask, conts); alx_cv_extract_imgdata(mask, NULL, &w, &h, NULL, NULL, NULL); if (alx_cv_conts_closest(NULL, &i, conts, w / 2, h / 2, NULL)) goto err; - alx_cv_contour_mask(mask, conts, i); dbg_show(2, mask); + alx_cv_contour_mask(mask, conts, i); dbg_show(3, mask); alx_cv_dilate(mask, 2); dbg_show(3, mask); /* Find BKGD */ - alx_cv_clone(bkgd, img); dbg_show(2, bkgd); - alx_cv_median(bkgd); dbg_show(2, bkgd); - alx_cv_invert(mask); dbg_show(2, mask); - alx_cv_and_2ref(bkgd, mask); dbg_show(2, bkgd); + alx_cv_clone(bkgd, img); dbg_show(3, bkgd); + alx_cv_median(bkgd); dbg_show(3, bkgd); + alx_cv_invert(mask); dbg_show(3, mask); + alx_cv_and_2ref(bkgd, mask); dbg_show(3, bkgd); /* Clean symbol */ - alx_cv_invert(mask); dbg_show(2, mask); - alx_cv_and_2ref(img, mask); dbg_show(2, img); - alx_cv_or_2ref(img, bkgd); dbg_show(2, img); + alx_cv_invert(mask); dbg_show(3, mask); + alx_cv_and_2ref(img, mask); dbg_show(3, img); + alx_cv_or_2ref(img, bkgd); dbg_show(3, img); /* Threshold */ alx_cv_normalize(img); dbg_show(3, img); alx_cv_smooth(img, ALX_CV_SMOOTH_MEDIAN, 3); dbg_show(3, img); w = ALX_MIN(w, h); alx_cv_adaptive_thr(img, ALX_CV_ADAPTIVE_THRESH_GAUSSIAN, - ALX_CV_THRESH_BINARY_INV, w / 2, 25); dbg_show(3, img); + ALX_CV_THRESH_BINARY_INV, w / 2, 25); dbg_show(1, img); /* deinit */ status = 0; @@ -243,7 +243,7 @@ int symbol_base (const img_s *restrict sym, img_s *restrict base) alx_cv_contour_mask(mask, conts, i); dbg_show(3, mask); alx_cv_and_2ref(base, mask); dbg_show(3, base); alx_cv_bounding_rect(rect, cont); - alx_cv_roi_set(base, rect); dbg_show(2, base); + alx_cv_roi_set(base, rect); dbg_show(1, base); /* deinit */ status = 0; @@ -280,7 +280,7 @@ int symbol_inner (const img_s *restrict sym, img_s *restrict in) if (alx_cv_conts_largest_a(&cont, NULL, conts)) goto err; alx_cv_bounding_rect(rect, cont); - alx_cv_roi_set(in, rect); dbg_show(2, in); + alx_cv_roi_set(in, rect); dbg_show(1, in); /* deinit */ @@ -316,7 +316,7 @@ int symbol_outer (const img_s *restrict sym, img_s *restrict out) alx_cv_contour_mask(mask, conts, i); dbg_show(3, mask); alx_cv_invert(mask); dbg_show(3, mask); alx_cv_and_2ref(out, mask); dbg_show(3, out); - alx_cv_erode_dilate(out, 1); dbg_show(2, out); + alx_cv_erode_dilate(out, 1); dbg_show(1, out); /* deinit */ status = 0; diff --git a/src/templates/base.c b/src/templates/base.c index 32367dc..081e474 100644 --- a/src/templates/base.c +++ b/src/templates/base.c @@ -73,7 +73,7 @@ int match_t_base (img_s *restrict sym, uint32_t *code, ptrdiff_t i) match = -INFINITY; BITFIELD_SET(code, CODE_BASE_POS, CODE_BASE_LEN); - m = alx_cv_compare_bitwise(base, base_templates[i], 2); dbg_printf(2, "match: %.5lf\n", m); + m = alx_cv_compare_bitwise(base, base_templates[i], 2); dbg_printf(4, "match: %.5lf\n", m); alx_cv_clone(tmp, base); alx_cv_resize_2largest(tmp, base_templates[i]); alx_cv_xor_2ref(tmp, base_templates[i]); dbg_show(2, tmp); @@ -83,7 +83,7 @@ int match_t_base (img_s *restrict sym, uint32_t *code, ptrdiff_t i) match = m; } - m = alx_cv_compare_bitwise(base, base_templates_not[i], 2); dbg_printf(2, "match: %.5lf\n", m); + m = alx_cv_compare_bitwise(base, base_templates_not[i], 2); dbg_printf(4, "match: %.5lf\n", m); alx_cv_clone(tmp, base); alx_cv_resize_2largest(tmp, base_templates_not[i]); alx_cv_xor_2ref(tmp, base_templates_not[i]); dbg_show(2, tmp); @@ -94,10 +94,10 @@ int match_t_base (img_s *restrict sym, uint32_t *code, ptrdiff_t i) } if (BIT_READ(*code, CODE_Y_N_POS)) { - dbg_printf(1, "%s\n", t_base_meaning[i]); + dbg_printf(4, "%s\n", t_base_meaning[i]); dbg_show(1, base_templates[i]); } else { - dbg_printf(1, "%s not\n", t_base_meaning[i]); + dbg_printf(4, "%s not\n", t_base_meaning[i]); dbg_show(1, base_templates_not[i]); } diff --git a/src/templates/templates.c b/src/templates/templates.c index cb6eaab..1264ae6 100644 --- a/src/templates/templates.c +++ b/src/templates/templates.c @@ -210,17 +210,17 @@ int match_t_inner (img_s *restrict sym, uint32_t *code) BITFIELD_WRITE(code, CODE_IN_POS, CODE_IN_LEN, 0); for (ptrdiff_t i = 0; i < ARRAY_SSIZE(inner_templates); i++) { m = alx_cv_compare_bitwise(in, inner_templates[i], 2); - dbg_printf(2, "match: %.4lf\n", m); + dbg_printf(4, "match: %.4lf\n", m); if (m >= match) { BITFIELD_WRITE(code, CODE_IN_POS, CODE_IN_LEN, i); match = m; - dbg_printf(1, "%s\n", t_inner_fnames[i]); + dbg_printf(4, "%s\n", t_inner_fnames[i]); } } dbg_show(1, inner_templates[BITFIELD_READ(*code, CODE_IN_POS, CODE_IN_LEN)]); t_inner_fix_code(code); - dbg_printf(1, "%s\n", t_inner_meaning[BITFIELD_READ(*code, CODE_IN_POS, CODE_IN_LEN)]); + dbg_printf(4, "%s\n", t_inner_meaning[BITFIELD_READ(*code, CODE_IN_POS, CODE_IN_LEN)]); /* deinit */ status = 0; @@ -251,7 +251,7 @@ int match_t_outer (img_s *restrict sym, uint32_t *code) /* Find inner match */ status--; if (symbol_outer(sym, out)) - goto err; dbg_show(2, out); + goto err; dbg_show(1, out); status--; alx_cv_contours(out, conts); @@ -350,13 +350,30 @@ void t_inner_fix_code (uint32_t *code) BITFIELD_SET(code, CODE_IN_POS, CODE_IN_LEN); break; case T_BASE_PRO: + switch (in_code) { + case T_INNER_FNAME_A ... T_INNER_FNAME_W: + in_code += T_INNER_A - T_INNER_FNAME_A; + BITFIELD_WRITE(code, CODE_IN_POS, CODE_IN_LEN, in_code); + break; + default: + BITFIELD_WRITE(code, CODE_IN_POS, CODE_IN_LEN, 0); + break; + } + break; in_code += T_INNER_A - T_INNER_FNAME_A; BITFIELD_WRITE(code, CODE_IN_POS, CODE_IN_LEN, in_code); break; case T_BASE_DRY: case T_BASE_IRON: - in_code += T_INNER_LO_T - T_INNER_FNAME_1_DOT; - BITFIELD_WRITE(code, CODE_IN_POS, CODE_IN_LEN, in_code); + switch (in_code) { + case T_INNER_FNAME_1_DOT ... T_INNER_FNAME_3_DOT: + in_code += T_INNER_LO_T - T_INNER_FNAME_1_DOT; + BITFIELD_WRITE(code, CODE_IN_POS, CODE_IN_LEN, in_code); + break; + default: + BITFIELD_WRITE(code, CODE_IN_POS, CODE_IN_LEN, 0); + break; + } break; case T_BASE_WASH: switch (in_code) { @@ -372,9 +389,8 @@ void t_inner_fix_code (uint32_t *code) in_code += T_INNER_95 - T_INNER_FNAME_95; BITFIELD_WRITE(code, CODE_IN_POS, CODE_IN_LEN, in_code); break; - case T_INNER_FNAME_A ... T_INNER_FNAME_W: - in_code += T_INNER_A - T_INNER_FNAME_A; - BITFIELD_WRITE(code, CODE_IN_POS, CODE_IN_LEN, in_code); + default: + BITFIELD_WRITE(code, CODE_IN_POS, CODE_IN_LEN, 0); break; } break; -- cgit v1.2.3