diff --git a/photon-core/src/main/java/org/photonvision/vision/pipe/impl/AprilTagDetectionPipe.java b/photon-core/src/main/java/org/photonvision/vision/pipe/impl/AprilTagDetectionPipe.java index 7931dbcb0a..e4737ce959 100644 --- a/photon-core/src/main/java/org/photonvision/vision/pipe/impl/AprilTagDetectionPipe.java +++ b/photon-core/src/main/java/org/photonvision/vision/pipe/impl/AprilTagDetectionPipe.java @@ -59,6 +59,7 @@ protected List 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()); diff --git a/photon-core/src/main/java/org/photonvision/vision/pipe/impl/AprilTagDetectionPipeParams.java b/photon-core/src/main/java/org/photonvision/vision/pipe/impl/AprilTagDetectionPipeParams.java index ab52d7bcfb..773a0d299b 100644 --- a/photon-core/src/main/java/org/photonvision/vision/pipe/impl/AprilTagDetectionPipeParams.java +++ b/photon-core/src/main/java/org/photonvision/vision/pipe/impl/AprilTagDetectionPipeParams.java @@ -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 @@ -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; } @@ -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; } } diff --git a/photon-core/src/main/java/org/photonvision/vision/pipeline/AprilTagPipeline.java b/photon-core/src/main/java/org/photonvision/vision/pipeline/AprilTagPipeline.java index a89d75d9dd..5cc9cc98f7 100644 --- a/photon-core/src/main/java/org/photonvision/vision/pipeline/AprilTagPipeline.java +++ b/photon-core/src/main/java/org/photonvision/vision/pipeline/AprilTagPipeline.java @@ -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();