ios - 如何在 Swift 3 中使用 AWS Rekognition 比较人脸
<p><p>我一直在尝试使用 AWSRekognition SDK 来比较人脸。但是,亚马逊没有关于如何将其 SDK 与 iOS 集成的文档。他们的链接展示了如何使用 Recognition (<a href="http://%20%20https://docs.aws.amazon.com/rekognition/latest/dg/what-is.html" rel="noreferrer noopener nofollow">Developer Guide</a>),其中的示例仅在 Java 中并且非常有限。</p>
<p>我想知道是否有人知道如何在 Swift 3 中集成 AWS Rekognition。如何初始化它并使用图像发出请求,接收带有标签的响应。 </p>
<p>我有 AWS 签名 AccessKey、SecretKey、AWS 区域、服务名称。还有 body </p>
<pre><code>{
"SourceImage": {
"S3Object": {
"Bucket": "bucketName",
"Name": "ios/sample.jpg"
}
},
"TargetImage": {
"S3Object": {
"Bucket": "buketName",
"Name": "ios/target.JPG"
}
}
}
</code></pre>
<p>如何初始化 Rekognition 并构建请求。</p>
<p>谢谢!</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><ol>
<li><p>实例化 Rekognition 客户端,这里我使用的是默认配置的客户端。</p>
<pre><code>let rekognitionClient:AWSRekognition = AWSRekognition.default()
</code></pre> </li>
</ol>
<p>否则,您可以按如下方式使用凭据:</p>
<pre><code> let credentialsProvider = AWSCognitoCredentialsProvider(
regionType: AWSRegionType.usEast2,
identityPoolId: "us-east-2_myPoolID")
let configuration = AWSServiceConfiguration(
region: AWSRegionType.usEast2,
credentialsProvider: credentialsProvider)
AWSServiceManager.default().defaultServiceConfiguration = configuration
let rekognitionClient:AWSRekognition = AWSRekognition.default()
</code></pre>
<ol 开始=“2”>
<li><p>现在构造请求并在其中设置图像。</p>
<pre><code>let image = UIImage(named: "MyImage")
let request = AWSRekognitionDetectLabelsRequest()
request.image = image
request.maxLabels = <num_labels_needed>
request.minConfidence = <confidence_interval_needed>
</code></pre> </li>
<li><p>现在要比较人脸,请阅读 CompareFacesRequest:<a href="https://github.com/aws/aws-sdk-ios/blob/master/AWSRekognition/AWSRekognitionService.m#L288" rel="noreferrer noopener nofollow">https://github.com/aws/aws-sdk-ios/blob/master/AWSRekognition/AWSRekognitionService.m#L288</a> </p></li>
</ol>
<p>SDK 中有一个示例测试,用于比较 ObjC 中的两个人脸,但您可以在 Swift 中进行翻译:</p>
<p> <a href="https://github.com/aws/aws-sdk-ios/blob/master/AWSRekognitionUnitTests/AWSGeneralRekognitionTests.m#L60" rel="noreferrer noopener nofollow">https://github.com/aws/aws-sdk-ios/blob/master/AWSRekognitionUnitTests/AWSGeneralRekognitionTests.m#L60</a> </p>
<pre><code> let key = "testCompareFaces"
let configuration = AWSServiceConfiguration(region: AWSRegionUSEast2, credentialsProvider: nil)
AWSRekognition.register(with: configuration, forKey: key)
AWSRekognition(for: key).compareFaces(AWSRekognitionCompareFacesRequest()).continue(withBlock: {(_ task: AWSTask) -> Any in
print("completed")
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何在 Swift 3 中使用 AWS Rekognition 比较人脸,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/46483447/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/46483447/
</a>
</p>
页:
[1]