OpenCV with Scala

OpenCV with Scala

I started with the official site of OpenCV.

Then, I clicked on the link:

I chose the easy way that was described there and downloaded an archive from SourceForge:

After extracting it, I created a folder named "build" and changed into it.

Next, I set the JAVA_HOME variable and generated a Makefile with CMake, which I already had in my system.

> sudo update-alternatives --config java
There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-17-openjdk-amd64/bin/java
> export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-amd64

In the output of the last command Java was present among the modules to be built.

--   OpenCV modules:
--     To be built:                 calib3d core dnn features2d flann gapi highgui imgcodecs imgproc java ml objdetect photo stitching ts video videoio

Then, I built the library utilizing all 16 processor cores of my computer.

> make -j16

When the build process was finished, I found a JAR-file in the build/bin directory.

I added it into the lib dirctory of my SBT-project as unmanaged dependency.

I copied the shared library from build/lib into /usr/lib.

I added it into my IDEA IDE as well.

File -> Project Settings -> Modules -> Dependencies -> + -> JAR Files

Now I've got all the functions of OpenCV in Scala.

import org.opencv.core.Core

@main def helloCV: Unit =