无法使用OpenCV访问网络摄像头 [英] Can't access webcam with OpenCV
问题描述
我正在Win 7 64位PC上使用带有Visual Studio 2010的OpenCV 2.2.
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 Webcam splitter,则应该在其中出现网络摄像头图像(视频)的新窗口将显示为统一的灰色.网络摄像头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:\Users\vp\work\ocv\opencv\modules\highgui\src\cap
_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_VIDEOINPUT HAVE_DSHOW
HAVE_VIDEOINPUT HAVE_DSHOW
希望这会有所帮助
这篇关于无法使用OpenCV访问网络摄像头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!