Example usage for org.opencv.videoio VideoCapture VideoCapture

List of usage examples for org.opencv.videoio VideoCapture VideoCapture

Introduction

In this page you can find the example usage for org.opencv.videoio VideoCapture VideoCapture.

Prototype

public VideoCapture(int index) 

Source Link

Usage

From source file:Face_Reco.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 w  w  w . ja  v  a 2 s. co  m

        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);
                Imgcodecs.imread("camera.jpg");
                Imgcodecs.imread("camera.jpg", Imgcodecs.CV_LOAD_IMAGE_GRAYSCALE);
                System.out.println("Done!");
                break;
            }
        }

    }
    camera.release();

}

From source file:RecorderInterace.java

private void jButtonStartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonStartActionPerformed
    // TODO add your handling code here:
    webSource = new VideoCapture(0); //video capture from default cam
    myThread = new DaemonThread(); //create object from thread class
    Thread t = new Thread(myThread);
    t.setDaemon(true);//from   w ww  . j a v a  2s.c o m
    myThread.runnable = true;
    t.start(); //start thread

    jButtonStart.setEnabled(false); //deactivate start button
    jButtonStop.setEnabled(true); // activate stop button
}

From source file:FaceView.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

    webSource = new VideoCapture(0);
    myThread = new MyThread();
    Thread t = new Thread(myThread);
    t.setDaemon(true);//  w  ww.  j  av  a  2  s  . c o m
    myThread.runnable = true;
    t.start();
    jButton1.setEnabled(false);
    jButton2.setEnabled(true);

}

From source file:app.device.manager.Source.java

/**
 * /*from www.  j  a v  a 2 s  .c o  m*/
 */
public Source() {
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    this.device = new VideoCapture(0);
    this.frame = new Mat();
    this.buffer = new MatOfByte();
}

From source file:app.device.manager.Source.java

/**
 * /*from   w w w .j  a  va  2s .com*/
 * @param filename 
 */
public Source(String filename) {
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    this.device = new VideoCapture(filename);
    this.frame = new Mat();
    this.buffer = new MatOfByte();
}

From source file:attendance_system_adder.video.java

public synchronized void displayVideo(int index) {
    isdisplayClose = false;/* ww w  .j  a va  2s.  c om*/
    if (vc == null) {
        vc = new VideoCapture(index);
    }
    if (img == null) {
        img = new image();
    }
    if (mat == null) {
        mat = new Mat();
    }

    vdf.setVisible(true);

    while (true) {
        if (isdisplayClose) {
            img.closeDisplayFrame();
            vc.release();
            break;
        }
        vc.read(mat);
        grayMat = img.RGBtoGRAY(mat);
        Mat2BufferedImage = img.Mat2BufferedImage(grayMat);
        img.displayImage(Mat2BufferedImage);

    }
}

From source file:attendance_system_adder.video.java

public void faceDetctDisplayVideo(int index) {
    isdisplayClose = false;// ww w  .ja  v a2s.  com
    if (vc == null) {
        vc = new VideoCapture(index);
    }
    if (img == null) {
        img = new image();
    }
    if (mat == null) {
        mat = new Mat();
    }

    vdf.setVisible(true);

    while (true) {
        if (isdisplayClose) {
            img.closeDisplayFrame();
            vc.release();
            break;
        }
        vc.read(mat);
        grayMat = img.RGBtoGRAY(mat);
        //            Mat2BufferedImage= img.Mat2BufferedImage(grayMat);
        img.faceDetctDisplayImage(grayMat);

        //            try {
        //                this.sleep(50);
        //            } catch (InterruptedException ex) {
        //                Logger.getLogger(video.class.getName()).log(Level.SEVERE, null, ex);
        //            }

    }
}

From source file:bgslibrary.Main.java

License:Open Source License

private void start() {
    if (begin == false) {
        video = new VideoCapture(0);

        if (video.isOpened()) {
            if (selectedAlgorithm != null)
                BgsLib.constructObject(selectedAlgorithm);

            thread = new CaptureThread();
            thread.start();/*from  w w  w. j  a  v a  2 s  .c om*/
            begin = true;
        }
    }
}

From source file:bikecalibration.fxml.controller.MainWindowController.java

@FXML
void fileOpenActionHandler(ActionEvent event) {
    // first we create an filechoser dialog
    FileChooser fc = new FileChooser();
    fc.setTitle("Open Video File");
    fc.getExtensionFilters().addAll(new FileChooser.ExtensionFilter("AVI file", "*.avi"),
            new FileChooser.ExtensionFilter("MP4 file", "*.mp4"));
    File videoFile = fc.showOpenDialog(borderPane.getScene().getWindow());
    if (videoFile == null) {
        return;//  ww  w  .ja v  a2  s .c o  m
    }
    String videoFileName = videoFile.getAbsolutePath();
    cap = new VideoCapture(videoFileName);
    double totalFrames = cap.get(Videoio.CAP_PROP_FRAME_COUNT);
    //GraphicsContext gc = imageViewCanvas.getGraphicsContext2D();
    videoSlider.setMax(totalFrames);
    videoSlider.setBlockIncrement(1 / cap.get(Videoio.CAP_PROP_FPS));
    currentFrameNumberField.setText("0");
    LOGGER.log(Level.INFO, "{0} loaded.", videoFileName);

    videoInfo = null;
    videoInfo = new VideoInfo(videoFileName);

    // print the video file properties
    propertiesData.clear();
    propertiesData.add(new Properties("Filename", videoInfo.FileName.get()));
    propertiesData.add(new Properties("Size", String.format("%d", videoInfo.FileSize.get())));
    propertiesData.add(new Properties("Width", String.format("%d", videoInfo.Width.get())));
    propertiesData.add(new Properties("Height", String.format("%d", videoInfo.Height.get())));
    propertiesData.add(new Properties("FPS", String.format("%f", videoInfo.FPS.get())));
    propertiesData.add(new Properties("Duration", Utils.secondsToString(videoInfo.Duration.get())));
    propertiesData
            .add(new Properties("Total frames", String.format("%d", videoInfo.TotalNumberOfFrames.get())));

    // crate a nodes array
    nodes = new Node[videoInfo.TotalNumberOfFrames.get()][];

    // at the end we draw the starting frame
    Image img = Utils.matToImage(OpenCvUtils.getImageFromVideo(0, cap));
    drawImage(img);
}

From source file:bikecalibration.VideoInfo.java

public VideoInfo(String fileName) {
    FileName = new SimpleStringProperty();
    Width = new SimpleIntegerProperty();
    Height = new SimpleIntegerProperty();
    FPS = new SimpleDoubleProperty();
    TotalNumberOfFrames = new SimpleIntegerProperty();
    Duration = new SimpleDoubleProperty();
    FileSize = new SimpleLongProperty();

    File f = new File(fileName);
    VideoCapture cap = new VideoCapture(fileName);
    FileName.set(fileName);//from   w  ww.  j  a va 2 s .  co  m
    Width.set((int) cap.get(Videoio.CAP_PROP_FRAME_WIDTH));
    Height.set((int) cap.get(Videoio.CAP_PROP_FRAME_HEIGHT));
    FPS.set(cap.get(Videoio.CAP_PROP_FPS));
    TotalNumberOfFrames.set((int) cap.get(Videoio.CAP_PROP_FRAME_COUNT));
    Duration.set(1 / cap.get(Videoio.CAP_PROP_FPS) * cap.get(Videoio.CAP_PROP_FRAME_COUNT));
    FileSize.set(f.length());
    cap.release();
}