Skip to content

Commit

Permalink
no worke
Browse files Browse the repository at this point in the history
  • Loading branch information
mdurrani808 committed Jan 10, 2024
1 parent ff03d15 commit 14d8c9a
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public Map<String, Object> toHashMap() {
LibCameraJNILoader.isSupported()
? "Zerocopy Libcamera Working"
: ""); // TODO add support for other types of GPU accel
generalSubmap.put("mrCalWorking", MrCalJNILoader.isWorking());
generalSubmap.put("mrCalWorking", MrCalJNILoader.getInstance().isLoaded());
generalSubmap.put("hardwareModel", hardwareConfig.deviceName);
generalSubmap.put("hardwarePlatform", Platform.getPlatformName());
settingsSubmap.put("general", generalSubmap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public enum Platform {
OSType.LINUX,
true), // Raspberry Pi 3/4 with a 64-bit image
LINUX_RK3588_64(
"Linux Armbian 64-bit with RK388",
"Linux AARCH 64-bit with RK388",
"linuxarm64",
false,
OSType.LINUX,
Expand Down Expand Up @@ -102,6 +102,9 @@ private enum OSType {
public static boolean isLinux() {
return currentPlatform.osType == OSType.LINUX;
}
public static boolean isRK3588() {
return Platform.isOrangePi();
}

public static boolean isRaspberryPi() {
return currentPlatform.isPi;
Expand Down Expand Up @@ -195,7 +198,12 @@ private static Platform getCurrentPlatform() {
return LINUX_32;
} else if (RuntimeDetector.isArm64()) {
// TODO - os detection needed?
return LINUX_AARCH64;
if(isOrangePi()) {
return LINUX_RK3588_64;
}
else {
return LINUX_AARCH64;
}
} else if (RuntimeDetector.isArm32()) {
return LINUX_ARM32;
} else {
Expand All @@ -212,6 +220,9 @@ private static Platform getCurrentPlatform() {
private static boolean isPiSBC() {
return fileHasText("/proc/cpuinfo", "Raspberry Pi");
}
private static boolean isOrangePi() {
return fileHasText("/proc/cpuinfo", "Orange Pi 5");
}

private static boolean isJetsonSBC() {
// https://forums.developer.nvidia.com/t/how-to-recognize-jetson-nano-device/146624
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
import org.photonvision.common.logging.Logger;

public abstract class PhotonJNICommon {
static boolean libraryLoaded = false;
public abstract boolean isLoaded();
public abstract void setLoaded(boolean state);
protected static Logger logger = null;

protected static synchronized void forceLoad(Class<?> clazz, List<String> libraries)
protected static synchronized void forceLoad(PhotonJNICommon instance, Class<?> clazz, List<String> libraries)
throws IOException {
if (libraryLoaded) return;
if (instance.isLoaded()) return;
if (logger == null) logger = new Logger(clazz, LogGroup.Camera);

for (var libraryName : libraries) {
Expand All @@ -42,7 +43,7 @@ protected static synchronized void forceLoad(Class<?> clazz, List<String> librar
var in = clazz.getResourceAsStream("/nativelibraries/" + arch_name + "/" + nativeLibName);

if (in == null) {
libraryLoaded = false;
instance.setLoaded(false);
return;
}

Expand All @@ -69,15 +70,11 @@ protected static synchronized void forceLoad(Class<?> clazz, List<String> librar
break;
}
}
libraryLoaded = true;
instance.setLoaded(true);
}

protected static synchronized void forceLoad(Class<?> clazz, String libraryName)
protected static synchronized void forceLoad(PhotonJNICommon instance, Class<?> clazz, String libraryName)
throws IOException {
forceLoad(clazz, List.of(libraryName));
}

public static boolean isWorking() {
return libraryLoaded;
forceLoad(instance, clazz, List.of(libraryName));
}
}
40 changes: 31 additions & 9 deletions photon-core/src/main/java/org/photonvision/jni/RknnDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,39 @@
import java.util.stream.Collector;
import java.util.stream.Collectors;

import org.photonvision.common.logging.LogGroup;
import org.photonvision.common.logging.Logger;
import org.photonvision.common.util.TestUtils;
import org.photonvision.mrcal.MrCalJNILoader;
import org.photonvision.rknn.RknnJNI;
import org.photonvision.rknn.RknnJNI.RknnResult;
import org.opencv.core.Rect2d;
import org.photonvision.common.util.TestUtils;
import org.photonvision.vision.opencv.CVMat;
import org.photonvision.vision.pipe.impl.NeuralNetworkPipeResult;

public class RknnDetector extends PhotonJNICommon {
static long objPointer = 0;
private static final Logger logger = new Logger(RknnDetector.class, LogGroup.General);
static long objPointer = -1;
static boolean hasBeenDestroyed = false;
private boolean isLoaded;
private static RknnDetector instance = null;
private RknnDetector() {
isLoaded = false;
objPointer = RknnJNI.create("null");
}
public static RknnDetector getRknnDetector() {
if (instance == null)
instance = new RknnDetector();

return instance;
}

public static synchronized void forceLoad() throws IOException {
forceLoad(RknnDetector.class, List.of("rknn_jni", "rga", "rknnrt"));
TestUtils.loadLibraries();

forceLoad(getRknnDetector(), RknnDetector.class, List.of("rknn_jni", "rga", "rknnrt"));
logger.debug("HEY");
}

public static List<NeuralNetworkPipeResult> detect(CVMat in) {
RknnResult[] ret = RknnJNI.detect(objPointer, in.getMat().getNativeObjAddr());

Expand All @@ -36,10 +55,13 @@ public static void release() {
}

}

public static void main(String[] args) throws IOException {
TestUtils.loadLibraries();
forceLoad();
objPointer = RknnJNI.create("null");
@Override
public boolean isLoaded() {
return isLoaded;
}
@Override
public void setLoaded(boolean state) {
isLoaded = state;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,26 @@
import org.photonvision.jni.PhotonJNICommon;

public class MrCalJNILoader extends PhotonJNICommon {
private boolean isLoaded;
private static MrCalJNILoader instance = null;
private MrCalJNILoader() {
isLoaded = false;
}
public static synchronized MrCalJNILoader getInstance()
{
if (instance == null)
instance = new MrCalJNILoader();

return instance;
}
public static synchronized void forceLoad() throws IOException {
// Force load opencv
TestUtils.loadLibraries();

// Library naming is dumb and has "lib" appended for Windows when it ought not to
if (Platform.isWindows()) {
// Order is correct to match dependencies of libraries
forceLoad(
forceLoad(MrCalJNILoader.getInstance(),
MrCalJNILoader.class,
List.of(
"libamd",
Expand All @@ -46,11 +58,21 @@ public static synchronized void forceLoad() throws IOException {
"mrcal_jni"));
} else {
// Nothing else to do on linux
forceLoad(MrCalJNILoader.class, List.of("mrcal_jni"));
forceLoad(MrCalJNILoader.getInstance(),MrCalJNILoader.class, List.of("mrcal_jni"));
}

if (!MrCalJNILoader.isWorking()) {
if (!MrCalJNILoader.getInstance().isLoaded()) {
throw new IOException("Unable to load mrcal JNI!");
}
}

@Override
public boolean isLoaded() {
return isLoaded;
}

@Override
public void setLoaded(boolean state) {
isLoaded = state;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected CameraCalibrationCoefficients process(

CameraCalibrationCoefficients ret;
var start = System.nanoTime();
if (MrCalJNILoader.isWorking() && params.useMrCal) {
if (MrCalJNILoader.getInstance().isLoaded() && params.useMrCal) {
logger.debug("Calibrating with mrcal!");
ret = calibrateMrcal(in);
} else {
Expand Down
13 changes: 12 additions & 1 deletion photon-server/src/main/java/org/photonvision/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.photonvision.common.util.TestUtils;
import org.photonvision.common.util.numbers.IntegerCouple;
import org.photonvision.mrcal.MrCalJNILoader;
import org.photonvision.jni.RknnDetector;
import org.photonvision.raspi.LibCameraJNILoader;
import org.photonvision.server.Server;
import org.photonvision.vision.camera.FileVisionSource;
Expand Down Expand Up @@ -317,7 +318,17 @@ public static void main(String[] args) {
} catch (IOException e) {
logger.error("Failed to load libcamera-JNI!", e);
}

try {

logger.warn("LOADING RK3588");
logger.debug("LOADING RK3588");
logger.debug("LOADING RK3588");
logger.debug("LOADING RK3588");
logger.debug("LOADING RK3588");
RknnDetector.forceLoad();
} catch (IOException e) {
logger.error("Failed to load rknn-JNI!", e);
}
try {
MrCalJNILoader.forceLoad();
} catch (IOException e) {
Expand Down

0 comments on commit 14d8c9a

Please sign in to comment.