I need to write a program that use a camera to detect presence of a vehicle inside a determined region on the road before stop line on the intersection (just like an inductive loop). Outputs will true or false based on the visibility of a vehicle on that region. Camera can be installed perpendicular to the road or above the road. Currently I need an algorithm.
The following image is a sample implementation in order to detect vehicles in the intersection:
After some study in this field I realized this technique is background subtraction, the program model background and when a vehicle got inside the area, it will be detected. But the definition says it detect moving vehicles so what if cars stop on the sensor 50%-60% of times(when signal lights becomes red)? Will they become background? Are they detected all the times?
I've seen some algorithm in the BS field, like Mixture of Gaussian, but doubt they work in the real situation because of the above problem.
Currently I program some method like averaging using OpenCV under Linux. Program calculate pixels average inside that rectangle and save this value inside a buffer, calculate mode and compare with current frame. But there are problems like vehicles lights at night, vehicles shadow in day, and stopping cars on my sensor because of red signal.