com.amazonaws.services.rekognition.AmazonRekognitionClientBuilder Java Examples

The following examples show how to use com.amazonaws.services.rekognition.AmazonRekognitionClientBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: rekognition-image-java-celebrity-info.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {
  //Change the value of id to an ID value returned by RecognizeCelebrities or GetCelebrityRecognition
   String id = "nnnnnnnn";

   AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();

   GetCelebrityInfoRequest request = new GetCelebrityInfoRequest()
      .withId(id);

   System.out.println("Getting information for celebrity: " + id);

   GetCelebrityInfoResult result=rekognitionClient.getCelebrityInfo(request);

   //Display celebrity information
   System.out.println("celebrity name: " + result.getName());
   System.out.println("Further information (if available):");
   for (String url: result.getUrls()){
      System.out.println(url);
   }
}
 
Example #2
Source File: rekognition-collection-java-search-face-matching-id-collection.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    
    AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();
  
    ObjectMapper objectMapper = new ObjectMapper();
  // Search collection for faces matching the face id.
  
  SearchFacesRequest searchFacesRequest = new SearchFacesRequest()
          .withCollectionId(collectionId)
          .withFaceId(faceId)
          .withFaceMatchThreshold(70F)
          .withMaxFaces(2);
       
   SearchFacesResult searchFacesByIdResult = 
           rekognitionClient.searchFaces(searchFacesRequest);

   System.out.println("Face matching faceId " + faceId);
  List < FaceMatch > faceImageMatches = searchFacesByIdResult.getFaceMatches();
  for (FaceMatch face: faceImageMatches) {
     System.out.println(objectMapper.writerWithDefaultPrettyPrinter()
             .writeValueAsString(face));
     
     System.out.println();
  }
}
 
Example #3
Source File: rekognition-collection-java-describe-collection.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
   //Change collectionID to the name of the desired collection.
   String collectionId = "CollectionID";
   
   AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();

         
   System.out.println("Describing collection: " +
      collectionId );
      
         
     DescribeCollectionRequest request = new DescribeCollectionRequest()
                 .withCollectionId(collectionId);
        
   DescribeCollectionResult describeCollectionResult = rekognitionClient.describeCollection(request); 
   System.out.println("Collection Arn : " +
      describeCollectionResult.getCollectionARN());
   System.out.println("Face count : " +
      describeCollectionResult.getFaceCount().toString());
   System.out.println("Face model version : " +
      describeCollectionResult.getFaceModelVersion());
   System.out.println("Created : " +
      describeCollectionResult.getCreationTimestamp().toString());

}
 
Example #4
Source File: RekognitionStreamProcessor.java    From amazon-kinesis-video-streams-parser-library with Apache License 2.0 5 votes vote down vote up
private RekognitionStreamProcessor(final Regions regions, final AWSCredentialsProvider provider,
                                   final RekognitionInput rekognitionInput) {
    this.streamProcessorName = rekognitionInput.getStreamingProcessorName();
    this.kinesisVideoStreamArn = rekognitionInput.getKinesisVideoStreamArn();
    this.kinesisDataStreamArn = rekognitionInput.getKinesisDataStreamArn();
    this.roleArn = rekognitionInput.getIamRoleArn();
    this.collectionId = rekognitionInput.getFaceCollectionId();
    this.matchThreshold = rekognitionInput.getMatchThreshold();

    rekognitionClient = AmazonRekognitionClientBuilder
            .standard()
            .withRegion(regions)
            .withCredentials(provider)
            .build();
}
 
Example #5
Source File: RekognitionImageAssessmentHandler.java    From smart-security-camera with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Parameters handleRequest(Parameters parameters, Context context) {

    context.getLogger().log("Input Function [" + context.getFunctionName() + 
            "], Parameters [" + parameters + "]");

    // Create Rekognition client using the parameters available form the runtime context
    AmazonRekognition rekognitionClient = 
            AmazonRekognitionClientBuilder.defaultClient();

    // Create a Rekognition request
    DetectLabelsRequest request = new DetectLabelsRequest().withImage(new Image()
            .withS3Object(new S3Object().withName(parameters.getS3Key())
                    .withBucket(parameters.getS3Bucket())));

    // Call the Rekognition Service
    DetectLabelsResult result = rekognitionClient.detectLabels(request);

    // Transfer labels and confidence scores over to Parameter POJO
    for (Label label : result.getLabels()) {
        parameters.getRekognitionLabels().put(label.getName(), label.getConfidence());
    }

    context.getLogger().log("Output Function [" + context.getFunctionName() +
            "], Parameters [" + parameters + "]");

    // Return the result (will be serialised to JSON)
    return parameters;
}
 
