jeudi 24 avril 2014

Impossible d'accéder à la webcam avec OpenCV - Stack Overflow


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


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.


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;
}

And the error message I got was:


warning: Error opening file (C:\Users\vp\work\ocv\opencv\modules\highgui\src\cap
_ffmpeg.cpp:454)
Error opening camera!

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.


Any help will be greatly appreciated.




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


Hope this helps




The cap_ffmpeg.cpp is the source file which uses ffmpeg to perform capturing of the device. If the default example given from OpenCV doesn't work with your webcam, you are out of luck. I suggest you buy another one that is supported.




Recently I have installed OpenCV 2.2 and NetBeans 6.9.1. I had a problem with camera capture, the image in the window was black but the program runs perfectly, without errors. I had to run NetBeans as admin user to fix this problem.


I hope this can help you all.




I just switched to OpenCV 2.2 and am having essentially the same problem but a 32 bit compture running Vista. The webcam would start but I'd get an error message setting the width property for the camera. If I specifically request the DirectShow camera, the cvCreateCameraCapture would fail.
What I think is going on is that the distribution version of HighGUI was build excluding the DirectShow camera. The favored Windows camera on OpenCV used to be Video For Windows, VFW but that has been deprecated since Windows Vista came out and has created all sorts of problems. Why they don't just include it, I don't know. Check the source file cap.cpp


My next step is to rebuild HighGUI myself and make sure the flag HAVE_DSHOW is set. I seem to remember having the same problem with the last version of OpenCV I've been using until I rebuilt it making sure the DirectShow version was enabled.




I experienced the same problem. My Vaio Webcam LED is on but no image on the screen. Then I tried to export the first frame to a JPEG file and its working. Then I tried to insert a delay of 33ms before capture any frame, this time it works like a charm. Hope this'll help.




Here's an article I wrote some time back. It uses the videoInput library to get input from webcams. It uses DirectX, so it works with almost every webcam out there. Capturing images with DirectX




Once you create the cv::VideoCapture you should give an integer not a string (since string implies the input is a file).


To open the default camera, open the stream with


cv::VideoCapture capture(0); 

and it will work fine.




CMAKE GUI, MSVC++10E, Vista 32bit, OpenCV2.2


It looks like HAVE_VIDEOINPUT/WITH_VIDEOINPUT option doesn't work.


However adding: /D HAVE_DSHOW /D HAVE_VIDEOINPUT to CMAKE_CXX_FLAGS, and CMAKE_C_FLAGS did the trick for me (there will be warns due to macro redefinitions).



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


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.


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;
}

And the error message I got was:


warning: Error opening file (C:\Users\vp\work\ocv\opencv\modules\highgui\src\cap
_ffmpeg.cpp:454)
Error opening camera!

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.


Any help will be greatly appreciated.



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


Hope this helps



The cap_ffmpeg.cpp is the source file which uses ffmpeg to perform capturing of the device. If the default example given from OpenCV doesn't work with your webcam, you are out of luck. I suggest you buy another one that is supported.



Recently I have installed OpenCV 2.2 and NetBeans 6.9.1. I had a problem with camera capture, the image in the window was black but the program runs perfectly, without errors. I had to run NetBeans as admin user to fix this problem.


I hope this can help you all.



I just switched to OpenCV 2.2 and am having essentially the same problem but a 32 bit compture running Vista. The webcam would start but I'd get an error message setting the width property for the camera. If I specifically request the DirectShow camera, the cvCreateCameraCapture would fail.
What I think is going on is that the distribution version of HighGUI was build excluding the DirectShow camera. The favored Windows camera on OpenCV used to be Video For Windows, VFW but that has been deprecated since Windows Vista came out and has created all sorts of problems. Why they don't just include it, I don't know. Check the source file cap.cpp


My next step is to rebuild HighGUI myself and make sure the flag HAVE_DSHOW is set. I seem to remember having the same problem with the last version of OpenCV I've been using until I rebuilt it making sure the DirectShow version was enabled.



I experienced the same problem. My Vaio Webcam LED is on but no image on the screen. Then I tried to export the first frame to a JPEG file and its working. Then I tried to insert a delay of 33ms before capture any frame, this time it works like a charm. Hope this'll help.



Here's an article I wrote some time back. It uses the videoInput library to get input from webcams. It uses DirectX, so it works with almost every webcam out there. Capturing images with DirectX



Once you create the cv::VideoCapture you should give an integer not a string (since string implies the input is a file).


To open the default camera, open the stream with


cv::VideoCapture capture(0); 

and it will work fine.



CMAKE GUI, MSVC++10E, Vista 32bit, OpenCV2.2


It looks like HAVE_VIDEOINPUT/WITH_VIDEOINPUT option doesn't work.


However adding: /D HAVE_DSHOW /D HAVE_VIDEOINPUT to CMAKE_CXX_FLAGS, and CMAKE_C_FLAGS did the trick for me (there will be warns due to macro redefinitions).


0 commentaires:

Enregistrer un commentaire