Issue
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:
- Go to (file -> project structure -> modules)
- Clicked on + sign
- Selected (library -> java)
- Selected that opencv-480.jar
- Clicked on apply and then ok
Above steps added jar file. Then I added library path by doing:
- Go to (file -> project structure -> libraries)
- Clicked on recently added library (opencv-480)
- Then in right panel, I clicked on + sign
- Selected lib folder which I got after installation of openCV
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.
Solution
I've solved above issue. What I've done is:
- Made a opencv_lib folder in root.
- Put opencv-480.jar file in this opencv_lib folder.
- Made another native_libs folder inside opencv_lib folder.
- Put files of lib folder (which I got after installing opencv) into that native_libs folder.
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.
Answered By - Zaryab Ali
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.