OpenCV SIGSEGV C++ minGW

OpenCV SIGSEGV C++ minGW

本文关键字:minGW C++ SIGSEGV OpenCV      更新时间:2023-10-16

即使在简单的程序中也有内存和异常错误。代码块+调试中的mingw - SIGSEGV,调用堆栈 - user32.dll。运行时崩溃并出现0xc0000005错误。VC 也会崩溃,并出现未经处理的异常。

#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;
  }

我在您的代码中没有看到任何错误。也许这是一些库的错误。

但是你为什么要使用这个旧的OpenCV版本。有了C++,它就更容易了

#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;
}

您是否尝试交换以下行:

cvDestroyWindow("capture");

cvReleaseCapture( &capture );

我相信你应该比cvReleaseCapture更早打电话给cvDestroyWindow.我认为窗户成了capture的主人,应该先被摧毁。