top of page

Head start to detect colours

Using python as a programming language to start coding the camera to detect the traffic lights (Green, Red). By using the code below, I managed to detect both colours and I tested the code at night and day time.

Now, I am working to detect only green and red circles (traffic light).

In the code, the libraries OpenCV and numpy are imported and the cap is loaded to get the frames from the camera module. The while loop is used so that the camera module captures the frames in every instance. Also, after capturing, the frames are converted in BGR colour space to HSV colour space and the BGR is the default colour space. In OpenCV, there are lots of method available for conversion but the most Widley used is BGR to HSV; that is why it has been used. Inside the while loop the HSV ranges of both colours are defined (low_red, high_red) and (low_green, high green).

Furthermore, mask technique is used which helps to create more specific region of the capture. Here it is created to show only the objects with the red and green colour, each colour has separate frame. To display the frame, green mask and red mask the function “imshow” is used.


7 views

Comments


bottom of page