OpenCV SIGSEGV C++ minGW

0

Even in simple program had a error with memory and exception. Codeblocks+mingw in debug - SIGSEGV, call stack - user32.dll. Runtime crashes with 0xc0000005 error. VC crashes too with unhandled exception.

#include "opencv2/video/tracking.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv/cv.h"
#include "opencv/highgui.h"

#include <iostream>
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>


using namespace cv;
using namespace std;

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

    IplImage* frame=0;

    cvNamedWindow("capture", CV_WINDOW_AUTOSIZE);

    int counter=0;
    char filename[512];

    while(true){

            frame = cvQueryFrame( capture );


            cvShowImage("capture", frame);

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

    }

    cvReleaseCapture( &capture );
    cvDestroyWindow("capture");
    return 0;
  }
c++
opencv
sigsegv
asked on Stack Overflow Dec 4, 2012 by user1847064 • edited Dec 9, 2018 by Cœur

2 Answers

1

I don't see any errors in your code. Maybe this is some libraries mistakes.

But why do you use this old OpenCV version. With C++ it's more easier

#include "opencv2/opencv.hpp"

using namespace cv;

int main(int, char**)
{
    VideoCapture cap(0); // open the default camera
    if(!cap.isOpened())  // check if we succeeded
        return -1;

    while(true)
    {
        Mat frame;
        cap >> frame; // get a new frame from camera
        imshow("frame", frame);
        if(waitKey(30) >= 0) break;
    }
    // the camera will be deinitialized automatically in VideoCapture destructor
    return 0;
}
answered on Stack Overflow Jul 3, 2018 by tenta4
0

Have you tried to exchange those following lines:

cvDestroyWindow("capture");

and

cvReleaseCapture( &capture );

I believe you should call cvDestroyWindow before than cvReleaseCapture. I think the window became the owner of the capture and should be destroyed first.

answered on Stack Overflow Jun 26, 2013 by (unknown user)

User contributions licensed under CC BY-SA 3.0