OpenCV mp4文件已关闭

时间:2019-02-01 11:57:55

标签: java opencv

我是OpenCV库的新手,目前正在尝试执行示例。 我正在从文件系统加载文件,并试图遍历框架。

Gradle配置:

dependencies {
   compile group: 'org.openpnp', name: 'opencv', version: '3.4.2-1'
}

示例:

public static void main(String args[]) {
    OpenCV.loadShared();
    VideoCapture camera = new VideoCapture();
    camera.open("C:\\Data\\OpenCV\\recognition\\src\\main\\resources\\example.mp4"); //tried many other ways to load file

    if(!camera.isOpened()){
        System.out.println("Error");
    }
    else {
        try {
            int index = 0;
            Mat frame = new Mat();
            while (true) {
                if (camera.read(frame)) {
                    System.out.println("Captured Frame Width " + frame.width() + " Height " + frame.height());
                    Imgcodecs.imwrite("camera" + (index++) + ".jpg", frame);
                    System.out.println("OK");
                }
            }
        } catch (Exception ex){
            System.out.println("Error occured "+ ex);
        }
    }
    camera.release();
}

但是,相机文件始终关闭。我在做什么错了?

0 个答案:

没有答案