Skip to content

Implement ball diameter-based calibration for distance and 3D position - #10

Open
atharva-matale wants to merge 1 commit into
r87-e:mainfrom
atharva-matale:jarvis-fix-1775375499
Open

Implement ball diameter-based calibration for distance and 3D position#10
atharva-matale wants to merge 1 commit into
r87-e:mainfrom
atharva-matale:jarvis-fix-1775375499

Conversation

@atharva-matale

Copy link
Copy Markdown

Closes #5

This PR implements the auto-calibration features for distance and 3D position estimation using the known golf ball diameter. The estimate_distance and estimate_3d_position functions in calibration.rs now 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 to trajectory.rs to utilize the new calibration outputs.

@r87-e r87-e left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_world with known values
  • Missing newline at end of file

The math is close, just needs these corrections. Looking forward to the update!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement auto-calibration from known ball diameter

2 participants