Many webcams today can take static pictures in high resolution. e.g. Logitech C920 should be able to make 16Mpx photography, while in live video mode it can produce frames only in Full HD. Is it possible to use OpenCV to get this 16Mpx photo? All examples I found only using VideoCapture or cvCaptureFromCAM which can only access the frames of live video.
Related
I’ve been trying to capture a H264 stream from my two C920 Logitech camera with OpenCV (On a Raspberry Pi 2). I have come to the conclusion that this is not possible because it is not yet implemented. I’ve looked a little in OpenCV/modules/highgui/cap_libv4l.cpp and found that the “Videocapture-function” always convert the pixelformat to BGR24. I tried to change this to h264, but only got a black screen. I guess this is because it is not being decoded the right way.
So I made a workaround using:
V4l2loopback
h264_v4l2_rtspserver
Gstreamer-0.10
(You can find the loopback and rtspserver on github)
First I setup a virtual device using v4l2loopback. Then the rtspserver captures in h264 then streams rtsp to my localhost(127.0.0.1). Then I catch it again with gstreamer and pipe it to my virtual v4l2 video device made by loopback using the “v4l2sink” option in gst-launch-0.10.
This solution works and I can actually connect to the virtual device with the opencv videocapture and get a full HD picture without overloading the cpu, but this is nowhere near a good enough solution. I get a roughly 3 second delay which is too high for my stereo vision application and it uses a ton of bandwidth.
So I was wondering if anybody knew a way that I could use the v4l2 capture program from Derek Molloys boneCV/capture program (which i know works) to capture in h264 then maybe pipe it to gst-launche-0.10 and then again pipe it to the v4l2sink for my virtual device?
(You can find the capture program here: https://github.com/derekmolloy/boneCV)
The gstreamer command I use is:
“gst-launch-0.10 rtspsrc location=rtsp://admin:pi#127.0.0.1:8554/unicast ! decodebin ! v4l2sink device=/dev/video4”
OR maybe in fact you know what I would change in the opencv highgui code to be able to capture h264 directly from my device without having to use the virtual device? That would be amazingly awesome!
Here is the links to loopback and the rtspserver that I use:
github.com/mpromonet/h264_v4l2_rtspserver
github.com/umlaeute/v4l2loopback
Sorry about the wierd links I don't have enough reputation yet to poste more links..
I don't know exactly where you need to change in the OpenCV, but very recently I started to code using video on Raspberry PI.
I'll share my findings with you.
I got this so far:
can read the C920 h264 stream directly from the camera using V4L2 API at 30 FPS (if you try to read YUYV buffers the driver has a limit of 10 fps, 5 fps or 2 fps from USB...)
can decode the stream to YUV 4:2:0 buffers using the broadcom chip from raspberry using OpenMax IL API
My Work In Progress code is at: GitHub.
Sorry about the code organization. But I think the abstraction I made is more readable than the plain V4L2 or OpenMAX code.
Some code examples:
Reading camera h264 using V4L2 Wrapper:
device.streamON();
v4l2_buffer bufferQueue;
while (!exit_requested){
//capture code
device.dequeueBuffer(&bufferQueue);
// use the h264 buffer inside bufferPtr[bufferQueue.index]
...
device.queueBuffer(bufferQueue.index, &bufferQueue);
}
device.streamOFF();
Decoding h264 using OpenMax IL:
BroadcomVideoDecode decoder;
while (!exit_requested) {
//capture code start
...
//decoding code
decoder.writeH264Buffer(bufferPtr[bufferQueue.index],bufferQueue.bytesused);
//capture code end
...
}
check out Derek Molloy on youtube. He's using a Beaglebone, but presumably ticks this box
https://www.youtube.com/watch?v=8QouvYMfmQo
My C++/OpenCV app runs well when I use a USB webcam to capture live video stream.
However, when I connect a Canon 5Dii with live video it doesn't find the camera.
The Canon utility captures the video well.
Should I use the VideoCapture cap(1)?
You should use the official Canon Digital Camera SDK to grab frames from 5D II. There are some sample apps for connecting to the camera (as a source device) from your PC and then receiving camera events/images. Keep in mind that you need to sign up and be approved by Canon to use the SDK.
I have created a c++ dll where it shows camera live streaming at panel handle with DirectShow API. My Camera is Logitech c920 Webcam. My camera offers H264 codec on the 3rd output pin.
When I use graphEdit, if I connect the Logitech Webcam 3rd output Pin to Video Mixing Render 9 1st input pin, it automaticly adds the DTV-DVD microsoft decoder between the connection like this :
Logitech HD Pro Webcam C920 [Capturer] => [VMR Input0] Video Mixing Renderer 9
(When connected become)
Logitech HD Pro Webcam C920 [Capturer] => [video Input1] Microsoft DTV-DVD Video Decoder [video Output 1] => [VMR Input0] Video Mixing Renderer 9
The quality is very nice and I have a fast video streaming rates on the active movie window.
This is where it's getting incorrect. In my code, I have directly connected the 3rd pin of capture source to vmr7 input pin (without adding dt-dvd decoder). I have also set the video settings as 1600x896 and H264 Mediatype with IAMStreamConfig.
I readed on msdn (if i have understand correctly) that directshow will automaticly put the necessary filter between two connected pins. It's working but the video quality is terrible.It looks like theres lot pixels mixed or corrupted. I also don't have any evidence that the filter as been added. Is it because i haven't programmaticaly put the decoder between them? And if it could be, how do I add this filter?
Thanks in advance and sorry for the english.
The problem is here:
if I connect the Logitech Webcam 3rd output Pin to Video Mixing Render 9
versus
I have directly connected the 3rd pin of capture source to vmr7 input pin
VMR-9 vs. VMR-7. The former is backed by Direct3D surfaces, with frames scaled smoothly by hardware. The latter, on the opposite, uses DirectDraw surfaces with scaling unavailable since Windows Vista, and the picture quality is terrible.
Use EVR as video renderer (or VMR-9) to get best picture quality.
I am using OpenCV 2.4 with C++ for image processing and video streaming . I would like to know how we can use fire-wire camera like pixilink to capture frames? I tried the VideoCapture class but it seems to work with only usb cameras unlike firewire one. If some one has done same thing with firewire camera then kindly give some guidance how to do that?
You can capture images using firewire SDK or you can also libdc1394 API. I found libdc1394 to more reliable and easy to use and there are couple of examples available to get start.
I have a built in webcam (HP) and an USB webcam. Whenever I use webcams in OpenCV, the built in webcam is used. However I want use the USB webcam. I tried disabling the built in webcam and even uninstalling the drivers, but after doing that, I get a message saying that no webcams were detected, even though the USB webcam is connected. How can I use the USB webcam instead of the built in webcam? I have searched the net top to bottom and have found no fix.
Thanks
The command CaptureFromCAM accepts an integer as its only argument which specifies the device number to use. Change this number and it will use a different device.