Skip to content

Commit

Permalink
Add QuadThresholdParameters to AprilTag config (#1519)
Browse files Browse the repository at this point in the history
This works around a change made to the default QuadThresholdParameters in the WPILib AprilTagDetector for 2025.
wpilibsuite/allwpilib#6847
  • Loading branch information
crschardt authored Nov 4, 2024
1 parent fc8ecac commit 625dacb
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ protected List<AprilTagDetection> process(CVMat in) {
public void setParams(AprilTagDetectionPipeParams newParams) {
if (this.params == null || !this.params.equals(newParams)) {
m_detector.setConfig(newParams.detectorParams);
m_detector.setQuadThresholdParameters(newParams.quadParams);

m_detector.clearFamilies();
m_detector.addFamily(newParams.family.getNativeName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,15 @@
public class AprilTagDetectionPipeParams {
public final AprilTagFamily family;
public final AprilTagDetector.Config detectorParams;
public final AprilTagDetector.QuadThresholdParameters quadParams;

public AprilTagDetectionPipeParams(AprilTagFamily tagFamily, AprilTagDetector.Config config) {
public AprilTagDetectionPipeParams(
AprilTagFamily tagFamily,
AprilTagDetector.Config config,
AprilTagDetector.QuadThresholdParameters quadParams) {
this.family = tagFamily;
this.detectorParams = config;
this.quadParams = quadParams;
}

@Override
Expand All @@ -35,6 +40,7 @@ public int hashCode() {
int result = 1;
result = prime * result + ((family == null) ? 0 : family.hashCode());
result = prime * result + ((detectorParams == null) ? 0 : detectorParams.hashCode());
result = prime * result + ((quadParams == null) ? 0 : quadParams.hashCode());
return result;
}

Expand All @@ -46,7 +52,11 @@ public boolean equals(Object obj) {
AprilTagDetectionPipeParams other = (AprilTagDetectionPipeParams) obj;
if (family != other.family) return false;
if (detectorParams == null) {
return other.detectorParams == null;
} else return detectorParams.equals(other.detectorParams);
if (other.detectorParams != null) return false;
} else if (!detectorParams.equals(other.detectorParams)) return false;
if (quadParams == null) {
if (other.quadParams != null) return false;
} else if (!quadParams.equals(other.quadParams)) return false;
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,21 @@ protected void setPipeParamsImpl() {
config.refineEdges = settings.refineEdges;
config.quadSigma = (float) settings.blur;
config.quadDecimate = settings.decimate;
aprilTagDetectionPipe.setParams(new AprilTagDetectionPipeParams(settings.tagFamily, config));

var quadParams = new AprilTagDetector.QuadThresholdParameters();
// 5 was the default minClusterPixels in WPILib prior to 2025
// increasing it causes detection problems when decimate > 1
quadParams.minClusterPixels = 5;
// these are the same as the values in WPILib 2025
// setting them here to prevent upstream changes from changing behavior of the detector
quadParams.maxNumMaxima = 10;
quadParams.criticalAngle = 45 * Math.PI / 180.0;
quadParams.maxLineFitMSE = 10.0f;
quadParams.minWhiteBlackDiff = 5;
quadParams.deglitch = false;

aprilTagDetectionPipe.setParams(
new AprilTagDetectionPipeParams(settings.tagFamily, config, quadParams));

if (frameStaticProperties.cameraCalibration != null) {
var cameraMatrix = frameStaticProperties.cameraCalibration.getCameraIntrinsicsMat();
Expand Down

0 comments on commit 625dacb

Please sign in to comment.