refactor: use aarecommon and remove common
This commit is contained in:
1 parent
8f0a85316d
commit
13bddd43c7
172 files changed
+8267
-8214
No files matched your search
@@ -4,11 +4,11 @@ import time
|
||||
import cv2
|
||||
import numpy as np
|
||||
import zmq
|
||||
from aarecommon.math.autofocus import focus_measure_edges
|
||||
from aarecommon.models.models import DAQStatusModel
|
||||
from PySide6.QtCore import QThread, Signal, Slot
|
||||
from PySide6.QtGui import QImage, QPixmap
|
||||
|
||||
from aare.common.autofocus_tools import focus_measure_edges
|
||||
from aare.common.models import DAQStatusModel
|
||||
|
||||
class SampleCameraThread(QThread):
|
||||
# Define a signal to communicate messages from the thread to the main GUI
|
||||
@@ -106,7 +106,10 @@ class SampleCameraThread(QThread):
|
||||
encoded = np.frombuffer(data, dtype=np.uint8)
|
||||
bgr = cv2.imdecode(encoded, cv2.IMREAD_COLOR)
|
||||
if bgr is None:
|
||||
self.__set_camera_available(False, "Sample camera feed unavailable: failed to decode JPEG frame")
|
||||
self.__set_camera_available(
|
||||
False,
|
||||
"Sample camera feed unavailable: failed to decode JPEG frame",
|
||||
)
|
||||
continue
|
||||
rgb = cv2.cvtColor(bgr, cv2.COLOR_BGR2RGB)
|
||||
elif "shape" in header:
|
||||
@@ -114,26 +117,41 @@ class SampleCameraThread(QThread):
|
||||
raw = np.frombuffer(data, np.uint8).reshape((h, w))
|
||||
rgb = cv2.cvtColor(raw, cv2.COLOR_BAYER_GB2RGB)
|
||||
else:
|
||||
self.__set_camera_available(False, f"Sample camera feed unavailable: unsupported frame header {header}")
|
||||
self.__set_camera_available(
|
||||
False,
|
||||
f"Sample camera feed unavailable: unsupported frame header {header}",
|
||||
)
|
||||
continue
|
||||
|
||||
self.__set_camera_available(True)
|
||||
|
||||
if self.__measure_focus:
|
||||
gray = cv2.cvtColor(rgb, cv2.COLOR_RGB2GRAY)
|
||||
if self.__focus_mask is None or self.__focus_mask.shape != gray.shape:
|
||||
if (
|
||||
self.__focus_mask is None
|
||||
or self.__focus_mask.shape != gray.shape
|
||||
):
|
||||
height, width = gray.shape
|
||||
y, x = np.ogrid[:height, :width]
|
||||
self.__focus_mask = (x - self.__beam_x) ** 2 + (
|
||||
y - self.__beam_y) ** 2 <= self.__radius ** 2
|
||||
y - self.__beam_y
|
||||
) ** 2 <= self.__radius**2
|
||||
|
||||
sharpness = focus_measure_edges(gray, self.__focus_mask)
|
||||
self.focus_measure.emit(sharpness)
|
||||
|
||||
qimage = QImage(rgb.data, rgb.shape[1], rgb.shape[0], QImage.Format.Format_RGB888).copy()
|
||||
qimage = QImage(
|
||||
rgb.data,
|
||||
rgb.shape[1],
|
||||
rgb.shape[0],
|
||||
QImage.Format.Format_RGB888,
|
||||
).copy()
|
||||
self.camera_image.emit(QPixmap.fromImage(qimage))
|
||||
else:
|
||||
self.__set_camera_available(False, "Sample camera feed unavailable: no frame header in zmq stream")
|
||||
self.__set_camera_available(
|
||||
False,
|
||||
"Sample camera feed unavailable: no frame header in zmq stream",
|
||||
)
|
||||
except zmq.Again: # Timeout occurred
|
||||
now = time.perf_counter()
|
||||
elapsed = now - self.__fps_window_start
|
||||
@@ -147,10 +165,14 @@ class SampleCameraThread(QThread):
|
||||
self.__fps_frame_count = 0
|
||||
|
||||
if no_frames_long:
|
||||
self.__set_camera_available(False, "Sample camera feed unavailable")
|
||||
self.__set_camera_available(
|
||||
False, "Sample camera feed unavailable"
|
||||
)
|
||||
continue # Check self.running again
|
||||
except Exception as e:
|
||||
self.__set_camera_available(False, f"Sample camera feed unavailable: {e}")
|
||||
self.__set_camera_available(
|
||||
False, f"Sample camera feed unavailable: {e}"
|
||||
)
|
||||
self.running = False
|
||||
|
||||
def stop(self):
|
||||
|
||||
Reference in new issue
Block a user