5

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 :)

user2058851
  • 51
  • 1
  • 2

2 Answers2

6
  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

berak
  • 39,159
  • 9
  • 91
  • 89
4

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.

Roman R.
  • 68,205
  • 6
  • 94
  • 158
  • Thanks so much for the information, i dont want to be picky, but can You provide me with sample code for using Directshow to capture frames without any needless filters in C++? – user2058851 Feb 12 '13 at 17:30
  • The easiest (not the best, but still the easiest!) is to make a chain like this: `Capture Filter` -> `Sample Grabber Filter` -> `Null Renderer Filter`. All three are standard, and there is a lot of sample code out there. The first corresponds to a camera and you set capture format on it, the second is where you set your callback to receive individual frames. All this started will have your code called for every frame from the camera. – Roman R. Feb 12 '13 at 19:35
  • you could look at the src of VideoCapture.lib, which is what opencv is using here: [https://github.com/ofTheo/videoInput/tree/master/videoInputSrcAndDemos/libs/videoInput] – berak Feb 12 '13 at 19:39