예제 #1
0
    def __init__(self, width, height, dev):
        self.fd = os.open(dev, os.O_RDWR)

        cap = v4l2.v4l2_capability()
        fcntl.ioctl(self.fd, v4l2.VIDIOC_QUERYCAP, cap)

        fmt = v4l2.v4l2_format()
        fmt.type = v4l2.V4L2_BUF_TYPE_VIDEO_CAPTURE
        fmt.fmt.pix.pixelformat = v4l2.V4L2_PIX_FMT_MJPEG
        fmt.fmt.pix.width = width
        fmt.fmt.pix.height = height
        fcntl.ioctl(self.fd, v4l2.VIDIOC_S_FMT, fmt)

        bufreq = v4l2.v4l2_requestbuffers()
        bufreq.type = v4l2.V4L2_BUF_TYPE_VIDEO_CAPTURE
        bufreq.memory = v4l2.V4L2_MEMORY_MMAP
        bufreq.count = 1
        fcntl.ioctl(self.fd, v4l2.VIDIOC_REQBUFS, bufreq)

        self.info = v4l2.v4l2_buffer()
        self.info.type = v4l2.V4L2_BUF_TYPE_VIDEO_CAPTURE
        self.info.memory = v4l2.V4L2_MEMORY_MMAP
        self.info.index = 0
        fcntl.ioctl(self.fd, v4l2.VIDIOC_QUERYBUF, self.info)

        self.buf = mmap.mmap(
                self.fd,
                self.info.length,
                mmap.MAP_SHARED,
                mmap.PROT_READ | mmap.PROT_WRITE,
                self.info.m.offset)

        self.type = ctypes.c_uint32(self.info.type)
예제 #2
0
파일: camera.py 프로젝트: kkavod/groupcam
 def _get_device_capability(self):
     capability = v4l2.v4l2_capability()
     ret_code = fcntl.ioctl(self._device_fd,
                            v4l2.VIDIOC_QUERYCAP, capability)
     if ret_code == -1:
         fail_with_error("Unable to get device capabilities")
     return capability
예제 #3
0
    def get_info(self):
        caps = v4l2.v4l2_capability()
        fcntl.ioctl(self, v4l2.VIDIOC_QUERYCAP, caps)

        caps._driver = array_to_string(caps.driver)
        caps._card = array_to_string(caps.card)
        caps._bus_info = array_to_string(caps.bus_info)

        l = []
        c = caps.capabilities
        if c & v4l2.V4L2_CAP_VIDEO_CAPTURE: l.append('video_capture')
        if c & v4l2.V4L2_CAP_VIDEO_OUTPUT: l.append('video_output')
        if c & v4l2.V4L2_CAP_VIDEO_OVERLAY: l.append('video_overlay')
        if c & v4l2.V4L2_CAP_VBI_CAPTURE: l.append('vbi_capture')
        if c & v4l2.V4L2_CAP_VBI_OUTPUT: l.append('vbi_output')
        if c & v4l2.V4L2_CAP_SLICED_VBI_CAPTURE: l.append('sliced_vbi_capture')
        if c & v4l2.V4L2_CAP_SLICED_VBI_OUTPUT: l.append('sliced_vbi_output')
        if c & v4l2.V4L2_CAP_RDS_CAPTURE: l.append('rds_capture')
        if c & v4l2.V4L2_CAP_VIDEO_OUTPUT_OVERLAY:
            l.append('video_output_overlay')
        if c & v4l2.V4L2_CAP_HW_FREQ_SEEK: l.append('hw_freq_seek')
        if c & v4l2.V4L2_CAP_RDS_OUTPUT: l.append('rds_output')
        if c & v4l2.V4L2_CAP_TUNER: l.append('tuner')
        if c & v4l2.V4L2_CAP_AUDIO: l.append('audio')
        if c & v4l2.V4L2_CAP_RADIO: l.append('radio')
        if c & v4l2.V4L2_CAP_MODULATOR: l.append('modulator')
        if c & v4l2.V4L2_CAP_READWRITE: l.append('readwrite')
        if c & v4l2.V4L2_CAP_ASYNCIO: l.append('asyncio')
        if c & v4l2.V4L2_CAP_STREAMING: l.append('streaming')
        caps._caps = l

        return caps
예제 #4
0
파일: tests.py 프로젝트: Cobra-Kao/ropon
def test_VIDIOC_G_CTRL(fd):
    cap = v4l2.v4l2_capability()
    ioctl(fd, v4l2.VIDIOC_QUERYCAP, cap)
    
    def test_get_control(fd, input_or_output):
        for queryctrl in get_device_controls(fd):
            if queryctrl.flags & v4l2.V4L2_CTRL_FLAG_DISABLED:
                continue

            control = v4l2.v4l2_control(queryctrl.id)
            ioctl(fd, v4l2.VIDIOC_G_CTRL, control)

            assert control.value >= queryctrl.minimum
            assert control.value <= queryctrl.maximum

    # general test
    foreach_device_input(fd, test_get_control)

    # test for each input devices
    if cap.capabilities & v4l2.V4L2_CAP_VIDEO_CAPTURE:
        foreach_device_input(fd, test_get_control)

    # test for each output devices
    if cap.capabilities & v4l2.V4L2_CAP_VIDEO_OUTPUT:
        foreach_device_output(fd, test_get_control)
예제 #5
0
def send_loopback(images):
    d = os.open("/dev/video1", os.O_RDWR)
    cap = v.v4l2_capability()
    ioctl(d, v.VIDIOC_QUERYCAP, cap)
    vid_format = v.v4l2_format()
    #ioctl(d, v.VIDIOC_G_FMT, vid_format)
    vid_format.type = v.V4L2_BUF_TYPE_VIDEO_OUTPUT
    vid_format.fmt.pix.width = 640
    #vid_format.fmt.pix.sizeimage=1036800
    vid_format.fmt.pix.height = 480
    vid_format.fmt.pix.pixelformat = v.V4L2_PIX_FMT_RGB24
    vid_format.fmt.pix.field = v.V4L2_FIELD_NONE
    vid_format.fmt.pix.colorspace = v.V4L2_COLORSPACE_SRGB
    ioctl(d, v.VIDIOC_S_FMT, vid_format)
    print "frame size", vid_format.fmt.pix.sizeimage, len(
        images[0][0]), images[0][1]
    raw_input()
    counter = 0
    old_t = time()
    fps_period = 1. / 29.97
    while True:
        counter += 1
        #print "Image", counter
        for img, size in images:
            t = time()
            delta_time = t - old_t
            print "Delta", delta_time,
            old_t = t
            if delta_time < fps_period:
                print "sleeping a bit"
                sleep(fps_period - delta_time)
            os.write(d, img)
예제 #6
0
def test_VIDIOC_QUERYCTRL_simp(fd):
    cap = v4l2.v4l2_capability()
    fcntl.ioctl(fd, v4l2.VIDIOC_QUERYCAP, cap)

    def test_controls(fd, input_or_output):
        '''
        Control: Red Balance
          Range: 0 - 1023
        Control: Blue Balance
          Range: 0 - 1023
        Control: Exposure
          Range: 0 - 800
        Control: Gain
          Range: 0 - 511
        '''
        print 'enum: original'
        # original enumeration method
        for queryctrl in get_device_controls(fd):
            print 'Control: %s' % queryctrl.name
            print '  Range: %d - %d' % (queryctrl.minimum, queryctrl.maximum)

    if not cap.capabilities & v4l2.V4L2_CAP_VIDEO_CAPTURE:
        raise Exception("Device doesn't support capture")

    print '*' * 80
    print 'Capture'
    foreach_device_input(fd, test_controls)

    print '*' * 80
