def open(self): self.set_esize(self.resolution) args = self.get_size() if not args: return h, w = args[1].value, args[0].value shape = (h, w) if self.bits == 8: dtype = uint8 else: dtype = uint32 self._data = zeros(shape, dtype=dtype) self._cnt = 0 def get_frame(nEvent, ctx): if nEvent == TOUPCAM_EVENT_IMAGE: w, h = ctypes.c_uint(), ctypes.c_uint() bits = ctypes.c_int(self.bits) lib.Toupcam_PullImage(self.cam, ctypes.c_void_p(self._data.ctypes.data), bits, ctypes.byref(w), ctypes.byref(h)) elif nEvent == TOUPCAM_EVENT_STILLIMAGE: w, h = self.get_size() h, w = h.value, w.value dtype = uint32 shape = (h, w) still = zeros(shape, dtype=dtype) bits = ctypes.c_int(self.bits) lib.Toupcam_PullStillImage(self.cam, ctypes.c_void_p(still.ctypes.data), bits, None, None) self._do_save(still) CB = ctypes.CFUNCTYPE(None, ctypes.c_uint, ctypes.c_void_p) self._frame_fn = CB(get_frame) result = lib.Toupcam_StartPullModeWithCallback(self.cam, self._frame_fn) return success(result)
def get_esize(self): res = ctypes.c_long() result = lib.Toupcam_get_eSize(self.cam, ctypes.byref(res)) if success(result): return res
def get_size(self): w, h = ctypes.c_long(), ctypes.c_long() result = lib.Toupcam_get_Size(self.cam, ctypes.byref(w), ctypes.byref(h)) if success(result): return w, h
def get_hardware_version(self): hw = ctypes.create_string_buffer(16) result = lib.Toupcam_get_HwVersion(self.cam, hw) if success(result): return hw.value
def get_firmware_version(self): fw = ctypes.create_string_buffer(16) result = lib.Toupcam_get_FwVersion(self.cam, fw) if success(result): return fw.value
def get_serial(self): sn = ctypes.create_string_buffer(32) result = lib.Toupcam_get_SerialNumber(self.cam, sn) if success(result): sn = sn.value return sn
def get_auto_exposure(self): expo_enabled = ctypes.c_bool() result = lib.Toupcam_get_AutoExpoEnable(self.cam, ctypes.byref(expo_enabled)) if success(result): return expo_enabled.value
def _lib_func(self, func, *args, **kw): ff = getattr(lib, 'Toupcam_{}'.format(func)) result = ff(self.cam, *args, **kw) return success(result)