0

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;
}
Cory Kramer
  • 114,268
  • 16
  • 167
  • 218
Pratul Jn
  • 69
  • 8
  • you never put anything in the output image (not sure if this fix the error)... by the way, it would be nice to see the stacktrace of it to know what could be the error – api55 May 02 '16 at 12:08
  • imshow("segmented", bg_mask); – sturkmen May 02 '16 at 14:30
  • @sturkmen changed it to what you mentioned. but, the problem is still there. – Pratul Jn May 02 '16 at 15:02
  • @api55 the stack call is in the link http://www84.zippyshare.com/v/HX9ytB8l/file.html – Pratul Jn May 02 '16 at 15:19
  • @PratulJn did you try removing the `imshow("segmented", output);` . The variable `output` is never set.... btw, you need to compile it in debug mode... your stacktrace just says a bunch of unknowns... – api55 May 02 '16 at 16:25
  • as @PratulJn said output is NULL and good line is imshow("segmented", bg_mask); – LBerger May 02 '16 at 19:27
  • @api55 I changed that line to imshow("segmented", bg_mask); I compiled and run it again in debug mode itself. but doesnt work. – Pratul Jn May 02 '16 at 21:01
  • the problem occurs in the line bg_sub->apply(frames, bg_mask, update ? -1 : 0); – Pratul Jn May 02 '16 at 22:09
  • @PratulJn what error does it gives you? is it an assert error? – api55 May 03 '16 at 19:36
  • @api55 it is stated above. Unhandled exception with Access violation writing when that line executed. – Pratul Jn May 04 '16 at 13:22

0 Answers0