コード例 #1
0
    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)
コード例 #2
0
 def get_esize(self):
     res = ctypes.c_long()
     result = lib.Toupcam_get_eSize(self.cam, ctypes.byref(res))
     if success(result):
         return res
コード例 #3
0
    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
コード例 #4
0
 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
コード例 #5
0
 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
コード例 #6
0
 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
コード例 #7
0
 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
コード例 #8
0
 def _lib_func(self, func, *args, **kw):
     ff = getattr(lib, 'Toupcam_{}'.format(func))
     result = ff(self.cam, *args, **kw)
     return success(result)