A Java wrapper around OpenCV with additions oriented toward medical imaging (window/level LUTs, segmentation primitives, raw image I/O). Packaged as an OSGi bundle that embeds the OpenCV Java classes and re-exports them, so consumers do not need a separate OpenCV dependency on the classpath. Used downstream by Weasis.
- Java 17 module (
org.weasis.core.img) re-exportingorg.opencv.core,imgcodecs,imgproc,img_hash,osgi,utils. PlanarImage/ImageCV—AutoCloseableabstraction over an OpenCVMatwith explicit release tracking.- Image operations split into focused entry points:
ImageAnalyzer(stats and measurements),ImageTransformer(geometric and visual operations),ImageIOHandler(read/write/thumbnails). - DICOM-oriented LUTs and presentation state helpers (
ByteLut,ColorLut,LutShape,LutParameters,WlParams,WlPresentation,DefaultWlPresentation,PresentationStateLut). - Segmentation primitives (
Region,Segment,ContourTopology,RegionAttributes). - Raw image format with a 46-byte header (
FileRawImage) and OpenCV-backed I/O. - Native-library resolver (
NativeLibrary) that mapsos.name/os.archto an OSGi-style<os>-<arch>spec and loadslibopencv_javafrom an absolute path or by library name.
- JDK 17 or later
- Maven 3.6.3 or later
- One of the supported OS/architecture pairs for tests:
linux-x86-64,linux-aarch64,macosx-x86-64,macosx-aarch64,windows-x86-64.
From the repository root:
mvn clean installBuild and test the bundle module only:
mvn -f weasis-core-img clean installRun tests:
mvn -f weasis-core-img testRun a single test class or method:
mvn -f weasis-core-img test -Dtest=ImageProcessorTest
mvn -f weasis-core-img test -Dtest=ImageProcessorTest#methodNameProduce a coverage report (JaCoCo, used by CI and SonarCloud):
mvn -Pcoverage -f weasis-core-img verifyApply formatting before committing (google-java-format + EPL-2.0 / Apache-2.0 license header):
mvn -f weasis-core-img spotless:applySpotless is not bound to a build phase, so it only runs when invoked explicitly.
All OpenCV native dependencies are declared with provided scope. A downstream application is expected to
ship the matching native library and load it at runtime by either:
- setting
-Djava.library.path="path/of/native/lib"and callingNativeLibrary.loadLibraryFromLibraryName(), or - calling
NativeLibrary.loadLibraryFromAbsolutePath(path)with the absolute path tolibopencv_java.
During tests, Maven unpacks the native library into
weasis-core-img/target/lib/<os-name>-<cpu-name>/ and Surefire is configured to point -Djava.library.path
there. The OS/arch profile in the root pom.xml selects which native classifier is unpacked.
Additional native binaries (other systems and architectures) are published in this Maven repository.
The artifact version tracks the underlying OpenCV release (currently 4.13.0), suffixed with a local
revision (.1).
<dependency>
<groupId>org.weasis.core</groupId>
<artifactId>weasis-core-img</artifactId>
<version>4.13.0.1</version>
</dependency>A matching native classifier must be added separately, for example for Linux x86-64:
<dependency>
<groupId>org.weasis.thirdparty.org.opencv</groupId>
<artifactId>libopencv_java</artifactId>
<version>4.13.0-dcm</version>
<type>so</type>
<classifier>linux-x86-64</classifier>
</dependency>Other classifiers: linux-aarch64, macosx-x86-64 / macosx-aarch64 (type dylib),
windows-x86-64 (artifactId opencv_java, type dll).
Two-module Maven build:
- Root
pom.xml— BOM (weasis-core-img-bom) pinningweasis.opencv.versionand declaring all supported native classifiers. weasis-core-img/— the library itself (packagingbundle; the OSGI bundle plugin embeds dependencies inline underlib/).
Main source roots under weasis-core-img/src/main/java:
org.weasis.core.util— generic helpers (file, string, math, stream, zip,Pair/Triple,SoftHashMap).org.weasis.opencv.natives— native-library loader.org.weasis.opencv.data— image data types (PlanarImage,ImageCV,FileRawImage,LookupTableCV,MetadataParser,ImageSize).org.weasis.opencv.op— image operations (ImageAnalyzer,ImageTransformer,ImageIOHandler,ImageConversion,ImageContentHash). The legacyImageProcessorfacade is kept for backward compatibility but is deprecated — new code should use the split classes above.org.weasis.opencv.op.lut— window/level and presentation LUTs.org.weasis.opencv.seg— segmentation primitives.
The OpenCV Java sources themselves are not vendored: they are pulled at build time from the opencv:sources
artifact, unpacked into target/sources-import, and added as an extra source root via
build-helper-maven-plugin.
- Formatter: google-java-format via Spotless.
- License header (EPL-2.0 OR Apache-2.0) is enforced by Spotless on every Java file.
- Tests use JUnit 6 (
org.junit.jupiter.*) and Mockito.
Dual-licensed under the Eclipse Public License v2.0 and the Apache License v2.0.