【问题标题】:Image Comparison in an androidandroid中的图像比较
【发布时间】:2023-03-11 04:00:01
【问题描述】:

我在 android 中有如下要求,

从安卓手机的相机或图库中读取图像。 将此图像与存储在数据库中的图像(任何有效格式)进行比较。 显示图像之间的匹配百分比。

告诉我实现它的可能方法。

【问题讨论】:

  • 请分享您尝试过的代码
  • @Sharan 可以查看此链接并回复我rosettacode.org/wiki/Percentage_difference_between_images#Java
  • 绝对有可能,使用不同的机器学习模型
  • 是的,还要检查@WebInsight 评论。它会帮助你。
  • @Weblnsight 我试过了,但问题是我有不同大小的图像

标签: android face-recognition image-comparison


【解决方案1】:

首先你必须比较图像的高度和宽度..如果它相同,那么你必须比较字节像素。

检查高度和宽度。

if (image1.getHeight() != image2.getHeight()){
 return false;
}
 if (image1.getWidth() != image2.getWidth()){
 return false;
}

然后检查图像像素

for (int i = 0; i < image1.getWidth(); i++)
    {
        for (int j = 0; j < image1.getHeight(); j++)
        {
            if (image1.getPixel(i,j) == image2.getPixel(i,j))
            {
               // Do whatever you want Correct Image.. // both image Are Same
            }
            else
            {
                // both image Are diffrent
            }
        }
    }

完整代码的样子

if (image1.getHeight() != image2.getHeight()){
    isImageSame = false;
    return;
}
if (image1.getWidth() != image2.getWidth()){
    isImageSame = false;
    return;
}


if(isImageSame){

for (int i = 0; i < image1.getWidth(); i++)
    {
        for (int j = 0; j < image1.getHeight(); j++)
        {
            if (image1.getPixel(i,j) == image2.getPixel(i,j))
            {
               // Do whatever you want Correct Image.. // both image Are Same
            }
            else
            {
                // both image Are diffrent
            }
        }
    }
}

你也可以通过 OpenCV 库来做到这一点 也可以在这里找到很好的例子https://github.com/opencv/opencv/tree/master/samples/android/face-detection

【讨论】:

  • @SharanBallundagi 请在您的问题中添加有关您的图像和一些代码的所有描述,以便人们能够对您的问题给出适当的答案。
猜你喜欢
  • 2015-10-27
  • 2011-09-01
  • 2013-01-29
  • 1970-01-01
  • 2012-04-04
  • 2016-09-19
  • 1970-01-01
  • 2023-03-07
相关资源
最近更新 更多