[英]Program won't start when using OpenCV in C++ to stream video from camera
right, I have a USB camera connected to the PC and I want to use OpenCV to stream images from it. 是的,我有一台连接到PC的USB摄像头,我想用OpenCV来传输它的图像。 Here is my code:
这是我的代码:
#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");
}
The problem is that when I start the program I get this pop-up error: "The application was unable to start correctly (0xc0150002). Click OK to close the application". 问题是,当我启动程序时,我收到此弹出错误:“应用程序无法正确启动(0xc0150002)。单击确定关闭应用程序”。 I have made sure I have included all the correct libraries, header files and ddl's so I'm really not sure whats wrong with it.
我已经确定我已经包含了所有正确的库,头文件和ddl,所以我真的不确定它有什么问题。
Any help to solve this problem will be greatly appreciated. 任何帮助解决这个问题将不胜感激。
I suggest you to try this way of dealing with cameras, using the OpenCV 2.3.1. 我建议你尝试使用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;
}
If this fails, the you will know for sure that the problem is with your camera. 如果此操作失败,您将确定问题出在您的相机上。 Maybe the drivers.
也许是司机。 Good luck.
祝好运。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.