Example #6
Source File: rekognition-collection-java-list-faces-in-collection.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
   
   AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();

   ObjectMapper objectMapper = new ObjectMapper();

   ListFacesResult listFacesResult = null;
   System.out.println("Faces in collection " + collectionId);

   String paginationToken = null;
   do {
      if (listFacesResult != null) {
         paginationToken = listFacesResult.getNextToken();
      }
      
      ListFacesRequest listFacesRequest = new ListFacesRequest()
              .withCollectionId(collectionId)
              .withMaxResults(1)
              .withNextToken(paginationToken);
     
      listFacesResult =  rekognitionClient.listFaces(listFacesRequest);
      List < Face > faces = listFacesResult.getFaces();
      for (Face face: faces) {
         System.out.println(objectMapper.writerWithDefaultPrettyPrinter()
            .writeValueAsString(face));
      }
   } while (listFacesResult != null && listFacesResult.getNextToken() !=
      null);
}
 
Example #7
Source File: rekognition-collection-java-add-faces-to-collection.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();

        Image image = new Image()
                .withS3Object(new S3Object()
                .withBucket(bucket)
                .withName(photo));
        
        IndexFacesRequest indexFacesRequest = new IndexFacesRequest()
                .withImage(image)
                .withQualityFilter(QualityFilter.AUTO)
                .withMaxFaces(1)
                .withCollectionId(collectionId)
                .withExternalImageId(photo)
                .withDetectionAttributes("DEFAULT");

        IndexFacesResult indexFacesResult = rekognitionClient.indexFaces(indexFacesRequest);
        
        System.out.println("Results for " + photo);
        System.out.println("Faces indexed:");
        List<FaceRecord> faceRecords = indexFacesResult.getFaceRecords();
        for (FaceRecord faceRecord : faceRecords) {
            System.out.println("  Face ID: " + faceRecord.getFace().getFaceId());
            System.out.println("  Location:" + faceRecord.getFaceDetail().getBoundingBox().toString());
        }
        
        List<UnindexedFace> unindexedFaces = indexFacesResult.getUnindexedFaces();
        System.out.println("Faces not indexed:");
        for (UnindexedFace unindexedFace : unindexedFaces) {
            System.out.println("  Location:" + unindexedFace.getFaceDetail().getBoundingBox().toString());
            System.out.println("  Reasons:");
            for (String reason : unindexedFace.getReasons()) {
                System.out.println("   " + reason);
            }
        }
    }
 
Example #8
Source File: rekognition-collection-java-list-collections.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {


      AmazonRekognition amazonRekognition = AmazonRekognitionClientBuilder.defaultClient();
 

      System.out.println("Listing collections");
      int limit = 10;
      ListCollectionsResult listCollectionsResult = null;
      String paginationToken = null;
      do {
         if (listCollectionsResult != null) {
            paginationToken = listCollectionsResult.getNextToken();
         }
         ListCollectionsRequest listCollectionsRequest = new ListCollectionsRequest()
                 .withMaxResults(limit)
                 .withNextToken(paginationToken);
         listCollectionsResult=amazonRekognition.listCollections(listCollectionsRequest);
         
         List < String > collectionIds = listCollectionsResult.getCollectionIds();
         for (String resultId: collectionIds) {
            System.out.println(resultId);
         }
      } while (listCollectionsResult != null && listCollectionsResult.getNextToken() !=
         null);
     
   }
 
Example #9
Source File: rekognition-image-java-detect-text.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
   
   //Change the value of bucket to the S3 bucket that contains your image file.
   //Change the value of photo to your image file name.
   String photo = "inputtext.jpg";
   String bucket = "bucket";

   AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();

  
   
   DetectTextRequest request = new DetectTextRequest()
           .withImage(new Image()
           .withS3Object(new S3Object()
           .withName(photo)
           .withBucket(bucket)));
 

   try {
      DetectTextResult result = rekognitionClient.detectText(request);
      List<TextDetection> textDetections = result.getTextDetections();

      System.out.println("Detected lines and words for " + photo);
      for (TextDetection text: textDetections) {
   
              System.out.println("Detected: " + text.getDetectedText());
              System.out.println("Confidence: " + text.getConfidence().toString());
              System.out.println("Id : " + text.getId());
              System.out.println("Parent Id: " + text.getParentId());
              System.out.println("Type: " + text.getType());
              System.out.println();
      }
   } catch(AmazonRekognitionException e) {
      e.printStackTrace();
   }
}
 
Example #10
Source File: rekognition-image-java-detect-moderation-labels.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception
{
  //Change the values of photo and bucket to your values.
   String photo = "input.jpg";
   String bucket = "bucket";
   
   AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();
   
   DetectModerationLabelsRequest request = new DetectModerationLabelsRequest()
     .withImage(new Image().withS3Object(new S3Object().withName(photo).withBucket(bucket)))
     .withMinConfidence(60F);
   try
   {
        DetectModerationLabelsResult result = rekognitionClient.detectModerationLabels(request);
        List<ModerationLabel> labels = result.getModerationLabels();
        System.out.println("Detected labels for " + photo);
        for (ModerationLabel label : labels)
        {
           System.out.println("Label: " + label.getName()
            + "\n Confidence: " + label.getConfidence().toString() + "%"
            + "\n Parent:" + label.getParentName());
       }
    }
    catch (AmazonRekognitionException e)
    {
      e.printStackTrace();
    }
 }
 
Example #11
Source File: rekognition-image-java-detect-labels-local-file.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Change photo to the path and filename of your image.
	String photo="input.jpg";


    ByteBuffer imageBytes;
    try (InputStream inputStream = new FileInputStream(new File(photo))) {
        imageBytes = ByteBuffer.wrap(IOUtils.toByteArray(inputStream));
    }


    AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();

    DetectLabelsRequest request = new DetectLabelsRequest()
            .withImage(new Image()
                    .withBytes(imageBytes))
            .withMaxLabels(10)
            .withMinConfidence(77F);

    try {

        DetectLabelsResult result = rekognitionClient.detectLabels(request);
        List <Label> labels = result.getLabels();

        System.out.println("Detected labels for " + photo);
        for (Label label: labels) {
           System.out.println(label.getName() + ": " + label.getConfidence().toString());
        }

    } catch (AmazonRekognitionException e) {
        e.printStackTrace();
    }

}
 
Example #12
Source File: rekognition-collection-java-search-face-matching-image-collection.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

       AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();
        
      ObjectMapper objectMapper = new ObjectMapper();
      
       // Get an image object from S3 bucket.
      Image image=new Image()
              .withS3Object(new S3Object()
                      .withBucket(bucket)
                      .withName(photo));
      
      // Search collection for faces similar to the largest face in the image.
      SearchFacesByImageRequest searchFacesByImageRequest = new SearchFacesByImageRequest()
              .withCollectionId(collectionId)
              .withImage(image)
              .withFaceMatchThreshold(70F)
              .withMaxFaces(2);
           
       SearchFacesByImageResult searchFacesByImageResult = 
               rekognitionClient.searchFacesByImage(searchFacesByImageRequest);

       System.out.println("Faces matching largest face in image from" + photo);
      List < FaceMatch > faceImageMatches = searchFacesByImageResult.getFaceMatches();
      for (FaceMatch face: faceImageMatches) {
          System.out.println(objectMapper.writerWithDefaultPrettyPrinter()
                  .writeValueAsString(face));
         System.out.println();
      }
   }
 
