JAVACV videocapture read 停止拍摄新照片并重复拍摄同一张照片,为什么会这样?
JAVACV videocapture read stops taking new pictures and just repeats the same one, why is it doing this?
我目前正在使用 Java Open Cv Library 从相机拍摄一系列连续图像。然后将捕获的帧传递给另一个保存图像的线程。
但是,出于某种原因,在拍摄一定数量后,它会停止拍摄新图像,而只是重复上一张。
如果我要求它取 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 循环中,这确实解决了问题,但是它确实大大降低了性能,我认为它不必存在,直到它开始工作这个"breaking point".
如有任何反馈,我们将不胜感激。
我想我已经找到了解决办法。我移动了行
Mat frame = new Mat();
for 循环内部。
正因为如此,这意味着每次捕获帧时都会将其捕获到空帧上,这似乎可以解决问题。
我目前正在使用 Java Open Cv Library 从相机拍摄一系列连续图像。然后将捕获的帧传递给另一个保存图像的线程。 但是,出于某种原因,在拍摄一定数量后,它会停止拍摄新图像,而只是重复上一张。
如果我要求它取 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 循环中,这确实解决了问题,但是它确实大大降低了性能,我认为它不必存在,直到它开始工作这个"breaking point".
如有任何反馈,我们将不胜感激。
我想我已经找到了解决办法。我移动了行
Mat frame = new Mat();
for 循环内部。
正因为如此,这意味着每次捕获帧时都会将其捕获到空帧上,这似乎可以解决问题。