15

In my robotic vision project, I need to detect a marker of a moving object but motion causes blurring effect in the image. Deconvolution methods are quite slow. So I was thinking to use a higher fps camera. Someone said I don't need higher fps, instead I need shorter exposure time.

OpenCV's Python Interface cv2 provides a method to change the settings of camera but it does not include "Exposure Time" or "Shutter Speed" settings. I'm also afraid that webcams don't even support this kind of settings.

Any other thoughts about:

Eliminating blurring effect using camera setting?

OR

Restoration of Image with real-time performance?

OR

Any suggestion about a low cost camera for real-time robotic applications?

Muhammad Abdullah
  • 876
  • 2
  • 8
  • 26
  • Which camera is it? – 101 Aug 16 '17 at 12:18
  • Logitech C310 USB WebCam – Muhammad Abdullah Aug 16 '17 at 12:19
  • 1
    You could try `cap = cv2.VideoCapture(0); print cap.get(cv2.cv.CV_CAP_PROP_EXPOSURE)`. – 101 Aug 16 '17 at 12:21
  • What about [`CAP_PROP_EXPOSURE`](http://docs.opencv.org/trunk/d4/d15/group__videoio__flags__base.html#gaeb8dd9c89c10a5c63c139bf7c4f5704d)? – Dan Mašek Aug 16 '17 at 12:22
  • It changes exposure not exposure time/shutter speed. The resultant image becomes brighter or darker. Does not affect the blurring. – Muhammad Abdullah Aug 16 '17 at 12:24
  • The first sentence contradicts itself. Of course the brightness changes, if you expose for a shorter time, less light hits the sensor, so the image becomes darker. To compensate for that, you need better lighting (think of flash photography) ... or perhaps a more sensitive sensor. The device you are using probably doesn't allow very extensive adjustment. | As for which camera... that really needs much more detailed list of requirements (and quantitative, rather than qualitative -- what does "low cost" really mean?) – Dan Mašek Aug 16 '17 at 12:35
  • Camera cost should be less than $100. High FPS to capture a moving human. I don't know how fast a human can run,jump or fall so can't quanitfy that. Comes with a driver that allows changing the shutter,aperture and exposure settings. – Muhammad Abdullah Aug 16 '17 at 12:38
  • As for the brightness, I don't know what's the problem. Once I changed the exposure to -10 and video became totally dark but now I'm trying to run the same program again but nothing changes. ```cap.set(cv2.CAP_PROP_EXPOSURE, -10)``` ```print cap.get(cv2.CAP_PROP_EXPOSURE)``` still prints ```inf``` – Muhammad Abdullah Aug 16 '17 at 12:43
  • @DanMašek I'm able to change exposure using v4l_ctl command line tool in linux but I'm unable to do so in Python using OpenCV. The problem with command line tool is that it works when VideoCapture is open, as soon as VideoCapture is released or Program terminates it changes back to old settings. So I need to change exposure withoin my python code. – Muhammad Abdullah Aug 16 '17 at 13:01
  • You may have hit something there. Unfortunately I'm not on linux to help much with that. | To get back to the camera question, here's something to think about: You mention robotic application. What other requirements does that entail? Resolution, some FPS requirements, color/mono, size/weight requirements, interface (USB or ethernet?), power, etc. How much can you budget for lighting (that's very important). – Dan Mašek Aug 16 '17 at 13:08

2 Answers2

16

There is a method available to change properties of VideoCapture object in OpenCV which can be used to set exposure of input image.

cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_EXPOSURE, 40) 

However this parameter is not supported by all cameras. Each camera type offers a different interface to set its parameters. There are many branches in OpenCV code to support as many of them, but of course not all the possibilities are covered.

Same is the case with my camera. So I had to find a different solution. That is using v4l2_ctl utility from command line terminal.

v4l2-ctl -d /dev/video0 -c exposure_absolute=40

But this retains its value for current video session only. That means you have to start video preview first and then set this property As soon as VideoCapture is released, the exposure value is restored to default.

I wanted to control exposure within my python script, so I used subprocess module to run linux bash command. e.g.

import subprocess
subprocess.check_call("v4l2-ctl -d /dev/video0 -c exposure_absolute=40",shell=True)
Mohammed Noureldin
  • 14,913
  • 17
  • 70
  • 99
Muhammad Abdullah
  • 876
  • 2
  • 8
  • 26
  • 3
    Wow. I don't know how many incantations of `opencv python exposure webcam` or similar I searched for, but I just found this maybe 3hrs after doing this myself! For reference [here's](https://gist.github.com/jwhendy/12bf558011fe5ff58bd5849954e84af4) a gist showing a way to do a bunch of these. I'm new-ish to `python`, but I think the dict method is reasonable for cycling through lots of settings? – Hendy Oct 29 '17 at 23:34
  • thanks for sharing @Hendy ... It is a nice way to set multiple properties of video camera. – Muhammad Abdullah Oct 31 '17 at 06:31
  • 3
    What is `exposure_absolute`here? is this a time? or what is this `40` here exactly? – Mohammed Noureldin May 03 '19 at 12:10
1

For instance

I was trying with a c920 for a while whithout success, but sometimes worked, other not using this:

cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_EXPOSURE, -4) 
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 240) # after not change the exposure

But finally I realized that I was setting the width and height just after, and so I change the order and now is working fine!! Don´t blow your mind trying to disable the CAP_PROP_AUTO_EXPOSURE flag!! Its not necessary(at least with c920 on windows)!!

cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 240) # before works fine
cap.set(cv2.CAP_PROP_EXPOSURE, -4) 

By the way, the range of exposure in C920 is from -2 to -11!!(on windows 10)

Thanks a lot