OpenCV 找不到我的 USB 网络摄像头

发布于 2024-12-14 00:04:06 字数 1408 浏览 2 评论 0原文

我正在尝试在带有内置 iSight 摄像头的 MacBook 上创建 OpenCV 应用程序。我从互联网上获取了一些非常简单的代码并毫无问题地运行它。 OpenCV 自动发现内置网络摄像头并正常运行,但我无法让它与我的 USB 网络摄像头配合使用。

#include <stdio.h>
#include <opencv.hpp>

int main( int argc, char **argv )
{
    CvCapture *capture = 0;
    IplImage  *frame = 0;
    int       key = 0;

    /* initialize camera */
    capture = cvCaptureFromCAM(0);

    /* always check */
    if ( !capture ) {
        fprintf( stderr, "Cannot open initialize webcam!\n" );
        return 1;
    }

    /* create a window for the video */
    cvNamedWindow( "Test", CV_WINDOW_AUTOSIZE );

    while( key != 'q' ) {
        /* get a frame */
        frame = cvQueryFrame( capture );

        /* always check */
        if( !frame ) break;

        /* display current frame */
        cvShowImage( "Test", frame );

        /* exit if user press 'q' */
        key = cvWaitKey( 1 );
    }

    /* free memory */
    cvDestroyWindow( "Test" );
    cvReleaseCapture( &capture );

    return 0;
}

我编译了这个:

g++ webcam.c -o webcam -I/opt/local/include/opencv2 -I/opt/local/include -L/opt/local/lib -lopencv_core -lopencv_highgui

根据文档,通过将行 capture = cvCaptureFromCAM(0); 更改为 capture = cvCaptureFromCAM(1); 我应该能够访问已插入的其他网络摄像头,但运行该程序会出现错误消息:警告:最大摄像机编号为 0;使用相机 0

我可以采取哪些步骤让 OpenCV 识别出我的 USB 驱动器连接了另一个相机?

I am trying to create an OpenCV application on my MacBook with built-in iSight camera. I grabbed some very simple code off the internet and ran it with no trouble. OpenCV automatically discovered the built-in webcam and ran properly but I can't get it to work with my USB webcam.

#include <stdio.h>
#include <opencv.hpp>

int main( int argc, char **argv )
{
    CvCapture *capture = 0;
    IplImage  *frame = 0;
    int       key = 0;

    /* initialize camera */
    capture = cvCaptureFromCAM(0);

    /* always check */
    if ( !capture ) {
        fprintf( stderr, "Cannot open initialize webcam!\n" );
        return 1;
    }

    /* create a window for the video */
    cvNamedWindow( "Test", CV_WINDOW_AUTOSIZE );

    while( key != 'q' ) {
        /* get a frame */
        frame = cvQueryFrame( capture );

        /* always check */
        if( !frame ) break;

        /* display current frame */
        cvShowImage( "Test", frame );

        /* exit if user press 'q' */
        key = cvWaitKey( 1 );
    }

    /* free memory */
    cvDestroyWindow( "Test" );
    cvReleaseCapture( &capture );

    return 0;
}

I compiled this with:

g++ webcam.c -o webcam -I/opt/local/include/opencv2 -I/opt/local/include -L/opt/local/lib -lopencv_core -lopencv_highgui

According to the documentation, by changing the line capture = cvCaptureFromCAM(0); to
capture = cvCaptureFromCAM(1); I should be able to access the other webcam that I have plugged in but running the program gives me the error message: Warning: Max Camera Num is 0; Using camera 0

What steps can I take to get OpenCV to recognize that I have another camera connected to my USB drive?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蓝颜夕 2024-12-21 00:04:06

这是基于 Windows 的经验,但我相信主要问题是相同的。 (从笔记本电脑上的罗技 USB 摄像头获取输入。)

据我记得; OpenCV不支持多摄像头,因而无法选择摄像头。
我猜您可以使用所显示的代码轻松运行内置相机。
我对类似问题的解决方案是停用内置摄像头。为 USB 摄像头提供用于 cvCaptureFromCAM(0) 函数的唯一“可用”插槽。

我希望这可以解决您的问题,尽管该解决方案有点“笨拙”。

This is based on windows experience, but I believe the main issue to be the same. (To get input from a logitech USB-camera on my laptop.)

As far as I recall; OpenCV does not support multiple cameras, and thereby not the choice of camera.
I am guessing that you can easily run your build-in camera with the code you've shown.
My solution to a similar problem was deactivating the build-in camera. Giving the USB camera the only "availavle" slot for your cvCaptureFromCAM(0) function.

I hope this can solve your problem, even though the solution is a little 'clunky'.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文