-
Notifications
You must be signed in to change notification settings - Fork 0
Week3: HSV Filter
Let's subscribe to the `/image' topic and apply HSV(Hue/Saturation/Value) filter to it so we can filter out blue lane of our image. The first thing to do is to isolate all the blue areas on the image. To do this, we first need to turn the color space used by the image, which is RGB (Red/Green/Blue) into the HSV (Hue/Saturation/Value) color space. (Read this for more details on the HSV color space.) The main idea behind this is that in an RGB image, different parts of the blue tape may be lit with different light, resulting them appears as darker blue or lighter blue. However, in HSV color space, the Hue component will render the entire blue tape as one color regardless of its shading.
create a new example3_hsv_filter.py file in \nodes folder and modify the process_image function to following
def process_image(msg):
try:
# convert sensor_msgs/Image to OpenCV Image
bridge = CvBridge()
orig = bridge.imgmsg_to_cv2(msg, "bgr8")
hsv = cv2.cvtColor(orig, cv2.COLOR_BGR2HSV)
except Exception as err:
print err
# show results
showImage(hsv)The code hsv = cv2.cvtColor(orig, cv2.COLOR_BGR2HSV) convert the RGB image into HSV space