DAQ: Doesn't work and don't know why
This commit is contained in:
@@ -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
@@ -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}")
|
||||
|
||||
Reference in New Issue
Block a user