I am developing an application for monitoring live vehicle traffic using opencv, in c++.
Currently, I am doing background subtraction method to get the back ground and then I find contours.
I use createBackgroundSubtractorGMG method for finding the bg.
The problem I face is during the night time, when the headlight of the vehicle is turned on. The illuminated area in the road is also detected as new traffic. Is there any way I can overcome this problem, or have I chosen a complete wrong approach for traffic monitoring?
The methods I follow for traffic detection are as follow,
void detection(Mat Frame){
Mat bg;
vector<Mat> Channels(3);
vector<Mat> channels;
cvtColor(frame,bg,CV_BGR2YCrCb);
split(bg,Channels);
equalizeHist(Channels[0], Channels[0]);
equalizeHist(Channels[1], Channels[1]);
channels.push_back(Channels[0]);
channels.push_back(Channels[1]);
channels.push_back(Channels[2]);
cv::merge(channels, bg);
cv::GaussianBlur(bg, bg, cv::Size(5,5), 1.5);
pMOG->apply(bg, fore);
cv::GaussianBlur(fore, fore, cv::Size(11,11), 1.5);
findContours(fore,contours,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_SIMPLE);
vector<vector<Point> > contours_poly(contours.size());
vector<Rect> boundRect(contours.size());
double area;
bool found;
for(size_t i = 0; i < contours.size(); i++ )
{
boundRect[i] = boundingRect( Mat(contours[i]) );
}
}