Compare two images in android

In my application, I want to capture two images using a camera, and then I want to compare these images.

So how can I compare two images?

EDIT: Comparison The first image is as accurate as the second image pixel for a pixel.

Thanks.

+8
android image-processing
source share
2 answers

1. Make sure the height matches if it doesn't return false. Then check if the width matches, and if not, return false. Then check each pixel until you find one that doesn't match. When you do, return false. If each pixel matches, return true.

pseudo code:

bool imagesAreEqual(Image i1, Image i2) { if (i1.getHeight() != i2.getHeight()) return false; if (i1.getWidth() != i2.getWidth()) return false; for (int y = 0; y < i1.getHeight(); ++y) for (int x = 0; x < i1.getWidth(); ++x) if (i1.getPixel(x, y) != i2.getPixel(x, y)) return false; return true; } 

in fact, you probably want to treat the image as a two-dimensional array if you can, and just compare the bytes. I don't know the image API for Android, but getPixel can be slow.

2. Perhaps you convert images to byte64 strings and then compare them.

3. * * OpenCV lib for Android:
have functions for compressing images

** a. Core.absdiff() b. Core.compare()

For more details see comparison of two images.

+6
source share

All Articles