dcm4che 5.29.1 gives libopencv error on raspberry pi4.

196 views
Skip to first unread message

Yogesh Devi

unread,
Jan 24, 2023, 5:48:51 AM1/24/23
to dcm4che
Hello,

We are using dcm4che version 5.29.1 jars in a java program  running on Raspberry Pi (Raspberry Pi 4 Model B Rev 1.2 ) .  
This is used with the  weasis-core-img-4.5.5.jar and libopencv_java.so to perform compression decompression using JNI 

Same code runs fine on a google virtual machine running ARM 64 bit processors with a higher memory provisioning .

Since this is running on a Raspberry Pi 4 Model B with a  64 bit arm processor we use the  ARM aarch64 libopencv_java.so library 

onour Pu4 server , On attempting compression the code throws  a  Native JPEG encoding error 

The excerpt from stack trace is attached below

Please suggest what we can to to prevent this error 

Caused by: org.opencv.core.CvException: cv::Exception: OpenCV(4.5.5) /work/modules/imgcodecs/src/loadsave.cpp:1219: error: (-215:Assertion failed) code in function 'dicomJpgWrite'

        at org.dcm4che3.net.ApplicationEntity.onDimseRQ(ApplicationEntity.java:474)
        at org.dcm4che3.net.Association.onDimseRQ(Association.java:746)
        at org.dcm4che3.net.PDUDecoder.decodeDIMSE(PDUDecoder.java:466)
        at org.dcm4che3.net.Association.handlePDataTF(Association.java:729)
        at org.dcm4che3.net.State$4.onPDataTF(State.java:103)
        at org.dcm4che3.net.Association.onPDataTF(Association.java:725)
        at org.dcm4che3.net.PDUDecoder.nextPDU(PDUDecoder.java:177)
        at org.dcm4che3.net.Association$2.run(Association.java:562)
        

Caused by: javax.imageio.IIOException: Native JPEG encoding error
        at org.dcm4che3.opencv.NativeJPEGImageWriter.write(NativeJPEGImageWriter.java:167)
        at org.dcm4che3.imageio.codec.Compressor$CompressedFrame.compress(Compressor.java:314)
        at org.dcm4che3.imageio.codec.Compressor$CompressedFrame.getEncodedLength(Compressor.java:269)
        at org.dcm4che3.imageio.codec.Compressor$CompressedFrame.calcLength(Compressor.java:263)
        at org.dcm4che3.data.Fragments.calcLength(Fragments.java:164)
        at org.dcm4che3.data.Attributes.calcLength(Attributes.java:2879)
        at org.dcm4che3.data.Attributes.calcLength(Attributes.java:2862)
        at org.dcm4che3.io.DicomOutputStream.writeDataset(DicomOutputStream.java:148)
        at com.nttdata.uca.dicomfile.impl.DicomFileService.writeDicomFile(DicomFileService.java:217)
        ... 16 common frames omitted
Caused by: org.opencv.core.CvException: cv::Exception: OpenCV(4.5.5) /work/modules/imgcodecs/src/loadsave.cpp:1219: error: (-215:Assertion failed) code in function 'dicomJpgWrite'

Nicolas Roduit

unread,
Jan 24, 2023, 1:54:08 PM1/24/23
to dcm4che
Is there more information about the error? Are you sure to have the right related version of the native library?

Default installations are usually with a 32-bit system even on 64-bit processors. If this is the case you need the 32-bit library.

Yogesh Devi

unread,
Jan 25, 2023, 2:09:25 AM1/25/23
to dcm4che
Hello Nick 
Thanks for your response - I will try with teh 32 bit library and let you know how it goes 

Meanwhile - to answer your question . Yes I am using the arm version of library 
Let me share some specific information below 

System information 
inxi -Fxz
System:    Kernel: 5.4.0-1078-raspi aarch64 bits: 64 compiler: gcc v: 9.4.0 Console: tty 4
           Distro: Ubuntu 20.04.5 LTS (Focal Fossa)
Machine:   Type: ARM Device System: Raspberry Pi 4 Model B Rev 1.2 details: BCM2835 rev: c03112
           serial: <filter>
CPU:       Topology: Quad Core model: N/A variant: cortex-a72 bits: 64 type: MCP arch: ARMv8 rev: 3
           features: Use -f option to see features bogomips: 432
           Speed: 700 MHz min/max: 600/1500 MHz Core speeds (MHz): 1: 700 2: 700 3: 700 4: 700


Library information 
 file libopencv_java.so