Example #13
Source File: rekognition-video-java-detect-labels-lambda.java    From aws-doc-sdk-examples with Apache License 2.0 4 votes vote down vote up
void GetResultsLabels(String startJobId, Context context) throws Exception {

      LambdaLogger logger = context.getLogger();

      AmazonRekognition rek = AmazonRekognitionClientBuilder.standard().withRegion(Regions.US_EAST_1).build();

      int maxResults = 1000;
      String paginationToken = null;
      GetLabelDetectionResult labelDetectionResult = null;
      String labels = "";
      Integer labelsCount = 0;
      String label = "";
      String currentLabel = "";
     
      //Get label detection results and log them. 
      do {

         GetLabelDetectionRequest labelDetectionRequest = new GetLabelDetectionRequest().withJobId(startJobId)
               .withSortBy(LabelDetectionSortBy.NAME).withMaxResults(maxResults).withNextToken(paginationToken);

         labelDetectionResult = rek.getLabelDetection(labelDetectionRequest);
         
         paginationToken = labelDetectionResult.getNextToken();
         VideoMetadata videoMetaData = labelDetectionResult.getVideoMetadata();

         // Add labels to log
         List<LabelDetection> detectedLabels = labelDetectionResult.getLabels();
         
         for (LabelDetection detectedLabel : detectedLabels) {
            label = detectedLabel.getLabel().getName();
            if (label.equals(currentLabel)) {
               continue;
            }
            labels = labels + label + " / ";
            currentLabel = label;
            labelsCount++;

         }
      } while (labelDetectionResult != null && labelDetectionResult.getNextToken() != null);

      logger.log("Total number of labels : " + labelsCount);
      logger.log("labels : " + labels);

   }
 
Example #14
Source File: rekognition-image-java-display-bounding-boxes.java    From aws-doc-sdk-examples with Apache License 2.0 4 votes vote down vote up
public static void main(String arg[]) throws Exception {
    //Change the value of bucket to the S3 bucket that contains your image file.
    //Change the value of photo to your image file name.
    String photo = "input.png";
    String bucket = "bucket";
    int height = 0;
    int width = 0;

    // Get the image from an S3 Bucket
    AmazonS3 s3client = AmazonS3ClientBuilder.defaultClient();

    com.amazonaws.services.s3.model.S3Object s3object = s3client.getObject(bucket, photo);
    S3ObjectInputStream inputStream = s3object.getObjectContent();
    BufferedImage image = ImageIO.read(inputStream);
    DetectFacesRequest request = new DetectFacesRequest()
            .withImage(new Image().withS3Object(new S3Object().withName(photo).withBucket(bucket)));

    width = image.getWidth();
    height = image.getHeight();

    // Call DetectFaces    
    AmazonRekognition amazonRekognition = AmazonRekognitionClientBuilder.defaultClient();
    DetectFacesResult result = amazonRekognition.detectFaces(request);
    
    //Show the bounding box info for each face.
    List<FaceDetail> faceDetails = result.getFaceDetails();
    for (FaceDetail face : faceDetails) {

        BoundingBox box = face.getBoundingBox();
        float left = width * box.getLeft();
        float top = height * box.getTop();
        System.out.println("Face:");

        System.out.println("Left: " + String.valueOf((int) left));
        System.out.println("Top: " + String.valueOf((int) top));
        System.out.println("Face Width: " + String.valueOf((int) (width * box.getWidth())));
        System.out.println("Face Height: " + String.valueOf((int) (height * box.getHeight())));
        System.out.println();

    }

    // Create frame and panel.
    JFrame frame = new JFrame("RotateImage");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    DisplayFaces panel = new DisplayFaces(result, image);
    panel.setPreferredSize(new Dimension(image.getWidth() / scale, image.getHeight() / scale));
    frame.setContentPane(panel);
    frame.pack();
    frame.setVisible(true);

}
 
