mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-29 02:21:41 +00:00
Add QuadThresholdParameters to AprilTag config (#1519)
This works around a change made to the default QuadThresholdParameters in the WPILib AprilTagDetector for 2025. https://github.com/wpilibsuite/allwpilib/pull/6847
This commit is contained in:
@@ -59,6 +59,7 @@ public class AprilTagDetectionPipe
|
||||
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());
|
||||
|
||||
@@ -23,10 +23,15 @@ import org.photonvision.vision.apriltag.AprilTagFamily;
|
||||
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 class AprilTagDetectionPipeParams {
|
||||
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 class AprilTagDetectionPipeParams {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +87,21 @@ public class AprilTagPipeline extends CVPipeline<CVPipelineResult, AprilTagPipel
|
||||
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();
|
||||
|
||||
Reference in New Issue
Block a user