MultiTemplateMatching-Fiji icon indicating copy to clipboard operation
MultiTemplateMatching-Fiji copied to clipboard

opencv not found after installation via update site

Open amichaut opened this issue 2 years ago • 6 comments

Hi, I have followed the installation procedure via the Fiji updater. I can see that IJ-opencv and multi-template-matching are installed (as they appear in the plugins dropdown menu).

However, when I run the Template Matching Image function, I have an error saying that the OpenCV dependencies are missing and the following error is raised: java.lang.NoClassDefFoundError: java.lang.NoClassDefFoundError: Could not initialize class org.bytedeco.javacpp.opencv_core

System: macOS 12.6.3 Fiji 2.9.0/1.53t

amichaut avatar Feb 28 '23 18:02 amichaut

Hi there, thanks for reporting the issue,

The problematic import statement is the following one : https://github.com/multi-template-matching/MultiTemplateMatching-Fiji/blob/53437bbb4e7129240c7ecf61443f2d6721ed6da6/Fiji.app/jars/Lib/Template_Matching/MatchTemplate_Module.py#L25

To reproduce the issue, I believe activating IJ-OpenCV and running this line in the script editor, selecting python as language should trigger a similar error.

I dont have a solution, but I think it might be due to the operating system. The import statement above, loads the opencv functions from platform-specific jars. All of them are shipped with the update site, and by some magic, the correct package is imported. It seems it's not the case for your OS.

Can you first check that you have all these jars in the subfolder jars of your Fiji installation ? image

If yes, maybe try moving all these packages out of the jars directory, except for the macosx one.

LauLauThom avatar Mar 03 '23 09:03 LauLauThom

Hi, Thanks for the reply! Running the import line in a script editor reproduces the error indeed. I moved out the linux and windows jars but running the import line in a script editor still raises the following error: Caused by: java.lang.UnsatisfiedLinkError: /Users/amichaut/.javacpp/cache/opencv-3.4.2-1.4.2-macosx-x86_64.jar/org/bytedeco/javacpp/macosx-x86_64/libjniopencv_core.dylib: dlopen(/Users/amichaut/.javacpp/cache/opencv-3.4.2-1.4.2-macosx-x86_64.jar/org/bytedeco/javacpp/macosx-x86_64/libjniopencv_core.dylib, 0x0001): Library not loaded: '@rpath/libopencv_imgproc.3.4.dylib' Referenced from: '/Users/amichaut/.javacpp/cache/opencv-3.4.2-1.4.2-macosx-x86_64.jar/org/bytedeco/javacpp/macosx-x86_64/libjniopencv_core.dylib' Reason: tried: '/Applications/Fiji.app/lib/macosx/libopencv_imgproc.3.4.dylib' (no such file), '/Applications/Fiji.app/mm/macosx/libopencv_imgproc.3.4.dylib' (no such file), '/Users/amichaut/.javacpp/cache/opencv-3.4.2-1.4.2-macosx-x86_64.jar/org/bytedeco/javacpp/macosx-x86_64/./libopencv_imgproc.3.4.dylib' (no such file), '/Users/travis/build/bytedeco/javacpp-presets/opencv/cppbuild/macosx-x86_64/lib/libopencv_imgproc.3.4.dylib' (no such file), '/Users/amichaut/.javacpp/cache/opencv-3.4.2-1.4.2-macosx-x86_64.jar/org/bytedeco/javacpp/maco

amichaut avatar Mar 03 '23 12:03 amichaut

Interesting, I had never noticed some files were being cached in the user directory ^^ ! It seems in your case it cant find the file related to opencv_imgproc

This is what I have in my user directory .javacpp/cache... image

Do you have something like that in your directory ? if yes do you have a file with imgproc in the name ?

LauLauThom avatar Mar 03 '23 13:03 LauLauThom

Yes I have. but it is a .dylib file (and actually it's a symbolic link pointing to another directory in the cache). Here's the content of the directory

-rw-r--r--  1 amichaut  staff   3,9M 16 jul  2018 libjniopencv_core.dylib
lrwxr-xr-x  1 amichaut  staff   115B 28 fév 19:14 libopencv_core.4.0.dylib@ -> /Users/amichaut/.javacpp/cache/opencv-macosx-x86_64.jar/org/bytedeco/javacpp/macosx-x86_64/libopencv_core.4.0.dylib
lrwxr-xr-x  1 amichaut  staff   118B 28 fév 19:14 libopencv_imgproc.4.0.dylib@ -> /Users/amichaut/.javacpp/cache/opencv-macosx-x86_64.jar/org/bytedeco/javacpp/macosx-x86_64/libopencv_imgproc.4.0.dylib

amichaut avatar Mar 03 '23 14:03 amichaut

hmm not sure what is going wrong there, maybe some permission issue on the directory ? Is there a way to run Fiji in admin ? Maybe delete the content of this cache directory.

Eventually you can try the next version of these dependencies, maybe it was fixed by then. Try version 3.4.3-1.4.3 for instance.

It's a bit tedious you have to download the packages manually from the link below, clicking the market artefact then download button on the right(see screencapture). And move the previous jar out of the Fiji.app/jars directory. image

So opencv https://oss.sonatype.org/#nexus-search;gav~org.bytedeco.javacpp-presets~opencv~~~~kw,versionexpand

Same for JavaCV (take the matching version, so here it would be 1.4.3) https://oss.sonatype.org/#nexus-search;quick~javacv image

and javacpp https://oss.sonatype.org/#nexus-search;gav~org.bytedeco~javacpp~~~ image

Otherwise it can be worse searching through (the numerous) issues of javacpp https://github.com/bytedeco/javacpp/issues?q=is%3Aissue+mac+

LauLauThom avatar Mar 03 '23 14:03 LauLauThom

ok, thanks a lot for your help. I have just tried removing the cache directory for now but it didn't change anything

amichaut avatar Mar 03 '23 16:03 amichaut