Example #15
Source File: rekognition-video-stored-video.java    From aws-doc-sdk-examples with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args)  throws Exception{


        sqs = AmazonSQSClientBuilder.defaultClient();
        rek = AmazonRekognitionClientBuilder.defaultClient();
        
        //Change active start function for the desired analysis. Also change the GetResults function later in this code.
        //=================================================
        StartLabels(bucket, video);
        //StartFaces(bucket,video);
        //StartFaceSearchCollection(bucket,video);
        //StartPersons(bucket,video);
        //StartCelebrities(bucket,video);
        //StartModerationLabels(bucket,video);
        //=================================================
        System.out.println("Waiting for job: " + startJobId);
        //Poll queue for messages
        List<Message> messages=null;
        int dotLine=0;
        boolean jobFound=false;

        //loop until the job status is published. Ignore other messages in queue.
        do{
            messages = sqs.receiveMessage(queueUrl).getMessages();
            if (dotLine++<20){
                System.out.print(".");
            }else{
                System.out.println();
                dotLine=0;
            }

            if (!messages.isEmpty()) {
                //Loop through messages received.
                for (Message message: messages) {
                    String notification = message.getBody();

                    // Get status and job id from notification.
                    ObjectMapper mapper = new ObjectMapper();
                    JsonNode jsonMessageTree = mapper.readTree(notification);
                    JsonNode messageBodyText = jsonMessageTree.get("Message");
                    ObjectMapper operationResultMapper = new ObjectMapper();
                    JsonNode jsonResultTree = operationResultMapper.readTree(messageBodyText.textValue());
                    JsonNode operationJobId = jsonResultTree.get("JobId");
                    JsonNode operationStatus = jsonResultTree.get("Status");
                    System.out.println("Job found was " + operationJobId);
                    // Found job. Get the results and display.
                    if(operationJobId.asText().equals(startJobId)){
                        jobFound=true;
                        System.out.println("Job id: " + operationJobId );
                        System.out.println("Status : " + operationStatus.toString());
                        if (operationStatus.asText().equals("SUCCEEDED")){
                            //Change to match the start function earlier in this code.
                            //============================================
                            GetResultsLabels();
                            //GetResultsFaces();
                            //GetResultsFaceSearchCollection();
                            //GetResultsPersons();
                            //GetResultsCelebrities();
                            //GetResultsModerationLabels();
                            //============================================
                        }
                        else{
                            System.out.println("Video analysis failed");
                        }

                        sqs.deleteMessage(queueUrl,message.getReceiptHandle());
                    }

                    else{
                        System.out.println("Job received was not job " +  startJobId);
                        //Delete unknown message. Consider moving message to dead letter queue
                        sqs.deleteMessage(queueUrl,message.getReceiptHandle());
                    }
                }
            }
        } while (!jobFound);


        System.out.println("Done!");
    }
 
Example #16
Source File: rekognition-image-java-detect-faces.java    From aws-doc-sdk-examples with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
   // Change bucket to your S3 bucket that contains the image file.
   // Change photo to your image file.
   String photo = "input.jpg";
   String bucket = "bucket";

   AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();


   DetectFacesRequest request = new DetectFacesRequest()
      .withImage(new Image()
         .withS3Object(new S3Object()
            .withName(photo)
            .withBucket(bucket)))
      .withAttributes(Attribute.ALL);
   // Replace Attribute.ALL with Attribute.DEFAULT to get default values.

   try {
      DetectFacesResult result = rekognitionClient.detectFaces(request);
      List < FaceDetail > faceDetails = result.getFaceDetails();

      for (FaceDetail face: faceDetails) {
         if (request.getAttributes().contains("ALL")) {
            AgeRange ageRange = face.getAgeRange();
            System.out.println("The detected face is estimated to be between "
               + ageRange.getLow().toString() + " and " + ageRange.getHigh().toString()
               + " years old.");
            System.out.println("Here's the complete set of attributes:");
         } else { // non-default attributes have null values.
            System.out.println("Here's the default set of attributes:");
         }

         ObjectMapper objectMapper = new ObjectMapper();
         System.out.println(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(face));
      }

   } catch (AmazonRekognitionException e) {
      e.printStackTrace();
   }

}
 
Example #17
Source File: rekognition-image-java-recognize-celebrities.java    From aws-doc-sdk-examples with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  //Change photo to the path and filename of your image. 
   String photo = "moviestars.jpg";

   AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();

   ByteBuffer imageBytes=null;
   try (InputStream inputStream = new FileInputStream(new File(photo))) {
      imageBytes = ByteBuffer.wrap(IOUtils.toByteArray(inputStream));
   }
   catch(Exception e)
   {
       System.out.println("Failed to load file " + photo);
       System.exit(1);
   }


   RecognizeCelebritiesRequest request = new RecognizeCelebritiesRequest()
      .withImage(new Image()
      .withBytes(imageBytes));

   System.out.println("Looking for celebrities in image " + photo + "\n");

   RecognizeCelebritiesResult result=rekognitionClient.recognizeCelebrities(request);

   //Display recognized celebrity information
   List<Celebrity> celebs=result.getCelebrityFaces();
   System.out.println(celebs.size() + " celebrity(s) were recognized.\n");

   for (Celebrity celebrity: celebs) {
       System.out.println("Celebrity recognized: " + celebrity.getName());
       System.out.println("Celebrity ID: " + celebrity.getId());
       BoundingBox boundingBox=celebrity.getFace().getBoundingBox();
       System.out.println("position: " +
          boundingBox.getLeft().toString() + " " +
          boundingBox.getTop().toString());
       System.out.println("Further information (if available):");
       for (String url: celebrity.getUrls()){
          System.out.println(url);
       }
       System.out.println();
    }
    System.out.println(result.getUnrecognizedFaces().size() + " face(s) were unrecognized.");
}
 
