Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculate average reprojection error when loading SimCameraProperties #1673

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

jlmcmchl
Copy link
Contributor

@jlmcmchl jlmcmchl commented Jan 2, 2025

Currently, exported photonvision camera configs cannot be loaded for sim use. Part of this is because SimCameraProperties expects the provided config file to include both the average and standard deviation of reprojection error measurements. Instead, the config file contains individual reprojection error measurements.

This PR improves sim support for the current exported camera calibration file from PhotonVision, additionally separating the X and Y pixel noise.

@jlmcmchl jlmcmchl requested a review from a team as a code owner January 2, 2025 07:44
double jsonErrorStdDevX = 0;
double jsonErrorStdDevY = 0;

if (jsonViewErrors != null && jsonErrorStdDev != null) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I bother with a fallback for the existing logic?

Copy link
Member

Choose a reason for hiding this comment

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

Probably unnecessary.

The load-by-path option here has not really been used since the SQLite storage was implemented and a calibration json was no longer easily accessible. Has this changed?

Copy link
Contributor

Choose a reason for hiding this comment

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

There is still currently no longer any way to access a camera config file no. The calibration json file is still easy to get. Let's kill this feature if we don't need it anymore?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Happy to yoink config file support if that's what we're looking to do here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've deprecated the two applicable constructors to this feature.

Copy link
Contributor

Choose a reason for hiding this comment

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

Given that we dropped support for this feature from the backend back in 2023, and the ctor is now a no-op, let's just delete them? Or open to your thoughts @amquake

Comment on lines 636 to 640
// error pixels in random direction
double error = avgErrorPx + rand.nextGaussian() * errorStdDevPx;
double errorAngle = rand.nextDouble() * 2 * Math.PI - Math.PI;
double errorX = avgErrorPxX + rand.nextGaussian() * errorStdDevPxX;
double errorY = avgErrorPxY + rand.nextGaussian() * errorStdDevPxY;
noisyPts[i] =
new Point(p.x + error * Math.cos(errorAngle), p.y + error * Math.sin(errorAngle));
new Point(p.x + errorX, p.y + errorY);
Copy link
Member

Choose a reason for hiding this comment

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

IIRC the previous "average error" from calibration seemed to report the average absolute error. The previous way of estimating noise tries to use both the average (absolute) error and standard deviation which is pretty goofy. I'm not sure these numbers even really make sense to use in the first place, considering they measure solely the reprojection error of the calibrated instrinsics.

Anyway, it probably makes more sense to just consider the corner pixel normally distributed with given standard deviation. Meaning, just remove (deprecate) the average view error from SimCameraProperties. This will noticeably lower the noise currently seen by whatever values are used, but the simulation already seemed to overestimate it.

Copy link
Contributor Author

@jlmcmchl jlmcmchl Jan 2, 2025

Choose a reason for hiding this comment

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

I figured I'd try separating x and y noise because I didn't want to assume that the shape of the pixel noise distribution was circular, but with removing support for file based configs there isn't much of a reason to keep it around. I found it to be useful because we could leverage existing data rather than come up with those values independent of calibration data.

In this changeset I opted to revert the separation of the two because otherwise we'd be deprecating setCalibError(double avgErrorPx, double errorStdDevPx) and introducing setCalibError(double errorStdDevPxX, double errorStdDevPxY). It's always easy to reintroduce at a better time,

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.

3 participants