小编Tox*_*its的帖子

如何使用cron + python定时调整屏幕亮度?

我想使用 cron 和这个脚本(http://askubuntu.com/questions/23593/use-webcam-to-sense-lighting-condition-and-adjust-screen-brightness):

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
Run Code Online (Sandbox Code Playgroud)

crontab: /30 *** sudo python /home/用户名/screen.py

然而,有两个问题:

首先,while …

cron python

4
推荐指数
1
解决办法
1837
查看次数

标签 统计

cron ×1

python ×1