我正在尝试使用Opencv从网络摄像头捕捉视频。麻烦安装OpenCV?
我有以下代码
#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;
}
这会导致程序一个错误
过程与状态-1073741510终止(0分钟,34秒)
终止我想知道如果我没有在代码块上正确安装opencv
注意,当我使用这个程序来代替,一切正常
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;
编辑
改变头来HPP文件也产生了同样的问题
#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;
}
我会注意到,intelisense的代码块似乎知道VideoCapture。编译工作正常,问题是当我运行该程序。 – sav
尝试将零器件编号或负器件编号作为捕获构造器参数。 另外,您希望从第一版的代码中获得什么? 你没有从主函数返回任何东西。捕获已创建,然后程序已达到结束。 – morynicz
不幸的是,添加返回值并没有解决主要问题。此外,我有一个摄像头插入,所以设备号码指的是我的摄像头。 – sav