Search in sources :

Example 1 with VideoCapture

use of org.opencv.videoio.VideoCapture in project Frankenstein by olir.

the class VideoInput method open.

@Override
public void open(ProcessingListener l) {
    movie = new VideoCapture(videofile);
    if (!movie.isOpened()) {
        String path = System.getProperty("OPENH264_LIBRARY_PATH");
        if (path == null)
            System.out.println("Warning: OPENH264_LIBRARY_PATH not set. Input Movie Opening Error for " + videofile);
        throw new RuntimeException("Input Movie Opening Error for " + videofile + ". Current path=" + new File(".").getAbsolutePath());
    }
    currentFrame = new Mat();
    currentPos = 0;
    grab();
    currentFrame = retrieve(currentFrame, l);
    frames = (int) movie.get(Videoio.CAP_PROP_FRAME_COUNT);
    fps = movie.get(Videoio.CAP_PROP_FPS);
    width = (int) movie.get(Videoio.CAP_PROP_FRAME_WIDTH);
    height = (int) movie.get(Videoio.CAP_PROP_FRAME_HEIGHT);
}
Also used : Mat(org.opencv.core.Mat) File(java.io.File) VideoCapture(org.opencv.videoio.VideoCapture)

Example 2 with VideoCapture

use of org.opencv.videoio.VideoCapture in project Frankenstein by olir.

the class CameraInput method open.

@Override
public void open(ProcessingListener l) {
    movie = new VideoCapture(id);
    if (!movie.isOpened()) {
        throw new RuntimeException("Camera Opening Error for #" + id);
    }
    currentFrame = new Mat();
    grab();
    currentFrame = retrieve(currentFrame, l);
    width = (int) movie.get(Videoio.CAP_PROP_FRAME_WIDTH);
    height = (int) movie.get(Videoio.CAP_PROP_FRAME_HEIGHT);
    frames = 1;
    currentPos = 0;
    timer = new Timer();
    timer.schedule(new TimerTask() {

        @Override
        public void run() {
            currentPos++;
            frames++;
            currentFrame = retrieve(currentFrame, l);
            l.nextFrameLoaded(CameraInput.this);
        }
    }, 0, (int) (1000.0 / fps));
}
Also used : Mat(org.opencv.core.Mat) Timer(java.util.Timer) TimerTask(java.util.TimerTask) VideoCapture(org.opencv.videoio.VideoCapture)

Example 3 with VideoCapture

use of org.opencv.videoio.VideoCapture in project Frankenstein by olir.

the class StreamInput method open.

@Override
public void open(ProcessingListener l) {
    boolean record = videofilename != null;
    if (record) {
        // Save stream to file
        process = executeCommand(commandBuffer);
        try {
            while (!videofile.exists()) {
                Thread.sleep(250L);
            }
            System.out.println("Streaming to " + videofile.getAbsolutePath());
            // open file
            movie = new VideoCapture(videofile.getAbsolutePath());
            while (!movie.isOpened()) {
                movie.release();
                Thread.sleep(250L);
                movie = new VideoCapture(videofile.getAbsolutePath());
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    } else {
        // open stream capture
        movie = new VideoCapture(streamurl);
        if (!movie.isOpened()) {
            throw new RuntimeException("Error opening stream " + streamurl);
        }
    }
    currentFrame = new Mat();
    currentPos = 0;
    grab();
    currentFrame = retrieve(currentFrame, l);
    frames = 1;
    fps = movie.get(Videoio.CAP_PROP_FPS);
    width = (int) movie.get(Videoio.CAP_PROP_FRAME_WIDTH);
    height = (int) movie.get(Videoio.CAP_PROP_FRAME_HEIGHT);
    System.out.println("open:  " + width + "x" + height);
    // stream from file
    timer = new Timer();
    timer.schedule(new TimerTask() {

        @Override
        public void run() {
            try {
                Thread.sleep((int) (1000.0 / fps));
            } catch (InterruptedException e) {
            }
            if (!grab()) {
                System.out.println("grab failed");
                return;
            }
            currentPos++;
            frames++;
            currentFrame = retrieve(currentFrame, l);
            l.nextFrameLoaded(StreamInput.this);
        }
    }, 2000, (int) (1000.0 / fps));
}
Also used : Mat(org.opencv.core.Mat) Timer(java.util.Timer) TimerTask(java.util.TimerTask) VideoCapture(org.opencv.videoio.VideoCapture)

Aggregations

Mat (org.opencv.core.Mat)3 VideoCapture (org.opencv.videoio.VideoCapture)3 Timer (java.util.Timer)2 TimerTask (java.util.TimerTask)2 File (java.io.File)1