OpenCV: Background subtraction 0xC0000005: Access violation writing locatio

282 views Asked by At

I am new to opencv and I am trying to use BackgroundSubtractorMOG2. But, i have a problem with access violation (I could not find a solution for this anywhere). I am not sure, if the problem is with my code? Please help!!

THE PROBLEM:

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

I am using VS2013 with opencv 3.1.

here is the code:

#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

There are 0 answers