GUI: Add sharpness

This commit is contained in:
2026-01-16 13:55:54 +01:00
parent 5a7f09a619
commit 0b44112eb4
3 changed files with 21 additions and 1 deletions
+1
View File
@@ -252,6 +252,7 @@ class MainWindow(QMainWindow):
self.camera_thread = SampleCameraThread(zmq_url=zmq_addr)
self.camera_thread.camera_image.connect(self.sample_camera.update_pixmap)
self.camera_thread.start()
self.camera_thread.focus_measure.connect(self.status_bar.update_sharpness)
else:
self.camera_thread = None
+14 -1
View File
@@ -3,13 +3,14 @@ import json
import cv2
import numpy as np
import zmq
from PySide6.QtCore import QThread, Signal
from PySide6.QtCore import QThread, Signal, Slot
from PySide6.QtGui import QImage, QPixmap
class SampleCameraThread(QThread):
# Define a signal to communicate messages from the thread to the main GUI
camera_image = Signal(QPixmap)
focus_measure = Signal(float) # Emits Laplacian variance (higher = sharper)
def __init__(self, zmq_url: str, parent=None):
super().__init__(parent)
@@ -20,6 +21,12 @@ class SampleCameraThread(QThread):
self.__socket.connect(zmq_url)
self.running = True
self.__measure_focus = True
@Slot(bool)
def enable_focus_measurement(self, enabled: bool = True):
"""Enable or disable focus measurement."""
self.__measure_focus = enabled
def run(self):
while self.running:
@@ -36,6 +43,12 @@ class SampleCameraThread(QThread):
rgb_image = cv2.cvtColor(bayer_image, cv2.COLOR_BAYER_GB2RGB)
#cv2.COLOR_BAYER_GB2RGB for ethernet connection
rgb_image = rgb_image[:, ::-1, :].copy()
if self.__measure_focus:
gray = cv2.cvtColor(rgb_image, cv2.COLOR_RGB2GRAY)
laplacian = cv2.Laplacian(gray, cv2.CV_64F)
self.focus_measure.emit(float(laplacian.var()))
qimage = QImage(rgb_image.data, header_shape[1], header_shape[0], #For ethernet need header_shape[0], header_shape[1], header_shape[0]*3,
QImage.Format.Format_RGB888)
self.camera_image.emit(QPixmap.fromImage(qimage))
+6
View File
@@ -32,6 +32,7 @@ class StatusBar(QStatusBar):
self.__is_staff = self.__decoded_token.staff
self.__allowed_pgroups = self.__decoded_token.pgroups
self.sharpness = ValueLabel("Samcam image sharpness", "", self)
self.flux = ValueLabel("Flux", "x 10<sup>9</sup> ph/s", self)
self.transmission = ValueLabel("Transmission", "", self)
self.ring_current = ValueLabel("Ring current", "mA", self)
@@ -53,6 +54,7 @@ class StatusBar(QStatusBar):
self.shutter_label.clicked.connect(self.show_shutter_menu)
self.exp_shutter_label = ValueLabel("ExpHutch Shutter", "", self)
self.addPermanentWidget(self.sharpness)
self.addPermanentWidget(self.flux)
self.addPermanentWidget(self.transmission)
self.addPermanentWidget(self.ring_current)
@@ -66,6 +68,10 @@ class StatusBar(QStatusBar):
self.addPermanentWidget(self.busy_label)
self.addPermanentWidget(self.session_label)
@Slot(float)
def update_sharpness(self, val: float):
self.sharpness.set_value(f"{val:.3f}")
@Slot(DAQStatusModel)
def update_daq_status(self, status: DAQStatusModel):
self.__status = status