[英]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.