Example usage for org.opencv.videoio VideoCapture get

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

Introduction

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

Prototype

public double get(int propId) 

Source Link

Usage

From source file:OCV_CntrlUvcCamera.java

License:Open Source License

@Override
public void run(ImageProcessor arg0) {
    boolean bret = true;

    // ----- stop dialog during continuous grabbing -----
    diag_free = new JDialog(diag_free, title, false);
    JButton but_stop_cont = new JButton("Stop");

    but_stop_cont.addMouseListener(new MouseAdapter() {
        @Override//from w w w. j  a v  a  2 s .  c o m
        public void mouseClicked(MouseEvent e) {
            flag_fin_loop = true;
            diag_free.dispose();
        }
    });

    diag_free.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            flag_fin_loop = true;
        }
    });

    diag_free.add(but_stop_cont);
    diag_free.setSize(100, 75);
    // ----- end of stop dialog -----

    // initialize camera
    VideoCapture src_cap = new VideoCapture();
    Mat src_mat = new Mat();
    bret = src_cap.open(device);

    if (!bret) {
        IJ.error("Camera initialization is failed.");
        diag_free.dispose();
        return;
    }

    src_cap.set(CV_CAP_PROP_FRAME_WIDTH, width);
    src_cap.set(CV_CAP_PROP_FRAME_HEIGHT, height);

    // Setting the image display window
    width = (int) src_cap.get(CV_CAP_PROP_FRAME_WIDTH);
    height = (int) src_cap.get(CV_CAP_PROP_FRAME_HEIGHT);

    ImagePlus impDsp = IJ.createImage(title, width, height, 1, 24);

    int[] impdsp_intarray = (int[]) impDsp.getChannelProcessor().getPixels();

    impDsp.show();
    impDsp.setRoi(0, 0, impDsp.getWidth(), impDsp.getHeight());

    // show stop dialog
    diag_free.setVisible(true);

    // run
    for (;;) {
        if (flag_fin_loop) {
            break;
        }

        // grab
        impDsp.startTiming();
        bret = src_cap.read(src_mat);
        IJ.showTime(impDsp, impDsp.getStartTime(), title + " : ");

        if (!bret) {
            IJ.error("Error occurred in grabbing.");
            diag_free.dispose();
            break;
        }

        if (src_mat.empty()) {
            IJ.error("Mat is empty.");
            diag_free.dispose();
            break;
        }

        // display
        if (src_mat.type() == CvType.CV_8UC3) {
            OCV__LoadLibrary.mat2intarray(src_mat, impdsp_intarray, width, height);
        } else {
            IJ.error("Color camera is supported only.");
            diag_free.dispose();
            break;
        }

        impDsp.draw();

        // wait
        wait(wait_time);
    }

    diag_free.dispose();

    if (src_cap.isOpened()) {
        src_cap.release();
    }
}

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);/*  w w  w  .  j  av  a 2s. c  om*/
    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();
}

From source file:com.armeniopinto.stress.control.vision.VisionConfig.java

@Bean(name = "visionDevice", destroyMethod = "release")
public VideoCapture videoCapture() throws VisionException {
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    LOGGER.debug("OpenCV native library loaded.");

    final VideoCapture device = new VideoCapture(deviceId) {
        @Override//  w  w w.  j av a 2  s.  c  o m
        public void release() {
            super.release();
            LOGGER.debug("Vision device stopped.");
        }
    };
    device.set(CAP_PROP_FRAME_WIDTH, width);
    device.set(CAP_PROP_FRAME_HEIGHT, height);
    try {
        TimeUnit.MICROSECONDS.sleep(2000L);
    } catch (final InterruptedException ie) {
        LOGGER.warn("Failed to sleep!", ie);
    }
    if (!device.isOpened()) {
        throw new VisionException("Unable to open the camera.");
    }

    final int actualWidth = (int) device.get(CAP_PROP_FRAME_WIDTH);
    final int actualHeight = (int) device.get(CAP_PROP_FRAME_HEIGHT);
    if (actualWidth != width) {
        LOGGER.warn(String.format("Requested frame width %d but got %d instead.", width, actualWidth));
    }
    if (actualHeight != height) {
        LOGGER.warn(String.format("Requested frame height %d but got %d instead.", height, actualHeight));
    }

    LOGGER.debug(String.format("Vision device %d started at %dx%d.", deviceId, actualWidth, actualHeight));

    return device;
}

From source file:ConfOpenCV_Java.ConfOpenCV_Java.java

/**
 * @param args the command line arguments
 *//* w  w w . j a v a 2s  . c o m*/
public static void main(String[] args) {

    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    System.out.println("Welcome to OpenCV " + Core.VERSION);
    String outputFile = "mivideo.avi";
    VideoCapture vc = new VideoCapture(0);
    System.out.println("fps= " + Videoio.CAP_PROP_FPS);

    //vc.set(5, 50);
    //System.out.println(vc.set(3, 1280));
    //vc.set(4, 720);
    double fps = 30;
    System.out.println(fps);

    Size frameSize = new Size((int) vc.get(Videoio.CV_CAP_PROP_FRAME_WIDTH),
            (int) vc.get(Videoio.CV_CAP_PROP_FRAME_HEIGHT));
    System.out.println(frameSize);

    VideoWriter vw = new VideoWriter(outputFile, VideoWriter.fourcc('X', '2', '6', '4'), fps, frameSize, true);
    //System.out.println(VideoWriter.fourcc('X', '2', '6', '4'));
    //System.out.println(vw.isOpened());
    Mat frame = new Mat();

    //para cargar fotos
    //Imgcodecs.imread(outputFile)
    //Imgcodecs.imwrite(outputFile, m);
    int numFramesRemaining = 5 * (int) fps;

    NewJFrame ventana = new NewJFrame();
    ventana.setVisible(true);
    g = ventana.getjPanel1().getGraphics();
    ventana.pack();
    ventana.setVisible(true);

    while (vc.read(frame) && numFramesRemaining > 0) {
        vw.write(frame);
        mostrarImagen(frame);
        numFramesRemaining--;
    }

    vw.release();
    vc.release();
    ventana.dispose();

}