Detecting a traffic light for a robot project

asked 2016-03-12 09:29:36 -0500

YaddyVirus gravatar image

(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- 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 ... (more)

edit retag flag offensive close merge delete



I am interested in your method about traffic light detection .

Could you share your code of detection ?

勳雞堡 gravatar image勳雞堡 ( 2016-06-07 03:35:18 -0500 )edit

Actually Its quite simple, just threshold the image, and use cv2.HoughCircles to find a circle, now put a condtional statement that as soon as the pixel intensity at the detected circle goes below a minimun threshold, activate the robot.

YaddyVirus gravatar imageYaddyVirus ( 2016-06-09 01:54:26 -0500 )edit

Thanks for your sharing. I thought about HoughCircles ,but it would cost much time to compute. Is that possible to get the real time ?

勳雞堡 gravatar image勳雞堡 ( 2016-07-18 23:18:40 -0500 )edit

How do I get the pixel intensity of the circle and what do I set the threshold value?

gkarmakar gravatar imagegkarmakar ( 2017-09-15 20:11:23 -0500 )edit