summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex <colomar.6.4.3@gmail.com>2018-11-20 00:21:11 +0100
committerAlex <colomar.6.4.3@gmail.com>2018-11-20 00:21:11 +0100
commitc25fca762415113c362804336c903bff2693dbb0 (patch)
tree3847d5acc986002d5a96fbdd2be08d90f68973f6
parent578ba6631120933b7c19c8f553ebcb10ebf3531b (diff)
Add function to update the image in save.cpp; Improve proc_resistor;
-rw-r--r--modules/image/inc/img_iface.h3
-rw-r--r--modules/image/inc/img_iface.hpp3
-rw-r--r--modules/image/src/img_iface.cpp17
-rw-r--r--modules/proc/inc/proc_common.hpp1
-rw-r--r--modules/proc/src/proc_common.cpp5
-rw-r--r--modules/proc/src/proc_resistor.cpp60
-rw-r--r--modules/user/inc/user_iface.h1
-rw-r--r--modules/user/inc/user_iface.hpp1
8 files changed, 64 insertions, 27 deletions
diff --git a/modules/image/inc/img_iface.h b/modules/image/inc/img_iface.h
index f917529..8bb023f 100644
--- a/modules/image/inc/img_iface.h
+++ b/modules/image/inc/img_iface.h
@@ -87,7 +87,8 @@
IMG_IFACE_ACT_SAVE_REF,
IMG_IFACE_ACT_SAVE = 0x2000,
- IMG_IFACE_ACT_SAVE_FILE
+ IMG_IFACE_ACT_SAVE_FILE,
+ IMG_IFACE_ACT_SAVE_UPDT
};
enum Img_Iface_Cmp_BGR {
diff --git a/modules/image/inc/img_iface.hpp b/modules/image/inc/img_iface.hpp
index 08a6fb0..0cb858b 100644
--- a/modules/image/inc/img_iface.hpp
+++ b/modules/image/inc/img_iface.hpp
@@ -93,7 +93,8 @@
IMG_IFACE_ACT_SAVE_REF,
IMG_IFACE_ACT_SAVE = 0x2000,
- IMG_IFACE_ACT_SAVE_FILE
+ IMG_IFACE_ACT_SAVE_FILE,
+ IMG_IFACE_ACT_SAVE_UPDT
};
enum Img_Iface_Cmp {
diff --git a/modules/image/src/img_iface.cpp b/modules/image/src/img_iface.cpp
index 6bf33ff..e13449a 100644
--- a/modules/image/src/img_iface.cpp
+++ b/modules/image/src/img_iface.cpp
@@ -142,6 +142,7 @@ 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);
/******************************************************************************
@@ -374,6 +375,9 @@ void img_iface_act (int action, void *data)
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 */
@@ -1753,6 +1757,19 @@ static void img_iface_save_file (void)
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/proc/inc/proc_common.hpp b/modules/proc/inc/proc_common.hpp
index e5eb1ec..f21e530 100644
--- a/modules/proc/inc/proc_common.hpp
+++ b/modules/proc/inc/proc_common.hpp
@@ -39,6 +39,7 @@ extern "C" {
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);
diff --git a/modules/proc/src/proc_common.cpp b/modules/proc/src/proc_common.cpp
index 662e7f8..514e025 100644
--- a/modules/proc/src/proc_common.cpp
+++ b/modules/proc/src/proc_common.cpp
@@ -76,6 +76,11 @@ 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);
diff --git a/modules/proc/src/proc_resistor.cpp b/modules/proc/src/proc_resistor.cpp
index a90e5a6..0bb9f51 100644
--- a/modules/proc/src/proc_resistor.cpp
+++ b/modules/proc/src/proc_resistor.cpp
@@ -90,7 +90,7 @@ static int chk_std_value (void);
/******************************************************************************
******* global functions *****************************************************
******************************************************************************/
-static int proc_resistor_ (void)
+int proc_resistor_ (void)
{
int status;
@@ -336,7 +336,6 @@ int proc_resistor (void)
separate_bkgd_bands_h();
separate_bkgd_bands_s();
-#if 0
separate_bkgd_bands_v();
bkgd_find();
@@ -417,11 +416,8 @@ int proc_resistor (void)
/* Measure time */
clock_stop("Chk STD values");
-#endif
}
- proc_apply();
- proc_save_file();
status = -1;
result_resistor(status);
@@ -476,6 +472,7 @@ 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);
}
@@ -519,7 +516,7 @@ static void resistor_bkgd (void)
bkgd = 0;
} else {
/* Blue */
- if ((bkgd_hue <= 90) || (bkgd_sat <= 140)) {
+ if ((bkgd_hue < 90) || (bkgd_sat < 100)) {
/* Teal blue */
bkgd = 1;
} else if (bkgd_hue >= 105) {
@@ -537,7 +534,7 @@ static void resistor_dimensions_1 (void)
proc_load_mem(3);
proc_dilate_erode(10);
- proc_erode_dilate(rect.height / 1.9 - 9);
+ proc_erode_dilate((rect.height * 0.67) / 2);
proc_contours(&contours, &hierarchy);
proc_bounding_rect(&(contours[0]), &rect, true);
}
@@ -550,10 +547,10 @@ static void resistor_crop_1 (void)
int y;
int w;
int h;
- w = rect.width * 0.9;
- h = rect.height * 0.9;
- x = rect.x + w * (1.0 - 0.9) / 2.0;
- y = rect.y + h * (1.0 - 0.9) / 2.0;
+ 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);
}
@@ -599,16 +596,20 @@ static void separate_bkgd_bands_s (void)
switch (bkgd) {
case 0:
- proc_threshold(cv::THRESH_TOZERO, 100);
+ proc_threshold(cv::THRESH_TOZERO_INV, 160);
+ proc_threshold(cv::THRESH_TOZERO, 110);
break;
case 1:
- proc_threshold(cv::THRESH_TOZERO, 95);
+ proc_threshold(cv::THRESH_TOZERO_INV, 180);
+ proc_threshold(cv::THRESH_TOZERO, 30);
break;
case 2:
- proc_threshold(cv::THRESH_TOZERO, 200);
+ proc_threshold(cv::THRESH_TOZERO_INV, 190);
+ proc_threshold(cv::THRESH_TOZERO, 170);
break;
case 3:
- proc_threshold(cv::THRESH_TOZERO, 130);
+ proc_threshold(cv::THRESH_TOZERO_INV, 210);
+ proc_threshold(cv::THRESH_TOZERO, 120);
break;
}
proc_threshold(cv::THRESH_BINARY_INV, 1);
@@ -625,22 +626,21 @@ static void separate_bkgd_bands_v (void)
switch (bkgd) {
case 0:
- proc_threshold(cv::THRESH_TOZERO_INV, 130);
- proc_threshold(cv::THRESH_TOZERO, 65);
+ proc_threshold(cv::THRESH_TOZERO_INV, 170);
+ proc_threshold(cv::THRESH_TOZERO, 100);
break;
case 1:
- proc_threshold(cv::THRESH_TOZERO_INV, 155);
- proc_threshold(cv::THRESH_TOZERO, 60);
+ proc_threshold(cv::THRESH_TOZERO_INV, 180);
+ proc_threshold(cv::THRESH_TOZERO, 100);
break;
case 2:
-
- proc_threshold(cv::THRESH_TOZERO_INV, 140);
- proc_threshold(cv::THRESH_TOZERO, 60);
+ proc_threshold(cv::THRESH_TOZERO_INV, 180);
+ proc_threshold(cv::THRESH_TOZERO, 150);
break;
case 3:
- proc_threshold(cv::THRESH_TOZERO_INV, 165);
- proc_threshold(cv::THRESH_TOZERO, 45);
+ proc_threshold(cv::THRESH_TOZERO_INV, 190);
+ proc_threshold(cv::THRESH_TOZERO, 90);
break;
}
proc_threshold(cv::THRESH_BINARY_INV, 1);
@@ -657,7 +657,9 @@ static void bkgd_find (void)
proc_save_ref();
proc_load_mem(5);
proc_or_2ref();
- proc_dilate_erode(1);
+ if (rect.width * 0.95 > 80) {
+ proc_dilate_erode(1);
+ }
proc_save_mem(8);
}
@@ -669,6 +671,11 @@ static int bands_find (void)
/* 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)) {
@@ -722,6 +729,9 @@ static int bands_find (void)
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)
diff --git a/modules/user/inc/user_iface.h b/modules/user/inc/user_iface.h
index 2206456..eea09ae 100644
--- a/modules/user/inc/user_iface.h
+++ b/modules/user/inc/user_iface.h
@@ -94,6 +94,7 @@
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,
diff --git a/modules/user/inc/user_iface.hpp b/modules/user/inc/user_iface.hpp
index 876506c..efb6b84 100644
--- a/modules/user/inc/user_iface.hpp
+++ b/modules/user/inc/user_iface.hpp
@@ -94,6 +94,7 @@
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,