|
I'm working on a hobby project in which two images get compared to each other and the similarity between these two images is calculated. My current implantation is pretty straightforward; The two images are drawn on screen and then glReadPixels() is used to get the bytebuffer for each image. Using the bytebuffers, the error value for each pixel is computed.
This approach works, but the problem is that two calls to glReadPixels absolutely kills performance. I did some googling and came across two solutions: 1. Use pixel buffer objects, but performance doesn't seem to be great for these either. 2. Use EGLImage, problem with this approach is that one of the images isn't really an image but rather a collection of polygons drawn directly on screen.
So now my question is, what would be the best approach to comparing two images and still have an acceptable performance?
For reference, my current code:
public void evaluate()
{
ByteBuffer bbOrigin = getBytebuffer(imageBounds[0][0], imageBounds[0][1], imageBounds[0][2], imageBounds[0][3]);
ByteBuffer bbCurrent = getBytebuffer(imageBounds[1][0], imageBounds[1][1], imageBounds[1][2], imageBounds[1][3]);
int error = 0;
while(bbOrigin.hasRemaining() && bbCurrent.hasRemaining())
{
error += Math.abs(bbOrigin.get() - bbCurrent.get());
}
}
private ByteBuffer getBytebuffer(int x1, int y1, int x2, int y2)
{
int width = (x2 - x1);
int height = (y2 - y1);
ByteBuffer bb = ByteBuffer.allocate(4 * width * height);
gl.glReadPixels(x1, y1, width, height, GL2.GL_RGBA, GL2.GL_BYTE, bb);
return bb;
}
|