Ask Your Question
0

opencv detect light frequency

asked 2016-05-13 14:47:36 -0500

I am currently working on a hobby project for a robot car. In front of the camera, I will place 2 light sources and with computer vision I want to detect the light sources and position my robot car in front of it.

With Python and OpenCV on a Raspberry Pi 3, I have the following working: I am using 2 red light sources. Using the following OpenCV functions: cvtColor(frame to HSV), inRange(red filter), findContours(find the 2 light sources), Moments(get the x,y coordinates of the light sources), calculate distance of the light sources compared to the edge of the frame and generate which direction the car have to move.

The problem now is, I cannot determine which red light source is left and which one is right. If I turn my breadboard with 2 red light sources 180 degrees, the program won't be able to tell that the car has to move around the light sources.

I have 2 ideas to fix this: - using frequency to let the light sources blink different. let's say LEFT(1, 0, 1) and RIGHT(0, 1, 0). Using one second time frame means 3 frames per second. Left(1,0,1) will be 0.33s ON, then 0.33s OFF, then 0.33s ON. Also possible to use 0.5s time frame. This means 0.167s ON, 0.167s OFF, 0.167s ON. I might not be able to use threading here, since I need 'every frame'. - using 1 red and 1 green light source. For this I have to add separate functions to detect green, which means more processing power.

I'm struggling with choosing the best option since I'm inexperienced in this field. Do you have any tips? Or which idea is better?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-05-14 00:24:15 -0500

Tetragramm gravatar image

The simple way to detect frequency would be to average the frames over a second or so. The light that is On, Off, On will be twice as bright as the one that is Off,On,Off.

The trick is that you have to be able to keep track of where it is while the camera is moving. One of the lights is always on, so that's ok, but you need to keep track of where the other light should be to do your math. A Kalman filter is a good choice for predicting that.

If your camera isn't exactly a multiple of 30 FPS you'll need to keep track and synchronize your time.

All of this is complicated, so what you probably should do is the red and green lights. You don't need to add much. Just an inRange(greenFilter) then bitwise_or with the red results. You do find contours to get the two lights just as you do now. Then telling red and green lights apart is simple. Pick the pixel value at the X,Y coordinates and check it against your green and red filters. It's just two pixel comparisons so it's very quick.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-05-13 14:46:49 -0500

Seen: 1,023 times

Last updated: May 14 '16