我是OpenCV库的新手,目前正在尝试执行一个示例。
我正在从文件系统加载一个文件,并尝试在帧之间循环。
梯度配置:
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();
}
但是,相机文件总是关闭的。我做错什么了?