diff --git a/config.toml b/config.toml index 33c7ed6..47f65a4 100644 --- a/config.toml +++ b/config.toml @@ -1,9 +1,9 @@ [camera] -type = "none" +type = "flir" gui-scale = 0.1 [stage] -homing = false -enabled = false +homing = true +enabled = true port = "COM4" baud-rate = 115200 diff --git a/src/gui.py b/src/gui.py index 3f2e8f3..9b074ac 100644 --- a/src/gui.py +++ b/src/gui.py @@ -33,10 +33,10 @@ def compute_focus_score(camera_image, blue_only): camera_image = camera_image.copy() - camera_image[:, :, 1] = 0 # green should never be used for focus - if blue_only: - camera_image[:, :, 0] = 0 # disable red - img = cv2.cvtColor(camera_image, cv2.COLOR_RGB2GRAY) + # camera_image[:, :, 1] = 0 # green should never be used for focus + # if blue_only: + # camera_image[:, :, 0] = 0 # disable red + img = cv2.cvtColor(camera_image, cv2.COLOR_BGR2GRAY) img = cv2.resize(img, (0, 0), fx=0.5, fy=0.5) mean = np.sum(img) / (img.shape[0] * img.shape[1]) img_lapl = cv2.Sobel(img, cv2.CV_64F, 1, 0, ksize=1) / mean @@ -735,38 +735,14 @@ def __init__( self.camera = c self.pending_frame = None - def _on_new_frame(self): - # FIXME: is this really the only way tkinter exposes to do this?? - # We want to send frames from the callback over to the main thread, - # but in way where it just grabs the most recently-made-available frame. - # If you send an event, events will just pile up in the queue if we ever fall behind. - # This might have the same problem! - # I have no idea how to fix this - self.event_dispatcher.root.after(33, lambda: self._on_new_frame()) - if self.pending_frame is None: - return - image, dimensions, format = self.pending_frame - - try: - filename = self.snapshots_pending.get_nowait() - print(f"Saving image {filename}") - img = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) - cv2.imwrite(filename, img) - except queue.Empty: - pass - - self.gui_camera_preview(image, dimensions) - def start(self): if not self.camera: print("No camera available") return - # self.event_dispatcher.root.bind('<>', lambda x: self._on_new_frame(x)) - def cameraCallback(image, dimensions, format): self.pending_frame = (image, dimensions, format) - # self.event_dispatcher.root.event_generate('<>', when='tail') + self.event_dispatcher.root.after_idle(lambda: self._on_new_frame(image, dimensions, format)) if not self.camera.open(): print("Camera failed to start") @@ -775,8 +751,17 @@ def cameraCallback(image, dimensions, format): self.camera.setStreamCaptureCallback(cameraCallback) if not self.camera.startStreamCapture(): print("Failed to start stream capture for camera") + + def _on_new_frame(self, image, dimensions, format): + try: + filename = self.snapshots_pending.get_nowait() + print(f"Saving image {filename}") + img = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) + cv2.imwrite(f"{self.event_dispatcher.snapshot_directory}/{filename}", img) + except queue.Empty: + pass - self._on_new_frame() + self.gui_camera_preview(image, dimensions) def cleanup(self): if self.camera is not None: @@ -942,7 +927,7 @@ def callback_set(): self.step_size_intputs.append( IntEntry( parent=self.relative_frame, - default=10, + default=[840, 540, 200][i], min_value=-1000, max_value=1000, ) @@ -1584,9 +1569,9 @@ def __init__(self, parent, model: EventDispatcher): self.model = model # TODO: Tune default offsets - self.x_settings = OffsetAmountFrame(self.frame, "X", 1050) + self.x_settings = OffsetAmountFrame(self.frame, "X", 840) self.x_settings.frame.grid(row=0, column=0) - self.y_settings = OffsetAmountFrame(self.frame, "Y", 900) + self.y_settings = OffsetAmountFrame(self.frame, "Y", 540) self.y_settings.frame.grid(row=1, column=0) def on_begin(): @@ -1689,7 +1674,7 @@ def on_start(): self.camera.start() if self.event_dispatcher.hardware.stage.has_homing(): self.event_dispatcher.home_stage() - self.event_dispatcher.move_relative({"x": 5000.0, "y": 3500.0, "z": 1900.0}) + self.event_dispatcher.move_relative({"x": 10000.0, "y": 3500.0, "z": 4000.0}) messagebox.showinfo( message="BEFORE CONTINUING: Ensure that you move the projector window to the correct display! Click on the fullscreen, completely black window, then press Windows Key + Shift + Left Arrow until it no longer is visible!" ) @@ -1724,6 +1709,7 @@ def main(): camera_config = config["camera"] + # Camera Type Selection if camera_config["type"] == "webcam": try: index = int(camera_config["index"]) @@ -1742,6 +1728,7 @@ def main(): print(f"config.toml specifies invalid camera type {camera_config['type']}") return 1 + # GUI-Scaling try: camera_scale = float(camera_config["gui-scale"]) except Exception: