def display_image(self):
        fps = ueye.DOUBLE()
        ueye.is_GetFramesPerSecond(self.hCam, fps)
        timeout = int((5 / fps) * 1000)
        h_event = None
        if platform.system() == 'Windows':
            h_event = win32event.CreateEvent(None, False, False, None)
            self.event = ueye.HANDLE(int(h_event))
            ueye.is_InitEvent(self.hCam, self.event, self.frame_event_id)
        ueye.is_EnableEvent(self.hCam, self.frame_event_id)

        while True:
            ret = None
            if not self.capturing:
                break
            if platform.system() == 'Windows':
                ret = win32event.WaitForSingleObject(h_event, timeout)
            elif platform.system() == 'Linux':
                ret = ueye.is_WaitEvent(self.hCam, self.frame_event_id,
                                        timeout)

            if ret == 0:
                converted_image_data = self.convert_image_data()

                self.image_data_copy = (
                    ueye.CHAR *
                    int(self.img_data.width * self.img_data.height * 3))()
                ueye.is_CopyImageMem(
                    hCam=self.hCam,
                    pcSource=converted_image_data.memory_pointer,
                    nID=converted_image_data.memory_id,
                    pcDest=self.image_data_copy)
                bytes_per_pixel = 3
                self.image_data_copy = numpy.reshape(
                    self.image_data_copy,
                    (int(self.img_data.height), int(
                        self.img_data.width), bytes_per_pixel))
                self.image_data_copy = self.image_data_copy.view(numpy.uint8)
                self.pil_image = Image.fromarray(self.image_data_copy)
                self.graphics_scene.clear()
                self.width, self.height = self.pil_image.size
                self.qt_image = ImageQt.ImageQt(self.pil_image)
                self.pix_map = QPixmap.fromImage(self.qt_image)
                self.graphics_scene.addPixmap(self.pix_map)
                self.graphics_view.fitInView(
                    QRectF(0, 0, self.width, self.height), Qt.KeepAspectRatio)
                self.graphics_scene.update()
                app.processEvents()
Exemple #2
0
 def capture(self):
     '''
     Takes an image from the camera and places it in the computer memory
     '''
     err = pue.is_FreezeVideo(
         self.cam,
         pue.IS_WAIT)  #IS_DONT_WAIT  = 0x0000, or IS_GET_LIVE = 0x8000
     if err != pue.IS_SUCCESS:
         raise CameraException(self.cam, 'ueye>capture>', err, False)
     err = pue.is_CopyImageMem(self.cam, self.ppcImgMem, self.pid,
                               self.image_data.ctypes.data)
     if err != pue.IS_SUCCESS:
         raise CameraException(self.cam, 'ueye>capture>', err, False)
Exemple #3
0
    def _poll_buffer(self):
        data = ueye.c_mem_p()
        buffer_id = ueye.int()

        try:
            self.check_success(
                ueye.is_WaitForNextImage(self.h, 1000, data, buffer_id))
            self.check_success(
                ueye.is_CopyImageMem(
                    self.h, data, buffer_id,
                    self.transfer_buffer.ctypes.data_as(
                        ctypes.POINTER(ctypes.c_uint8))))
        except RuntimeError:
            try:
                self.check_success(
                    ueye.is_UnlockSeqBuf(self.h, ueye.IS_IGNORE_PARAMETER,
                                         data))
            except:
                pass
            finally:
                return

        if self.n_accum_current == 0:
            self.accum_buffer[:] = self.transfer_buffer
        else:
            self.accum_buffer[:] = self.accum_buffer + self.transfer_buffer
        self.n_accum_current += 1

        self.check_success(
            ueye.is_UnlockSeqBuf(self.h, ueye.IS_IGNORE_PARAMETER, data))

        if self.n_accum_current >= self.n_accum:
            self.full_buffers.put(self.accum_buffer)
            self.accum_buffer = self.free_buffers.get()
            self.n_accum_current = 0
            self.n_full += 1
Exemple #4
0
def capture():
    uEyeDll.is_FreezeVideo(cam, ueye.IS_WAIT)
    ueye.is_CopyImageMem(cam, pcImgMem, pid, ImageData.ctypes.data)
    return ImageData
def CopyImg(cam, ImageData, pcImgMem, pid):
    """copys the image from the memory to a numpy array"""
    ret = ueye.is_CopyImageMem(cam, pcImgMem, pid, ImageData.ctypes.data)
    return ret
Exemple #6
0
    def capture_image(self):
        """ In order to preserve compatibility with the old version, this function returns (R , G1 , G1 , B) images in the form of dictionary. """

        time.sleep(0.25)

        if self.frames_avg == 1:

            ueye.is_AllocImageMem(self.CamID, self.sensorWidth_ctype,
                                  self.sensorHeight_ctype, self.bitdepth,
                                  self.memPointer, self.memID)
            ueye.is_SetImageMem(self.CamID, self.memPointer, self.memID)

            imageArray = np.zeros(
                (self.sensorHeight_ctype.value, self.sensorWidth_ctype.value),
                dtype=np.uint16)

            ueye.is_FreezeVideo(self.CamID, ueye.IS_WAIT)
            ueye.is_CopyImageMem(self.CamID, self.memPointer, self.memID,
                                 imageArray.ctypes.data)
            # Clean memory
            ueye.is_FreeImageMem(self.CamID, self.memPointer, self.memID)

        else:
            imageStack = []
            print('(' + str(self.frames_avg) + 'x) ', end='')
            for i in range(self.frames_avg):
                ueye.is_AllocImageMem(self.CamID, self.sensorWidth_ctype,
                                      self.sensorHeight_ctype, self.bitdepth,
                                      self.memPointer, self.memID)
                ueye.is_SetImageMem(self.CamID, self.memPointer, self.memID)

                imageArrayFrame = np.zeros((self.sensorHeight_ctype.value,
                                            self.sensorWidth_ctype.value),
                                           dtype=np.uint16)

                ueye.is_FreezeVideo(self.CamID, ueye.IS_WAIT)
                ueye.is_CopyImageMem(self.CamID, self.memPointer, self.memID,
                                     imageArrayFrame.ctypes.data)
                # Clean memory
                ueye.is_FreeImageMem(self.CamID, self.memPointer, self.memID)

                imageStack.append(np.array(imageArrayFrame, dtype=np.uint16))

            imageArray = np.mean(imageStack, axis=0)

        #Binning Recuting
        if self.binningEnabled == True:
            imageArray = imageArray[0:self.currentHeight, 0:self.currentWidth]

        #imageArrayResized = self.resizeImage(imageArray)
        if self.sensorInfo.strSensorName.decode('utf8')[-1] == 'C':
            imageDict = self.colorPipe_Bayer12(imageArray)
        elif self.sensorInfo.strSensorName.decode('utf8')[-1] == 'M':
            imageDict = self.colorPipe_Mono(imageArray)
        elif self.sensorInfo.strSensorName.decode(
                'utf8')[-1] != 'C' and self.sensorInfo.strSensorName.decode(
                    'utf8')[-1] != 'M':
            raise NameError(
                'Sensor type not recognized by the IDSCamera.capture_image function!'
            )

        return imageDict