I'm new to openCV, I want to use openCV in Intellij IDEA (Scala) to detect image blurriness.
I'm using library dependency openpnp-opencv
Here is versions detail.
Ubuntu version 22.04.3 LTS
scala version 12.13.1
sbt version 1.9.6
here is my build.sbt
ThisBuild / version := "0.1.0-SNAPSHOT"
ThisBuild / scalaVersion := "2.13.4"
lazy val root = (project in file("."))
.settings(
name := "FaceRecognitionAndComparison"
)
libraryDependencies ++= Seq("org.openpnp" % "opencv" % "4.5.1-1")
here is my FaceRecognition.scala
import org.opencv.core.{Core, CvType, Mat, MatOfDouble}
import org.opencv.imgcodecs.Imgcodecs
import org.opencv.imgproc.Imgproc
object FaceRecognition extends App {
def isImageBlurry(imagePath: String): Boolean = {
val image: Mat = Imgcodecs.imread(imagePath)
val grayImage: Mat = new Mat()
Imgproc.cvtColor(image, grayImage, Imgproc.COLOR_BGR2GRAY)
val laplacian: Mat = new Mat()
Imgproc.Laplacian(grayImage, laplacian, CvType.CV_64F)
println(laplacian)
val meanStdDevResult: MatOfDouble = new MatOfDouble()
val stdDev: Double = meanStdDevResult.toArray()(1)
val threshold: Double = 100.0
stdDev < threshold
}
System.loadLibrary(Core.NATIVE_LIBRARY_NAME)
val imagePath = "/home/Pictures/Screenshots/Screenshot.png"
if (isImageBlurry(imagePath)) {
println("The image is blurry.")
} else {
println("The image is not blurry.")
}
}
Build unfortunately got an error
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.imgcodecs.Imgcodecs.imread_1(Ljava/lang/String;)J
at org.opencv.imgcodecs.Imgcodecs.imread_1(Native Method)
at org.opencv.imgcodecs.Imgcodecs.imread(Imgcodecs.java:320)
at FaceRecognition$.isImageBlurry(FaceRecognition.scala:65)
what I have tried is to download and install openCV from it's official website which is https://docs.opencv.org/4.x/d7/d9f/tutorial_linux_install.html.
After that I added following lines in my code to load jar file System.load("/home/build/bin/opencv-480.jar") but this didn't resolve my issue.
Then I added jar file in project module (file -> Project Structure -> Modules -> Click on plus -> add opencv-480.jar -> apply -> OK), this time I got an error which is
Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java470 in java.library.path: [/usr/java/packages/lib, /usr/lib64, /lib64, /lib, /usr/lib]
at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2662)
at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:827)
at java.base/java.lang.System.loadLibrary(System.java:1871)
at FaceRecognition$.delayedEndpoint$FaceRecognition$1(FaceRecognition.scala:83)
Guide me how can I resolve this error and implement openCV in (Intellij IDEA) scala.