Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opencv_cudaoptflow produces no jniopencv_ximgproc in java.library.path #911

Closed
n-kai-cj opened this issue Jul 18, 2020 · 8 comments
Closed
Labels

Comments

@n-kai-cj
Copy link
Contributor

I make a opencv + cuda test code like below and confirmed to success of opencv_cudafeatures2d and opencv_cudaimgproc, but opencv_cudaoptflow failed with java.lang.UnsatisfiedLinkError: no jniopencv_ximgproc in java.library.path: [...].
Does anybody know why?

import org.bytedeco.opencv.global.opencv_core;
import org.bytedeco.opencv.global.opencv_cudaimgproc;
import org.bytedeco.opencv.global.opencv_imgproc;
import org.bytedeco.opencv.opencv_core.GpuMat;
import org.bytedeco.opencv.opencv_cudaoptflow.FarnebackOpticalFlow;
import org.bytedeco.opencv.opencv_cudafeatures2d.ORB;
import org.bytedeco.opencv.opencv_cudaimgproc.TemplateMatching;

public class Main {
    public static void main(String[] args) {
        GpuMat mat_cuda = new GpuMat();
        System.out.println("mat_cuda succeed");
        ORB orb_cuda = ORB.create();
        System.out.println("orb_cuda succeed");
        TemplateMatching temp_cuda = opencv_cudaimgproc.createTemplateMatching(opencv_core.CV_8UC1, opencv_imgproc.TM_SQDIFF);
        System.out.println("temp_cuda succeed");
        FarnebackOpticalFlow optflow_cuda = FarnebackOpticalFlow.create();
        System.out.println("optflow_cuda succeed");
    }
}

run

mat_cuda succeed
orb_cuda succeed
temp_cuda succeed
java.lang.UnsatisfiedLinkError: no jniopencv_ximgproc in java.library.path: [...]
    at java.lang.ClassLoader.loadLibrary (ClassLoader.java:2670)
    at java.lang.Runtime.loadLibrary0 (Runtime.java:830)
    at java.lang.System.loadLibrary (System.java:1870)
    at org.bytedeco.javacpp.Loader.loadLibrary (Loader.java:1631)
    at org.bytedeco.javacpp.Loader.load (Loader.java:1265)
    at org.bytedeco.javacpp.Loader.load (Loader.java:1109)
    at org.bytedeco.opencv.global.opencv_ximgproc.<clinit> (opencv_ximgproc.java:31)
    at java.lang.Class.forName0 (Native Method)
    at java.lang.Class.forName (Class.java:398)
    at org.bytedeco.javacpp.Loader.load (Loader.java:1176)
    at org.bytedeco.javacpp.Loader.load (Loader.java:1109)
    at org.bytedeco.opencv.opencv_cudaoptflow.DenseOpticalFlow.<clinit> (DenseOpticalFlow.java:57)
    at Main.main (Main.java:17)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:254)
    at java.lang.Thread.run (Thread.java:834)
Caused by: java.lang.UnsatisfiedLinkError: C:\Users\-\.javacpp\cache\opencv-4.3.0-1.5.3-windows-x86_64.jar\org\bytedeco\opencv\windows-x86_64\jniopencv_ximgproc.dll: The specified procedure could not be found
    at java.lang.ClassLoader$NativeLibrary.load0 (Native Method)
    at java.lang.ClassLoader$NativeLibrary.load (ClassLoader.java:2442)
    at java.lang.ClassLoader$NativeLibrary.loadLibrary (ClassLoader.java:2498)
    at java.lang.ClassLoader.loadLibrary0 (ClassLoader.java:2694)
    at java.lang.ClassLoader.loadLibrary (ClassLoader.java:2627)
    at java.lang.Runtime.load0 (Runtime.java:768)
    at java.lang.System.load (System.java:1834)
    at org.bytedeco.javacpp.Loader.loadLibrary (Loader.java:1581)
    at org.bytedeco.javacpp.Loader.load (Loader.java:1265)
    at org.bytedeco.javacpp.Loader.load (Loader.java:1109)
    at org.bytedeco.opencv.global.opencv_ximgproc.<clinit> (opencv_ximgproc.java:31)
    at java.lang.Class.forName0 (Native Method)
    at java.lang.Class.forName (Class.java:398)
    at org.bytedeco.javacpp.Loader.load (Loader.java:1176)
    at org.bytedeco.javacpp.Loader.load (Loader.java:1109)
    at org.bytedeco.opencv.opencv_cudaoptflow.DenseOpticalFlow.<clinit> (DenseOpticalFlow.java:57)
    at Main.main (Main.java:17)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:254)
    at java.lang.Thread.run (Thread.java:834)
