4

我正在使用opencv 2.4.4,当我在它上面运行这个算法时,它给了我nmixtures错误 bShadowDetection

#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;
}

错误的

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' 

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

bg.set("nmixtures", 3);
bg.set("detectShadows", false); 

错误

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 

谢谢

4

3 回答 3

3

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

无法使用该.set()功能设置阴影检测;这是opencv中的一个错误。如果你想设置它,你应该在你的构造函数中初始化它。以下是您应该如何初始化背景模型:

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
于 2013-06-29T19:46:55.763 回答
1

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

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

更新

供您使用

bg.set("nmixtures", 3); 
bg.set("detectShadows", false);

至于链接器错误:

error LNK2019: unresolved external symbol ...

也许您忘记与 opencv_video244.lib 链接?

于 2013-06-25T05:20:23.447 回答
-1

OpenCV 2.4 nmixtures 受到保护而不是公共的,因此您可能必须使用构造函数设置 nmixtures 和 bShadowDetection 的值

于 2014-03-07T07:20:52.063 回答