简体   繁体   English

在Objective-C中比较ios中的多个图像

[英]compare multiple images in ios in objective-C

i am comparing images with each other here is the code for it. 我正在互相比较图像,这是它的代码。

for (int i=0; i<arrImageData.count; i++)
{
    for (int j=i+1; j<arrImageData.count; j++)
    {
        if ([arrImageData[i]isEqualToData:arrImageData[j]])
        {
            [arrImages addObject:arrImage[i]];
        }
    }
}

now problem is when number of images increase it takes too much time to calculate.is there any better solution for it? 现在的问题是,当图像数量增加时,要花费太多时间进行计算。是否有更好的解决方案?

you should use hashes to compare big amount of data 您应该使用散列来比较大量数据

1 you can compare UImage directrly: image1.hash == image2.hash 1您可以直接比较UImage:image1.hash == image2.hash

2 you can calculate your own hash for each image added to the array, it will be calculated once and used for every comparison 2您可以为添加到数组中的每个图像计算自己的哈希,它将被计算一次并用于每次比较

here is the hash algorithm https://en.wikipedia.org/wiki/MD5 这是哈希算法https://en.wikipedia.org/wiki/MD5

PS it will works if image data is absolutely equal, it much more difficult to compare two different images with one "content" Image comparison - fast algorithm PS,如果图像数据绝对相等,它将可以工作,将两个不同的图像与一个“内容”进行比较要困难得多。 图像比较-快速算法

I think you should use hashes for comparison. 我认为您应该使用哈希进行比较。 Refer this link: Generate hash from UIImage It will help you. 请参考此链接: 从UIImage生成哈希值将为您提供帮助。

you can try something like this: 您可以尝试这样的事情:

- (BOOL)image:(UIImage *)image1 isEqualTo:(UIImage *)image2{    
    return [UIImagePNGRepresentation(image1) isEqual:UIImagePNGRepresentation(image2)];
}

You can use Fast Enumeration as Below 您可以如下使用快速枚举

    for(UIImage *img in arrImageData)
    {
        for (UIImage *comImg in arrImageData) {
            if ([UIImageJPEGRepresentation(img, 0) isEqual:UIImageJPEGRepresentation(comImg, 0)]) {
                [arrImages addObject:img];
            }
        }
    }

Hope it helps you...! 希望它可以帮助您...!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM