dcm4che / dcm4che

DICOM Implementation in JAVA
www.dcm4che.org
Other
1.17k stars 636 forks source link

STORESCU fails on opencv_java #1341

Open jssuttles opened 10 months ago

jssuttles commented 10 months ago

Describe the bug When using the storescu process, we get the following error: Exception in thread "main" java.lang.UnsatisfiedLinkError: \<file path>\opencv_java.dll: Can't find dependent libraries at java.base/jdk.internal.loader.NativeLibraries.load(Native Method) at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:388) at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:232) at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:174) at java.base/jdk.internal.loader.NativeLibraries.findFromPaths(NativeLibraries.java:315) at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:287) at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2422) at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:818) at java.base/java.lang.System.loadLibrary(System.java:1989) at org.opencv.osgi.OpenCVNativeLoader.init(OpenCVNativeLoader.java:17) at org.dcm4che3.opencv.StreamSegment.(StreamSegment.java:76) at org.dcm4che3.opencv.NativeImageReader.getNativeImage(NativeImageReader.java:260) at org.dcm4che3.opencv.NativeImageReader.read(NativeImageReader.java:251) at org.dcm4che3.imageio.codec.Decompressor.decompressFrame(Decompressor.java:299) at org.dcm4che3.imageio.codec.Decompressor.writeFrameTo(Decompressor.java:285) at org.dcm4che3.imageio.codec.Decompressor.writeTo(Decompressor.java:269) at org.dcm4che3.imageio.codec.Decompressor$1.writeTo(Decompressor.java:202) at org.dcm4che3.io.DicomOutputStream.writeAttribute(DicomOutputStream.java:213) at org.dcm4che3.io.DicomOutputStream.writeAttribute(DicomOutputStream.java:189) at org.dcm4che3.data.Attributes.writeTo(Attributes.java:3123) at org.dcm4che3.data.Attributes.writeTo(Attributes.java:3062) at org.dcm4che3.io.DicomOutputStream.writeDataset(DicomOutputStream.java:150) at org.dcm4che3.net.DataWriterAdapter.writeTo(DataWriterAdapter.java:67) at org.dcm4che3.net.PDUEncoder.writeDIMSE(PDUEncoder.java:475) at org.dcm4che3.net.Association.invoke(Association.java:1286) at org.dcm4che3.net.Association.invoke(Association.java:1274) at org.dcm4che3.net.Association.cstore(Association.java:939) at org.dcm4che3.tool.storescu.StoreSCU.send(StoreSCU.java:511) at org.dcm4che3.tool.storescu.StoreSCU.sendFiles(StoreSCU.java:415) at org.dcm4che3.tool.storescu.StoreSCU.main(StoreSCU.java:294)

This causes the store process to stop and fail.

To Reproduce We're not sure what causes this and how to reproduce this behavior.

Desktop (please complete the following information):

Additional context The storescu process works for some studies but fails for others. We've had this issue intermittently occur on certain other machines as well starting as far back as May 18th 2023.

jssuttles commented 10 months ago

We are still investigating this issue, but we're not as familiar with Java and OpenCV and a direction would certainly be helpful.

nroduit commented 10 months ago

Do you mean the command line storescu or with the Java API?

jssuttles commented 10 months ago

@nroduit Command line StoreSCU

nroduit commented 10 months ago

Did you modify the bat file? because I do not understand why you get "\<file path>\opencv_java.dll"

Or do you change the environment variable %DCM4CHE_HOME% or %JAVA_OPTS%

To debug, add "echo %JAVA_OPTS%" before the last command line of the bat file to show the command option.

jssuttles commented 10 months ago

Thanks for guidance. We do change the bat file. I'll take a look at this soon.

jssuttles commented 10 months ago
@echo off
rem -------------------------------------------------------------------------
rem storescu  Launcher
rem -------------------------------------------------------------------------

if not "%ECHO%" == ""  echo %ECHO%
if "%OS%" == "Windows_NT"  setlocal

set MAIN_CLASS=org.dcm4che3.tool.storescu.StoreSCU
set MAIN_JAR=dcm4che-tool-storescu-5.29.2.jar

set DIRNAME=.\
if "%OS%" == "Windows_NT" set DIRNAME=%~dp0%

rem Read all command line arguments

set ARGS=
:loop
if [%1] == [] goto end
        set ARGS=%ARGS% %1
        shift
        goto loop
