Created
April 8, 2013 19:09
-
-
Save rladstaetter/5339553 to your computer and use it in GitHub Desktop.
Example code to grab images from the ISight Webcam using only OpenCV
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
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 :)") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you have the complete code, ? thanks,