0

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:

enter image description here

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.

SAMPro
  • 1,068
  • 1
  • 15
  • 39
  • You need to define problem much more clearly. What is your input? What rectangle are you talking about? What does output of true/false mean? Are you trying to infer the presence of traffic lights in different color? Try to write function prototype that declares inputs and outputs. Also, give some diagram. – Shital Shah Dec 03 '16 at 06:09
  • Question edited. I've added a photo that clearly show my intention. As seen the detected region is shown with white borders. – SAMPro Dec 03 '16 at 08:51

1 Answers1

0

I would like to recommend better detection of vehicles than separate the foreground from the background. There is much lights conditions problems and it is old fashion. In opencv you can use for example haar cascade or LBP for the fast and simple detection of vehicles. In opencv 3.1 there are 2 utilily for learning the detector. To use detector is simple.

Same as In this tutorial

There is also some sources on web where you can download already pretrained cascade for car detection.

Code in detection Opencv is simple on and easy to understand You can find the examples on my blog. Also I have one car dataset containing 2000 car positive samples. This samples just list in bash into the list of positiva samples and use utility to create sample and traincascade. LBP cascades are little bit faster with comparable performance..

I learned cascade on windows also under Linux.. The diference is about the run the program. Also the training (vec.vec bg.dat data have to be prepared in create samples utility.. If you have dataset the prepare the training takes 20 minutes. Problem is where to find data. I got dataset on my blog. Also try to understand the script. My -w 32 -h 64 parameters are for people detection. Dor Car is better something like -w 32 -h 32.

./opencv_traincascade and parameters

opencv_traincascade.exe -data v5 -vec vec.vec -bg bg.dat -numPos 540 -numNeg 700 -numStages 11 numThreads 4 -stageType BOOST -featureType LBP -w 32 -h 64 -minHitRate 0.999995 -maxFalseAlarmRate 0.2 -maxDepth 10 -maxWeakCount 120 -mode ALL

I also collect some dataset to train the detector.. You can download the dataset also from Dataset

Car dataset

globalex
  • 549
  • 3
  • 11