' BackgroundSubtractorMOG '不是' cv '的成员

‘BackgroundSubtractorMOG’ is not a member of ‘cv’

本文关键字:成员 BackgroundSubtractorMOG 不是 cv      更新时间:2023-10-16

我在运动检测器脚本工作,但当我运行我的代码,我得到这个错误,每次当我使用这个函数,但我不知道为什么它是错误的。

我使用的是opencv3,下面是我的代码。我试图运行其他的例子,我得到它从网络到相同的功能,但错误仍然存在。有什么好办法吗?

错误提示:

cv.cpp: In function ' int main() ':

cv.cpp:23:4: error: ' BackgroundSubtractorMOG '不是' cv '的成员

我的代码:
#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;
  }

}

正如@shar所说,答案就在这篇文章中。为了创建一个指向算法的智能指针,你需要这样做:

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

使用算法:

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