Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

compare two images in android

In my application I want to capture two images using camera and then I want to compare those images.

So, how can I compare two images?

EDIT: Compare First image is exact as second image pixel to pixel.

Thank You.

like image 233
user861973 Avatar asked Mar 19 '12 17:03

user861973


People also ask

How do you compare two images for similarity?

The similarity of the two images is detected using the package “imagehash”. If two images are identical or almost identical, the imagehash difference will be 0. Two images are more similar if the imagehash difference is closer to 0.

How can I compare two files in Android?

Go to file name in project then press control then select Compare File and select another file you wish to compare. Seperate window will open up showing differences by colour contrast.


1 Answers

1. Check that the height matches, if not 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 every pixel matches, return true.

Pseudocode:

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 reality, you probably want to treat the image as a two dimensional array if you can, and just compare bytes. I don't know the Android image API, but getPixel might be slow.

2. maybe you convert the images in to byte64 Strings and then compare them.

3.**OpenCV lib for Android :
have to functions for images compression

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

for more details see comparing two images

like image 115
ρяσѕρєя K Avatar answered Oct 11 '22 07:10

ρяσѕρєя K