'class cv :: BackgroundSubtractorMOG2'没有名为'operator()'的成员

时间:2018-12-19 12:38:44

标签: opencv3.0

我正在尝试编译此c ++应用程序

int main ()
{
  Mat frame;
  Mat back;
  Mat fore;
  VideoCapture cap1;
  cap1.open(0);  /*to capture from camera*/
  cv::Ptr<BackgroundSubtractorMOG> pMOG = createBackgroundSubtractorMOG();
cv::Ptr<BackgroundSubtractorMOG2> pMOG2 = createBackgroundSubtractorMOG2();
  pMOG2->setNMixtures(10);
  vector < vector < Point > >contours;
  namedWindow ("Frame");
  int i=0;

  for (;;)
    {
    cap1 >> frame;
    pMOG2->operator()(frame, fore);
    pMOG2->getBackgroundImage (back);
    erode (fore, fore, cv::Mat ());
    erode (fore, fore, cv::Mat ());
    dilate (fore, fore, cv::Mat ());
    dilate (fore, fore, cv::Mat ());
    dilate (fore, fore, cv::Mat ());
    findContours (fore, contours, CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE);
    drawContours (frame, contours, -1, Scalar (255, 255, 255), 1);
    Scalar color = Scalar(200,200,200);
    int a=0;
    vector<Rect> boundRect( contours.size() );
    for( int i = 0; i < contours.size(); i++ )
      {
           boundRect[i] = boundingRect( contours[i] );
      }
    for( i = 0; i< contours.size(); i++ )
     {
        if(boundRect[i].width>=40 || boundRect[i].height>=40)//eliminates small boxes
            {
                a=a+(boundRect[i].height)*(boundRect[i].width);
             }
        //  cout<<"Net contour area is "<<a<<"\n";
        if(a>=int(frame.rows)*int(frame.cols)/2)//change denominator as per convenience
            {
                putText(frame,"Tampering",Point(5,30),FONT_HERSHEY_SIMPLEX,1,Scalar(0,255,255),2);
                cout<<"\a";
            }
       }
   imshow ("Frame", frame);
   waitKey(10);  
 }

我在编译时遇到以下错误

错误:

  

Tampering.cpp:27:21:错误:'类cv :: BackgroundSubtractorMOG2'具有   没有名为“ operator()”的成员        pMOG2-> operator()(frame,fore);

我的opencv版本3.3.0

预先感谢

1 个答案:

答案 0 :(得分:1)

首先,感谢您订阅我的存储库:https://github.com/SaranshKejriwal/Tampering-Detection/blob/master/Tampering%20main/Tampering.cpp

在我的案例中,我使用过openCV 2.4.5,它在BackgroundSubtractorMOG2类中具有operator()方法。

由于您使用的是openCV 3.3.0,因此建议您查看文档,以确认此方法仍然存在