shar
shar

Reputation: 1243

‘BackgroundSubtractorMOG’ is not a member of ‘cv’

I am working in Motion Detector Script but when i run my code i get this error every time when i use this function, but i don't know why it's wrong.

I am using opencv3, below is my code. I tried to run other examples i get it from web to same function, but the error still there. Any idea to fix it ?

This is the Error:

cv.cpp: In function ‘int main()’:

cv.cpp:23:4: error: ‘BackgroundSubtractorMOG’ is not a member of ‘cv’

My code :

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <vector>
#include <iostream>
#include <sstream>
#include <opencv2/video/background_segm.hpp>  
using namespace std;


int main()
{
   //Openthevideofile
   cv::VideoCapture capture("/home/shar/Desktop/op.mp4");
   //checkifvideosuccessfullyopened
   if (!capture.isOpened())
     return 0;
   //currentvideoframe
   cv::Mat frame;
   //foregroundbinaryimage
   cv::Mat foreground;
   cv::namedWindow("ExtractedForeground");
   //TheMixtureofGaussianobject
   //used with all default parameters
   cv::BackgroundSubtractorMOG mog;

   bool stop(false);
   //forallframesinvideo
   while(!stop){
  //readnextframeifany
    if(!capture.read(frame))
      break;
   //updatethebackground
   //andreturntheforeground
    mog(frame,foreground,0.01)
  //learningrate
  //Complementtheimage
    cv::threshold(foreground,foreground,128,255,cv::THRESH_BINARY_INV);
  //showforeground
    cv::imshow("ExtractedForeground",foreground);
  //introduceadelay
  //orpresskeytostop
    if(cv::waitKey(10)>=0)
    stop=true;
  }


}

Upvotes: 0

Views: 2310

Answers (1)

ikaro
ikaro

Reputation: 741

As @shar said, the answer is in this post. In order to create a smart pointer to the algorithm you need to do:

  cv::Ptr<cv::BackgroundSubtractorMOG2> pMOG2 = cv::createBackgroundSubtractorMOG2();

EDIT:

And for use the algorithm:

 float learningRate = 0.01; // or whatever
 cv::Mat foreground; 
 pMOG2->apply(frame, foreground, learningRate);

Upvotes: 1

Related Questions