简体   繁体   English

在 Linux 中禁用网络摄像头的自动对焦

[英]Disable webcam's Autofocus in Linux

I'm working in embebed system in the beagleboard.我正在使用 beagleboard 的嵌入系统。 The source code is in Python, but I import libraries from OpenCV to do image processing.源代码在 Python 中,但我从 OpenCV 导入库来进行图像处理。 Actually, I'm using the webcam Logitech c910, it's a excellent camera but it has autofocus.实际上,我正在使用网络摄像头 Logitech c910,它是一款出色的相机,但它具有自动对焦功能。 I would like to know if I can disable the autofocus from Python or any program in Linux?我想知道是否可以从 Python 或 Linux 中的任何程序禁用自动对焦?

Use program v4l2-ctl from your shell to control hardware settings on your webcam.使用 shell 中v4l2-ctl程序来控制网络摄像头上的硬件设置。 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, ie /dev/video0 .这些命令默认为您的第一个 Video4Linux 设备,即/dev/video0 If you got more than one webcam plugged in, use -d switch to select your target device.如果您插入了多个网络摄像头,请使用-d开关选择您的目标设备。


Installing v4l-utils安装 v4l-utils

Easiest way to install the utility is using your package manager, eg on Ubuntu or other Debian-based systems try:安装该实用程序的最简单方法是使用您的包管理器,例如在 Ubuntu 或其他基于 Debian 的系统上尝试:

apt-get install v4l-utils

or on Fedora, CentOS and other RPM-based distros use:或者在 Fedora、CentOS 和其他基于 RPM 的发行版上使用:

yum install v4l-utils

You can also do it in Linux with:你也可以在 Linux 中使用:

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 ).对于某些人来说,这在 Windows 中不起作用(请参阅使用 opencv-python 在 Windows 中禁用网络摄像头的自动对焦)。 In my system it does (ubuntu 14.04, V4L 2.0.2, opencv 3.4.3 ,logitech c922).在我的系统中是这样(ubuntu 14.04,V4L 2.0.2,opencv 3.4.3,logitech c922)。

In case anyone finds is useful, I've come up with a small snippet that can be added to your .bashrc .万一有人觉得有用,我想出了一个可以添加到您的.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.我将它与具有缺陷自动对焦系统的 Microsoft LifeCam HD-6000 一起使用。

Prerequisite: v4l-utils先决条件: 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您想在所有具有它的视频设备上禁用自动对焦

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM