# Weasis (problem with opencv_java)



## martinrame (Feb 12, 2021)

Hi, I'm trying to run Weasis, a viewer for Medical Images (Dicom) written in java.

As you can see here: https://github.com/nroduit/Weasis/issues/175 I was able to run it, but I cannot see images because it relies on `opencv_java`.

Can anyone help me with this fix?.


----------



## SirDice (Feb 12, 2021)

Try installing graphics/opencv. You're going to need to build it from ports and enable the JAVA option. That option is off by default so it's not enabled for the package.


----------



## martinrame (Feb 12, 2021)

Thanks SirDice, I'll try building from the port, but I already installed the `opencv-java-3.4.1_37`, isn't that the same as compiling from ports?

Please see:


```
[leonardo@ws1 ~/.weasis/log] $ sudo pkg search opencv     
frei0r-plugins-opencv-1.6.1_1  Frei0r OpenCV plugins
gstreamer-plugins-opencv-0.10.23_6,3 Gstreamer opencv real time computer vision plugin
gstreamer1-plugins-opencv-1.16.2 GStreamer opencv real time computer vision plugin
opencv-3.4.1_37                Open Source Computer Vision library
opencv-core-3.4.1_37           Open Source Computer Vision library
opencv-java-3.4.1_37           Open Source Computer Vision library
opencvs-20151230               BSD-licensed CVS implementation
py37-opencv-3.4.1_37           Open Source Computer Vision library
```


----------



## martinrame (Feb 12, 2021)

Hi again SirDice, I built opencv with the JAVA option, from ports, but I still get the following error:


```
ERROR : bundle weasis-core-api:3.7.0 (9)[org.weasis.core.api.internal.cv.NativeOpenCVCodec(0)] : The activate method has thrown an exception
java.lang.UnsatisfiedLinkError: no opencv_java in java.library.path
```


----------



## shkhln (Feb 12, 2021)

> no opencv_java in java.library.path: [/usr/lib, /usr/local/lib]




```
% pkg info -l opencv-java
opencv-java-3.4.1_37:
    /usr/local/share/OpenCV/java/libopencv_java341.so
    /usr/local/share/OpenCV/java/opencv-341.jar
    /usr/local/share/licenses/opencv-java-3.4.1_37/BSD3CLAUSE
    /usr/local/share/licenses/opencv-java-3.4.1_37/LICENSE
    /usr/local/share/licenses/opencv-java-3.4.1_37/catalog.mk
```


----------



## martinrame (Feb 12, 2021)

Ok, I deinstalled the package compiled from ports, and reinstalled using `pkg`, but now the error doesn't mention the `[/usr/lib, /usr/local/lib`, just `java.lang.UnsatisfiedLinkError: no opencv_java in java.library.path`.

How can I set that variable (is an environment variable, no?).


----------



## martinrame (Feb 12, 2021)

I managed to set the library path to `/usr/local/share/OpenCV/java/` but the application still can't find the needed files, now the error is this:


```
ERROR : bundle weasis-core-api:3.7.0 (9)[org.weasis.core.api.internal.cv.NativeOpenCVCodec(0)] : The activate method has thrown an exception
java.lang.UnsatisfiedLinkError: no opencv_java in java.library.path: [/usr/local/share/OpenCV/java/]
```


----------



## Jose (Feb 13, 2021)

martinrame said:


> I managed to set the library path to `/usr/local/share/OpenCV/java/` but the application still can't find the needed files, now the error is this:
> 
> 
> ```
> ...


Maybe you need `ln -s libopencv_java341.so libopencv_java.so`?


----------



## martinrame (Feb 13, 2021)

Thanks, I'm making some progress on this, if you want you can follow here: https://github.com/nroduit/Weasis/issues/175


----------



## tuxador (Feb 13, 2021)

martinrame said:


> Thanks, I'm making some progress on this, if you want you can follow here: https://github.com/nroduit/Weasis/issues/175


Hi! thank you for sharing all the steps needed to make it working (i was using a small windows executable with wine).
i have an offtopic question: did you already manage to install gnuhealth in freebsd? i'am stuck with it actually.


----------



## martinrame (Feb 14, 2021)

tuxador said:


> Hi! thank you for sharing all the steps needed to make it working (i was using a small windows executable with wine).
> i have an offtopic question: did you already manage to install gnuhealth in freebsd? i'am stuck with it actually.


Hi, no I don't use GNUHealth, I tested it many years ago but it didn't fit my requirements at that time. Maybe it's time to take a look at it again.


----------



## martinrame (Feb 14, 2021)

I finally managed to make it work with linuxulator!.


----------



## tuxador (Feb 14, 2021)

martinrame said:


> I finally managed to make it work with linuxulator!.


Great! i hope you will tell us more about the process.


----------



## ziomario (Jul 1, 2022)

I'm looking for a way to install and make sikulix works on FreeBSD. I have a similar problem to yours,with the library opencv_java. Which version did you use when you tried to make Weasis work ? I ask this because you had found the package opencv-java-3.4.1_37 between the packages :


```
[leonardo@ws1 ~/.weasis/log] $ sudo pkg search opencv 


frei0r-plugins-opencv-1.6.1_1  Frei0r OpenCV plugins

gstreamer-plugins-opencv-0.10.23_6,3 Gstreamer opencv real time computer vision plugin

gstreamer1-plugins-opencv-1.16.2 GStreamer opencv real time computer vision plugin

opencv-3.4.1_37                Open Source Computer Vision library

opencv-core-3.4.1_37           Open Source Computer Vision library

opencv-java-3.4.1_37           Open Source Computer Vision library

opencvs-20151230               BSD-licensed CVS implementation

py37-opencv-3.4.1_37           Open Source Computer Vision library
```

but I'm not and I'm using FreeBSD 13.1-RELEASE :


```
mario@marietto:/home/marietto # pkg search opencv

frei0r-plugins-opencv-1.8.0    Frei0r OpenCV plugins
gstreamer1-plugins-opencv-1.16.2_3 GStreamer opencv real time computer vision plugin
opencv-4.5.5_7                 Open Source Computer Vision library
opencvs-20151230               BSD-licensed CVS implementation
```
 
I tried to compile opencv from ports enabling java like this :


```
mario@marietto:/usr/ports/graphics/opencv # make (enabled JAVA)
everything is ok

mario@marietto:/usr/ports/graphics/opencv # make install
everything is ok until this point :

  
===>  Installing for opencv-4.5.5_7
===>  Checking if opencv is already installed
===>   Registering installation for opencv-4.5.5_7
pkg-static: Unable to access file /usr/ports/graphics/opencv/work/stage/usr/local/lib/python3.9/site-packages/cv2/__init__.py:No such file or directory
pkg-static: Unable to access file /usr/ports/graphics/opencv/work/stage/usr/local/lib/python3.9/site-packages/cv2/config-3.9.py:No such file or directory
pkg-static: Unable to access file /usr/ports/graphics/opencv/work/stage/usr/local/lib/python3.9/site-packages/cv2/config.py:No such file or directory
pkg-static: Unable to access file /usr/ports/graphics/opencv/work/stage/usr/local/lib/python3.9/site-packages/cv2/gapi/__init__.py:No such file or directory
pkg-static: Unable to access file /usr/ports/graphics/opencv/work/stage/usr/local/lib/python3.9/site-packages/cv2/load_config_py2.py:No such file or directory
pkg-static: Unable to access file /usr/ports/graphics/opencv/work/stage/usr/local/lib/python3.9/site-packages/cv2/load_config_py3.py:No such file or directory
pkg-static: Unable to access file /usr/ports/graphics/opencv/work/stage/usr/local/lib/python3.9/site-packages/cv2/mat_wrapper/__init__.py:No such file or directory
pkg-static: Unable to access file /usr/ports/graphics/opencv/work/stage/usr/local/lib/python3.9/site-packages/cv2/misc/__init__.py:No such file or directory
pkg-static: Unable to access file /usr/ports/graphics/opencv/work/stage/usr/local/lib/python3.9/site-packages/cv2/misc/version.py:No such file or directory
pkg-static: Unable to access file /usr/ports/graphics/opencv/work/stage/usr/local/lib/python3.9/site-packages/cv2/python-3.9/cv2.cpython-39.so:No such file or directory
pkg-static: Unable to access file /usr/ports/graphics/opencv/work/stage/usr/local/lib/python3.9/site-packages/cv2/utils/__init__.py:No such file or directory
*** Error code 1

