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 as 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 as 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 as e: assert e.errno == errno.ERANGE ioctl(fd, v4l2.VIDIOC_S_CTRL, original_control)
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)
def test_set_control(fd, input_or_output): for queryctrl in get_device_controls(fd): if queryctrl.flags & v4l2.V4L2_CTRL_FLAG_DISABLED: continue print 'Ctrl: %s' % queryctrl.name original_control = v4l2.v4l2_control(queryctrl.id) fcntl.ioctl(fd, v4l2.VIDIOC_G_CTRL, original_control) print ' Set: defalut' control = v4l2.v4l2_control(queryctrl.id, queryctrl.default) fcntl.ioctl(fd, v4l2.VIDIOC_S_CTRL, control) print ' Set: min' control.value = queryctrl.minimum + queryctrl.step fcntl.ioctl(fd, v4l2.VIDIOC_S_CTRL, control) control.value = queryctrl.minimum - queryctrl.step try: fcntl.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: fcntl.ioctl(fd, v4l2.VIDIOC_S_CTRL, control) except IOError, e: assert e.errno in (errno.ERANGE, errno.EINVAL, errno.EIO)
def _set_device_controls(self): queryctrl = v4l2.v4l2_queryctrl() queryctrl.id = self.CtrlId if fcntl.ioctl(self.camera, v4l2.VIDIOC_QUERYCTRL, queryctrl): print 'queryctrl.id:0x%x is not supprotted' % (queryctrl.id) else: print 'queryctrl id:0x%x,type:%d,name:%s,minimum:%d,maximum:%d,step:%d\n' % ( queryctrl.id, queryctrl.type, queryctrl.name, queryctrl.minimum, queryctrl.maximum, queryctrl.step) ctrl = v4l2.v4l2_control() ctrl.id = self.CtrlId if fcntl.ioctl(self.camera, v4l2.VIDIOC_G_CTRL, ctrl): print 'ctrl.id:0x%x is not supprotted' % (ctrl.id) else: print 'Get current control...id:0x%x,valus:%d\n' % (ctrl.id, ctrl.value) ctrl = v4l2.v4l2_control() ctrl.id = self.CtrlId ctrl.value = self.CtrlValue if fcntl.ioctl(self.camera, v4l2.VIDIOC_S_CTRL, ctrl): print 'ctrl.id:0x%x is not supprotted' % (ctrl.id) else: print 'Set control...id:0x%x,valus:%d\n' % (ctrl.id, ctrl.value) ctrl = v4l2.v4l2_control() ctrl.id = self.CtrlId if fcntl.ioctl(self.camera, v4l2.VIDIOC_G_CTRL, ctrl): print 'ctrl.id:0x%x is not supprotted' % (ctrl.id) else: print 'Check current control...id:0x%x,valus:%d\n' % (ctrl.id, ctrl.value)
def read_exposure(): vd = open("/dev/video0", "rw") cp = v4l2.v4l2_control() cp.id = v4l2.V4L2_CID_EXPOSURE fcntl.ioctl(vd, v4l2.VIDIOC_G_CTRL, cp) vd.close() return cp.value
def write_global_gain(val): vd = open("/dev/video0", "rw") cp = v4l2.v4l2_control() cp.id = v4l2.V4L2_CID_GAIN cp.value = int(val) fcntl.ioctl(vd, v4l2.VIDIOC_S_CTRL, cp) vd.close()
def read_red_gain(): vd = open("/dev/video0", "rw") cp = v4l2.v4l2_control() cp.id = v4l2.V4L2_CID_RED_BALANCE fcntl.ioctl(vd, v4l2.VIDIOC_G_CTRL, cp) vd.close() return cp.value
def write_exposure(val): vd = open("/dev/video0", "rw") cp = v4l2.v4l2_control() cp.id = v4l2.V4L2_CID_EXPOSURE cp.value = int(val) fcntl.ioctl(vd, v4l2.VIDIOC_S_CTRL, cp) vd.close()
def queryctrl_print(queryctrl): print 'Control: %s' % queryctrl.name print ' Range: %d - %d' % (queryctrl.minimum, queryctrl.maximum) control = v4l2.v4l2_control(queryctrl.id) fcntl.ioctl(fd, v4l2.VIDIOC_G_CTRL, control) print ' Id: %d' % control.id print ' Value: %d' % control.value
def SetControlValue(self, qcid, val): ctrl = v4l2.v4l2_control() ctrl.id = qcid ctrl.value = val xioctl(self.vd, v4l2.VIDIOC_S_CTRL, ctrl) if self.verbose: print '--SetControlValue' print ' + ID:', ctrl.id print ' + Value:', ctrl.value
def set_ctrl(dev, ctrl, value): sctrl = v4l2.v4l2_control() sctrl.id = ctrl.id sctrl.value = value try: fcntl.ioctl(dev, v4l2.VIDIOC_S_CTRL, sctrl) except Exception: pass
def _check_available_control(self, v4l2_control): control = v4l2.v4l2_control(v4l2_control) try: ioctl(VD, v4l2.VIDIOC_QUERYCTRL, control) except IOError: logging.exception('error setting control') return False else: return v4l2_control
def GetControlValue(self, qcid): ctrl = v4l2.v4l2_control() ctrl.id = qcid xioctl(self.vd, v4l2.VIDIOC_G_CTRL, ctrl) if self.verbose: print '--GetControl' print ' + ID:', ctrl.id print ' + Value:', ctrl.value return ctrl.value
def get_ctrl(self, ctrl_name): (idx, v, mn, mx) = self.controls[ctrl_name] ctrl = v4l2.v4l2_control() ctrl.id = idx try: fcntl.ioctl(self.vd, v4l2.VIDIOC_G_CTRL, ctrl) self.controls[ctrl_name] = (idx, ctrl.value, mn, mx) return ctrl.value except: l.error("G_CTRL failed")
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
def get_ctrl(dev, ctrl): gctrl = v4l2.v4l2_control() gctrl.id = ctrl.id try: fcntl.ioctl(dev, v4l2.VIDIOC_G_CTRL, gctrl) return gctrl.value except Exception: return None
def ctrl_get(fd, name): for queryctrl in get_device_controls(fd): if queryctrl.flags & v4l2.V4L2_CTRL_FLAG_DISABLED: continue if queryctrl.name != name: continue control = v4l2.v4l2_control(queryctrl.id) fcntl.ioctl(fd, v4l2.VIDIOC_G_CTRL, control) return control.value raise ValueError("Failed to find control %s" % name)
def set_ctrl(self, ctrl_name, val): (idx, v, mn, mx) = self.controls[ctrl_name] if val > mx: val = mx if val < mn: val = mn ctrl = v4l2.v4l2_control() ctrl.id = idx ctrl.value = val try: fcntl.ioctl(self.vd, v4l2.VIDIOC_S_CTRL, ctrl) self.controls[ctrl_name] = (idx, ctrl.value, mn, mx) l.debug("New controls: ", str(self.controls)) except: l.error("S_CTRL failed")
def ctrl_set(fd, name, value): for queryctrl in get_device_controls(fd): if queryctrl.flags & v4l2.V4L2_CTRL_FLAG_DISABLED: continue if queryctrl.name != name: continue if value < queryctrl.minimum or value > queryctrl.maximum: raise ValueError("Require %d <= %d <= %d" % (queryctrl.minimum, value, queryctrl.maximum)) control = v4l2.v4l2_control(queryctrl.id, value) fcntl.ioctl(fd, v4l2.VIDIOC_S_CTRL, control) return raise ValueError("Failed to find control %s" % name)
def __capture_image_cb(self, w): if int(self._bracketing) > 0: v4l2_control = v4l2.V4L2_CID_EXPOSURE if self._check_available_control(v4l2_control): self._control = v4l2.v4l2_control(v4l2_control) ioctl(VD, v4l2.VIDIOC_G_CTRL, self._control) self._exposure_value = self._control.value gobject.timeout_add((1000 * int(self._delay)), self.__delayed_capture_image_cb, w) # two more pictures self._bracketing_count = 2 else: gobject.timeout_add((1000 * int(self._delay)), self.__delayed_capture_image_cb, w)
def read_camera_controls( ): # CID_BASE IDs do not include all settings that v4l2-ctl -L has, check CAMERA_CLASS_BASE ID range for the rest vd = open('/dev/video0', 'rb+', buffering=0) encoding = 'utf-8' qctrl = v4l2.v4l2_queryctrl() mctrl = v4l2.v4l2_querymenu() vctrl = v4l2.v4l2_control() qctrl.id = v4l2.V4L2_CID_CAMERA_CLASS_BASE mctrl.index = 0 while qctrl.id < v4l2.V4L2_CID_PRIVACY: try: vctrl.id = qctrl.id fcntl.ioctl(vd, v4l2.VIDIOC_QUERYCTRL, qctrl) fcntl.ioctl(vd, v4l2.VIDIOC_G_CTRL, vctrl) print("Control name:", str(qctrl.name, encoding)) print("Control type, 1=int, 2=bool, 3=menu:", qctrl.type) print("Maximum:", qctrl.maximum) print("Minimum:", qctrl.minimum) print("Step:", qctrl.step) print("Default:", qctrl.default_value) print("Value:", vctrl.value) if qctrl.type == 3: # is menu while mctrl.index <= qctrl.maximum: try: # needed because sometimes index 0 doesn't exist but 1 does mctrl.id = qctrl.id fcntl.ioctl(vd, v4l2.VIDIOC_QUERYMENU, mctrl) print("Menu name:", str(qctrl.name, encoding)) print("Menu option name:", str(mctrl.name, encoding)) print("Menu option index:", mctrl.index) mctrl.index += 1 except: mctrl.index += 1 except: pass qctrl.id += 1 vd.close()
def read_base_capabalities(): vd = open('/dev/video0', 'rb+', buffering=0) cp = v4l2.v4l2_capability() encoding = 'utf-8' # basic info fcntl.ioctl(vd, v4l2.VIDIOC_QUERYCAP, cp) print(str(cp.card, encoding)) print(str(cp.driver, encoding)) print("video capture device?\t", bool(cp.capabilities & v4l2.V4L2_CAP_VIDEO_CAPTURE)) print("Supports read() call?\t", bool(cp.capabilities & v4l2.V4L2_CAP_READWRITE)) print("Supports streaming?\t", bool(cp.capabilities & v4l2.V4L2_CAP_STREAMING)) # current height, width qctrl = v4l2.v4l2_format() qctrl.type = v4l2.V4L2_BUF_TYPE_VIDEO_CAPTURE fcntl.ioctl(vd, v4l2.VIDIOC_G_FMT, qctrl) print("Width:", qctrl.fmt.pix.width) print("Height:", qctrl.fmt.pix.height) # output overview qctrl = v4l2.v4l2_fmtdesc() qctrl.type = v4l2.V4L2_BUF_TYPE_VIDEO_CAPTURE qctrl.index = 0 fcntl.ioctl(vd, v4l2.VIDIOC_ENUM_FMT, qctrl) print("Format:", str(qctrl.description, encoding)) print("Pixelformat ID:", qctrl.pixelformat) get_outputs( qctrl.pixelformat ) # pass pixelformat to read outputs, increase index for different codecs # main controls qctrl = v4l2.v4l2_queryctrl() mctrl = v4l2.v4l2_querymenu() vctrl = v4l2.v4l2_control() qctrl.id = v4l2.V4L2_CID_BASE mctrl.index = 0 while qctrl.id < v4l2.V4L2_CID_LASTP1: # LASTP1 is last item in CID_BASE try: vctrl.id = qctrl.id fcntl.ioctl(vd, v4l2.VIDIOC_QUERYCTRL, qctrl) fcntl.ioctl(vd, v4l2.VIDIOC_G_CTRL, vctrl) print("Control name:", str(qctrl.name, encoding)) print("Control type, 1=int, 2=bool, 3=menu:", qctrl.type) ''' There are more types, 4=BUTTON, 5=INTEGER64, 6=CTRL_CLASS, 7=STRING, 8=BITMASK, 9=INTEGER_MENU Not sure what to do with those, can't test ''' print("Maximum:", qctrl.maximum) print("Minimum:", qctrl.minimum) print("Step:", qctrl.step) print("Default:", qctrl.default_value) print("Value:", vctrl.value) set_value(vctrl.id) # test setting value ''' if qctrl.type == 1: # int win.label = Gtk.Label(hexpand = True, vexpand = False) win.label.set_text(str(qctrl.name, encoding)) win.label.set_size_request(-1, 35) win.label.set_halign(Gtk.Align.END) adj = Gtk.Adjustment(value = vctrl.value, lower = qctrl.minimum, upper = qctrl.maximum, step_increment = qctrl.step, page_increment = 5, page_size=0) win.scale = Gtk.Scale(orientation=Gtk.Orientation.HORIZONTAL, adjustment=adj) win.scale.set_digits(0) win.scale.set_value_pos(Gtk.PositionType.RIGHT) win.scale.set_size_request(-1, 35) win.scale.connect("value-changed", set_int_value, card, vctrl.id) win.intcontrolbox.pack_start(win.scale, False, False, 0) win.intlabelbox.pack_start(win.label, False, False, 0) ''' if qctrl.type == 3: # is menu while mctrl.index <= qctrl.maximum: try: mctrl.id = qctrl.id fcntl.ioctl(vd, v4l2.VIDIOC_QUERYMENU, mctrl) print("Menu name:", str(qctrl.name, encoding)) print("Menu option name:", str(mctrl.name, encoding)) print("Menu option index:", mctrl.index) mctrl.index += 1 except: mctrl.index += 1 except: pass qctrl.id += 1 vd.close()
def set_value(controlid): vd = open('/dev/video0', 'rb+', buffering=0) vctrl = v4l2.v4l2_control() vctrl.id = controlid vctrl.value = 0 # testing with 0, should read from widget fcntl.ioctl(vd, v4l2.VIDIOC_S_CTRL, vctrl)
import time from fcntl import ioctl vd = open('/dev/video0', 'r') # 打开视频设备文件 vd = os.open('/dev/video0', os.O_RDWR, 0) cp = v4l2.v4l2_capability() # 查询视频设备的能力 print(fcntl.ioctl(vd, v4l2.VIDIOC_QUERYCAP, cp)) print(cp.driver) # 驱动名字 print(cp.card) # 设备名字 fmt = v4l2.v4l2_fmtdesc() # 查询视频设备的能力, 支持Motion-JPEG和YUYV4:2:2 fmt.index = 1 fmt.type = v4l2.V4L2_BUF_TYPE_VIDEO_CAPTURE print(fcntl.ioctl(vd, v4l2.VIDIOC_ENUM_FMT, fmt)) print(fmt.index, fmt.description) print('------------------------------------------------') # 控制曝光 ctrl = v4l2.v4l2_control() # 括号漏了,各种报错... ctrl.id = v4l2.V4L2_CID_EXPOSURE_AUTO ctrl.value = v4l2.V4L2_EXPOSURE_MANUAL # 只能是V4L2_EXPOSURE_MANUAL 或V4L2_EXPOSURE_APERTURE_PRIORITY fcntl.ioctl(vd, v4l2.VIDIOC_S_CTRL, ctrl) # print('exposure auto type: ', ctrl.value) # # ctrl1 = v4l2.v4l2_control() # ctrl1.id = v4l2.V4L2_CID_EXPOSURE_ABSOLUTE # ctrl1.value = 12 # fcntl.ioctl(vd, v4l2.VIDIOC_S_CTRL, ctrl1) # fcntl.ioctl(vd, v4l2.VIDIOC_G_CTRL, ctrl1) # print('exposure time: ', ctrl1.value) # ctrl2 = v4l2.v4l2_control() # ctrl2.id = v4l2.V4L2_CID_SHARPNESS
def update_brightness(self, value): c = v4l2.v4l2_control() c.id = v4l2.V4L2_CID_BRIGHTNESS c.value = value fcntl.ioctl(self.video, v4l2.VIDIOC_S_CTRL, c)
def update_exposure(self, value): c = v4l2.v4l2_control() c.id = v4l2.V4L2_CID_EXPOSURE_ABSOLUTE c.value = value fcntl.ioctl(self.video, v4l2.VIDIOC_S_CTRL, c)
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)
def __init__(self, primary_text, v4l2_control = False, v4l2_auto_control = False): Palette.__init__(self, label=primary_text) vbox = gtk.VBox() self.set_content(vbox) vbox.show() if v4l2_control: self._query_control = v4l2.v4l2_queryctrl(v4l2_control) self._control = v4l2.v4l2_control(v4l2_control) ioctl(VD, v4l2.VIDIOC_QUERYCTRL, self._query_control) ioctl(VD, v4l2.VIDIOC_G_CTRL, self._control) _max = self._query_control.maximum _min = self._query_control.minimum if v4l2_control == v4l2.V4L2_CID_EXPOSURE: _min = 0 _max = 512 elif v4l2_control == v4l2.V4L2_CID_GAIN: _min = 0 _max = 37 elif v4l2_control == v4l2.V4L2_CID_CONTRAST: _min = 0 _max = 127 elif v4l2_control == v4l2.V4L2_CID_BRIGHTNESS: _min = 0 _max = 255 #elif v4l2_control == v4l2.V4L2_CID_NIGHT_MODE: # _min = 0 # _max = 1 self._adjustment = gtk.Adjustment(value=self._control.value, lower=_min, upper=_max, step_incr=1, page_incr=1, page_size=0) self._hscale = gtk.HScale(self._adjustment) self._hscale.set_digits(0) self._hscale.set_draw_value(False) self._hscale.set_update_policy(gtk.UPDATE_DISCONTINUOUS) vbox.add(self._hscale) self._hscale.show() self._adjustment_handler_id = \ self._adjustment.connect('value_changed', self.__adjustment_changed_cb) if v4l2_auto_control: self._auto_query_control =\ v4l2.v4l2_queryctrl(v4l2_auto_control) self._auto_control = v4l2.v4l2_control(v4l2_auto_control) self._auto_button = gtk.CheckButton('Auto') self._auto_button.set_active(self._auto_control.value) self._auto_button.connect('toggled', self.__auto_button_toggled_cb) vbox.add(self._auto_button) self._auto_button.show() if self._auto_control.value == True: self._hscale.set_sensitive(False) vbox.show()
def _set_ctrl(self, ctrl_id, value, desc): ctrl = v4l2.v4l2_control(id=ctrl_id, value=value) self._v4l2_ioctl_nonfatal(v4l2.VIDIOC_S_CTRL, ctrl, 'failed to set control: {}'.format(desc))
import select import time import v4l2 import fcntl if __name__ == '__main__': #cap = cv2.VideoCapture(0) #cap.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, 1920) # <-- this doesn't work. OpenCV tries to set VIDIO_S_CROP instead of the frame format #cap.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, 1080) # The following is from: https://github.com/gebart/python-v4l2capture # Open the video device. video1 = v4l2capture.Video_device("/dev/video2") c = v4l2.v4l2_control() c.id = v4l2.V4L2_CID_EXPOSURE_ABSOLUTE c.value = 50 fcntl.ioctl(video1, v4l2.VIDIOC_S_CTRL, c) time.sleep(1) # Suggest an image size to the device. The device may choose and # return another size if it doesn't support the suggested one. size_x, size_y = video1.set_format(1280, 960, 1) print "device chose {0}x{1} res".format(size_x, size_y) # Create a buffer to store image data in. This must be done before # calling 'start' if v4l2capture is compiled with libv4l2. Otherwise # raises IOError. video1.create_buffers(1)
def update_privacy(self, value): c = v4l2.v4l2_control() c.id = v4l2.V4L2_CID_PRIVACY #c.value = cam_data["privacy"] c.value = value fcntl.ioctl(self.video, v4l2.VIDIOC_S_CTRL, c)