:end

if not "%DCM4CHE_HOME%" == "" goto HAVE_DCM4CHE_HOME

set DCM4CHE_HOME=%DIRNAME%..

:HAVE_DCM4CHE_HOME

set JAVA=%DIRNAME%..\..\java\bin\java

set CP=%DCM4CHE_HOME%\etc\storescu\
set CP=%CP%;%DCM4CHE_HOME%\etc\certs\
set CP=%CP%;%DCM4CHE_HOME%\lib\%MAIN_JAR%
set CP=%CP%;%DCM4CHE_HOME%\lib\dcm4che-core-5.29.2.jar
set CP=%CP%;%DCM4CHE_HOME%\lib\dcm4che-net-5.29.2.jar
set CP=%CP%;%DCM4CHE_HOME%\lib\dcm4che-image-5.29.2.jar
set CP=%CP%;%DCM4CHE_HOME%\lib\dcm4che-imageio-5.29.2.jar
set CP=%CP%;%DCM4CHE_HOME%\lib\dcm4che-imageio-opencv-5.29.2.jar
set CP=%CP%;%DCM4CHE_HOME%\lib\dcm4che-imageio-rle-5.29.2.jar
set CP=%CP%;%DCM4CHE_HOME%\lib\dcm4che-tool-common-5.29.2.jar
set CP=%CP%;%DCM4CHE_HOME%\lib\weasis-core-img-4.6.0.jar
set CP=%CP%;%DCM4CHE_HOME%\lib\jai_imageio-1.2-pre-dr-b04.jar
set CP=%CP%;%DCM4CHE_HOME%\lib\clibwrapper_jiio-1.2-pre-dr-b04.jar
set CP=%CP%;%DCM4CHE_HOME%\lib\slf4j-api-1.7.32.jar
set CP=%CP%;%DCM4CHE_HOME%\lib\slf4j-simple-1.7.32.jar
set CP=%CP%;%DCM4CHE_HOME%\lib\commons-cli-1.4.jar

rem Setup native library path
"%JAVA%" -version 2>&1 | findstr 64-Bit >nul && set "OS=windows-x86-64" || set "OS=windows-x86"
set JAVA_LIBRARY_PATH=%DCM4CHE_HOME%\lib\%OS%

set JAVA_OPTS=%JAVA_OPTS% -Djava.library.path="%JAVA_LIBRARY_PATH%"

if not "%IMAGE_READER_FACTORY%" == "" ^
 set JAVA_OPTS=%JAVA_OPTS% -Dorg.dcm4che3.imageio.codec.ImageReaderFactory=%IMAGE_READER_FACTORY%

if not "%IMAGE_WRITER_FACTORY%" == "" ^
 set JAVA_OPTS=%JAVA_OPTS% -Dorg.dcm4che3.imageio.codec.ImageWriterFactory=%IMAGE_WRITER_FACTORY%

rem Required from JDK 16 with legacy image API (Decompressor and Compressor)
set JAVA_OPTS=%JAVA_OPTS% -XX:+IgnoreUnrecognizedVMOptions --add-opens=java.desktop/javax.imageio.stream=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED

"%JAVA%" %JAVA_OPTS% -cp "%CP%" %MAIN_CLASS% %ARGS%

We haven't upgraded to the latest version yet. We use slf4j-simple instead of logback. We use a packaged version of Java. I'll return with the java opts echo.

jssuttles commented 10 months ago

echo -Djava.library.path="\<filepath>\dcm4che\bin..\lib\windows-x86-64" -XX:+IgnoreUnrecognizedVMOptions --add-opens=java.desktop/javax.imageio.stream=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED -Djava.library.path="\<filepath>\dcm4che\bin..\lib\windows-x86-64" -XX:+IgnoreUnrecognizedVMOptions --add-opens=java.desktop/javax.imageio.stream=ALL-UNNAMED

jssuttles commented 10 months ago

To clarify: \<filepath> is me replacing my computer's file path with \<filepath>. That's not how it shows up in the error. (I just don't want my computer's file path available on the internet.)

jssuttles commented 10 months ago

(I hope you don't mind if I ping you @nroduit.)

nroduit commented 10 months ago

Please check with the original file first, as we cannot respond to issues that contain modifications.

jssuttles commented 9 months ago

Ok. I don't think I'll be able to do that where the issue occurs, but I'll see what I can do.