Gradle- Building vision code on Pi 3

Greetings,

We’re following the “Off-board Vision Processing In Java” screensteps and have run into a bit of an issue with Gradle grabbing the OpenCV package when building.

Currently, “sudo ./gradlew build” is failing with the following error:

:downloadOpenCv
Download http://first.wpi.edu/FRC/roborio/maven/release/org/opencv/opencv-jni/3.2.0/opencv-jni-3.2.0.pom
:downloadOpenCv FAILED

FAILURE: Build failed with an exception.

* Where:
Script '/home/pi/Downloads/code/3593vision/dependencies.gradle' line: 58

* What went wrong:
Execution failed for task ':downloadOpenCv'.
> Could not resolve all files for configuration ':detachedConfiguration1'.
   > Could not find opencv-jni-linux-arm-raspbian.jar (org.opencv:opencv-jni:3.2.0).
     Searched in the following locations:
         http://first.wpi.edu/FRC/roborio/maven/release/org/opencv/opencv-jni/3.2.0/opencv-jni-3.2.0-linux-arm-raspbian.jar

Looking at the link it’s referencing, it doesn’t appears that a file “opencv-jni-linux-arm-raspbian.jar” is present in this directory.

The dependencies.gradle file function that is failing looks like this:

task downloadOpenCv() {
    description = 'Downloads the OpenCV Native maven dependency.'
    group = 'WPILib'
    def depFolder = "$buildDir/dependencies"
    def cvZip = file("$depFolder/opencv.zip")
    outputs.file(cvZip)
    def armOpenCv

    doFirst {
        def classifier = getOpenCvPlatformPackage()
        def armOpenCvDependency = project.dependencies.create("org.opencv:opencv-jni:+:$classifier@jar")
        def armOpenCvConfig = project.configurations.detachedConfiguration(armOpenCvDependency)
        armOpenCvConfig.setTransitive(false)
        armOpenCv = armOpenCvConfig.files[0].canonicalFile
    }

    doLast {
        copy {
            from armOpenCv
            rename 'opencv(.+)', 'opencv.zip'
            into depFolder
        }
    }
}

Can someone advise on how we should modify this dependency to grab the correct file so that it can complete?

Thank you!

Yeah, …-arm-raspberry.jar is in the 3.1.0 folder (first thing, actually), but not in 3.2.0.

You can try regressing the references to 3.1.0, but I’m not sure what issues that might cause.

Thanks for the input! We were able to get it working downloading and building OpenCV 3.2.0, however now we’re getting the following error when attempting to run the program in the output folder:

pi@pi-3593:~/Downloads/code/3593vision/output $ java -Djava.library.path=. -jar CameraVision-all.jar
platform: /Linux/arm/
java.lang.UnsatisfiedLinkError: no opencv_java320 in java.library.path
        at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
        at java.lang.Runtime.loadLibrary0(Runtime.java:870)
        at java.lang.System.loadLibrary(System.java:1122)
        at edu.wpi.cscore.CameraServerJNI.<clinit>(CameraServerJNI.java:77)
        at edu.wpi.cscore.MjpegServer.<init>(MjpegServer.java:17)
        at edu.wpi.cscore.MjpegServer.<init>(MjpegServer.java:24)
        at Main.main(Main.java:17)

The screensteps link for this error shows that this should indicate that the program was built for the wrong system, but we’ve triple-checked the build.gradle file and we’ve definitely set this to build for “arm-raspbian”. The only opencv-related file I see in the output folder is a “libopencv_java310.so” file, but nothing for version 3.2.0.

Anyone have any input on this?

When you change your reference to the V3.1.0 folder, you get a 310 library file. I’m not familiar enough with this project to tell you how to make the code look for the 310 file at runtime instead of the 320 file.

You need to also switch your Java dependency (in build.gradle) for opencv to 3.1.0 as well.

Basically you need to do the changes that were done in the following commit.

Awesome! This worked, thanks! The dependencies.gradle file had the change, but the build.gradle file did not.

OK! We got Vision working on the RPi. I can see the raw sample on pi.ip.adr:1185 and processed image on 1186 in our windows machine browser.

We want to use the cscore raw image in Grip on the windows machine to ensure we’re filtering on the same image cscore is grabbing. However, when we put pi.ip.adr:1185 in Grip it shows an error.

Anyway to make this work or should we just load a different Server, Motion(?), or some other ideas?

I have done a lot of this work for you and produced a series of videos you might find helpful:

Actually, I watched your series last week. Very well done. It helped me understand some of what was going on and get the FRC example code working.

I may still give your version a try (only cost me another mSD card). However, right now we are trying to work with the FRC example. We’ve been burnt in the past wandering too far from supported solutions. But then what fun is it to always follow the instructions.

Your code does seem similar to what FRC is using except for Camera Server. You use a bundled camera+server modules and FRC has cscore. When running cscore I cannot see the camera on Grip but I can see it on my browser. I got Motion working (Sparrow camera example) with Grip. So I can now setup openCV pipeline and cut it in to the example code. One step at a time. Thanks.

You may be interested in the Pi 3 image with all libraries included that we just released; there’s a Java example in there that uses gradle to build with all the required dependencies already set up. https://www.chiefdelphi.com/forums/showthread.php?threadid=186643