Ask Your Question
0

VideoCapture::read frame drops with dark pixels.

asked 2016-05-21 12:12:38 -0600

socapex gravatar image

Hello, I have a strange performance problem with a standard and very simple webcam capture prototype. I am using openCV inside Unreal engine (if that changes anything). I read() a frame from my webcam every .033s (30fps capped) at 640x480. The CPU is not a problem :)

If my webcam is pointed at light colors, mainly a white frame, the fps is at 120 (the whole app is capped at 120). But whenever I move the webcam, to record things with darker colors, the fps drops to 8 frame per second!

I've been profiling a lot, and all my cycles are coming from 1 line: cap.read(f). This is extremely strange to me, and I am going to guess maybe openCV has defaults that do image processing? Anyone has experienced this before? Should the read method be deterministic?

Thank you for any help, I am just starting out with openCV, so it could be something really simple :)

P.S. Using windows build (x64) v3.1.0. These are unmodified from the download.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2016-05-24 12:35:45 -0600

socapex gravatar image

Ok, so LBerger gave me a great lead when pointing out time exposure is at a low framerate. It seems the camera is simply lowering its' fps when exposure (gain?) is high. There doesn't seem to be a way to get the actual framerate of the cam (CV_CAP_PROP_FPS only returns the user set fps).

A hack is to lower the cam processing to 10fps instead of thirty. So when the webcam lowers its fps, you aren't stuck waiting for videocapture::read. A real solution would be a callback hookup into videocapture called when data is ready (like pretty much every audio API out there).

Since openCV doesn't seem to have that, another solution is to run the capture on a low priority thread, that can stall at read without affecting the rest of the app.

Hope this helps someone.

edit flag offensive delete link more

Comments

CV_CAP_PROP_FPS is for video file. If you want to change exposure time use CV_CAP_PROP_EXPOSURE and increase gain using CAP_PROP_GAIN. Again those method will work only if driver and hardware camera is OK. Example it does not work with Microsoft surface but works with logitech C270

LBerger gravatar imageLBerger ( 2016-05-25 01:12:53 -0600 )edit

I think you didn't see my other comment due to moderation time. But yes, I tried both and it didn't work. The webcam seems to be adjusting its' behavior at a lower level than that. I also popped-open the settings panel (can't remember the constant though), and nothing was ticked "auto".

Anyways, a callback is what we need, but not what we deserve? lol

socapex gravatar imagesocapex ( 2016-05-25 18:02:23 -0600 )edit

I think I haven't got any answer to your problem. IMHO it's a driver problem. Try to find a webcam Logitech 270 and use method set. You will see a saturate image for light region and good contrast in darker region there is no automatic adjustement with this webcam on windows 10. If you can reproduce this you have localised problem

LBerger gravatar imageLBerger ( 2016-05-26 04:13:53 -0600 )edit

Well auto gain/ auto contrast is desired for my use case (QR Code scanner). Running at 10fps is ok for that too. If I need more, I will just read on another thread. Also, I cannot choose the webcam ;)

Thx for the help though!

socapex gravatar imagesocapex ( 2016-05-26 11:44:59 -0600 )edit
1

answered 2016-05-22 08:34:26 -0600

LBerger gravatar image

Your camera must adjust contrast automatically with time exposure priority. When scene is darker time exposure is increased then 120fps is impossible because time exposure is set to 1/10s. Try to use method set with parameter CAP_PROP_GAIN in videocapture class

Sometimes automotic adjustement is disable when you call this method.

edit flag offensive delete link more

Comments

Hi, thank you so much for answering. Unfortunately that didn't work :( But auto-exposure/gain is definitely on. I've been following the lead you gave me, but so far no way to turn it off. If you have any other ideas, I'd love to hear them! :)

socapex gravatar imagesocapex ( 2016-05-24 11:18:49 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-05-21 12:11:29 -0600

Seen: 1,593 times

Last updated: May 22 '16