Disable webcam's Autofocus in Linux

Use program v4l2-ctl from your shell to control hardware settings on your webcam. To turn off autofocus just do:

v4l2-ctl -c focus_auto=0

You can list all possible controls with:

v4l2-ctl -l

The commands default to your first Video4Linux device, i.e. /dev/video0. If you got more than one webcam plugged in, use -d switch to select your target device.


Installing v4l-utils

Easiest way to install the utility is using your package manager, e.g. on Ubuntu or other Debian-based systems try:

apt-get install v4l-utils

or on Fedora, CentOS and other RPM-based distros use:

yum install v4l-utils

You can also do it in Linux with:

cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_AUTOFOCUS, 0)

For some people this doesn't work in Windows (see Disable webcam's autofocus in Windows using opencv-python). In my system it does (ubuntu 14.04, V4L 2.0.2, opencv 3.4.3 ,logitech c922).