예제 #7
0
def test_VIDIOC_ENUMSTD(fd):
    cap = v4l2.v4l2_capability()
    ioctl(fd, v4l2.VIDIOC_QUERYCAP, cap)

    def assert_valid_standard(index, std):
        # assert std.index == index
        assert valid_v4l2_std_id(std.id)
        assert valid_string(std.name)
        assert std.frameperiod.numerator != 0
        assert std.frameperiod.denominator != 0
        assert std.framelines != 0
        assert std.reserved[0] == 0
        assert std.reserved[1] == 0
        assert std.reserved[2] == 0
        assert std.reserved[3] == 0

    # The spec says that a different set of standards may be yielded
    # by different inputs and outputs, so we repeat the test for each
    # available input and output of the current device.

    def test_available_standards(fd, input_or_output):
        for index, std in enumerate(get_device_standards(fd)):
            assert_valid_standard(index, std)

    # test for input devices
    if cap.capabilities & v4l2.V4L2_CAP_VIDEO_CAPTURE:
        foreach_device_input(fd, test_available_standards)

    # test for output devices
    if cap.capabilities & v4l2.V4L2_CAP_VIDEO_OUTPUT:
        foreach_device_output(fd, test_available_standards)
예제 #8
0
def test_VIDIOC_G_CTRL(fd):
    cap = v4l2.v4l2_capability()
    ioctl(fd, v4l2.VIDIOC_QUERYCAP, cap)

    def test_get_control(fd, input_or_output):
        for queryctrl in get_device_controls(fd):
            if queryctrl.flags & v4l2.V4L2_CTRL_FLAG_DISABLED:
                continue

            control = v4l2.v4l2_control(queryctrl.id)
            ioctl(fd, v4l2.VIDIOC_G_CTRL, control)

            assert control.value >= queryctrl.minimum
            assert control.value <= queryctrl.maximum

    # general test
    foreach_device_input(fd, test_get_control)

    # test for each input devices
    if cap.capabilities & v4l2.V4L2_CAP_VIDEO_CAPTURE:
        foreach_device_input(fd, test_get_control)

    # test for each output devices
    if cap.capabilities & v4l2.V4L2_CAP_VIDEO_OUTPUT:
        foreach_device_output(fd, test_get_control)
예제 #9
0
def RefreshCamList(
):  #Function to refresh the list of available Webcams and Arduinoes
    #Some local empty lists are initialised
    CamList = []
    AddressList = []
    CamDict = {}
    ArduinoList = []
    DeviceList = os.listdir(
        "/dev")  #it will return a list of the contents inside /dev
    for i in DeviceList:
        temp = i
        if (temp[:5] == 'video'):
            AddressList.append(i)  #the video devices are added to CamList
    for i in AddressList:
        vd = open("/dev/" + i, 'rw')
        cp = v4l2.v4l2_capability()
        fcntl.ioctl(vd, v4l2.VIDIOC_QUERYCAP, cp)
        CamList.append(cp.card)
        CamDict[
            cp.
            card] = i  #appends the data to the dictionary in the format "Logitech":"video1"

    for i in DeviceList:
        temp = i
        if (temp[:6] == 'ttyACM'):
            ArduinoList.append(i)
    VideoDeviceNumber = len(
        CamList) - 1  #Default Camera is the external webcam
    BoardNumber = len(ArduinoList)  #Default Arduino is the first one
    return VideoDeviceNumber, CamList, CamDict, ArduinoList, BoardNumber
예제 #10
0
def test_VIDIOC_S_STD(fd):
    cap = v4l2.v4l2_capability()
    ioctl(fd, v4l2.VIDIOC_QUERYCAP, cap)

    def test_set_standard(fd, input_or_output):
        original_std_id = v4l2.v4l2_std_id()
        try:
            ioctl(fd, v4l2.VIDIOC_G_STD, original_std_id)
        except IOError as e:
            assert e.errno == errno.EINVAL
            return

        for std in get_device_standards(fd):
            std_id = v4l2.v4l2_std_id(std.id)
            ioctl(fd, v4l2.VIDIOC_S_STD, std_id)

        bad_std_id = v4l2.v4l2_std_id(1 << 31)
        try:
            ioctl(fd, v4l2.VIDIOC_S_STD, bad_std_id)
        except IOError as e:
            assert e.errno == errno.EINVAL

        ioctl(fd, v4l2.VIDIOC_S_STD, original_std_id)

    # test for input devices
    if cap.capabilities & v4l2.V4L2_CAP_VIDEO_CAPTURE:
        foreach_device_input(fd, test_set_standard)

    # test for output devices
    if cap.capabilities & v4l2.V4L2_CAP_VIDEO_OUTPUT:
        foreach_device_output(fd, test_set_standard)
예제 #11
0
파일: tests.py 프로젝트: Cobra-Kao/ropon
def test_VIDIOC_ENUMSTD(fd):
    cap = v4l2.v4l2_capability()
    ioctl(fd, v4l2.VIDIOC_QUERYCAP, cap)

    def assert_valid_standard(index, std):
        # assert std.index == index
        assert valid_v4l2_std_id(std.id)
        assert valid_string(std.name)
        assert std.frameperiod.numerator != 0
        assert std.frameperiod.denominator != 0
        assert std.framelines != 0
        assert std.reserved[0] == 0
        assert std.reserved[1] == 0
        assert std.reserved[2] == 0
        assert std.reserved[3] == 0

    # The spec says that a different set of standards may be yielded
    # by different inputs and outputs, so we repeat the test for each
    # available input and output of the current device.

    def test_available_standards(fd, input_or_output):
        for index, std in enumerate(get_device_standards(fd)):
            assert_valid_standard(index, std)

    # test for input devices
    if cap.capabilities & v4l2.V4L2_CAP_VIDEO_CAPTURE:
        foreach_device_input(fd, test_available_standards)

    # test for output devices
    if cap.capabilities & v4l2.V4L2_CAP_VIDEO_OUTPUT:
        foreach_device_output(fd, test_available_standards)
예제 #12
0
def send_loopback(images):
    d=os.open("/dev/video1", os.O_RDWR)
    cap=v.v4l2_capability()
    ioctl(d, v.VIDIOC_QUERYCAP, cap)
    vid_format=v.v4l2_format()
    #ioctl(d, v.VIDIOC_G_FMT, vid_format)
    vid_format.type=v.V4L2_BUF_TYPE_VIDEO_OUTPUT
    vid_format.fmt.pix.width=640
    #vid_format.fmt.pix.sizeimage=1036800
    vid_format.fmt.pix.height=480
    vid_format.fmt.pix.pixelformat=v.V4L2_PIX_FMT_RGB24
    vid_format.fmt.pix.field=v.V4L2_FIELD_NONE
    vid_format.fmt.pix.colorspace=v.V4L2_COLORSPACE_SRGB
    ioctl(d, v.VIDIOC_S_FMT, vid_format)
    print "frame size", vid_format.fmt.pix.sizeimage, len(images[0][0]), images[0][1]
    raw_input()
    counter=0
    old_t=time()
    fps_period=1./29.97
    while True:
        counter+=1
        #print "Image", counter
        for img, size in images:
            t=time()
            delta_time=t-old_t
            print "Delta", delta_time,
            old_t=t
            if delta_time<fps_period:
                print "sleeping a bit"
                sleep(fps_period-delta_time)
            os.write(d, img)
예제 #13
0
def query_driver(dev):
    try:
        cp = v4l2.v4l2_capability()
        fcntl.ioctl(dev, v4l2.VIDIOC_QUERYCAP, cp)
        return cp.driver
    except Exception:
        return "unknown"
예제 #14
0
def test_VIDIOC_S_EXT_CTRLS(fd):
    cap = v4l2.v4l2_capability()
    ioctl(fd, v4l2.VIDIOC_QUERYCAP, cap)

    for class_ in (v4l2.V4L2_CTRL_CLASS_USER, v4l2.V4L2_CTRL_CLASS_MPEG,
                   v4l2.V4L2_CTRL_CLASS_CAMERA):

        def set_controls(fd, input_or_output):
            # first we get the controls through enumeration
            queryctrls = list(get_device_controls_by_class(fd, class_))

            control_array = (v4l2.v4l2_ext_control * len(queryctrls))()
            for index, queryctrl in enumerate(queryctrls):
                control_array[index].id = queryctrl.id
            ext_controls = v4l2.v4l2_ext_controls(class_, len(queryctrls))
            ext_controls.controls = control_array

            # we store the original values so we can set them back later
            try:
                ioctl(fd, v4l2.VIDIOC_G_EXT_CTRLS, ext_controls)
            except IOError as e:
                assert e.errno == errno.EINVAL
                assert not queryctrls
                return
            original_values = [(c.value, c.value64) for c in control_array]

            # set to minimum value
            for index, control in enumerate(control_array):
                control.value = queryctrls[index].minimum
                control.value64 = queryctrls[index].minimum
            ioctl(fd, v4l2.VIDIOC_S_EXT_CTRLS, ext_controls)

            # test invalid control
            if queryctrls:
                control_array[-1].value = 1 << 31
                control_array[-1].value64 = 1 << 32
                try:
                    ioctl(fd, v4l2.VIDIOC_S_EXT_CTRLS, ext_controls)
                except IOError as e:
                    # the driver may either prune the value or raise
                    # ERANGE if control value is out of bounds
                    assert e.errno == errno.ERANGE
                    assert ext_controls.error_idx == len(control_array) - 1

            # set back original values
            for index, control in enumerate(control_array):
                control.value = original_values[index][0]
                control.value64 = original_values[index][1]
            ioctl(fd, v4l2.VIDIOC_S_EXT_CTRLS, ext_controls)

        # general test
        foreach_device_input(fd, set_controls)

        # test for each input devices
        if cap.capabilities & v4l2.V4L2_CAP_VIDEO_CAPTURE:
            foreach_device_input(fd, set_controls)

        # test for each output devices
        if cap.capabilities & v4l2.V4L2_CAP_VIDEO_OUTPUT:
            foreach_device_output(fd, set_controls)
예제 #15
0
파일: tests.py 프로젝트: PSC-SR/robotpy
def test_VIDIOC_S_CTRL(fd):
    cap = v4l2.v4l2_capability()
    ioctl(fd, v4l2.VIDIOC_QUERYCAP, cap)
    
    def test_set_control(fd, input_or_output):
        for queryctrl in get_device_controls(fd):
            if queryctrl.flags & v4l2.V4L2_CTRL_FLAG_DISABLED:
                continue

            original_control = v4l2.v4l2_control(queryctrl.id)
            ioctl(fd, v4l2.VIDIOC_G_CTRL, original_control)

            control = v4l2.v4l2_control(queryctrl.id, queryctrl.default)
            ioctl(fd, v4l2.VIDIOC_S_CTRL, control)
            control.value = queryctrl.minimum + queryctrl.step
            ioctl(fd, v4l2.VIDIOC_S_CTRL, control)

            control.value = queryctrl.minimum - queryctrl.step
            try:
                ioctl(fd, v4l2.VIDIOC_S_CTRL, control)
            except IOError, e:
                assert e.errno in (
                    errno.ERANGE, errno.EINVAL, errno.EIO)
            control.value = queryctrl.maximum + queryctrl.step
            try:
                ioctl(fd, v4l2.VIDIOC_S_CTRL, control)
            except IOError, e:
                assert e.errno in (
                    errno.ERANGE, errno.EINVAL, errno.EIO)
            if queryctrl.step > 1:
                control.value = queryctrl.default + queryctrl.step - 1
                try:
                    ioctl(fd, v4l2.VIDIOC_S_CTRL, control)
                except IOError, e:
                    assert e.errno == errno.ERANGE
예제 #16
0
    def print_capabilities(self):

        capability = _v4l2.v4l2_capability()
        print(("get capabilities result", (fcntl.ioctl(self._video_device,
                                                       _v4l2.VIDIOC_QUERYCAP,
                                                       capability))))
        print(("capabilities", hex(capability.capabilities)))
        print(("v4l2 driver: {}".format(capability.driver)))
예제 #17
0
def list_v4l2_cameras():
    for index in range(64):
        device_path = "/dev/video%d" % (index)
        if os.path.exists(device_path):
            vd = open(device_path, 'rw') 
            cp = v4l2.v4l2_capability() 
            fcntl.ioctl(vd, v4l2.VIDIOC_QUERYCAP, cp) 
            print("%s %s %s %s" % (cp.card, device_path, cp.driver, cp.bus_info))
            vd.close()
예제 #18
0
파일: tests.py 프로젝트: Cobra-Kao/ropon
def test_VIDIOC_G_OUTPUT(fd):
    cap = v4l2.v4l2_capability()
    ioctl(fd, v4l2.VIDIOC_QUERYCAP, cap)

    if not cap.capabilities & v4l2.V4L2_CAP_VIDEO_OUTPUT:
        # test does not apply for this device
        return

    index = v4l2.c_int()
    ioctl(fd, v4l2.VIDIOC_G_OUTPUT, index)
예제 #19
0
def test_VIDIOC_G_OUTPUT(fd):
    cap = v4l2.v4l2_capability()
    ioctl(fd, v4l2.VIDIOC_QUERYCAP, cap)

    if not cap.capabilities & v4l2.V4L2_CAP_VIDEO_OUTPUT:
        # test does not apply for this device
        return

    index = v4l2.c_int()
    ioctl(fd, v4l2.VIDIOC_G_OUTPUT, index)
예제 #20
0
 def video_loop(self):
     camera_devices = {}
     videos = glob('/dev/video*')
     for video in videos:
         with open(video, 'w') as path:
             dev = v4l2.v4l2_capability()
             ioctl(path, v4l2.VIDIOC_QUERYCAP, dev)
             dev.interface = video
             iot_device = IoTDevice(dev, 'video')
             camera_devices[dev.bus_info.decode('utf-8')] = iot_device
     return camera_devices
예제 #21
0
파일: driver.py 프로젝트: Vauxoo/odoo
 def video_loop(self):
     camera_devices = {}
     videos = glob('/dev/video*')
     for video in videos:
         with open(video, 'w') as path:
             dev = v4l2.v4l2_capability()
             ioctl(path, v4l2.VIDIOC_QUERYCAP, dev)
             dev.interface = video
             iot_device = IoTDevice(dev, 'video')
             camera_devices[dev.bus_info.decode('utf-8')] = iot_device
     return camera_devices
예제 #22
0
 def Capability(self):
   cp = v4l2.v4l2_capability()
   xioctl(self.vd, v4l2.VIDIOC_QUERYCAP, cp)
   if self.verbose :
     print '--Capability '
     print '  + driver:', cp.driver
     print '  + card:', cp.card
     print '  + bus info:', cp.bus_info
     print '  + VIDEO_CAPture:', hex(cp.capabilities&v4l2.V4L2_CAP_VIDEO_CAPTURE)
     print '  + STREAMING', hex(cp.capabilities&v4l2.V4L2_CAP_STREAMING)
   return cp.card 
예제 #23
0
	def camInit(self):
		pygame.camera.init()
		camlist = pygame.camera.list_cameras()
		pygame.quit()
		i=0
		for item in camlist:
			vd = open(item, 'r')
			cp = v4l2.v4l2_capability()
			fcntl.ioctl(vd, v4l2.VIDIOC_QUERYCAP, cp)
			CameraDialog.search[cp.card] = int(item[len(item)-1])
			CameraDialog.CameraComboboxChoices.append(cp.card)
			i=i+1
