2012-11-15 12 views
5

Mam dwie kamery internetowe, z którymi chcę robić zdjęcia. Następujący kod spełnia to:Czy istnieje sposób kontrolowania ostrości kamery w 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 

Ale muszę ustawić ostrość.

znalazłem te wiersze polecenia:

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 

I choć może być następujący:

import os 
os.system('command to set the focus') 

Ale na moim (Logitech) aparat nie działa, a ja się z tego wyjścia linia poleceń (Ubuntu 12,04, pyton 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' 

Edycja:

Aparat jest Logitech HD Pro Webcam C920 i prowadzenie:

uvcdynctrl --device=/dev/video1 --clist 

Daje wyjście:

[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 
+0

Pierwsza rzecz - pobierz najnowszą wersję i kompilację ze źródła. To wydaje się być aktywnym projektem. http://sourceforge.net/p/libwebcam/wiki/Home/ – avishayp

+1

Czy to nie zależy od modelu kamery internetowej? Możesz zacząć od wymienienia konkretnego numeru modelu kamery internetowej, z którą masz problemy. Być może ten model po prostu nie pozwala na ręczne dopasowanie ostrości. – jozzas

+0

Model to kamera internetowa Logitech HD Pro Webcam C920 i obsługuje funkcję ustawiania ostrości. – Delta

Odpowiedz

8

wykonać to

sudo apt-get install v4l-utils 

i w python

os.system('v4l2-ctl -d 0 -c focus_auto=0') 
os.system('v4l2-ctl -d 0 -c focus_absolute=250') 
Powiązane problemy