Commit 6f4747f2 authored by Hugo LEVY-FALK's avatar Hugo LEVY-FALK

Gestion plus logique des thresholds de détection.

parent 3e0b1e9d
/home/klafyvel/Documents/supelec/2A/projet/workspace/devel/./cmake.lock 88
/home/klafyvel/Documents/supelec/2A/projet/workspace/devel/./cmake.lock 89
\subsubsection usage Usage
\verbatim
<node name="detect_targets" pkg="detect_targets" type="detect_targets">
<param name="blue" type="int" value="140" />
<param name="red" type="int" value="120" />
<param name="green" type="int" value="190" />
<param name="draw_targets" type="bool" value="False" />
<param name="blue_min" type="int" value="140" />
<param name="blue_max" type="int" value="255" />
<param name="red_min" type="int" value="0" />
<param name="red_max" type="int" value="120" />
<param name="green_min" type="int" value="0" />
<param name="green_max" type="int" value="190" />
</node>
\endverbatim
......@@ -2,8 +2,10 @@
Reads and maintains the following parameters on the ROS server
- \b "~blue" : \b [int] Blue threshold min: 0, default: 140, max: 255
- \b "~red" : \b [int] Bed threshold min: 0, default: 120, max: 255
- \b "~green" : \b [int] Green threshold min: 0, default: 190, max: 255
- \b "~draw_targets" : \b [bool] Draw Targets min: False, default: False, max: True
- \b "~blue_min" : \b [int] Blue minimal threshold min: 0, default: 140, max: 255
- \b "~blue_max" : \b [int] Blue maximal threshold min: 0, default: 255, max: 255
- \b "~red_min" : \b [int] Red minimal threshold min: 0, default: 0, max: 255
- \b "~red_max" : \b [int] Red maximal threshold min: 0, default: 120, max: 255
- \b "~green_min" : \b [int] Green minimal threshold min: 0, default: 0, max: 255
- \b "~green_max" : \b [int] Green maximal threshold min: 0, default: 190, max: 255
......@@ -3,22 +3,30 @@ param {
group.0 {
name=Dynamically Reconfigurable Parameters
desc=See the [[dynamic_reconfigure]] package for details on dynamically reconfigurable parameters.
0.name= ~blue
0.name= ~blue_min
0.default= 140
0.type= int
0.desc=Blue threshold Range: 0 to 255
1.name= ~red
1.default= 120
0.desc=Blue minimal threshold Range: 0 to 255
1.name= ~blue_max
1.default= 255
1.type= int
1.desc=Bed threshold Range: 0 to 255
2.name= ~green
2.default= 190
1.desc=Blue maximal threshold Range: 0 to 255
2.name= ~red_min
2.default= 0
2.type= int
2.desc=Green threshold Range: 0 to 255
3.name= ~draw_targets
3.default= False
3.type= bool
3.desc=Draw Targets
2.desc=Red minimal threshold Range: 0 to 255
3.name= ~red_max
3.default= 120
3.type= int
3.desc=Red maximal threshold Range: 0 to 255
4.name= ~green_min
4.default= 0
4.type= int
4.desc=Green minimal threshold Range: 0 to 255
5.name= ~green_max
5.default= 190
5.type= int
5.desc=Green maximal threshold Range: 0 to 255
}
}
# End of autogenerated section. You may edit below.
......@@ -5,9 +5,11 @@ from dynamic_reconfigure.parameter_generator_catkin import *
gen = ParameterGenerator()
gen.add("blue", int_t, 0, "Blue threshold", 140, 0, 255)
gen.add("red", int_t, 0, "Bed threshold", 120, 0, 255)
gen.add("green", int_t, 0, "Green threshold", 190, 0, 255)
gen.add("draw_targets", bool_t, 0, "Draw Targets", False)
gen.add("blue_min", int_t, 0, "Blue minimal threshold", 140, 0, 255)
gen.add("blue_max", int_t, 0, "Blue maximal threshold", 255, 0, 255)
gen.add("red_min", int_t, 0, "Red minimal threshold", 0, 0, 255)
gen.add("red_max", int_t, 0, "Red maximal threshold", 120, 0, 255)
gen.add("green_min", int_t, 0, "Green minimal threshold", 0, 0, 255)
gen.add("green_max", int_t, 0, "Green maximal threshold", 190, 0, 255)
exit(gen.generate(PACKAGE, "detect_targets", "DetectTargets"))
......@@ -27,18 +27,15 @@ def normalize_coordinates(p, w, h):
def find_targets(
picture, threshold_blue=140, threshold_red=120,
threshold_green=190, return_slices=False):
picture, threshold_blue=(140, 255), threshold_red=(0, 120),
threshold_green=(0, 190), return_slices=False):
"""Find three blue targets in the given picture (RGB matrix).
Args:
picture: a 2D matrix of RGB values
threshold_blue: minimal value of the blue channel for a point to be
considered as blue.
threshold_red: maximal value of the red channel allowed for a
target
threshold_green: maximal value of the green channel allowed for a
target
threshold_blue: interval of allowed values for blue channel.
threshold_red: interval of allowed values for red channel
threshold_green: interval of allowed values for green channel
return_slices: Boolean stating if the slices locating the targets
should be returned.
......@@ -50,9 +47,12 @@ def find_targets(
"""
blue_points = np.where(
(picture[:, :, 2] > threshold_blue)
& (picture[:, :, 0] < threshold_red)
& (picture[:, :, 1] < threshold_green),
(threshold_red[0] <= picture[:, :, 0])
& (picture[:, :, 0] <= threshold_red[1])
& (threshold_green[0] <= picture[:, :, 1])
& (picture[:, :, 1] <= threshold_green[1])
& (threshold_blue[0] <= picture[:, :, 2])
& (picture[:, :, 2] <= threshold_blue[1]),
1,
0
)
......@@ -97,6 +97,6 @@ def find_targets(
R = tuple(reversed(sides[-1]))
if return_slices:
return H, L, R, [(o[0], o[1]) for o in objects]
return H, L, R, ((o[0], o[1]) for o in objects)
else:
return H, L, R
......@@ -13,22 +13,20 @@ from detect_targets.cfg import DetectTargetsConfig
class Publisher:
def __init__(self):
self.threshold_blue = 140
self.threshold_red = 120
self.threshold_green = 190
self.threshold_blue = (140, 255)
self.threshold_red = (0, 120)
self.threshold_green = (0, 190)
self.centers = component_centers()
self.pub = rospy.Publisher('targets', component_centers, queue_size=10)
self.img_pub = rospy.Publisher('img_targets', Image, queue_size=0)
rospy.Subscriber("/bebop/image_raw", Image, self.on_picture)
self.bridge = CvBridge()
self.config_srv = dynamic_reconfigure.server.Server(DetectTargetsConfig, self.on_reconf)
self.draw_targets = False
def on_reconf(self, config, level):
self.threshold_red = config['red']
self.threshold_blue = config['blue']
self.threshold_green = config['green']
self.draw_targets = config['draw_targets']
self.threshold_red = (config['red_min'], config['red_max'])
self.threshold_blue = (config['blue_min'], config['blue_max'])
self.threshold_green = (config['green_min'], config['green_max'])
return config
def on_picture(self, msg):
......
# coding: utf-8
import matplotlib.pyplot as pl
from matplotlib.patches import Rectangle
......@@ -26,7 +27,7 @@ L = normalize_coordinates(L, w, h)
R = normalize_coordinates(R, w, h)
ax.plot([H[0], L[0], R[0]], [H[1], L[1], R[1]], 'o', color='red')
ax.grid()
ax.set_title("Positions normalisées")
ax.set_title(u"Positions normalisées")
pl.show()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment