We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm receiving a Syphon stream (Syphon library for Processing 1.0-RC1) and applying CPU intensive OpenCV (OpenCV for Processing 0.4.2) on it. But the received frames don't change very often. I would like to check, if the new frame is different from the last frame and only do further calculations on it, if it's really different from the last frame.
How can I check if these frames identical in the fastest way?
I tried stuff like that, but it always prints "true" no matter what.
PGraphics syphonInput;
PImage oldFrame;
…
syphonInput = syphonClient.getGraphics(syphonInput);
syphonInput.loadPixels();
if (oldFrame != null){
println(Arrays.equals(syphonInput.pixels, oldFrame.pixels));
}
oldFrame = syphonClient.getGraphics(syphonInput);
oldFrame.loadPixels();
Thanks!
Answers
Upps, found a mistake:
…
The comparison works now. But I still don't know, if this is the fastest way. Does anybody know?
If the library's dev(s) implemented both equals() & hashCode(),
you can use some of the same approach as a HashMap does,
like checking whether the object's changed its internal structure since its last state:
but Arrays.equals() will fail as soon as it finds a non-matching byte. hashing both means accessing each byte of both arrays and lots of maths...
You're right! For such heavy objects, hashCode() & equals() can be very slow indeed! :o3
Thanks for your answers!
Looked into the library and don't think there is some hashing implemented anyways.
Does that mean there might be a situation where this doesn't work? Seems to work now at least.
That means as soon it reads a byte (pixel) which isn't the same as the corresponding byte reading for the other array, it returns
false
immediately, skipping the rest of the other byte checks! ;))