[英]Program won't start when using OpenCV in C++ to stream video from camera
是的,我有一台连接到PC的USB摄像头,我想用OpenCV来传输它的图像。 这是我的代码:
#include <cv.h>
#include <highgui.h>
#include <stdio.h>
int main()
{
CvCapture* cameraCapture = cvCaptureFromCAM(CV_CAP_ANY);
cvNamedWindow("Camera");
while(1)
{
IplImage* frame = cvQueryFrame(cameraCapture);
cvShowImage("Camera", frame);
if((cvWaitKey(10) & 255) == 27)
break;
}
cvReleaseCapture(&cameraCapture);
cvDestroyWindow("Camera");
}
问题是,当我启动程序时,我收到此弹出错误:“应用程序无法正确启动(0xc0150002)。单击确定关闭应用程序”。 我已经确定我已经包含了所有正确的库,头文件和ddl,所以我真的不确定它有什么问题。
任何帮助解决这个问题将不胜感激。
我建议你尝试使用OpenCV 2.3.1来处理相机。
VideoCapture _videoSource;
bool camera = 1;
if(camera)
{
if(!_videoSource.open(0)) // Try to start camera. 0 = default camera
{
cout << "Error opening camera" << endl; // here you control why the error happens
exit(1); // Exit if fail
}
}
else
{
if(!_videoSource.open(Path+"video.avi"))
{
cout << "Error opening file" << endl;
exit(2); // Exit if fail
}
}
_videoSource.set(CV_CAP_PROP_CONVERT_RGB, 1);
Mat frame;
namedWindow("Image");
while(1)
{
_videoSource >> frame;
imshow("output", frame);
return 0;
}
如果此操作失败,您将确定问题出在您的相机上。 也许是司机。 祝好运。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.