OpenCV Webcam Frame Rate

I have a webcam capable of 1080p 30 frames per second, which I confirmed with VirtualDub to preview and save the video from the webcam itself.

For some reason, OpenCV will give me only 4FPS, the processor does not maximize any of the cores, so I don’t understand why? (This does not actually output the channel, but simply extracts the frames).

Does anyone with OpenCV experience know why? Maybe OpenCV doesn't use DirectShow to read from a webcam (assuming DirectShow is what you need for 30fps / 1080p - I believe it uses virtualdub). Could the fact that OpenCV reads the image into its own Mat data type be a bottleneck?

My camera is Microsoft LifeCam Studio, and my OS is Windows 7 with Visual Studios 2010.

Does anyone have any ideas?

+4
source share
2 answers

30 FPS is achieved by capturing compressed video (most likely JPEG). It seems to me that OpenCV is switching to capturing raw video, such as RGB, in which case the effective FPS is limited by the USB bandwidth. 4 FPS is the amount of data that USB can skip in the 24-bit RGB format 1920x2080 (25 MB / s).

The solution is to ensure that the capture format (media type in DirectShow terms) is compressed video with post-decompression software.

+2
source

As Roman noted, the default mode for most webcams is MJPEG compression, in order to reduce the data transfer rate that should pass through the USB connection (and, possibly, USB hubs, etc.), and / or maximize the available frame rate / resolution.

For computer vision, this is often undesirable, since we would prefer to have a lower frame rate, but not compression artifacts. In fact, it is possible to generally change the stream format (for example, to uncompressed YUV) in much the same way as, for example, the resolution is changed. Is this possible for you, depends on

  • which supports hardware
  • which of these modes supports the low-level driver (often a common USB class driver / UVC driver),
  • which of the last modes performs it through various frameworks used (for example, video for Windows / DirectX / Video4Linux2, etc.) and
  • finally, which one is supported by the video capture backend, is used in OpenCV.

Unfortunately, the answer for the latter is simply none . OpenCV has 18 (!) Different capture servers (for various platforms, for example mobile phones, OS X, Windows and Linux, often several for different versions of the basic frameworks), and although it seems that the API for changing the stream format [1], he, doesn't seem to be implemented by any backend. :-(

If you or someone else wants to work on this, you can check the OpenCV problem that I discovered about this: http://code.opencv.org/issues/3007

In my case, I researched this for some Logitech webcams, which even had different features available with low-level Windows and Linux drivers. On Linux, I unknowingly used the GStreamer OpenCV backend, which means another level of indirection - at the lower level, it always comes down to the V4L kernel API (video for Linux). Using the libv4l backend improved the situation, since it had a nice default property for some YUV stream format (albeit at a lower frame rate, which may be undesirable in other contexts). (There are even different, diverging backends for direct access to the v4l kernel API or through libv4l.)

[1] See CV_CAP_PROP_FORMAT in the API docs: http://opencv.willowgarage.com/documentation/cpp/reading_and_writing_images_and_video.html

+2
source

All Articles