@saudet
Copy link
Member

saudet commented Jul 18, 2020

You might not have the right version of CUDA installed. Please add a dependency on cuda-redist-platform.

@n-kai-cj
Copy link
Contributor Author

Thank you for quick reply. As you said, my CUDA version (10.2.89) is different from javacpp-cuda version (10.2.76).
Unfortunately CUDA 10.2.76 seems not to be available for now, so I can't try to re-install the same version.
Could you try to run my above code on your PC if you have 10.2.76 version of CUDA ?

$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2019 NVIDIA Corporation
Built on Wed_Oct_23_19:32:27_Pacific_Daylight_Time_2019
Cuda compilation tools, release 10.2, V10.2.89

my pom.xml is below.

<project>
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.bytedeco.opencv</groupId>
    <artifactId>optflowcuda</artifactId>
    <version>1.5.3</version>
    <properties>
        <exec.mainClass>Main</exec.mainClass>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.bytedeco</groupId>
            <artifactId>opencv-platform</artifactId>
            <version>4.3.0-1.5.3</version>
        </dependency>

        <!-- Additional dependencies required to use CUDA and cuDNN -->
        <dependency>
            <groupId>org.bytedeco</groupId>
            <artifactId>opencv-platform-gpu</artifactId>
            <version>4.3.0-1.5.3</version>
        </dependency>

        <!-- Additional dependencies to use bundled CUDA and cuDNN -->
        <dependency>
            <groupId>org.bytedeco</groupId>
            <artifactId>cuda-platform-redist</artifactId>
            <version>10.2-7.6-1.5.3</version>
        </dependency>

        <!-- Additional dependencies to use bundled full version of MKL -->
        <dependency>
            <groupId>org.bytedeco</groupId>
            <artifactId>mkl-platform-redist</artifactId>
            <version>2020.1-1.5.3</version>
        </dependency>

        <!-- Optional dependencies to load the Python module -->
        <dependency>
            <groupId>org.bytedeco</groupId>
            <artifactId>numpy-platform</artifactId>
            <version>1.18.2-1.5.3</version>
        </dependency>

    </dependencies>
    <build>
        <sourceDirectory>.</sourceDirectory>
    </build>
</project>

@saudet
Copy link
Member

saudet commented Jul 18, 2020

We don't need to install CUDA with cuda-redist-platform. Maybe there's some other dependency missing. Please let me know what the Dependencies tool says: https://github.com/bytedeco/javacpp-presets/wiki/Debugging-UnsatisfiedLinkError-on-Windows

@n-kai-cj
Copy link
Contributor Author

n-kai-cj commented Jul 18, 2020

Nice tool, thank you! I tested like below and it's not working yet...

It seemed to load my prebuilt OpenCV libraries that are different version from javacpp-opencv.

  1. remove my prebuilt OpenCV from PATH and run.

    Debugging1

    missing libraries are:

    • opencv_imgcodecs430.dll
    • opencv_video430.dll
    • opencv_calib3d430.dll
    • opencv_features2d430.dll
    • opencv_flann430.dll
    • opencv_imgproc430.dll
    • opencv_core430.dll
  2. copy all dll from cache\opencv-4.3.0-1.5.3-windows-x86_64-gpu.jar\org\bytedeco\opencv\windows-x86_64-gpu

    I have some of missing libraries in opencv-gpu cache, so copy all dll to working directory and run.

    Debugging2

    missing libraries are:

    • opencv_video430.dll

    error message has changed

    mat_cuda succeed
    orb_cuda succeed
    temp_cuda succeed
    java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.opencv.global.opencv_ximgproc
        at java.lang.Class.forName0 (Native Method)
        at java.lang.Class.forName (Class.java:398)
        at org.bytedeco.javacpp.Loader.load (Loader.java:1176)
        at org.bytedeco.javacpp.Loader.load (Loader.java:1109)
        at org.bytedeco.opencv.opencv_cudaoptflow.DenseOpticalFlow.<clinit> (DenseOpticalFlow.java:57)
        at Main.main (Main.java:32)
        at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:254)
        at java.lang.Thread.run (Thread.java:834)
    

