rclone/vendor/github.com/aws/aws-sdk-go/service/rekognition/examples_test.go

532 lines
19 KiB
Go
Raw Normal View History

// Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT.
package rekognition_test
import (
"fmt"
2017-07-23 09:51:42 +02:00
"strings"
"time"
"github.com/aws/aws-sdk-go/aws"
2017-07-23 09:51:42 +02:00
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/rekognition"
)
var _ time.Duration
2017-07-23 09:51:42 +02:00
var _ strings.Reader
var _ aws.Config
2017-07-23 09:51:42 +02:00
func parseTime(layout, value string) *time.Time {
t, err := time.Parse(layout, value)
if err != nil {
panic(err)
}
return &t
}
2017-07-23 09:51:42 +02:00
// To compare two images
//
// This operation compares the largest face detected in the source image with each face
// detected in the target image.
func ExampleRekognition_CompareFaces_shared00() {
svc := rekognition.New(session.New())
input := &rekognition.CompareFacesInput{
SimilarityThreshold: aws.Float64(90.000000),
SourceImage: &rekognition.Image{
S3Object: &rekognition.S3Object{
2017-07-23 09:51:42 +02:00
Bucket: aws.String("mybucket"),
Name: aws.String("mysourceimage"),
},
},
2017-07-23 09:51:42 +02:00
TargetImage: &rekognition.Image{
S3Object: &rekognition.S3Object{
2017-07-23 09:51:42 +02:00
Bucket: aws.String("mybucket"),
Name: aws.String("mytargetimage"),
},
},
}
2017-07-23 09:51:42 +02:00
result, err := svc.CompareFaces(input)
if err != nil {
2017-07-23 09:51:42 +02:00
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case rekognition.ErrCodeInvalidParameterException:
fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error())
case rekognition.ErrCodeInvalidS3ObjectException:
fmt.Println(rekognition.ErrCodeInvalidS3ObjectException, aerr.Error())
case rekognition.ErrCodeImageTooLargeException:
fmt.Println(rekognition.ErrCodeImageTooLargeException, aerr.Error())
case rekognition.ErrCodeAccessDeniedException:
fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error())
case rekognition.ErrCodeInternalServerError:
fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error())
case rekognition.ErrCodeThrottlingException:
fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error())
case rekognition.ErrCodeProvisionedThroughputExceededException:
fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error())
case rekognition.ErrCodeInvalidImageFormatException:
fmt.Println(rekognition.ErrCodeInvalidImageFormatException, aerr.Error())
default:
fmt.Println(aerr.Error())
}
} else {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
}
return
}
2017-07-23 09:51:42 +02:00
fmt.Println(result)
}
2017-07-23 09:51:42 +02:00
// To create a collection
//
// This operation creates a Rekognition collection for storing image data.
func ExampleRekognition_CreateCollection_shared00() {
svc := rekognition.New(session.New())
input := &rekognition.CreateCollectionInput{
CollectionId: aws.String("myphotos"),
}
2017-07-23 09:51:42 +02:00
result, err := svc.CreateCollection(input)
if err != nil {
2017-07-23 09:51:42 +02:00
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case rekognition.ErrCodeInvalidParameterException:
fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error())
case rekognition.ErrCodeAccessDeniedException:
fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error())
case rekognition.ErrCodeInternalServerError:
fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error())
case rekognition.ErrCodeThrottlingException:
fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error())
case rekognition.ErrCodeProvisionedThroughputExceededException:
fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error())
case rekognition.ErrCodeResourceAlreadyExistsException:
fmt.Println(rekognition.ErrCodeResourceAlreadyExistsException, aerr.Error())
default:
fmt.Println(aerr.Error())
}
} else {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
}
return
}
2017-07-23 09:51:42 +02:00
fmt.Println(result)
}
2017-07-23 09:51:42 +02:00
// To delete a collection
//
// This operation deletes a Rekognition collection.
func ExampleRekognition_DeleteCollection_shared00() {
svc := rekognition.New(session.New())
input := &rekognition.DeleteCollectionInput{
CollectionId: aws.String("myphotos"),
}
2017-07-23 09:51:42 +02:00
result, err := svc.DeleteCollection(input)
if err != nil {
2017-07-23 09:51:42 +02:00
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case rekognition.ErrCodeInvalidParameterException:
fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error())
case rekognition.ErrCodeAccessDeniedException:
fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error())
case rekognition.ErrCodeInternalServerError:
fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error())
case rekognition.ErrCodeThrottlingException:
fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error())
case rekognition.ErrCodeProvisionedThroughputExceededException:
fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error())
case rekognition.ErrCodeResourceNotFoundException:
fmt.Println(rekognition.ErrCodeResourceNotFoundException, aerr.Error())
default:
fmt.Println(aerr.Error())
}
} else {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
}
return
}
2017-07-23 09:51:42 +02:00
fmt.Println(result)
}
2017-07-23 09:51:42 +02:00
// To delete a face
//
// This operation deletes one or more faces from a Rekognition collection.
func ExampleRekognition_DeleteFaces_shared00() {
svc := rekognition.New(session.New())
input := &rekognition.DeleteFacesInput{
CollectionId: aws.String("myphotos"),
FaceIds: []*string{
aws.String("ff43d742-0c13-5d16-a3e8-03d3f58e980b"),
},
}
2017-07-23 09:51:42 +02:00
result, err := svc.DeleteFaces(input)
if err != nil {
2017-07-23 09:51:42 +02:00
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case rekognition.ErrCodeInvalidParameterException:
fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error())
case rekognition.ErrCodeAccessDeniedException:
fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error())
case rekognition.ErrCodeInternalServerError:
fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error())
case rekognition.ErrCodeThrottlingException:
fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error())
case rekognition.ErrCodeProvisionedThroughputExceededException:
fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error())
case rekognition.ErrCodeResourceNotFoundException:
fmt.Println(rekognition.ErrCodeResourceNotFoundException, aerr.Error())
default:
fmt.Println(aerr.Error())
}
} else {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
}
return
}
2017-07-23 09:51:42 +02:00
fmt.Println(result)
}
2017-07-23 09:51:42 +02:00
// To detect faces in an image
//
// This operation detects faces in an image stored in an AWS S3 bucket.
func ExampleRekognition_DetectFaces_shared00() {
svc := rekognition.New(session.New())
input := &rekognition.DetectFacesInput{
Image: &rekognition.Image{
S3Object: &rekognition.S3Object{
2017-07-23 09:51:42 +02:00
Bucket: aws.String("mybucket"),
Name: aws.String("myphoto"),
},
},
}
2017-07-23 09:51:42 +02:00
result, err := svc.DetectFaces(input)
if err != nil {
2017-07-23 09:51:42 +02:00
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case rekognition.ErrCodeInvalidS3ObjectException:
fmt.Println(rekognition.ErrCodeInvalidS3ObjectException, aerr.Error())
case rekognition.ErrCodeInvalidParameterException:
fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error())
case rekognition.ErrCodeImageTooLargeException:
fmt.Println(rekognition.ErrCodeImageTooLargeException, aerr.Error())
case rekognition.ErrCodeAccessDeniedException:
fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error())
case rekognition.ErrCodeInternalServerError:
fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error())
case rekognition.ErrCodeThrottlingException:
fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error())
case rekognition.ErrCodeProvisionedThroughputExceededException:
fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error())
case rekognition.ErrCodeInvalidImageFormatException:
fmt.Println(rekognition.ErrCodeInvalidImageFormatException, aerr.Error())
default:
fmt.Println(aerr.Error())
}
} else {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
}
return
}
2017-07-23 09:51:42 +02:00
fmt.Println(result)
}
2017-07-23 09:51:42 +02:00
// To detect labels
//
// This operation detects labels in the supplied image
func ExampleRekognition_DetectLabels_shared00() {
svc := rekognition.New(session.New())
input := &rekognition.DetectLabelsInput{
Image: &rekognition.Image{
S3Object: &rekognition.S3Object{
2017-07-23 09:51:42 +02:00
Bucket: aws.String("mybucket"),
Name: aws.String("myphoto"),
},
},
2017-07-23 09:51:42 +02:00
MaxLabels: aws.Int64(123),
MinConfidence: aws.Float64(70.000000),
}
2017-07-23 09:51:42 +02:00
result, err := svc.DetectLabels(input)
if err != nil {
2017-07-23 09:51:42 +02:00
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case rekognition.ErrCodeInvalidS3ObjectException:
fmt.Println(rekognition.ErrCodeInvalidS3ObjectException, aerr.Error())
case rekognition.ErrCodeInvalidParameterException:
fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error())
case rekognition.ErrCodeImageTooLargeException:
fmt.Println(rekognition.ErrCodeImageTooLargeException, aerr.Error())
case rekognition.ErrCodeAccessDeniedException:
fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error())
case rekognition.ErrCodeInternalServerError:
fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error())
case rekognition.ErrCodeThrottlingException:
fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error())
case rekognition.ErrCodeProvisionedThroughputExceededException:
fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error())
case rekognition.ErrCodeInvalidImageFormatException:
fmt.Println(rekognition.ErrCodeInvalidImageFormatException, aerr.Error())
default:
fmt.Println(aerr.Error())
}
} else {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
}
return
}
2017-07-23 09:51:42 +02:00
fmt.Println(result)
}
2017-07-23 09:51:42 +02:00
// To add a face to a collection
//
// This operation detects faces in an image and adds them to the specified Rekognition
// collection.
func ExampleRekognition_IndexFaces_shared00() {
svc := rekognition.New(session.New())
input := &rekognition.IndexFacesInput{
CollectionId: aws.String("myphotos"),
ExternalImageId: aws.String("myphotoid"),
Image: &rekognition.Image{
S3Object: &rekognition.S3Object{
2017-07-23 09:51:42 +02:00
Bucket: aws.String("mybucket"),
Name: aws.String("myphoto"),
},
},
}
2017-07-23 09:51:42 +02:00
result, err := svc.IndexFaces(input)
if err != nil {
2017-07-23 09:51:42 +02:00
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case rekognition.ErrCodeInvalidS3ObjectException:
fmt.Println(rekognition.ErrCodeInvalidS3ObjectException, aerr.Error())
case rekognition.ErrCodeInvalidParameterException:
fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error())
case rekognition.ErrCodeImageTooLargeException:
fmt.Println(rekognition.ErrCodeImageTooLargeException, aerr.Error())
case rekognition.ErrCodeAccessDeniedException:
fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error())
case rekognition.ErrCodeInternalServerError:
fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error())
case rekognition.ErrCodeThrottlingException:
fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error())
case rekognition.ErrCodeProvisionedThroughputExceededException:
fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error())
case rekognition.ErrCodeResourceNotFoundException:
fmt.Println(rekognition.ErrCodeResourceNotFoundException, aerr.Error())
case rekognition.ErrCodeInvalidImageFormatException:
fmt.Println(rekognition.ErrCodeInvalidImageFormatException, aerr.Error())
default:
fmt.Println(aerr.Error())
}
} else {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
}
return
}
2017-07-23 09:51:42 +02:00
fmt.Println(result)
}
2017-07-23 09:51:42 +02:00
// To list the collections
//
// This operation returns a list of Rekognition collections.
func ExampleRekognition_ListCollections_shared00() {
svc := rekognition.New(session.New())
input := &rekognition.ListCollectionsInput{}
2017-07-23 09:51:42 +02:00
result, err := svc.ListCollections(input)
if err != nil {
2017-07-23 09:51:42 +02:00
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case rekognition.ErrCodeInvalidParameterException:
fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error())
case rekognition.ErrCodeAccessDeniedException:
fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error())
case rekognition.ErrCodeInternalServerError:
fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error())
case rekognition.ErrCodeThrottlingException:
fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error())
case rekognition.ErrCodeProvisionedThroughputExceededException:
fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error())
case rekognition.ErrCodeInvalidPaginationTokenException:
fmt.Println(rekognition.ErrCodeInvalidPaginationTokenException, aerr.Error())
case rekognition.ErrCodeResourceNotFoundException:
fmt.Println(rekognition.ErrCodeResourceNotFoundException, aerr.Error())
default:
fmt.Println(aerr.Error())
}
} else {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
}
return
}
2017-07-23 09:51:42 +02:00
fmt.Println(result)
}
2017-07-23 09:51:42 +02:00
// To list the faces in a collection
//
// This operation lists the faces in a Rekognition collection.
func ExampleRekognition_ListFaces_shared00() {
svc := rekognition.New(session.New())
input := &rekognition.ListFacesInput{
CollectionId: aws.String("myphotos"),
MaxResults: aws.Int64(20),
}
2017-07-23 09:51:42 +02:00
result, err := svc.ListFaces(input)
if err != nil {
2017-07-23 09:51:42 +02:00
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case rekognition.ErrCodeInvalidParameterException:
fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error())
case rekognition.ErrCodeAccessDeniedException:
fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error())
case rekognition.ErrCodeInternalServerError:
fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error())
case rekognition.ErrCodeThrottlingException:
fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error())
case rekognition.ErrCodeProvisionedThroughputExceededException:
fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error())
case rekognition.ErrCodeInvalidPaginationTokenException:
fmt.Println(rekognition.ErrCodeInvalidPaginationTokenException, aerr.Error())
case rekognition.ErrCodeResourceNotFoundException:
fmt.Println(rekognition.ErrCodeResourceNotFoundException, aerr.Error())
default:
fmt.Println(aerr.Error())
}
} else {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
}
return
}
2017-07-23 09:51:42 +02:00
fmt.Println(result)
}
2017-07-23 09:51:42 +02:00
// To delete a face
//
// This operation searches for matching faces in the collection the supplied face belongs
// to.
func ExampleRekognition_SearchFaces_shared00() {
svc := rekognition.New(session.New())
input := &rekognition.SearchFacesInput{
CollectionId: aws.String("myphotos"),
FaceId: aws.String("70008e50-75e4-55d0-8e80-363fb73b3a14"),
FaceMatchThreshold: aws.Float64(90.000000),
MaxFaces: aws.Int64(10),
}
2017-07-23 09:51:42 +02:00
result, err := svc.SearchFaces(input)
if err != nil {
2017-07-23 09:51:42 +02:00
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case rekognition.ErrCodeInvalidParameterException:
fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error())
case rekognition.ErrCodeAccessDeniedException:
fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error())
case rekognition.ErrCodeInternalServerError:
fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error())
case rekognition.ErrCodeThrottlingException:
fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error())
case rekognition.ErrCodeProvisionedThroughputExceededException:
fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error())
case rekognition.ErrCodeResourceNotFoundException:
fmt.Println(rekognition.ErrCodeResourceNotFoundException, aerr.Error())
default:
fmt.Println(aerr.Error())
}
} else {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
}
return
}
2017-07-23 09:51:42 +02:00
fmt.Println(result)
}
2017-07-23 09:51:42 +02:00
// To search for faces matching a supplied image
//
// This operation searches for faces in a Rekognition collection that match the largest
// face in an S3 bucket stored image.
func ExampleRekognition_SearchFacesByImage_shared00() {
svc := rekognition.New(session.New())
input := &rekognition.SearchFacesByImageInput{
CollectionId: aws.String("myphotos"),
FaceMatchThreshold: aws.Float64(95.000000),
Image: &rekognition.Image{
S3Object: &rekognition.S3Object{
2017-07-23 09:51:42 +02:00
Bucket: aws.String("mybucket"),
Name: aws.String("myphoto"),
},
},
2017-07-23 09:51:42 +02:00
MaxFaces: aws.Int64(5),
}
2017-07-23 09:51:42 +02:00
result, err := svc.SearchFacesByImage(input)
if err != nil {
2017-07-23 09:51:42 +02:00
if aerr, ok := err.(awserr.Error); ok {
switch aerr.Code() {
case rekognition.ErrCodeInvalidS3ObjectException:
fmt.Println(rekognition.ErrCodeInvalidS3ObjectException, aerr.Error())
case rekognition.ErrCodeInvalidParameterException:
fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error())
case rekognition.ErrCodeImageTooLargeException:
fmt.Println(rekognition.ErrCodeImageTooLargeException, aerr.Error())
case rekognition.ErrCodeAccessDeniedException:
fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error())
case rekognition.ErrCodeInternalServerError:
fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error())
case rekognition.ErrCodeThrottlingException:
fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error())
case rekognition.ErrCodeProvisionedThroughputExceededException:
fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error())
case rekognition.ErrCodeResourceNotFoundException:
fmt.Println(rekognition.ErrCodeResourceNotFoundException, aerr.Error())
case rekognition.ErrCodeInvalidImageFormatException:
fmt.Println(rekognition.ErrCodeInvalidImageFormatException, aerr.Error())
default:
fmt.Println(aerr.Error())
}
} else {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
}
return
}
2017-07-23 09:51:42 +02:00
fmt.Println(result)
}