I am using the java wrapper of OpenCV. I tried to write an Iterator over frames of a film. My problem is that the iterator is a huge memory leak. Here is a very simplified v
I would modify your .hasNext method to:
public boolean hasNext() {
return hasNext;
}
And then the method you described, copied below, should work fine... You will iterate until nothing is left, at which point you can assign that last image to a new Mat object...
public Mat next() {
capture.retrieve(mat);
hasNext = capture.grab();
return mat;
}
and then:
final VideoCapture vc = new VideoCapture("/path/to/file");
final SimpleIt it = new SimpleIt(vc);
final Mat lastFrame = new Mat();
while (it.hasNext) {
lastFrame = it.next();
}
I do realize this creates additional memory usage. There is probably a way around this, but it should work fine...