比较android中的两个图像 [英] compare two images in android

查看:26
本文介绍了比较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?

比较第一张图片与第二张图片的像素到像素完全相同.

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

谢谢.

推荐答案

1. 检查高度是否匹配,如果不匹配返回false.然后,检查宽度是否匹配,如果不匹配,则返回 false.然后检查每个像素,直到找到不匹配的像素.当你这样做时,返回false.如果每个像素都匹配,则返回 true.

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.

伪代码:

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;
}

实际上,如果可以,您可能希望将图像视为二维数组,并且只比较字节.我不知道 Android 图像 API,但 getPixel 可能很慢.

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.也许您将图像转换为 byte64 字符串,然后进行比较.

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

3.**Android 的 OpenCV 库:
必须具有图像压缩功能

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

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

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

有关详细信息,请参阅比较两张图片

for more details see comparing two images

这篇关于比较android中的两个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