Remove PhotonJNICommon in favor of CombinedRuntimeLoader (#2223)

## Description

PhotonJNICommon is just our implementation of combined runtime loader,
which we don't really need. This removes it and just uses
CombinedRuntimeLoader directly. This also fixes the issues introduced in
#2219, which lead to some of our JNIs not loading.

## Meta

Merge checklist:
- [x] Pull Request title is [short, imperative
summary](https://cbea.ms/git-commit/) of proposed changes
- [x] The description documents the _what_ and _why_
- [ ] If this PR changes behavior or adds a feature, user documentation
is updated
- [ ] If this PR touches photon-serde, all messages have been
regenerated and hashes have not changed unexpectedly
- [ ] If this PR touches configuration, this is backwards compatible
with settings back to v2025.3.2
- [ ] If this PR touches pipeline settings or anything related to data
exchange, the frontend typing is updated
- [x] If this PR addresses a bug, a regression test for it is added

---------

Co-authored-by: Matt M <matthew.morley.ca@gmail.com>
This commit is contained in:
Sam Freund
2025-12-09 02:39:41 -06:00
committed by GitHub
parent 0c4c310c66
commit 1bb05a0e3e
37 changed files with 169 additions and 388 deletions

View File

@@ -416,35 +416,31 @@ jobs:
fail-fast: false
matrix:
include:
- os: ubuntu-24.04
artifact-name: LinuxArm64
image_suffix: RaspberryPi
- image_suffix: RaspberryPi
image_url: https://github.com/PhotonVision/photon-image-modifier/releases/download/$IMAGE_VERSION/photonvision_raspi.img.xz
cpu: cortex-a7
image_additional_mb: 0
extraOpts: -Djdk.lang.Process.launchMechanism=vfork
- image_suffix: rubikpi3
image_url: https://github.com/PhotonVision/photon-image-modifier/releases/download/$IMAGE_VERSION/photonvision_rubikpi3.tar.xz
root_location: 'offset=569376768'
- image_suffix: orangepi5
image_url: https://github.com/PhotonVision/photon-image-modifier/releases/download/$IMAGE_VERSION/photonvision_opi5.img.xz
runs-on: ${{ matrix.os }}
runs-on: ubuntu-24.04-arm
name: smoketest-${{ matrix.image_suffix }}
steps:
- uses: actions/download-artifact@v4
with:
name: jar-${{ matrix.artifact-name }}
name: jar-LinuxArm64
- uses: pguyot/arm-runner-action@v2
- uses: photonvision/photon-image-runner@HEAD
name: Run photon smoketest
id: generate_image
with:
base_image: ${{ matrix.image_url }}
image_additional_mb: ${{ matrix.image_additional_mb }}
optimize_image: yes
cpu: ${{ matrix.cpu }}
# We do _not_ wanna copy photon into the image. Bind mount instead
bind_mount_repository: true
image_url: ${{ matrix.image_url }}
root_location: ${{ matrix.root_location || 'partition=2' }}
# our image better have java installed already
commands: |
java -jar ${{ matrix.extraOpts }} *.jar --smoketest
java -jar *.jar --smoketest
build-image:
needs: [build-package]

View File

@@ -37,9 +37,9 @@ ext {
openCVYear = "2025"
openCVversion = "4.10.0-3"
javalinVersion = "6.7.0"
libcameraDriverVersion = "v2025.0.4"
rknnVersion = "dev-v2025.0.0-5-g666c0c6"
rubikVersion = "dev-v2025.1.0-6-g4a5e508"
libcameraDriverVersion = "dev-v2025.0.4-2-gc91d4b7"
rknnVersion = "dev-v2025.0.0-7-g83c1bf3"
rubikVersion = "dev-v2025.1.0-7-g39588a8"
frcYear = "2025"
mrcalVersion = "dev-v2025.0.0-2-g2adb187";

View File

@@ -28,25 +28,31 @@ dependencies {
wpilibNatives wpilibTools.deps.wpilib("hal")
wpilibNatives wpilibTools.deps.wpilibOpenCv("frc" + openCVYear, wpi.versions.opencvVersion.get())
// Zip
// These stay as implementation dependencies since they don't have native code that gets packaged
implementation 'org.zeroturnaround:zt-zip:1.14'
implementation "org.xerial:sqlite-jdbc:3.41.0.0"
implementation("org.photonvision:rknn_jni-jni:$rknnVersion:linuxarm64") {
transitive = false
// The JNI libraries use wpilibNatives, the java libraries use implementation
if (jniPlatform == "linuxarm64") {
wpilibNatives("org.photonvision:rknn_jni-jni:$rknnVersion:$wpilibNativeName") {
transitive = false
}
wpilibNatives("org.photonvision:rubik_jni-jni:$rubikVersion:$wpilibNativeName") {
transitive = false
}
wpilibNatives("org.photonvision:photon-libcamera-gl-driver-jni:$libcameraDriverVersion:$wpilibNativeName") {
transitive = false
}
}
implementation("org.photonvision:rknn_jni-java:$rknnVersion") {
transitive = false
}
implementation("org.photonvision:rubik_jni-jni:$rubikVersion:linuxarm64") {
transitive = false
}
implementation("org.photonvision:rubik_jni-java:$rubikVersion") {
transitive = false
}
implementation("org.photonvision:photon-libcamera-gl-driver-jni:$libcameraDriverVersion:linuxarm64") {
transitive = false
}
implementation "org.photonvision:photon-libcamera-gl-driver-java:$libcameraDriverVersion"
implementation "org.photonvision:photon-mrcal-java:$mrcalVersion"

View File

@@ -0,0 +1,59 @@
/*
* Copyright (C) Photon Vision.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.photonvision.common;
import edu.wpi.first.util.CombinedRuntimeLoader;
import java.io.IOException;
import java.util.HashMap;
import org.photonvision.jni.LibraryLoader;
public class LoadJNI {
private static HashMap<JNITypes, Boolean> loadedMap = new HashMap<>();
public enum JNITypes {
RUBIK_DETECTOR("tensorflowlite", "tensorflowlite_c", "external_delegate", "rubik_jni"),
RKNN_DETECTOR("rga", "rknnrt", "rknn_jni"),
MRCAL("mrcal_jni"),
LIBCAMERA("photonlibcamera");
public final String[] libraries;
JNITypes(String... libraries) {
this.libraries = libraries;
}
}
public static synchronized void forceLoad(JNITypes type) throws IOException {
loadLibraries();
if (loadedMap.getOrDefault(type, false)) {
return;
}
CombinedRuntimeLoader.loadLibraries(LoadJNI.class, type.libraries);
loadedMap.put(type, true);
}
public static boolean loadLibraries() {
return LibraryLoader.loadWpiLibraries() && LibraryLoader.loadTargeting();
}
public static boolean hasLoaded(JNITypes t) {
return loadedMap.getOrDefault(t, false);
}
}

View File

@@ -19,14 +19,14 @@ package org.photonvision.common.dataflow.websocket;
import java.util.List;
import org.photonvision.PhotonVersion;
import org.photonvision.common.LoadJNI;
import org.photonvision.common.LoadJNI.JNITypes;
import org.photonvision.common.configuration.NeuralNetworkModelManager;
import org.photonvision.common.configuration.PhotonConfiguration;
import org.photonvision.common.dataflow.networktables.NetworkTablesManager;
import org.photonvision.common.hardware.Platform;
import org.photonvision.common.networking.NetworkManager;
import org.photonvision.common.networking.NetworkUtils;
import org.photonvision.common.util.TestUtils;
import org.photonvision.raspi.LibCameraJNILoader;
import org.photonvision.vision.processes.VisionModule;
import org.photonvision.vision.processes.VisionSourceManager;
@@ -53,8 +53,8 @@ public class UIPhotonConfiguration {
new UIGeneralSettings(
PhotonVersion.versionString,
// TODO add support for other types of GPU accel
LibCameraJNILoader.getInstance().isSupported() ? "Zerocopy Libcamera Working" : "",
TestUtils.isMrcalLoaded(),
LoadJNI.hasLoaded(JNITypes.LIBCAMERA) ? "Zerocopy Libcamera Working" : "",
LoadJNI.hasLoaded(JNITypes.MRCAL),
c.neuralNetworkPropertyManager().getModels(),
NeuralNetworkModelManager.getInstance().getSupportedBackends(),
c.getHardwareConfig().deviceName.isEmpty()

View File

@@ -20,41 +20,17 @@ package org.photonvision.common.util;
import com.fasterxml.jackson.databind.ObjectMapper;
import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.math.util.Units;
import edu.wpi.first.util.CombinedRuntimeLoader;
import java.awt.HeadlessException;
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import org.opencv.core.Mat;
import org.opencv.highgui.HighGui;
import org.photonvision.jni.LibraryLoader;
import org.photonvision.vision.calibration.CameraCalibrationCoefficients;
import org.photonvision.vision.pipeline.result.CVPipelineResult;
import org.photonvision.vision.target.TrackedTarget;
public class TestUtils {
private static boolean hasMrcalLoaded = false;
public static boolean loadLibraries() {
return LibraryLoader.loadWpiLibraries() && LibraryLoader.loadTargeting();
}
public static boolean loadMrcal() {
if (hasMrcalLoaded) return true;
try {
CombinedRuntimeLoader.loadLibraries(TestUtils.class, "mrcal_jni");
hasMrcalLoaded = true;
} catch (IOException e) {
e.printStackTrace();
hasMrcalLoaded = false;
}
return hasMrcalLoaded;
}
public static boolean isMrcalLoaded() {
return hasMrcalLoaded;
}
@SuppressWarnings("unused")
public enum WPI2019Image {
kCargoAngledDark48in(1.2192),

View File

@@ -1,76 +0,0 @@
/*
* Copyright (C) Photon Vision.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.photonvision.jni;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
import java.util.List;
import org.photonvision.common.hardware.Platform;
import org.photonvision.common.logging.LogGroup;
import org.photonvision.common.logging.Logger;
public abstract class PhotonJNICommon {
public abstract boolean isLoaded();
public abstract void setLoaded(boolean state);
protected static Logger logger = null;
protected static synchronized void forceLoad(
PhotonJNICommon instance, Class<?> clazz, List<String> libraries) throws IOException {
if (instance.isLoaded()) return;
if (logger == null) logger = new Logger(clazz, LogGroup.General);
for (var libraryName : libraries) {
logger.info("Loading " + libraryName);
// We always extract the shared object (we could hash each so, but that's a lot
// of work)
var arch_name = Platform.getNativeLibraryFolderName();
var nativeLibName = System.mapLibraryName(libraryName);
try (var in =
clazz.getResourceAsStream("/nativelibraries/" + arch_name + "/" + nativeLibName)) {
if (in == null) {
logger.error("Could not find " + libraryName);
instance.setLoaded(false);
return;
}
// It's important that we don't mangle the names of these files
var temp = Files.createTempDirectory("nativeExtract").resolve(nativeLibName);
Files.copy(in, temp, StandardCopyOption.REPLACE_EXISTING);
try {
System.load(temp.toAbsolutePath().toString());
logger.info("Successfully loaded shared object " + temp.getFileName());
} catch (UnsatisfiedLinkError e) {
logger.error("Couldn't load shared object " + libraryName, e);
e.printStackTrace();
instance.setLoaded(false);
return;
}
}
}
instance.setLoaded(true);
}
protected static synchronized void forceLoad(
PhotonJNICommon instance, Class<?> clazz, String libraryName) throws IOException {
forceLoad(instance, clazz, List.of(libraryName));
}
}

View File

@@ -1,53 +0,0 @@
/*
* Copyright (C) Photon Vision.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.photonvision.jni;
import java.io.IOException;
import java.util.List;
import org.photonvision.common.util.TestUtils;
public class RknnDetectorJNI extends PhotonJNICommon {
private boolean isLoaded;
private static RknnDetectorJNI instance = null;
private RknnDetectorJNI() {
isLoaded = false;
}
public static RknnDetectorJNI getInstance() {
if (instance == null) instance = new RknnDetectorJNI();
return instance;
}
public static synchronized void forceLoad() throws IOException {
TestUtils.loadLibraries();
forceLoad(getInstance(), RknnDetectorJNI.class, List.of("rga", "rknnrt", "rknn_jni"));
}
@Override
public boolean isLoaded() {
return isLoaded;
}
@Override
public void setLoaded(boolean state) {
isLoaded = state;
}
}

View File

@@ -1,56 +0,0 @@
/*
* Copyright (C) Photon Vision.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.photonvision.jni;
import java.io.IOException;
import java.util.List;
import org.photonvision.common.util.TestUtils;
public class RubikDetectorJNI extends PhotonJNICommon {
private boolean isLoaded;
private static RubikDetectorJNI instance = null;
private RubikDetectorJNI() {
isLoaded = false;
}
public static RubikDetectorJNI getInstance() {
if (instance == null) instance = new RubikDetectorJNI();
return instance;
}
public static synchronized void forceLoad() throws IOException {
TestUtils.loadLibraries();
forceLoad(
getInstance(),
RubikDetectorJNI.class,
List.of("tensorflowlite", "tensorflowlite_c", "external_delegate", "rubik_jni"));
}
@Override
public boolean isLoaded() {
return isLoaded;
}
@Override
public void setLoaded(boolean state) {
isLoaded = state;
}
}

View File

@@ -1,53 +0,0 @@
/*
* Copyright (C) Photon Vision.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.photonvision.raspi;
import java.io.IOException;
import java.util.List;
import org.photonvision.jni.PhotonJNICommon;
/** Helper for extracting photon-libcamera-gl-driver shared library files. */
public class LibCameraJNILoader extends PhotonJNICommon {
private boolean libraryLoaded = false;
private static LibCameraJNILoader instance = null;
public static synchronized LibCameraJNILoader getInstance() {
if (instance == null) instance = new LibCameraJNILoader();
return instance;
}
public static synchronized void forceLoad() throws IOException {
forceLoad(
LibCameraJNILoader.getInstance(), LibCameraJNILoader.class, List.of("photonlibcamera"));
}
@Override
public boolean isLoaded() {
return libraryLoaded;
}
@Override
public void setLoaded(boolean state) {
libraryLoaded = state;
}
public boolean isSupported() {
return libraryLoaded && LibCameraJNI.isSupported();
}
}

View File

@@ -26,13 +26,12 @@ import org.opencv.core.Size;
import org.photonvision.common.logging.LogGroup;
import org.photonvision.common.logging.Logger;
import org.photonvision.common.util.ColorHelper;
import org.photonvision.jni.RknnDetectorJNI;
import org.photonvision.rknn.RknnJNI;
import org.photonvision.vision.pipe.impl.NeuralNetworkPipeResult;
/** Manages an object detector using the rknn backend. */
public class RknnObjectDetector implements ObjectDetector {
private static final Logger logger = new Logger(RknnDetectorJNI.class, LogGroup.General);
private static final Logger logger = new Logger(RknnObjectDetector.class, LogGroup.General);
/** Cleaner instance to release the detector when it goes out of scope */
private final Cleaner cleaner = Cleaner.create();

View File

@@ -26,13 +26,12 @@ import org.opencv.core.Size;
import org.photonvision.common.logging.LogGroup;
import org.photonvision.common.logging.Logger;
import org.photonvision.common.util.ColorHelper;
import org.photonvision.jni.RubikDetectorJNI;
import org.photonvision.rubik.RubikJNI;
import org.photonvision.vision.pipe.impl.NeuralNetworkPipeResult;
/** Manages an object detector using the rubik backend. */
public class RubikObjectDetector implements ObjectDetector {
private static final Logger logger = new Logger(RubikDetectorJNI.class, LogGroup.General);
private static final Logger logger = new Logger(RubikObjectDetector.class, LogGroup.General);
/** Cleaner instance to release the detector when it goes out of scope */
private final Cleaner cleaner = Cleaner.create();

View File

@@ -27,9 +27,10 @@ import org.apache.commons.io.FileUtils;
import org.opencv.calib3d.Calib3d;
import org.opencv.core.*;
import org.opencv.imgcodecs.Imgcodecs;
import org.photonvision.common.LoadJNI;
import org.photonvision.common.LoadJNI.JNITypes;
import org.photonvision.common.logging.LogGroup;
import org.photonvision.common.logging.Logger;
import org.photonvision.common.util.TestUtils;
import org.photonvision.common.util.math.MathUtils;
import org.photonvision.mrcal.MrCalJNI;
import org.photonvision.mrcal.MrCalJNI.MrCalResult;
@@ -94,7 +95,7 @@ public class Calibrate3dPipe
CameraCalibrationCoefficients ret;
var start = System.nanoTime();
if (TestUtils.isMrcalLoaded() && params.useMrCal) {
if (LoadJNI.hasLoaded(JNITypes.MRCAL) && params.useMrCal) {
logger.debug("Calibrating with mrcal!");
ret =
calibrateMrcal(

View File

@@ -27,6 +27,8 @@ import java.util.Optional;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import org.photonvision.common.LoadJNI;
import org.photonvision.common.LoadJNI.JNITypes;
import org.photonvision.common.configuration.CameraConfiguration;
import org.photonvision.common.configuration.ConfigManager;
import org.photonvision.common.dataflow.DataChangeService;
@@ -40,7 +42,6 @@ import org.photonvision.common.logging.LogGroup;
import org.photonvision.common.logging.Logger;
import org.photonvision.common.util.TimedTaskManager;
import org.photonvision.raspi.LibCameraJNI;
import org.photonvision.raspi.LibCameraJNILoader;
import org.photonvision.vision.camera.CameraType;
import org.photonvision.vision.camera.FileVisionSource;
import org.photonvision.vision.camera.PVCameraInfo;
@@ -301,7 +302,7 @@ public class VisionSourceManager {
.filter(c -> !(String.join("", c.otherPaths()).contains("csi-video")))
.filter(c -> !c.name().equals("unicam"))
.forEach(cameraInfos::add);
if (LibCameraJNILoader.getInstance().isSupported()) {
if (LoadJNI.hasLoaded(JNITypes.LIBCAMERA)) {
// find all CSI cameras (Raspberry Pi cameras)
Stream.of(LibCameraJNI.getCameraNames())
.map(

View File

@@ -40,7 +40,7 @@ import org.photonvision.vision.pipeline.result.CVPipelineResult;
public class BenchmarkTest {
@BeforeAll
public static void init() {
TestUtils.loadLibraries();
LoadJNI.loadLibraries();
}
@Test

View File

@@ -56,7 +56,7 @@ import org.photonvision.vision.pipeline.result.CVPipelineResult;
public class ShapeBenchmarkTest {
@BeforeAll
public static void init() {
TestUtils.loadLibraries();
LoadJNI.loadLibraries();
}
@Test

View File

@@ -28,10 +28,10 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.*;
import org.photonvision.common.LoadJNI;
import org.photonvision.common.logging.LogGroup;
import org.photonvision.common.logging.LogLevel;
import org.photonvision.common.logging.Logger;
import org.photonvision.common.util.TestUtils;
import org.photonvision.common.util.file.JacksonUtils;
import org.photonvision.vision.camera.PVCameraInfo;
import org.photonvision.vision.pipeline.AprilTagPipelineSettings;
@@ -51,7 +51,7 @@ public class ConfigTest {
@BeforeAll
public static void init() {
TestUtils.loadLibraries();
LoadJNI.loadLibraries();
var path = Path.of("testconfigdir");
configMgr = new ConfigManager(path, new LegacyConfigProvider(path));
configMgr.load();
@@ -79,7 +79,7 @@ public class ConfigTest {
@Test
@Order(1)
public void serializeConfig() {
TestUtils.loadLibraries();
LoadJNI.loadLibraries();
Logger.setLevel(LogGroup.General, LogLevel.TRACE);
configMgr.getConfig().addCameraConfig(cameraConfig);

View File

@@ -27,6 +27,7 @@ import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.photonvision.common.LoadJNI;
import org.photonvision.common.util.TestUtils;
import org.photonvision.vision.camera.CameraQuirk;
import org.photonvision.vision.camera.PVCameraInfo;
@@ -39,7 +40,7 @@ public class SQLConfigTest {
@BeforeAll
public static void init() {
TestUtils.loadLibraries();
LoadJNI.loadLibraries();
}
@Test

View File

@@ -25,12 +25,13 @@ import edu.wpi.first.math.geometry.Transform3d;
import edu.wpi.first.math.geometry.Translation3d;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.photonvision.common.LoadJNI;
import org.photonvision.common.util.math.MathUtils;
public class CoordinateConversionTest {
@BeforeAll
public static void Init() {
TestUtils.loadLibraries();
LoadJNI.loadLibraries();
}
@Test

View File

@@ -21,17 +21,17 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import org.photonvision.common.LoadJNI;
import org.photonvision.common.hardware.GPIO.CustomGPIO;
import org.photonvision.common.hardware.GPIO.GPIOBase;
import org.photonvision.common.hardware.GPIO.pi.PigpioPin;
import org.photonvision.common.hardware.Platform;
import org.photonvision.common.hardware.metrics.MetricsManager;
import org.photonvision.common.util.TestUtils;
public class HardwareTest {
@Test
public void testHardware() {
TestUtils.loadLibraries();
LoadJNI.loadLibraries();
MetricsManager mm = new MetricsManager();
if (!Platform.isRaspberryPi()) return;

View File

@@ -23,13 +23,14 @@ import java.nio.file.Files;
import java.nio.file.Paths;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.photonvision.common.LoadJNI;
import org.photonvision.common.util.TestUtils;
import org.photonvision.vision.frame.Frame;
public class FileFrameProviderTest {
@BeforeAll
public static void initPath() {
TestUtils.loadLibraries();
LoadJNI.loadLibraries();
}
@Test

View File

@@ -25,12 +25,12 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.opencv.core.MatOfPoint;
import org.opencv.core.Point;
import org.photonvision.common.util.TestUtils;
import org.photonvision.common.LoadJNI;
public class ContourTest {
@BeforeEach
public void Init() {
TestUtils.loadLibraries();
LoadJNI.loadLibraries();
}
@Test

View File

@@ -22,6 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import edu.wpi.first.math.geometry.Translation3d;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.photonvision.common.LoadJNI;
import org.photonvision.common.configuration.ConfigManager;
import org.photonvision.common.util.TestUtils;
import org.photonvision.vision.apriltag.AprilTagFamily;
@@ -33,7 +34,7 @@ import org.photonvision.vision.target.TargetModel;
public class AprilTagTest {
@BeforeEach
public void setup() {
TestUtils.loadLibraries();
LoadJNI.loadLibraries();
ConfigManager.getInstance().load();
}

View File

@@ -22,6 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import edu.wpi.first.math.geometry.Translation3d;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.photonvision.common.LoadJNI;
import org.photonvision.common.configuration.ConfigManager;
import org.photonvision.common.util.TestUtils;
import org.photonvision.vision.apriltag.AprilTagFamily;
@@ -33,7 +34,7 @@ import org.photonvision.vision.target.TargetModel;
public class ArucoPipelineTest {
@BeforeEach
public void setup() {
TestUtils.loadLibraries();
LoadJNI.loadLibraries();
ConfigManager.getInstance().load();
}

View File

@@ -32,6 +32,7 @@ import org.opencv.calib3d.Calib3d;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.photonvision.common.LoadJNI;
import org.photonvision.common.configuration.ConfigManager;
import org.photonvision.common.logging.LogGroup;
import org.photonvision.common.logging.LogLevel;
@@ -50,8 +51,8 @@ import org.photonvision.vision.pipeline.UICalibrationData.TagFamily;
public class Calibrate3dPipeTest {
@BeforeAll
public static void init() throws IOException {
TestUtils.loadLibraries();
TestUtils.loadMrcal();
LoadJNI.loadLibraries();
LoadJNI.forceLoad(LoadJNI.JNITypes.MRCAL);
var logLevel = LogLevel.DEBUG;
Logger.setLevel(LogGroup.Camera, logLevel);

View File

@@ -29,11 +29,11 @@ import org.junitpioneer.jupiter.cartesian.CartesianTest;
import org.junitpioneer.jupiter.cartesian.CartesianTest.Enum;
import org.opencv.core.Point;
import org.opencv.core.Size;
import org.photonvision.common.LoadJNI;
import org.photonvision.common.configuration.ConfigManager;
import org.photonvision.common.logging.LogGroup;
import org.photonvision.common.logging.LogLevel;
import org.photonvision.common.logging.Logger;
import org.photonvision.common.util.TestUtils;
import org.photonvision.estimation.OpenCVHelp;
import org.photonvision.vision.calibration.CameraCalibrationCoefficients;
import org.photonvision.vision.calibration.CameraLensModel;
@@ -48,8 +48,8 @@ import org.photonvision.vision.target.TrackedTarget;
public class CalibrationRotationPipeTest {
@BeforeAll
public static void init() throws IOException {
TestUtils.loadLibraries();
TestUtils.loadMrcal();
LoadJNI.loadLibraries();
LoadJNI.forceLoad(LoadJNI.JNITypes.MRCAL);
var logLevel = LogLevel.DEBUG;
Logger.setLevel(LogGroup.Camera, logLevel);

View File

@@ -22,6 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.photonvision.common.LoadJNI;
import org.photonvision.common.util.TestUtils;
import org.photonvision.vision.calibration.CameraCalibrationCoefficients;
import org.photonvision.vision.camera.QuirkyCamera;
@@ -40,7 +41,7 @@ public class CirclePNPTest {
@BeforeEach
public void Init() {
TestUtils.loadLibraries();
LoadJNI.loadLibraries();
}
@Test
@@ -132,7 +133,7 @@ public class CirclePNPTest {
// used to run VisualVM for profiling, which won't run on unit tests.
public static void main(String[] args) {
TestUtils.loadLibraries();
LoadJNI.loadLibraries();
var frameProvider =
new FileFrameProvider(
TestUtils.getWPIImagePath(TestUtils.WPI2019Image.kCargoStraightDark72in_HighRes, false),

View File

@@ -18,6 +18,7 @@
package org.photonvision.vision.pipeline;
import org.junit.jupiter.api.Test;
import org.photonvision.common.LoadJNI;
import org.photonvision.common.util.TestUtils;
import org.photonvision.vision.camera.QuirkyCamera;
import org.photonvision.vision.frame.Frame;
@@ -89,7 +90,7 @@ public class ColoredShapePipelineTest {
}
public static void main(String[] args) {
TestUtils.loadLibraries();
LoadJNI.loadLibraries();
System.out.println(
TestUtils.getWPIImagePath(TestUtils.WPI2020Image.kBlueGoal_108in_Center, false));
var frameProvider =

View File

@@ -21,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import org.photonvision.common.LoadJNI;
import org.photonvision.common.util.TestUtils;
import org.photonvision.vision.camera.QuirkyCamera;
import org.photonvision.vision.frame.Frame;
@@ -34,7 +35,7 @@ import org.photonvision.vision.pipeline.result.CVPipelineResult;
public class ReflectivePipelineTest {
@Test
public void test2019() {
TestUtils.loadLibraries();
LoadJNI.loadLibraries();
var pipeline = new ReflectivePipeline();
pipeline.getSettings().hsvHue.set(60, 100);
pipeline.getSettings().hsvSaturation.set(100, 255);
@@ -72,7 +73,7 @@ public class ReflectivePipelineTest {
@Test
public void test2020() {
TestUtils.loadLibraries();
LoadJNI.loadLibraries();
var pipeline = new ReflectivePipeline();
pipeline.getSettings().hsvHue.set(60, 100);
@@ -108,7 +109,7 @@ public class ReflectivePipelineTest {
// used to run VisualVM for profiling. It won't run on unit tests.
public static void main(String[] args) {
TestUtils.loadLibraries();
LoadJNI.loadLibraries();
var frameProvider =
new FileFrameProvider(
TestUtils.getWPIImagePath(TestUtils.WPI2019Image.kCargoStraightDark72in_HighRes, false),

View File

@@ -26,6 +26,7 @@ import edu.wpi.first.math.geometry.Translation3d;
import edu.wpi.first.math.util.Units;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.photonvision.common.LoadJNI;
import org.photonvision.common.util.TestUtils;
import org.photonvision.vision.calibration.CameraCalibrationCoefficients;
import org.photonvision.vision.camera.QuirkyCamera;
@@ -44,7 +45,7 @@ public class SolvePNPTest {
@BeforeEach
public void Init() {
TestUtils.loadLibraries();
LoadJNI.loadLibraries();
}
@Test
@@ -213,7 +214,7 @@ public class SolvePNPTest {
// used to run VisualVM for profiling, which won't run on unit tests.
public static void main(String[] args) {
TestUtils.loadLibraries();
LoadJNI.loadLibraries();
var frameProvider =
new FileFrameProvider(
TestUtils.getWPIImagePath(TestUtils.WPI2019Image.kCargoStraightDark72in_HighRes, false),

View File

@@ -23,15 +23,15 @@ import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.photonvision.common.LoadJNI;
import org.photonvision.common.configuration.ConfigManager;
import org.photonvision.common.util.TestUtils;
import org.photonvision.vision.pipeline.DriverModePipelineSettings;
import org.photonvision.vision.pipeline.PipelineType;
public class PipelineManagerTest {
@BeforeAll
public static void init() {
TestUtils.loadLibraries();
LoadJNI.loadLibraries();
}
@Test

View File

@@ -27,6 +27,7 @@ import java.util.HashMap;
import java.util.List;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.photonvision.common.LoadJNI;
import org.photonvision.common.configuration.CameraConfiguration;
import org.photonvision.common.configuration.ConfigManager;
import org.photonvision.common.dataflow.CVPipelineResultConsumer;
@@ -46,7 +47,7 @@ public class VisionModuleManagerTest {
String classpathStr = System.getProperty("java.class.path");
System.out.print(classpathStr);
TestUtils.loadLibraries();
LoadJNI.loadLibraries();
if (!LibraryLoader.loadTargeting()) fail();
}

View File

@@ -29,6 +29,7 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.photonvision.common.LoadJNI;
import org.photonvision.common.configuration.CameraConfiguration;
import org.photonvision.common.configuration.ConfigManager;
import org.photonvision.common.util.TestUtils;
@@ -58,7 +59,7 @@ public class VisionSourceManagerTest {
@BeforeAll
public static void loadLibraries() {
assertTrue(TestUtils.loadLibraries());
assertTrue(LoadJNI.loadLibraries());
// Broadcast all still calls into configmanager (ew) so set that up here
ConfigManager.getInstance().load();

View File

@@ -32,7 +32,7 @@ import org.junit.jupiter.params.provider.MethodSource;
import org.opencv.calib3d.Calib3d;
import org.opencv.core.*;
import org.opencv.imgproc.Imgproc;
import org.photonvision.common.util.TestUtils;
import org.photonvision.common.LoadJNI;
import org.photonvision.common.util.numbers.DoubleCouple;
import org.photonvision.vision.calibration.CameraCalibrationCoefficients;
import org.photonvision.vision.calibration.CameraLensModel;
@@ -63,7 +63,7 @@ public class TargetCalculationsTest {
@BeforeAll
public static void setup() {
TestUtils.loadLibraries();
LoadJNI.loadLibraries();
}
@Test

View File

@@ -25,14 +25,14 @@ import org.junit.jupiter.api.Test;
import org.opencv.core.MatOfPoint;
import org.opencv.core.Point;
import org.opencv.core.Size;
import org.photonvision.common.util.TestUtils;
import org.photonvision.common.LoadJNI;
import org.photonvision.vision.opencv.Contour;
import org.photonvision.vision.opencv.DualOffsetValues;
public class TrackedTargetTest {
@BeforeEach
public void Init() {
TestUtils.loadLibraries();
LoadJNI.loadLibraries();
}
@Test

View File

@@ -23,6 +23,7 @@ import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.cli.*;
import org.photonvision.common.LoadJNI;
import org.photonvision.common.configuration.CameraConfiguration;
import org.photonvision.common.configuration.ConfigManager;
import org.photonvision.common.configuration.NeuralNetworkModelManager;
@@ -38,9 +39,6 @@ import org.photonvision.common.logging.Logger;
import org.photonvision.common.logging.PvCSCoreLogger;
import org.photonvision.common.networking.NetworkManager;
import org.photonvision.common.util.TestUtils;
import org.photonvision.jni.RknnDetectorJNI;
import org.photonvision.jni.RubikDetectorJNI;
import org.photonvision.raspi.LibCameraJNILoader;
import org.photonvision.server.Server;
import org.photonvision.vision.apriltag.AprilTagFamily;
import org.photonvision.vision.camera.PVCameraInfo;
@@ -194,7 +192,7 @@ public class Main {
}
try {
boolean success = TestUtils.loadLibraries();
boolean success = LoadJNI.loadLibraries();
if (!success) {
logger.error("Failed to load native libraries! Giving up :(");
@@ -213,41 +211,35 @@ public class Main {
try {
if (Platform.isRaspberryPi()) {
LibCameraJNILoader.forceLoad();
LoadJNI.forceLoad(LoadJNI.JNITypes.LIBCAMERA);
logger.info("Loaded libcamera-JNI");
}
} catch (IOException e) {
logger.error("Failed to load libcamera-JNI!", e);
}
try {
if (Platform.isRK3588()) {
RknnDetectorJNI.forceLoad();
if (RknnDetectorJNI.getInstance().isLoaded()) {
logger.info("RknnDetectorJNI loaded successfully.");
} else {
logger.error("Failed to load RknnDetectorJNI!");
}
LoadJNI.forceLoad(LoadJNI.JNITypes.RKNN_DETECTOR);
logger.info("Loaded RKNN-JNI");
} else {
logger.error("Platform does not support RKNN based machine learning!");
}
} catch (IOException e) {
logger.error("Failed to load rknn-JNI!", e);
logger.error("Failed to load RKNN-JNI!", e);
}
try {
if (Platform.isQCS6490()) {
RubikDetectorJNI.forceLoad();
if (RubikDetectorJNI.getInstance().isLoaded()) {
logger.info("RubikDetectorJNI loaded successfully.");
} else {
logger.error("Failed to load RubikDetectorJNI!");
}
LoadJNI.forceLoad(LoadJNI.JNITypes.RUBIK_DETECTOR);
logger.info("Loaded Rubik-JNI");
} else {
logger.error("Platform does not support Rubik based machine learning!");
}
} catch (IOException e) {
logger.error("Failed to load rubik-JNI!", e);
logger.error("Failed to load Rubik-JNI!", e);
}
try {
TestUtils.loadMrcal();
LoadJNI.forceLoad(LoadJNI.JNITypes.MRCAL);
logger.info("mrcal-JNI loaded successfully.");
} catch (Exception e) {
logger.warn(
"Failed to load mrcal-JNI! Camera calibration will fall back to opencv\n"

View File

@@ -27,65 +27,50 @@ import java.util.function.Supplier;
@SuppressWarnings("unused")
public enum Platform {
// WPILib Supported (JNI)
WINDOWS_64("Windows x64", Platform::getUnknownModel, "winx64", false, OSType.WINDOWS, true),
LINUX_32("Linux x86", Platform::getUnknownModel, "linuxx64", false, OSType.LINUX, true),
LINUX_64("Linux x64", Platform::getUnknownModel, "linuxx64", false, OSType.LINUX, true),
WINDOWS_64("Windows x64", Platform::getUnknownModel, false, OSType.WINDOWS, true),
LINUX_32("Linux x86", Platform::getUnknownModel, false, OSType.LINUX, true),
LINUX_64("Linux x64", Platform::getUnknownModel, false, OSType.LINUX, true),
LINUX_RASPBIAN32(
"Linux Raspbian 32-bit",
Platform::getLinuxDeviceTreeModel,
"linuxarm32",
true,
OSType.LINUX,
true), // Raspberry Pi 3/4 with a 32-bit image
LINUX_RASPBIAN64(
"Linux Raspbian 64-bit",
Platform::getLinuxDeviceTreeModel,
"linuxarm64",
true,
OSType.LINUX,
true), // Raspberry Pi 3/4 with a 64-bit image
LINUX_RK3588_64(
"Linux AARCH 64-bit with RK3588",
Platform::getLinuxDeviceTreeModel,
"linuxarm64",
false,
OSType.LINUX,
true),
LINUX_QCS6490(
"Linux AARCH 64-bit with QCS6490",
Platform::getLinuxDeviceTreeModel,
"linuxarm64",
false,
OSType.LINUX,
true), // QCS6490 SBCs
LINUX_AARCH64(
"Linux AARCH64",
Platform::getLinuxDeviceTreeModel,
"linuxarm64",
false,
OSType.LINUX,
true), // Jetson Nano, Jetson TX2
// PhotonVision Supported (Manual build/install)
LINUX_ARM64(
"Linux ARM64",
Platform::getLinuxDeviceTreeModel,
"linuxarm64",
false,
OSType.LINUX,
true), // ODROID C2, N2
"Linux ARM64", Platform::getLinuxDeviceTreeModel, false, OSType.LINUX, true), // ODROID C2, N2
// Completely unsupported
WINDOWS_32("Windows x86", Platform::getUnknownModel, "windowsx64", false, OSType.WINDOWS, false),
MACOS("Mac OS", Platform::getUnknownModel, "osxuniversal", false, OSType.MACOS, false),
WINDOWS_32("Windows x86", Platform::getUnknownModel, false, OSType.WINDOWS, false),
MACOS("Mac OS", Platform::getUnknownModel, false, OSType.MACOS, false),
LINUX_ARM32(
"Linux ARM32",
Platform::getUnknownModel,
"linuxarm32",
false,
OSType.LINUX,
false), // ODROID XU4, C1+
UNKNOWN("Unsupported Platform", Platform::getUnknownModel, "", false, OSType.UNKNOWN, false);
"Linux ARM32", Platform::getUnknownModel, false, OSType.LINUX, false), // ODROID XU4, C1+
UNKNOWN("Unsupported Platform", Platform::getUnknownModel, false, OSType.UNKNOWN, false);
public enum OSType {
WINDOWS,
@@ -96,7 +81,6 @@ public enum Platform {
public final String description;
public final String hardwareModel;
public final String nativeLibraryFolderName;
public final boolean isPi;
public final OSType osType;
public final boolean isSupported;
@@ -108,7 +92,6 @@ public enum Platform {
Platform(
String description,
Supplier<String> getHardwareModel,
String nativeLibFolderName,
boolean isPi,
OSType osType,
boolean isSupported) {
@@ -117,7 +100,6 @@ public enum Platform {
this.isPi = isPi;
this.osType = osType;
this.isSupported = isSupported;
this.nativeLibraryFolderName = nativeLibFolderName;
}
public static void overridePlatform(Platform platform) {
@@ -161,10 +143,6 @@ public enum Platform {
return currentPlatform.hardwareModel;
}
public static String getNativeLibraryFolderName() {
return currentPlatform.nativeLibraryFolderName;
}
public static boolean isSupported() {
return currentPlatform.isSupported;
}