6

Is there any way to set camera settings (iso, focus, etc.) by using OpenCV Python? We are using computer vision on robot, but everytime angle or light changes, camera reconfigures itself so using SVM from SciKit Learn is not possible. Is there any way to stop it?

mkmeral
  • 111
  • 1
  • 2
  • 10

1 Answers1

10

Yes, there is a way to manually control a USB webcam with OpenCV. The webcam that I'm using is Logitech C525, nonetheless I think the following code is applicable to all Logitech webcams.

import cv2

cam = cv2.VideoCapture(0)

#       key value
cam.set(3 , 640  ) # width        
cam.set(4 , 480  ) # height       
cam.set(10, 120  ) # brightness     min: 0   , max: 255 , increment:1  
cam.set(11, 50   ) # contrast       min: 0   , max: 255 , increment:1     
cam.set(12, 70   ) # saturation     min: 0   , max: 255 , increment:1
cam.set(13, 13   ) # hue         
cam.set(14, 50   ) # gain           min: 0   , max: 127 , increment:1
cam.set(15, -3   ) # exposure       min: -7  , max: -1  , increment:1
cam.set(17, 5000 ) # white_balance  min: 4000, max: 7000, increment:1
cam.set(28, 0    ) # focus          min: 0   , max: 255 , increment:5

Please note that the focus value only comes at multiples of 5 (0, 5, 10, 15... 255). The ISO you mentioned should be more related to "exposure" and "gain", which affects signal intensity.

Good luck!

Yu-Cheng Lin
  • 431
  • 4
  • 7
  • Hi! i took a chronometer and output the difference of time between the beginning time and the ending time of 500 iterations. The problem is that exposure setting does not seems to slow or fasten up the process. Its kind of useless. Any help? I'm using picameraV2 – Cătălina Sîrbu Jan 16 '20 at 10:41