the code:
A simple example that works great with the main webcam (device 0):
VideoCapture cap(0); if (!cap.isOpened()) { std::cout << "Unable to read stream from specified device." << std::endl; return; } while (true) { // retrieve the frame: Mat frame; if (!cap.read(frame)) { std::cout << "Unable to retrieve frame from video stream." << std::endl; break; } // display it: imshow("MyVideo", frame); // check if Esc has been pressed: if (waitKey(1) == 27) { break; } // else continue: } cap.release();
Problem:
I have a second webcam that I would like to use. However, when I replace VideoCapture cap(0); on the VideoCapture cap(1); . , the thread opens correctly (or at least cap.isOpened() returns true ) , but calling cap.read(frame) returns false > , and I cannot find out why.
What I tried:
I'm trying to play with the VideoCapture settings a bit like a call:
cap.set(CV_CAP_PROP_FORMAT, CV_8UC3);
and random things like this, but nothing helps.
I also found this: VideoCapture :: read with an error on an uncompressed video (error No. 2281) , which seems to be resolved on version 2.4.7 .. but I just upgraded OpenCV to 2.4.8 and it still doesn't work. ..
I tried using AMCap to capture raw video from this camera, save it as aaa.avi file and built VideoCapture by calling:
VideoCapture cap("aaa.avi");
and it works (when reading from a file) ... I need real-time processing with live viewing.
HW, OS, SW details:
My HW: HP ProBook 4510s with integrated webcam that always works great
+ CANYON CNR-FWCII3 external webcam designated by the OS as βUSB Video Deviceβ (complex) OS, SW: Windows 8.1 Pro x86, Visual Studio 2012 Pro, OpenCV 2.4.8 ~ using the vc11 assembly
Questions:
- Did I miss something?
- Is there anything else I could do?
- Is there any way to get more information about what could actually be?
... the OpenCV API seems pretty bad in this case and wherever people seem to run into a similar problem, someone claimed it was an "OS / HW depnendant" as an excuse.
Any help would be appreciated.
c ++ opencv video video-capture usb
Liho
source share