Stop.
make[1]: stopped in /usr/ports/graphics/opencv
*** Error code 1

Stop.
make: stopped in /usr/ports/graphics/opencv
```


Despite these errors,the `libopencv_java455.so file has been generated :`


```
mario@marietto:/home/marietto # find / -name libopencv_java455.so

/usr/ports/graphics/opencv/work/.build/lib/libopencv_java455.so
/usr/ports/graphics/opencv/work/stage/usr/local/share/java/opencv4/libopencv_java455.so
```


but it's not useful,because sikulix wants the file : libopencv_java430.so

Infact as soon as I have implemented my first "click on the image" function,I've got the error message that you see below and I don't know how to fix it :


```
[error] RunTime:loadLib: libopencv_java430.so (failed) probably dependent libs missing:
Can't load library: /root/.Sikulix/SikulixLibs/libopencv_java430.so
[error] Save your work, correct the problem and restart the IDE!
[error] see: [URL]https://github.com/RaiMan/SikuliX1/wiki/macOS-Linux:-Support-Libraries-for-OpenCV-4[/URL]
TERMINATING: problem with native library: libopencv_java430.so
[error] script [ click_image ] stopped with error in line 1
[error] java.lang.ExceptionInInitializerError ( java.lang.ExceptionInInitializerError )
[error] --- Traceback --- error source first
line: module ( function ) statement
1: main (  <module> )     click("1656348124939.png")
[error] --- Traceback --- end --------------
```



Do you have some suggestions for me ?


----------



## martinrame (Jul 1, 2022)

Hi!, I didn't find a solution for this. I ended up using the Linux version via Linuxulator.


----------



## ziomario (Jul 1, 2022)

How ? because I even tried to run sikulix with the linuxulator,but it didn't work for me. It wants the Xorg server. Does the tool that you need to run wants also Xorg ? I mean :


```
mario@marietto:/home/marietto # /usr/sbin/chroot /compat/ubuntu /bin/bash
mario@marietto:/home/mario/Sikulix# java -jar sikulixide-2.0.5.jar
No protocol specified
Exception in thread "main" java.awt.AWTError: Can't connect to X11 window server using ':0.0' as the
value of the DISPLAY variable.
at sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at sun.awt.X11GraphicsEnvironment.access$200(X11GraphicsEnvironment.java:65)
at sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:115)
at java.security.AccessController.doPrivileged(Native Method)
at sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:74)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:103)
at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:82)
at sun.awt.X11.XToolkit.<clinit>(XToolkit.java:132)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at java.awt.Toolkit$2.run(Toolkit.java:860)
at java.awt.Toolkit$2.run(Toolkit.java:855)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Toolkit.getDefaultToolkit(Toolkit.java:854)
at org.sikuli.ide.SikulixIDE.<clinit>(SikulixIDE.java:52)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at org.sikuli.script.support.RunTime.getRunningJar(RunTime.java:203)
at org.sikuli.script.support.RunTime.start(RunTime.java:125)
at org.sikuli.ide.Sikulix.main(Sikulix.java:13)
```


----------

