Capturing video from SMI Grabber Device using Opencv C++ - c++

I am trying to capture a video from an SMI grabber device using opencv c++. The line VideoCapture cap(0) obtains video from web cam. How do I get the feed from the device that I have connected.

From openCV docs
VideoCapture
public VideoCapture(int device)
Parameters:
device - id of the opened video capturing device (i.e. a camera index). If there is a single camera connected, just pass 0.
As per this answer, it's not possible at the moment to enumerate devices via OpenCV however you could try passing 1 and see if the SMI device is found there.

Related

Capturing H264 with logitech C920 to OpenCV

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

Capture live video from a DSLR in C++/OpenCV

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.

Can OPENCV access a analog camera using a video capture device

I have been trying to access my analog camera via a EasyCap video capture device. Any code I try only picks the usb webcam or internal webcam. I guess that since video capture device is a video controller, opencv doesnt recognize it as a imaging device.
Can anyone conform if you cannot access analog cameras with opencv via a video capture device.
If so, then what other method can be used.
i struggled with the same problem (in my case within python instead of C++, although I am certain it will be the same root cause) and hope it helps!
the original thread + ANSWER
also relevant XKCD
Even for digital devices, OpenCV isn't good at reading them, it is good at processing them. The library has supply for generic webcams, of course; however it does not supply most of the commercial or industrial cameras.
In short, to decode, you should try using "video for linux" or "video for windows" libraries; or the device SDK itself. Since you are using a video2usb converter, you shouldn't have any problem accessing the analog camera through these software.

Is decoder automaticly added between two filter?

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.

How to write an opencv image (IplImage) to a V4L2 loopback device?

As the title says I am not sure how to write an IplImage to a V4l2 loopback device. I know how to write to a device as I have posted here How to write/pipe to a virtual webcam created by V4L2loopback module?
But now I am not sure how I can exactly write IplImage objects in to the device. If I just write the image->imageData where image is an IplImage*, when I view the device using "luvcview" the malformed frames show up for about a second then it throws the following error.
luvcview 0.2.6
SDL information:
Video driver: x11
A window manager is available
Device information:
Device path: /dev/video3
Stream settings:
Frame format: YUYV (MJPG is not supported by device)
Frame size: 520x474 (requested size 640x480 is not supported by device)
Frame rate: 30 fps
libv4l2: error dequeuing buf: Invalid argument
Unable to dequeue buffer: Invalid argument
Error grabbing
Cleanup done. Exiting ...
Could it be because I have not converted the opencv images to v4l2 format? or the v4l2 arguments does not match with the IplImage properties? If so how to do it?
If anyone knows what this error means please let me know.
I decided to post this question separately as this question is not about writing to the device its particularly about write an IplImage to the device.
Could anyone please give me a code snippet that shows how to write an IplImage to a V4l2 loopback device?
I worked out that the above issue was not an issue anymore as it seems that luvcview or skype does not fully support v4l2. But if I view the loopback device using VLC player, it works fine.