ameingast / cocoaimagehashing

Perceptual Image Hashing for macOS, iOS, tvOS and watchOS
Other
262 stars 66 forks source link

I want to use Concurrent, stream based similarity search but don't understand how to do that. #23

Closed kuls14 closed 4 years ago

kuls14 commented 4 years ago

I want to use Concurrent, stream-based similarity search for finding similar images from all images in the phone gallery but I cannot understand how to do that. I have tried to use an array-based method but that takes too long to get all the image data in an array and causes memory management issues. If anyone knows this please help me.

ameingast commented 4 years ago

You can try the following in the project's playground:

var names = ["blurred_architecture1.bmp", "compressed_architecture1.jpg", "blurred_architecture_2.bmp", "compressed_architecture_2.jpg"]
let similarImages = imageHashing.similarImages(withProvider: .pHash) { () -> OSTuple<NSString, NSData>? in
   if names.count > 0 {
       let name = names.removeFirst()
       let url = Bundle.main.urlForImageResource(NSImage.Name(name))!
       let data = try! Data(contentsOf: url)
       return OSTuple<NSString, NSData>(first: name as NSString, andSecond: data as NSData)
   } else {
       return nil
   }
}
print("Images", similarImages)
kuls14 commented 4 years ago

Thanks.