Пример #1
0
    def do_image_polling(self, sleep_time):
        with Vimba() as vimba:
            system = vimba.getSystem()

            if system.GeVTLIsPresent:
                system.runFeatureCommand("GeVDiscoveryAllOnce")
                time.sleep(0.2)
            cameraIds = vimba.getCameraIds()

            # self.camera = vimba.getCamera(self.camera_id)
            self.camera = vimba.getCamera(cameraIds[self.camera_index])
            self.camera.openCamera(cameraAccessMode=2)
            self.camera.framerate = 1
            self.frame0 = self.camera.getFrame()  # creates a frame
            self.frame0.announceFrame()
            self.camera.startCapture()

            self.raw_image_dimensions = (self.frame0.width, self.frame0.height)

            while True:
                self.frame0.waitFrameCapture(1000)
                self.frame0.queueFrameCapture()

                if self.use_qt:
                    self.qimage = QImage(
                        self.frame0.getBufferByteData(),
                        self.raw_image_dimensions[0],
                        self.raw_image_dimensions[1],
                        QImage.Format_RGB888,
                    )
                    if self.cam_mirror is not None:
                        self.qimage = self.qimage.mirrored(
                            self.cam_mirror[0], self.cam_mirror[1])
                    if self.qpixmap is None:
                        self.qpixmap = QPixmap(self.qimage)
                    else:
                        self.qpixmap.convertFromImage(self.qimage)
                    self.emit("imageReceived", self.qpixmap)
                else:
                    image_data = np.ndarray(
                        buffer=self.frame0.getBufferByteData(),
                        dtype=np.uint8,
                        shape=(
                            self.frame0.height,
                            self.frame0.width,
                            self.frame0.pixel_bytes,
                        ),
                    )
                    image_data = cv2.cvtColor(image_data, cv2.COLOR_BGR2RGBA)
                    ret, im = cv2.imencode(".jpg", image_data)
                    self.emit(
                        "imageReceived",
                        im.tostring(),
                        self.frame0.width,
                        self.frame0.height,
                    )

                time.sleep(sleep_time)
Пример #2
0
def load(icon_name):
    """
    Try to load an icon from file and return the QPixmap object
    """
    filename = get_icon_path(icon_name)

    try:
        icon = QPixmap(filename)
    except BaseException:
        return QPixmap(os.path.join(ICONS_DIR, "brick.png"))
    else:
        if icon.isNull():
            return QPixmap(os.path.join(ICONS_DIR, "brick.png"))
        else:
            return icon
Пример #3
0
 def refresh_video(self):
     """
     Descript. : reads new image into member variable, scales it and emits
                 imageReceived event. Added for compatibility.
     """
     image = self.get_new_image()
     if image is not None:
         self.image = QPixmap.fromImage(image.scaled(self.width, self.height))
         self.emit("imageReceived", self.image)
 def refresh_video(self):
     """
     Descript. : reads new image into member variable, scales it and emits
                 imageReceived event. Added for compatibility.
     """
     image = self.get_new_image()
     if image is not None:
         self.image = QPixmap.fromImage(image.scaled(self.width, self.height))
         self.emit("imageReceived", self.image)
Пример #5
0
 def _do_imagePolling(self, sleep_time):
     """
     Descript. : worker method
     """
     while True:
         image = self.get_new_image()
         if image is not None:
             self.image = QPixmap.fromImage(image.scaled(self.width, self.height))
             self.emit("imageReceived", self.image)
         gevent.sleep(sleep_time)
 def _do_imagePolling(self, sleep_time):
     """
     Descript. : worker method
     """
     while True:
         image = self.get_new_image()
         if image is not None:
             self.image = QPixmap.fromImage(image.scaled(self.width, self.height))
             self.emit("imageReceived", self.image)
         gevent.sleep(sleep_time)
Пример #7
0
    def get_new_image(self):
        """
        Descript. :
        """
        raw_buffer, width, height = self.get_image()

        if raw_buffer is not None:
            qimage = QImage(raw_buffer, width, height, QImage.Format_RGB888)

            qpixmap = QPixmap(qimage)
            self.emit("imageReceived", qpixmap)
            return qimage
