From 2264a28a3f67407fa3c8aa2a25d174d0587ac86b Mon Sep 17 00:00:00 2001 From: matteo porta Date: Wed, 5 Oct 2022 14:57:36 +0200 Subject: [PATCH] camera test --- src/components/galaxy_camera.py | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/src/components/galaxy_camera.py b/src/components/galaxy_camera.py index c7fb6ed..818815c 100644 --- a/src/components/galaxy_camera.py +++ b/src/components/galaxy_camera.py @@ -30,6 +30,19 @@ class GalaxyCamera(Component): self._last_frame = None def config_changed(self): + if self.simulate: + self.device_manager = None + self.camera = DummyCamera() + self.sim_imgs = cycle(sorted(pathlib.Path("data/simulation_images/").glob("*.png"))) + else: + self.device_manager = gx.DeviceManager() + # create a device manager + dev_num, dev_info_list = self.device_manager.update_device_list() + if dev_num == 0: + self.log.exception("camera not detected") + QMessageBox.critical(None, "Errore hardware", "Telecamera non rilevata.\nControllare connessione usb") + quit() + self.camera = self.device_manager.open_device_by_index(1) self.resolution = { "w": int(self.round_4(self.config[self.name]["horizontal_resolution"])), "h": int(self.round_4(self.config[self.name]["vertical_resolution"])), @@ -99,21 +112,6 @@ class GalaxyCamera(Component): def round_4(x): return 4 * round(int(x) / 4) - def start(self): - if self.simulate: - self.camera = DummyCamera() - self.sim_imgs = cycle(sorted(pathlib.Path("data/simulation_images/").glob("*.png"))) - else: - self.device_manager = gx.DeviceManager() - # create a device manager - dev_num, dev_info_list = self.device_manager.update_device_list() - if dev_num == 0: - self.log.exception("camera not detected") - QMessageBox.critical(None, "Errore hardware", "Telecamera non rilevata.\nControllare connessione usb") - quit() - self.camera = self.device_manager.open_device_by_index(1) - super().start() - @Component.reconfig_on_error def _get(self): # print("GALAXY CAMERA", str(int(QThread.currentThreadId())), flush=True) @@ -145,8 +143,9 @@ class GalaxyCamera(Component): super()._get([frame]) def __del__(self, event=None): - self.camera.stream_off() - self.camera.close_device() + if self.camera is not None: + self.camera.stream_off() + self.camera.close_device() def init_edits(self): self.edits_enabled = True