【发布时间】:2020-08-13 10:05:22
【问题描述】:
当一切都在 Windows 10 上运行时,我也在使用 Java OpenJdk 14.0.2 和 OpenCV-440。我的 JavaFX 应用程序应该捕获网络摄像头(或任何其他视频设备)的帧并将这些帧存储为视频文件,例如 avi。
这是我的代码:
public void run() {
Mat frame = new Mat();
VideoCapture videoCapture = new VideoCapture(0);
videoCapture.read(frame);
Size frameSize = new Size((int) videoCapture.get(Videoio.CAP_PROP_FRAME_WIDTH), (int) videoCapture.get(Videoio.CAP_PROP_FRAME_HEIGHT));
int fourcc = VideoWriter.fourcc('x', '2','6','4');
VideoWriter writer = new VideoWriter();
//if myuniquefile%02d.jpg is using any kind of video extension instead, it is not working (e.g. avi)
writer.open("images/myuniquefile%02d.jpg", fourcc,
videoCapture.get(Videoio.CAP_PROP_FPS), frameSize, true);
while (isRunning) {
if (videoCapture.read(frame)) {
writer.write(frame);
}
}
videoCapture.release();
writer.release();
}
这段代码运行良好,但是一旦我将“.jpg”更改为 .avi 之类的扩展名,它就不再运行了。对于 VideoWriter.isOpened() 上面的代码,它返回 true,对于带有“.avi”的相同代码,它返回 false。我尝试了很多文件扩展名和编解码器(VideoWriter.fourcc)的组合,但它永远不会打开。
让我们继续我的设置,我使用的是 Intellij (2020.1.2),openCV 440 以这种方式链接:
唯一的附加库是 javafx-sdk-14.0.2.1
我一开始就使用这个example,但它从来没有对我起作用。 我非常感谢任何建议
BR迈克尔
【问题讨论】:
标签: java opencv video-capture