So I've been trying to use the AWSRekognition SDK in order to detect faces and labels in images. However, Amazon has no Documentation on how to integrate their SDK with iOS. They have links that show how to work with Rekognition (Developer Guide) with examples only in Java and very limited.
Amazon Rekognition Developer Guide
If you click on their "iOS Documentation", it takes you to the general iOS documentation page, with no signs of Rekognition in any section.
I wanted to know if anyone knows how to integrate AWS Rekognition in Swift 3. How to Initialize it and make a request with an image, receiving a response with the labels.
I already downloaded the AWSRekognition.framework
and the AWSCore.framework
and added them into my project. Also I have imported both of them in my AppDelegate.swift
and initialized my AWS Credentials.
let credentialsProvider = AWSCognitoCredentialsProvider(
regionType: AWSRegionType.usEast1,
identityPoolId: "us-east-1_myPoolID")
let configuration = AWSServiceConfiguration(
region: AWSRegionType.usEast1,
credentialsProvider: credentialsProvider)
AWSServiceManager.default().defaultServiceConfiguration = configuration
Also I've tried to initialize Rekognition and build a Request:
do {
let rekognitionClient:AWSRekognition = AWSRekognition(forKey: "Maybe a Key from AWS?")
let request: AWSRekognitionDetectLabelsRequest = try AWSRekognitionDetectLabelsRequest(dictionary: ["image": UIImage(named:"TestImage")!, "maxLabels":3, "minConfidence":90], error: (print("error")))
rekognitionClient.detectLabels(request) { (response:AWSRekognitionDetectLabelsResponse?, error:Error?) in
if error == nil {
print(response!)
}
}
} catch {
print("Error")
}
Thanks a lot!
The documentation on the web for the Rekognition iOS SDK is lacking but the comments in the SDK code were pretty helpful for me. If you hold Cmd while clicking on a keyword in Xcode you should be able to find all the info you need in the comments.
From this you can see that the Key is referring to a previously registered client which you can do with
registerRekognitionWithConfiguration
, but you can skip all that by using the default as Karthik mentioned:I have been working with face detection so I haven't used
AWSRekognitionDetectLabelsRequest
in my own code, but I think where you might be going wrong is that theimage
property ofAWSRekognitionDetectLabelsRequest
should be anAWSRekognitionImage
and not aUIImage
like you are passing in. You can callUIImageJPEGRepresentation
to get the raw bytes from a UIImage.It should also be a lot easier to debug if you set the request properties individually like this too.