Detecting Lines Using OpenCV on ROS

OpenCV is a widely used computer vision library. In order to perform ROS Perception, learning OpenCV is essential. OpenCV uses the BGR (Blue, Green, Red) format whereas ROS uses the RGB (Red, Blue, Green) format. In order to convert this image encoding, we use the Opencv_bridge.

Once we have the image in BGR format, it's ready to be processed using OpenCV. The first step is to crop the image in order to work with the minimum size. Hence by doing this, we process only the part of the image that is important to us and discard away the unnecessary parts.

The second step is to convert the cropped image to HSV format. HSV removes the image intensity which is very helpful in recognizing the same colors in different lights.

Then we define the upper and the lower color boundaries in HSV format to detect a particular color. Say we want to detect yellow color :
Lower : [20, 100, 100]
Upper : [30, 255, 255]

Once we have boundaries defined, we apply a mask on the image to get a binary image (Black and white) where the yellow color (all colors defined within the upper and lower boundaries) are represented by white and all the other colors are defined by black color.

In the next step, we perform Bitwise AND on the cropped image and the masked image to get an image where the yellow color (all colors defined within the upper and lower boundaries) are represented by their original color and all the other colors are defined by black color. Using image moments, we find the centroid of the yellow color and mark it with a red-colored dot.

Complete code for a Line Follower:https://github.com/YugAjmera/line_maze_ros


Comments

Popular posts from this blog

The move_base ROS node

Three Wheeled Omnidirectional Robot : Motion Analysis

Overview of ATmega328P