无法检测OpenCV的网络摄像头 [英] Unable to detect web cam in OpenCV

查看:613
本文介绍了无法检测OpenCV的网络摄像头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用以下code我越来越黑屏虽然我的网络摄像头通过USB连接到我的电脑检测OpenCV的网络摄像头

我的网络摄像头使用*的 ICatch(VI)电脑摄像头* 的驱动器和放大器;我使用的OpenCV 2.1 VS 2008

 的#includecv.h
#包括highgui.hINT主(INT ARGC,字符** argv的){
cvNamedWindow(凸轮,CV_WINDOW_AUTOSIZE);
CvCapture *捕获;
如果(的argc == 1){
    捕获= cvCreateCameraCapture(0);
}其他{
    捕获= cvCreateFileCapture(的argv [1]);
}
断言(捕捉!= NULL);* IplImage结构框架;
而(1){
    帧= cvQueryFrame(捕捉);
    如果突破(帧!);
    cvShowImage(凸轮,帧);
    焦C = cvWaitKey(10);
    如果(C == 27)破;
}
cvReleaseCapture(安培;捕捉);
cvDestroyWindow(凸轮);
}


解决方案

好吧,首先...确实与其他摄像头应用摄像头的工作?

您code是有点搞砸了!您创建一个名为Example2_9窗口,但你尝试用cvShowImage()来绘制到另一个窗口(名为凸轮的)不存在!解决这个问题!更换的出现的凸轮的由Example2_9。

如果不解决这个问题,我可能会取代之初的main()本:

  INT主(INT ARGC,字符** argv的)
{
  cvNamedWindow(Example2_9,CV_WINDOW_AUTOSIZE);
  CvCapture *捕获;  捕获= cvCreateCameraCapture(-1); //是的,如果0不工作,尝试-1
  断言(捕捉!= NULL);

您code缺乏的错误在几个地方检查,要小心。其中的一个功能,可以返回一个错误,你永远不会知道,直到你做适当的检查。

您还可以找到一堆在谷歌其他OpenCV的例子调用cvCaptureFromCAM()而不是cvCreateCameraCapture()。如果上述建议不起作用,试试吧!

还有一件事,在我的MacBook Pro我必须使用cvCaptureFromCAM(0)应用程序的工作。在Linux上,我总是使用cvCaptureFromCAM(-1)。

Hi I am trying to detect web cam in opencv using following code I am getting blank black screen though my web cam is attached to my PC via usb

My web cam is using *ICatch(VI) PC Camera * driver & I am using OpenCV 2.1 with VS 2008

#include "cv.h"
#include "highgui.h"

int main( int argc, char** argv ) { 
cvNamedWindow( "cam", CV_WINDOW_AUTOSIZE );
CvCapture* capture;
if (argc==1) {
    capture = cvCreateCameraCapture( 0 );
} else {
    capture = cvCreateFileCapture( argv[1] );
}
assert( capture != NULL );

IplImage* frame;
while(1) {
    frame = cvQueryFrame( capture );
    if( !frame ) break;
    cvShowImage( "cam", frame );
    char c = cvWaitKey(10);
    if( c == 27 ) break;
}
cvReleaseCapture( &capture );
cvDestroyWindow( "cam" );
}

解决方案

Ok, first... does your webcam work with other webcam applications?

Your code is a little messed up! You create a window named Example2_9 , but you try to draw with cvShowImage() to another window (named cam) that doesn't exist! Fix that! Replace the occurrences of cam by Example2_9.

IF that doesn't solve the problem, I would probably replace the beginning of main() by this:

int main( int argc, char** argv ) 
{ 
  cvNamedWindow( "Example2_9", CV_WINDOW_AUTOSIZE );
  CvCapture* capture;

  capture = cvCreateCameraCapture( -1 ); //yes, if 0 doesn't work try with -1
  assert( capture != NULL );

You code lacks error checking in several places, be careful. One of the functions could be returning an error and you'll never know until you do the proper check.

You can also find a bunch of other OpenCV examples on Google that calls cvCaptureFromCAM() instead of cvCreateCameraCapture(). If the above suggestions doesn't work, try it!

One more thing, on my Macbook Pro I have to use cvCaptureFromCAM(0) for the application to work. On Linux, I always use cvCaptureFromCAM(-1).

这篇关于无法检测OpenCV的网络摄像头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