Visual Servoing Platform  version 3.6.1 under development (2024-11-15)
Tutorial: Live color segmentation using HSV color scale

Introduction

This tutorial follows Tutorial: HSV low/high range tuner tool.

To run this tutorial you will need:

  • a Realsense camera like a D435 device
  • ViSP build with librealsense and PCL libraries as 3rd parties

We suppose here that you already set the HSV low/high ranges using the range tuner tool explained in Tutorial: HSV low/high range tuner tool.

Note that all the material (source code and images) described in this tutorial is part of ViSP source code (in tutorial/segmentation/color folder) and could be found in https://github.com/lagadic/visp/tree/master/tutorial/segmentation/color.

Color segmentation on a recorded video

  • If not already done, the first step is to record a video as described in Tutorial: Image frame grabbing. Let us consider the case of a Realsense camera. To record a video you may run:
    $ cd $VISP_WS/visp-build/tutorial/grabber
    $ ./tutorial-grabber-realsense --seqname /tmp/seq/image-%04d.png --record 0
    
    • Use left click to start recording, and then right click to stop and quit.
    • The sequence of successive images is recorded in /tmp/seq/ folder.
  • Use the HSV range tuner tool explained in Tutorial: HSV low/high range tuner tool to select the color you want to segment. We select the HSV low/high range on the first image of the sequence with
    $ cd $VISP_WS/visp-build/tutorial/segmentation/color
    $ ./tutorial-hsv-range-tuner --image /tmp/seq/image-0001.png
    
    • As a result you will find the learned HSV low/high ranges in calib/hsv-thresholds.yml
  • Now you are ready to process all the recorded video in order to perform color segmentation based on the content of calib/hsv-thresholds.yml
    $ ./tutorial-hsv-segmentation --video /tmp/seq/image-%04d.png --hsv-thresholds calib/hsv-thresholds.yml
    

Color segmentation on a live stream

  • We suppose here that you have a Realsense camera and that you install librealsense before building ViSP with librealsense 3rdparty support. If you are not familiar with these steps, follow one of the Installation from source code tutorials.
  • Plug your Realsense camera and use the HSV range tuner tool explained in Tutorial: HSV low/high range tuner tool to select the color you want to segment.
    $ cd $VISP_WS/visp-build/tutorial/segmentation/color
    $ ./tutorial-hsv-range-tuner --hsv-thresholds calib/hsv-thresholds.yml
    
    • As a result you will find the learned HSV low/high ranges in calib/hsv-thresholds.yml
  • Now you are ready to process the Realsense live stream in order to perform color segmentation based on the content of calib/hsv-thresholds.yml
    $ ./tutorial-hsv-segmentation --hsv-thresholds calib/hsv-thresholds.yml
    

Next tutorial

You are now ready to see how to continue with Tutorial: Point cloud segmentation using HSV color scale.