bytedeco / javacv

Java interface to OpenCV, FFmpeg, and more
Other
7.51k stars 1.58k forks source link

org.bytedeco.opencv.* missing some packages? #1959

Closed gingerbraden closed 1 year ago

gingerbraden commented 1 year ago

I am trying to build an app in Java which uses saliency implementations from OpenCV, but while using bytedeco I've come to some problems:

My dependencies in Gradle are set like this: implementation group: 'org.bytedeco', name: 'javacpp', version: '1.5.8' implementation group: 'org.bytedeco', name: 'javacpp-presets', version: '1.5.8' implementation group: 'org.bytedeco', name: 'javacv', version: '1.5.8'

And the code I'm trying to run is as simple as:

public static void main(String[] args) {

        Mat image = Imgcodecs.imread("image.jpg");

        Mat imageHSV = new Mat();
        Imgproc.cvtColor(image, imageHSV, Imgproc.COLOR_BGR2HSV);

        StaticSaliencySpectralResidual saliency = StaticSaliencySpectralResidual.create();

        Mat saliencyMap = new Mat();
        saliency.computeSaliency(imageHSV, saliencyMap);

        Mat outputImage = new Mat();
        Core.addWeighted(image, 0.5, saliencyMap, 0.5, 0.0, outputImage);

    }

But I can't get Imgcodecs, Imgproc and Core to work...

saudet commented 1 year ago

Why do you say they are missing? We can use them if you want to: https://github.com/bytedeco/javacpp-presets/tree/master/opencv#documentation

gingerbraden commented 1 year ago

I see that, but I checked the Java API documentation and all three of the classes I mentioned are missing.

saudet commented 1 year ago

Those classes are in the org.opencv package, not the org.bytedeco.opencv one.

gingerbraden commented 1 year ago

That is true, but I have problems combining them - f.e. passing a org.bytedeco.opencv.opencv_core.Mat into a org.opencv.core.Core image

(combining them is necessary as Saliency requires a Mat, and that has to come from the same package - org.bytedeco.opencv...

saudet commented 1 year ago

We can use OpenCVFrameConverter for that.

gingerbraden commented 1 year ago

Yes! That's it, that works like a charm, thank you so much. Now I have to solve the "No implementation found for org.opencv....."

saudet commented 1 year ago

Please make sure that Loader.load(opencv_java.class) has been called: https://github.com/bytedeco/javacpp-presets/tree/master/opencv#documentation

gingerbraden commented 1 year ago

It has been, and now I'm digging through old issues to solve the _java.lang.UnsatisfiedLinkError: dlopen failed: library "libjniopencvcore.so" not found error

EDIT trying the solution from issue #386 EDIT2 still missing jniopencv_core.so. Added relinker, added splits to gradle.build as in issue #906, but no luck

saudet commented 1 year ago

Are you trying this on Android? The plugin doesn't support native libraries in JAR files but we can work around that: https://github.com/bytedeco/gradle-javacpp#the-platform-plugin

gingerbraden commented 1 year ago

Yes, I am trying this on Android. After adding the code from the Platform Plugin chapter to build.gradle file, I am getting a The 'java' plugin has been applied, but it is not compatible with the Android plugins. error

saudet commented 1 year ago

That's correct, the Java plugin doesn't work with Android. That bit isn't for Android. Please read below that.

gingerbraden commented 1 year ago

Shoot... So there is no way of using OpenCV's Saliency modules on Android, even with using ByteDeco/JavaCPP ?

saudet commented 1 year ago

Yes, it should work fine. If you're looking for an existing sample project to use as template, there's this one: https://github.com/bytedeco/sample-projects/tree/master/JavaCV-android-example

gingerbraden commented 1 year ago

Managed to make it work, all fault was on my side.