예제 #24
0
 def print_capability(self):
     cp = v4l2.v4l2_capability()
     fcntl.ioctl(self.fd, v4l2.VIDIOC_QUERYCAP, cp)
     print(cp.driver)
     print("Draiver:", "".join((chr(c) for c in cp.driver)))
     print("Name:", "".join((chr(c) for c in cp.card)))
     print("Is a video capture device?",
           bool(cp.capabilities & v4l2.V4L2_CAP_VIDEO_CAPTURE))
     print("Supports read() call?",
           bool(cp.capabilities & v4l2.V4L2_CAP_READWRITE))
     print("Supports streaming?",
           bool(cp.capabilities & v4l2.V4L2_CAP_STREAMING))
예제 #25
0
 def init_device(self):
     cap = v4l2.v4l2_capability()
     fmt = v4l2.v4l2_format()
     
     ioctl(self.fd, v4l2.VIDIOC_QUERYCAP, cap)
     
     if not (cap.capabilities & v4l2.V4L2_CAP_VIDEO_CAPTURE):
         raise Exception("{} is not a video capture device".format(self.device_name))
     
     fmt.type = v4l2.V4L2_BUF_TYPE_VIDEO_CAPTURE
     ioctl(self.fd, v4l2.VIDIOC_G_FMT, fmt)
     
     self.init_mmap()
예제 #26
0
def open_video_device(path="/dev/video0"):
    device = None

    if os.path.exists(path):
        # binary, unbuffered write
        device = open(path, "wb", 0)
        capability = v4l2.v4l2_capability()
        fcntl.ioctl(device, v4l2.VIDIOC_QUERYCAP, capability)
        print("Opened %s with %s: " % (path, capability.driver))
    else:
        print("Could not open %s" % path)

    return device
예제 #27
0
파일: tests.py 프로젝트: PSC-SR/robotpy
def test_VIDIOC_G_STD(fd):
    cap = v4l2.v4l2_capability()
    ioctl(fd, v4l2.VIDIOC_QUERYCAP, cap)

    def test_get_standard(fd, input_or_output):
        std_id = v4l2.v4l2_std_id()
        try:
            ioctl(fd, v4l2.VIDIOC_G_STD, std_id)
        except IOError, e:
            assert e.errno == errno.EINVAL
            # input/output may not support a standard
            return
        assert valid_v4l2_std_id(std_id.value)
예제 #28
0
파일: tests.py 프로젝트: PSC-SR/robotpy
def test_VIDIOC_QUERYSTD(fd):
    cap = v4l2.v4l2_capability()
    ioctl(fd, v4l2.VIDIOC_QUERYCAP, cap)

    def test_query_standard(fd, input_):
        std_id = v4l2.v4l2_std_id()
        try:
            ioctl(fd, v4l2.VIDIOC_QUERYSTD, std_id)
        except IOError, e:
            # this ioctl might not be supported on this device
            assert e.errno == errno.EINVAL
            return
        assert valid_v4l2_std_id(std_id.value)
예제 #29
0
 def findDummyCamera(self):
     for i in range(10):
         try:
             fd = open('/dev/video{}'.format(i), 'wb')
             cp = v4l2.v4l2_capability()
             fcntl.ioctl(fd, v4l2.VIDIOC_QUERYCAP, cp)
             if cp.driver.decode() == 'v4l2 loopback':
                 return fd
             fd.close()
         except:
             pass
     print('dummy camera notfound')
     return None
예제 #30
0
def open_video_device(path="/dev/video0"):
    device = None

    if os.path.exists(path):
        # binary, unbuffered write
        device = open(path, "wb", 0)
        capability = v4l2.v4l2_capability()
        fcntl.ioctl(device, v4l2.VIDIOC_QUERYCAP, capability)
        print "Opened %s with %s: " % (path, capability.driver)
    else:
        print "Could not open %s" % path

    return device
예제 #31
0
파일: tests.py 프로젝트: Cobra-Kao/ropon
def test_VIDIOC_S_EXT_CTRLS(fd):
    cap = v4l2.v4l2_capability()
    ioctl(fd, v4l2.VIDIOC_QUERYCAP, cap)

    for class_ in (
        v4l2.V4L2_CTRL_CLASS_USER,
        v4l2.V4L2_CTRL_CLASS_MPEG,
        v4l2.V4L2_CTRL_CLASS_CAMERA):

        def set_controls(fd, input_or_output):
            # first we get the controls through enumeration
            queryctrls = list(get_device_controls_by_class(fd, class_))

            control_array = (v4l2.v4l2_ext_control * len(queryctrls))()
            for index, queryctrl in enumerate(queryctrls):
                control_array[index].id = queryctrl.id
            ext_controls = v4l2.v4l2_ext_controls(class_, len(queryctrls))
            ext_controls.controls = control_array

            # we store the original values so we can set them back later
            try:
                ioctl(fd, v4l2.VIDIOC_G_EXT_CTRLS, ext_controls)
            except IOError, e:
                assert e.errno == errno.EINVAL
                assert not queryctrls
                return
            original_values = [(c.value, c.value64) for c in control_array]

            # set to minimum value
            for index, control in enumerate(control_array):
                control.value = queryctrls[index].minimum
                control.value64 = queryctrls[index].minimum
            ioctl(fd, v4l2.VIDIOC_S_EXT_CTRLS, ext_controls)

            # test invalid control
            if queryctrls:
                control_array[-1].value = 1 << 31
                control_array[-1].value64 = 1 << 32
                try:
                    ioctl(fd, v4l2.VIDIOC_S_EXT_CTRLS, ext_controls)
                except IOError, e:
                    # the driver may either prune the value or raise
                    # ERANGE if control value is out of bounds
                    assert e.errno == errno.ERANGE
                    assert ext_controls.error_idx == len(control_array) - 1

            # set back original values
            for index, control in enumerate(control_array):
                control.value = original_values[index][0]
                control.value64 = original_values[index][1]
            ioctl(fd, v4l2.VIDIOC_S_EXT_CTRLS, ext_controls)
예제 #32
0
    def getCameraName(self):

        if os.path.exists("/dev/video%d" % self.number_of_video_device):

            device = '/dev/video%d' % self.number_of_video_device
            with open(device, 'r') as vd:
                try:
                    cp = v4l2.v4l2_capability()
                    fcntl.ioctl(vd, v4l2.VIDIOC_QUERYCAP, cp)
                    return cp.card
                except:
                    return 'unknown'
        else:
            return 'No camera found'
예제 #33
0
파일: tests.py 프로젝트: PSC-SR/robotpy
def test_VIDIOC_S_INPUT(fd):
    cap = v4l2.v4l2_capability()
    ioctl(fd, v4l2.VIDIOC_QUERYCAP, cap)

    if not cap.capabilities & v4l2.V4L2_CAP_VIDEO_CAPTURE:
        # test does not apply for this device
        return

    index = v4l2.c_int(0)
    try:
        ioctl(fd, v4l2.VIDIOC_S_INPUT, index)
    except IOError, e:
        assert e.errno == errno.EBUSY
        return
예제 #34
0
	def getCameraName(self):

		if  os.path.exists("/dev/video%d" % self.number_of_video_device):

			device = '/dev/video%d' % self.number_of_video_device
			with open(device, 'r') as vd:
				try:
					cp = v4l2.v4l2_capability()
					fcntl.ioctl(vd, v4l2.VIDIOC_QUERYCAP, cp)
					return cp.card
				except:
					return 'unknown'
		else:
			return 'No camera found'
