opencv detect light frequency
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?