List of usage examples for org.opencv.videoio VideoCapture read
public boolean read(Mat image)
From source file:spycam.Spycam.java
public static void main(String args[]) { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); VideoCapture camera = new VideoCapture(0); if (!camera.isOpened()) { System.out.println("Error"); } else {//from www . j ava2 s . c om Mat frame = new Mat(); while (true) { if (camera.read(frame)) { System.out.println("Frame Obtained"); System.out.println("Captured Frame Width " + frame.width() + " Height " + frame.height()); Imgcodecs.imwrite("camera.jpg", frame); System.out.println("OK"); break; } } } camera.release(); }
From source file:webcamfacedetect.WebcamFaceDetect.java
/** * @param args the command line arguments *//*ww w. j a v a 2 s . co m*/ public static void main(String args[]) { // Load the native library. Libloader.load(); String window_name = "Capture - Face detection"; JFrame frame = new JFrame(window_name); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(1024, 800); FaceDetect faceDetect = new FaceDetect(); Processor my_processor = new Processor(); frame.setContentPane(faceDetect); frame.setVisible(true); // Read the video stream Mat webcam_image = new Mat(); VideoCapture capture = null; for (int numCam = 0; numCam < 5; numCam++) { try { capture = new VideoCapture(numCam); break; } catch (Exception e) { System.out.println("Webcam number " + numCam + " unavailable ..."); } } if (capture.isOpened()) { while (true) { capture.read(webcam_image); if (!webcam_image.empty()) { frame.setSize(webcam_image.width() + 40, webcam_image.height() + 60); // Apply the classifier to the captured image webcam_image = my_processor.detect(webcam_image); // Display recognized image faceDetect.MatToBufferedImage(webcam_image); faceDetect.repaint(); } else { System.out.println("No captured frame. Exit."); break; } } } }