0

I am using OpenCV for motion detection and using back ground subtraction algo for this. I got the following code from net.

cv::Mat frame;
    cv::Mat back;
    cv::Mat fore;
    cv::VideoCapture cap(0);
    bg.nmixtures = 3;
    bg.bShadowDetection = false;
const int history = 5;
cv::BackgroundSubtractorMOG2 bg (history,nmixtures,bShadowDetection);

    std::vector<std::vector<cv::Point> > contours;

    cv::namedWindow("Frame");
    cv::namedWindow("Background");

    for(;;)
    {
        cap >> frame;
        bg.operator ()(frame,fore);
        bg.getBackgroundImage(back);
        cv::erode(fore,fore,cv::Mat());
        cv::dilate(fore,fore,cv::Mat());
        cv::findContours(fore,contours,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE);
        cv::drawContours(frame,contours,-1,cv::Scalar(0,0,255),2);
        cv::imshow("Frame",frame);
        cv::imshow("Background",back);
        if(cv::waitKey(30) >= 0) break;
    }

So can i set a threshold so that if the change in new and old frame is more than the threshold then dont do anything. Or may be some other algorithm that should suit my situation of capturing only slow moving object.

herohuyongtao
  • 49,413
  • 29
  • 133
  • 174
user2588495
  • 93
  • 1
  • 5

2 Answers2

0

You can change the history value (increase it) in the mixture of gaussian model if you wish to detect slow moving objects.

Bharat
  • 2,139
  • 2
  • 16
  • 35
0

You can try to use moving average of frames instead of using every frame as input for BG subtraction. Or use moving average to output of BG subtraction, then binarize by thresholding.

See addWeighted and moving Average (see Cumulative moving average).

Integration will reduce influence of fast changes.

Andrey Smorodov
  • 10,649
  • 2
  • 35
  • 42