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 init(self): """ Descript. : """ self.qimage = QImage() current_path = os.path.dirname(os.path.abspath(__file__)).split(os.sep) current_path = os.path.join(*current_path[1:-1]) image_path = os.path.join("/", current_path, "ExampleFiles/fakeimg.jpg") self.qimage.load(image_path) self.force_update = False self.image_dimensions = [600, 400] self.image_type = JpegType() self.set_is_ready(True)
def get_new_image(self): """ Descript. : reads new image, flips it if necessary and returns the result or None on error """ image = self.http_get("?action=snapshot") if image is not None: return QImage.fromData(image).mirrored(self.flip["h"], self.flip["v"]) return None
def generate_image(self): self.vapory_sene = vapory.Scene( self.vapory_camera, objects=[self.vapory_light, self.simulated_loop.loop_object], ) image_array = self.vapory_sene.render( "/tmp/vapory_tmp_image.png", width=self.image_dimensions[0], height=self.image_dimensions[1], ) self.qimage = QImage("/tmp/vapory_tmp_image.png") self.emit( "imageReceived", self.qimage, self.qimage.width(), self.qimage.height(), self.force_update, )
def _do_imagePolling(self, sleep_time): """ Descript. : """ while True: image_array = self.vapory_sene.render( "/tmp/vapory_tmp_image.png", width=self.image_dimensions[0], height=self.image_dimensions[1], ) self.qimage = QImage("/tmp/vapory_tmp_image.png") self.emit( "imageReceived", self.qimage, self.qimage.width(), self.qimage.height(), self.force_update, ) time.sleep(sleep_time)
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): """ 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
def init(self): """ Descript. : """ self.qimage = QImage() current_path = os.path.dirname(os.path.abspath(__file__)).split(os.sep) current_path = os.path.join(*current_path[1:-1]) image_path = os.path.join("/", current_path, "ExampleFiles/fakeimg.jpg") self.qimage.load(image_path) self.force_update = False self.image_dimensions = [600, 400] self.image_type = JpegType() self.setIsReady(True)
class VaporyVideo(BaseHardwareObjects.Device): """ Descript. : """ def __init__(self, name): """ Descript. : """ BaseHardwareObjects.Device.__init__(self, name) self.force_update = None self.image_dimensions = None self.image_polling = None self.image_type = None self.qimage = None def init(self): """ Descript. : """ self.vapory_camera = vapory.Camera("location", [0, 2, -3], "look_at", [0, 1, 2]) self.vapory_light = vapory.LightSource([2, 4, -3], "color", [1, 1, 1]) self.simulated_loop = SimulatedLoop() self.simulated_loop.set_position(0, 0, 0) self.force_update = False self.image_dimensions = [600, 400] self.image_type = JpegType() self.setIsReady(True) self.generate_image() self.image_polling = gevent.spawn(self._do_imagePolling, 1) def rotate_scene_absolute(self, angle): self.simulated_loop.set_position(angle, 0, 0) self.generate_image() def rotate_scene_relative(self, angle): return def generate_image(self): self.vapory_sene = vapory.Scene( self.vapory_camera, objects=[self.vapory_light, self.simulated_loop.loop_object], ) image_array = self.vapory_sene.render( "/tmp/vapory_tmp_image.png", width=self.image_dimensions[0], height=self.image_dimensions[1], ) self.qimage = QImage("/tmp/vapory_tmp_image.png") self.emit( "imageReceived", self.qimage, self.qimage.width(), self.qimage.height(), self.force_update, ) def imageType(self): """ Descript. : """ return self.image_type def contrastExists(self): """ Descript. : """ return def setContrast(self, contrast): """ Descript. : """ return def getContrast(self): """ Descript. : """ return def getContrastMinMax(self): """ Descript. : """ return def brightnessExists(self): """ Descript. : """ return def setBrightness(self, brightness): """ Descript. : """ return def getBrightness(self): """ Descript. : """ return def getBrightnessMinMax(self): """ Descript. : """ return def gainExists(self): """ Descript. : """ return def setGain(self, gain): """ Descript. : """ return def getGain(self): """ Descript. : """ return def getGainMinMax(self): """ Descript. : """ return def gammaExists(self): """ Descript. : """ return def setGamma(self, gamma): """ Descript. : """ return def getGamma(self): """ Descript. : """ return def getGammaMinMax(self): """ Descript. : """ return (0, 1) def setLive(self, mode): """ Descript. : """ return def getWidth(self): """ Descript. : """ return self.image_dimensions[0] def getHeight(self): """ Descript. : """ return self.image_dimensions[1] def _do_imagePolling(self, sleep_time): """ Descript. : """ while True: image_array = self.vapory_sene.render( "/tmp/vapory_tmp_image.png", width=self.image_dimensions[0], height=self.image_dimensions[1], ) self.qimage = QImage("/tmp/vapory_tmp_image.png") self.emit( "imageReceived", self.qimage, self.qimage.width(), self.qimage.height(), self.force_update, ) time.sleep(sleep_time)
class VideoMockup(BaseHardwareObjects.Device): """ Descript. : """ def __init__(self, name): """ Descript. : """ BaseHardwareObjects.Device.__init__(self, name) self.force_update = None self.image_dimensions = None self.image_polling = None self.image_type = None self.qimage = None def init(self): """ Descript. : """ self.qimage = QImage() current_path = os.path.dirname(os.path.abspath(__file__)).split(os.sep) current_path = os.path.join(*current_path[1:-1]) image_path = os.path.join("/", current_path, "ExampleFiles/fakeimg.jpg") self.qimage.load(image_path) self.force_update = False self.image_dimensions = [600, 400] self.image_type = JpegType() self.setIsReady(True) def imageType(self): """ Descript. : """ return self.image_type def contrastExists(self): """ Descript. : """ return def setContrast(self, contrast): """ Descript. : """ return def getContrast(self): """ Descript. : """ return def getContrastMinMax(self): """ Descript. : """ return def brightnessExists(self): """ Descript. : """ return def setBrightness(self, brightness): """ Descript. : """ return def getBrightness(self): """ Descript. : """ return def getBrightnessMinMax(self): """ Descript. : """ return def gainExists(self): """ Descript. : """ return def setGain(self, gain): """ Descript. : """ return def getGain(self): """ Descript. : """ return def getGainMinMax(self): """ Descript. : """ return def gammaExists(self): """ Descript. : """ return def setGamma(self, gamma): """ Descript. : """ return def getGamma(self): """ Descript. : """ return def getGammaMinMax(self): """ Descript. : """ return (0, 1) def setLive(self, mode): """ Descript. : """ return def getWidth(self): """ Descript. : """ return self.image_dimensions[0] def getHeight(self): """ Descript. : """ return self.image_dimensions[1] def _do_imagePolling(self, sleep_time): """ Descript. : """ self.image_dimensions = (self.qimage.width(), self.qimage.height()) while True: self.emit( "imageReceived", self.qimage, self.qimage.width(), self.qimage.height(), self.force_update, ) time.sleep(sleep_time) def connectNotify(self, signal): """ Descript. : """ if signal == "imageReceived": self.image_polling = gevent.spawn(self._do_imagePolling, 1)
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
class VaporyVideo(BaseHardwareObjects.Device): """ Descript. : """ def __init__(self, name): """ Descript. : """ BaseHardwareObjects.Device.__init__(self, name) self.force_update = None self.image_dimensions = None self.image_polling = None self.image_type = None self.qimage = None def init(self): """ Descript. : """ self.vapory_camera = vapory.Camera("location", [0, 2, -3], "look_at", [0, 1, 2]) self.vapory_light = vapory.LightSource([2, 4, -3], "color", [1, 1, 1]) self.simulated_loop = SimulatedLoop() self.simulated_loop.set_position(0, 0, 0) self.force_update = False self.image_dimensions = [600, 400] self.image_type = JpegType() self.set_is_ready(True) self.generate_image() self.image_polling = gevent.spawn(self._do_imagePolling, 1) def rotate_scene_absolute(self, angle): self.simulated_loop.set_position(angle, 0, 0) self.generate_image() def rotate_scene_relative(self, angle): return def generate_image(self): self.vapory_sene = vapory.Scene( self.vapory_camera, objects=[self.vapory_light, self.simulated_loop.loop_object], ) image_array = self.vapory_sene.render( "/tmp/vapory_tmp_image.png", width=self.image_dimensions[0], height=self.image_dimensions[1], ) self.qimage = QImage("/tmp/vapory_tmp_image.png") self.emit( "imageReceived", self.qimage, self.qimage.width(), self.qimage.height(), self.force_update, ) def imageType(self): """ Descript. : """ return self.image_type def contrastExists(self): """ Descript. : """ return def setContrast(self, contrast): """ Descript. : """ return def getContrast(self): """ Descript. : """ return def getContrastMinMax(self): """ Descript. : """ return def brightnessExists(self): """ Descript. : """ return def setBrightness(self, brightness): """ Descript. : """ return def getBrightness(self): """ Descript. : """ return def getBrightnessMinMax(self): """ Descript. : """ return def gainExists(self): """ Descript. : """ return def setGain(self, gain): """ Descript. : """ return def getGain(self): """ Descript. : """ return def getGainMinMax(self): """ Descript. : """ return def gammaExists(self): """ Descript. : """ return def setGamma(self, gamma): """ Descript. : """ return def getGamma(self): """ Descript. : """ return def getGammaMinMax(self): """ Descript. : """ return (0, 1) def set_live(self, mode): """ Descript. : """ return def get_width(self): """ Descript. : """ return self.image_dimensions[0] def get_height(self): """ Descript. : """ return self.image_dimensions[1] def _do_imagePolling(self, sleep_time): """ Descript. : """ while True: image_array = self.vapory_sene.render( "/tmp/vapory_tmp_image.png", width=self.image_dimensions[0], height=self.image_dimensions[1], ) self.qimage = QImage("/tmp/vapory_tmp_image.png") self.emit( "imageReceived", self.qimage, self.qimage.width(), self.qimage.height(), self.force_update, ) time.sleep(sleep_time)
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