aws-amplify / aws-sdk-ios

AWS SDK for iOS. For more information, see our web site:
https://aws-amplify.github.io/docs
Other
1.68k stars 885 forks source link

Amazon Rekognition documentation in Swift #987

Closed anmolmalhotra closed 6 years ago

anmolmalhotra commented 6 years ago

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! :)

scb01 commented 6 years ago

@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.

anmolmalhotra commented 6 years ago

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:

<AWSTask: 0x600000472dc0; completed = NO; cancelled = NO; faulted = NO;>

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.

scb01 commented 6 years ago

@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
        }
}
scb01 commented 6 years ago

@anmolmalhotra

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

anmolmalhotra commented 6 years ago

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

ymurali commented 5 years ago

@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 : <AWSTask: 0x2802a2240; completed = YES; cancelled = NO; faulted = YES; result = (null)>

ymurali commented 5 years ago

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