c++ - “BackgroundSubtractorMOG”不是 ‘cv’ 的成员

标签 c++ opencv opencv3.0

我在 Motion Detector Script 中工作,但是当我运行我的代码时,我每次使用这个函数时都会收到这个错误,但我不知道为什么会出错。

我正在使用 opencv3,下面是我的代码。我尝试运行其他示例,我从网络上获取它以实现相同的功能,但错误仍然存​​在。有什么办法解决吗?

这是错误:

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

cv.cpp:23:4: error: ‘BackgroundSubtractorMOG’ is not a member of ‘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 所说,答案在this post 中.为了创建指向算法的智能指针,您需要执行以下操作:

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

编辑:

并使用算法:

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

关于c++ - “BackgroundSubtractorMOG”不是 ‘cv’ 的成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32493710/

相关文章:

c++ - 将 std::string 中的一段文本向左移动 X 个字符

android - 比较连续的帧以确定使用OpenCV的运动方向

opencv - 为什么cv::stereoRectify返回大小为(0,0)的ROI

android - OpenCV,通过单应矩阵扭曲图像

java - Core.rectangle 返回 cannot resolve method 错误 in openCv 3.0

c++ - 找不到头文件 (boost/bind.hpp)

c++ - #pragma AVRT_CODE_BEGIN - 这是什么意思?

Python - 属性错误 : 'module' object has no attribute 'QueryFrame'

python - Opencv:无法获得对faceRecognizer的预测信心

c++ - C/C++ 中的 Retro、Lomo、Vignette 滤镜?