Skip to content

Commit 10a266a

Browse files
committed
Monorepo Aruco Nano
1 parent 5212506 commit 10a266a

File tree

5 files changed

+690
-2
lines changed

5 files changed

+690
-2
lines changed

.styleguide

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ modifiableFileExclude {
2525
gradlew
2626
photon-lib/py/photonlibpy/generated/
2727
photon-targeting/src/main/native/cpp/photon/constrained_solvepnp/generate/
28+
photon-targeting/src/main/native/include/photon/aruco_nano.h
2829
photon-targeting/src/generated/
2930
}
3031

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import org.opencv.core.TermCriteria;
2727
import org.opencv.imgproc.Imgproc;
2828
import org.opencv.objdetect.Objdetect;
29+
import org.photonvision.jni.ArucoNanoV5Detector;
30+
import org.photonvision.jni.ArucoNanoV5Detector.DetectionResult;
2931
import org.photonvision.vision.aruco.ArucoDetectionResult;
3032
import org.photonvision.vision.aruco.PhotonArucoDetector;
3133
import org.photonvision.vision.opencv.CVMat;
@@ -53,7 +55,7 @@ protected List<ArucoDetectionResult> process(CVMat in) {
5355
return List.of();
5456
}
5557

56-
var detections = photonDetector.detect(imgMat);
58+
var detections = detect(imgMat);
5759
// manually do corner refinement ourselves
5860
if (params.useCornerRefinement) {
5961
for (var detection : detections) {
@@ -94,7 +96,7 @@ protected List<ArucoDetectionResult> process(CVMat in) {
9496
}
9597
}
9698
}
97-
return List.of(detections);
99+
return detections;
98100
}
99101

100102
@Override
@@ -134,6 +136,14 @@ private void drawCornerRefineWindow(Mat outputMat, Point corner, int windowSize)
134136
Imgproc.rectangle(outputMat, pt1, pt2, new Scalar(0, 0, 255), thickness);
135137
}
136138

139+
public static List<ArucoDetectionResult> detect(Mat in) {
140+
DetectionResult[] ret = ArucoNanoV5Detector.detect(in);
141+
142+
return List.of(ret).stream()
143+
.map(it -> new ArucoDetectionResult(it.xCorners(), it.yCorners(), it.id()))
144+
.toList();
145+
}
146+
137147
@Override
138148
public void release() {
139149
photonDetector.release();
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Copyright (C) Photon Vision.
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
package org.photonvision.jni;
19+
20+
import org.opencv.core.Mat;
21+
22+
public final class ArucoNanoV5Detector {
23+
public static record DetectionResult(double[] xCorners, double[] yCorners, int id) {}
24+
25+
/**
26+
* Detects Aruco markers.
27+
*
28+
* @param matPtr The pointer to the Mat to detect tags from.
29+
* @return A double array with the detections. Each detection is encoded as 9 doubles,
30+
* representing the XY corner coordinates for the 4 corners and a tag ID at the end.
31+
*/
32+
private static native double[] detect(long matPtr);
33+
34+
public static DetectionResult[] detect(Mat mat) {
35+
var detectionData = detect(mat.getNativeObjAddr());
36+
DetectionResult[] detections = new DetectionResult[(int) (detectionData.length / 9)];
37+
for (int i = 0; i < detectionData.length; i += 9) {
38+
double[] xCorners = {
39+
detectionData[i + 0], detectionData[i + 2], detectionData[i + 4], detectionData[i + 6]
40+
};
41+
double[] yCorners = {
42+
detectionData[i + 1], detectionData[i + 3], detectionData[i + 5], detectionData[i + 7]
43+
};
44+
detections[(int) (i / 9)] =
45+
new DetectionResult(xCorners, yCorners, (int) detectionData[i + 8]);
46+
}
47+
return detections;
48+
}
49+
}

0 commit comments

Comments
 (0)