예제 #35
0
        def _check_capability(self):
            cap = v4l2.v4l2_capability()

            ioctl(self.camera, v4l2.VIDIOC_QUERYCAP, cap)

            assert 0 < len(cap.driver)
            assert valid_string(cap.card)
            # bus_info is allowed to be an empty string
            assert valid_string(cap.bus_info)
            assert valid_capabilities(cap.capabilities)
            assert cap.reserved[0] == 0
            assert cap.reserved[1] == 0
            assert cap.reserved[2] == 0
            assert cap.reserved[3] == 0
예제 #36
0
    def init_device(self):
        cap = v4l2.v4l2_capability()
        fmt = v4l2.v4l2_format()

        ioctl(self.fd, v4l2.VIDIOC_QUERYCAP, cap)

        if not (cap.capabilities & v4l2.V4L2_CAP_VIDEO_CAPTURE):
            raise Exception("{} is not a video capture device".format(
                self.device_name))

        fmt.type = v4l2.V4L2_BUF_TYPE_VIDEO_CAPTURE
        ioctl(self.fd, v4l2.VIDIOC_G_FMT, fmt)

        self.init_mmap()
예제 #37
0
파일: tests.py 프로젝트: Cobra-Kao/ropon
def test_VIDIOC_QUERYCAP(fd):
    cap = v4l2.v4l2_capability()

    ioctl(fd, v4l2.VIDIOC_QUERYCAP, cap)

    assert 0 < len(cap.driver)
    assert valid_string(cap.card)
    # bus_info is allowed to be an empty string
    assert valid_string(cap.bus_info)
    assert valid_capabilities(cap.capabilities)
    assert cap.reserved[0] == 0
    assert cap.reserved[1] == 0
    assert cap.reserved[2] == 0
    assert cap.reserved[3] == 0
예제 #38
0
파일: tests.py 프로젝트: PSC-SR/robotpy
def test_VIDIOC_QUERYCTRL(fd):
    cap = v4l2.v4l2_capability()
    ioctl(fd, v4l2.VIDIOC_QUERYCAP, cap)

    def assert_valid_queryctrl(queryctrl):
        assert queryctrl.type & (
            v4l2.V4L2_CTRL_TYPE_INTEGER |
            v4l2.V4L2_CTRL_TYPE_BOOLEAN |
            v4l2.V4L2_CTRL_TYPE_MENU |
            v4l2.V4L2_CTRL_TYPE_BUTTON |
            v4l2.V4L2_CTRL_TYPE_INTEGER64 |
            v4l2.V4L2_CTRL_TYPE_CTRL_CLASS)
        assert valid_string(queryctrl.name)
        assert queryctrl.minimum < queryctrl.maximum
        assert queryctrl.step > 0
        if queryctrl.flags:
            assert queryctrl.flags & (
                v4l2.V4L2_CTRL_FLAG_DISABLED |
                v4l2.V4L2_CTRL_FLAG_GRABBED |
                v4l2.V4L2_CTRL_FLAG_READ_ONLY |
                v4l2.V4L2_CTRL_FLAG_UPDATE |
                v4l2.V4L2_CTRL_FLAG_INACTIVE |
                v4l2.V4L2_CTRL_FLAG_SLIDER)
        assert queryctrl.reserved[0] == 0
        assert queryctrl.reserved[1] == 0

    def test_controls(fd, input_or_output):
        # original enumeration method
        for queryctrl in get_device_controls(fd):
            assert_valid_queryctrl(queryctrl)

        # enumeration by control class
        for class_ in (
            v4l2.V4L2_CTRL_CLASS_USER,
            v4l2.V4L2_CTRL_CLASS_MPEG,
            v4l2.V4L2_CTRL_CLASS_CAMERA):
            for queryctrl in get_device_controls_by_class(fd, class_):
                assert_valid_queryctrl(queryctrl)

    # general test
    foreach_device_input(fd, test_controls)

    # test for each input devices
    if cap.capabilities & v4l2.V4L2_CAP_VIDEO_CAPTURE:
        foreach_device_input(fd, test_controls)

    # test for each output devices
    if cap.capabilities & v4l2.V4L2_CAP_VIDEO_OUTPUT:
        foreach_device_output(fd, test_controls)
예제 #39
0
파일: tests.py 프로젝트: Cobra-Kao/ropon
def test_VIDIOC_S_OUTPUT(fd):
    cap = v4l2.v4l2_capability()
    ioctl(fd, v4l2.VIDIOC_QUERYCAP, cap)

    if not cap.capabilities & v4l2.V4L2_CAP_VIDEO_OUTPUT:
        # test does not apply for this device
        return

    index = v4l2.c_int(0)
    ioctl(fd, v4l2.VIDIOC_S_OUTPUT, index)

    index.value = 1 << 31
    try:
        ioctl(fd, v4l2.VIDIOC_S_OUTPUT, index)
    except IOError, e:
        assert e.errno == errno.EINVAL
예제 #40
0
 def v4l_init(self):
     self.d=os.open(self.v4l_device, os.O_RDWR)
     cap=v.v4l2_capability()
     ioctl(self.d, v.VIDIOC_QUERYCAP, cap)
     vid_format=v.v4l2_format()
     #ioctl(d, v.VIDIOC_G_FMT, vid_format)
     vid_format.type=v.V4L2_BUF_TYPE_VIDEO_OUTPUT
     vid_format.fmt.pix.width=720
     vid_format.fmt.pix.sizeimage=1036800
     vid_format.fmt.pix.height=480
     vid_format.fmt.pix.pixelformat=v.V4L2_PIX_FMT_YUYV
     vid_format.fmt.pix.field=v.V4L2_FIELD_NONE
     vid_format.fmt.pix.colorspace=v.V4L2_COLORSPACE_SRGB
     ioctl(self.d, v.VIDIOC_S_FMT, vid_format)
     print "frame size", vid_format.fmt.pix.sizeimage, len(self.s_packets)
     self.old_t=time()
예제 #41
0
def test_VIDIOC_S_OUTPUT(fd):
    cap = v4l2.v4l2_capability()
    ioctl(fd, v4l2.VIDIOC_QUERYCAP, cap)

    if not cap.capabilities & v4l2.V4L2_CAP_VIDEO_OUTPUT:
        # test does not apply for this device
        return

    index = v4l2.c_int(0)
    ioctl(fd, v4l2.VIDIOC_S_OUTPUT, index)

    index.value = 1 << 31
    try:
        ioctl(fd, v4l2.VIDIOC_S_OUTPUT, index)
    except IOError as e:
        assert e.errno == errno.EINVAL
예제 #42
0
 def v4l_init(self):
     self.d = os.open(self.v4l_device, os.O_RDWR)
     cap = v.v4l2_capability()
     ioctl(self.d, v.VIDIOC_QUERYCAP, cap)
     vid_format = v.v4l2_format()
     #ioctl(d, v.VIDIOC_G_FMT, vid_format)
     vid_format.type = v.V4L2_BUF_TYPE_VIDEO_OUTPUT
     vid_format.fmt.pix.width = 720
     vid_format.fmt.pix.sizeimage = 1036800
     vid_format.fmt.pix.height = 480
     vid_format.fmt.pix.pixelformat = v.V4L2_PIX_FMT_YUYV
     vid_format.fmt.pix.field = v.V4L2_FIELD_NONE
     vid_format.fmt.pix.colorspace = v.V4L2_COLORSPACE_SRGB
     ioctl(self.d, v.VIDIOC_S_FMT, vid_format)
     print "frame size", vid_format.fmt.pix.sizeimage, len(self.s_packets)
     self.old_t = time()
예제 #43
0
def test_VIDIOC_TRY_EXT_CTRLS(fd):
    cap = v4l2.v4l2_capability()
    ioctl(fd, v4l2.VIDIOC_QUERYCAP, cap)

    for class_ in (v4l2.V4L2_CTRL_CLASS_USER, v4l2.V4L2_CTRL_CLASS_MPEG,
                   v4l2.V4L2_CTRL_CLASS_CAMERA):

        def try_controls(fd, input_or_output):
            # first we get the controls through enumeration
            queryctrls = list(get_device_controls_by_class(fd, class_))

            # try sane values
            control_array = (v4l2.v4l2_ext_control * len(queryctrls))()
            for index, queryctrl in enumerate(queryctrls):
                control_array[index].id = queryctrl.id
                control_array[index].value = queryctrl.default
            ext_controls = v4l2.v4l2_ext_controls(class_, len(queryctrls))
            ext_controls.controls = control_array
            try:
                ioctl(fd, v4l2.VIDIOC_TRY_EXT_CTRLS, ext_controls)
            except IOError as e:
                # driver may raise EINVAL if the control array has a
                # length of zero
                assert e.errno == errno.EINVAL
                assert not queryctrls
                return

            # try invalid values
            for index, control in enumerate(control_array):
                control.value = queryctrls[index].maximum + 1
                control.value64 = queryctrls[index].maximum + 1
            try:
                ioctl(fd, v4l2.VIDIOC_TRY_EXT_CTRLS, ext_controls)
            except IOError as e:
                assert e.errno == errno.EINVAL
                assert ext_controls.error_idx != 0

        # general test
        foreach_device_input(fd, try_controls)

        # test for each input devices
        if cap.capabilities & v4l2.V4L2_CAP_VIDEO_CAPTURE:
            foreach_device_input(fd, try_controls)

        # test for each output devices
        if cap.capabilities & v4l2.V4L2_CAP_VIDEO_OUTPUT:
            foreach_device_output(fd, try_controls)
예제 #44
0
	def __init__(self):
		self.available = False
		self.cp = None
		self.device = None
		self.fmt = None
		self.reqbuf = None
		self.imagebuffers = []
		
		try:
			fd = os.open('/dev/video0', os.O_RDWR)
			self.device = open(fd, 'wb+', buffering=0)
			
			self.available = True
			self.cp = v4l2.v4l2_capability()
			fcntl.ioctl(self.device, v4l2.VIDIOC_QUERYCAP, self.cp)
		except:
			pass
예제 #45
0
def RefreshCamList():
    CamList = []
    AddressList = []
    CamDict = {}
    DeviceList = os.listdir(
        "/dev")  #it will return a list of the contents inside /dev
    for i in DeviceList:
        temp = i
        if (temp[:5] == 'video'):
            AddressList.append(i)  #the video devices are added to CamList
    for i in AddressList:
        vd = open("/dev/" + i, 'rw')
        cp = v4l2.v4l2_capability()
        fcntl.ioctl(vd, v4l2.VIDIOC_QUERYCAP, cp)
        CamList.append(cp.card)
        CamDict[cp.card] = i
    return CamList, CamDict
예제 #46
0
def test_VIDIOC_QUERYSTD(fd):
    cap = v4l2.v4l2_capability()
    ioctl(fd, v4l2.VIDIOC_QUERYCAP, cap)

    def test_query_standard(fd, input_):
        std_id = v4l2.v4l2_std_id()
        try:
            ioctl(fd, v4l2.VIDIOC_QUERYSTD, std_id)
        except IOError as e:
            # this ioctl might not be supported on this device
            assert e.errno == errno.EINVAL
            return
        assert valid_v4l2_std_id(std_id.value)

    # test for input devices
    if cap.capabilities & v4l2.V4L2_CAP_VIDEO_CAPTURE:
        foreach_device_input(fd, test_query_standard)
예제 #47
0
파일: tests.py 프로젝트: Cobra-Kao/ropon
def test_VIDIOC_G_EXT_CTRLS(fd):
    cap = v4l2.v4l2_capability()
    ioctl(fd, v4l2.VIDIOC_QUERYCAP, cap)

    for class_ in (
        v4l2.V4L2_CTRL_CLASS_USER,
        v4l2.V4L2_CTRL_CLASS_MPEG,
        v4l2.V4L2_CTRL_CLASS_CAMERA):

        def get_controls(fd, input_or_output):
            # first we get the controls through enumeration
            # note, currently not distinguishing by disabled flag.
            queryctrls = list(get_device_controls_by_class(fd, class_))

            control_array = (v4l2.v4l2_ext_control * len(queryctrls))()
            for index, queryctrl in enumerate(queryctrls):
                control_array[index].id = queryctrl.id
            ext_controls = v4l2.v4l2_ext_controls(class_, len(queryctrls))
            ext_controls.controls = control_array

            try:
                ioctl(fd, v4l2.VIDIOC_G_EXT_CTRLS, ext_controls)
            except IOError, e:
                assert e.errno == errno.EINVAL
                assert not queryctrls
                return

            assert ext_controls.error_idx == 0
            assert ext_controls.reserved[0] == 0
            assert ext_controls.reserved[1] == 0
            for index, control in enumerate(control_array):
                assert control.value >= queryctrls[index].minimum
                assert control.value <= queryctrls[index].maximum

        # general test
        foreach_device_input(fd, get_controls)

        # test for each input devices
        if cap.capabilities & v4l2.V4L2_CAP_VIDEO_CAPTURE:
            foreach_device_input(fd, get_controls)

        # test for each output devices
        if cap.capabilities & v4l2.V4L2_CAP_VIDEO_OUTPUT:
            foreach_device_output(fd, get_controls)
예제 #48
0
파일: tests.py 프로젝트: Cobra-Kao/ropon
def test_VIDIOC_ENUMOUTPUT(fd):
    cap = v4l2.v4l2_capability()
    ioctl(fd, v4l2.VIDIOC_QUERYCAP, cap)

    if not cap.capabilities & v4l2.V4L2_CAP_VIDEO_OUTPUT:
        # test does not apply for this device
        return

    def assert_valid_output(fd, output):
        # assert output.index == index
        assert valid_string(output.name)
        assert output.type & (
            v4l2.V4L2_OUTPUT_TYPE_MODULATOR | v4l2.V4L2_OUTPUT_TYPE_ANALOG |
            v4l2.V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY)
        assert output.audioset < 32
        # assert output.modulator ?
        assert valid_v4l2_std_id(output.std)
        assert output.reserved == 0

    foreach_device_output(fd, assert_valid_ouput)
예제 #49
0
파일: tests.py 프로젝트: Cobra-Kao/ropon
def test_VIDIOC_S_STD(fd):
    cap = v4l2.v4l2_capability()
    ioctl(fd, v4l2.VIDIOC_QUERYCAP, cap)

    def test_set_standard(fd, input_or_output):
        original_std_id = v4l2.v4l2_std_id()
        try:
            ioctl(fd, v4l2.VIDIOC_G_STD, original_std_id)
        except IOError, e:
            assert e.errno == errno.EINVAL
            return

        for std in get_device_standards(fd):
            std_id = v4l2.v4l2_std_id(std.id)
            ioctl(fd, v4l2.VIDIOC_S_STD, std_id)

        bad_std_id = v4l2.v4l2_std_id(1 << 31)
        try:
            ioctl(fd, v4l2.VIDIOC_S_STD, bad_std_id)
        except IOError, e:
            assert e.errno == errno.EINVAL
예제 #50
0
파일: tests.py 프로젝트: Cobra-Kao/ropon
def test_VIDIOC_QUERYMENU(fd):
    cap = v4l2.v4l2_capability()
    ioctl(fd, v4l2.VIDIOC_QUERYCAP, cap)

    def test_query_menu(fd, input_or_output):
        for queryctrl in get_device_controls(fd):
            if queryctrl.type == v4l2.V4L2_CTRL_TYPE_MENU:
                for querymenu in get_device_controls_menu(fd, queryctrl):
                    assert valid_string(querymenu.name)
                    assert querymenu.reserved == 0
        
    # general test
    foreach_device_input(fd, test_query_menu)

    # test for each input devices
    if cap.capabilities & v4l2.V4L2_CAP_VIDEO_CAPTURE:
        foreach_device_input(fd, test_query_menu)

    # test for each output devices
    if cap.capabilities & v4l2.V4L2_CAP_VIDEO_OUTPUT:
        foreach_device_output(fd, test_query_menu)
예제 #51
0
파일: tests.py 프로젝트: Cobra-Kao/ropon
def test_VIDIOC_TRY_EXT_CTRLS(fd):
    cap = v4l2.v4l2_capability()
    ioctl(fd, v4l2.VIDIOC_QUERYCAP, cap)

    for class_ in (
        v4l2.V4L2_CTRL_CLASS_USER,
        v4l2.V4L2_CTRL_CLASS_MPEG,
        v4l2.V4L2_CTRL_CLASS_CAMERA):

        def try_controls(fd, input_or_output):
            # first we get the controls through enumeration
            queryctrls = list(get_device_controls_by_class(fd, class_))

            # try sane values
            control_array = (v4l2.v4l2_ext_control * len(queryctrls))()
            for index, queryctrl in enumerate(queryctrls):
                control_array[index].id = queryctrl.id
                control_array[index].value = queryctrl.default
            ext_controls = v4l2.v4l2_ext_controls(class_, len(queryctrls))
            ext_controls.controls = control_array
            try:
                ioctl(fd, v4l2.VIDIOC_TRY_EXT_CTRLS, ext_controls)
            except IOError, e:
                # driver may raise EINVAL if the control array has a
                # length of zero
                assert e.errno == errno.EINVAL
                assert not queryctrls
                return

            # try invalid values
            for index, control in enumerate(control_array):
                control.value = queryctrls[index].maximum + 1
                control.value64 = queryctrls[index].maximum + 1
            try:
                ioctl(fd, v4l2.VIDIOC_TRY_EXT_CTRLS, ext_controls)
            except IOError, e:
                assert e.errno == errno.EINVAL
                assert ext_controls.error_idx != 0
예제 #52
0
파일: tests.py 프로젝트: Cobra-Kao/ropon
def test_VIDIOC_ENUMINPUT(fd):
    cap = v4l2.v4l2_capability()
    ioctl(fd, v4l2.VIDIOC_QUERYCAP, cap)

    if not cap.capabilities & v4l2.V4L2_CAP_VIDEO_CAPTURE:
        # test does not apply for this device
        return

    def assert_valid_input(fd, input_):
        # assert input_.index == index
        assert valid_string(input_.name)
        assert input_.type & (
            v4l2.V4L2_INPUT_TYPE_CAMERA | v4l2.V4L2_INPUT_TYPE_TUNER)
        assert input_.audioset < 32
        assert valid_v4l2_std_id(input_.std)
        if input_.status:
            assert valid_input_status(status)
        assert input_.reserved[0] == 0
        assert input_.reserved[1] == 0
        assert input_.reserved[2] == 0
        assert input_.reserved[3] == 0

    foreach_device_input(fd, assert_valid_input)
예제 #53
0
	def _getSupportedResolutions(self):
		"""Query the camera for supported resolutions for a given pixel_format.
		Data is returned in a list of dictionaries with supported pixel
		formats as the following example shows:
		resolution['pixelformat'] = "YUYV"
		resolution['description'] = "(YUV 4:2:2 (YUYV))"
		resolution['resolutions'] = [[width, height], [640, 480], [1280, 720] ]

		If we are unable to gather any information from the driver, then we
		return YUYV and 640x480 which seems to be a safe default. Per the v4l2
		spec the ioctl used here is experimental but seems to be well supported.
		"""
		try:

			device = '/dev/video%d' % self.number_of_video_device
			supported_formats = self.__getPixelFormats(device)

			if not supported_formats:
				resolution = {}
				#resolution['description'] = "YUYV"
				#resolution['pixelformat'] = "YUYV"
				#resolution['resolutions'] = [[640, 480]]
				#resolution['pixelformat_int'] = v4l2.v4l2_fmtdesc().pixelformat
				supported_formats.append(resolution)
				return None

			for supported_format in supported_formats:
			    resolutions = []
			    framesize = v4l2.v4l2_frmsizeenum()
			    framesize.index = 0
			    framesize.pixel_format = supported_format['pixelformat_int']
			    with open(device, 'r') as vd:
			        try:
						cp = v4l2.v4l2_capability()
						fcntl.ioctl(vd, v4l2.VIDIOC_QUERYCAP, cp)
						self.cameraName = cp.card

						while fcntl.ioctl(vd,v4l2.VIDIOC_ENUM_FRAMESIZES,framesize) == 0:
							if framesize.type == v4l2.V4L2_FRMSIZE_TYPE_DISCRETE:
								resolutions.append([framesize.discrete.width,
								framesize.discrete.height])
								# for continuous and stepwise, let's just use min and
								# max they use the same structure and only return
								# one result
							elif framesize.type == v4l2.V4L2_FRMSIZE_TYPE_CONTINUOUS or framesize.type == v4l2.V4L2_FRMSIZE_TYPE_STEPWISE:

								if hasattr(framesize.stepwise, 'max_width'):
									max_width = framesize.stepwise.max_width
   							 	else:
									max_width = framesize.stepwise.max_height

								width = framesize.stepwise.min_width
								height = framesize.stepwise.min_height

								stepWidth = framesize.stepwise.step_width
								stepHeight = framesize.stepwise.step_height
								
								widthCounter = 1
								heightCounter = 1

								"""while width <= max_width:
									while height <= framesize.stepwise.max_height:
										resolutions.append([width,height])
										height = height * stepHeight
										
									width = width * stepWidth
									height = framesize.stepwise.min_height
								"""


								########## Low resolution #########
								if(self._calcMCD(640,stepWidth) == stepWidth):
									if(self._calcMCD(480,stepHeight) == stepHeight):
										resolutions.append([640L,480L])

								########## High resolution #########
								if(self._calcMCD(1280L,stepWidth) == stepWidth):
									if(self._calcMCD(720L,stepHeight) == stepHeight):
										resolutions.append([1280L,720L])

								break
							framesize.index = framesize.index + 1
			        except IOError as e:
			            # EINVAL is the ioctl's way of telling us that there are no
			            # more formats, so we ignore it
			            if e.errno != errno.EINVAL: 
			                self._logger.error("Unable to determine supported framesizes (resolutions), this may be a driver issue.") 
			                return None
