1

I'm trying to use Opencv to capture video from a webcam.

I have the following code

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"

#include <cstdio>
#include <iostream>
#include "cv.h"
#include "highgui.h"
#include <stdio.h>

using namespace cv;
using namespace std;

int main()
{
    VideoCapture cap;
}

Which causes the program to terminate with an error

Process terminated with status -1073741510 (0 minutes, 34 seconds)

I'm wondering if I have not installed opencv correctly on codeblocks

Note that when I use this program instead, everything works fine

CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
if ( !capture )
{
    fprintf( stderr, "ERROR: capture is NULL \n" );
    getchar();
    return -1;
}

IplImage* frame = cvQueryFrame( capture );

cvNamedWindow( "mywindow", CV_WINDOW_AUTOSIZE );

while ( 1 )
{
    frame = cvQueryFrame( capture );
    if ( !frame )
    {
        fprintf( stderr, "ERROR: frame is null...\n" );
        getchar();
        break;
    }

    cvShowImage( "mywindow", frame );

    if ( (cvWaitKey(10) & 255) == 27 )
        break;
}

cvReleaseCapture( &capture );
cvDestroyWindow( "mywindow" );

return 0;

linker Settings compiler settings linker

EDIT

changing the headers to hpp files also produces the same problem

#include "opencv2/opencv.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include <cstdio>
#include <iostream>
#include <stdio.h>

using namespace cv;
using namespace std;

int main()
{
    VideoCapture cap;
    cap.open(1);
    return 0;
}
4

2 回答 2

3

编译和运行的程序使用 OpenCV 1.x 和您包含在其中的头文件不是来自 OpenCV 2.x。如果你想让它工作,你需要安装这个版本的 OpenCV。

于 2013-07-04T06:55:26.167 回答
1

您需要包括:

#include "opencv2/opencv.hpp"  
#include "opencv2/highgui/highgui.hpp"

代替

#include "cv.h"
#include "highgui.h"

C 和 C++ 头文件不应包含在同一个 OpenCV 项目中。最后,它应该是这样的:

#include "opencv2/opencv.hpp"  
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"

#include <cstdio>
#include <iostream>

#include <stdio.h>

using namespace cv;
using namespace std;

int main()
{
    VideoCapture cap;
}
于 2013-07-04T07:11:34.123 回答