Hi everyone,
I am building a system to generate a scale-accurate top-down view of a large area using three ceiling-mounted 48MP webcams. While the stitching works visually, the real-world measurements (verified in ImageJ) are significantly off.
The Setup:
-
Cameras: 3x Webcams (8000x6000 px), fixed at the ceiling.
-
Reference: ArUco markers on the floor with known global coordinates (in mm).
-
Goal: A stitched image where 1 pixel represents 1 mm.
The Issue:
I am using pre-calculated Homography matrices (\(H\)) to warp the images onto a common canvas. Although the markers are detected and the math seems correct, the scale in the final output is inconsistent.
Key parts of my Stitching Logic:
I am loading pre-calculated Homography matrices that map pixels directly to millimeter coordinates:
# How I apply the transformation and stitching
def stitch_from_precalibrated(img_paths):
# px_per_mm is set to 1.0 as world coords are in mm
px_per_mm = config.get("px_per_mm_ref", 1.0)
# Calculate canvas size based on min/max marker coordinates (in mm)
all_world_points_mm = np.array([corner for marker in config['markers'].values() for corner in marker[0]], dtype=np.float32)
x_min_mm, y_min_mm = np.min(all_world_points_mm, axis=0)
x_max_mm, y_max_mm = np.max(all_world_points_mm, axis=0)
padding_px = 100
canvas_w = int(np.ceil(x_max_mm - x_min_mm)) + (2 * padding_px)
canvas_h = int(np.ceil(y_max_mm - y_min_mm)) + (2 * padding_px)
# Shift origin to fit everything on canvas
translation_matrix = np.array([[1, 0, -x_min_mm + padding_px],
[0, 1, -y_min_mm + padding_px],
[0, 0, 1]], dtype=np.float32)
for i, img in enumerate(images):
H = master_calibration_data[i]['H'] # Pre-calculated Homography
final_transform = translation_matrix @ H
# Warping to the large 1px = 1mm canvas
warped = cv2.warpPerspective(img, final_transform, (canvas_w, canvas_h))
# ... (masking and blending logic)
Verwende Code mit Vorsicht.
My Questions:
-
Lens Distortion: With 48MP resolution,
cv2.warpPerspectiveuses a linear homography. Is it possible that the radial distortion of the lenses (not accounted for before warping) is causing the scale drift towards the image edges? -
Order of Operations: Should I first
undistort()the raw frames using a camera matrix (\(K\)) and distortion coefficients (\(D\)) before applying the Homography, or can a Homography alone (calculated from markers) theoretically handle 48MP distortion? -
Coordinate Precision: At this high resolution, could the floating-point precision of the
translation_matrix @ Hmultiplication lead to measurable errors over a large canvas?
