github.com/aavshr/aws-sdk-go@v1.41.3/service/rekognition/examples_test.go (about) 1 // Code generated by private/model/cli/gen-api/main.go. DO NOT EDIT. 2 3 package rekognition_test 4 5 import ( 6 "fmt" 7 "strings" 8 "time" 9 10 "github.com/aavshr/aws-sdk-go/aws" 11 "github.com/aavshr/aws-sdk-go/aws/awserr" 12 "github.com/aavshr/aws-sdk-go/aws/session" 13 "github.com/aavshr/aws-sdk-go/service/rekognition" 14 ) 15 16 var _ time.Duration 17 var _ strings.Reader 18 var _ aws.Config 19 20 func parseTime(layout, value string) *time.Time { 21 t, err := time.Parse(layout, value) 22 if err != nil { 23 panic(err) 24 } 25 return &t 26 } 27 28 // To compare two images 29 // 30 // This operation compares the largest face detected in the source image with each face 31 // detected in the target image. 32 func ExampleRekognition_CompareFaces_shared00() { 33 svc := rekognition.New(session.New()) 34 input := &rekognition.CompareFacesInput{ 35 SimilarityThreshold: aws.Float64(90.000000), 36 SourceImage: &rekognition.Image{ 37 S3Object: &rekognition.S3Object{ 38 Bucket: aws.String("mybucket"), 39 Name: aws.String("mysourceimage"), 40 }, 41 }, 42 TargetImage: &rekognition.Image{ 43 S3Object: &rekognition.S3Object{ 44 Bucket: aws.String("mybucket"), 45 Name: aws.String("mytargetimage"), 46 }, 47 }, 48 } 49 50 result, err := svc.CompareFaces(input) 51 if err != nil { 52 if aerr, ok := err.(awserr.Error); ok { 53 switch aerr.Code() { 54 case rekognition.ErrCodeInvalidParameterException: 55 fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error()) 56 case rekognition.ErrCodeInvalidS3ObjectException: 57 fmt.Println(rekognition.ErrCodeInvalidS3ObjectException, aerr.Error()) 58 case rekognition.ErrCodeImageTooLargeException: 59 fmt.Println(rekognition.ErrCodeImageTooLargeException, aerr.Error()) 60 case rekognition.ErrCodeAccessDeniedException: 61 fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error()) 62 case rekognition.ErrCodeInternalServerError: 63 fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error()) 64 case rekognition.ErrCodeThrottlingException: 65 fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error()) 66 case rekognition.ErrCodeProvisionedThroughputExceededException: 67 fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error()) 68 case rekognition.ErrCodeInvalidImageFormatException: 69 fmt.Println(rekognition.ErrCodeInvalidImageFormatException, aerr.Error()) 70 default: 71 fmt.Println(aerr.Error()) 72 } 73 } else { 74 // Print the error, cast err to awserr.Error to get the Code and 75 // Message from an error. 76 fmt.Println(err.Error()) 77 } 78 return 79 } 80 81 fmt.Println(result) 82 } 83 84 // To create a collection 85 // 86 // This operation creates a Rekognition collection for storing image data. 87 func ExampleRekognition_CreateCollection_shared00() { 88 svc := rekognition.New(session.New()) 89 input := &rekognition.CreateCollectionInput{ 90 CollectionId: aws.String("myphotos"), 91 } 92 93 result, err := svc.CreateCollection(input) 94 if err != nil { 95 if aerr, ok := err.(awserr.Error); ok { 96 switch aerr.Code() { 97 case rekognition.ErrCodeInvalidParameterException: 98 fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error()) 99 case rekognition.ErrCodeAccessDeniedException: 100 fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error()) 101 case rekognition.ErrCodeInternalServerError: 102 fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error()) 103 case rekognition.ErrCodeThrottlingException: 104 fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error()) 105 case rekognition.ErrCodeProvisionedThroughputExceededException: 106 fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error()) 107 case rekognition.ErrCodeResourceAlreadyExistsException: 108 fmt.Println(rekognition.ErrCodeResourceAlreadyExistsException, aerr.Error()) 109 case rekognition.ErrCodeServiceQuotaExceededException: 110 fmt.Println(rekognition.ErrCodeServiceQuotaExceededException, aerr.Error()) 111 default: 112 fmt.Println(aerr.Error()) 113 } 114 } else { 115 // Print the error, cast err to awserr.Error to get the Code and 116 // Message from an error. 117 fmt.Println(err.Error()) 118 } 119 return 120 } 121 122 fmt.Println(result) 123 } 124 125 // To delete a collection 126 // 127 // This operation deletes a Rekognition collection. 128 func ExampleRekognition_DeleteCollection_shared00() { 129 svc := rekognition.New(session.New()) 130 input := &rekognition.DeleteCollectionInput{ 131 CollectionId: aws.String("myphotos"), 132 } 133 134 result, err := svc.DeleteCollection(input) 135 if err != nil { 136 if aerr, ok := err.(awserr.Error); ok { 137 switch aerr.Code() { 138 case rekognition.ErrCodeInvalidParameterException: 139 fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error()) 140 case rekognition.ErrCodeAccessDeniedException: 141 fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error()) 142 case rekognition.ErrCodeInternalServerError: 143 fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error()) 144 case rekognition.ErrCodeThrottlingException: 145 fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error()) 146 case rekognition.ErrCodeProvisionedThroughputExceededException: 147 fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error()) 148 case rekognition.ErrCodeResourceNotFoundException: 149 fmt.Println(rekognition.ErrCodeResourceNotFoundException, aerr.Error()) 150 default: 151 fmt.Println(aerr.Error()) 152 } 153 } else { 154 // Print the error, cast err to awserr.Error to get the Code and 155 // Message from an error. 156 fmt.Println(err.Error()) 157 } 158 return 159 } 160 161 fmt.Println(result) 162 } 163 164 // To delete a face 165 // 166 // This operation deletes one or more faces from a Rekognition collection. 167 func ExampleRekognition_DeleteFaces_shared00() { 168 svc := rekognition.New(session.New()) 169 input := &rekognition.DeleteFacesInput{ 170 CollectionId: aws.String("myphotos"), 171 FaceIds: []*string{ 172 aws.String("ff43d742-0c13-5d16-a3e8-03d3f58e980b"), 173 }, 174 } 175 176 result, err := svc.DeleteFaces(input) 177 if err != nil { 178 if aerr, ok := err.(awserr.Error); ok { 179 switch aerr.Code() { 180 case rekognition.ErrCodeInvalidParameterException: 181 fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error()) 182 case rekognition.ErrCodeAccessDeniedException: 183 fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error()) 184 case rekognition.ErrCodeInternalServerError: 185 fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error()) 186 case rekognition.ErrCodeThrottlingException: 187 fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error()) 188 case rekognition.ErrCodeProvisionedThroughputExceededException: 189 fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error()) 190 case rekognition.ErrCodeResourceNotFoundException: 191 fmt.Println(rekognition.ErrCodeResourceNotFoundException, aerr.Error()) 192 default: 193 fmt.Println(aerr.Error()) 194 } 195 } else { 196 // Print the error, cast err to awserr.Error to get the Code and 197 // Message from an error. 198 fmt.Println(err.Error()) 199 } 200 return 201 } 202 203 fmt.Println(result) 204 } 205 206 // To detect faces in an image 207 // 208 // This operation detects faces in an image stored in an AWS S3 bucket. 209 func ExampleRekognition_DetectFaces_shared00() { 210 svc := rekognition.New(session.New()) 211 input := &rekognition.DetectFacesInput{ 212 Image: &rekognition.Image{ 213 S3Object: &rekognition.S3Object{ 214 Bucket: aws.String("mybucket"), 215 Name: aws.String("myphoto"), 216 }, 217 }, 218 } 219 220 result, err := svc.DetectFaces(input) 221 if err != nil { 222 if aerr, ok := err.(awserr.Error); ok { 223 switch aerr.Code() { 224 case rekognition.ErrCodeInvalidS3ObjectException: 225 fmt.Println(rekognition.ErrCodeInvalidS3ObjectException, aerr.Error()) 226 case rekognition.ErrCodeInvalidParameterException: 227 fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error()) 228 case rekognition.ErrCodeImageTooLargeException: 229 fmt.Println(rekognition.ErrCodeImageTooLargeException, aerr.Error()) 230 case rekognition.ErrCodeAccessDeniedException: 231 fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error()) 232 case rekognition.ErrCodeInternalServerError: 233 fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error()) 234 case rekognition.ErrCodeThrottlingException: 235 fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error()) 236 case rekognition.ErrCodeProvisionedThroughputExceededException: 237 fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error()) 238 case rekognition.ErrCodeInvalidImageFormatException: 239 fmt.Println(rekognition.ErrCodeInvalidImageFormatException, aerr.Error()) 240 default: 241 fmt.Println(aerr.Error()) 242 } 243 } else { 244 // Print the error, cast err to awserr.Error to get the Code and 245 // Message from an error. 246 fmt.Println(err.Error()) 247 } 248 return 249 } 250 251 fmt.Println(result) 252 } 253 254 // To detect labels 255 // 256 // This operation detects labels in the supplied image 257 func ExampleRekognition_DetectLabels_shared00() { 258 svc := rekognition.New(session.New()) 259 input := &rekognition.DetectLabelsInput{ 260 Image: &rekognition.Image{ 261 S3Object: &rekognition.S3Object{ 262 Bucket: aws.String("mybucket"), 263 Name: aws.String("myphoto"), 264 }, 265 }, 266 MaxLabels: aws.Int64(123), 267 MinConfidence: aws.Float64(70.000000), 268 } 269 270 result, err := svc.DetectLabels(input) 271 if err != nil { 272 if aerr, ok := err.(awserr.Error); ok { 273 switch aerr.Code() { 274 case rekognition.ErrCodeInvalidS3ObjectException: 275 fmt.Println(rekognition.ErrCodeInvalidS3ObjectException, aerr.Error()) 276 case rekognition.ErrCodeInvalidParameterException: 277 fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error()) 278 case rekognition.ErrCodeImageTooLargeException: 279 fmt.Println(rekognition.ErrCodeImageTooLargeException, aerr.Error()) 280 case rekognition.ErrCodeAccessDeniedException: 281 fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error()) 282 case rekognition.ErrCodeInternalServerError: 283 fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error()) 284 case rekognition.ErrCodeThrottlingException: 285 fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error()) 286 case rekognition.ErrCodeProvisionedThroughputExceededException: 287 fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error()) 288 case rekognition.ErrCodeInvalidImageFormatException: 289 fmt.Println(rekognition.ErrCodeInvalidImageFormatException, aerr.Error()) 290 default: 291 fmt.Println(aerr.Error()) 292 } 293 } else { 294 // Print the error, cast err to awserr.Error to get the Code and 295 // Message from an error. 296 fmt.Println(err.Error()) 297 } 298 return 299 } 300 301 fmt.Println(result) 302 } 303 304 // To add a face to a collection 305 // 306 // This operation detects faces in an image and adds them to the specified Rekognition 307 // collection. 308 func ExampleRekognition_IndexFaces_shared00() { 309 svc := rekognition.New(session.New()) 310 input := &rekognition.IndexFacesInput{ 311 CollectionId: aws.String("myphotos"), 312 ExternalImageId: aws.String("myphotoid"), 313 Image: &rekognition.Image{ 314 S3Object: &rekognition.S3Object{ 315 Bucket: aws.String("mybucket"), 316 Name: aws.String("myphoto"), 317 }, 318 }, 319 } 320 321 result, err := svc.IndexFaces(input) 322 if err != nil { 323 if aerr, ok := err.(awserr.Error); ok { 324 switch aerr.Code() { 325 case rekognition.ErrCodeInvalidS3ObjectException: 326 fmt.Println(rekognition.ErrCodeInvalidS3ObjectException, aerr.Error()) 327 case rekognition.ErrCodeInvalidParameterException: 328 fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error()) 329 case rekognition.ErrCodeImageTooLargeException: 330 fmt.Println(rekognition.ErrCodeImageTooLargeException, aerr.Error()) 331 case rekognition.ErrCodeAccessDeniedException: 332 fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error()) 333 case rekognition.ErrCodeInternalServerError: 334 fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error()) 335 case rekognition.ErrCodeThrottlingException: 336 fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error()) 337 case rekognition.ErrCodeProvisionedThroughputExceededException: 338 fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error()) 339 case rekognition.ErrCodeResourceNotFoundException: 340 fmt.Println(rekognition.ErrCodeResourceNotFoundException, aerr.Error()) 341 case rekognition.ErrCodeInvalidImageFormatException: 342 fmt.Println(rekognition.ErrCodeInvalidImageFormatException, aerr.Error()) 343 case rekognition.ErrCodeServiceQuotaExceededException: 344 fmt.Println(rekognition.ErrCodeServiceQuotaExceededException, aerr.Error()) 345 default: 346 fmt.Println(aerr.Error()) 347 } 348 } else { 349 // Print the error, cast err to awserr.Error to get the Code and 350 // Message from an error. 351 fmt.Println(err.Error()) 352 } 353 return 354 } 355 356 fmt.Println(result) 357 } 358 359 // To list the collections 360 // 361 // This operation returns a list of Rekognition collections. 362 func ExampleRekognition_ListCollections_shared00() { 363 svc := rekognition.New(session.New()) 364 input := &rekognition.ListCollectionsInput{} 365 366 result, err := svc.ListCollections(input) 367 if err != nil { 368 if aerr, ok := err.(awserr.Error); ok { 369 switch aerr.Code() { 370 case rekognition.ErrCodeInvalidParameterException: 371 fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error()) 372 case rekognition.ErrCodeAccessDeniedException: 373 fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error()) 374 case rekognition.ErrCodeInternalServerError: 375 fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error()) 376 case rekognition.ErrCodeThrottlingException: 377 fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error()) 378 case rekognition.ErrCodeProvisionedThroughputExceededException: 379 fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error()) 380 case rekognition.ErrCodeInvalidPaginationTokenException: 381 fmt.Println(rekognition.ErrCodeInvalidPaginationTokenException, aerr.Error()) 382 case rekognition.ErrCodeResourceNotFoundException: 383 fmt.Println(rekognition.ErrCodeResourceNotFoundException, aerr.Error()) 384 default: 385 fmt.Println(aerr.Error()) 386 } 387 } else { 388 // Print the error, cast err to awserr.Error to get the Code and 389 // Message from an error. 390 fmt.Println(err.Error()) 391 } 392 return 393 } 394 395 fmt.Println(result) 396 } 397 398 // To list the faces in a collection 399 // 400 // This operation lists the faces in a Rekognition collection. 401 func ExampleRekognition_ListFaces_shared00() { 402 svc := rekognition.New(session.New()) 403 input := &rekognition.ListFacesInput{ 404 CollectionId: aws.String("myphotos"), 405 MaxResults: aws.Int64(20), 406 } 407 408 result, err := svc.ListFaces(input) 409 if err != nil { 410 if aerr, ok := err.(awserr.Error); ok { 411 switch aerr.Code() { 412 case rekognition.ErrCodeInvalidParameterException: 413 fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error()) 414 case rekognition.ErrCodeAccessDeniedException: 415 fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error()) 416 case rekognition.ErrCodeInternalServerError: 417 fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error()) 418 case rekognition.ErrCodeThrottlingException: 419 fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error()) 420 case rekognition.ErrCodeProvisionedThroughputExceededException: 421 fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error()) 422 case rekognition.ErrCodeInvalidPaginationTokenException: 423 fmt.Println(rekognition.ErrCodeInvalidPaginationTokenException, aerr.Error()) 424 case rekognition.ErrCodeResourceNotFoundException: 425 fmt.Println(rekognition.ErrCodeResourceNotFoundException, aerr.Error()) 426 default: 427 fmt.Println(aerr.Error()) 428 } 429 } else { 430 // Print the error, cast err to awserr.Error to get the Code and 431 // Message from an error. 432 fmt.Println(err.Error()) 433 } 434 return 435 } 436 437 fmt.Println(result) 438 } 439 440 // To delete a face 441 // 442 // This operation searches for matching faces in the collection the supplied face belongs 443 // to. 444 func ExampleRekognition_SearchFaces_shared00() { 445 svc := rekognition.New(session.New()) 446 input := &rekognition.SearchFacesInput{ 447 CollectionId: aws.String("myphotos"), 448 FaceId: aws.String("70008e50-75e4-55d0-8e80-363fb73b3a14"), 449 FaceMatchThreshold: aws.Float64(90.000000), 450 MaxFaces: aws.Int64(10), 451 } 452 453 result, err := svc.SearchFaces(input) 454 if err != nil { 455 if aerr, ok := err.(awserr.Error); ok { 456 switch aerr.Code() { 457 case rekognition.ErrCodeInvalidParameterException: 458 fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error()) 459 case rekognition.ErrCodeAccessDeniedException: 460 fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error()) 461 case rekognition.ErrCodeInternalServerError: 462 fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error()) 463 case rekognition.ErrCodeThrottlingException: 464 fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error()) 465 case rekognition.ErrCodeProvisionedThroughputExceededException: 466 fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error()) 467 case rekognition.ErrCodeResourceNotFoundException: 468 fmt.Println(rekognition.ErrCodeResourceNotFoundException, aerr.Error()) 469 default: 470 fmt.Println(aerr.Error()) 471 } 472 } else { 473 // Print the error, cast err to awserr.Error to get the Code and 474 // Message from an error. 475 fmt.Println(err.Error()) 476 } 477 return 478 } 479 480 fmt.Println(result) 481 } 482 483 // To search for faces matching a supplied image 484 // 485 // This operation searches for faces in a Rekognition collection that match the largest 486 // face in an S3 bucket stored image. 487 func ExampleRekognition_SearchFacesByImage_shared00() { 488 svc := rekognition.New(session.New()) 489 input := &rekognition.SearchFacesByImageInput{ 490 CollectionId: aws.String("myphotos"), 491 FaceMatchThreshold: aws.Float64(95.000000), 492 Image: &rekognition.Image{ 493 S3Object: &rekognition.S3Object{ 494 Bucket: aws.String("mybucket"), 495 Name: aws.String("myphoto"), 496 }, 497 }, 498 MaxFaces: aws.Int64(5), 499 } 500 501 result, err := svc.SearchFacesByImage(input) 502 if err != nil { 503 if aerr, ok := err.(awserr.Error); ok { 504 switch aerr.Code() { 505 case rekognition.ErrCodeInvalidS3ObjectException: 506 fmt.Println(rekognition.ErrCodeInvalidS3ObjectException, aerr.Error()) 507 case rekognition.ErrCodeInvalidParameterException: 508 fmt.Println(rekognition.ErrCodeInvalidParameterException, aerr.Error()) 509 case rekognition.ErrCodeImageTooLargeException: 510 fmt.Println(rekognition.ErrCodeImageTooLargeException, aerr.Error()) 511 case rekognition.ErrCodeAccessDeniedException: 512 fmt.Println(rekognition.ErrCodeAccessDeniedException, aerr.Error()) 513 case rekognition.ErrCodeInternalServerError: 514 fmt.Println(rekognition.ErrCodeInternalServerError, aerr.Error()) 515 case rekognition.ErrCodeThrottlingException: 516 fmt.Println(rekognition.ErrCodeThrottlingException, aerr.Error()) 517 case rekognition.ErrCodeProvisionedThroughputExceededException: 518 fmt.Println(rekognition.ErrCodeProvisionedThroughputExceededException, aerr.Error()) 519 case rekognition.ErrCodeResourceNotFoundException: 520 fmt.Println(rekognition.ErrCodeResourceNotFoundException, aerr.Error()) 521 case rekognition.ErrCodeInvalidImageFormatException: 522 fmt.Println(rekognition.ErrCodeInvalidImageFormatException, aerr.Error()) 523 default: 524 fmt.Println(aerr.Error()) 525 } 526 } else { 527 // Print the error, cast err to awserr.Error to get the Code and 528 // Message from an error. 529 fmt.Println(err.Error()) 530 } 531 return 532 } 533 534 fmt.Println(result) 535 }