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 Cuda warping bug #806

Closed
Senna-chan opened this issue Oct 16, 2019 · 10 comments
Closed

Opencv Cuda warping bug #806

Senna-chan opened this issue Oct 16, 2019 · 10 comments

Comments

@Senna-chan
Copy link

Hello,

After compiling opencv with cuda on my devboard I've run into a problem.
The wrapper for cuda to warp mats is wrong.
The parameters are input(GpuMat), output(GpuMat), M(GpuMat)
It needs to be input(GpuMat), output(GpuMat), M(Mat)
This is with the warpAffine and warpPerspective function

I do not know if it is with more cuda functions but I will update this issue if I encounter more errors

@saudet
Copy link
Member

saudet commented Oct 16, 2019

I'm pretty sure we can use a GpuMat for M regardless. What error do you get when you try it that way?

@Senna-chan
Copy link
Author

linux-arm64-gpu/opencv-4.0.1/modules/core/src/matrix_wrap.cpp:118: error: (-213:The function/feature is not implemented) You should explicitly call download method for cuda::GpuMat object in function 'getMat_'
The underlying C++ code is calling getMat instead of getGpuMat in getMat there is a check for what kind of mat it is and if it is a CUDA_GPU_MAT(GpuMat) it gives an error.

@saudet
Copy link
Member

saudet commented Oct 16, 2019

The one from the core module probably doesn't support GpuMat, that's normal. Try the one from the cudawarping module.

@Senna-chan
Copy link
Author

That is the one from cudawarping.
This is a part of the code

void cv::cuda::warpPerspective(InputArray _src, OutputArray _dst, InputArray _M, Size dsize, int flags, int borderMode, Scalar borderValue, Stream& stream)
{
    GpuMat src = _src.getGpuMat();
    Mat M = _M.getMat();

    CV_Assert( M.rows == 3 && M.cols == 3 );

When changed to the code below the error goes away

void cv::cuda::warpPerspective(InputArray _src, OutputArray _dst, InputArray _M, Size dsize, int flags, int borderMode, Scalar borderValue, Stream& stream)
{
    GpuMat src = _src.getGpuMat();
    GpuMat __M = _M.getGpuMat();
    Mat M;
    __M.download(M); 

    CV_Assert( M.rows == 3 && M.cols == 3 );

Also an other thing. The videowriter gives the same error. There is a cuda videowriter but it is not exposed in Java.

saudet added a commit that referenced this issue Oct 17, 2019
…nd `cudabgsegm` modules of OpenCV (issue #806)

 * Fix mapping of `warpAffine` and `warpPerspective` from `opencv_cudawarping` (issue #806)
@Senna-chan
Copy link
Author

I tested the new build but could not start it. I do not know if I should report it here or in another issue. When starting I get the following error

Exception in thread "main" java.lang.UnsatisfiedLinkError: no jniopenblas_nolapack in java.library.path: [., /usr/local/cuda-10.0/lib64, /usr/local/lib, /home/farmbot/sourcebuilding/javacpp-presets-ci, /home/farmbot/sourcebuilding/javacpp-presets-ci/opencv/cppbuild/linux-arm64-gpu/lib, /usr/java/packages/lib, /usr/lib/aarch64-linux-gnu/jni, /lib/aarch64-linux-gnu, /usr/lib/aarch64-linux-gnu, /usr/lib/jni, /lib, /usr/lib]
	at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2660)
	at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:829)
	at java.base/java.lang.System.loadLibrary(System.java:1867)
	at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1543)
	at org.bytedeco.javacpp.Loader.load(Loader.java:1192)
	at org.bytedeco.javacpp.Loader.load(Loader.java:1042)
	at org.bytedeco.openblas.global.openblas_nolapack.<clinit>(openblas_nolapack.java:10)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:398)
	at org.bytedeco.javacpp.Loader.load(Loader.java:1109)
	at org.bytedeco.javacpp.Loader.load(Loader.java:1058)
	at nl.ideax.farmbot.camera.Main.main(Main.java:54)
Caused by: java.lang.UnsatisfiedLinkError: no quadmath in java.library.path: [., /usr/local/cuda-10.0/lib64, /usr/local/lib, /home/farmbot/sourcebuilding/javacpp-presets-ci, /home/farmbot/sourcebuilding/javacpp-presets-ci/opencv/cppbuild/linux-arm64-gpu/lib, /usr/java/packages/lib, /usr/lib/aarch64-linux-gnu/jni, /lib/aarch64-linux-gnu, /usr/lib/aarch64-linux-gnu, /usr/lib/jni, /lib, /usr/lib]
	at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2660)
	at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:829)
	at java.base/java.lang.System.loadLibrary(System.java:1867)
	at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1543)
	at org.bytedeco.javacpp.Loader.load(Loader.java:1143)
	... 7 more

I tried building openblas but that failed as well.
The board that I use now is a Nvidia Jetson AGX Xavier

@saudet
Copy link
Member

saudet commented Oct 17, 2019

I'm pretty sure it works, see issue #735. What does it look like with the system property "org.bytedeco.javacpp.logger.debug" set to "true"?

@Senna-chan
Copy link
Author

With debug on I get the following

