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);
}
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));
}
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));
}
Aggregations