无法使用 OpenCV 访问网络摄像头 [英] Can't access webcam with OpenCV

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

问题描述

我在 win 7 64 位电脑上使用 OpenCV 2.2 和 Visual Studio 2010.

I'm using OpenCV 2.2 with visual studio 2010 on a win 7 64 bit pc.

我能够按照学习 OpenCV"一书中的说明通过 OpenCV 显示图片和播放 AVI 文件,但我无法捕获网络摄像头图像.即使是随 OpenCV 文件一起提供的示例也无法访问网络摄像头.

I'm able to display pictures and play AVI files through OpenCV as given in the book "Learning OpenCV" but I'm not able to capture webcam images. Even the samples given along with the OpenCV files cant access the webcam.

我被要求输入视频源 -> 捕获源",有两个选项:HP 网络摄像头分路器和 HP 网络摄像头.如果我选择 HP 网络摄像头,窗口会立即关闭而不显示任何错误.(我认为任何错误消息在关闭之前都太快而无法看到).如果我选择 HP 网络摄像头分离器,则网络摄像头图像(视频)应该出现的新窗口将填充均匀的灰色.网络摄像头 LED 亮起,但看不到视频.我的网络摄像头适用于 flash (www.testmycam.com) 和 DirectShow http://www.codeproject.com/KB/audio-video/WebcamUsingDirectShowNET.aspx

I get asked for " video source -> capture source" and there are two options: HP webcam Splitter and HP webcam. If I select HP webcam the window closes immediately without displaying any error. (i think any error message is too fast to be seen before it closes). If I select HP Webcam splitter then the new window, where the webcam images(video) are supposed to come, is filled with uniform gray. The webcam LED is on but no video is seen. My webcam works fine with flash (www.testmycam.com) and with DirectShow http://www.codeproject.com/KB/audio-video/WebcamUsingDirectShowNET.aspx

我确实尝试使用以下方法获取一些错误消息:

I did try getting some error message by using this:

#include "cv.h"
#include "highgui.h"
#include <iostream>
using namespace cv;
using namespace std;

int main(int, char**)
{
    VideoCapture cap("0"); // open the default camera
    if(!cap.isOpened())  // check if we succeeded
       {
     cout << "Error opening camera!";
     getchar();
     return -1;
 }

    Mat edges;
    namedWindow("edges",1);
    for(;;)
    {
        Mat frame;
        cap >> frame; // get a new frame from camera
        cvtColor(frame, edges, CV_BGR2GRAY);
        GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
        Canny(edges, edges, 0, 30, 3);
        imshow("edges", edges);
        if(waitKey(30) >= 0) break;
    }
    // the camera will be deinitialized automatically in VideoCapture destructor
    return 0;
}

我得到的错误信息是:

warning: Error opening file (C:Usersvpworkocvopencvmoduleshighguisrccap
_ffmpeg.cpp:454)
Error opening camera!

我不知道这个cap_ffmpeg.cpp"是什么,我不知道这是否与爱管闲事的HP Media Smart"有关.

I don't know what this "cap_ffmpeg.cpp" is and I don't know if this is any issue with the nosy "HP Media Smart" stuff.

任何帮助将不胜感激.

推荐答案

我在 64 位 Windows 7 上遇到了同样的问题.我不得不重新编译 opencv_highgui 更改属性页面的 C/C++ 面板中的预处理器定义"以包括:

I had the same issue on Windows 7 64-bit. I had to recompile opencv_highgui changing the "Preprocesser Definitions" in the C/C++ panel of the properties page to include:

HAVE_VIDEOINPUTHAVE_DSHOW

HAVE_VIDEOINPUT HAVE_DSHOW

希望能帮到你

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

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