I have 2 questions.

  1. Why didn't they load opencv-gpu cache?
  2. Why is opencv_video430.dll missing in opencv cache?

@saudet
Copy link
Member

saudet commented Jul 18, 2020

Those are probably the files that have issues loading. Please check the dependencies of those modules.

@n-kai-cj
Copy link
Contributor Author

I totally forgot the documentation saying (https://github.com/bytedeco/javacpp-presets/tree/master/opencv#documentation).

∗ Call Loader.load(opencv_java.class) before using the API in the org.opencv namespace.

Finally my fixed code works well.

import org.bytedeco.javacpp.Loader;
import org.bytedeco.opencv.global.opencv_core;
import org.bytedeco.opencv.global.opencv_cudaimgproc;
import org.bytedeco.opencv.global.opencv_imgproc;
import org.bytedeco.opencv.opencv_core.GpuMat;
import org.bytedeco.opencv.opencv_cudaoptflow.FarnebackOpticalFlow;
import org.bytedeco.opencv.opencv_cudafeatures2d.ORB;
import org.bytedeco.opencv.opencv_cudaimgproc.TemplateMatching;
import org.bytedeco.opencv.opencv_java;

import java.io.IOException;

public class Main {
    public static void main(String[] args) {
        Loader.load(opencv_java.class);
        try {
            Loader.load(org.bytedeco.opencv.opencv_cudaoptflow.FarnebackOpticalFlow.class);
        } catch (UnsatisfiedLinkError e) {
            try {
            String path = Loader.cacheResource(org.bytedeco.opencv.opencv_cudaoptflow.FarnebackOpticalFlow.class, "windows-x86_64/jniopencv_ximgproc.dll").getPath();
            new ProcessBuilder("c:/DependenciesGui.exe", path).start().waitFor();
            } catch (IOException|InterruptedException e1) {
                e1.printStackTrace();
            }
        }
        GpuMat mat_cuda = new GpuMat();
        System.out.println("mat_cuda succeed");
        ORB orb_cuda = ORB.create();
        System.out.println("orb_cuda succeed");
        TemplateMatching temp_cuda = opencv_cudaimgproc.createTemplateMatching(opencv_core.CV_8UC1, opencv_imgproc.TM_SQDIFF);
        System.out.println("temp_cuda succeed");
        FarnebackOpticalFlow optflow_cuda = FarnebackOpticalFlow.create();
        System.out.println("optflow_cuda succeed");
    }
}

and run

mat_cuda succeed
orb_cuda succeed
temp_cuda succeed
optflow_cuda succeed

Thank you for your help @saudet !!

@saudet
Copy link
Member

saudet commented Jul 19, 2020

We shouldn't need to load opencv_java for this. I've narrowed down the issue to opencv_ximgproc actually depending on opencv_video, so we can call Loader.load(opencv_video.class) to work around this. I'll be fixing this. Thanks for reporting!

@saudet saudet added the bug label Jul 19, 2020
saudet added a commit that referenced this issue Jul 20, 2020
…ONNX Runtime, etc (issue #907)

 * Fix loading issue with `opencv_ximgproc` (issue #911)
saudet added a commit that referenced this issue Jul 20, 2020
…ONNX Runtime, etc (issue #907)

 * Fix loading issue with `opencv_ximgproc` (issue #911)
@saudet
Copy link
Member

saudet commented Sep 10, 2020

Fix included in version 1.5.4! Thanks for reporting

@saudet saudet closed this as completed Sep 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants