【问题标题】:‘BackgroundSubtractorMOG’ is not a member of ‘cv’“BackgroundSubtractorMOG”不是“cv”的成员
【发布时间】:2015-09-10 05:19:58
【问题描述】:

我正在使用 Motion Detector Script,但是当我运行我的代码时,每次使用此功能时都会出现此错误,但我不知道为什么会出错。

我正在使用opencv3,下面是我的代码。我尝试运行其他示例,我将它从 web 获取到相同的功能,但错误仍然存​​在。任何想法来解决它?

这是错误:

cv.cpp:在函数'int main()'中:

cv.cpp:23:4: 错误:‘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;
  }


}

【问题讨论】:

标签: c++ opencv opencv3.0


【解决方案1】:

正如@shar 所说,答案在this post。为了创建一个指向你需要做的算法的智能指针:

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

编辑:

以及使用算法:

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

【讨论】:

  • 你的意思是修复它我应该用这个 cv::BackgroundSubtractorMOG mog 替换你的行;和 mog(frame,foreground,0.01) ?
  • 我添加了执行算法的行
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-02-15
  • 2015-10-22
  • 1970-01-01
  • 2019-10-17
  • 1970-01-01
  • 1970-01-01
  • 2016-12-18
相关资源
最近更新 更多