예제 #54
0
 def __init__( self, parent ):
     wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = u"SimpleShow", pos = wx.DefaultPosition, size = wx.Size( -1,-1 ), style = wx.DEFAULT_FRAME_STYLE ^ wx.MAXIMIZE_BOX ^ wx.RESIZE_BORDER|wx.TAB_TRAVERSAL)
     
     
     pygame.camera.init()
     camlist = pygame.camera.list_cameras()
     pygame.quit()
     
     ChooseCameraChoices = list()
     i=0
     for item in camlist:
         vd = open(item, 'r')
         cp = v4l2.v4l2_capability()
         fcntl.ioctl(vd, v4l2.VIDIOC_QUERYCAP, cp)
         search[cp.card] = int(item[len(item)-1])
         ChooseCameraChoices.append(cp.card)
         i=i+1
         
     self.SetSizeHintsSz( wx.DefaultSize, wx.Size( -1,-1 ) )
     
     BSizer = wx.BoxSizer( wx.VERTICAL )
     
     self.ChooseCamera = wx.ComboBox( self, wx.ID_ANY, u"Select Camera", wx.DefaultPosition, wx.DefaultSize, ChooseCameraChoices, wx.CB_READONLY)
     BSizer.Add( self.ChooseCamera, 1, wx.ALL|wx.EXPAND, 5 )
     
     self.m_staticline2 = wx.StaticLine( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL )
     BSizer.Add( self.m_staticline2, 0, wx.EXPAND |wx.ALL, 5 )
     
     self.PictureShow = wx.StaticBitmap( self, wx.ID_ANY, wx.BitmapFromImage(img), wx.DefaultPosition, wx.DefaultSize, 0 )
     self.PictureShow.SetMinSize( wx.Size( 640,480 ) )
     
     BSizer.Add( self.PictureShow, 0, wx.ALL, 5 )
     
     self.m_staticline1 = wx.StaticLine( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL )
     BSizer.Add( self.m_staticline1, 0, wx.EXPAND |wx.ALL, 5 )
     
     ApplyFeatureChoices = [ u"c", u"d" ]
     self.ApplyFeature = wx.ComboBox( self, wx.ID_ANY, u"Select Feature", wx.Point( -1,-1 ), wx.DefaultSize, ApplyFeatureChoices, 0 )
     BSizer.Add( self.ApplyFeature, 1, wx.ALL|wx.EXPAND, 5 )
     
     self.m_staticline3 = wx.StaticLine( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL )
     BSizer.Add( self.m_staticline3, 0, wx.EXPAND |wx.ALL, 5 )
     
     GridSizer = wx.GridSizer( 0, 2, 0, 0 )
     
     self.saveButton = wx.Button( self, wx.ID_ANY, u"Save", wx.DefaultPosition, wx.DefaultSize, 0 )
     GridSizer.Add( self.saveButton, 0, wx.ALL|wx.ALIGN_RIGHT, 5 )
     
     self.SelectDirectory = wx.DirPickerCtrl( self, wx.ID_ANY, u"/home/sushilthe", u"Select a folder", wx.DefaultPosition, wx.DefaultSize, wx.DIRP_DEFAULT_STYLE )
     GridSizer.Add( self.SelectDirectory, 0, wx.ALL, 5 )
     
     
     BSizer.Add( GridSizer, 0, wx.EXPAND, 5 )
     
     
     self.SetSizer( BSizer )
     self.Layout()
     BSizer.Fit( self )
     self.FileMenuBar = wx.MenuBar( 0 )
     self.FileMenu = wx.Menu()
     self.AboutMenu = wx.MenuItem( self.FileMenu, wx.ID_ABOUT, u"About", u"About this app", wx.ITEM_NORMAL )
     self.FileMenu.AppendItem( self.AboutMenu )
     
     self.FileMenu.AppendSeparator()
     
     self.ExitMenu = wx.MenuItem( self.FileMenu, wx.ID_EXIT, u"Exit", u"Exit this app", wx.ITEM_NORMAL )
     self.FileMenu.AppendItem( self.ExitMenu )
     
     self.FileMenuBar.Append( self.FileMenu, u"File" ) 
     
     self.SetMenuBar( self.FileMenuBar )
     
     
     self.Centre( wx.BOTH )
 
     # Connect Events
     self.Bind(wx.EVT_MENU, self.OnAbout, self.AboutMenu)
     self.Bind(wx.EVT_MENU, self.OnExit, self.ExitMenu)
     self.ChooseCamera.Bind( wx.EVT_COMBOBOX, self.capture )
예제 #55
0
    def __init__(self):
        self.W = 1920
        self.H = 1080
        self.controls = {}
        #open
        l.debug("open")
        self.vd = open('/dev/video0', 'rb+', buffering=0)

        #queryctrl/g_ctrl
        qctrl = v4l2.v4l2_queryctrl()
        ctrl = v4l2.v4l2_control()
        #brightness
        qctrl.id = v4l2.V4L2_CID_BRIGHTNESS
        try:
            fcntl.ioctl(self.vd, v4l2.VIDIOC_QUERYCTRL, qctrl)
            ctrl.id = qctrl.id
            fcntl.ioctl(self.vd, v4l2.VIDIOC_G_CTRL, ctrl)
        except:
            l.error("QUERYCTRL/G_CTRL failed")
        self.controls["brightness"] = (ctrl.id, ctrl.value, qctrl.minimum, qctrl.maximum)
        #exposure
        qctrl.id = v4l2.V4L2_CID_EXPOSURE_ABSOLUTE
        try:
            fcntl.ioctl(self.vd, v4l2.VIDIOC_QUERYCTRL, qctrl)
            ctrl.id = qctrl.id
            fcntl.ioctl(self.vd, v4l2.VIDIOC_G_CTRL, ctrl)
        except:
            l.error("QUERYCTRL/G_CTRL failed")
        self.controls["exposure"] = (ctrl.id, ctrl.value, qctrl.minimum, qctrl.maximum)

        #querycap
        l.debug("querycap")
        cp = v4l2.v4l2_capability()
        fcntl.ioctl(self.vd, v4l2.VIDIOC_QUERYCAP, cp)

        #s_fmt
        l.debug("s_fmt")
        fmt = v4l2.v4l2_format()
        fmt.type = v4l2.V4L2_BUF_TYPE_VIDEO_CAPTURE
        fmt.fmt.pix.width = self.W
        fmt.fmt.pix.height = self.H
        fmt.fmt.pix.pixelformat = v4l2.V4L2_PIX_FMT_SBGGR10
        fmt.fmt.pix.field = v4l2.V4L2_FIELD_NONE
        fcntl.ioctl(self.vd, v4l2.VIDIOC_S_FMT, fmt)

        #g_fmt
        fmt = v4l2.v4l2_format()
        fmt.type = v4l2.V4L2_BUF_TYPE_VIDEO_CAPTURE
        fcntl.ioctl(self.vd, v4l2.VIDIOC_G_FMT, fmt)
        self.framesize = fmt.fmt.pix.sizeimage

        #reqbufs
        l.debug("reqbufs")
        req = v4l2.v4l2_requestbuffers()
        req.type = v4l2.V4L2_BUF_TYPE_VIDEO_CAPTURE
        req.memory = v4l2.V4L2_MEMORY_MMAP
        req.count = 4
        fcntl.ioctl(self.vd, v4l2.VIDIOC_REQBUFS, req)

        self.buffers = []
        for ind in range(req.count):
            #querybufs
            buf = v4l2.v4l2_buffer()
            buf.type = v4l2.V4L2_BUF_TYPE_VIDEO_CAPTURE
            buf.memory = v4l2.V4L2_MEMORY_MMAP
            buf.index = ind
            fcntl.ioctl(self.vd, v4l2.VIDIOC_QUERYBUF, buf)

            #mmap
            mm = mmap.mmap(self.vd.fileno(), buf.length, mmap.MAP_SHARED, mmap.PROT_READ | mmap.PROT_WRITE, offset=buf.m.offset)
            self.buffers.append(mm)

            #qbuf
            fcntl.ioctl(self.vd, v4l2.VIDIOC_QBUF, buf)

        #streamon
        l.debug("streamon")
        buf_type = v4l2.v4l2_buf_type(v4l2.V4L2_BUF_TYPE_VIDEO_CAPTURE)
        fcntl.ioctl(self.vd, v4l2.VIDIOC_STREAMON, buf_type)

        #select
        l.debug("select")
        t0 = time.time()
        max_t = 1
        ready_to_read, ready_to_write, in_error = ([], [], [])
        while len(ready_to_read) == 0 and time.time() - t0 < max_t:
            ready_to_read, ready_to_write, in_error = select.select([self.vd], [], [], max_t)