我是OpenCV的新手,我想显示我的网络摄像头看到的OpenCV.我正在使用C编码语言.
我试过这段代码:
#include <stdio.h>
#include <cv.h> // Include the OpenCV library
#include <highgui.h> // Include interfaces for video capturing
int main()
{
cvNamedWindow("Window", CV_WINDOW_AUTOSIZE);
CvCapture* capture =cvCreateCameraCapture(-1);
if (!capture){
printf("Error. Cannot capture.");
}
else{
cvNamedWindow("Window", CV_WINDOW_AUTOSIZE);
while (1){
IplImage* frame = cvQueryFrame(capture);
if(!frame){
printf("Error. Cannot get the frame.");
break;
}
cvShowImage("Window",frame);
}
cvReleaseCapture(&capture);
cvDestroyWindow("Window");
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我的网络摄像头的指示灯亮起,但结果是一个完全灰色的窗口,没有图像.
你能帮助我吗?