2012-11-15 15 views
5

मेरे पास दो वेब कैम हैं जिनके साथ मैं चित्र लेना चाहता हूं। निम्नलिखित कोड पूरा करते हैं कि:क्या 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') 

लेकिन मेरे (Logitech) कैमरे पर यह काम नहीं करता है, और मैं इस आउटपुट प्राप्त कमांड लाइन (Ubuntu 12.04, अजगर 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 और चल रहा है:

[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

करने वाली पहली चीज़ - नवीनतम संस्करण डाउनलोड करें और स्रोत से बनाएं। यह एक सक्रिय परियोजना प्रतीत होता है। http://sourceforge.net/p/libwebcam/wiki/Home/ – avishayp

+1

क्या यह वेबकैम के मॉडल पर निर्भर नहीं होगा? आप उस वेबकैम के विशिष्ट मॉडल नंबर का उल्लेख करके शुरू कर सकते हैं जिसमें आपको समस्याएं आ रही हैं। यह हो सकता है कि यह मॉडल आपको मैन्युअल रूप से फोकस को समायोजित करने की अनुमति न दे। – jozzas

+0

मॉडल लॉजिटेक एचडी प्रो वेबकैम सी 9 20 है, और यह फोकस सुविधा का समर्थन करता है। – Delta

उत्तर

8

निष्पादित इस

sudo apt-get install v4l-utils 

और अजगर में

os.system('v4l2-ctl -d 0 -c focus_auto=0') 
os.system('v4l2-ctl -d 0 -c focus_absolute=250') 
012:

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

उत्पादन देता है

संबंधित मुद्दे

 संबंधित मुद्दे