Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Detecting a traffic light for a robot project

(Too many questions in very little time)

Hi there, I'm new to OpenCV (downloaded 24 hours ago, I've learnt a lot, but still), I am working on a project that requires image processing on a Raspberry Pi. The Pi has to detect a traffic light(when the robot is standing on the start line), and as soon as the light goes green, signal the Arduino to run the motors. Now to detect the traffic lights, based on my research, I have thought of 3 different approaches...

Approach 1. With the help of a great tutorial (Link- http://opencv-srf.blogspot.in/2010/09/object-detection-using-color-seperation.html) which told me how to detect a red coloured object, I've wrote a code which detects red lights(most of it is same as the tutorial), it shows the object as white and rest as black. Now what I think of doing is, adjust the HSV values for the threshold image so it sees my traffic light(appears as a white spot on the threshold image), set hem there and then monitor the the ROI until it goes black(meaning that the red light has gone off), and send signal to Arduino. In this approach, I need to know-
1. How to fix the HSV values once i set them to the desired values?
2. How to mark the Region of Interest(ROI)?
3. How to track this ROI and when it goes black(meaning the light has gone off), send the commands to the Arduino.
(Please note that currently I'm using OpenCV on my Windows PC in Visual Studio, and my code is written in C++, so if you can tell me how to show output on the computer screen rather than the Arduino part, that would be great. I can later convert the code to python and make necessary modifications, but first I need to get it working on my PC.)

Approach 2- Convert the RGB frames received from the camera feed into greyscale. Once they have been converted find the brightest spot(which should be traffic light), once the spot is found mark it as a ROI, monitor it and as soon as it goes below the threshold value(say 200, meaning the light has gone off), send appropriate commands to the Arduino. In this method what I need to know is same as in the first approach.
(I'm not very sure about the reliability of this approach as there will be direct sunlight where I have to detect the light, so will it be able to find the light and not just point to any well lit area? Please tell me if I'm wrong because this method seems the easiest.)

Approach 3- Take a sample image of a traffic light(when it is red) and then compare it with the frames from my camera feed. As soon as there is a mismatch( meaning the light has gone off), send appropriate command to the Arduino. I'm thinking of Template matching here.

So what is the best approach to use, the most simplest/reliable one? And if you guys have some other ways I'd love to know them. Since I don't have a RPi yet currently I'm using OpenCV on my Windows PC in Visual Studio, and my code is written in C++(about which I know very less, but can understand code written in it), so if you can tell me how to show output on the computer screen rather than the Arduino part, and general coding in C++(because I found that OpenCV libraries for C are almost obsolete) that would be great. I can later convert the code to python and make necessary modifications, but first I need to get it working on my PC. I have to make this work guys, failure is not an option for me. I've already spent nights reading the OpenCV documentation and code samples.

Any help would be greatly appreciated. Very sorry for the long code.

Thanks...