def pull_image(self, bits, func):

        lib.Toupcam_StartPullModeWithCallback(self.cam, func)
        w, h = ctypes.c_uint(), ctypes.c_uint()

        return lib.Toupcam_PullImage(self.cam,
                                     ctypes.c_void_p(self._data.ctypes.data),
                                     bits, ctypes.byref(w), ctypes.byref(h))
Beispiel #2
0
    def open(self):
        if self.resolution:
            self.set_esize(self.resolution)
        else:
            self.set_size(*self.size)

        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

        # Users have to make sure that the data buffer capacity is enough to save the image data.
        self._data = zeros(shape, dtype=dtype)

        bits = ctypes.c_int(self.bits)

        def get_frame(nEvent, ctx):
            if nEvent == TOUPCAM_EVENT_IMAGE:
                w, h = ctypes.c_uint(), ctypes.c_uint()
                '''
                :param HToupCam: handle to cam
                :param pImageData: (void*) Data buffer. 
                :param bits: (int) 24, 32 or 8, means RGB24, RGB32 or 8 bits grey images. This parameter is ignored in RAW mode.
                :param pnWidth: (unsigned*) width of image.
                :param pnWidth: (unsigned*) height of image.
                '''
                lib.Toupcam_PullImage(self.cam,
                                      ctypes.c_void_p(self._data.ctypes.data),
                                      bits, ctypes.byref(w), ctypes.byref(h))
                print(
                    f"TOUPCAM_IMAGE_EVENT- width:{w.value}, height:{h.value}; data-length:{len(self._data)}; data-shape:{self._data.shape}; bitdepth:{bits.value}; dtype:{dtype}"
                )

            elif nEvent == TOUPCAM_EVENT_STILLIMAGE:
                w, h = self.get_size()
                h, w = h.value, w.value

                still = zeros((h, w), dtype=uint32)
                lib.Toupcam_PullStillImage(self.cam,
                                           ctypes.c_void_p(still.ctypes.data),
                                           bits, None, None)
                self._do_save(still)

        callback = ctypes.CFUNCTYPE(None, ctypes.c_uint, ctypes.c_void_p)
        self._frame_fn = callback(get_frame)

        result = lib.Toupcam_StartPullModeWithCallback(self.cam,
                                                       self._frame_fn)

        return success(result)
    def set_with_callback(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)

        bits = ctypes.c_int(self.bits)

        #print("opened")

        def get_frame(nEvent, ctx):
            #print("getting frame")
            if nEvent == TOUPCAM_EVENT_IMAGE:
                w, h = ctypes.c_uint(), ctypes.c_uint()

                lib.Toupcam_PullImage(self.cam,
                                      ctypes.c_void_p(self._data.ctypes.data),
                                      bits, ctypes.byref(w), ctypes.byref(h))
                if self._master is not None:
                    self._master.update_image()

            elif nEvent == TOUPCAM_EVENT_STILLIMAGE:
                w, h = self.get_size()
                h, w = h.value, w.value

                still = zeros((h, w), dtype=uint32)
                lib.Toupcam_PullStillImage(self.cam,
                                           ctypes.c_void_p(still.ctypes.data),
                                           bits, None, None)
                self._do_save(still)
                if self._master is not None:
                    self._master.update_image()

        callback = ctypes.CFUNCTYPE(None, ctypes.c_uint, ctypes.c_void_p)
        self._frame_fn = callback(get_frame)
        result = lib.Toupcam_StartPullModeWithCallback(self.cam,
                                                       self._frame_fn)
        return success(result)
Beispiel #4
0
    def open(self):
        if self.resolution:
            self.set_esize(self.resolution)
        else:
            self.set_size(*self.size)

        args = self.get_size()
        if not args:
            print('Failed opening camera')
            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)

        bits = ctypes.c_int(self.bits)

        def get_frame(nEvent, ctx):
            if nEvent == TOUPCAM_EVENT_IMAGE:
                w, h = ctypes.c_uint(), ctypes.c_uint()

                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

                still = zeros((h, w), dtype=uint32)
                lib.Toupcam_PullStillImage(self.cam,
                                           ctypes.c_void_p(still.ctypes.data),
                                           bits, None, None)
                self._do_save(still)

        callback = ctypes.CFUNCTYPE(None, ctypes.c_uint, ctypes.c_void_p)
        self._frame_fn = callback(get_frame)

        result = lib.Toupcam_StartPullModeWithCallback(self.cam,
                                                       self._frame_fn)

        return success(result)
Beispiel #5
0
    def cam_open(self):
        'Open camera'
        self.set_esize(self.resolution)
        args = self.get_size()
        if not args:
            print('Camera not open!')
            return

        def get_frame(nEvent, ctx):
            'callback function, to be stored in _frame_fn'
            #ctx is not used
            if nEvent == TOUPCAM_EVENT_STILLIMAGE:
                w, h = self.get_size()
                h, w = h.value, w.value

                still = np.zeros((h, w), dtype=np.uint32)
                lib.Toupcam_PullStillImage(self.cam,
                                           ctypes.c_void_p(still.ctypes.data),
                                           None, None, None)
                # lib.Toupcam_PullStillImage(handle,void_pointer_pImageData,
                # int bits,unsigned pointer pnWidth,unsigned pointer pnHeight)
                self._do_save(still)

        # converts get_frame into a C function
        # with None returned, and arguments (int, void*)
        callback = ctypes.CFUNCTYPE(None, ctypes.c_uint, ctypes.c_void_p)
        self._frame_fn = callback(get_frame)

        # try to set camera to raw output
        result1 = lib.Toupcam_put_option(self.cam, ctypes.c_uint(0x04),
                                         ctypes.c_uint(0x1))
        print('set to raw? result = {}'.format(result1))

        # Start Camera Pull Mode
        result = lib.Toupcam_StartPullModeWithCallback(self.cam,
                                                       self._frame_fn)
        return success(result)