Пример #8
0
    def do_image_polling(self, sleep_time):
        with Vimba() as vimba:
            system = vimba.getSystem()

            if system.GeVTLIsPresent:
                system.runFeatureCommand("GeVDiscoveryAllOnce")
                time.sleep(0.2)
            cameraIds = vimba.getCameraIds()

            # self.camera = vimba.getCamera(self.camera_id)
            self.camera = vimba.getCamera(cameraIds[self.camera_index])
            self.camera.openCamera(cameraAccessMode=2)
            self.camera.framerate = 1
            self.frame0 = self.camera.getFrame()  # creates a frame
            self.frame0.announceFrame()
            self.camera.startCapture()

            self.raw_image_dimensions = (self.frame0.width, self.frame0.height)

            while True:
                self.frame0.waitFrameCapture(1000)
                self.frame0.queueFrameCapture()

                if self.use_qt:
                    self.qimage = QImage(
                        self.frame0.getBufferByteData(),
                        self.raw_image_dimensions[0],
                        self.raw_image_dimensions[1],
                        QImage.Format_RGB888,
                    )
                    if self.cam_mirror is not None:
                        self.qimage = self.qimage.mirrored(
                            self.cam_mirror[0], self.cam_mirror[1]
                        )
                    if self.qpixmap is None:
                        self.qpixmap = QPixmap(self.qimage)
                    else:
                        self.qpixmap.convertFromImage(self.qimage)
                    self.emit("imageReceived", self.qpixmap)
                else:
                    image_data = np.ndarray(buffer=self.frame0.getBufferByteData(),
                                            dtype=np.uint8,
                                            shape=(self.frame0.height,
                                                   self.frame0.width,
                                                   self.frame0.pixel_bytes))
                    image_data = cv2.cvtColor(image_data, cv2.COLOR_BGR2RGBA)
                    ret, im = cv2.imencode('.jpg', image_data)
                    self.emit("imageReceived",
                              im.tostring(),
                              self.frame0.width,
                              self.frame0.height)

                time.sleep(sleep_time)
Пример #9
0
    def _do_imagePolling(self, sleep_time):
        """
        Descript. : worker method
        """
        while True:
            if self.changing_pars:
                self.log.debug("  / not reading image. busy changing pars")
                gevent.sleep(sleep_time)
                continue

            image = self.get_new_image()
            if image is not None:
                self.image = QPixmap.fromImage(
                    image.scaled(self.width, self.height))
                self.emit("imageReceived", self.image)
Пример #10
0
class VimbaVideo(AbstractVideoDevice):
    def __init__(self, name):
        AbstractVideoDevice.__init__(self, name)

        self.camera = None
        self.camera_index = 0
        self.qimage = None
        self.qpixmap = None
        self.use_qt = False
        self.raw_image_dimensions = [1360, 1024]

    def init(self):
        # start Vimba
        self.camera_index = self.getProperty("camera_index", 0)
        self.use_qt = self.getProperty('use_qt', True)
             
        atexit.register(self.close_camera)
        AbstractVideoDevice.init(self)

    def get_raw_image_size(self):
        return self.raw_image_dimensions

    def do_image_polling(self, sleep_time):
        with Vimba() as vimba:
            system = vimba.getSystem()

            if system.GeVTLIsPresent:
                system.runFeatureCommand("GeVDiscoveryAllOnce")
                time.sleep(0.2)
            cameraIds = vimba.getCameraIds()

            # self.camera = vimba.getCamera(self.camera_id)
            self.camera = vimba.getCamera(cameraIds[self.camera_index])
            self.camera.openCamera(cameraAccessMode=2)
            self.camera.framerate = 1
            self.frame0 = self.camera.getFrame()  # creates a frame
            self.frame0.announceFrame()
            self.camera.startCapture()

            self.raw_image_dimensions = (self.frame0.width, self.frame0.height)

            while True:
                self.frame0.waitFrameCapture(1000)
                self.frame0.queueFrameCapture()

                if self.use_qt:
                    self.qimage = QImage(
                        self.frame0.getBufferByteData(),
                        self.raw_image_dimensions[0],
                        self.raw_image_dimensions[1],
                        QImage.Format_RGB888,
                    )
                    if self.cam_mirror is not None:
                        self.qimage = self.qimage.mirrored(
                            self.cam_mirror[0], self.cam_mirror[1]
                        )
                    if self.qpixmap is None:
                        self.qpixmap = QPixmap(self.qimage)
                    else:
                        self.qpixmap.convertFromImage(self.qimage)
                    self.emit("imageReceived", self.qpixmap)
                else:
                    image_data = np.ndarray(buffer=self.frame0.getBufferByteData(),
                                            dtype=np.uint8,
                                            shape=(self.frame0.height,
                                                   self.frame0.width,
                                                   self.frame0.pixel_bytes))
                    image_data = cv2.cvtColor(image_data, cv2.COLOR_BGR2RGBA)
                    ret, im = cv2.imencode('.jpg', image_data)
                    self.emit("imageReceived",
                              im.tostring(),
                              self.frame0.width,
                              self.frame0.height)

                time.sleep(sleep_time)

    def get_new_image(self):
        return self.qimage

    def get_video_live(self):
        return True

    def close_camera(self):
        with Vimba() as vimba:
            self.camera.flushCaptureQueue()
            self.camera.endCapture()
            self.camera.revokeAllFrames()
            vimba.shutdown()

    def start_camera(self):
        pass

    def change_owner(self):
        pass
