Skip to content

Instantly share code, notes, and snippets.

@rladstaetter
Created April 8, 2013 19:09
Show Gist options
  • Save rladstaetter/5339553 to your computer and use it in GitHub Desktop.
Save rladstaetter/5339553 to your computer and use it in GitHub Desktop.
Example code to grab images from the ISight Webcam using only OpenCV
package net.ladstatt.apps.isight
import org.opencv.highgui.VideoCapture
import java.io.File
import org.opencv.core.Mat
import org.opencv.highgui.Highgui
import scala.collection.JavaConversions._
import org.opencv.core.CvType
import java.util.Date
import java.util.UUID
object VideoCaptureWithOpenCV {
def main(args: Array[String]) {
System.load(new File("/opt/local/share/OpenCV/java/libopencv_java244.dylib").getAbsolutePath())
val videocapture = new VideoCapture(0)
assert(videocapture.isOpened())
while (videocapture.grab) {
val image = new Mat()
while (videocapture.read(image) == false) { println("waiting for successful grab") }
val fn = "image_%s.png".format(UUID.randomUUID.toString())
Highgui.imwrite(fn, image)
println("grabbing photo ...")
}
println("now you have many photos of yourself :)")
}
}
@roj12134
Copy link

Do you have the complete code, ? thanks,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment