DAQ: Doesn't work and don't know why

This commit is contained in:
2026-01-16 17:24:00 +01:00
parent 8c45eb7be9
commit 8ef96c9ca7
2 changed files with 9 additions and 8 deletions
+5
View File
@@ -16,9 +16,14 @@ def focus_measure_edges(gray: np.ndarray, mask: np.ndarray | None = None) -> flo
# threshold relative to median -> knocks out noise floor
t = float(np.median(roi) * 3.0)
strong = roi[roi > t]
if strong.size == 0:
return 0.0
print(f"mask pixels: {mask.sum()}, "
f"focus={strong.mean():.2f}"
f"strong_size={strong.size}")
return float(strong.mean()) # higher = sharper
def focus_measure_blob_size(gray: np.ndarray, mask: np.ndarray | None = None) -> float:
+4 -8
View File
@@ -408,11 +408,8 @@ class AareDAQ:
time.sleep(settle_time_s)
# Capture image
img = self.camera_image
img = img[:, ::-1, :].copy() # Apply horizontal flip to match GUI
gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
gray = self.camera_image_gray
print(gray.shape)
if gray is None:
logger.warning(f"Failed to get image at z={z_pos:.4f}")
continue
@@ -423,13 +420,12 @@ class AareDAQ:
y, x = np.ogrid[:h, :w]
focus_mask = (x - center_x) ** 2 + (y - center_y) ** 2 <= radius_pxl ** 2
print(focus_mask.shape)
print(gray.shape)
# Calculate focus measure
fm = focus_measure_edges(gray, focus_mask)
roi_pixels = gray[focus_mask] if focus_mask is not None else gray.ravel()[:2824]
print(f"Step {i}: gray mean={gray.mean():.1f}, roi mean={roi_pixels.mean():.1f}, "
f"roi std={roi_pixels.std():.1f}, roi min={roi_pixels.min()}, roi max={roi_pixels.max()}")
z_positions.append(z_pos)
focus_values.append(fm)
logger.debug(f"Autofocus step {i + 1}/{n_steps}: z={z_pos:.4f}mm, focus={fm:.2f}")