From 627101b188be976f2dc2f5e4dea679d8541a5cd7 Mon Sep 17 00:00:00 2001
From: fherrero <fherrero@iri.upc.edu>
Date: Mon, 10 Sep 2018 10:14:57 +0200
Subject: [PATCH] Fixed Hue dynamic reconfigure limits. Removed OpenCV
 dependency. Fixed filter value limits calculation. Added color simulation
 examples.

---
 cfg/BlobDetector.cfg      | 2 +-
 config/blue.yaml          | 9 +++++++++
 config/green.yaml         | 9 +++++++++
 config/red.yaml           | 9 +++++++++
 config/yellow.yaml        | 9 +++++++++
 package.xml               | 4 ++--
 src/blob_detector_alg.cpp | 9 +++++----
 7 files changed, 44 insertions(+), 7 deletions(-)
 create mode 100644 config/blue.yaml
 create mode 100644 config/green.yaml
 create mode 100644 config/red.yaml
 create mode 100644 config/yellow.yaml

diff --git a/cfg/BlobDetector.cfg b/cfg/BlobDetector.cfg
index fff6358..d184edb 100755
--- a/cfg/BlobDetector.cfg
+++ b/cfg/BlobDetector.cfg
@@ -41,7 +41,7 @@ gen = ParameterGenerator()
 #gen.add("velocity_scale_factor",  double_t,  0,                               "Maximum velocity scale factor",  0.5,      0.0,  1.0)
 gen.add("get_filter",              bool_t, 0,                                  "Get current filter coeficients", False)
 gen.add("color_id",                str_t,  0,                                  "ID of the color",                "")
-gen.add("H_center",                int_t,  0,                                  "Hue window center",              90,       0,    180)
+gen.add("H_center",                int_t,  0,                                  "Hue window center",              0,       0,     360)
 gen.add("H_window",                int_t,  0,                                  "Hue window width",               180,      0,    180)
 gen.add("S_center",                int_t,  0,                                  "Saturation window center",       128,      0,    256)
 gen.add("S_window",                int_t,  0,                                  "Saturation window width",        255,      0,    256)
diff --git a/config/blue.yaml b/config/blue.yaml
new file mode 100644
index 0000000..aa0f35c
--- /dev/null
+++ b/config/blue.yaml
@@ -0,0 +1,9 @@
+color_id: blue
+H_center: 240
+H_window: 10
+S_center: 255
+S_window: 10
+V_center: 102
+V_window: 10
+max_area: 100000
+min_area: 10
diff --git a/config/green.yaml b/config/green.yaml
new file mode 100644
index 0000000..05eee86
--- /dev/null
+++ b/config/green.yaml
@@ -0,0 +1,9 @@
+color_id: green
+H_center: 120
+H_window: 10
+S_center: 255
+S_window: 10
+V_center: 102
+V_window: 10
+max_area: 100000
+min_area: 10
diff --git a/config/red.yaml b/config/red.yaml
new file mode 100644
index 0000000..6f10fda
--- /dev/null
+++ b/config/red.yaml
@@ -0,0 +1,9 @@
+color_id: red
+H_center: 0
+H_window: 10
+S_center: 255
+S_window: 10
+V_center: 102
+V_window: 10
+max_area: 100000
+min_area: 10
diff --git a/config/yellow.yaml b/config/yellow.yaml
new file mode 100644
index 0000000..9981fdd
--- /dev/null
+++ b/config/yellow.yaml
@@ -0,0 +1,9 @@
+color_id: yellow
+H_center: 60
+H_window: 10
+S_center: 255
+S_window: 10
+V_center: 102
+V_window: 10
+max_area: 100000
+min_area: 10
diff --git a/package.xml b/package.xml
index 221eb2e..02f4ccd 100644
--- a/package.xml
+++ b/package.xml
@@ -43,14 +43,14 @@
   <build_depend>iri_base_algorithm</build_depend>
   <build_depend>sensor_msgs</build_depend>
   <build_depend>image_transport</build_depend>
-  <build_depend>OpenCV</build_depend>
+  <!--<build_depend>OpenCV</build_depend>-->
   <build_depend>nodelet</build_depend>
   <build_depend>cv_bridge</build_depend>
   <build_depend>message_generation</build_depend>
   <run_depend>iri_base_algorithm</run_depend>
   <run_depend>sensor_msgs</run_depend>
   <run_depend>image_transport</run_depend>
-  <run_depend>OpenCV</run_depend>
+  <!--<run_depend>OpenCV</run_depend>-->
   <run_depend>nodelet</run_depend>
   <run_depend>cv_bridge</run_depend>
   <run_depend>message_runtime</run_depend>
diff --git a/src/blob_detector_alg.cpp b/src/blob_detector_alg.cpp
index 49f8f62..92565a6 100644
--- a/src/blob_detector_alg.cpp
+++ b/src/blob_detector_alg.cpp
@@ -54,6 +54,7 @@ void BlobDetectorAlgorithm::config_update(Config& new_cfg, uint32_t level)
     this->v_max=this->config_.V_center+this->config_.V_window/2;
     this->params.minArea = this->config_.min_area;
     this->params.maxArea = this->config_.max_area;
+    ROS_INFO("Color_id: %s: H(%d,%d),S(%d,%d),V(%d,%d)", this->config_.color_id.c_str(), this->h_min, this->h_max, this->s_min, this->s_max, this->v_min, this->v_max);
   }
   
   this->unlock();
@@ -104,10 +105,10 @@ void BlobDetectorAlgorithm::get_filter(iri_blob_detector::hsv_filter &filter)
   this->lock();
     filter.hue_center=(this->h_min+this->h_max);
     filter.hue_window=(this->h_max-this->h_min)*2;
-    filter.saturation_center=(this->h_min+this->s_max)/2;
-    filter.saturation_window=(this->h_max-this->s_min);
-    filter.value_center=(this->h_min+this->v_max)/2;
-    filter.value_window=(this->h_max-this->v_min);
+    filter.saturation_center=(this->s_min+this->s_max)/2;
+    filter.saturation_window=(this->s_max-this->s_min);
+    filter.value_center=(this->v_min+this->v_max)/2;
+    filter.value_window=(this->v_max-this->v_min);
     filter.blob_min_size=this->params.minArea;
     filter.blob_max_size=this->params.maxArea;
   this->unlock();
-- 
GitLab