Пример #11
0
class VimbaVideo(AbstractVideoDevice):
    def __init__(self, name):
        AbstractVideoDevice.__init__(self, name)

        self.camera = None
        self.camera_index = 0
        self.qimage = None
        self.qpixmap = None
        self.use_qt = False
        self.raw_image_dimensions = [1360, 1024]

    def init(self):
        # start Vimba
        self.camera_index = self.get_property("camera_index", 0)
        self.use_qt = self.get_property("use_qt", True)

        atexit.register(self.close_camera)
        AbstractVideoDevice.init(self)

    def get_raw_image_size(self):
        return self.raw_image_dimensions

    def do_image_polling(self, sleep_time):
        with Vimba() as vimba:
            system = vimba.getSystem()

            if system.GeVTLIsPresent:
                system.runFeatureCommand("GeVDiscoveryAllOnce")
                time.sleep(0.2)
            cameraIds = vimba.getCameraIds()

            # self.camera = vimba.getCamera(self.camera_id)
            self.camera = vimba.getCamera(cameraIds[self.camera_index])
            self.camera.openCamera(cameraAccessMode=2)
            self.camera.framerate = 1
            self.frame0 = self.camera.getFrame()  # creates a frame
            self.frame0.announceFrame()
            self.camera.startCapture()

            self.raw_image_dimensions = (self.frame0.width, self.frame0.height)

            while True:
                self.frame0.waitFrameCapture(1000)
                self.frame0.queueFrameCapture()

                if self.use_qt:
                    self.qimage = QImage(
                        self.frame0.getBufferByteData(),
                        self.raw_image_dimensions[0],
                        self.raw_image_dimensions[1],
                        QImage.Format_RGB888,
                    )
                    if self.cam_mirror is not None:
                        self.qimage = self.qimage.mirrored(
                            self.cam_mirror[0], self.cam_mirror[1])
                    if self.qpixmap is None:
                        self.qpixmap = QPixmap(self.qimage)
                    else:
                        self.qpixmap.convertFromImage(self.qimage)
                    self.emit("imageReceived", self.qpixmap)
                else:
                    image_data = np.ndarray(
                        buffer=self.frame0.getBufferByteData(),
                        dtype=np.uint8,
                        shape=(
                            self.frame0.height,
                            self.frame0.width,
                            self.frame0.pixel_bytes,
                        ),
                    )
                    image_data = cv2.cvtColor(image_data, cv2.COLOR_BGR2RGBA)
                    ret, im = cv2.imencode(".jpg", image_data)
                    self.emit(
                        "imageReceived",
                        im.tostring(),
                        self.frame0.width,
                        self.frame0.height,
                    )

                time.sleep(sleep_time)

    def get_new_image(self):
        return self.qimage

    def get_video_live(self):
        return True

    def close_camera(self):
        with Vimba() as vimba:
            self.camera.flushCaptureQueue()
            self.camera.endCapture()
            self.camera.revokeAllFrames()
            vimba.shutdown()

    def start_camera(self):
        pass

    def change_owner(self):
        pass