【问题标题】:Comparing two images whether same or not (iOS) [duplicate]比较两个图像是否相同(iOS)[重复]
【发布时间】:2012-12-29 02:50:45
【问题描述】:

可能重复:
How does one compare one image to another to see if they are similar by a certain percentage, on the iPhone?

我找到了这段代码并试图更好地理解它:

UIImage *img1 = // Some photo;
UIImage *img2 = // Some photo;

NSData *imgdata1 = UIImagePNGRepresentation(img1);

NSData *imgdata2 = UIImagePNGRepresentation(img2);

if ([imgdata1 isEqualToData:imgdata2]) {
    NSLog(@"Same Image");
}

这会确认图片 1 与图片 2 完全相同吗?这种方法是最佳实践,还是有更好的方法?

【问题讨论】:

  • “图 1 设计.. 开始编写你的第一个应用程序”
  • 你真的应该解决你的问题。如果您引用一本书,请明确说明,不要对Figure 1等进行无意义的引用
  • 当您使用 [UIImage imageWithContentsOfFile:YOUR_IMAGE_FILE_PATH] 而不是 [UIImage imageNamed:@"YOUR_IMAGE_NAME">] 设置图像时,这种比较非常有用,因为如果您使用文件路径设置图像并尝试比较它是行不通的,所以当时这种比较很有用。
  • 其实这是stackoverflow.com/questions/3400707/…的副本,而不是当前的副本。

标签: iphone objective-c ios


【解决方案1】:

您的代码正在逐位比较两个图像,所以是的,这是一个 100% 的比较。

如果您需要更快的东西,您可以从每个 UIImage 生成一个哈希并比较两个哈希,如 here 所述。

【讨论】:

  • 当您使用 [UIImage imageWithContentsOfFile:YOUR_IMAGE_FILE_PATH] 而不是 [UIImage imageNamed:@"YOUR_IMAGE_NAME">] 设置图像时,这种比较非常有用,因为如果您使用文件路径设置图像并尝试比较它是行不通的,所以当时这种比较很有用。
【解决方案2】:

看看这个链接,它谈到了对图像进行采样以查看相似度百分比:How does one compare one image to another to see if they are similar by a certain percentage, on the iPhone?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-22
    • 1970-01-01
    • 1970-01-01
    • 2021-05-31
    • 1970-01-01
    相关资源
    最近更新 更多