This project uses the fundamentals of computer vision to track three different colours: red, blue and yellow. When you run this program, a camera window opens up along with the object detected by the webcam or a laptop camera. Colour detection is indicated by rectangular boxes around the objects along with the names of the colours: red, blue and yellow.
The program can be used in robotics to detect colours. It can also be used for driverless cars, traffic, vehicles, etc, besides the separation of different coloured objects using pick-and-place robotic arms.
The project requires OpenCV_3.0, Python_2.7 and Numpy Python modules. OpenCV is a library used for computer vision. Flowchart of the program is shown in Fig. 1.
Input from the camera is in the form of blue, green and red (BGR) colours, so we have to convert it into hue saturation value, or HSV. OpenCV usually captures images and videos in 8-bit, unsigned integer and BGR formats. Captured images can be considered as three matrices of blue, green and red with integer values ranging from zero to 255.
HSV colour space consists of three matrices, namely, hue, saturation and value. In OpenCV, value range for the three matrices is 0-179, 0-255 and 0-255, respectively. Hue represents colour, saturation represents the amount to which that colour is mixed with white and value represents the amount to which that colour is mixed with black.
RGB colour model describes colours in terms of the amount of red, green and blue. In situations where colour description plays an integral role, HSV colour model is often preferred over RGB model.
Since we implement HSV colour model in this project, first find HSV of red, blue and yellow. Here, take care that none of the values overlap with other colours. To achieve this, implement the following in the code.