Last active
June 25, 2016 18:09
-
-
Save cive/873dac2dba8a533d2dffdb0e4841a2f2 to your computer and use it in GitHub Desktop.
scalaでJavaCV使ってみたかっただけ ref: http://qiita.com/NakamuraFukurou/items/65467e36a044d2e7ebe3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // @formatter:off | |
| name := "sample" | |
| organization := "com.github.cive" | |
| scalaVersion := "2.11.8" | |
| scalacOptions ++= Seq("-unchecked", "-deprecation", "-Xlint") | |
| classpathTypes += "maven-plugin" | |
| libraryDependencies ++= Seq( | |
| "org.scala-lang.modules" % "scala-swing_2.11" % "1.0.1", | |
| "junit" % "junit" % "4.12" % "test", | |
| "com.novocode" % "junit-interface" % "0.11" % "test" | |
| ) | |
| resolvers ++= Seq( | |
| Resolver.sonatypeRepo("snapshots"), | |
| // Use local maven repo for local javacv builds | |
| "Local Maven Repository" at "file:///" + Path.userHome.absolutePath + "/.m2/repository" | |
| ) | |
| autoCompilerPlugins := true | |
| fork := true | |
| javaOptions += "-Xmx1G" | |
| shellPrompt in ThisBuild := { state => "sbt:" + Project.extract(state).currentRef.project + "> " } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| logLevel := Level.Warn | |
| addSbtPlugin("org.bytedeco" % "sbt-javacpp" % "1.4") | |
| addSbtPlugin("org.bytedeco" % "sbt-javacv" % "1.6") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.awt.image.BufferedImage | |
| import java.awt.{AWTException, GraphicsEnvironment, Robot} | |
| import java.io.IOException | |
| import javax.swing.JFrame | |
| import org.bytedeco.javacpp.opencv_core._ | |
| import org.bytedeco.javacv._ | |
| object mainApp extends App { | |
| val image: Mat = try { | |
| val bounds = GraphicsEnvironment.getLocalGraphicsEnvironment.getMaximumWindowBounds | |
| val robot = new Robot | |
| val screen: BufferedImage = robot.createScreenCapture(bounds) | |
| new OpenCVFrameConverter.ToMat().convert(new Java2DFrameConverter().convert(screen)) | |
| } catch { | |
| case e: AWTException => { | |
| println("awt" + e) | |
| new Mat(1, 1, CV_8UC3) | |
| } | |
| case e: IOException => { | |
| println("io" + e) | |
| new Mat(1, 1, CV_8UC3) | |
| } | |
| } | |
| val canvas = new CanvasFrame("My Image", 1) | |
| canvas.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) | |
| val converter = new OpenCVFrameConverter.ToMat() | |
| canvas.showImage(converter.convert(image)) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment