示例#1
0
文件: __init__.py 项目: Tyex/pupil
def Camera_List():
    '''
    Thin wrapper around list_devices to improve formatting.
    '''
    class Cam(object):
        def __init__(self, d):
            self.device = d

        @property
        def name(self):
            return self.device.friendlyName

        @property
        def src_id(self):
            return self.device.symbolicName
        
        # TODO: property bus_info

    devices = vi.DeviceList()
    _getVideoInputInstance().getListOfDevices(devices)

    cam_list = []
    for d in devices:
        cam_list.append(Cam(d))
    return cam_list
示例#2
0
def device_list():
    devices = vi.DeviceList()
    _getVideoInputInstance().getListOfDevices(devices)

    cam_list = []
    for d in devices:
        cam_list.append({'name':d.friendlyName,'uid':d.symbolicName})
    return cam_list
示例#3
0
def Camera_List():
    '''
    Thin wrapper around list_devices to improve formatting.
    '''
    devices = vi.DeviceList()
    _getVideoInputInstance().getListOfDevices(devices)

    cam_list = []
    for d in devices:
        cam_list.append(Cam(d))
    return cam_list
示例#4
0
    def _init(self, uid, size=(640,480), fps=None, timebase=None):

        devices = vi.DeviceList()
        for cam in _getVideoInputInstance().getListOfDevices(devices):
            if cam.symbolicName == uid:
                break
        if cam.symbolicName != uid:
            raise CameraCaptureError("uid for camera not found.")

        if not len(size) == 2:
            msg = ERR_INIT_FAIL + "Parameter 'size' must have length 2."
            logger.error(msg)
            raise CameraCaptureError(msg)
        # setting up device
        self.device = cam.device
        self.deviceSettings = vi.DeviceSettings()
        self.deviceSettings.symbolicLink = self.device.symbolicName
        self.deviceSettings.indexStream = 0
        self.deviceSettings.indexMediaType = 0
        self.captureSettings = vi.CaptureSettings()
        self.captureSettings.readMode = vi.ReadMode.SYNC
        self.captureSettings.videoFormat = vi.CaptureVideoFormat.RGB32
        self.stream = self.device.listStream[self.deviceSettings.indexStream]

        # collecting additional information
        if timebase == None:
            logger.debug("Capture will run with default system timebase")
            self.timebase = 0
        else:
            logger.debug("Capture will run with app wide adjustable timebase")
            self.timebase = timebase

        self.width = size[0]
        self.height = size[1]
        self.preferred_fps = fps
        self._initFrameRates()
        self._initMediaTypeId()

        self.context = _getVideoInputInstance()
        while True:
            res = self.context.setupDevice(self.deviceSettings, self.captureSettings)
            if res != vi.ResultCode.OK:
                self._failed_inits += 1
                msg = ERR_INIT_FAIL + "Error code: %d" %(res)
                if self._failed_inits < MAX_RETRY_INIT_CAMERA:
                    logger.error("Retry initializing camera: {0}/{1}: ".format(self._failed_inits, MAX_RETRY_INIT_CAMERA) + msg)
                else:
                    logger.error(msg)
                    raise CameraCaptureError(msg)
                sleep(1)
            else:
                break

        # creating frame buffer and initializing capture settings
        frame = np.empty((self.actual_height * self.actual_width * 4), dtype=np.uint8)
        self.readSetting = vi.ReadSetting()
        self.readSetting.symbolicLink = self.deviceSettings.symbolicLink
        self.readSetting.setNumpyArray(frame)
        frame.shape = (self.actual_height, self.actual_width, -1)
        self._frame = frame

        logger.debug("Successfully set up device: %s @ %dx%dpx %dfps (mediatype %d)" %(self.name, self.actual_height, self.actual_width, self.frame_rate, self.deviceSettings.indexMediaType))
        self._is_initialized = True
        self._failed_inits = 0
示例#5
0
import videoInput as vi
import numpy as np

print vi.VERSION

print "LOADED VIDEOINPUT LIB"

vin = vi.videoInput_getInstance()
assert isinstance(vin, vi.videoInput)

devices = vi.DeviceList()
vin.getListOfDevices(devices)
for d in devices:
    assert isinstance(d, vi.Device)
    print d.friendlyName, d.symbolicName
    dev = d
dev = devices[1]
assert isinstance(dev, vi.Device)
print "LOADED CAPTURE DEVICES"

deviceSettings = vi.DeviceSettings()
deviceSettings.symbolicLink = dev.symbolicName
deviceSettings.indexStream = 0
deviceSettings.indexMediaType = 195
captureSettings = vi.CaptureSettings()
captureSettings.readMode = vi.ReadMode.SYNC
captureSettings.videoFormat = vi.CaptureVideoFormat.RGB24

stream = dev.listStream[0]
assert isinstance(stream, vi.Stream)
mediaType = stream.listMediaType[195]