I'm working in embebed system in the beagleboard. The source code is in Python, but I import libraries from OpenCV to do image processing. Actually, I'm using the webcam Logitech c910, it's a excellent camera but it has autofocus. I would like to know if I can disable the autofocus from Python or any program in Linux?
3 Answers
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

- 10,664
- 4
- 46
- 58
-
3First, I had to `sudo apt-get install v4l-utils`. – SpeedCoder5 Mar 11 '19 at 15:11
-
2Just in case anyone else gets confused. The package `v4l-utils` package has a little 'L' character after the '4' and is not a '1'! – Matt Gosden Oct 15 '20 at 19:31
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).

- 334
- 2
- 10
In case anyone finds is useful, I've come up with a small snippet that can be added to your .bashrc
. It will detect which of your webcams has autofocus and disable it.
I'm using this with a Microsoft LifeCam HD-6000 that has a flawed autofocus system.
Prerequisite: v4l-utils
# Get a space-separated list of all the video devices available
webcams=$(ls -pd /dev/* | grep video | tr '\n' ' ')
for webcam in $webcams; do
# Check if the tested video device features autofocus
no_autofocus=$(v4l2-ctl --device=$webcam --all | grep focus)
# If it does, disable it
if [ -n "${no_autofocus}" ];
then
v4l2-ctl --device=$webcam --set-ctrl=focus_auto=0
fi
done
This snippet does certain assumptions:
- You want to disable autofocus on all the video devices featuring it

- 11
- 3