camera test

This commit is contained in:
matteo porta 2022-10-05 14:57:36 +02:00
parent a20bef6538
commit 2264a28a3f

View File

@ -30,6 +30,19 @@ class GalaxyCamera(Component):
self._last_frame = None self._last_frame = None
def config_changed(self): 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 = { self.resolution = {
"w": int(self.round_4(self.config[self.name]["horizontal_resolution"])), "w": int(self.round_4(self.config[self.name]["horizontal_resolution"])),
"h": int(self.round_4(self.config[self.name]["vertical_resolution"])), "h": int(self.round_4(self.config[self.name]["vertical_resolution"])),
@ -99,21 +112,6 @@ class GalaxyCamera(Component):
def round_4(x): def round_4(x):
return 4 * round(int(x) / 4) 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 @Component.reconfig_on_error
def _get(self): def _get(self):
# print("GALAXY CAMERA", str(int(QThread.currentThreadId())), flush=True) # print("GALAXY CAMERA", str(int(QThread.currentThreadId())), flush=True)
@ -145,8 +143,9 @@ class GalaxyCamera(Component):
super()._get([frame]) super()._get([frame])
def __del__(self, event=None): def __del__(self, event=None):
self.camera.stream_off() if self.camera is not None:
self.camera.close_device() self.camera.stream_off()
self.camera.close_device()
def init_edits(self): def init_edits(self):
self.edits_enabled = True self.edits_enabled = True