Aws-sdk-ios: Amazon Rekognition documentation in Swift

Created on 9 Jul 2018  路  7Comments  路  Source: aws-amplify/aws-sdk-ios

This is not an issue in aws-sdk-ios.

I am just trying to confirm if Amazon Rekognition SDK is available in Swift or ObjC?

I am currently referring this documentation - https://docs.aws.amazon.com/rekognition/latest/dg/.

It has Java, .NET, Python and AWS CLI. Any help would be greatly appreciated! Thank you! :)

rekognition requesting info

Most helpful comment

@anmolmalhotra

Here is a code sample

    let rekognition = AWSRekognition.default()

    let faceRequest = AWSRekognitionIndexFacesRequest()
    let image = AWSRekognitionImage()
    let s3Object = AWSRekognitionS3Object()
    s3Object?.bucket = "bucket"
    s3Object?.name = "image.jpg"
    image?.s3Object = s3Object

    faceRequest!.image = image
    faceRequest!.collectionId = "CollectionID"

    rekognition.indexFaces(faceRequest!).continueWith { (response) -> Any? in
       if let error = response.error {
            //handle error
       }
        else if let result = response.result {
            if let fr = result.faceRecords {
            //app logic here
            }
        }
        return nil
        }
}

All 7 comments

@anmolmalhotra

AWS Rekognition is supported as part of the Mobile SDK (see http://aws.github.io/aws-sdk-ios/docs/reference//Classes/AWSRekognition.html). It is implemented in Obejctive C, but you can use it both from Swift as well as Objective C.

Hey @cbommas, sorry for not being specific first. I am looking for Amazon Recognition iOS documentation. I found the available documentation in Java, .NET, Python and AWS CLI. Can you tell me where I can refer?

The url you sent me shows the list of methods, properties, classes. I have already referred to that and it was helpful to me but I am not sure if I am writing the code correctly because console keeps on printing this error to me:

If you're interested, this is the code I am writing to detect a face from a collection:

        let rekognition = AWSRekognition.default()

        let faceRequest = AWSRekognitionIndexFacesRequest()

        guard let faceReq = faceRequest else { return }

        let image = AWSRekognitionImage()
        let object = AWSRekognitionS3Object()
        object?.bucket = "bucket"
        object?.name = "face.jpg"
        image?.s3Object = object

        image!.bytes = UIImageJPEGRepresentation(UIImage(named: "face")!, 0.7)

        faceReq.image = image
        faceReq.collectionId = collectionId
        faceReq.externalImageId = "face.jpg"
        faceReq.detectionAttributes = ["ALL"]

        let result = rekognition.indexFaces(faceReq)

        print(result)

        if let result = result.result?.faceRecords {
            result.forEach { print($0) }
        } else {
            print(result.error)
        }

It'll be really helpful if you can show me only 1 sample regarding the recognition APIs.

@anmolmalhotra

Here is a code sample

    let rekognition = AWSRekognition.default()

    let faceRequest = AWSRekognitionIndexFacesRequest()
    let image = AWSRekognitionImage()
    let s3Object = AWSRekognitionS3Object()
    s3Object?.bucket = "bucket"
    s3Object?.name = "image.jpg"
    image?.s3Object = s3Object

    faceRequest!.image = image
    faceRequest!.collectionId = "CollectionID"

    rekognition.indexFaces(faceRequest!).continueWith { (response) -> Any? in
       if let error = response.error {
            //handle error
       }
        else if let result = response.result {
            if let fr = result.faceRecords {
            //app logic here
            }
        }
        return nil
        }
}

@anmolmalhotra

Just checking back to see if you had any further questions.

@cbommas Thanks for your help!! It worked perfectly and my app is already live in review! Thank you again. 馃憤

@anmolmalhotra

Hi I got this error AWS Rekognition.

guard let request = AWSRekognitionIndexFacesRequest()
        else {
            return
    }
    let image = AWSRekognitionImage()
    let s3Object = AWSRekognitionS3Object()
    s3Object?.bucket = "bucket"
    s3Object?.name = "img.jpg"
    image?.s3Object = s3Object
    request.maxFaces = 3
    request.image = image
    request.collectionId = collectionId
    let rekognitionClient = AWSRekognition.default()
    rekognitionClient.indexFaces(request).continueWith { (response) -> Any? in
        if response.error != nil {
        }
        else if let result = response.result {
            if result.faceRecords != nil {
            }
        }
        return nil
    }

Error :

@anmolmalhotra
tried to implement AWSRekognitionCreateCollectionRequest
got this error : not authorized to perform: rekognition:CreateCollection on resource:

Was this page helpful?
0 / 5 - 0 ratings