mkmeral
mkmeral

Reputation: 111

Editing Camera Settings by using Opencv

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?

Upvotes: 6

Views: 12486

Answers (1)

Yu-Cheng Lin
Yu-Cheng Lin

Reputation: 481

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!

Upvotes: 10

Related Questions