首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >BackgroundSubtraction Mog2中的错误

BackgroundSubtraction Mog2中的错误
EN

Stack Overflow用户
提问于 2013-06-25 04:41:43
回答 3查看 5.5K关注 0票数 4

我使用的是opencv 2.4.4,当我在它上面运行这个算法时,它在nmixturesbShadowDetection上给出了错误

代码语言:javascript
复制
#include <iostream>
#include <sys/stat.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <opencv/cv.h>
#include "opencv2/features2d/features2d.hpp"
#include <opencv/highgui.h>
#include "opencv2/opencv.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/nonfree/features2d.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include  <vector>
#pragma comment (lib , "opencv_core244d.lib")
#pragma comment (lib ,"opencv_highgui244d.lib")
#pragma comment(lib , "opencv_imgproc244d.lib")
#pragma comment(lib ,"opencv_video244.lib")
using namespace cv;
int main(int argc, char *argv[])
{
    cv::Mat frame;
    cv::Mat back;
    cv::Mat fore;
    cv::VideoCapture cap("try2.avi");
    cap >> frame;
    cv::initModule_video(); 
     cv::BackgroundSubtractorMOG2 bg(100, 16, true); // history is an int, distance_threshold is an int (usually set to 16), shadow_detection is a bool
     bg.set("nmixtures", 3);
     bg(frame, fore, -1); //learning_rate = -1 here
    std::vector<std::vector<cv::Point> > contours;
    cv::namedWindow("Frame");
    cv::namedWindow("Background");

    for(;;)
    {
        cap >> frame;
        bg.operator ()(frame,fore);
        bg.getBackgroundImage(back);
        cv::erode(fore,fore,cv::Mat());
        cv::dilate(fore,fore,cv::Mat());
        cv::findContours(fore,contours,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE);
        cv::drawContours(frame,contours,-1,cv::Scalar(0,0,255),2);
        cv::imshow("Frame",frame);
        cv::imshow("Background",back);
        if(cv::waitKey(30) >= 0) break;
    }
    return 0;
}

错误的

代码语言:javascript
复制
error C2248: 'cv::BackgroundSubtractorMOG2::nmixtures' : cannot access protected member declared in class 'cv::BackgroundSubtractorMOG2'
error C2248: 'cv::BackgroundSubtractorMOG2::bShadowDetection' : cannot access protected member declared in class 'cv::BackgroundSubtractorMOG2' 

当我像下面这样使用它时,它没有给出语法错误,但在运行时给出了错误

代码语言:javascript
复制
bg.set("nmixtures", 3);
bg.set("detectShadows", false); 

错误

代码语言:javascript
复制
Unhandled exception at 0x7617812f in WK01.exe: Microsoft C++ exception: cv::Exception at memory location 0x001de2d0..
opencv error : Bad argument (no parameter nmixture is found) in unknown function 

谢谢

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2013-06-30 03:46:56

您显示的错误显示为(no parameter nmixture is found)。这里的问题是您输入的是nmixture而不是nmixtures

不能使用.set()函数设置阴影检测;这是opencv中的一个错误。如果你想设置它,你应该使用initialize it in your constructor。下面是你应该如何初始化你的背景模型:

代码语言:javascript
复制
cv::BackgroundSubtractorMOG2 bg(history, distance_threshold, shadow_detection); // history is an int, distance_threshold is an int (usually set to 16), shadow_detection is a bool
票数 3
EN

Stack Overflow用户

发布于 2013-06-25 13:20:23

这是一个错误:http://code.opencv.org/issues/2168

该错误已修复,并将在2.4.6版本中提供修复(它已经在2.4分支中可用)。

更新

适用于您的案例

代码语言:javascript
复制
bg.set("nmixtures", 3); 
bg.set("detectShadows", false);

至于链接器错误:

代码语言:javascript
复制
error LNK2019: unresolved external symbol ...

也许你忘了链接opencv_video244.lib?

票数 1
EN

Stack Overflow用户

发布于 2014-03-07 15:20:52

nmixtures是受保护的,而不是公共的,因此您可能需要使用构造函数来设置nmixtures和bShadowDetection的值

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17284712

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档