Loading class org.bytedeco.openblas.global.openblas_nolapack
Loading class org.bytedeco.openblas.global.openblas_nolapack
Loading library gcc_s
Failed to load for gcc_s@.1: java.lang.UnsatisfiedLinkError: no gcc_s in java.library.path: [., /usr/local/cuda-10.0/lib64, /usr/local/lib, /home/farmbot/sourcebuilding/javacpp-presets-ci, /home/farmbot/sourcebuilding/javacpp-presets-ci/opencv/cppbuild/linux-arm64-gpu/lib, /usr/java/packages/lib, /usr/lib/aarch64-linux-gnu/jni, /lib/aarch64-linux-gnu, /usr/lib/aarch64-linux-gnu, /usr/lib/jni, /lib, /usr/lib]
Loading library quadmath
Failed to load for quadmath@.0: java.lang.UnsatisfiedLinkError: no quadmath in java.library.path: [., /usr/local/cuda-10.0/lib64, /usr/local/lib, /home/farmbot/sourcebuilding/javacpp-presets-ci, /home/farmbot/sourcebuilding/javacpp-presets-ci/opencv/cppbuild/linux-arm64-gpu/lib, /usr/java/packages/lib, /usr/lib/aarch64-linux-gnu/jni, /lib/aarch64-linux-gnu, /usr/lib/aarch64-linux-gnu, /usr/lib/jni, /lib, /usr/lib]
Loading /usr/lib/aarch64-linux-gnu/libgfortran.so
Loading /usr/lib/aarch64-linux-gnu/libgfortran.so.4
Loading /usr/lib/aarch64-linux-gnu/libgfortran.so
Loading /root/.javacpp/cache/aarch64-linux-gnu/libopenblas_nolapack.so.0
Loading library jniopenblas_nolapack
Failed to load for jniopenblas_nolapack: java.lang.UnsatisfiedLinkError: no jniopenblas_nolapack in java.library.path: [., /usr/local/cuda-10.0/lib64, /usr/local/lib, /home/farmbot/sourcebuilding/javacpp-presets-ci, /home/farmbot/sourcebuilding/javacpp-presets-ci/opencv/cppbuild/linux-arm64-gpu/lib, /usr/java/packages/lib, /usr/lib/aarch64-linux-gnu/jni, /lib/aarch64-linux-gnu, /usr/lib/aarch64-linux-gnu, /usr/lib/jni, /lib, /usr/lib]
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jniopenblas_nolapack in java.library.path: [., /usr/local/cuda-10.0/lib64, /usr/local/lib, /home/farmbot/sourcebuilding/javacpp-presets-ci, /home/farmbot/sourcebuilding/javacpp-presets-ci/opencv/cppbuild/linux-arm64-gpu/lib, /usr/java/packages/lib, /usr/lib/aarch64-linux-gnu/jni, /lib/aarch64-linux-gnu, /usr/lib/aarch64-linux-gnu, /usr/lib/jni, /lib, /usr/lib]
	at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2660)
	at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:829)
	at java.base/java.lang.System.loadLibrary(System.java:1867)
	at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1543)
	at org.bytedeco.javacpp.Loader.load(Loader.java:1192)
	at org.bytedeco.javacpp.Loader.load(Loader.java:1042)
	at org.bytedeco.openblas.global.openblas_nolapack.<clinit>(openblas_nolapack.java:10)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:398)
	at org.bytedeco.javacpp.Loader.load(Loader.java:1109)
	at org.bytedeco.javacpp.Loader.load(Loader.java:1058)
	at nl.ideax.farmbot.camera.Main.main(Main.java:54)
Caused by: java.lang.UnsatisfiedLinkError: no quadmath in java.library.path: [., /usr/local/cuda-10.0/lib64, /usr/local/lib, /home/farmbot/sourcebuilding/javacpp-presets-ci, /home/farmbot/sourcebuilding/javacpp-presets-ci/opencv/cppbuild/linux-arm64-gpu/lib, /usr/java/packages/lib, /usr/lib/aarch64-linux-gnu/jni, /lib/aarch64-linux-gnu, /usr/lib/aarch64-linux-gnu, /usr/lib/jni, /lib, /usr/lib]
	at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2660)
	at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:829)
	at java.base/java.lang.System.loadLibrary(System.java:1867)
	at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1543)
	at org.bytedeco.javacpp.Loader.load(Loader.java:1143)
	... 7 more

@saudet
Copy link
Member

saudet commented Oct 17, 2019

Looks like /root/.javacpp/cache/aarch64-linux-gnu/libopenblas_nolapack.so.0 isn't loading for some reason but JavaCPP isn't guessing right. What does ldd say on that file?

@saudet
Copy link
Member

saudet commented Oct 17, 2019

Actually that file most likely doesn't exist. The JAR files for OpenBLAS are probably just missing from the class path. If you're not using Maven, make sure you have everything it needs.

saudet added a commit that referenced this issue Oct 19, 2019
…nd `cudabgsegm` modules of OpenCV (issue #806)

 * Fix mapping of `warpAffine` and `warpPerspective` from `opencv_cudawarping` (issue #806)
@Senna-chan
Copy link
Author

The problem with OpenBLAS is fixed. Seems that maven didn't like to add the platform compiled jar to the classpath.

The other problems with the warp functions is solved.

Thanks for the quick responses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants