我目前正在使用 Java Open Cv 库从相机拍摄一系列连续图像。然后,捕获的帧将传递到另一个保存图像的线程。 但是,由于某种原因,在花费一定数量后,它会停止拍摄新图像,而只是重复前一个图像。
如果我要求它取 10,它会停在 5,而 20 它会停在 11,所以每次的值都不相同。
代码当前位于线程内部,但我认为这不会以任何方式影响它。
这是当前代码。
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
VideoCapture camera = new VideoCapture(0);
camera.open(0);
Mat frame = new Mat();
for (int i = 0; i < 20; i++) {
camera.read(frame);
fileName = "Captures/" + timetoNano + ".png";
fileTime = timetoNano;
fileToSave = frame;
ImageProperties newProperties = new ImageProperties(fileName,
fileToSave, fileTime);
bufferImageProps.add(newProperties);
}
如果我把 camera.open(0) 放在 for 循环中,这确实解决了这个问题,但它确实大大降低了性能,我认为它不必在那里,因为它一直工作到这个"突破点"。
任何反馈将不胜感激。
我已经找到了解决方案。我移动了线
Mat frame = new Mat();
在 for 循环内。
因此,这意味着每次捕获帧时,您都会将其捕获到空帧上,这似乎可以解决问题。