Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fastest way to get frames from webcam

Tags:

opencv

webcam

I have a little wee of a problem developing one of my programs in C++ (Visual studio) - Right now im struggling with connection of multiple webcams (connected via usb cables), creating for each of them separate thread to capture frames, and separate frame for processing image.

I use OpenCV to process frames, but the problem is that i dont get a peak of webcam possibilities (it supports 25 fps, i get only 18) is there some library that i could use to get frames, than process them with OpenCV that would made frames be captured faster?

I was researching a bit and the most popular way is to use directshow to get frames and OpenCV to process them.

Do You agree? Or do You have another solution? I wouldn't be offended by some links :)

like image 788
user2058851 Avatar asked Dec 27 '22 09:12

user2058851


2 Answers

  1. DirectShow is only used, if you open your capture using the CV_CAP_DSHOW flag, like:

    VideoCapture capture( CV_CAP_DSHOW + 0 );  // 0,1,2, your cam id there
    

    (without it, it defaults to vfw )

  2. the capture already runs in a separate thread, so wrapping it with more threads won't give you any gain.

  3. another obstacle with multiple cams is the usb bandwidth, so if you got ports on the back & the front of your machine, dont plug all your cams into the same port/controller else you just saturate it

like image 167
berak Avatar answered Jan 01 '23 14:01

berak


OpenCV uses DirectShow. Using DirectShow (primary video capture API in Windows) directly will obviously get you par or better performance (and even more likely so if OpenCV is set to use Video for Windows). USB cams typically hit USB bandwidth and hence frame rate limit, using DirectShow to capture in compressed formats or in formats with less bits/pixel is the way to reach higher frame rates within the same USB bandwidth limit.

Another typical problem causing low frame rates is slow synchronous processing delaying the capture. You typically identify this by putting trivial processing into the same capture loop and seeing higher FPS compared to processing-enabled operation.

like image 25
Roman R. Avatar answered Jan 01 '23 15:01

Roman R.