wpilibsuite / WPILibPi

WPILib Raspberry Pi images designed for FRC (formerly FRCVision)
Other
86 stars 40 forks source link

Missing java library for aprilcodes #234

Closed builder173 closed 4 months ago

builder173 commented 4 months ago

Hi, I'm starting from the downloadable java vision example shell and trying to work through the vision examples in WPILib and elsewhere. I was able to get a simple vision pipeline running that drew a square on the image and then use outputStreams to send both the raw image and processed image to Shuffleboard for display. Also able to report the "count" of frames in Shuffleboard via Network Tables. (running 2024 WPILib on Mac)

I am moving on to AprilCodes and working from the example bundled with WPILib. It seemed reasonable to just add this detection to the existing pipeline and generate a new output stream with the detection information. However when I load the vision program to the WPILibPi interface it reports an error. Code and corresponding error below.

Not sure if I'm trying to go outside what's supported here or there is really a missing native library. Any help would be appreciated.

Pipeline code:
public static class MyPipeline implements VisionPipeline {
    public int val;
    public Mat input_mat;
    public Mat april_mat;
    public Mat proc_mat;
    public AprilTagDetector detector = initializeDetector();
    public ArrayList<Long> tags = new ArrayList<>();
    public Scalar outlineColor = new Scalar(0, 255, 0);
    public Scalar crossColor = new Scalar(0, 0, 255);

    private static AprilTagDetector initializeDetector() {
      AprilTagDetector myDetector = new AprilTagDetector();
      // look for tag36h11, correct 3 error bits
      myDetector.addFamily("tag36h11", 3);
      return myDetector;
    }
Waiting 5 seconds...
Setting up NetworkTables client for team 294
NT: starting network client
Starting camera 'rPi Camera 0' on /dev/video0
CS: rPi Camera 0: Connecting to USB camera on /dev/video0
CS: rPi Camera 0: set format 1 res 160x120
CS: rPi Camera 0: SetConfigJson: setting video mode to pixelFormat 1, width 640, height 480, fps 30
CS: rPi Camera 0: Connecting to USB camera on /dev/video0
CS: rPi Camera 0: set format 1 res 640x480
CS: rPi Camera 0: set FPS to 30
could not load class edu/wpi/first/math/geometry/Rotation3d
Exception in thread "main" java.lang.NoClassDefFoundError: org/ejml/data/Matrix
    at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
    at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:388)
    at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:232)
    at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:174)
    at java.base/jdk.internal.loader.NativeLibraries.findFromPaths(NativeLibraries.java:315)
    at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:287)
    at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2422)
    at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:818)
    at java.base/java.lang.System.loadLibrary(System.java:1989)
    at edu.wpi.first.util.RuntimeLoader.loadLibrary(RuntimeLoader.java:86)
    at edu.wpi.first.apriltag.jni.AprilTagJNI.<clinit>(AprilTagJNI.java:38)
    at edu.wpi.first.apriltag.AprilTagDetector.<init>(AprilTagDetector.java:186)
    at Main$MyPipeline.initializeDetector(Main.java:310)
    at Main$MyPipeline.<init>(Main.java:304)
    at Main.main(Main.java:421)

Caused by: java.lang.ClassNotFoundException: org.ejml.data.Matrix
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
    ... 15 more
builder173 commented 4 months ago

Steps I took to get Aprilcodes working in the java example downloaded from wpilibpi dash

  1. Followed the links to Source Forge from here on ejml.org
  2. Downloaded .jars and placed ejml-core-0.42.jar in root of my vision project (alongside wpilibj.jar for example)
  3. Added this jar to the dependencies block of build.gradle

I had one more hiccup of needing turn down the error bits from 3 to 1 to avoid this error: _apriltag.c:224:quick_decodeinit(): Failed to allocate hamming decode table

    private static AprilTagDetector initializeDetector() {
      AprilTagDetector myDetector = new AprilTagDetector();
      // look for tag36h11, correct 1 error bits
      myDetector.addFamily("tag36h11", 1);
      return myDetector;
    }

After that I was able to get the intermediate vision example working, at least the first part I attempted which superimposes the apriltag number and a center marker on the Aprilcode in frame.