I was trying to use openCV in Intellij Idea (scala), for that I've downloaded openCV from their official website - and after installing openCV I got opencv-480.jar file in build/bin. For installation I have done (in Ubuntu):
$ sudo apt update && sudo apt install -y cmake g++ wget unzip
$ wget -O opencv.zip https://github.com/opencv/opencv/archive/4.x.zip
$ unzip opencv.zip
$ mkdir -p build && cd build
$ cmake ../opencv-4.x
$ make -j4
$ sudo make install
Then I've opened my Intellij Idea and performed following steps:
Above steps added jar file. Then I added library path by doing:
After all above, now I'm able to access and use openCV in my scala project.
But the problem is whenever I clean the project and run in sbt-shell, it removes that jar file from project structure. Now I want to add that external jar file and setting of lib folder path via build.sbt - but I'm not able to find any help on this.
Guide me how can I add external jar file and use it as dependency in build.sbt.
I've solved above issue. What I've done is:
Then at last added some lines in build.sbt, my project's build.sbt is:
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / scalaVersion := "2.13.4"
lazy val root = (project in file("."))
.settings(
name := "OpenCV-Check"
)
run / fork := true
unmanagedBase := baseDirectory.value / "opencv_lib"
val openCVNativeLibPath = file("opencv_lib/native_libs")
run / javaOptions += s"-Djava.library.path=${openCVNativeLibPath.getAbsolutePath}"
Then I build the project and it worked for me.
https://www.scala-sbt.org/release/docs/Library-Dependencies.html
Above linked helped me. Thanks to Gael J for that link.