Answers:
我已经改进了以前的尝试:
import opencv
import opencv.highgui
import time
import commands
def get_image():
image = opencv.highgui.cvQueryFrame(camera)
return opencv.adaptors.Ipl2PIL(image)
camera = opencv.highgui.cvCreateCameraCapture(-1)
while 1:
image = get_image()
image.thumbnail((32, 24, ))
image = tuple(ord(i) for i in image.tostring())
x = int((int((max(image) / 256.0) * 10) + 1) ** 0.5 / 3 * 10)
cmd = ("sudo su -c 'echo " + str(x) +
" > /sys/devices/virtual/backlight/acpi_video0/brightness'")
status, output = commands.getstatusoutput(cmd)
assert status is 0
这种方法有两个问题:至少在我的网络摄像头中,显示亮度永远不会低于4,因为在黑暗中摄像头无法很好地工作,并且它可能会在4到5之间跳一点。无论如何,
这是使用方法:
sudo apt-get install python-opencv
~/test.py
python test.py
我现在得到的不是平均亮度,而是小钉子的最大亮度(这是为了避免像素坏点并使其更快)。至少结合我的灯光和摄像头,它可以很好地工作!
试试看 (:
highgui
从stackoverflow.com/questions/30684661/…中没有任何内容。还有其他办法吗?
看一下RedShift项目,该项目会像F.Lux以前所做的那样根据您的地理位置更改屏幕温度。
网站上详细记录了安装和使用说明,根据您的硬件和显示器,RedShift可以带来不错的效果,使您的眼睛像“刷新”的眼睛。
要添加PPA,请按键盘上的Ctrl+ Alt+ T打开终端。打开时,运行以下命令:
sudo add-apt-repository ppa:fantasyleague0629/wildguppy
然后通过以下方式安装WildGuppy:
sudo apt-get update; sudo apt-get install wildguppy
适用于Ubuntu 14.04,Ubuntu 13.10,Ubuntu 13.04,Ubuntu 12.10和Ubuntu 12.04。
使WildGuppy在启动时运行:
运行命令以编辑配置文件。
sudo gedit ~/.config/autostart/wildguppy-gtk.desktop
出现提示时输入密码。请注意,终端在键入时不会显示您的密码,只需记住并按Enter。
打开文件后,将其粘贴在内容下方并保存。
[Desktop Entry]
Type=Application
Exec=wildguppy-gtk
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name[en_US]=WildGuppy
Name=WildGuppy
Comment[en_US]=
Comment=
/opt/wildguppy/wildguppy.py
。因此,您可以在任何发行版中使用此软件包!干杯!
我还使用OpenCV为此制作了一个C工具。您可以在https://launchpad.net/brightness上找到它(您必须自己编译)。希望对您有帮助。
您可以使用 https://github.com/Wandersalamander/Dimmer 来完全满足您的要求。
这对我有用:
#!/usr/bin/env python3
import subprocess, time
# webcam brightness if webcam doesn’t get any light
blackpoint = 0.05
# webcam brightness if webcam is fully exposed (e.g. sun at noon)
whitepoint = 0.92549
# Path to program that sets screen brightness. Takes float between 0 and 1 as
# a parameter. Should be whitelisted for sudo if this script is not run as
# root. Sample script:
#
# #!/bin/sh
# echo "($1 * 4882) / 1" | bc > /sys/class/backlight/intel_backlight/brightness
brightness_setter = "/home/bronger/bin/set_brightness.sh"
# it doen’t get any darker
minimal_brightness = 0.1
# in seconds
sleeping_time = 20
def get_brightness():
"""Returns webcam brightness as a float between 0 and 1 (boundaries
included)."""
fswebcam = subprocess.Popen(["fswebcam", "-q", "--no-banner", "--png", "0", "-"], stdout=subprocess.PIPE)
convert = subprocess.run(["convert", "png:-", "-colorspace", "gray", "-scale", "10%x10%",
"-format", "%[fx:image.maxima]", "info:"],
check=True, stdin=fswebcam.stdout, capture_output=True, text=True)
assert fswebcam.wait() == 0
brightness = float(convert.stdout)
brightness = (brightness - blackpoint) / (whitepoint - blackpoint)
brightness = max(0.0, min(1.0, brightness))
return brightness
old_brightness = None
while True:
brightness = get_brightness() ** 2
brightness = max(minimal_brightness, brightness)
if old_brightness is None or abs(brightness - old_brightness) > 0.2:
subprocess.run(["sudo", brightness_setter, str(brightness)], check=True)
old_brightness = brightness
time.sleep(sleeping_time)
我已经开发了一个可以执行此操作的C应用程序。参见https://github.com/goglecm/AutoBrightnessCam。
它用于fswebcam
拍照,可以配置systemd
为自动启动并检测笔记本电脑是否正在放电(然后启动)。