Skip to content

Commit 4a42ebd

Browse files
committed
Delete old Aruco
1 parent 3724a97 commit 4a42ebd

File tree

7 files changed

+27
-238
lines changed

7 files changed

+27
-238
lines changed

photon-core/src/main/java/org/photonvision/vision/aruco/PhotonArucoDetector.java

Lines changed: 0 additions & 131 deletions
This file was deleted.

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

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,16 @@
2525
import org.opencv.core.Size;
2626
import org.opencv.core.TermCriteria;
2727
import org.opencv.imgproc.Imgproc;
28-
import org.opencv.objdetect.Objdetect;
2928
import org.photonvision.jni.ArucoNanoV5Detector;
3029
import org.photonvision.jni.ArucoNanoV5Detector.DetectionResult;
3130
import org.photonvision.vision.aruco.ArucoDetectionResult;
32-
import org.photonvision.vision.aruco.PhotonArucoDetector;
3331
import org.photonvision.vision.opencv.CVMat;
3432
import org.photonvision.vision.opencv.Releasable;
3533
import org.photonvision.vision.pipe.CVPipe;
3634

3735
public class ArucoDetectionPipe
3836
extends CVPipe<CVMat, List<ArucoDetectionResult>, ArucoDetectionPipeParams>
3937
implements Releasable {
40-
// ArucoDetector wrapper class
41-
private final PhotonArucoDetector photonDetector = new PhotonArucoDetector();
4238

4339
// Ratio multiplied with image size and added to refinement window size
4440
private static final double kRefineWindowImageRatio = 0.004;
@@ -101,33 +97,9 @@ protected List<ArucoDetectionResult> process(CVMat in) {
10197

10298
@Override
10399
public void setParams(ArucoDetectionPipeParams newParams) {
104-
if (this.params == null || !this.params.equals(newParams)) {
105-
System.out.println("Changing tag family to " + newParams.tagFamily);
106-
photonDetector
107-
.getDetector()
108-
.setDictionary(Objdetect.getPredefinedDictionary(newParams.tagFamily));
109-
var detectParams = photonDetector.getParams();
110-
111-
detectParams.set_adaptiveThreshWinSizeMin(newParams.threshMinSize);
112-
detectParams.set_adaptiveThreshWinSizeStep(newParams.threshStepSize);
113-
detectParams.set_adaptiveThreshWinSizeMax(newParams.threshMaxSize);
114-
detectParams.set_adaptiveThreshConstant(newParams.threshConstant);
115-
116-
detectParams.set_errorCorrectionRate(newParams.errorCorrectionRate);
117-
118-
detectParams.set_useAruco3Detection(newParams.useAruco3);
119-
detectParams.set_minSideLengthCanonicalImg(newParams.aruco3MinCanonicalImgSide);
120-
detectParams.set_minMarkerLengthRatioOriginalImg((float) newParams.aruco3MinMarkerSideRatio);
121-
122-
photonDetector.setParams(detectParams);
123-
}
124-
125100
super.setParams(newParams);
126101
}
127102

128-
public PhotonArucoDetector getPhotonDetector() {
129-
return photonDetector;
130-
}
131103

132104
private void drawCornerRefineWindow(Mat outputMat, Point corner, int windowSize) {
133105
int thickness = (int) (Math.ceil(Math.max(outputMat.cols(), outputMat.rows()) * 0.003));
@@ -146,6 +118,5 @@ public static List<ArucoDetectionResult> detect(Mat in) {
146118

147119
@Override
148120
public void release() {
149-
photonDetector.release();
150121
}
151122
}

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

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,6 @@ public class ArucoDetectionPipeParams {
3030
public int threshMaxSize = 91;
3131
public double threshConstant = 10;
3232

33-
/**
34-
* Bits allowed to be corrected, expressed as a ratio of the tag families theoretical maximum.
35-
*
36-
* <p>E.g. 36h11 = 11 * errorCorrectionRate = Max error bits
37-
*/
38-
public double errorCorrectionRate = 0;
39-
4033
/**
4134
* If obtained corners should be iteratively refined. This should always be on for 3D estimation.
4235
*/
@@ -53,22 +46,6 @@ public class ArucoDetectionPipeParams {
5346

5447
public boolean debugRefineWindow = false;
5548

56-
/**
57-
* If the 'Aruco3' speedup should be used. This is similar to AprilTag's 'decimate' value, but
58-
* automatically determined with the given parameters.
59-
*
60-
* <p>T_i = aruco3MinMarkerSideRatio, and T_c = aruco3MinCanonicalImgSide
61-
*
62-
* <p>Scale factor = T_c / (T_c + T_i * max(img_width, img_height))
63-
*/
64-
public boolean useAruco3 = false;
65-
66-
/** Minimum side length of markers expressed as a ratio of the largest image dimension. */
67-
public double aruco3MinMarkerSideRatio = 0.02;
68-
69-
/** Minimum side length of the canonical image (marker after undoing perspective distortion). */
70-
public int aruco3MinCanonicalImgSide = 32;
71-
7249
@Override
7350
public boolean equals(Object o) {
7451
if (this == o) return true;
@@ -79,13 +56,9 @@ public boolean equals(Object o) {
7956
&& threshStepSize == that.threshStepSize
8057
&& threshMaxSize == that.threshMaxSize
8158
&& threshConstant == that.threshConstant
82-
&& errorCorrectionRate == that.errorCorrectionRate
8359
&& useCornerRefinement == that.useCornerRefinement
8460
&& refinementMaxIterations == that.refinementMaxIterations
85-
&& refinementMinErrorPx == that.refinementMinErrorPx
86-
&& useAruco3 == that.useAruco3
87-
&& aruco3MinMarkerSideRatio == that.aruco3MinMarkerSideRatio
88-
&& aruco3MinCanonicalImgSide == that.aruco3MinCanonicalImgSide;
61+
&& refinementMinErrorPx == that.refinementMinErrorPx;
8962
}
9063

9164
@Override
@@ -96,12 +69,8 @@ public int hashCode() {
9669
threshStepSize,
9770
threshMaxSize,
9871
threshConstant,
99-
errorCorrectionRate,
10072
useCornerRefinement,
10173
refinementMaxIterations,
102-
refinementMinErrorPx,
103-
useAruco3,
104-
aruco3MinMarkerSideRatio,
105-
aruco3MinCanonicalImgSide);
74+
refinementMinErrorPx);
10675
}
10776
}

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ private Rotation3d rvecToRotation3d(Mat mat) {
7171

7272
@Override
7373
protected AprilTagPoseEstimate process(ArucoDetectionResult in) {
74-
// We receive 2d corners as (BL, BR, TR, TL) but we want (BR, BL, TL, TR)
74+
// We receive 2d corners as (TL, TR, BR, BL) but we want (BR, BL, TL, TR)
7575
double[] xCorn = in.getXCorners();
7676
double[] yCorn = in.getYCorners();
77-
imagePoints.put(0, 0, new float[] {(float) xCorn[1], (float) yCorn[1]});
78-
imagePoints.put(1, 0, new float[] {(float) xCorn[0], (float) yCorn[0]});
79-
imagePoints.put(2, 0, new float[] {(float) xCorn[3], (float) yCorn[3]});
80-
imagePoints.put(3, 0, new float[] {(float) xCorn[2], (float) yCorn[2]});
77+
imagePoints.put(0, 0, new float[] {(float) xCorn[2], (float) yCorn[2]});
78+
imagePoints.put(1, 0, new float[] {(float) xCorn[3], (float) yCorn[3]});
79+
imagePoints.put(2, 0, new float[] {(float) xCorn[0], (float) yCorn[0]});
80+
imagePoints.put(3, 0, new float[] {(float) xCorn[1], (float) yCorn[1]});
8181

8282
float[] reprojErrors = new float[2];
8383
// very rarely the solvepnp solver returns NaN results, so we retry with slight noise added

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,6 @@
1515
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1616
*/
1717

18-
/*
19-
* Copyright (C) Photon Vision.
20-
*
21-
* This program is free software: you can redistribute it and/or modify
22-
* it under the terms of the GNU General Public License as published by
23-
* the Free Software Foundation, either version 3 of the License, or
24-
* (at your option) any later version.
25-
*
26-
* This program is distributed in the hope that it will be useful,
27-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
28-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29-
* GNU General Public License for more details.
30-
*
31-
* You should have received a copy of the GNU General Public License
32-
* along with this program. If not, see <https://www.gnu.org/licenses/>.
33-
*/
34-
3518
package org.photonvision.vision.pipeline;
3619

3720
import edu.wpi.first.apriltag.AprilTagPoseEstimate;
@@ -116,9 +99,6 @@ protected void setPipeParamsImpl() {
11699
params.useCornerRefinement = settings.useCornerRefinement;
117100
params.refinementMaxIterations = settings.refineNumIterations;
118101
params.refinementMinErrorPx = settings.refineMinErrorPx;
119-
params.useAruco3 = settings.useAruco3;
120-
params.aruco3MinMarkerSideRatio = settings.aruco3MinMarkerSideRatio;
121-
params.aruco3MinCanonicalImgSide = settings.aruco3MinCanonicalImgSide;
122102
arucoDetectionPipe.setParams(params);
123103

124104
if (frameStaticProperties.cameraCalibration != null) {

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ public class ArucoPipelineSettings extends AdvancedPipelineSettings {
3535
public int refineNumIterations = 30;
3636
public double refineMinErrorPx = 0.005;
3737

38-
public boolean useAruco3 = false;
39-
public double aruco3MinMarkerSideRatio = 0.02;
40-
public int aruco3MinCanonicalImgSide = 32;
41-
4238
public boolean doMultiTarget = false;
4339
public boolean doSingleTargetAlways = false;
4440

photon-core/src/test/java/org/photonvision/vision/pipeline/ArucoPipelineTest.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@
1919

2020
import static org.junit.jupiter.api.Assertions.assertEquals;
2121

22+
import java.io.IOException;
23+
2224
import edu.wpi.first.math.geometry.Translation3d;
2325
import org.junit.jupiter.api.BeforeEach;
2426
import org.junit.jupiter.api.Test;
2527
import org.photonvision.common.configuration.ConfigManager;
2628
import org.photonvision.common.util.TestUtils;
29+
import org.photonvision.jni.PhotonTargetingJniLoader;
2730
import org.photonvision.vision.apriltag.AprilTagFamily;
2831
import org.photonvision.vision.camera.QuirkyCamera;
2932
import org.photonvision.vision.frame.provider.FileFrameProvider;
@@ -32,8 +35,9 @@
3235

3336
public class ArucoPipelineTest {
3437
@BeforeEach
35-
public void setup() {
38+
public void setup() throws IOException {
3639
TestUtils.loadLibraries();
40+
PhotonTargetingJniLoader.load();
3741
ConfigManager.getInstance().load();
3842
}
3943

@@ -51,9 +55,9 @@ public void testApriltagFacingCamera() {
5155

5256
var frameProvider =
5357
new FileFrameProvider(
54-
TestUtils.getApriltagImagePath(TestUtils.ApriltagTestImages.kTag1_640_480, false),
55-
TestUtils.WPI2020Image.FOV,
56-
TestUtils.get2020LifeCamCoeffs(false));
58+
TestUtils.getTestImagesPath(false).resolve(TestUtils.WPI2024Images.kSpeakerCenter_143in.path),
59+
TestUtils.WPI2024Images.FOV,
60+
TestUtils.get2023LifeCamCoeffs(true));
5761
frameProvider.requestFrameThresholdType(pipeline.getThresholdType());
5862

5963
CVPipelineResult pipelineResult;
@@ -69,24 +73,24 @@ public void testApriltagFacingCamera() {
6973
TestUtils.showImage(ret.inputAndOutputFrame.processedImage.getMat(), "Pipeline output", 999999);
7074

7175
// these numbers are not *accurate*, but they are known and expected
72-
var target = pipelineResult.targets.get(0);
76+
var target = pipelineResult.targets.get(1); // tag 4
7377

7478
// Test corner order
7579
var corners = target.getTargetCorners();
76-
assertEquals(260, corners.get(0).x, 10);
77-
assertEquals(245, corners.get(0).y, 10);
78-
assertEquals(315, corners.get(1).x, 10);
79-
assertEquals(245, corners.get(1).y, 10);
80-
assertEquals(315, corners.get(2).x, 10);
81-
assertEquals(190, corners.get(2).y, 10);
82-
assertEquals(260, corners.get(3).x, 10);
83-
assertEquals(190, corners.get(3).y, 10);
80+
assertEquals(650, corners.get(3).x, 10);
81+
assertEquals(540, corners.get(3).y, 10);
82+
assertEquals(690, corners.get(2).x, 10);
83+
assertEquals(540, corners.get(2).y, 10);
84+
assertEquals(690, corners.get(1).x, 10);
85+
assertEquals(500, corners.get(1).y, 10);
86+
assertEquals(650, corners.get(0).x, 10);
87+
assertEquals(500, corners.get(0).y, 10);
8488

8589
var pose = target.getBestCameraToTarget3d();
8690
// Test pose estimate translation
87-
assertEquals(2, pose.getTranslation().getX(), 0.2);
88-
assertEquals(0.1, pose.getTranslation().getY(), 0.2);
89-
assertEquals(0.0, pose.getTranslation().getZ(), 0.2);
91+
assertEquals(4.8, pose.getTranslation().getX(), 0.2);
92+
assertEquals(-0.2, pose.getTranslation().getY(), 0.2);
93+
assertEquals(-0.7, pose.getTranslation().getZ(), 0.2);
9094

9195
// Test pose estimate rotation
9296
// We expect the object axes to be in NWU, with the x-axis coming out of the tag

0 commit comments

Comments
 (0)