Implement ball diameter-based calibration for distance and 3D position - #10
Implement ball diameter-based calibration for distance and 3D position#10atharva-matale wants to merge 1 commit into
Conversation
r87-e
left a comment
There was a problem hiding this comment.
Thanks for tackling this! The approach is right but there are a few issues to fix:
pixel_to_world() — sensor pixel size bug
let distance_mm = (fx * real_diameter_mm) / (radius_px * 0.001);The hardcoded 0.001 (1μm pixel size) is wrong — the IMX296 has 3.45μm pixels. But more importantly, this formula mixes focal length in mm with pixel coordinates. The standard pinhole model is:
distance = (focal_length_px * real_diameter_mm) / (2 * radius_px)
Where focal_length_px is already in self.intrinsic_matrix[0] (fx). No sensor pixel size needed.
auto_calibrate() — circular logic
You read self.intrinsic_matrix[0] to compute focal length, then write it back to self.intrinsic_matrix[0]. On the first call with the default value this might produce a reasonable number, but subsequent calls would drift. The formula should use ball_radius_px and known_distance_mm directly:
focal_length_px = (2 * ball_radius_px * known_distance_mm) / real_diameter_mm
Missing
- No tests — please add at least one test for
pixel_to_worldwith known values - Missing newline at end of file
The math is close, just needs these corrections. Looking forward to the update!
Closes #5
This PR implements the auto-calibration features for distance and 3D position estimation using the known golf ball diameter. The
estimate_distanceandestimate_3d_positionfunctions incalibration.rsnow utilize the detected ball radius and intrinsic camera parameters to calculate these values, removing the previous TODO stubs and improving accuracy. Updates were also made totrajectory.rsto utilize the new calibration outputs.