【问题标题】:Search iOS photos by keyword?按关键字搜索 iOS 照片?
【发布时间】:2020-02-07 04:04:24
【问题描述】:

Apple 的照片应用程序允许用户使用“冲浪”、“食物”、“天空”等搜索关键字查询照片。

具有相机和照片权限的第三方 iOS 应用如何使用任意字符串搜索手机的相机胶卷?

Searching for Photos is part of the SiriKit API。我们可以传递字符串作为一种可能的方法还是有更好的方法?

【问题讨论】:

    标签: ios react-native search photo photokit


    【解决方案1】:

    即使经过更长时间的研究,我也找不到方法。但好消息是,您可以使用与在照片应用程序中实现结果完全相同的神经网络来构建您自己的搜索索引。下面是一些示例代码:

    let fetchOptions = PHFetchOptions()           
    let fetchResult = PHAsset.fetchAssets(with: fetchOptions)
    fetchResult.enumerateObjects { asset, index, pointer in
        self.assetManager.requestImage(for: asset,
                                       targetSize: CGSize(width: 150, height: 100), 
                                       contentMode: .aspectFit, 
                                       options: .none) { image, metadata in
                if let uiImage = image, let cgImage = uiImage.cgImage {
                    let requestHandler = VNImageRequestHandler(cgImage: cgImage)
                    let request = VNClassifyImageRequest()
                    try? requestHandler.perform([request])
                    let results = request.results as! [VNClassificationObservation]
                    // Filter the 1303 classification results, and use them in your app
                    // in my case, fullfill promise with a wrapper object
                    promise(.success(ClassifiedImage(imageIdentifier: asset.localIdentifier,
                                    classifications: results.filter { $0.hasMinimumPrecision(0.9, forRecall: 0.0) }.map{
                                        ($0.identifier, nil)
                                        })))
                }
    
            }
    }
    

    更多信息:https://developer.apple.com/videos/play/wwdc2019/222

    另请注意:在构建搜索索引时,您可以在获取资产时使用 PHAsset 类的 localIdentifier

    【讨论】:

      猜你喜欢
      • 2019-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-09
      • 1970-01-01
      • 1970-01-01
      • 2012-07-24
      • 1970-01-01
      相关资源
      最近更新 更多