Skip to content

Commit 625dacb

Browse files
authored
Add QuadThresholdParameters to AprilTag config (#1519)
This works around a change made to the default QuadThresholdParameters in the WPILib AprilTagDetector for 2025. wpilibsuite/allwpilib#6847
1 parent fc8ecac commit 625dacb

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

photon-core/src/main/java/org/photonvision/vision/pipe/impl/AprilTagDetectionPipe.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ protected List<AprilTagDetection> process(CVMat in) {
5959
public void setParams(AprilTagDetectionPipeParams newParams) {
6060
if (this.params == null || !this.params.equals(newParams)) {
6161
m_detector.setConfig(newParams.detectorParams);
62+
m_detector.setQuadThresholdParameters(newParams.quadParams);
6263

6364
m_detector.clearFamilies();
6465
m_detector.addFamily(newParams.family.getNativeName());

photon-core/src/main/java/org/photonvision/vision/pipe/impl/AprilTagDetectionPipeParams.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,15 @@
2323
public class AprilTagDetectionPipeParams {
2424
public final AprilTagFamily family;
2525
public final AprilTagDetector.Config detectorParams;
26+
public final AprilTagDetector.QuadThresholdParameters quadParams;
2627

27-
public AprilTagDetectionPipeParams(AprilTagFamily tagFamily, AprilTagDetector.Config config) {
28+
public AprilTagDetectionPipeParams(
29+
AprilTagFamily tagFamily,
30+
AprilTagDetector.Config config,
31+
AprilTagDetector.QuadThresholdParameters quadParams) {
2832
this.family = tagFamily;
2933
this.detectorParams = config;
34+
this.quadParams = quadParams;
3035
}
3136

3237
@Override
@@ -35,6 +40,7 @@ public int hashCode() {
3540
int result = 1;
3641
result = prime * result + ((family == null) ? 0 : family.hashCode());
3742
result = prime * result + ((detectorParams == null) ? 0 : detectorParams.hashCode());
43+
result = prime * result + ((quadParams == null) ? 0 : quadParams.hashCode());
3844
return result;
3945
}
4046

@@ -46,7 +52,11 @@ public boolean equals(Object obj) {
4652
AprilTagDetectionPipeParams other = (AprilTagDetectionPipeParams) obj;
4753
if (family != other.family) return false;
4854
if (detectorParams == null) {
49-
return other.detectorParams == null;
50-
} else return detectorParams.equals(other.detectorParams);
55+
if (other.detectorParams != null) return false;
56+
} else if (!detectorParams.equals(other.detectorParams)) return false;
57+
if (quadParams == null) {
58+
if (other.quadParams != null) return false;
59+
} else if (!quadParams.equals(other.quadParams)) return false;
60+
return true;
5161
}
5262
}

photon-core/src/main/java/org/photonvision/vision/pipeline/AprilTagPipeline.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,21 @@ protected void setPipeParamsImpl() {
8787
config.refineEdges = settings.refineEdges;
8888
config.quadSigma = (float) settings.blur;
8989
config.quadDecimate = settings.decimate;
90-
aprilTagDetectionPipe.setParams(new AprilTagDetectionPipeParams(settings.tagFamily, config));
90+
91+
var quadParams = new AprilTagDetector.QuadThresholdParameters();
92+
// 5 was the default minClusterPixels in WPILib prior to 2025
93+
// increasing it causes detection problems when decimate > 1
94+
quadParams.minClusterPixels = 5;
95+
// these are the same as the values in WPILib 2025
96+
// setting them here to prevent upstream changes from changing behavior of the detector
97+
quadParams.maxNumMaxima = 10;
98+
quadParams.criticalAngle = 45 * Math.PI / 180.0;
99+
quadParams.maxLineFitMSE = 10.0f;
100+
quadParams.minWhiteBlackDiff = 5;
101+
quadParams.deglitch = false;
102+
103+
aprilTagDetectionPipe.setParams(
104+
new AprilTagDetectionPipeParams(settings.tagFamily, config, quadParams));
91105

92106
if (frameStaticProperties.cameraCalibration != null) {
93107
var cameraMatrix = frameStaticProperties.cameraCalibration.getCameraIntrinsicsMat();

0 commit comments

Comments
 (0)