Example #18
Source File: rekognition-collection-java-delete-collection.java    From aws-doc-sdk-examples with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {

      AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();
      // Replace collectionId with the ID of the collection that you want to delete.
      String collectionId = "MyCollection";

      System.out.println("Deleting collections");
      
      DeleteCollectionRequest request = new DeleteCollectionRequest()
         .withCollectionId(collectionId);
      DeleteCollectionResult deleteCollectionResult = rekognitionClient.deleteCollection(request);        
  
      System.out.println(collectionId + ": " + deleteCollectionResult.getStatusCode()
         .toString());

   }
 
Example #19
Source File: rekognition-collection-java-create-collection.java    From aws-doc-sdk-examples with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {


      AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();
      
      //Replace collectionId with the name of the collection that you want to create.
      
      String collectionId = "MyCollection";
            System.out.println("Creating collection: " +
         collectionId );
            
        CreateCollectionRequest request = new CreateCollectionRequest()
                    .withCollectionId(collectionId);
           
      CreateCollectionResult createCollectionResult = rekognitionClient.createCollection(request); 
      System.out.println("CollectionArn : " +
         createCollectionResult.getCollectionArn());
      System.out.println("Status code : " +
         createCollectionResult.getStatusCode().toString());

   }
 
Example #20
Source File: rekognition-image-java-delete-faces-from-collection.java    From aws-doc-sdk-examples with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
   
   AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();
  
   
   DeleteFacesRequest deleteFacesRequest = new DeleteFacesRequest()
           .withCollectionId(collectionId)
           .withFaceIds(faces);
  
   DeleteFacesResult deleteFacesResult=rekognitionClient.deleteFaces(deleteFacesRequest);
   
  
   List < String > faceRecords = deleteFacesResult.getDeletedFaces();
   System.out.println(Integer.toString(faceRecords.size()) + " face(s) deleted:");
   for (String face: faceRecords) {
      System.out.println("FaceID: " + face);
   }
}
 
Example #21
Source File: rekognition-image-java-detect-labels.java    From aws-doc-sdk-examples with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    // Change bucket and photo to your S3 Bucket and image.
    String photo = "photo";
    String bucket = "bucket";

    AmazonRekognition rekognitionClient = AmazonRekognitionClientBuilder.defaultClient();

    DetectLabelsRequest request = new DetectLabelsRequest()
            .withImage(new Image().withS3Object(new S3Object().withName(photo).withBucket(bucket)))
            .withMaxLabels(10).withMinConfidence(75F);

    try {
        DetectLabelsResult result = rekognitionClient.detectLabels(request);
        List<Label> labels = result.getLabels();

        System.out.println("Detected labels for " + photo + "\n");
        for (Label label : labels) {
            System.out.println("Label: " + label.getName());
            System.out.println("Confidence: " + label.getConfidence().toString() + "\n");

            List<Instance> instances = label.getInstances();
            System.out.println("Instances of " + label.getName());
            if (instances.isEmpty()) {
                System.out.println("  " + "None");
            } else {
                for (Instance instance : instances) {
                    System.out.println("  Confidence: " + instance.getConfidence().toString());
                    System.out.println("  Bounding box: " + instance.getBoundingBox().toString());
                }
            }
            System.out.println("Parent labels for " + label.getName() + ":");
            List<Parent> parents = label.getParents();
            if (parents.isEmpty()) {
                System.out.println("  None");
            } else {
                for (Parent parent : parents) {
                    System.out.println("  " + parent.getName());
                }
            }
            System.out.println("--------------------");
            System.out.println();
           
        }
    } catch (AmazonRekognitionException e) {
        e.printStackTrace();
    }
}