简体   繁体   English

无法在OpenCV中使用网络摄像头显示图像

[英]Image not being displayed using webcam in opencv

I have just started to learn opencv, but now stuck in a program. 我刚刚开始学习opencv,但是现在陷入了程序中。

I am trying to run a program which just displays the video from the in-built webcam. 我正在尝试运行一个程序,该程序仅显示内置网络摄像头中的视频。

#include <opencv2\highgui\highgui.hpp>

int main() {
cvNamedWindow("Streaming", CV_WINDOW_AUTOSIZE);
CvCapture* capture = cvCreateCameraCapture(0);
IplImage* frame;
while (1) {
    frame = cvQueryFrame(capture);
    if (!frame) break;
    cvShowImage("Streaming", frame);
    char c = cvWaitKey(33);
    if (c == 27) break;
}
cvReleaseCapture(&capture);
cvDestroyWindow("Streaming");
return 0;
}

All is working fine no errors being thrown, but when i run the program a new window named Streaming is being opened and my webcam light also switch on (means webcam has started), but inspite of all this no video is being displayed in the new window which opened. 一切正常,没有错误,但是当我运行该程序时,一个新的窗口名为Streaming正在打开,并且我的网络摄像头指示灯也打开了(意味着网络摄像头已经启动),但是尽管如此,新的窗口中也没有视频显示打开的窗口。

Can any help on this? 请问有什么帮助吗? I am just a beginner in this. 我只是一个初学者。

Thanks in advance!! 提前致谢!!

I suggest migrating from your old cv implementation to the newly made methods from OpenCV 2 . 我建议从旧的cv实现迁移到OpenCV 2的新方法。

Take a look at the VideoCapture class, it has much more intuitive methods. 看一下VideoCapture类,它具有更加直观的方法。 For example, you can use the method isOpened() to check if your webcam has been successfully activated. 例如,您可以使用isOpened()方法检查网络摄像头是否已成功激活。

There's also a nice tutorial over here to help you out with the new methods. 还有一个很好的教程在这里帮助你用新的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM