[英]Is there a way to control a webcam focus in pygame?
我有兩個網絡攝像頭,我想拍照。 以下代碼實現了:
import pygame
import pygame.camera
from datetime import datetime
import Image
import threading
import time
class Camera (threading.Thread):
def __init__(self, camera):
self.camera = pygame.camera.Camera(camera,(2304,1536))
self.stop = False
threading.Thread.__init__(self)
def run(self):
self.camera.start()
srf = self.camera.get_image()
img = pygame.image.tostring(srf, 'RGB')
img = Image.fromstring('RGB', srf.get_size(), img)
img.save('%s.png'%datetime.now(), 'PNG')
s = datetime.now()
pygame.init()
pygame.camera.init()
cam1 = Camera("/dev/video0")
cam2 = Camera("/dev/video1")
cam1.start()
cam2.start()
cam1.join()
cam2.join()
print datetime.now() - s
但我需要設定焦點。
我找到了這些命令行:
apt-get install uvcdynctrl
uvcdynctrl --device=/dev/video1 --clist
uvcdynctrl --device=/dev/video1 --get='Focus, Auto'
uvcdynctrl --device=/dev/video1 --set='Focus, Auto' 0
uvcdynctrl --device=/dev/video1 --set='Focus (absolute)' 20
我雖然可以使用以下內容:
import os
os.system('command to set the focus')
但在我的(羅技)相機上它不起作用,我從命令行(Ubuntu 12.04,python 2.7)獲得此輸出:
uvcdynctrl --device=/dev/video1 --set='Focus, Auto' 0
[libwebcam] Unsupported V4L2_CID_EXPOSURE_AUTO control with a non-contiguous
range of choice IDs found
[libwebcam] Invalid or unsupported V4L2 control encountered: ctrl_id = 0x009A0901, name = 'Exposure, Auto'
[libwebcam] Unsupported V4L2_CID_EXPOSURE_AUTO control with a non-contiguous
range of choice IDs found
[libwebcam] Invalid or unsupported V4L2 control encountered: ctrl_id = 0x009A0901, name = 'Exposure, Auto'
編輯:
相機是Logitech HD Pro Webcam C920
並運行:
uvcdynctrl --device=/dev/video1 --clist
給出輸出:
[libwebcam] Unsupported V4L2_CID_EXPOSURE_AUTO control with a non-contiguous
range of choice IDs found
[libwebcam] Invalid or unsupported V4L2 control encountered: ctrl_id = 0x009A0901, name = 'Exposure, Auto'
[libwebcam] Unsupported V4L2_CID_EXPOSURE_AUTO control with a non-contiguous
range of choice IDs found
[libwebcam] Invalid or unsupported V4L2 control encountered: ctrl_id = 0x009A0901, name = 'Exposure, Auto'
Listing available controls for device /dev/video1:
Brightness
Contrast
Saturation
White Balance Temperature, Auto
Gain
Power Line Frequency
White Balance Temperature
Sharpness
Backlight Compensation
Exposure (Absolute)
Exposure, Auto Priority
Pan (Absolute)
Tilt (Absolute)
Focus (absolute)
Focus, Auto
Zoom, Absolute
執行此操作
sudo apt-get install v4l-utils
並在python中
os.system('v4l2-ctl -d 0 -c focus_auto=0')
os.system('v4l2-ctl -d 0 -c focus_absolute=250')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.