Opencv – Disable Auto Focus in Video Input Library or OpenCV

computer visionimage processingopencv

I am using Video Input library to get frames from a webcam. I want to set FOCUS of this camera in C code.

Camera has AUTO FOCUS enabled. Isn't there a way to disable autofocus and set a specific focus value.

Regards,
Saleh…

Best Answer

If you use the OpenCV 3.1.0-dev version and Python 2.7.5, the following code snipped should help you ;)

cap = cv2.VideoCapture(1) # my webcam
cap.set(3, 1280) # set the resolution
cap.set(4, 720)
cap.set(cv2.CAP_PROP_AUTOFOCUS, 0) # turn the autofocus off

With my Logitech HD Pro Webcam C920 is works fine. There are many other cool control functions inside cv2, like cv2.CAP_PROP_BRITHNESS or cv2.CAP_PROP_CONTRAST. Check out what the auto-complete is showing you ;)

Related Topic