OpenCV:背景减法0xC0000005:访问冲突写入位置

时间:2016-05-02 11:48:02

标签: c++ opencv background-subtraction mog

我是opencv的新手,我正在尝试使用BackgroundSubtractorMOG2。但是,我有访问冲突的问题(我无法在任何地方找到解决方案)。我不确定,问题是否与我的代码有关?请帮忙!!

问题:

Unhandled exception at 0x000007F81A1F3F33 (igdfcl64.dll) in opencv_31_test.exe: 0xC0000005: Access violation writing location 0x0000000067648A80.

我正在使用VS2013和opencv 3.1。

这是代码:

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/videoio/videoio.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/video/background_segm.hpp"
#include <iostream>
using namespace std;
using namespace cv;


int main()
{
    VideoCapture cap(0);
    bool update = false;

    if (!cap.isOpened())
    {
        cout<<"camera not open";
        return -1;
    }
    Mat frames, bg_mask, output, image;
    cap >> image;
    if (image.empty())
    {
        cout<<"no image from camera";
        return -1;
    }
    resize(image, frames, Size(640, 480));
    namedWindow("webcam", WINDOW_AUTOSIZE);
    namedWindow("segmented", WINDOW_AUTOSIZE);
    Ptr<BackgroundSubtractorMOG2> bg_sub = createBackgroundSubtractorMOG2();
    bg_sub->setVarThreshold(10);
    for (;;)
    {
        cap >> frames;
        if (frames.empty())
            break;
        bg_sub->apply(frames, bg_mask, update ? -1 : 0);
        imshow("webcam", frames);
        imshow("segmented", output);
        if (waitKey(30) == 27)
            break;
    }
    return 0;
}

0 个答案:

没有答案