libopencv_java.so: ELF 64-bit LSB shared object, ARM aarch64, version 1 (GNU/Linux), dynamically linked, with debug_info, not stripped
 ldd libopencv_java.so
        linux-vdso.so.1 (0x0000ffff82494000)
        libdl.so.2 => /lib/aarch64-linux-gnu/libdl.so.2 (0x0000ffff818f5000)
        libpthread.so.0 => /lib/aarch64-linux-gnu/libpthread.so.0 (0x0000ffff818c4000)
        libm.so.6 => /lib/aarch64-linux-gnu/libm.so.6 (0x0000ffff81819000)
        libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000ffff816a6000)
        /lib/ld-linux-aarch64.so.1 (0x0000ffff82464000)


DCM4Che information 
dcm4che-core-5.29.1.jar   
dcm4che-imageio-5.29.1.jar        
...

Weasis 
 weasis-core-img-4.5.5.jar

Permissions 
all have rwx permissions for the user running these libraries 


Yogesh Devi

unread,
Jan 25, 2023, 3:10:31 AM1/25/23
to dcm4che
With the 32 bit library it gives a clear " architecture word width mismatch" error that I was almost expecting 
relevant stack trace is below 

2023-01-25 08:05:01.750 [1664743|46] DEBUG org.dcm4che3.net.Dimse - ANY-SCP<-DCMSEND(1) >> 1:C-STORE-RQ Dataset       receiving...
2023-01-25 08:05:02.064 [1664743|46] ERROR c.n.u.d.scp.service.CStoreService - Error occurred while storing DICO      M file for SOPInstanceUID '2.16.840.1.114255.65850.1.1.11'
java.lang.UnsatisfiedLinkError: /opt/uca/lib/libopencv_java.so: /opt/uca/lib/libopencv_java.so: wrong ELF class:       ELFCLASS32 (Possible cause: architecture word width mismatch)
        at java.base/java.lang.ClassLoader$NativeLibrary.load0(Native Method)
        at java.base/java.lang.ClassLoader$NativeLibrary.load(ClassLoader.java:2445)
        at java.base/java.lang.ClassLoader$NativeLibrary.loadLibrary(ClassLoader.java:2501)
        at java.base/java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2700)
        at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2662)
        at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:830)
        at java.base/java.lang.System.loadLibrary(System.java:1873)
        at org.opencv.osgi.OpenCVNativeLoader.init(OpenCVNativeLoader.java:17)
        at org.dcm4che3.opencv.NativeJPEGImageWriter.<clinit>(NativeJPEGImageWriter.java:79)
        at org.dcm4che3.opencv.NativeJPEGImageWriterSpi.createWriterInstance(NativeJPEGImageWriterSpi.java:123)
        at java.desktop/javax.imageio.spi.ImageWriterSpi.createWriterInstance(ImageWriterSpi.java:351)
        at java.desktop/javax.imageio.ImageIO$ImageWriterIterator.next(ImageIO.java:849)
        at java.desktop/javax.imageio.ImageIO$ImageWriterIterator.next(ImageIO.java:833)
        at org.dcm4che3.imageio.codec.ImageWriterFactory.getImageWriterFromImageIOServiceRegistry(ImageWriterFac      tory.java:245)
        at org.dcm4che3.imageio.codec.ImageWriterFactory.getImageWriter(ImageWriterFactory.java:237)
        at org.dcm4che3.imageio.codec.Compressor.compress(Compressor.java:141)
        at com.nttdata.uca.dicom.image.handler.impl.DicomImageHandlerImpl.compress(DicomImageHandlerImpl.java:10   


And BTW - on my google based arm VM the 64 bit library works just fine .. so I am not sure what is teh problem on the bare metal arm raspberry pi
Message has been deleted

Yogesh Devi

unread,
Jan 25, 2023, 5:50:33 AM1/25/23
to dcm4che
So Nick - this problem is fixed - 
I continue to use the 64 bit library for arm - and ths system remains same 

ONLY difference  - is that I did an 
apt update 
followed by a
apt upgrade 
And that fixed it for me 
Sadly I had not kept record of package versions so not sure what changed 
This is how the library looks like now ( same as before - except that the loaded address has changed - 

libopencv_java.so: ELF 64-bit LSB shared object, ARM aarch64, version 1 (GNU/Linux), dynamically linked, with debug_info, not stripped

root@pi4-01:/opt/uca/lib# ldd libopencv_java.so
        linux-vdso.so.1 (0x0000ffffbbd2e000)
        libdl.so.2 => /lib/aarch64-linux-gnu/libdl.so.2 (0x0000ffffbb18f000)
        libpthread.so.0 => /lib/aarch64-linux-gnu/libpthread.so.0 (0x0000ffffbb15e000)
        libm.so.6 => /lib/aarch64-linux-gnu/libm.so.6 (0x0000ffffbb0b3000)
        libc.so.6 => /lib/aarch64-linux-gnu/libc.so.6 (0x0000ffffbaf40000)
        /lib/ld-linux-aarch64.so.1 (0x0000ffffbbcfe000)


I am sure glad its working ; I'd have been happier if I could tell - what changed when I did apt update and apt upgrade 

Anyways grateful thanks for your help

Nicolas Roduit

unread,
Jan 27, 2023, 3:31:43 AM1/27/23
to dcm4che
As the library is built in a static way, I don't understand the reason. The only dependency is GLibC. Maybe it's related to a system-level bug that was fixed by updating it. 

Yogesh Devi

unread,
Feb 13, 2023, 9:11:22 AM2/13/23
to dcm4che
Hello,

I am reopening this thread because - while on the Raspberry Pi4 server this problem went away,  it re-appeared with the same software running on a newer model of raspberry pi.
This time it  wont go away despite a system patch update.

System:    Kernel: 5.10.66-27-rockchip-gea60d388902d aarch64 bits: 64 compiler: N/A
           Console: tty 3 Distro: Ubuntu 20.04.5 LTS (Focal Fossa)
Machine:   Type: ARM Device System: Radxa ROCK 5B details: N/A serial: <filter>
CPU:       Topology: 8-Core (3-Die) model: N/A variant-1: cortex-a76 variant-2: cortex-a55
           bits: 64 type: MCP MCM arch: ARMv8
           features: Use -f option to see features bogomips: 0
           Speed: 408 MHz min/max: 408/1800:2400 MHz Core speeds (MHz): 1: 408 2: 408
           3: 408 4: 408 5: 408 6: 408 7: 408 8: 408
Info:      Processes: 273 Uptime: 10h 01m Memory: 7.51 GiB used: 4.32 GiB (57.4%)
           Init: systemd runlevel: 5 Compilers: gcc: 9.4.0 Shell: bash v: 5.0.17
           inxi: 3.0.38

To refresh the context.
We are using dcm4che version 5.29.1 jars in a java program  running on Raspberry Pi (Raspberry Pi 4 Model B Rev 1.2 ) .  
This is used with the  weasis-core-img-4.5.5.jar and libopencv_java.so to perform compression and decompression using JNI 

We are using the arm 64 bit version of the libopencv_java.so library ( see below) 
$ file libopencv_java.so

libopencv_java.so: ELF 64-bit LSB shared object, ARM aarch64, version 1 (GNU/Linux), dynamically linked, with debug_info, not stripped


Very interesting that the decompression path works perfectly fine - its only in the compression path we get an exception with stack trace as follows that indicates there is an error in  org.opencv.imgcodecs.Imgcodecs.dicomJpgWrite_0(Native Method) 
at org.dcm4che3.net.ApplicationEntity.onDimseRQ(ApplicationEntity.java:474)
        at org.dcm4che3.net.Association.onDimseRQ(Association.java:746)
        at org.dcm4che3.net.PDUDecoder.decodeDIMSE(PDUDecoder.java:466)
        at org.dcm4che3.net.Association.handlePDataTF(Association.java:729)
        at org.dcm4che3.net.State$4.onPDataTF(State.java:103)
        at org.dcm4che3.net.Association.onPDataTF(Association.java:725)
        at org.dcm4che3.net.PDUDecoder.nextPDU(PDUDecoder.java:177)
        at org.dcm4che3.net.Association$2.run(Association.java:562)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at java.base/java.lang.Thread.run(Thread.java:829)

Caused by: javax.imageio.IIOException: Native JPEG encoding error
        at org.dcm4che3.opencv.NativeJPEGImageWriter.write(NativeJPEGImageWriter.java:167)
        at org.dcm4che3.imageio.codec.Compressor$CompressedFrame.compress(Compressor.java:314)
        at org.dcm4che3.imageio.codec.Compressor$CompressedFrame.getEncodedLength(Compressor.java:269)
        at org.dcm4che3.imageio.codec.Compressor$CompressedFrame.calcLength(Compressor.java:263)
        at org.dcm4che3.data.Fragments.calcLength(Fragments.java:164)
        at org.dcm4che3.data.Attributes.calcLength(Attributes.java:2879)
        at org.dcm4che3.data.Attributes.calcLength(Attributes.java:2862)
        at org.dcm4che3.io.DicomOutputStream.writeDataset(DicomOutputStream.java:148)
        at com.nttdata.uca.dicomfile.impl.DicomFileService.writeDicomFile(DicomFileService.java:217)
        ... 16 common frames omitted
Caused by: org.opencv.core.CvException: cv::Exception: OpenCV(4.5.5) /work/modules/imgcodecs/src/loadsave.cpp:1219: error: (-215:Assertion failed) code in function 'dicomJpgWrite'
        at org.opencv.imgcodecs.Imgcodecs.dicomJpgWrite_0(Native Method)
        at org.opencv.imgcodecs.Imgcodecs.dicomJpgWrite(Imgcodecs.java:545)
        at org.dcm4che3.opencv.NativeJPEGImageWriter.write(NativeJPEGImageWriter.java:153)
        ... 24 common frames omitted

 It is worth taking note that code and library work fine for performing decompression,  -it is only during compression we get this error 

Thanks for your help 

Yogesh 

Message has been deleted

Yogesh Devi

unread,
Feb 14, 2023, 12:58:39 AM2/14/23
to dcm4che
A correction - we are using  RadXa ROCK 5B  (and not a newer version of raspberry pi as I mentioned)  - 
ROCK 5B   uses  ARM Cortex-A76 as its evident from  inxi -Fxz output cited in original question

Nicolas Roduit

unread,
Feb 14, 2023, 1:42:15 AM2/14/23
to dcm4che
The error is in writing the compressed image in JPEG. However, the error is not explicit.

There is a new version in the next release of dcm4chee (5.29.2) which contains important changes for JPEG2000 and for the memory management between Java and the system. You can try this new version.

Yogesh Devi

unread,
Feb 14, 2023, 8:13:23 AM2/14/23
to dcm4che
Hi Nick - thanks a lot  - I will try it once released ( any idea when is the ETA ? ) and post the results 
Message has been deleted

Yogesh Devi

unread,
Feb 15, 2023, 11:34:49 AM2/15/23
to dcm4che
So 

Again - looks like  installing a few packages and  OS patch updates followed by restart fixed this problem 


It had continued to fail despite updates  as looks like some Ubuntu repos were not configured  in the /etc/apt/sources.list on Ubuntu , That  had limited entries as follows 
deb http://ports.ubuntu.com/ubuntu-ports/ focal main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports/ focal-security main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports/ focal-updates main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports/ focal-backports main restricted universe multiverse

I then borrowed a more comprehensive /etc/apt/sources.list from the pi4 box ( that had following 10 repos configured) 
deb http://ports.ubuntu.com/ubuntu-ports focal main restricted
deb http://ports.ubuntu.com/ubuntu-ports focal-updates main restricted
deb http://ports.ubuntu.com/ubuntu-ports focal universe
deb http://ports.ubuntu.com/ubuntu-ports focal-updates universe
deb http://ports.ubuntu.com/ubuntu-ports focal multiverse
deb http://ports.ubuntu.com/ubuntu-ports focal-updates multiverse
deb http://ports.ubuntu.com/ubuntu-ports focal-backports main restricted universe multiverse
deb http://ports.ubuntu.com/ubuntu-ports focal-security main restricted
deb http://ports.ubuntu.com/ubuntu-ports focal-security universe
deb http://ports.ubuntu.com/ubuntu-ports focal-security multiverse

Moreover  I installed some more packages for different reasons ; while I don't think its related - posting the list anyways 

  • apt install rockchip-overlay
  • apt install fio
  • apt install sysstat
  • apt install hdparm
  • apt install mariadb-common
  • apt install mariadb-client mariadb-server mycli
  • apt install htop
  • apt install git
  • apt install npm
  • apt install traceroute
  • apt install curl
  • apt install tcpdump
  • apt install netplan
  • apt install netplan.io
  • apt install accountservice
  • apt install inxi
  • apt install wireguard

I will be glad to hear opinions on what made the JNI error go away ... and why 
Thanks for your patience 

Nicolas Roduit

unread,
Feb 17, 2023, 2:55:26 AM2/17/23
to dcm4che
The error is in the library that compresses to jpeg. I guess the error is not caught by the third-party library but only in my code. This makes it difficult to debug.

Unfortunately, as this problem only appears on this system and seems to be directly related to a bug or a missing library in the base installation, I can't invest time to find the problem.
Reply all
Reply to author
Forward
0 new messages