From f4a3fba57c450babcd7e4929038e04aa7133c249 Mon Sep 17 00:00:00 2001 From: Gold856 <117957790+Gold856@users.noreply.github.com> Date: Tue, 7 Nov 2023 19:15:20 -0500 Subject: [PATCH] [apriltag] Improve AprilTagDetector's default config --- .../java/edu/wpi/first/apriltag/AprilTagDetector.java | 9 +++++---- apriltag/src/main/native/cpp/AprilTagDetector.cpp | 4 +++- .../main/native/include/frc/apriltag/AprilTagDetector.h | 8 ++++---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/apriltag/src/main/java/edu/wpi/first/apriltag/AprilTagDetector.java b/apriltag/src/main/java/edu/wpi/first/apriltag/AprilTagDetector.java index 8b0d5ca721d..b09c973e687 100644 --- a/apriltag/src/main/java/edu/wpi/first/apriltag/AprilTagDetector.java +++ b/apriltag/src/main/java/edu/wpi/first/apriltag/AprilTagDetector.java @@ -112,8 +112,8 @@ public boolean equals(Object obj) { /** Quad threshold parameters. */ @SuppressWarnings("MemberName") public static class QuadThresholdParameters { - /** Threshold used to reject quads containing too few pixels. Default is 5 pixels. */ - public int minClusterPixels = 5; + /** Threshold used to reject quads containing too few pixels. Default is 300 pixels. */ + public int minClusterPixels = 300; /** * How many corner candidates to consider when segmenting a group of pixels into a quad. Default @@ -124,9 +124,9 @@ public static class QuadThresholdParameters { /** * Critical angle, in radians. The detector will reject quads where pairs of edges have angles * that are close to straight or close to 180 degrees. Zero means that no quads are rejected. - * Default is 10 degrees. + * Default is 45 degrees. */ - public double criticalAngle = 10 * Math.PI / 180.0; + public double criticalAngle = 45 * Math.PI / 180.0; /** * When fitting lines to the contours, the maximum mean squared error allowed. This is useful in @@ -203,6 +203,7 @@ public boolean equals(Object obj) { /** Constructs an AprilTagDetector. */ public AprilTagDetector() { m_native = AprilTagJNI.createDetector(); + setQuadThresholdParameters(new QuadThresholdParameters()); } @Override diff --git a/apriltag/src/main/native/cpp/AprilTagDetector.cpp b/apriltag/src/main/native/cpp/AprilTagDetector.cpp index cae9c0a5e59..036dc20431f 100644 --- a/apriltag/src/main/native/cpp/AprilTagDetector.cpp +++ b/apriltag/src/main/native/cpp/AprilTagDetector.cpp @@ -46,7 +46,9 @@ void AprilTagDetector::Results::Destroy() { } } -AprilTagDetector::AprilTagDetector() : m_impl{apriltag_detector_create()} {} +AprilTagDetector::AprilTagDetector() : m_impl{apriltag_detector_create()} { + SetQuadThresholdParameters({}); +} AprilTagDetector& AprilTagDetector::operator=(AprilTagDetector&& rhs) { Destroy(); diff --git a/apriltag/src/main/native/include/frc/apriltag/AprilTagDetector.h b/apriltag/src/main/native/include/frc/apriltag/AprilTagDetector.h index 59dedf1a7f1..29e5b79d4f8 100644 --- a/apriltag/src/main/native/include/frc/apriltag/AprilTagDetector.h +++ b/apriltag/src/main/native/include/frc/apriltag/AprilTagDetector.h @@ -83,10 +83,10 @@ class WPILIB_DLLEXPORT AprilTagDetector { bool operator==(const QuadThresholdParameters&) const = default; /** - * Threshold used to reject quads containing too few pixels. Default is 5 + * Threshold used to reject quads containing too few pixels. Default is 300 * pixels. */ - int minClusterPixels = 5; + int minClusterPixels = 300; /** * How many corner candidates to consider when segmenting a group of pixels @@ -97,9 +97,9 @@ class WPILIB_DLLEXPORT AprilTagDetector { /** * Critical angle. The detector will reject quads where pairs of edges have * angles that are close to straight or close to 180 degrees. Zero means - * that no quads are rejected. Default is 10 degrees. + * that no quads are rejected. Default is 45 degrees. */ - units::radian_t criticalAngle = 10_deg; + units::radian_t criticalAngle = 45_deg; /** * When fitting lines to the contours, the maximum mean squared error