Ask Your Question

Motion detection false alarms from light changes

asked 2014-02-26 05:39:18 -0500

updated 2014-02-28 13:55:18 -0500

Will Stewart gravatar image

In order to use the motion detection in my software with OpenCV, I use this elementary approach:

cv::GaussianBlur(Frame, Frame, cv::Size(5, 5), 0, 0, cv::BORDER_DEFAULT);
MOG2Background.operator ()(Frame, Foreground);
std::vector<std::vector<cv::Point> > Contours;
cv::findContours(Foreground, Contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
cv::rectangle(Foreground, cv::Point(0, 0), cv::Point(Foreground.cols, Foreground.rows), cv::Scalar(0, 0, 0), CV_FILLED);
cv::drawContours(Foreground, Contours, -1, cv::Scalar(255, 255, 255), CV_FILLED);

This code works correctly but, if there is a flash light from the Window (by a car lights during the night for example) I obtain an alarm. How can I do to optimize my code?

edit retag flag offensive close merge delete


Denis, if my answer addressed your question, pls mark it as answered.

Will Stewart gravatar imageWill Stewart ( 2014-03-01 08:09:56 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2014-02-26 11:56:15 -0500

Will Stewart gravatar image

updated 2014-02-26 13:50:14 -0500

Bursts of light (e.g. car lights in your example, a neighbor turning on a porch light, etc) are a challenge when it comes to false alarms. There are three ways that I've worked to tackle this;

  1. Max threshold for number of contours (or contour areas): I find that some of these flashes of light tend to create a large number (e.g., sometimes hundreds) of contours. I set a limit which tends to suppress most of these false alarms (by disqualifying such frames in alarm processing), though one has to be careful not to suppress actual objects that they are seeking to detect.

  2. Mask: There are certainly specific areas that are susceptible to flashes of car lights from the roadway in my camera's field of view, so I create a mask with GIMP (load a camera frame, add a transparent layer over top, paint the area that I want masked, save that layer only) and copyTo() the mask to the image, then do the background subtraction.

  3. Rapid changes in histogram levels (still working on this one on the back burner, too early to gauge results).

My most difficult challenge at this time is tracking a car at night that is coming towards the camera in the driveway, due to the massive light change and resulting obscuration of the car itself (which greatly impedes feature detection or classifier matching).

Camera placement is key to helping to moderate these issues, though the perfect location to mount a camera to mitigate these issues is not always available;

edit flag offensive delete link more
Login/Signup to Answer

Question Tools


Asked: 2014-02-26 05:39:18 -0500

Seen: 2,042 times

Last updated: Feb 28 '14