GreUJnik
GreUJnik

Reputation: 41

OpenCV + WebCam results in crash (memory access violation during writing)

Recently installed OpenCV 2.4.3 to try to do some video capturing and object distinction. But sadly, every attempt to capture video through web-camera results in memory access violation.

I'm using Visual Studio 2010 (Win 7 x86), and web-camera "A4 Tech USB2.0". First I thought that maybe problem is with camera itself, but then i tried using videoInput.h lib to get any response from camera, still no result. (Other apps like Skype see it (and make it work) no-problem).

Here is a code (almost by the book):

    <pre>
    #include "cv.h"
    #include "highgui.h"
    #include "stdlib.h"
    #include "stdio.h"

    int main(int argc, char* argv[])
    {
    CvCapture* capture = cvCreateCameraCapture(CV_CAP_ANY); //cvCaptureFromCAM( 0 );
    assert( capture );

    double width = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);
    double height = cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);
    printf("[i] %.0f x %.0f\n", width, height );

    IplImage* frame=0;

    cvNamedWindow("capture", CV_WINDOW_AUTOSIZE);

    printf("[i] press Esc for quit!\n\n");

    if(capture != NULL)
    {
      while(true)
     {
       frame = cvQueryFrame( capture ); //it crashes here all the time

        cvShowImage("capture", frame);

       char c = cvWaitKey(35);
       if (c == 27) 
       { 
        break;
       }
      }
     }

     cvReleaseCapture( &capture );
     cvDestroyWindow("capture");
     return 0;
     }
</pre>

Read other topics with the same issue and tried to account some problems: (add interval between captures cvWaitKey(35), add check for if capture device really exists if (capture != NULL) ) but still can`t understand why this keep happening.

UPDATE: What i basically get in the end is console with generated atributes of the OpenCVwindow and window itself(gray background it seems). And memory access violation error.

Upvotes: 0

Views: 1409

Answers (1)

GreUJnik
GreUJnik

Reputation: 41

After some thought and testing, found the resolution.

It seems, that DirectVobSub filter on DirectShow somehow prevented me from accessing my camera programmly (both through OpenCV and VideoInput libs). It created a new instance of itself every time I ran my program and accessed my camera, which led to Access Memory Violation). After uninstalling it from my PC, the code started to work.

Upvotes: 1

Related Questions