Search in sources :

Example 1 with JCodecSimplified

use of boofcv.io.jcodec.JCodecSimplified in project BoofCV by lessthanoptimal.

the class ExampleJCodecDisplayFrames method main.

public static void main(String[] args) {
    String fileName = UtilIO.pathExample("background/highway_bridge_jitter.mp4");
    ImageType type = ImageType.pl(3, GrayU8.class);
    // ImageType type = ImageType.single(GrayU8.class);
    // ImageType type = ImageType.pl(3, GrayF32.class);
    // ImageType type = ImageType.single(GrayF32.class);
    JCodecSimplified sequence = new JCodecSimplified<>(fileName, type);
    BufferedImage out;
    if (sequence.hasNext()) {
        ImageBase frame = sequence.next();
        out = new BufferedImage(frame.width, frame.height, BufferedImage.TYPE_INT_RGB);
        ConvertBufferedImage.convertTo(frame, out, false);
    } else {
        throw new RuntimeException("No first frame?!?!");
    }
    ImagePanel gui = new ImagePanel(out);
    ShowImages.showWindow(gui, "Video!", true);
    long totalNano = 0;
    while (sequence.hasNext()) {
        long before = System.nanoTime();
        ImageBase frame = sequence.next();
        totalNano += System.nanoTime() - before;
        ConvertBufferedImage.convertTo(frame, out, false);
        gui.repaint();
        try {
            Thread.sleep(22);
        } catch (InterruptedException e) {
        }
    }
    System.out.println("Only read FPS = " + (totalNano / 1000000.0) / sequence.getFrameNumber());
}
Also used : JCodecSimplified(boofcv.io.jcodec.JCodecSimplified) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) ImageBase(boofcv.struct.image.ImageBase) ImageType(boofcv.struct.image.ImageType) ImagePanel(boofcv.gui.image.ImagePanel)

Aggregations

ImagePanel (boofcv.gui.image.ImagePanel)1 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)1 JCodecSimplified (boofcv.io.jcodec.JCodecSimplified)1 ImageBase (boofcv.struct.image.ImageBase)1 ImageType (boofcv.struct.image.ImageType)1 BufferedImage (java.awt.image.BufferedImage)1