OpenCV:VideoCapture :: get(CV_CAP_PROP_FPS)在java中不使用相机返回0 FPS直接视频输入

时间:2016-03-03 06:08:30

标签: java opencv netbeans

 VideoWriter videoWriter = new VideoWriter(outputFile, fourCC.toInt(), videoCapture.get(Videoio.CAP_PROP_FPS),
                    frameSize, true);

此返回的帧大小为0

1 个答案:

答案 0 :(得分:1)

解决方案首先,您尝试打开视频并检查是否成功打开,如下所示:

VideoCapture capture = new VideoCapture(filePath);
if(!capture.isOpened()) {
    System.out.println("Cannot open the video.");
    return;
}

如果没有返回,则表示已成功打开,现在您已阅读框架并显示或至少检查框架的高度和宽度,如下所示:

Mat frame = new Frame();
capture.read(frame);
int width = (int) capture.get(Videoio.CAP_PROP_FRAME_WIDTH);
int height = (int) capture.get(Videoio.CAP_PROP_FRAME_HEIGHT);
System.out.println("width = " + width );
System.out.println("height = " + height);

如果一切顺利,那就没关系,您可以使用capture并阅读相框,如果不能正常工作,请转到OpenCV解压缩的文件夹并复制此行

C:\opencv\build\x64\vc14\bin

Environment Variable并重新启动电脑,然后重试。