diff --git a/FlyCapture2-demo/build.sbt b/FlyCapture2-demo/build.sbt index 39e526d..c9ceac1 100644 --- a/FlyCapture2-demo/build.sbt +++ b/FlyCapture2-demo/build.sbt @@ -3,25 +3,25 @@ import sbt.Keys._ name := "FlyCapture2-demo" -version := "1.3.6" +version := "1.5" -scalaVersion := "2.12.7" +scalaVersion := "2.12.8" // Platform classifier for native library dependencies lazy val platform = org.bytedeco.javacpp.Loader.getPlatform // @formatter:off val commonSettings = Seq( - scalaVersion := "2.12.7", + scalaVersion := "2.12.8", scalacOptions ++= Seq("-unchecked", "-deprecation", "-Xlint", "-explaintypes"), // Some dependencies like `javacpp` are packaged with maven-plugin packaging classpathTypes += "maven-plugin", libraryDependencies ++= Seq( - "org.bytedeco.javacpp-presets" % "flycapture" % "2.11.3.121-1.4.3" classifier "", - "org.bytedeco.javacpp-presets" % "flycapture" % "2.11.3.121-1.4.3" classifier platform, - "log4j" % "log4j" % "1.2.17", - "org.scala-lang" % "scala-reflect" % scalaVersion.value, - "org.scala-lang.modules" %% "scala-parser-combinators" % "1.1.1", + "org.bytedeco" % "flycapture" % "2.13.3.31-1.5" classifier "", + "org.bytedeco" % "flycapture" % "2.13.3.31-1.5" classifier platform, + "log4j" % "log4j" % "1.2.17", + "org.scala-lang" % "scala-reflect" % scalaVersion.value, + "org.scala-lang.modules" %% "scala-parser-combinators" % "1.1.2", ), resolvers ++= Seq( // Resolver.sonatypeRepo("snapshots"), @@ -35,15 +35,26 @@ val commonSettings = Seq( javaOptions += "-Xmx1G" ) +// Determine OS version of JavaFX binaries +lazy val osName = System.getProperty("os.name") match { + case n if n.startsWith("Linux") => "linux" + case n if n.startsWith("Mac") => "mac" + case n if n.startsWith("Windows") => "win" + case _ => throw new Exception("Unknown platform!") +} + +lazy val javaFXModules = Seq("base", "controls", "fxml", "graphics", "media", "swing", "web") + val uiSettings = commonSettings ++ Seq( libraryDependencies ++= Seq( - "org.clapper" %% "grizzled-slf4j" % "1.3.2", - "org.slf4j" % "slf4j-api" % "1.7.25", - "org.slf4j" % "slf4j-log4j12" % "1.7.25", - "org.scalafx" %% "scalafx" % "8.0.181-R13", + "org.clapper" %% "grizzled-slf4j" % "1.3.3", + "org.slf4j" % "slf4j-api" % "1.7.26", + "org.slf4j" % "slf4j-log4j12" % "1.7.26", + "org.scalafx" %% "scalafx" % "11-R16", "org.scalafx" %% "scalafxml-core-sfx8" % "0.4", - "org.scalafx" %% "scalafx-extras" % "0.2.0" + "org.scalafx" %% "scalafx-extras" % "0.3.0" ), + libraryDependencies ++= javaFXModules.map(m => "org.openjfx" % s"javafx-$m" % "11.0.2" classifier osName), addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.1" cross CrossVersion.full) ) diff --git a/FlyCapture2-demo/check_macro/src/main/scala/flycapture/CheckMacro.scala b/FlyCapture2-demo/check_macro/src/main/scala/flycapture/CheckMacro.scala index 35c69fe..4440420 100644 --- a/FlyCapture2-demo/check_macro/src/main/scala/flycapture/CheckMacro.scala +++ b/FlyCapture2-demo/check_macro/src/main/scala/flycapture/CheckMacro.scala @@ -1,12 +1,12 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ package flycapture -import org.bytedeco.javacpp.FlyCapture2.Error +import org.bytedeco.flycapture.FlyCapture2.Error import scala.collection.mutable import scala.language.experimental.macros @@ -139,7 +139,7 @@ class CheckMacro(val c: blackbox.Context) { val result = q""" ..${tempVars.map(_.decl)} - if( $transformed.GetType() != org.bytedeco.javacpp.FlyCapture2.PGRERROR_OK ) { + if( $transformed.GetType() != org.bytedeco.flycapture.global.FlyCapture2.PGRERROR_OK ) { val errorDesc = $transformed.GetDescription().getString val printedCode = ${show(expr)} val printedValues = List(..${tempVars.map(_.debug)}) diff --git a/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/FC2Exception.scala b/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/FC2Exception.scala index e9f810e..3c5dd6c 100644 --- a/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/FC2Exception.scala +++ b/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/FC2Exception.scala @@ -1,10 +1,10 @@ /* - * Copyright (c) 2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ package flycapture.examples.cpp -import org.bytedeco.javacpp.FlyCapture2.Error +import org.bytedeco.flycapture.FlyCapture2._ class FC2Exception(message: String, val error: Error) extends Exception(message: String) diff --git a/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/FC2Utils.scala b/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/FC2Utils.scala index 043ada9..9ce9294 100644 --- a/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/FC2Utils.scala +++ b/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/FC2Utils.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -7,23 +7,20 @@ package flycapture.examples.cpp import flycapture.CheckMacro._ +import org.bytedeco.flycapture.FlyCapture2._ +import org.bytedeco.flycapture.global.FlyCapture2._ import org.bytedeco.javacpp -import org.bytedeco.javacpp.FlyCapture2._ import org.bytedeco.javacpp.{FloatPointer, IntPointer} /** - * Some helper methods extracted from FlyCapture2 SDK sample application. - * Arguments and return values and input arguments are modified to fit Scala style. - * Method names correspond to the original names - * - * @author Jarek Sacha - */ + * Some helper methods extracted from FlyCapture2 SDK sample application. + * Arguments and return values and input arguments are modified to fit Scala style. + * Method names correspond to the original names + * + * @author Jarek Sacha + */ object FC2Utils { - case class Dimension(rows: Int, columns: Int) - - case class ResolutionAndPixelFormat(rows: Int, columns: Int, pixelFormat: Int) - def getCamResolutionAndPixelFormat(camera: CameraBase): ResolutionAndPixelFormat = { // get the current source-image settings @@ -100,7 +97,6 @@ object FC2Utils { case _ => None } - private def getDimensionsFromVideoMode(videoMode: Int): Option[Dimension] = videoMode match { case VIDEOMODE_160x120YUV444 => Some(Dimension(columns = 160, rows = 120)) @@ -120,4 +116,8 @@ object FC2Utils { case _ => None } + + case class Dimension(rows: Int, columns: Int) + + case class ResolutionAndPixelFormat(rows: Int, columns: Int, pixelFormat: Int) } diff --git a/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/CameraConfiguration.scala b/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/CameraConfiguration.scala index 64316f9..483e76e 100644 --- a/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/CameraConfiguration.scala +++ b/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/CameraConfiguration.scala @@ -1,17 +1,17 @@ /* - * Copyright (c) 2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ package flycapture.examples.cpp.snap -import org.bytedeco.javacpp.FlyCapture2.CameraBase - -import scala.reflect.runtime.universe.typeOf +import org.bytedeco.flycapture.FlyCapture2._ import scalafx.scene.Parent import scalafx.stage.Stage +import scala.reflect.runtime.universe.typeOf + /** * Create camera configuration UI. * diff --git a/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/CameraConfigurationModel.scala b/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/CameraConfigurationModel.scala index b3b160a..49cd1c2 100644 --- a/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/CameraConfigurationModel.scala +++ b/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/CameraConfigurationModel.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -7,13 +7,13 @@ package flycapture.examples.cpp.snap import java.util.concurrent.atomic.AtomicBoolean -import javafx.{concurrent => jfxc} import flycapture.CheckMacro.check import flycapture.examples.cpp.FC2Exception -import org.bytedeco.javacpp.FlyCapture2._ +import javafx.{concurrent => jfxc} +import org.bytedeco.flycapture.FlyCapture2._ +import org.bytedeco.flycapture.global.FlyCapture2._ import org.bytedeco.javacpp.IntPointer - import scalafx.Includes._ import scalafx.beans.property.{BooleanProperty, ObjectProperty} import scalafx.geometry.Pos diff --git a/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/CameraConfigurationView.scala b/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/CameraConfigurationView.scala index 2aa35d7..7238c3f 100644 --- a/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/CameraConfigurationView.scala +++ b/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/CameraConfigurationView.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -7,7 +7,6 @@ package flycapture.examples.cpp.snap import flycapture.examples.cpp.snap.CameraConfigurationModel.TestPattern - import scalafx.Includes._ import scalafx.scene.control.{CheckBox, RadioButton, ToggleGroup} import scalafx.scene.layout.GridPane diff --git a/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/CameraID.scala b/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/CameraID.scala index 75f07b2..26059ca 100644 --- a/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/CameraID.scala +++ b/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/CameraID.scala @@ -1,18 +1,18 @@ /* - * Copyright (c) 2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ package flycapture.examples.cpp.snap -import org.bytedeco.javacpp.FlyCapture2.{CameraInfo, PGRGuid} +import org.bytedeco.flycapture.FlyCapture2._ /** - * Basic camera information. - * - * @author Jarek Sacha - */ + * Basic camera information. + * + * @author Jarek Sacha + */ case class CameraID(guid: PGRGuid, cameraInfo: CameraInfo) { override def toString = s"#${cameraInfo.serialNumber} (${cameraInfo.modelName.getString})" } diff --git a/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/CameraSelectionModel.scala b/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/CameraSelectionModel.scala index 070e3c9..222f176 100644 --- a/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/CameraSelectionModel.scala +++ b/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/CameraSelectionModel.scala @@ -1,27 +1,25 @@ /* - * Copyright (c) 2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ package flycapture.examples.cpp.snap -import javafx.scene.control.MultipleSelectionModel - import flycapture.CheckMacro.check import grizzled.slf4j.Logger -import org.bytedeco.javacpp.FlyCapture2._ - +import javafx.scene.control.MultipleSelectionModel +import org.bytedeco.flycapture.FlyCapture2._ import scalafx.Includes._ import scalafx.beans.property.{IntegerProperty, ObjectProperty, StringProperty} import scalafx.collections.ObservableBuffer import scalafx.event.subscriptions.Subscription /** - * Model for camera selection UI. - * - * @author Jarek Sacha - */ + * Model for camera selection UI. + * + * @author Jarek Sacha + */ class CameraSelectionModel(busManager: BusManager) { // TODO automatically update list of cameras when cameras are connected/disconnected diff --git a/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/CameraSelectionView.scala b/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/CameraSelectionView.scala index 703314e..9923551 100644 --- a/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/CameraSelectionView.scala +++ b/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/CameraSelectionView.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -7,7 +7,6 @@ package flycapture.examples.cpp.snap import javafx.beans.{binding => jfxbb} - import scalafx.Includes._ import scalafx.scene.control._ import scalafxml.core.macros.sfxml diff --git a/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/FlyCaptureSnapApp.scala b/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/FlyCaptureSnapApp.scala index 562a723..4ca51f2 100644 --- a/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/FlyCaptureSnapApp.scala +++ b/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/FlyCaptureSnapApp.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -10,8 +10,6 @@ import java.io.IOException import grizzled.slf4j.Logger import org.apache.log4j.Level - -import scala.reflect.runtime.universe.typeOf import scalafx.Includes._ import scalafx.application.JFXApp.PrimaryStage import scalafx.application.{JFXApp, Platform} @@ -19,6 +17,8 @@ import scalafx.scene.Scene import scalafx.scene.image.Image import scalafxml.core.{DependenciesByType, FXMLView} +import scala.reflect.runtime.universe.typeOf + /** * `FlyCaptureSnapApp` starts the FlyCaptureSnap application. * diff --git a/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/SnapModel.scala b/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/SnapModel.scala index d625776..1790f16 100644 --- a/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/SnapModel.scala +++ b/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/SnapModel.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -8,16 +8,15 @@ package flycapture.examples.cpp.snap import java.io.{File, IOException} import java.util.concurrent.locks.ReentrantReadWriteLock -import javafx.{concurrent => jfxc} import flycapture.CheckMacro.check import flycapture.examples.cpp.FC2Exception import flycapture.examples.cpp.FC2Utils._ import grizzled.slf4j.Logger -import org.bytedeco.javacpp.FlyCapture2._ +import javafx.{concurrent => jfxc} +import org.bytedeco.flycapture.FlyCapture2._ +import org.bytedeco.flycapture.global.FlyCapture2._ import org.bytedeco.javacpp.{IntPointer, Pointer} - -import scala.reflect.runtime.universe.typeOf import scalafx.Includes._ import scalafx.application.Platform import scalafx.beans.property.{BooleanProperty, ObjectProperty, StringProperty} @@ -32,6 +31,8 @@ import scalafx.stage.{FileChooser, Stage} import scalafx.util.Duration import scalafxml.core.{DependenciesByType, FXMLView} +import scala.reflect.runtime.universe.typeOf + object SnapModel { diff --git a/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/package.scala b/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/package.scala index ec63a25..acbcc45 100644 --- a/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/package.scala +++ b/FlyCapture2-demo/example_ui/src/main/scala/flycapture/examples/cpp/snap/package.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -11,8 +11,6 @@ import java.util.concurrent import grizzled.slf4j.Logger import org.apache.log4j.{BasicConfigurator, Level} - -import scala.reflect.runtime.universe._ import scalafx.Includes._ import scalafx.application.Platform import scalafx.scene.Parent @@ -22,6 +20,8 @@ import scalafx.scene.layout.{GridPane, Priority} import scalafx.stage.Window import scalafxml.core.{DependenciesByType, FXMLView} +import scala.reflect.runtime.universe._ + /** * @author Jarek Sacha */ diff --git a/FlyCapture2-demo/example_ui/src/test/scala/flycapture/examples/cpp/snap/CameraConfigurationViewDemo.scala b/FlyCapture2-demo/example_ui/src/test/scala/flycapture/examples/cpp/snap/CameraConfigurationViewDemo.scala index 9490315..181aa9d 100644 --- a/FlyCapture2-demo/example_ui/src/test/scala/flycapture/examples/cpp/snap/CameraConfigurationViewDemo.scala +++ b/FlyCapture2-demo/example_ui/src/test/scala/flycapture/examples/cpp/snap/CameraConfigurationViewDemo.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,19 +9,20 @@ package flycapture.examples.cpp.snap import flycapture.CheckMacro.check import grizzled.slf4j.Logger import org.apache.log4j.Level -import org.bytedeco.javacpp.FlyCapture2.{BusManager, Camera, PGRGuid} - +import org.bytedeco.flycapture.FlyCapture2._ import scalafx.application.JFXApp.PrimaryStage import scalafx.application.{JFXApp, Platform} import scalafx.scene.Scene /** - * @author Jarek Sacha - */ + * @author Jarek Sacha + */ object CameraConfigurationViewDemo extends JFXApp { - private val logger = Logger(this.getClass) + lazy val title = "Fly Capture CameraConfiguration Demo" initializeLogging(Level.INFO) + + private val logger = Logger(this.getClass) setupUncaughtExceptionHandling(logger, title) private val busMgr = new BusManager() @@ -36,9 +37,6 @@ object CameraConfigurationViewDemo extends JFXApp { private val cam = new Camera() check(cam.Connect(guid)) - - lazy val title = "Fly Capture CameraConfiguration Demo" - try { val cameraConfiguration = new CameraConfiguration(cam, null) @@ -54,6 +52,7 @@ object CameraConfigurationViewDemo extends JFXApp { Platform.exit() } + override def stopApp(): Unit = { super.stopApp() diff --git a/FlyCapture2-demo/example_ui/src/test/scala/flycapture/examples/cpp/snap/CameraSelectionViewDemo.scala b/FlyCapture2-demo/example_ui/src/test/scala/flycapture/examples/cpp/snap/CameraSelectionViewDemo.scala index 4d7552a..e6b39dd 100644 --- a/FlyCapture2-demo/example_ui/src/test/scala/flycapture/examples/cpp/snap/CameraSelectionViewDemo.scala +++ b/FlyCapture2-demo/example_ui/src/test/scala/flycapture/examples/cpp/snap/CameraSelectionViewDemo.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -8,16 +8,16 @@ package flycapture.examples.cpp.snap import grizzled.slf4j.Logger import org.apache.log4j.Level -import org.bytedeco.javacpp.FlyCapture2.BusManager - -import scala.reflect.runtime.universe.typeOf +import org.bytedeco.flycapture.FlyCapture2._ import scalafx.application.JFXApp.PrimaryStage import scalafx.application.{JFXApp, Platform} import scalafx.scene.Scene +import scala.reflect.runtime.universe.typeOf + /** - * @author Jarek Sacha - */ + * @author Jarek Sacha + */ object CameraSelectionViewDemo extends JFXApp { lazy val title = "Fly Capture CameraSelectionView Demo" diff --git a/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/c/FlyCapture2Test_C.scala b/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/c/FlyCapture2Test_C.scala index 1f6f755..994def2 100644 --- a/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/c/FlyCapture2Test_C.scala +++ b/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/c/FlyCapture2Test_C.scala @@ -1,10 +1,12 @@ /* - * Copyright (c) 2014 Jarek Sacha. All Rights Reserved. - * Author's e-mail: jpsacha at gmail dot com + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. + * + * Author's e-mail: jpsacha at gmail.com */ package flycapture.examples.c -import org.bytedeco.javacpp.FlyCapture2_C._ +import org.bytedeco.flycapture.FlyCapture2_C._ +import org.bytedeco.flycapture.global.FlyCapture2_C._ /** * Example of using FlyCapture2 C API. diff --git a/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/BusEventEx.scala b/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/BusEventEx.scala index 784960e..d20121d 100644 --- a/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/BusEventEx.scala +++ b/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/BusEventEx.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -8,7 +8,8 @@ package flycapture.examples.cpp import java.util.Date -import org.bytedeco.javacpp.FlyCapture2._ +import org.bytedeco.flycapture.FlyCapture2._ +import org.bytedeco.flycapture.global.FlyCapture2._ import org.bytedeco.javacpp.{IntPointer, Pointer} import scala.io.StdIn.readLine diff --git a/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/CameraPropertyInfoEx.scala b/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/CameraPropertyInfoEx.scala index dd18b9d..a299fe8 100644 --- a/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/CameraPropertyInfoEx.scala +++ b/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/CameraPropertyInfoEx.scala @@ -1,11 +1,14 @@ /* - * Copyright (c) 2014 Jarek Sacha. All Rights Reserved. - * Author's e-mail: jpsacha at gmail dot com + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. + * + * Author's e-mail: jpsacha at gmail.com */ package flycapture.examples.cpp import flycapture.CheckMacro.check -import org.bytedeco.javacpp.FlyCapture2._ +import org.bytedeco.flycapture.FlyCapture2.{BusManager, Camera, CameraInfo, PGRGuid} +//import org.bytedeco.flycapture.FlyCapture2._ +//import org.bytedeco.flycapture.global.FlyCapture2._ /** * The CameraPropertyInfoEx prints out property information from attached cameras. diff --git a/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/ExtendedShutterEx.scala b/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/ExtendedShutterEx.scala index c43682f..1934a36 100644 --- a/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/ExtendedShutterEx.scala +++ b/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/ExtendedShutterEx.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -7,7 +7,8 @@ package flycapture.examples.cpp import flycapture.CheckMacro.check -import org.bytedeco.javacpp.FlyCapture2._ +import org.bytedeco.flycapture.FlyCapture2._ +import org.bytedeco.flycapture.global.FlyCapture2._ import org.bytedeco.javacpp.IntPointer /** diff --git a/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/FC2Exception.scala b/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/FC2Exception.scala index 5483e45..3c5dd6c 100644 --- a/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/FC2Exception.scala +++ b/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/FC2Exception.scala @@ -1,9 +1,10 @@ /* - * Copyright (c) 2014 Jarek Sacha. All Rights Reserved. - * Author's e-mail: jpsacha at gmail dot com + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. + * + * Author's e-mail: jpsacha at gmail.com */ package flycapture.examples.cpp -import org.bytedeco.javacpp.FlyCapture2.Error +import org.bytedeco.flycapture.FlyCapture2._ class FC2Exception(message: String, val error: Error) extends Exception(message: String) diff --git a/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/FlyCapture2Test.scala b/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/FlyCapture2Test.scala index 71416dd..47252e7 100644 --- a/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/FlyCapture2Test.scala +++ b/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/FlyCapture2Test.scala @@ -1,12 +1,13 @@ /* - * Copyright (c) 2014 Jarek Sacha. All Rights Reserved. - * Author's e-mail: jpsacha at gmail dot com + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. + * + * Author's e-mail: jpsacha at gmail.com */ package flycapture.examples.cpp -import flycapture.CheckMacro -import org.bytedeco.javacpp.FlyCapture2._ -import CheckMacro.check +import flycapture.CheckMacro.check +import org.bytedeco.flycapture.FlyCapture2._ +import org.bytedeco.flycapture.global.FlyCapture2._ /** * The FlyCapture2Test sample program is a simple program designed to report information related to all compatible diff --git a/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/GrabCallbackEx.scala b/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/GrabCallbackEx.scala index 9e387ea..ad0cfff 100644 --- a/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/GrabCallbackEx.scala +++ b/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/GrabCallbackEx.scala @@ -1,12 +1,13 @@ /* - * Copyright (c) 2014 Jarek Sacha. All Rights Reserved. - * Author's e-mail: jpsacha at gmail dot com + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. + * + * Author's e-mail: jpsacha at gmail.com */ package flycapture.examples.cpp -import flycapture.CheckMacro import flycapture.CheckMacro.check -import org.bytedeco.javacpp.FlyCapture2._ +import org.bytedeco.flycapture.FlyCapture2._ +import org.bytedeco.flycapture.global.FlyCapture2._ import org.bytedeco.javacpp.Pointer /** diff --git a/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/SoftwareTriggerEx.scala b/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/SoftwareTriggerEx.scala index 6e9bfdd..21bb0c8 100644 --- a/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/SoftwareTriggerEx.scala +++ b/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/SoftwareTriggerEx.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -7,7 +7,8 @@ package flycapture.examples.cpp import flycapture.CheckMacro.check -import org.bytedeco.javacpp.FlyCapture2._ +import org.bytedeco.flycapture.FlyCapture2._ +import org.bytedeco.flycapture.global.FlyCapture2._ import org.bytedeco.javacpp.IntPointer import scala.io.StdIn.readLine diff --git a/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/package.scala b/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/package.scala index 5eb7065..9dfa5d9 100644 --- a/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/package.scala +++ b/FlyCapture2-demo/examples/src/main/scala/flycapture/examples/cpp/package.scala @@ -1,12 +1,13 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ package flycapture.examples import flycapture.CheckMacro.check -import org.bytedeco.javacpp.FlyCapture2._ +import org.bytedeco.flycapture.FlyCapture2._ +import org.bytedeco.flycapture.global.FlyCapture2._ /** * Helper functions for C++ API examples. diff --git a/FlyCapture2-demo/examples/src/test/scala/flycapture/CheckOverheadBenchmark.scala b/FlyCapture2-demo/examples/src/test/scala/flycapture/CheckOverheadBenchmark.scala index 0382abd..c23ee38 100644 --- a/FlyCapture2-demo/examples/src/test/scala/flycapture/CheckOverheadBenchmark.scala +++ b/FlyCapture2-demo/examples/src/test/scala/flycapture/CheckOverheadBenchmark.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -7,8 +7,9 @@ package flycapture import flycapture.CheckMacro._ -import org.bytedeco.javacpp.FlyCapture2.BusManager -import org.bytedeco.javacpp.{FlyCapture2, IntPointer} +import org.bytedeco.flycapture.FlyCapture2._ +import org.bytedeco.flycapture.global.FlyCapture2._ +import org.bytedeco.javacpp.IntPointer import scala.math.min @@ -67,7 +68,7 @@ object CheckOverheadBenchmark extends App { val t0 = System.nanoTime() for (_ <- 0 until nbIterations) { - if (busMgr.GetNumOfCameras(numCameras).GetType() != FlyCapture2.PGRERROR_OK) { + if (busMgr.GetNumOfCameras(numCameras).GetType() != PGRERROR_OK) { throw new Exception("Error in ...") } } diff --git a/FlyCapture2-demo/project/build.properties b/FlyCapture2-demo/project/build.properties index 4c31ed2..e2820dd 100644 --- a/FlyCapture2-demo/project/build.properties +++ b/FlyCapture2-demo/project/build.properties @@ -1,2 +1,2 @@ -sbt.version=1.2.6 +sbt.version=1.2.8 diff --git a/FlyCapture2-demo/project/plugin.sbt b/FlyCapture2-demo/project/plugin.sbt index 1356235..723b86b 100644 --- a/FlyCapture2-demo/project/plugin.sbt +++ b/FlyCapture2-demo/project/plugin.sbt @@ -5,6 +5,6 @@ classpathTypes += "maven-plugin" // javacpp `Loader` is used to determine `platform` classifier in the project`s `build.sbt` // We define dependency here (in folder `project`) since it is used by the build itself. -libraryDependencies += "org.bytedeco" % "javacpp" % "1.4.3" +libraryDependencies += "org.bytedeco" % "javacpp" % "1.5" diff --git a/OpenCV_Cookbook/README.md b/OpenCV_Cookbook/README.md index 9e06b69..b8d9429 100644 --- a/OpenCV_Cookbook/README.md +++ b/OpenCV_Cookbook/README.md @@ -6,13 +6,13 @@ OpenCV Cookbook Examples Overview -------- -**OpenCV Cookbook Examples** are JavaCV versions of the examples presented in the Robert Laganière's book "[OpenCV 2 Computer Vision Application Programming Cookbook](https://www.packtpub.com/application-development/opencv-3-computer-vision-application-programming-cookbook)". The examples in the book use [OpenCV](http://opencv.org/) C++ API. Here they are translated to use [JavaCV](https://github.com/bytedeco/javacv) and [JavaCPP-Presets](https://github.com/bytedeco/javacpp-presets) APIs. +**OpenCV Cookbook Examples** illustrate use of OpenCV with [JavaCV][javacv]. The Examples started as a port of C++ code from Robert Laganière's book "[OpenCV 2 Computer Vision Application Programming Cookbook](https://www.packtpub.com/application-development/opencv-2-computer-vision-application-programming-cookbook)". Later updated for the ssecond edition of the book "[OpenCV Computer Vision Application Programming Cookbook Second Edition](https://www.packtpub.com/application-development/opencv-3-computer-vision-application-programming-cookbook)". The examples in the book use [OpenCV](http://opencv.org/) C++ API. Here they are translated to use [JavaCV][javacv](https://github.com/bytedeco/javacv) and [JavaCPP-Presets](https://github.com/bytedeco/javacpp-presets) APIs. [OpenCV](http://opencv.org/) (Open Source Computer Vision) is a library of several hundred algorithms for computer vision and video analysis. OpenCV can be us on JVM using two approaches. First are Java [wrappers provided by OpenCV](http://docs.opencv.org/doc/tutorials/introduction/desktop_java/java_dev_intro.html). Second are are wrappers based on [JavaCPP](https://github.com/bytedeco/javacpp) (C++ wrapper engine for JVM) called [OpenCV JavaCPP Presets](https://github.com/bytedeco/javacpp-presets). There are also JavaCPP presets for other computer vision related libraries like: [FFmpeg](http://ffmpeg.org/), [libdc1394](http://damien.douxchamps.net/ieee1394/libdc1394/), [PGR FlyCapture](http://www.ptgrey.com/products/pgrflycapture/), [OpenKinect](http://openkinect.org/), [videoInput](http://muonics.net/school/spring05/videoInput/), [ARToolKitPlus](http://studierstube.icg.tugraz.at/handheld_ar/artoolkitplus.php), [flandmark](http://cmp.felk.cvut.cz/~uricamic/flandmark/), and [others](https://github.com/bytedeco/javacpp-presets). JavaCV combines libraries in JavaCPP Presets and add some additional functionality that makes them easier use on JVM. -The *OpenCV Cookbook Examples* project illustrates use of OpenCV through JavaCV and OpenCV JavaCPP Presets. Current version is updated to match the second edition of the Robert Laganière's book "[OpenCV 2 Computer Vision Application Programming Cookbook](https://www.packtpub.com/application-development/opencv-3-computer-vision-application-programming-cookbook)". It is intended for use with OpenCV v.3 (JavaCV v.1). +The *OpenCV Cookbook Examples* project illustrates use of OpenCV through JavaCV and OpenCV JavaCPP Presets. Current version is updated to match the second edition of the Robert Laganière's book "[OpenCV Computer Vision Application Programming Cookbook Second Edition](https://www.packtpub.com/application-development/opencv-3-computer-vision-application-programming-cookbook)". It is intended for use with OpenCV v.4 (JavaCV v.1). -While code in the examples is primarily written in [Scala](http://www.scala-lang.org), one of the leading JVM languages. It can be easily converted to Java and other languages running on JVM, for instance, [Groovy](http://groovy.codehaus.org/). The use of the JavaCV API is very similar in most HVM languages. +While code in the examples is primarily written in [Scala](http://www.scala-lang.org), one of the leading JVM languages. It can be easily converted to Java and other languages running on JVM, for instance, [Groovy](http://groovy.codehaus.org/). The use of the JavaCV API is very similar in most JVM languages. Some examples are provided in Java version. Quick Sample @@ -23,7 +23,8 @@ Here is a quick preview that compares an original C++ example with code in Scala Here is the original C++ example that opens an image (without error checking), creates a window, displays image in the window, and waits for 5 seconds before exiting. -``` c + +```cpp #include #include #include @@ -57,12 +58,13 @@ void display(Mat image, char* caption) { The above C++ example translated to Scala using JavaCV wrapper: -``` scala +```scala import javax.swing._ -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgcodecs._ -import org.bytedeco.javacpp.opencv_imgproc._ import org.bytedeco.javacv._ +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ object MyFirstOpenCVApp extends App { @@ -75,8 +77,9 @@ object MyFirstOpenCVApp extends App { Laplacian(src, dest, src.depth(), 1, 3, 0, BORDER_DEFAULT) display(dest, "Laplacian") -//--------------------------------------------------------------------------- + //--------------------------------------------------------------------------- + /** Display `image` with given `caption`. */ def display(image: Mat, caption: String): Unit = { // Create image window named "My Image." val canvas = new CanvasFrame(caption, 1) @@ -94,17 +97,16 @@ object MyFirstOpenCVApp extends App { Now the same example expressed in a Java. Note that use of JavaCV API is exactly the same in Scala and Java code. The only practical difference is that in Java code is more verbose, you have to explicitly provide type for each variable, in Scala it is optional. -``` java -import org.bytedeco.javacpp.opencv_core.Mat; +```java import org.bytedeco.javacv.CanvasFrame; import org.bytedeco.javacv.OpenCVFrameConverter; +import org.bytedeco.opencv.opencv_core.Mat; import javax.swing.*; -import static org.bytedeco.javacpp.opencv_core.BORDER_DEFAULT; -import static org.bytedeco.javacpp.opencv_imgcodecs.imread; -import static org.bytedeco.javacpp.opencv_imgproc.Laplacian; - +import static org.bytedeco.opencv.global.opencv_core.BORDER_DEFAULT; +import static org.bytedeco.opencv.global.opencv_imgcodecs.imread; +import static org.bytedeco.opencv.global.opencv_imgproc.Laplacian; public class MyFirstOpenCVAppInJava { @@ -120,7 +122,7 @@ public class MyFirstOpenCVAppInJava { display(dest, "Laplacian"); } -//--------------------------------------------------------------------------- + //--------------------------------------------------------------------------- static void display(Mat image, String caption) { // Create image window named "My Image". @@ -145,7 +147,7 @@ If you are looking for a particular OpenCV operation, use the [OpenCV documentat How to use JavaCV Examples -------------------------- -The *OpenCV Cookbook Examples* project is intended as a companion to the Robert Laganière's book "[OpenCV 2 Computer Vision Application Programming Cookbook](https://www.packtpub.com/application-development/opencv-3-computer-vision-application-programming-cookbook)". The recommended way is to read the Cookbook and refer to JavaCV examples when in doubt how to translate the Cookbook's C++ code to JavaCV. The Cookbook provides explanation how the algorithms work. The JavaCV examples provide only very brief comments related to specifics of JavaCV API. +The *OpenCV Cookbook Examples* project is intended as a companion to the Robert Laganière's book "[OpenCV Computer Vision Application Programming Cookbook Second Edition](https://www.packtpub.com/application-development/opencv-3-computer-vision-application-programming-cookbook)". The recommended way is to read the Cookbook and refer to JavaCV examples when in doubt how to translate the Cookbook's C++ code to JavaCV. The Cookbook provides explanation how the algorithms work. The JavaCV examples provide only very brief comments related to specifics of JavaCV API. Simplest way to use the JavaCV examples is to browse the code located in [src/main] online. You can also download it to you computer either use Git or as a ZIP file. @@ -260,4 +262,6 @@ Why Scala? Unlike Java or C++, Scala supports writing of scripts - code that can be executed without explicit compiling. Scala also has a console, called REPL, where single lines of code can be typed in and executed on a spot. Both of those features make prototyping of OpenCV-based programs easier in Scala than in Java. Last but not least, IDE support for Scala reached level of maturity allowing easy creation, modification, and execution of Scala code.In particular, the [Scala plugin](http://blog.jetbrains.com/scala/) for [JetBrains IDEA](http://www.jetbrains.com/idea/) works very well. There is also Scala support for [Eclipse](http://scala-ide.org/index.html) and [NetBeans](https://github.com/dcaoyuan/nbscala). -| [Next: Chapter 1>](src/main/scala/opencv_cookbook/chapter01) | \ No newline at end of file +| [Next: Chapter 1>](src/main/scala/opencv_cookbook/chapter01) | + +[javacv]: https://github.com/bytedeco/javacv \ No newline at end of file diff --git a/OpenCV_Cookbook/build.sbt b/OpenCV_Cookbook/build.sbt index 78b12c8..bc64a16 100644 --- a/OpenCV_Cookbook/build.sbt +++ b/OpenCV_Cookbook/build.sbt @@ -3,32 +3,35 @@ name := "opencv-cookbook" organization := "javacv.examples" -val javacppVersion = "1.4.3" +val javacppVersion = "1.5" version := javacppVersion -scalaVersion := "2.12.7" +scalaVersion := "2.12.8" scalacOptions ++= Seq("-unchecked", "-deprecation", "-Xlint") // Platform classifier for native library dependencies val platform = org.bytedeco.javacpp.Loader.getPlatform // Libraries with native dependencies val bytedecoPresetLibs = Seq( - "opencv" -> s"3.4.3-$javacppVersion", - "ffmpeg" -> s"4.0.2-$javacppVersion").flatMap { + "opencv" -> s"4.0.1-$javacppVersion", + "ffmpeg" -> s"4.1.3-$javacppVersion").flatMap { case (lib, ver) => Seq( // Add both: dependency and its native binaries for the current `platform` - "org.bytedeco.javacpp-presets" % lib % ver withSources() withJavadoc(), - "org.bytedeco.javacpp-presets" % lib % ver classifier platform + "org.bytedeco" % lib % ver withSources() withJavadoc(), + "org.bytedeco" % lib % ver classifier platform ) } libraryDependencies ++= Seq( "org.bytedeco" % "javacpp" % javacppVersion withSources() withJavadoc(), "org.bytedeco" % "javacv" % javacppVersion withSources() withJavadoc(), - "org.scala-lang.modules" %% "scala-swing" % "2.0.3", + "org.scala-lang.modules" %% "scala-swing" % "2.1.1", "junit" % "junit" % "4.12" % "test", "com.novocode" % "junit-interface" % "0.11" % "test" ) ++ bytedecoPresetLibs +resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots" +resolvers += Resolver.mavenLocal + autoCompilerPlugins := true // fork a new JVM for 'run' and 'test:run' diff --git a/OpenCV_Cookbook/project/build.properties b/OpenCV_Cookbook/project/build.properties index 4c31ed2..42d9077 100644 --- a/OpenCV_Cookbook/project/build.properties +++ b/OpenCV_Cookbook/project/build.properties @@ -1,2 +1,7 @@ -sbt.version=1.2.6 +# +# Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. +# +# Author's e-mail: jpsacha at gmail.com +# +sbt.version=1.2.8 diff --git a/OpenCV_Cookbook/project/plugins.sbt b/OpenCV_Cookbook/project/plugins.sbt index ea9fcc7..a5911d0 100644 --- a/OpenCV_Cookbook/project/plugins.sbt +++ b/OpenCV_Cookbook/project/plugins.sbt @@ -4,4 +4,4 @@ classpathTypes += "maven-plugin" // javacpp `Loader` is used to determine `platform` classifier in the project`s `build.sbt` // We define dependency here (in folder `project`) since it is used by the build itself. -libraryDependencies += "org.bytedeco" % "javacpp" % "1.4.3" +libraryDependencies += "org.bytedeco" % "javacpp" % "1.5" diff --git a/OpenCV_Cookbook/src/main/java/opencv_cookbook/OpenCVUtilsJava.java b/OpenCV_Cookbook/src/main/java/opencv_cookbook/OpenCVUtilsJava.java index 37956e0..5391c43 100644 --- a/OpenCV_Cookbook/src/main/java/opencv_cookbook/OpenCVUtilsJava.java +++ b/OpenCV_Cookbook/src/main/java/opencv_cookbook/OpenCVUtilsJava.java @@ -1,16 +1,21 @@ +/* + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. + * + * Author's e-mail: jpsacha at gmail.com + */ + package opencv_cookbook; -import org.bytedeco.javacpp.opencv_core; + import org.bytedeco.javacv.CanvasFrame; import org.bytedeco.javacv.OpenCVFrameConverter; +import org.bytedeco.opencv.opencv_core.Mat; import javax.swing.*; import java.awt.image.BufferedImage; import java.io.File; -import static org.bytedeco.javacpp.opencv_imgcodecs.IMREAD_COLOR; -import static org.bytedeco.javacpp.opencv_imgcodecs.imread; -import static org.bytedeco.javacpp.opencv_imgcodecs.imwrite; +import static org.bytedeco.opencv.global.opencv_imgcodecs.*; /** * Helper methods that simplify use of OpenCV API. @@ -21,7 +26,7 @@ public class OpenCVUtilsJava { * * @return loaded image */ - public opencv_core.Mat loadAndShowOrExit(File file){ + public Mat loadAndShowOrExit(File file) { return loadAndShowOrExit(file,IMREAD_COLOR); } @@ -38,8 +43,8 @@ public opencv_core.Mat loadAndShowOrExit(File file){ * Default is gray scale. * @return loaded image */ - public static opencv_core.Mat loadAndShowOrExit(File file, Integer flags){ - opencv_core.Mat image = loadOrExit(file, flags); + public static Mat loadAndShowOrExit(File file, Integer flags) { + Mat image = loadOrExit(file, flags); show(image,file.getName()); return image; } @@ -49,7 +54,7 @@ public static opencv_core.Mat loadAndShowOrExit(File file, Integer flags){ * * @return loaded image */ - public static opencv_core.Mat loadOrExit(File file) { + public static Mat loadOrExit(File file) { return loadOrExit(file,IMREAD_COLOR); } @@ -66,8 +71,8 @@ public static opencv_core.Mat loadOrExit(File file) { * Default is gray scale. * @return loaded image */ - public static opencv_core.Mat loadOrExit(File file, Integer flags) { - opencv_core.Mat image = imread(file.getAbsolutePath(), flags); + public static Mat loadOrExit(File file, Integer flags) { + Mat image = imread(file.getAbsolutePath(), flags); if(image.empty()){ System.out.println("Couldn't load image: " + file.getAbsolutePath()); System.exit(1); @@ -76,7 +81,7 @@ public static opencv_core.Mat loadOrExit(File file, Integer flags) { } /** Show image in a window. Closing the window will exit the application. */ - public static void show(opencv_core.Mat mat, String title) { + public static void show(Mat mat, String title) { OpenCVFrameConverter.ToMat converter = new OpenCVFrameConverter.ToMat(); CanvasFrame canvas = new CanvasFrame(title, 1); canvas.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); @@ -100,7 +105,7 @@ public static void show(BufferedImage image, String title) { * @param file file to save to. File name extension decides output image format. * @param image image to save. */ - public void save(File file, opencv_core.Mat image) { + public void save(File file, Mat image) { imwrite(file.getAbsolutePath(), image); } } diff --git a/OpenCV_Cookbook/src/main/java/opencv_cookbook/chapter01/Ex2MyFirstGUIAppJava.java b/OpenCV_Cookbook/src/main/java/opencv_cookbook/chapter01/Ex2MyFirstGUIAppJava.java index 7018cf1..5771af2 100644 --- a/OpenCV_Cookbook/src/main/java/opencv_cookbook/chapter01/Ex2MyFirstGUIAppJava.java +++ b/OpenCV_Cookbook/src/main/java/opencv_cookbook/chapter01/Ex2MyFirstGUIAppJava.java @@ -1,11 +1,14 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ package opencv_cookbook.chapter01; + +import org.bytedeco.opencv.opencv_core.Mat; + import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; @@ -14,11 +17,10 @@ import static javax.swing.JOptionPane.ERROR_MESSAGE; import static javax.swing.JOptionPane.showMessageDialog; import static opencv_cookbook.OpenCVUtils.toBufferedImage; -import static org.bytedeco.javacpp.opencv_core.Mat; -import static org.bytedeco.javacpp.opencv_core.flip; -import static org.bytedeco.javacpp.opencv_imgcodecs.imread; -import static org.bytedeco.javacpp.opencv_imgproc.COLOR_BGR2RGB; -import static org.bytedeco.javacpp.opencv_imgproc.cvtColor; +import static org.bytedeco.opencv.global.opencv_core.flip; +import static org.bytedeco.opencv.global.opencv_imgcodecs.imread; +import static org.bytedeco.opencv.global.opencv_imgproc.COLOR_BGR2RGB; +import static org.bytedeco.opencv.global.opencv_imgproc.cvtColor; /** diff --git a/OpenCV_Cookbook/src/main/java/opencv_cookbook/chapter04/Ex2ComputeHistogramGraphJava.java b/OpenCV_Cookbook/src/main/java/opencv_cookbook/chapter04/Ex2ComputeHistogramGraphJava.java index a511ddb..61ef33f 100644 --- a/OpenCV_Cookbook/src/main/java/opencv_cookbook/chapter04/Ex2ComputeHistogramGraphJava.java +++ b/OpenCV_Cookbook/src/main/java/opencv_cookbook/chapter04/Ex2ComputeHistogramGraphJava.java @@ -1,13 +1,21 @@ +/* + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. + * + * Author's e-mail: jpsacha at gmail.com + */ + package opencv_cookbook.chapter04; -import org.bytedeco.javacpp.opencv_core.Mat; + +import org.bytedeco.opencv.opencv_core.Mat; import java.awt.image.BufferedImage; import java.io.File; -import static opencv_cookbook.OpenCVUtils.loadAndShowOrExit; -import static opencv_cookbook.OpenCVUtils.show; -import static org.bytedeco.javacpp.opencv_imgcodecs.IMREAD_GRAYSCALE; +import static opencv_cookbook.OpenCVUtilsJava.loadAndShowOrExit; +import static opencv_cookbook.OpenCVUtilsJava.show; +import static org.opencv.imgcodecs.Imgcodecs.IMREAD_GRAYSCALE; + /** * The second example for section "Computing the image histogram" in Chapter 4, page 92. diff --git a/OpenCV_Cookbook/src/main/java/opencv_cookbook/chapter04/Histogram1DJava.java b/OpenCV_Cookbook/src/main/java/opencv_cookbook/chapter04/Histogram1DJava.java index 0117376..36a5f0c 100644 --- a/OpenCV_Cookbook/src/main/java/opencv_cookbook/chapter04/Histogram1DJava.java +++ b/OpenCV_Cookbook/src/main/java/opencv_cookbook/chapter04/Histogram1DJava.java @@ -1,14 +1,20 @@ +/* + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. + * + * Author's e-mail: jpsacha at gmail.com + */ + package opencv_cookbook.chapter04; import org.bytedeco.javacpp.FloatPointer; import org.bytedeco.javacpp.IntPointer; import org.bytedeco.javacpp.indexer.Indexer; -import org.bytedeco.javacpp.opencv_core.Mat; +import org.bytedeco.opencv.opencv_core.Mat; import java.awt.*; import java.awt.image.BufferedImage; -import static org.bytedeco.javacpp.opencv_imgproc.calcHist; +import static org.bytedeco.opencv.global.opencv_imgproc.calcHist; /** * Created by john on 16/08/16. diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/OpenCVUtils.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/OpenCVUtils.scala index 3d29932..15aee14 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/OpenCVUtils.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/OpenCVUtils.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -14,12 +14,13 @@ import java.nio.IntBuffer import javax.swing.WindowConstants import org.bytedeco.javacpp.indexer.FloatIndexer -import org.bytedeco.javacpp.opencv_core.{Point, _} -import org.bytedeco.javacpp.opencv_imgcodecs._ -import org.bytedeco.javacpp.opencv_imgproc._ import org.bytedeco.javacpp.{DoublePointer, IntPointer} import org.bytedeco.javacv.OpenCVFrameConverter.ToMat import org.bytedeco.javacv.{CanvasFrame, Java2DFrameConverter} +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core.{Point, _} import scala.math.round @@ -240,6 +241,7 @@ object OpenCVUtils { for (i <- 0 until size) dest(i) = new Point2f(indexer.get(0, i, 0), indexer.get(0, i, 1)) dest } + /** * Convert a vector of Point2f to a Mat representing a vector of Points2f. */ diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter01/Ex1MyFirstOpenCVApp.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter01/Ex1MyFirstOpenCVApp.scala index f271495..b4cb3b9 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter01/Ex1MyFirstOpenCVApp.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter01/Ex1MyFirstOpenCVApp.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -7,8 +7,8 @@ package opencv_cookbook.chapter01 import javax.swing.WindowConstants -import org.bytedeco.javacpp.opencv_imgcodecs._ import org.bytedeco.javacv.{CanvasFrame, OpenCVFrameConverter} +import org.bytedeco.opencv.global.opencv_imgcodecs._ /** diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter01/Ex2MyFirstGUIApp.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter01/Ex2MyFirstGUIApp.scala index a0ed830..ee6309d 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter01/Ex2MyFirstGUIApp.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter01/Ex2MyFirstGUIApp.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -8,12 +8,13 @@ package opencv_cookbook.chapter01 import java.awt.Cursor._ import java.io.File -import javax.swing.ImageIcon -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgcodecs._ -import org.bytedeco.javacpp.opencv_imgproc._ +import javax.swing.ImageIcon import org.bytedeco.javacv.{Java2DFrameConverter, OpenCVFrameConverter} +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ import scala.swing.Dialog.Message.Error import scala.swing.FileChooser.Result.Approve diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter01/Ex3LoadAndSave.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter01/Ex3LoadAndSave.scala index e692ab7..42a6e40 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter01/Ex3LoadAndSave.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter01/Ex3LoadAndSave.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -7,10 +7,11 @@ package opencv_cookbook.chapter01 import javax.swing.WindowConstants -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgcodecs._ -import org.bytedeco.javacpp.opencv_imgproc._ import org.bytedeco.javacv.{CanvasFrame, OpenCVFrameConverter} +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ /** * Example of reading, saving, displaying, and drawing on an image. diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter01/README.md b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter01/README.md index 719c005..251e766 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter01/README.md +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter01/README.md @@ -63,28 +63,40 @@ Make sure that you have Scala plugin installed, it provides support for SBT too. Loading, Displaying, and Saving Images with JavaCV -------------------------------------------------- -A simple example of loading and displaying an image using JavaCV is in class `opencv_cookbook.chapter01.Ex1MyFirstOpenCVApp`: +A simple example of loading and displaying an image using JavaCV is in class [`opencv_cookbook.chapter01.Ex1MyFirstOpenCVApp`: -``` scala -import javax.swing.JFrame - -import org.bytedeco.javacpp.opencv_imgcodecs._ +```scala +import javax.swing.WindowConstants import org.bytedeco.javacv.{CanvasFrame, OpenCVFrameConverter} +import org.bytedeco.opencv.global.opencv_imgcodecs._ + +/** + * Example of loading and displaying and image using JavaCV API, + * corresponds to C++ example in Chapter 1 page 18. + * Please note how in the Scala example code CanvasFrame from JavaCV API is used to display the image. + */ object Ex1MyFirstOpenCVApp extends App { // Read an image val image = imread("data/boldt.jpg") if (image.empty()) { + // error handling + // no image has been created... + // possibly display an error message + // and quit the application println("Error reading image...") System.exit(0) } // Create image window named "My Image". + // + // Note that you need to indicate to CanvasFrame not to apply gamma correction, + // by setting gamma to 1, otherwise the image will not look correct. val canvas = new CanvasFrame("My Image", 1) // Request closing of the application when the image window is closed - canvas.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) + canvas.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE) // Convert from OpenCV Mat to Java Buffered image for display val converter = new OpenCVFrameConverter.ToMat() @@ -102,12 +114,12 @@ JavaCV methods for loading images and saving images are based on based on OpenCV OpenCV has a couple of classes to represent images. Some are ore obsolete, like `IplImage` and `CvMat`. We will use the currently recommended `Mat`. -`Mat` images are loaded using method [`imread`](http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=imread#Mat%20imread%28const%20string&%20filename,%20int%20flags%29), it takes one or two parameters. The first one is a file name, the second is a conversion parameter, frequently used to load color images area gray scale. +`Mat` images are loaded using method `imread`, it takes one or two parameters. The first one is a file name, the second is a conversion parameter, frequently used to load color images area gray scale. Here are some examples. -``` scala -import org.bytedeco.javacpp.opencv_core.Mat -import org.bytedeco.javacpp.opencv_imgcodecs._ +```scala +import org.bytedeco.opencv.opencv_core.Mat +import org.bytedeco.opencv.global.opencv_imgcodecs._ val image1: Mat = imread("data/boldt.jpg") val image2: Mat = imread("data/boldt.jpg", IMREAD_COLOR) @@ -117,7 +129,7 @@ The default value for the conversion parameter is `IMREAD_COLOR`. If image cannot be loaded both `imread` will return `null`. You may want to wrap a call to `imread` in a method that throws an exception if an image cannot be loaded. -``` scala +```scala def load(file: File, flags: Int = IMREAD_GRAYSCALE): Mat = { // Verify file if (!file.exists()) { @@ -139,7 +151,7 @@ Saving Images The method `imwrite(filename, image)` saves the image to the specified file. The image format is chosen based on the filename extension. -``` scala +```scala imwrite("my_image.png", image1) ``` @@ -159,7 +171,7 @@ It is not an intention of this module to describe how to create GUI applications The example is using Scala Swing framework, which may be interesting in its own right. The framework enables writing a more concise Swing code, in this particular example Java core requires about 30% more characters to achieve the same result. -**Note:** The new GUI framework for building UIs is JavaFX. Working in scale you may consider [ScalaFX](http://scalafx.org) over Scala Swing. +**Note:** The new GUI framework for building UIs is JavaFX. Working in Scala you may consider [ScalaFX](http://scalafx.org) over Scala Swing. You can find code for the `Ex2MyFirstGUIApp` example [here](/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter01/Ex2MyFirstGUIApp.scala). For the sake of comparison an equivalent Java code is also [Ex2MyFirstGUIAppJava.java](/OpenCV_Cookbook/src/main/java/opencv_cookbook/chapter01/Ex2MyFirstGUIAppJava.java). diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter02/Ex1Salt.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter02/Ex1Salt.scala index 3afaf72..e186fcb 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter02/Ex1Salt.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter02/Ex1Salt.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -10,8 +10,8 @@ import java.io.File import opencv_cookbook.OpenCVUtils._ import org.bytedeco.javacpp.indexer.UByteIndexer -import org.bytedeco.javacpp.opencv_core.Mat -import org.bytedeco.javacpp.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ +import org.bytedeco.opencv.opencv_core._ import scala.util.Random diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter02/Ex2ColorReduce.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter02/Ex2ColorReduce.scala index 8cf14bf..7942a31 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter02/Ex2ColorReduce.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter02/Ex2ColorReduce.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -10,8 +10,8 @@ import java.io.File import opencv_cookbook.OpenCVUtils._ import org.bytedeco.javacpp.indexer.UByteIndexer -import org.bytedeco.javacpp.opencv_core.Mat -import org.bytedeco.javacpp.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ +import org.bytedeco.opencv.opencv_core._ /** diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter02/Ex3Sharpen.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter02/Ex3Sharpen.scala index b23b717..760914a 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter02/Ex3Sharpen.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter02/Ex3Sharpen.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -10,9 +10,10 @@ import java.io.File import opencv_cookbook.OpenCVUtils._ import org.bytedeco.javacpp.indexer.FloatIndexer -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgcodecs._ -import org.bytedeco.javacpp.opencv_imgproc._ +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ /** diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter02/Ex4BlendImages.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter02/Ex4BlendImages.scala index 42585e3..cb13c9f 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter02/Ex4BlendImages.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter02/Ex4BlendImages.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,8 +9,9 @@ package opencv_cookbook.chapter02 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ +import org.bytedeco.opencv.opencv_core._ /** diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter02/Ex5ROILogo.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter02/Ex5ROILogo.scala index 812f198..2544864 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter02/Ex5ROILogo.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter02/Ex5ROILogo.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,8 +9,8 @@ package opencv_cookbook.chapter02 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ +import org.bytedeco.opencv.opencv_core._ /** diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter03/ColorDetector.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter03/ColorDetector.scala index 5291dca..599fd62 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter03/ColorDetector.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter03/ColorDetector.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -7,9 +7,10 @@ package opencv_cookbook.chapter03 import org.bytedeco.javacpp.indexer.UByteIndexer -import org.bytedeco.javacpp.opencv_core.Mat +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.opencv_core._ -import scala.math._ +import scala.math.abs /** Example of using a strategy pattern in algorithm design. @@ -35,7 +36,7 @@ class ColorDetector(private var _minDist: Int = 100, def colorDistanceThreshold: Int = _minDist def colorDistanceThreshold_=(dist: Int) { - _minDist = max(0, dist) + _minDist = scala.math.max(0, dist) } def targetColor: ColorRGB = _target @@ -50,7 +51,7 @@ class ColorDetector(private var _minDist: Int = 100, val srcI = image.createIndexer().asInstanceOf[UByteIndexer] // Create output image and itx indexer - val dest = new Mat(image.rows, image.cols, org.bytedeco.javacpp.opencv_core.CV_8U) + val dest = new Mat(image.rows, image.cols, CV_8U) val destI = dest.createIndexer().asInstanceOf[UByteIndexer] // Iterate through pixels and check if their distance from the target color is diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter03/ColorDetectorController.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter03/ColorDetectorController.scala index 5f16730..3235761 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter03/ColorDetectorController.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter03/ColorDetectorController.scala @@ -1,13 +1,13 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ package opencv_cookbook.chapter03 -import org.bytedeco.javacpp.opencv_core.Mat -import org.bytedeco.javacpp.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ +import org.bytedeco.opencv.opencv_core._ /** diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter03/ColorDetectorLab.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter03/ColorDetectorLab.scala index 6e9f422..acc8cd7 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter03/ColorDetectorLab.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter03/ColorDetectorLab.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -7,8 +7,9 @@ package opencv_cookbook.chapter03 import org.bytedeco.javacpp.indexer.{UByteIndexer, UByteRawIndexer} -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgproc._ +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ import scala.math.abs diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter03/Ex1ColorDetector.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter03/Ex1ColorDetector.scala index a2e32ff..437e0f3 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter03/Ex1ColorDetector.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter03/Ex1ColorDetector.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,7 +9,7 @@ package opencv_cookbook.chapter03 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ /** * Example for section "Using the Strategy pattern in algorithm design" in Chapter 3. diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter03/Ex2ColorDetectorSimpleApplication.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter03/Ex2ColorDetectorSimpleApplication.scala index dd060f4..d85f813 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter03/Ex2ColorDetectorSimpleApplication.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter03/Ex2ColorDetectorSimpleApplication.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -8,10 +8,10 @@ package opencv_cookbook.chapter03 import java.awt.Cursor._ import java.io.File -import javax.swing.WindowConstants -import org.bytedeco.javacpp.opencv_core.Mat +import javax.swing.WindowConstants import org.bytedeco.javacv.{CanvasFrame, OpenCVFrameConverter} +import org.bytedeco.opencv.opencv_core._ import scala.swing.Dialog.Message.Error import scala.swing.FileChooser.Result.Approve diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter03/Ex3ColorDetectorMVCApplication.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter03/Ex3ColorDetectorMVCApplication.scala index 155bb8f..01f4e91 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter03/Ex3ColorDetectorMVCApplication.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter03/Ex3ColorDetectorMVCApplication.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -8,10 +8,10 @@ package opencv_cookbook.chapter03 import java.awt.Cursor._ import java.io.File -import javax.swing.{ImageIcon, JColorChooser} +import javax.swing.{ImageIcon, JColorChooser} import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_core.Mat +import org.bytedeco.opencv.opencv_core._ import scala.swing.Dialog.Message.Error import scala.swing.FileChooser.Result.Approve @@ -148,7 +148,7 @@ object Ex3ColorDetectorMVCApplication extends SimpleSwingApplication { */ def onSelectColor() { waitCursor { - val color = JColorChooser.showDialog(buttonsPanel.self, "Select Target Color", colorDetectorController.targetColor.toColor) + val color = JColorChooser.showDialog(buttonsPanel.peer, "Select Target Color", colorDetectorController.targetColor.toColor) if (color != null) { colorDetectorController.targetColor = new ColorRGB(color) } diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter03/Ex4ConvertingColorSpaces.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter03/Ex4ConvertingColorSpaces.scala index ba5010b..789ce69 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter03/Ex4ConvertingColorSpaces.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter03/Ex4ConvertingColorSpaces.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,7 +9,7 @@ package opencv_cookbook.chapter03 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ /** * Example for section "Converting color spaces" in Chapter 3. diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/ColorHistogram.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/ColorHistogram.scala index 8b4d55d..dbe998e 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/ColorHistogram.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/ColorHistogram.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -10,9 +10,10 @@ package opencv_cookbook.chapter04 import java.nio.{FloatBuffer, IntBuffer} import opencv_cookbook.OpenCVUtils.wrapInIntBuffer -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgproc._ import org.bytedeco.javacpp.{FloatPointer, IntPointer, PointerPointer} +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ /** * Helper class that simplifies usage of OpenCV `calcHist` function for color images. diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/ContentFinder.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/ContentFinder.scala index 390eb0b..4940893 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/ContentFinder.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/ContentFinder.scala @@ -1,28 +1,31 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ package opencv_cookbook.chapter04 -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgproc._ -import org.bytedeco.javacpp.{FloatPointer, IntPointer, PointerPointer, opencv_imgproc => imgproc} +import org.bytedeco.javacpp.{FloatPointer, IntPointer, PointerPointer} +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.global.{opencv_imgproc => imgproc} +import org.bytedeco.opencv.opencv_core._ /** - * Used by examples from section "Backprojecting a histogram to detect specific image content" in chapter 4. - */ + * Used by examples from section "Backprojecting a histogram to detect specific image content" in chapter 4. + */ class ContentFinder { private val _histogram = new Mat() private var _threshold = -1f /** - * Find content back projecting a histogram. - * @param image input used for back projection. - * @return Result of the back-projection of the histogram. Image is binary (0,255) if threshold is larger than 0. - */ + * Find content back projecting a histogram. + * + * @param image input used for back projection. + * @return Result of the back-projection of the histogram. Image is binary (0,255) if threshold is larger than 0. + */ def find(image: Mat): Mat = { val channels = Array(0, 1, 2) @@ -48,16 +51,20 @@ class ContentFinder { } def threshold: Float = _threshold + /** - * Set threshold for converting the back-projected image to a binary. - * If value is negative no thresholding will be done. - */ - def threshold_=(t: Float) { _threshold = t } + * Set threshold for converting the back-projected image to a binary. + * If value is negative no thresholding will be done. + */ + def threshold_=(t: Float) { + _threshold = t + } def histogram: Mat = _histogram + /** - * Set reference histogram, it will be normalized. - */ + * Set reference histogram, it will be normalized. + */ def histogram_=(h: Mat): Unit = { normalize(h, _histogram) } diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex1ComputeHistogram.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex1ComputeHistogram.scala index 3e0930b..0c6afd2 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex1ComputeHistogram.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex1ComputeHistogram.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,7 +9,7 @@ package opencv_cookbook.chapter04 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ import scala.math.round diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex2ComputeHistogramGraph.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex2ComputeHistogramGraph.scala index 040396e..1ba5414 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex2ComputeHistogramGraph.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex2ComputeHistogramGraph.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,7 +9,7 @@ package opencv_cookbook.chapter04 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ /** * The second example for section "Computing the image histogram" in Chapter 4, page 92. diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex3Threshold.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex3Threshold.scala index 31d4825..f39db5a 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex3Threshold.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex3Threshold.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,9 +9,9 @@ package opencv_cookbook.chapter04 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgcodecs._ -import org.bytedeco.javacpp.opencv_imgproc._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ /** diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex4InvertLut.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex4InvertLut.scala index 944aa82..33d7f27 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex4InvertLut.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex4InvertLut.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -10,8 +10,9 @@ import java.io.File import opencv_cookbook.OpenCVUtils._ import org.bytedeco.javacpp.indexer.UByteIndexer -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ +import org.bytedeco.opencv.opencv_core._ /** * Creates inverted image by inverting its look-up table. diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex5EqualizeHistogram.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex5EqualizeHistogram.scala index 598d820..5e7fb08 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex5EqualizeHistogram.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex5EqualizeHistogram.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,7 +9,7 @@ package opencv_cookbook.chapter04 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ /** * Modifies image using histogram equalization. diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex6ContentDetectionGrayscale.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex6ContentDetectionGrayscale.scala index f6e11d4..1daf711 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex6ContentDetectionGrayscale.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex6ContentDetectionGrayscale.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,8 +9,9 @@ package opencv_cookbook.chapter04 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ +import org.bytedeco.opencv.opencv_core._ /** diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex7ContentDetectionColor.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex7ContentDetectionColor.scala index 175a2c1..76a973c 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex7ContentDetectionColor.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex7ContentDetectionColor.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,7 +9,7 @@ package opencv_cookbook.chapter04 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_core._ +import org.bytedeco.opencv.opencv_core._ /** diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex8MeanShiftDetector.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex8MeanShiftDetector.scala index 0d32df4..10056b7 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex8MeanShiftDetector.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex8MeanShiftDetector.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,10 +9,10 @@ package opencv_cookbook.chapter04 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgcodecs._ -import org.bytedeco.javacpp.opencv_imgproc._ -import org.bytedeco.javacpp.opencv_video._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.global.opencv_video._ +import org.bytedeco.opencv.opencv_core._ /** Uses the mean shift algorithm to find best matching location of the 'template' in another image. diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex9ImageComparator.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex9ImageComparator.scala index c2c197d..9e6e918 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex9ImageComparator.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Ex9ImageComparator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,7 +9,7 @@ package opencv_cookbook.chapter04 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ /** diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Histogram1D.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Histogram1D.scala index 3669f76..4466932 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Histogram1D.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/Histogram1D.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -11,9 +11,10 @@ import java.awt.image.BufferedImage import opencv_cookbook.OpenCVUtils.{wrapInIntPointer, wrapInMatVector} import org.bytedeco.javacpp.indexer.FloatRawIndexer -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgproc._ import org.bytedeco.javacpp.{FloatPointer, IntPointer} +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ /** diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/ImageComparator.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/ImageComparator.scala index 277050c..d9a6211 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/ImageComparator.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter04/ImageComparator.scala @@ -1,13 +1,13 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ package opencv_cookbook.chapter04 -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgproc._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ /** diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter05/Ex1ErodingAndDilating.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter05/Ex1ErodingAndDilating.scala index 3c5536a..137dc6a 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter05/Ex1ErodingAndDilating.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter05/Ex1ErodingAndDilating.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,8 +9,9 @@ package opencv_cookbook.chapter05 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgproc._ +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ /** * Example of using morphological erosion and dilation in chapter 5 section diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter05/Ex2OpeningAndClosing.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter05/Ex2OpeningAndClosing.scala index 0621b74..a6b1130 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter05/Ex2OpeningAndClosing.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter05/Ex2OpeningAndClosing.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,8 +9,9 @@ package opencv_cookbook.chapter05 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgproc._ +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ /** diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter05/Ex3EdgesAndCorners.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter05/Ex3EdgesAndCorners.scala index d1504e6..ae9a9d0 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter05/Ex3EdgesAndCorners.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter05/Ex3EdgesAndCorners.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,9 +9,9 @@ package opencv_cookbook.chapter05 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgcodecs._ -import org.bytedeco.javacpp.opencv_imgproc._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ /** * Example of detecting edges and corners using morphological filters. Based on section "Detecting edges and diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter05/Ex4WatershedSegmentation.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter05/Ex4WatershedSegmentation.scala index e9f4b4e..d4c7729 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter05/Ex4WatershedSegmentation.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter05/Ex4WatershedSegmentation.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,9 +9,10 @@ package opencv_cookbook.chapter05 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgcodecs._ -import org.bytedeco.javacpp.opencv_imgproc._ +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ /** diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter05/Ex5GrabCut.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter05/Ex5GrabCut.scala index 996211e..adfad72 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter05/Ex5GrabCut.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter05/Ex5GrabCut.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,9 +9,9 @@ package opencv_cookbook.chapter05 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgcodecs._ -import org.bytedeco.javacpp.opencv_imgproc._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ /** diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter05/MorphoFeatures.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter05/MorphoFeatures.scala index b71dc74..e6a9696 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter05/MorphoFeatures.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter05/MorphoFeatures.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -11,9 +11,9 @@ import java.awt.{Color, Graphics2D, Image} import opencv_cookbook.OpenCVUtils._ import org.bytedeco.javacpp.BytePointer -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgproc._ - +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ /** * Equivalent of C++ class MorphoFeatures presented in section "Detecting edges and filters using diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter05/WatershedSegmenter.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter05/WatershedSegmenter.scala index 74c0dd1..d93d353 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter05/WatershedSegmenter.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter05/WatershedSegmenter.scala @@ -1,14 +1,14 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ package opencv_cookbook.chapter05 -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgproc._ - +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ /** * Helper class for section "Segmenting images using watersheds". diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter06/Ex1LowPassFilter.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter06/Ex1LowPassFilter.scala index acb680e..e356e2b 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter06/Ex1LowPassFilter.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter06/Ex1LowPassFilter.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,9 +9,10 @@ package opencv_cookbook.chapter06 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgcodecs._ -import org.bytedeco.javacpp.opencv_imgproc._ +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ /** * The example for section "Filtering images using low-pass filters" in Chapter 6, page 142. diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter06/Ex2MedianFilter.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter06/Ex2MedianFilter.scala index d7bf8f6..c3c8b1f 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter06/Ex2MedianFilter.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter06/Ex2MedianFilter.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,9 +9,10 @@ package opencv_cookbook.chapter06 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgcodecs._ -import org.bytedeco.javacpp.opencv_imgproc._ +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ /** * The example for section "Filtering images using a median filter" in Chapter 6, page 147. diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter06/Ex3DirectionalFilters.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter06/Ex3DirectionalFilters.scala index 89c89bb..9d066b2 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter06/Ex3DirectionalFilters.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter06/Ex3DirectionalFilters.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -11,10 +11,10 @@ import java.io.File import opencv_cookbook.OpenCVUtils._ import org.bytedeco.javacpp.DoublePointer -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgcodecs._ -import org.bytedeco.javacpp.opencv_imgproc._ - +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ /** * The example for section "Applying directional filters to detect edges" in Chapter 6, page 148. diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter06/Ex4Laplacian.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter06/Ex4Laplacian.scala index 6b6110b..884646c 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter06/Ex4Laplacian.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter06/Ex4Laplacian.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -10,7 +10,7 @@ package opencv_cookbook.chapter06 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ /** diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter06/LaplacianZC.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter06/LaplacianZC.scala index 0493b05..a135f1e 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter06/LaplacianZC.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter06/LaplacianZC.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -7,9 +7,9 @@ package opencv_cookbook.chapter06 -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgproc._ - +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ /** * Computation of Laplacian and zero-crossing. diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter07/Ex1CannyOperator.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter07/Ex1CannyOperator.scala index 11673e5..fcc0eae 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter07/Ex1CannyOperator.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter07/Ex1CannyOperator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,9 +9,9 @@ package opencv_cookbook.chapter07 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgcodecs._ -import org.bytedeco.javacpp.opencv_imgproc._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ /** diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter07/Ex2HoughLines.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter07/Ex2HoughLines.scala index 3d6712f..c1a4393 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter07/Ex2HoughLines.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter07/Ex2HoughLines.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,27 +9,28 @@ package opencv_cookbook.chapter07 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.indexer.FloatRawIndexer -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgcodecs._ -import org.bytedeco.javacpp.opencv_imgproc._ +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ +import org.bytedeco.opencv.opencv_imgproc._ import scala.math._ /** - * Detect lines using standard Hough transform approach. - * The example for section "Detecting lines in image with the Hough transform" in Chapter 7, page 167. - * - * @see JavaCV sample [https://code.google.com/p/javacv/source/browse/javacv/samples/HoughLines.java] - */ + * Detect lines using standard Hough transform approach. + * The example for section "Detecting lines in image with the Hough transform" in Chapter 7, page 167. + * + * @see JavaCV sample [https://code.google.com/p/javacv/source/browse/javacv/samples/HoughLines.java] + */ object Ex2HoughLines extends App { // Read input image val src = loadAndShowOrExit(new File("data/road.jpg"), IMREAD_GRAYSCALE) // Canny contours - val canny = new Mat() + val canny = new Mat() val threshold1 = 125 val threshold2 = 350 val apertureSize = 3 @@ -37,27 +38,31 @@ object Ex2HoughLines extends App { show(canny, "Canny Contours") // Hough transform for line detection - val lines = new Mat() - val storage = cvCreateMemStorage(0) - val method = HOUGH_STANDARD + val lines = new Vec2fVector() + val storage = cvCreateMemStorage(0) + val method = HOUGH_STANDARD val distanceResolutionInPixels = 1 - val angleResolutionInRadians = Pi / 180 - val minimumVotes = 80 + val angleResolutionInRadians = Pi / 180 + val minimumVotes = 80 + val srn = 0.0 + val stn = 0.0 + val min_theta = 0.0 + val max_theta = CV_PI HoughLines( canny, lines, distanceResolutionInPixels, angleResolutionInRadians, - minimumVotes) + minimumVotes, + srn, stn, min_theta, max_theta) // Draw lines on the canny contour image - val indexer = lines.createIndexer().asInstanceOf[FloatRawIndexer] - val result = new Mat() + val result = new Mat() src.copyTo(result) cvtColor(src, result, COLOR_GRAY2BGR) - for (i <- 0 until lines.rows()) { - val rho = indexer.get(i, 0, 0) - val theta = indexer.get(i, 0, 1) + for (i <- 0 until lines.size().toInt) { + val rho = lines.get(i).get(0) + val theta = lines.get(i).get(1) val (pt1, pt2) = if (theta < Pi / 4.0 || theta > 3.0 * Pi / 4.0) { // ~vertical line diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter07/Ex3HoughLineSegments.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter07/Ex3HoughLineSegments.scala index 5709753..d55e34a 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter07/Ex3HoughLineSegments.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter07/Ex3HoughLineSegments.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,10 +9,9 @@ package opencv_cookbook.chapter07 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgcodecs._ -import org.bytedeco.javacpp.opencv_imgproc._ - +import org.bytedeco.opencv.global.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ /** * Detect lines segments using probabilistic Hough transform approach. diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter07/Ex4HoughCircles.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter07/Ex4HoughCircles.scala index 34d3b8c..4b3ca90 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter07/Ex4HoughCircles.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter07/Ex4HoughCircles.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,10 +9,11 @@ package opencv_cookbook.chapter07 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.indexer.FloatRawIndexer -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgcodecs._ -import org.bytedeco.javacpp.opencv_imgproc._ +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ +import org.bytedeco.opencv.opencv_imgproc._ /** @@ -45,16 +46,15 @@ object Ex4HoughCircles extends App { val votes = 100 val minRadius = 40 val maxRadius = 90 - val circles = new Mat + val circles = new Vec3fVector() HoughCircles(smooth, circles, HOUGH_GRADIENT, dp, minDist, highThreshold, votes, minRadius, maxRadius) - // Draw lines on the canny contour image val colorDst = new Mat() cvtColor(src, colorDst, COLOR_GRAY2BGR) - val indexer = circles.createIndexer().asInstanceOf[FloatRawIndexer] - for (i <- 0 until circles.cols) { - val center = new Point(cvRound(indexer.get(0, i, 0)), cvRound(indexer.get(0, i, 1))) - val radius = cvRound(indexer.get(0, i, 2)) + for (i <- 0 until circles.size().toInt) { + val c = circles.get(i) + val center = new Point(cvRound(c.get(0)), cvRound(c.get(1))) + val radius = cvRound(c.get(2)) println(s"Circle ((${center.x}, ${center.y}), $radius)") circle(colorDst, center, radius, new Scalar(0, 0, 255, 0), 1, LINE_AA, 0) } diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter07/Ex5ExtractContours.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter07/Ex5ExtractContours.scala index 01c1c1f..9ee4200 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter07/Ex5ExtractContours.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter07/Ex5ExtractContours.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,9 +9,10 @@ package opencv_cookbook.chapter07 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgcodecs._ -import org.bytedeco.javacpp.opencv_imgproc._ +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ /** diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter07/Ex6ShapeDescriptors.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter07/Ex6ShapeDescriptors.scala index 30b975d..d3718a0 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter07/Ex6ShapeDescriptors.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter07/Ex6ShapeDescriptors.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -11,9 +11,10 @@ import java.io.File import opencv_cookbook.OpenCVUtils._ import org.bytedeco.javacpp.FloatPointer -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgcodecs._ -import org.bytedeco.javacpp.opencv_imgproc._ +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ /** diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter07/LineFinder.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter07/LineFinder.scala index a32c7fd..6cd590c 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter07/LineFinder.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter07/LineFinder.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -7,52 +7,56 @@ package opencv_cookbook.chapter07 -import org.bytedeco.javacpp.indexer.IntRawIndexer -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgproc._ +import org.bytedeco.javacpp.IntPointer +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ +import org.bytedeco.opencv.opencv_imgproc._ import scala.math._ /** - * Helper class to detect lines segments using probabilistic Hough transform approach. - * The example for section "Detecting lines in image with the Hough transform" in Chapter 7, page 170. - * - * @see JavaCV sample [https://code.google.com/p/javacv/source/browse/javacv/samples/HoughLines.java] - * @param deltaRho Accumulator resolution distance. - * @param deltaTheta Accumulator resolution angle. - * @param minVotes Minimum number of votes that a line must receive before being considered. - * @param minLength Minimum number of votes that a line must receive before being considered. - * @param minGap Max gap allowed along the line. Default no gap. - */ + * Helper class to detect lines segments using probabilistic Hough transform approach. + * The example for section "Detecting lines in image with the Hough transform" in Chapter 7, page 170. + * + * @see JavaCV sample [https://code.google.com/p/javacv/source/browse/javacv/samples/HoughLines.java] + * @param deltaRho Accumulator resolution distance. + * @param deltaTheta Accumulator resolution angle. + * @param minVotes Minimum number of votes that a line must receive before being considered. + * @param minLength Minimum number of votes that a line must receive before being considered. + * @param minGap Max gap allowed along the line. Default no gap. + */ class LineFinder(val deltaRho: Double = 1, val deltaTheta: Double = Pi / 180, val minVotes: Int = 10, val minLength: Double = 0, val minGap: Double = 0d) { - private var lines: Mat = _ + // Each line is represented by a 4-element vector (x1,y1,x2,y2), + // where (x1,y1) and (x2,y2) are the ending points of each detected line segment. + private var lines: Vec4iVector = _ /** - * Apply probabilistic Hough transform. - */ + * Apply probabilistic Hough transform. + */ def findLines(binary: Mat) { // Hough transform for line detection - lines = new Mat() + lines = new Vec4iVector() HoughLinesP(binary, lines, deltaRho, deltaTheta, minVotes, minLength, minGap) } /** - * Draws detected lines on an image - */ + * Draws detected lines on an image + */ def drawDetectedLines(image: Mat) { - - val indexer = lines.createIndexer().asInstanceOf[IntRawIndexer] - - for (i <- 0 until lines.rows()) { - val pt1 = new Point(indexer.get(i, 0, 0), indexer.get(i, 0, 1)) - val pt2 = new Point(indexer.get(i, 0, 2), indexer.get(i, 0, 3)) + for (i <- 0 until lines.size().toInt) { + // Due to bug #717 in OpenCV wrapper in v.1.5 for Vec4iVector, line segment coordinates cannot be extracted directly. + // A workaround is to wrap `FloatPointer` returned from `lines.get` in `IntPointer`, + // based on suggestion [[https://github.com/bytedeco/javacpp-presets/issues/717#issuecomment-485057141]] + val l = new IntPointer(lines.get(i)) + val pt1 = new Point(l.get(0), l.get(1)) + val pt2 = new Point(l.get(2), l.get(3)) // draw the segment on the image line(image, pt1, pt2, new Scalar(0, 0, 255, 128), 1, LINE_AA, 0) diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter08/Ex1HarrisCornerMap.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter08/Ex1HarrisCornerMap.scala index 138bbfd..56ef893 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter08/Ex1HarrisCornerMap.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter08/Ex1HarrisCornerMap.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,9 +9,9 @@ package opencv_cookbook.chapter08 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgcodecs._ -import org.bytedeco.javacpp.opencv_imgproc._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ /** diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter08/Ex2HarrisCornerDetector.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter08/Ex2HarrisCornerDetector.scala index ec7e96f..85b996b 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter08/Ex2HarrisCornerDetector.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter08/Ex2HarrisCornerDetector.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,7 +9,7 @@ package opencv_cookbook.chapter08 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ /** diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter08/Ex3GoodFeaturesToTrack.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter08/Ex3GoodFeaturesToTrack.scala index af05b87..2d343e2 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter08/Ex3GoodFeaturesToTrack.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter08/Ex3GoodFeaturesToTrack.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,9 +9,9 @@ package opencv_cookbook.chapter08 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_core.{KeyPointVector, Mat, Scalar} -import org.bytedeco.javacpp.opencv_features2d._ - +import org.bytedeco.opencv.global.opencv_features2d._ +import org.bytedeco.opencv.opencv_core._ +import org.bytedeco.opencv.opencv_features2d._ /** * Example of using the Good Features to Track detector. @@ -37,6 +37,6 @@ object Ex3GoodFeaturesToTrack extends App { // Draw keyPoints val canvas = new Mat() - drawKeypoints(image, keyPoints, canvas, new Scalar(255, 255, 255, 0), DrawMatchesFlags.DEFAULT) + drawKeypoints(image, keyPoints, canvas, new Scalar(255, 255, 255, 0), DEFAULT) show(canvas, "Good Features to Track Detector") } \ No newline at end of file diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter08/Ex4FAST.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter08/Ex4FAST.scala index ea6e47f..7464dee 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter08/Ex4FAST.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter08/Ex4FAST.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,8 +9,9 @@ package opencv_cookbook.chapter08 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_core.{KeyPointVector, Mat, Scalar} -import org.bytedeco.javacpp.opencv_features2d._ +import org.bytedeco.opencv.global.opencv_features2d._ +import org.bytedeco.opencv.opencv_core._ +import org.bytedeco.opencv.opencv_features2d._ /** * The example for section "Detecting FAST features" in Chapter 8, page 203. @@ -30,6 +31,6 @@ object Ex4FAST extends App { // Draw keyPoints val canvas = new Mat() - drawKeypoints(image, keyPoints, canvas, new Scalar(255, 255, 255, 0), DrawMatchesFlags.DEFAULT) + drawKeypoints(image, keyPoints, canvas, new Scalar(255, 255, 255, 0), DEFAULT) show(canvas, "FAST Features") } diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter08/Ex5SURF.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter08/Ex5SURF.scala index ae4300a..4387e16 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter08/Ex5SURF.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter08/Ex5SURF.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,9 +9,9 @@ package opencv_cookbook.chapter08 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_features2d._ -import org.bytedeco.javacpp.opencv_xfeatures2d._ +import org.bytedeco.opencv.global.opencv_features2d._ +import org.bytedeco.opencv.opencv_core._ +import org.bytedeco.opencv.opencv_xfeatures2d._ /** @@ -19,6 +19,7 @@ import org.bytedeco.javacpp.opencv_xfeatures2d._ */ object Ex5SURF extends App { + // Read input image val image = loadAndShowOrExit(new File("data/church01.jpg")) @@ -35,6 +36,6 @@ object Ex5SURF extends App { // Draw keyPoints // val featureImage = cvCreateImage(cvGetSize(image), image.depth(), 3) val featureImage = new Mat() - drawKeypoints(image, keyPoints, featureImage, new Scalar(255, 255, 255, 0), DrawMatchesFlags.DRAW_RICH_KEYPOINTS) + drawKeypoints(image, keyPoints, featureImage, new Scalar(255, 255, 255, 0), DRAW_RICH_KEYPOINTS) show(featureImage, "SURF Features") } \ No newline at end of file diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter08/Ex6SIFT.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter08/Ex6SIFT.scala index 1d0be32..a903e97 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter08/Ex6SIFT.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter08/Ex6SIFT.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,9 +9,9 @@ package opencv_cookbook.chapter08 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_features2d._ -import org.bytedeco.javacpp.opencv_xfeatures2d.SIFT +import org.bytedeco.opencv.global.opencv_features2d._ +import org.bytedeco.opencv.opencv_core._ +import org.bytedeco.opencv.opencv_xfeatures2d._ /** @@ -34,6 +34,6 @@ object Ex6SIFT extends App { // Draw keyPoints val featureImage = new Mat() - drawKeypoints(image, keyPoints, featureImage, new Scalar(255, 255, 255, 0), DrawMatchesFlags.DRAW_RICH_KEYPOINTS) + drawKeypoints(image, keyPoints, featureImage, new Scalar(255, 255, 255, 0), DRAW_RICH_KEYPOINTS) show(featureImage, "SIFT Features") } \ No newline at end of file diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter08/HarrisDetector.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter08/HarrisDetector.scala index ffc2785..9704cfd 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter08/HarrisDetector.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter08/HarrisDetector.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -8,8 +8,9 @@ package opencv_cookbook.chapter08 import org.bytedeco.javacpp.DoublePointer import org.bytedeco.javacpp.indexer.UByteIndexer -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgproc._ +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ /** Uses Harris Corner strength image to detect well localized corners, diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter09/Ex2TemplateMatching.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter09/Ex2TemplateMatching.scala index 27a080c..ff8d2d5 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter09/Ex2TemplateMatching.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter09/Ex2TemplateMatching.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -10,9 +10,10 @@ import java.io.File import opencv_cookbook.OpenCVUtils._ import org.bytedeco.javacpp.DoublePointer -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgcodecs._ -import org.bytedeco.javacpp.opencv_imgproc._ +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ /** Example for section "Template Matching" in chapter 9, page 265, 2nd edition. * diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter09/Ex7DescribingSURF.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter09/Ex7DescribingSURF.scala index 344b2f9..cf1799d 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter09/Ex7DescribingSURF.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter09/Ex7DescribingSURF.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -10,9 +10,11 @@ import java.io.File import java.nio.ByteBuffer import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_features2d._ -import org.bytedeco.javacpp.opencv_xfeatures2d.SURF +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_features2d._ +import org.bytedeco.opencv.opencv_core._ +import org.bytedeco.opencv.opencv_features2d._ +import org.bytedeco.opencv.opencv_xfeatures2d._ /** Example for section "Describing SURF features" in chapter 8, page 212. * @@ -65,7 +67,7 @@ object Ex7DescribingSURF extends App { val mask: ByteBuffer = null drawMatches( images(0), keyPoints(0), images(1), keyPoints(1), - bestMatches, imageMatches, new Scalar(0, 0, 255, 0), new Scalar(255, 0, 0, 0), mask, DrawMatchesFlags.DEFAULT) + bestMatches, imageMatches, new Scalar(0, 0, 255, 0), new Scalar(255, 0, 0, 0), mask, DEFAULT) show(imageMatches, "Best SURF Feature Matches") diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/CameraCalibrator.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/CameraCalibrator.scala index fddf259..856d86f 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/CameraCalibrator.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/CameraCalibrator.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -7,15 +7,16 @@ package opencv_cookbook.chapter10 import java.io.{File, IOException} -import javax.swing.WindowConstants +import javax.swing.WindowConstants import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_calib3d._ -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgcodecs._ -import org.bytedeco.javacpp.opencv_imgproc -import org.bytedeco.javacpp.opencv_imgproc._ import org.bytedeco.javacv.CanvasFrame +import org.bytedeco.opencv.global.opencv_calib3d._ +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgproc +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ import scala.collection.mutable.ArrayBuffer import scala.language.postfixOps @@ -150,7 +151,7 @@ class CameraCalibrator { val map2 = new Mat() if (mustInitUndistort) { // Called once per calibration - opencv_imgproc.initUndistortRectifyMap( + initUndistortRectifyMap( _cameraMatrix, // computed camera matrix _distortionCoeffs, // computed distortion matrix new Mat(), // optional rectification (none) @@ -168,17 +169,17 @@ class CameraCalibrator { } /** Prepare object points, image points, and point counts in format required by `cvCalibrateCamera2`. */ - private def convertPoints(): (MatVector, MatVector) = { + private def convertPoints(): (Point3fVectorVector, Point2fVectorVector) = { require(objectPoints.size == imagePoints.size, "Number of object and image points must match.") - val objectPointsMatVect = new MatVector(objectPoints.size) - val imagePointsMatVect = new MatVector(objectPoints.size) + val objectPointsVV = new Point3fVectorVector(objectPoints.size) + val imagePointsVV = new Point2fVectorVector(objectPoints.size) for (((objectP, imageP), i) <- objectPoints zip imagePoints zipWithIndex) { - objectPointsMatVect.put(i, toMatPoint3f(objectP)) - imagePointsMatVect.put(i, imageP) + objectPointsVV.put(i, new Point3fVector(objectP: _ *)) + imagePointsVV.put(i, new Point2fVector(toPoint2fArray(imageP): _ *)) } - (objectPointsMatVect, imagePointsMatVect) + (objectPointsVV, imagePointsVV) } } diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/Ex1FindChessboardCorners.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/Ex1FindChessboardCorners.scala index 1e2c7e6..4d2efe8 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/Ex1FindChessboardCorners.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/Ex1FindChessboardCorners.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,9 +9,8 @@ package opencv_cookbook.chapter10 import java.io.File import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_calib3d._ -import org.bytedeco.javacpp.opencv_core._ - +import org.bytedeco.opencv.global.opencv_calib3d._ +import org.bytedeco.opencv.opencv_core._ /** * The first example for section "Calibrating a camera" in Chapter 9, page 219. diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/Ex2CalibrateCamera.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/Ex2CalibrateCamera.scala index e40d26d..15bdbc0 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/Ex2CalibrateCamera.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/Ex2CalibrateCamera.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -10,7 +10,7 @@ import java.io.File import opencv_cookbook.OpenCVUtils._ import org.bytedeco.javacpp.indexer.DoubleRawIndexer -import org.bytedeco.javacpp.opencv_core.Size +import org.bytedeco.opencv.opencv_core.Size /** diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/Ex3ComputeFundamentalMatrix.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/Ex3ComputeFundamentalMatrix.scala index a5697ca..7780cf1 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/Ex3ComputeFundamentalMatrix.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/Ex3ComputeFundamentalMatrix.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -11,10 +11,12 @@ import java.nio.ByteBuffer import opencv_cookbook.OpenCVUtils._ import opencv_cookbook.chapter10.MatcherUtils._ -import org.bytedeco.javacpp.opencv_calib3d._ -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_features2d._ -import org.bytedeco.javacpp.opencv_xfeatures2d.SURF +import org.bytedeco.opencv.global.opencv_calib3d._ +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_features2d._ +import org.bytedeco.opencv.opencv_core._ +import org.bytedeco.opencv.opencv_features2d._ +import org.bytedeco.opencv.opencv_xfeatures2d._ /** The example for section "Computing the fundamental matrix of an image pair" in Chapter 9, page 228. @@ -89,7 +91,7 @@ object Ex3ComputeFundamentalMatrix extends App { val matchMask: ByteBuffer = null val imageMatches = new Mat() drawMatches(imageRight, keypointsRight, imageLeft, keypointsLeft, - selected7Matches, imageMatches, blue, red, matchMask, DrawMatchesFlags.DEFAULT) + selected7Matches, imageMatches, blue, red, matchMask, DEFAULT) show(imageMatches, "Matches 7-point") @@ -147,7 +149,7 @@ object Ex3ComputeFundamentalMatrix extends App { // val canvas = cvCreateImage(cvGetSize(image), image.depth(), 3) val canvas = new Mat() val white = new Scalar(255, 255, 255, 0) - drawKeypoints(image, keypoints, canvas, white, DrawMatchesFlags.DRAW_RICH_KEYPOINTS) + drawKeypoints(image, keypoints, canvas, white, DRAW_RICH_KEYPOINTS) show(canvas, title) } diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/Ex4MatchingUsingSampleConsensus.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/Ex4MatchingUsingSampleConsensus.scala index 6add1f1..219c559 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/Ex4MatchingUsingSampleConsensus.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/Ex4MatchingUsingSampleConsensus.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -11,10 +11,10 @@ import java.io.File import opencv_cookbook.OpenCVUtils._ import opencv_cookbook.chapter10.MatcherUtils._ import org.bytedeco.javacpp.BytePointer -import org.bytedeco.javacpp.opencv_calib3d._ -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_features2d._ -import org.bytedeco.javacpp.opencv_xfeatures2d.SURF +import org.bytedeco.opencv.global.opencv_calib3d._ +import org.bytedeco.opencv.global.opencv_features2d._ +import org.bytedeco.opencv.opencv_core._ +import org.bytedeco.opencv.opencv_xfeatures2d._ /** The example for section "Matching images using random sample consensus" in Chapter 10, p. 299 (2nd edition) diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/Ex5Homography.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/Ex5Homography.scala index f412438..22f4a3c 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/Ex5Homography.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/Ex5Homography.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -12,11 +12,13 @@ import java.nio.ByteBuffer import opencv_cookbook.OpenCVUtils._ import opencv_cookbook.chapter10.MatcherUtils._ import org.bytedeco.javacpp.indexer.UByteRawIndexer -import org.bytedeco.javacpp.opencv_calib3d._ -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_features2d._ -import org.bytedeco.javacpp.opencv_imgproc._ -import org.bytedeco.javacpp.opencv_xfeatures2d.SURF +import org.bytedeco.opencv.global.opencv_calib3d._ +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_features2d._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ +import org.bytedeco.opencv.opencv_features2d._ +import org.bytedeco.opencv.opencv_xfeatures2d._ import scala.math.round diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/MatcherUtils.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/MatcherUtils.scala index 32fc2bf..139806e 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/MatcherUtils.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/MatcherUtils.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -7,8 +7,8 @@ package opencv_cookbook.chapter10 import org.bytedeco.javacpp.indexer.FloatIndexer -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgproc._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ object MatcherUtils { diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/RobustMatcher.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/RobustMatcher.scala index d4f4e08..e7f9770 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/RobustMatcher.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter10/RobustMatcher.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -10,10 +10,11 @@ import opencv_cookbook.OpenCVUtils._ import opencv_cookbook.chapter10.MatcherUtils._ import opencv_cookbook.chapter10.RobustMatcher._ import org.bytedeco.javacpp.indexer.{FloatIndexer, UByteRawIndexer} -import org.bytedeco.javacpp.opencv_calib3d._ -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_features2d._ -import org.bytedeco.javacpp.opencv_xfeatures2d.SURF +import org.bytedeco.opencv.global.opencv_calib3d._ +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.opencv_core._ +import org.bytedeco.opencv.opencv_features2d._ +import org.bytedeco.opencv.opencv_xfeatures2d._ import scala.collection.mutable.{ArrayBuffer, ListBuffer} diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/BGFGSegmenter.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/BGFGSegmenter.scala index 8f6297f..a0929b8 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/BGFGSegmenter.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/BGFGSegmenter.scala @@ -1,13 +1,14 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ package opencv_cookbook.chapter11 -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgproc._ +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ /** Moving average background/foreground segmenter. * diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/Ex1ReadVideoSequence.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/Ex1ReadVideoSequence.scala index 37b5f7f..ae54573 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/Ex1ReadVideoSequence.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/Ex1ReadVideoSequence.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -7,7 +7,6 @@ package opencv_cookbook.chapter11 import javax.swing.WindowConstants - import org.bytedeco.javacv.{CanvasFrame, FFmpegFrameGrabber} import scala.collection.Iterator.continually diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/Ex2ProcessVideoFrames.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/Ex2ProcessVideoFrames.scala index aa8e7e2..e3c566a 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/Ex2ProcessVideoFrames.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/Ex2ProcessVideoFrames.scala @@ -1,13 +1,13 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ package opencv_cookbook.chapter11 -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgproc._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ /** The example for section "Processing the video frames" in Chapter 10, page 251. diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/Ex3WriteVideoSequence.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/Ex3WriteVideoSequence.scala index a84c448..c920ef3 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/Ex3WriteVideoSequence.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/Ex3WriteVideoSequence.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -8,9 +8,10 @@ package opencv_cookbook.chapter11 import java.io.File -import org.bytedeco.javacpp.opencv_core.Mat -import org.bytedeco.javacpp.opencv_imgproc._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ +import scala.Console.print /** The example for section "Writing video sequences" in Chapter 10, page 261. * diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/Ex6MOGMotionDetector.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/Ex6MOGMotionDetector.scala index 1d9793a..18f5a95 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/Ex6MOGMotionDetector.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/Ex6MOGMotionDetector.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,10 +9,10 @@ package opencv_cookbook.chapter11 import javax.swing.WindowConstants import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgproc._ -import org.bytedeco.javacpp.opencv_video._ import org.bytedeco.javacv.{CanvasFrame, FFmpegFrameGrabber, OpenCVFrameConverter} +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.global.opencv_video._ +import org.bytedeco.opencv.opencv_core._ /** The second example example for section "Extracting the foreground objects in video" in Chapter 10, page 272. diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/FeatureTracker.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/FeatureTracker.scala index 460a9f6..2cd24b0 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/FeatureTracker.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/FeatureTracker.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -8,9 +8,9 @@ package opencv_cookbook.chapter11 import opencv_cookbook.OpenCVUtils._ import org.bytedeco.javacpp.indexer.UByteRawIndexer -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgproc._ -import org.bytedeco.javacpp.opencv_video._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.global.opencv_video._ +import org.bytedeco.opencv.opencv_core._ import scala.collection.mutable.ArrayBuffer import scala.math.abs diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/README.md b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/README.md index 56c05fa..6bc4617 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/README.md +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/README.md @@ -26,7 +26,7 @@ grabber.release() ``` Similarly in Java: - ```java + ``` java FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("my_video.avi"); // Open video video file grabber.start(); diff --git a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/VideoProcessor.scala b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/VideoProcessor.scala index 328dfdc..2cd1f37 100644 --- a/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/VideoProcessor.scala +++ b/OpenCV_Cookbook/src/main/scala/opencv_cookbook/chapter11/VideoProcessor.scala @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2015 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -8,8 +8,8 @@ package opencv_cookbook.chapter11 import javax.swing.WindowConstants import opencv_cookbook.OpenCVUtils._ -import org.bytedeco.javacpp.opencv_core._ import org.bytedeco.javacv._ +import org.bytedeco.opencv.opencv_core._ /** Video processor. * @@ -44,6 +44,7 @@ class VideoProcessor(var frameProcessor: (Mat, Mat) => Unit = { (src, dest) => s private var _grabber: Option[FFmpegFrameGrabber] = None def input: String = _input.orNull + def input_=(filename: String): Unit = { _grabber.foreach(_.release()) _input = Option(filename) @@ -81,6 +82,7 @@ class VideoProcessor(var frameProcessor: (Mat, Mat) => Unit = { (src, dest) => s } private var _stop: Boolean = false + def isStopped: Boolean = _stop /** to grab (and process) the frames of the sequence */ diff --git a/OpenCV_Cookbook/src/test/java/opencv_cookbook/CalcHistTest.java b/OpenCV_Cookbook/src/test/java/opencv_cookbook/CalcHistTest.java index 37b7eec..801db24 100644 --- a/OpenCV_Cookbook/src/test/java/opencv_cookbook/CalcHistTest.java +++ b/OpenCV_Cookbook/src/test/java/opencv_cookbook/CalcHistTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ @@ -9,11 +9,11 @@ import org.bytedeco.javacpp.FloatPointer; import org.bytedeco.javacpp.IntPointer; import org.bytedeco.javacpp.PointerPointer; +import org.bytedeco.opencv.opencv_core.Mat; import org.junit.Test; -import static org.bytedeco.javacpp.opencv_core.Mat; -import static org.bytedeco.javacpp.opencv_imgcodecs.imread; -import static org.bytedeco.javacpp.opencv_imgproc.calcHist; +import static org.bytedeco.opencv.global.opencv_imgcodecs.imread; +import static org.bytedeco.opencv.global.opencv_imgproc.calcHist; import static org.junit.Assert.assertNotNull; public class CalcHistTest { diff --git a/OpenCV_Cookbook/src/test/java/opencv_cookbook/ImreadTest.java b/OpenCV_Cookbook/src/test/java/opencv_cookbook/ImreadTest.java index b47ae71..7ea7399 100644 --- a/OpenCV_Cookbook/src/test/java/opencv_cookbook/ImreadTest.java +++ b/OpenCV_Cookbook/src/test/java/opencv_cookbook/ImreadTest.java @@ -1,15 +1,15 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ package opencv_cookbook; +import org.bytedeco.opencv.opencv_core.Mat; import org.junit.Test; -import static org.bytedeco.javacpp.opencv_core.Mat; -import static org.bytedeco.javacpp.opencv_imgcodecs.imread; +import static org.bytedeco.opencv.global.opencv_imgcodecs.imread; import static org.junit.Assert.assertNotNull; public class ImreadTest { diff --git a/OpenCV_Cookbook/src/test/java/opencv_cookbook/MyFirstOpenCVAppInJava.java b/OpenCV_Cookbook/src/test/java/opencv_cookbook/MyFirstOpenCVAppInJava.java index c39c8af..0ce97bd 100644 --- a/OpenCV_Cookbook/src/test/java/opencv_cookbook/MyFirstOpenCVAppInJava.java +++ b/OpenCV_Cookbook/src/test/java/opencv_cookbook/MyFirstOpenCVAppInJava.java @@ -1,16 +1,20 @@ -package opencv_cookbook; +/* + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. + * + * Author's e-mail: jpsacha at gmail.com + */ +package opencv_cookbook; -import org.bytedeco.javacpp.opencv_core.Mat; import org.bytedeco.javacv.CanvasFrame; import org.bytedeco.javacv.OpenCVFrameConverter; +import org.bytedeco.opencv.opencv_core.Mat; import javax.swing.*; -import static org.bytedeco.javacpp.opencv_core.BORDER_DEFAULT; -import static org.bytedeco.javacpp.opencv_imgcodecs.imread; -import static org.bytedeco.javacpp.opencv_imgproc.Laplacian; - +import static org.bytedeco.opencv.global.opencv_core.BORDER_DEFAULT; +import static org.bytedeco.opencv.global.opencv_imgcodecs.imread; +import static org.bytedeco.opencv.global.opencv_imgproc.Laplacian; public class MyFirstOpenCVAppInJava { @@ -26,7 +30,7 @@ public static void main(String[] args) { display(dest, "Laplacian"); } -//--------------------------------------------------------------------------- + //--------------------------------------------------------------------------- static void display(Mat image, String caption) { // Create image window named "My Image". diff --git a/OpenCV_Cookbook/src/test/java/opencv_cookbook/PointerPutTest.java b/OpenCV_Cookbook/src/test/java/opencv_cookbook/PointerPutTest.java index ae9ab6d..b32abfe 100644 --- a/OpenCV_Cookbook/src/test/java/opencv_cookbook/PointerPutTest.java +++ b/OpenCV_Cookbook/src/test/java/opencv_cookbook/PointerPutTest.java @@ -1,12 +1,12 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ package opencv_cookbook; -import org.bytedeco.javacpp.opencv_core.DMatch; +import org.bytedeco.opencv.opencv_core.DMatch; import org.junit.Assert; import org.junit.Test; diff --git a/OpenCV_Cookbook/src/test/java/opencv_cookbook/SURFDetectorTest.java b/OpenCV_Cookbook/src/test/java/opencv_cookbook/SURFDetectorTest.java index 8c303fc..82dcb91 100644 --- a/OpenCV_Cookbook/src/test/java/opencv_cookbook/SURFDetectorTest.java +++ b/OpenCV_Cookbook/src/test/java/opencv_cookbook/SURFDetectorTest.java @@ -1,17 +1,17 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ package opencv_cookbook; +import org.bytedeco.opencv.opencv_core.KeyPointVector; +import org.bytedeco.opencv.opencv_core.Mat; +import org.bytedeco.opencv.opencv_xfeatures2d.SURF; import org.junit.Test; -import static org.bytedeco.javacpp.opencv_core.KeyPointVector; -import static org.bytedeco.javacpp.opencv_core.Mat; -import static org.bytedeco.javacpp.opencv_imgcodecs.imread; -import static org.bytedeco.javacpp.opencv_xfeatures2d.SURF; +import static org.bytedeco.opencv.global.opencv_imgcodecs.imread; import static org.junit.Assert.assertEquals; public class SURFDetectorTest { diff --git a/OpenCV_Cookbook/src/test/java/opencv_cookbook/VideoFileCaptureTest.java b/OpenCV_Cookbook/src/test/java/opencv_cookbook/VideoFileCaptureTest.java index 752aa8b..6b1b530 100644 --- a/OpenCV_Cookbook/src/test/java/opencv_cookbook/VideoFileCaptureTest.java +++ b/OpenCV_Cookbook/src/test/java/opencv_cookbook/VideoFileCaptureTest.java @@ -1,18 +1,20 @@ /* - * Copyright (c) 2011-2014 Jarek Sacha. All Rights Reserved. + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. * * Author's e-mail: jpsacha at gmail.com */ package opencv_cookbook; -import org.bytedeco.javacpp.opencv_core.Mat; +import org.bytedeco.opencv.opencv_core.Mat; +import org.bytedeco.opencv.opencv_videoio.VideoCapture; import org.junit.Ignore; import org.junit.Test; import java.io.File; -import static org.bytedeco.javacpp.opencv_videoio.*; +import static org.bytedeco.opencv.global.opencv_videoio.CAP_PROP_FPS; +import static org.bytedeco.opencv.global.opencv_videoio.CAP_PROP_FRAME_COUNT; import static org.junit.Assert.*; /** @@ -34,7 +36,7 @@ public void captureFromFile() throws Exception { final long nbFrames = (long) capture.get(CAP_PROP_FRAME_COUNT); assertEquals(119, nbFrames); - final double fps = (long) capture.get(CV_CAP_PROP_FPS); + final double fps = (long) capture.get(CAP_PROP_FPS); assertEquals(15, fps, 0.0001); final Mat frame = new Mat(); diff --git a/OpenCV_Cookbook/src/test/scala/opencv_cookbook/MyFirstOpenCVApp.scala b/OpenCV_Cookbook/src/test/scala/opencv_cookbook/MyFirstOpenCVApp.scala index 5546c8b..cc57c8d 100644 --- a/OpenCV_Cookbook/src/test/scala/opencv_cookbook/MyFirstOpenCVApp.scala +++ b/OpenCV_Cookbook/src/test/scala/opencv_cookbook/MyFirstOpenCVApp.scala @@ -1,11 +1,17 @@ +/* + * Copyright (c) 2011-2019 Jarek Sacha. All Rights Reserved. + * + * Author's e-mail: jpsacha at gmail.com + */ + package opencv_cookbook import javax.swing._ - -import org.bytedeco.javacpp.opencv_core._ -import org.bytedeco.javacpp.opencv_imgcodecs._ -import org.bytedeco.javacpp.opencv_imgproc._ import org.bytedeco.javacv._ +import org.bytedeco.opencv.global.opencv_core._ +import org.bytedeco.opencv.global.opencv_imgcodecs._ +import org.bytedeco.opencv.global.opencv_imgproc._ +import org.bytedeco.opencv.opencv_core._ object MyFirstOpenCVApp extends App { @@ -18,7 +24,6 @@ object MyFirstOpenCVApp extends App { Laplacian(src, dest, src.depth(), 1, 3, 0, BORDER_DEFAULT) display(dest, "Laplacian") - //--------------------------------------------------------------------------- /** Display `image` with given `caption`. */ @@ -34,5 +39,4 @@ object MyFirstOpenCVApp extends App { // Show image on window canvas.showImage(converter.convert(image)) } - } diff --git a/Spinnaker-demo/build.sbt b/Spinnaker-demo/build.sbt index c0beae8..3abe593 100644 --- a/Spinnaker-demo/build.sbt +++ b/Spinnaker-demo/build.sbt @@ -3,26 +3,26 @@ name := "Spinnaker-demo" organization := "javacv.examples" -val javacppVersion = "1.4.3" +val javacppVersion = "1.5" version := javacppVersion -scalaVersion := "2.12.7" +scalaVersion := "2.12.8" scalacOptions ++= Seq("-unchecked", "-deprecation", "-Xlint") // Platform classifier for native library dependencies val platform = org.bytedeco.javacpp.Loader.getPlatform // Libraries with native dependencies val bytedecoPresetLibs = Seq( - "spinnaker" -> s"1.15.0.63-1.4.3").flatMap { + "spinnaker" -> s"1.19.0.22-$javacppVersion").flatMap { case (lib, ver) => Seq( // Add both: dependency and its native binaries for the current `platform` - "org.bytedeco.javacpp-presets" % lib % ver withSources() withJavadoc(), - "org.bytedeco.javacpp-presets" % lib % ver classifier platform + "org.bytedeco" % lib % ver withSources() withJavadoc(), + "org.bytedeco" % lib % ver classifier platform ) } libraryDependencies ++= Seq( - "org.bytedeco" % "javacpp" % javacppVersion withSources() withJavadoc(), - "org.bytedeco" % "javacv" % javacppVersion withSources() withJavadoc() + "org.bytedeco" % "javacpp" % javacppVersion withSources() withJavadoc(), + "org.bytedeco" % "javacv" % javacppVersion withSources() withJavadoc() ) ++ bytedecoPresetLibs resolvers ++= Seq( diff --git a/Spinnaker-demo/project/build.properties b/Spinnaker-demo/project/build.properties index 4c31ed2..e2820dd 100644 --- a/Spinnaker-demo/project/build.properties +++ b/Spinnaker-demo/project/build.properties @@ -1,2 +1,2 @@ -sbt.version=1.2.6 +sbt.version=1.2.8 diff --git a/Spinnaker-demo/project/plugins.sbt b/Spinnaker-demo/project/plugins.sbt index ea9fcc7..a5911d0 100644 --- a/Spinnaker-demo/project/plugins.sbt +++ b/Spinnaker-demo/project/plugins.sbt @@ -4,4 +4,4 @@ classpathTypes += "maven-plugin" // javacpp `Loader` is used to determine `platform` classifier in the project`s `build.sbt` // We define dependency here (in folder `project`) since it is used by the build itself. -libraryDependencies += "org.bytedeco" % "javacpp" % "1.4.3" +libraryDependencies += "org.bytedeco" % "javacpp" % "1.5" diff --git a/Spinnaker-demo/src/main/java/spinnaker_c/Acquisition_C.java b/Spinnaker-demo/src/main/java/spinnaker_c/Acquisition_C.java index 699392c..2042a35 100644 --- a/Spinnaker-demo/src/main/java/spinnaker_c/Acquisition_C.java +++ b/Spinnaker-demo/src/main/java/spinnaker_c/Acquisition_C.java @@ -17,12 +17,15 @@ package spinnaker_c; -import org.bytedeco.javacpp.*; -import org.bytedeco.javacpp.Spinnaker_C.*; +import org.bytedeco.javacpp.BytePointer; +import org.bytedeco.javacpp.IntPointer; +import org.bytedeco.javacpp.LongPointer; +import org.bytedeco.javacpp.SizeTPointer; +import org.bytedeco.spinnaker.Spinnaker_C.*; import java.io.File; -import static org.bytedeco.javacpp.Spinnaker_C.*; +import static org.bytedeco.spinnaker.global.Spinnaker_C.*; import static spinnaker_c.Utils.*; /** @@ -405,7 +408,7 @@ public static void main(String[] args) { exitOnError(err, "Unable to retrieve system instance."); // Retrieve list of cameras from the system - Spinnaker_C.spinCameraList hCameraList = new Spinnaker_C.spinCameraList(); + spinCameraList hCameraList = new spinCameraList(); err = spinCameraListCreateEmpty(hCameraList); exitOnError(err, "Unable to create camera list."); @@ -414,7 +417,7 @@ public static void main(String[] args) { // Retrieve number of cameras SizeTPointer numCameras = new SizeTPointer(1); - err = Spinnaker_C.spinCameraListGetSize(hCameraList, numCameras); + err = spinCameraListGetSize(hCameraList, numCameras); exitOnError(err, "Unable to retrieve number of cameras."); System.out.println("Number of cameras detected: " + numCameras.get() + "\n"); diff --git a/Spinnaker-demo/src/main/java/spinnaker_c/Sequencer_C.java b/Spinnaker-demo/src/main/java/spinnaker_c/Sequencer_C.java index 1b3278d..67e892f 100644 --- a/Spinnaker-demo/src/main/java/spinnaker_c/Sequencer_C.java +++ b/Spinnaker-demo/src/main/java/spinnaker_c/Sequencer_C.java @@ -1,12 +1,12 @@ package spinnaker_c; import org.bytedeco.javacpp.*; -import org.bytedeco.javacpp.Spinnaker_C.*; +import org.bytedeco.spinnaker.Spinnaker_C.*; import java.io.File; -import static org.bytedeco.javacpp.Spinnaker_C._spinError.*; -import static org.bytedeco.javacpp.Spinnaker_C.*; +import static org.bytedeco.spinnaker.global.Spinnaker_C.*; +import static org.bytedeco.spinnaker.global.Spinnaker_C._spinError.*; import static spinnaker_c.Utils.*; /** @@ -1402,7 +1402,7 @@ public static void main(String[] args) { // hLibraryVersion.build); // Retrieve list of cameras from the system - Spinnaker_C.spinCameraList hCameraList = new Spinnaker_C.spinCameraList(); + spinCameraList hCameraList = new spinCameraList(); err = spinCameraListCreateEmpty(hCameraList); exitOnError(err, "Unable to create camera list."); @@ -1411,7 +1411,7 @@ public static void main(String[] args) { // Retrieve number of cameras SizeTPointer numCameras = new SizeTPointer(1); - err = Spinnaker_C.spinCameraListGetSize(hCameraList, numCameras); + err = spinCameraListGetSize(hCameraList, numCameras); exitOnError(err, "Unable to retrieve number of cameras."); System.out.println("Number of cameras detected: " + numCameras.get() + "\n"); diff --git a/Spinnaker-demo/src/main/java/spinnaker_c/Utils.java b/Spinnaker-demo/src/main/java/spinnaker_c/Utils.java index cdcbe84..2415ee6 100644 --- a/Spinnaker-demo/src/main/java/spinnaker_c/Utils.java +++ b/Spinnaker-demo/src/main/java/spinnaker_c/Utils.java @@ -2,9 +2,10 @@ import org.bytedeco.javacpp.BytePointer; import org.bytedeco.javacpp.SizeTPointer; -import org.bytedeco.javacpp.Spinnaker_C; +import org.bytedeco.spinnaker.Spinnaker_C.spinNodeHandle; +import org.bytedeco.spinnaker.Spinnaker_C.spinNodeMapHandle; -import static org.bytedeco.javacpp.Spinnaker_C.*; +import static org.bytedeco.spinnaker.global.Spinnaker_C.*; /** * Created by Jarek Sacha on 10/29/2018. @@ -20,7 +21,7 @@ class Utils { * @param err error value. * @param message additional message to print. */ - static void exitOnError(Spinnaker_C._spinError err, String message) { + static void exitOnError(_spinError err, String message) { if (Utils.printOnError(err, message)) { System.out.println("Aborting."); System.exit(err.value); @@ -35,8 +36,8 @@ static void exitOnError(Spinnaker_C._spinError err, String message) { * @param message additional message to print. * @return 'false' if err is not SPINNAKER_ERR_SUCCESS, or 'true' for any other 'err' value. */ - static boolean printOnError(Spinnaker_C._spinError err, String message) { - if (err.value != Spinnaker_C._spinError.SPINNAKER_ERR_SUCCESS.value) { + static boolean printOnError(_spinError err, String message) { + if (err.value != _spinError.SPINNAKER_ERR_SUCCESS.value) { System.out.println(message); System.out.println("Error " + err.value + " " + findErrorNameByValue(err.value) + "\n"); return true; @@ -50,11 +51,11 @@ static boolean printOnError(Spinnaker_C._spinError err, String message) { * layer; please see NodeMapInfo_C example for more in-depth comments on * printing device information from the nodemap. */ - static _spinError printDeviceInfo(Spinnaker_C.spinNodeMapHandle hNodeMap) { - Spinnaker_C._spinError err; + static _spinError printDeviceInfo(spinNodeMapHandle hNodeMap) { + _spinError err; System.out.println("\n*** DEVICE INFORMATION ***\n\n"); // Retrieve device information category node - Spinnaker_C.spinNodeHandle hDeviceInformation = new Spinnaker_C.spinNodeHandle(); + spinNodeHandle hDeviceInformation = new spinNodeHandle(); err = spinNodeMapGetNode(hNodeMap, new BytePointer("DeviceInformation"), hDeviceInformation); Utils.printOnError(err, "Unable to retrieve node."); @@ -65,12 +66,12 @@ static _spinError printDeviceInfo(Spinnaker_C.spinNodeMapHandle hNodeMap) { Utils.printOnError(err, "Unable to retrieve number of nodes."); } else { printRetrieveNodeFailure("node", "DeviceInformation"); - return Spinnaker_C._spinError.SPINNAKER_ERR_ACCESS_DENIED; + return _spinError.SPINNAKER_ERR_ACCESS_DENIED; } // Iterate through nodes and print information for (int i = 0; i < numFeatures.get(); i++) { - Spinnaker_C.spinNodeHandle hFeatureNode = new Spinnaker_C.spinNodeHandle(); + spinNodeHandle hFeatureNode = new spinNodeHandle(); err = spinCategoryGetFeatureByIndex(hDeviceInformation, i, hFeatureNode); Utils.printOnError(err, "Unable to retrieve node."); @@ -187,7 +188,7 @@ static void printf(String format, Object... args) { } private static String findErrorNameByValue(int value) { - for (Spinnaker_C._spinError v : Spinnaker_C._spinError.values()) { + for (_spinError v : _spinError.values()) { if (v.value == value) { return v.name(); } @@ -196,7 +197,7 @@ private static String findErrorNameByValue(int value) { } static String findImageStatusNameByValue(int value) { - for (Spinnaker_C._spinImageStatus v : Spinnaker_C._spinImageStatus.values()) { + for (_spinImageStatus v : _spinImageStatus.values()) { if (v.value == value) { return v.name(); } diff --git a/flandmark-demo/build.sbt b/flandmark-demo/build.sbt index 62b794c..244f0e2 100644 --- a/flandmark-demo/build.sbt +++ b/flandmark-demo/build.sbt @@ -2,10 +2,10 @@ name := "flandmark-demo" // Project version -version := "1.4.1" +version := "1.5" // Version of Scala used by the project -scalaVersion := "2.12.7" +scalaVersion := "2.12.8" scalacOptions ++= Seq("-unchecked", "-deprecation", "-optimize", "-Xlint") @@ -17,11 +17,11 @@ lazy val platform = org.bytedeco.javacpp.Loader.getPlatform // @formatter:off libraryDependencies ++= Seq( - "org.bytedeco" % "javacv" % "1.4.3", - "org.bytedeco.javacpp-presets" % "flandmark" % "1.07-1.4.3" classifier "", - "org.bytedeco.javacpp-presets" % "flandmark" % "1.07-1.4.3" classifier platform, - "org.bytedeco.javacpp-presets" % "opencv" % "3.4.3-1.4.3" classifier "", - "org.bytedeco.javacpp-presets" % "opencv" % "3.4.3-1.4.3" classifier platform + "org.bytedeco" % "javacv" % "1.5", + "org.bytedeco" % "flandmark" % "1.07-1.5" classifier "", + "org.bytedeco" % "flandmark" % "1.07-1.5" classifier platform, + "org.bytedeco" % "opencv" % "4.0.1-1.5" classifier "", + "org.bytedeco" % "opencv" % "4.0.1-1.5" classifier platform ) // @formatter:on diff --git a/flandmark-demo/project/build.properties b/flandmark-demo/project/build.properties index 4c31ed2..e2820dd 100644 --- a/flandmark-demo/project/build.properties +++ b/flandmark-demo/project/build.properties @@ -1,2 +1,2 @@ -sbt.version=1.2.6 +sbt.version=1.2.8 diff --git a/flandmark-demo/project/plugin.sbt b/flandmark-demo/project/plugin.sbt index 1356235..723b86b 100644 --- a/flandmark-demo/project/plugin.sbt +++ b/flandmark-demo/project/plugin.sbt @@ -5,6 +5,6 @@ classpathTypes += "maven-plugin" // javacpp `Loader` is used to determine `platform` classifier in the project`s `build.sbt` // We define dependency here (in folder `project`) since it is used by the build itself. -libraryDependencies += "org.bytedeco" % "javacpp" % "1.4.3" +libraryDependencies += "org.bytedeco" % "javacpp" % "1.5" diff --git a/flandmark-demo/src/main/java/flandmark/Example1.java b/flandmark-demo/src/main/java/flandmark/Example1.java index 1c093e2..ee0df90 100644 --- a/flandmark-demo/src/main/java/flandmark/Example1.java +++ b/flandmark-demo/src/main/java/flandmark/Example1.java @@ -1,20 +1,21 @@ package flandmark; -import org.bytedeco.javacpp.BytePointer; +import org.bytedeco.flandmark.FLANDMARK_Model; import org.bytedeco.javacv.CanvasFrame; import org.bytedeco.javacv.OpenCVFrameConverter; +import org.bytedeco.opencv.opencv_core.*; +import org.bytedeco.opencv.opencv_objdetect.CascadeClassifier; -import javax.naming.OperationNotSupportedException; import javax.swing.*; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; -import static org.bytedeco.javacpp.flandmark.*; -import static org.bytedeco.javacpp.opencv_core.*; -import static org.bytedeco.javacpp.opencv_imgcodecs.cvLoadImage; -import static org.bytedeco.javacpp.opencv_imgproc.*; -import static org.bytedeco.javacpp.opencv_objdetect.*; +import static org.bytedeco.flandmark.global.flandmark.flandmark_detect; +import static org.bytedeco.flandmark.global.flandmark.flandmark_init; +import static org.bytedeco.opencv.global.opencv_imgcodecs.imread; +import static org.bytedeco.opencv.global.opencv_imgproc.*; + /** * JVM version of flandmark example 1: @@ -22,21 +23,6 @@ */ public final class Example1 { - private static CvHaarClassifierCascade loadFaceCascade(final File file) throws IOException { - if (!file.exists()) { - throw new FileNotFoundException("Face cascade file does not exist: " + file.getAbsolutePath()); - } - - final CvHaarClassifierCascade faceCascade = - cvLoadHaarClassifierCascade(file.getCanonicalPath(), cvSize(0, 0)); - - if (faceCascade == null) { - throw new IOException("Failed to load face cascade from file: " + file.getAbsolutePath()); - } - - return faceCascade; - } - private static FLANDMARK_Model loadFLandmarkModel(final File file) throws IOException { if (!file.exists()) { throw new FileNotFoundException("FLandmark model file does not exist: " + file.getAbsolutePath()); @@ -50,99 +36,74 @@ private static FLANDMARK_Model loadFLandmarkModel(final File file) throws IOExce return model; } - private static IplImage loadImage(File file) throws IOException { - // Verify file - if (!file.exists()) { - throw new FileNotFoundException("Image file does not exist: " + file.getAbsolutePath()); - } - // Read input image - IplImage image = cvLoadImage(file.getAbsolutePath()); - if (image == null) { - throw new IOException("Couldn't load image: " + file.getAbsolutePath()); - } - return image; - } - - private static void show(final IplImage image, final String title) { - final IplImage image1 = cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, image.nChannels()); - cvCopy(image, image1); + private static void show(final Mat image, final String title) { CanvasFrame canvas = new CanvasFrame(title, 1); canvas.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); final OpenCVFrameConverter.ToIplImage converter = new OpenCVFrameConverter.ToIplImage(); - canvas.showImage(converter.convert(image1)); + canvas.showImage(converter.convert(image)); } - private static void detectFaceInImage(final IplImage orig, - final IplImage input, - final CvHaarClassifierCascade cascade, + private static void detectFaceInImage(final Mat orig, + final Mat input, + final CascadeClassifier faceCascade, final FLANDMARK_Model model, final int[] bbox, final double[] landmarks) throws Exception { - CvMemStorage storage = cvCreateMemStorage(0); - cvClearMemStorage(storage); - try { - double search_scale_factor = 1.1; - int flags = CV_HAAR_DO_CANNY_PRUNING; - CvSize minFeatureSize = cvSize(40, 40); - CvSeq rects = cvHaarDetectObjects(input, cascade, storage, search_scale_factor, 2, flags, minFeatureSize, cvSize(0, 0)); - int nFaces = rects.total(); - if (nFaces == 0) { - throw new Exception("No faces detected"); - } - - - for (int iface = 0; iface < nFaces; ++iface) { - BytePointer elem = cvGetSeqElem(rects, iface); - CvRect rect = new CvRect(elem); + RectVector faces = new RectVector(); + faceCascade.detectMultiScale(input, faces); - bbox[0] = rect.x(); - bbox[1] = rect.y(); - bbox[2] = rect.x() + rect.width(); - bbox[3] = rect.y() + rect.height(); - - flandmark_detect(input, bbox, model, landmarks); - - // display landmarks - cvRectangle(orig, cvPoint(bbox[0], bbox[1]), cvPoint(bbox[2], bbox[3]), CV_RGB(255, 0, 0)); - cvRectangle(orig, - cvPoint((int) model.bb().get(0), (int) model.bb().get(1)), - cvPoint((int) model.bb().get(2), (int) model.bb().get(3)), CV_RGB(0, 0, 255)); - cvCircle(orig, - cvPoint((int) landmarks[0], (int) landmarks[1]), 3, CV_RGB(0, 0, 255), CV_FILLED, 8, 0); - for (int i = 2; i < 2 * model.data().options().M(); i += 2) { - cvCircle(orig, cvPoint((int) (landmarks[i]), (int) (landmarks[i + 1])), 3, CV_RGB(255, 0, 0), CV_FILLED, 8, 0); - - } + long nFaces = faces.size(); + System.out.println("Faces detected: " + nFaces); + if (nFaces == 0) { + throw new Exception("No faces detected"); + } + for (int iface = 0; iface < nFaces; ++iface) { + Rect rect = faces.get(iface); + + bbox[0] = rect.x(); + bbox[1] = rect.y(); + bbox[2] = rect.x() + rect.width(); + bbox[3] = rect.y() + rect.height(); + + flandmark_detect(new IplImage(input), bbox, model, landmarks); + + // display landmarks + rectangle(orig, new Point(bbox[0], bbox[1]), new Point(bbox[2], bbox[3]), new Scalar(255, 0, 0, 128)); + rectangle(orig, + new Point((int) model.bb().get(0), (int) model.bb().get(1)), + new Point((int) model.bb().get(2), (int) model.bb().get(3)), new Scalar(0, 0, 255, 128)); + circle(orig, + new Point((int) landmarks[0], (int) landmarks[1]), 3, + new Scalar(0, 0, 255, 128), CV_FILLED, 8, 0); + for (int i = 2; i < 2 * model.data().options().M(); i += 2) { + circle(orig, new Point((int) (landmarks[i]), (int) (landmarks[i + 1])), 3, + new Scalar(255, 0, 0, 128), CV_FILLED, 8, 0); } - - } finally { - cvReleaseMemStorage(storage); } } - public static void main(String[] args) throws OperationNotSupportedException { + public static void main(String[] args) { final File inputImage = new File("face.jpg"); final File faceCascadeFile = new File("haarcascade_frontalface_alt.xml"); final File flandmarkModelFile = new File("flandmark_model.dat"); try { - final CvHaarClassifierCascade faceCascade = loadFaceCascade(faceCascadeFile); - System.out.println("Count: " + faceCascade.count()); + CascadeClassifier faceCascade = new CascadeClassifier(faceCascadeFile.getCanonicalPath()); final FLANDMARK_Model model = loadFLandmarkModel(flandmarkModelFile); System.out.println("Model w_cols: " + model.W_COLS()); System.out.println("Model w_rows: " + model.W_ROWS()); - final IplImage image = loadImage(inputImage); + Mat image = imread(inputImage.getCanonicalPath()); show(image, "Example 1 - original"); - final IplImage imageBW = cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, 1); - cvCvtColor(image, imageBW, CV_BGR2GRAY); + Mat imageBW = new Mat(); + cvtColor(image, imageBW, CV_BGR2GRAY); show(imageBW, "Example 1 - BW input"); final int[] bbox = new int[4];