Java Code Examples for software.amazon.awssdk.core.SdkBytes#fromInputStream()
The following examples show how to use
software.amazon.awssdk.core.SdkBytes#fromInputStream() .
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: ServiceIntegrationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 6 votes |
@Before public void uploadFunction() throws IOException { // Upload function SdkBytes functionBits; InputStream functionZip = new FileInputStream(cloudFuncZip); try { functionBits = SdkBytes.fromInputStream(functionZip); } finally { functionZip.close(); } CreateFunctionResponse result = lambda.createFunction(r -> r.description("My cloud function").functionName(FUNCTION_NAME) .code(FunctionCode.builder().zipFile(functionBits).build()) .handler("helloworld.handler") .memorySize(128) .runtime(Runtime.NODEJS12_X) .timeout(10) .role(lambdaServiceRoleArn)).join(); checkValid_CreateFunctionResponse(result); }
Example 2
Source File: GetExportIntegrationTest.java From aws-sdk-java-v2 with Apache License 2.0 | 5 votes |
@BeforeClass public static void setUp() throws IOException { IntegrationTestBase.setUp(); restApi = SdkBytes.fromInputStream(GetExportIntegrationTest.class.getResourceAsStream("/PetStore-Alpha-swagger-apigateway.json")); restApiId = apiGateway.importRestApi(r -> r.body(restApi).failOnWarnings(false)).id(); deploymentId = apiGateway.createDeployment(r -> r.stageName(STAGE).restApiId(restApiId)).id(); }
Example 3
Source File: DetectFaces.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
public static void detectFacesinImage(RekognitionClient rekClient,String sourceImage ) { try { InputStream sourceStream = new FileInputStream(new File(sourceImage)); SdkBytes sourceBytes = SdkBytes.fromInputStream(sourceStream); // Create an Image object for the source image Image souImage = Image.builder() .bytes(sourceBytes) .build(); DetectFacesRequest facesRequest = DetectFacesRequest.builder() .attributes(Attribute.ALL) .image(souImage) .build(); DetectFacesResponse facesResponse = rekClient.detectFaces(facesRequest); List<FaceDetail> faceDetails = facesResponse.faceDetails(); for (FaceDetail face : faceDetails) { //if (facesRequest.attributes().contains("ALL")) { AgeRange ageRange = face.ageRange(); System.out.println("The detected face is estimated to be between " + ageRange.low().toString() + " and " + ageRange.high().toString() + " years old."); System.out.println("There is a smile : "+face.smile().value().toString()); } } catch (RekognitionException | FileNotFoundException e) { System.out.println(e.getMessage()); System.exit(1); } // snippet-end:[rekognition.java2.detect_faces.main] }
Example 4
Source File: DetectLabels.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
public static void detectImageLabels(RekognitionClient rekClient, String sourceImage) { try { InputStream sourceStream = new FileInputStream(new File(sourceImage)); SdkBytes sourceBytes = SdkBytes.fromInputStream(sourceStream); // Create an Image object for the source image Image souImage = Image.builder() .bytes(sourceBytes) .build(); DetectLabelsRequest detectLabelsRequest = DetectLabelsRequest.builder() .image(souImage) .maxLabels(10) .build(); DetectLabelsResponse labelsResponse = rekClient.detectLabels(detectLabelsRequest); // Display the results List<Label> labels = labelsResponse.labels(); System.out.println("Detected labels for the given photo"); for (Label label: labels) { System.out.println(label.name() + ": " + label.confidence().toString()); } } catch (RekognitionException | FileNotFoundException e) { System.out.println(e.getMessage()); System.exit(1); } // snippet-end:[rekognition.java2.detect_labels.main] }
Example 5
Source File: DetectModerationLabels.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
public static void detectModLabels(RekognitionClient rekClient, String sourceImage) { try { InputStream sourceStream = new FileInputStream(new File(sourceImage)); SdkBytes sourceBytes = SdkBytes.fromInputStream(sourceStream); // Create an Image object for the source image Image souImage = Image.builder() .bytes(sourceBytes) .build(); DetectModerationLabelsRequest moderationLabelsRequest = DetectModerationLabelsRequest.builder() .image(souImage) .minConfidence(60F) .build(); DetectModerationLabelsResponse moderationLabelsResponse = rekClient.detectModerationLabels(moderationLabelsRequest); // Get the results List<ModerationLabel> labels = moderationLabelsResponse.moderationLabels(); System.out.println("Detected labels for image"); for (ModerationLabel label : labels) { System.out.println("Label: " + label.name() + "\n Confidence: " + label.confidence().toString() + "%" + "\n Parent:" + label.parentName()); } } catch (RekognitionException | FileNotFoundException e) { e.printStackTrace(); System.exit(1); } // snippet-end:[rekognition.java2.detect_mod_labels.main] }
Example 6
Source File: RecognizeCelebrities.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
public static void recognizeAllCelebrities(RekognitionClient rekClient, String sourceImage) { try { InputStream sourceStream = new FileInputStream(new File(sourceImage)); SdkBytes sourceBytes = SdkBytes.fromInputStream(sourceStream); // Create an Image object for the source image Image souImage = Image.builder() .bytes(sourceBytes) .build(); RecognizeCelebritiesRequest request = RecognizeCelebritiesRequest.builder() .image(souImage) .build(); RecognizeCelebritiesResponse result = rekClient.recognizeCelebrities(request) ; List<Celebrity> celebs=result.celebrityFaces(); System.out.println(celebs.size() + " celebrity(s) were recognized.\n"); for (Celebrity celebrity: celebs) { System.out.println("Celebrity recognized: " + celebrity.name()); System.out.println("Celebrity ID: " + celebrity.id()); System.out.println("Further information (if available):"); for (String url: celebrity.urls()){ System.out.println(url); } System.out.println(); } System.out.println(result.unrecognizedFaces().size() + " face(s) were unrecognized."); } catch (RekognitionException | FileNotFoundException e) { System.out.println(e.getMessage()); System.exit(1); } // snippet-end:[rekognition.java2.recognize_celebs.main] }
Example 7
Source File: SearchFaceMatchingImageCollection.java From aws-doc-sdk-examples with Apache License 2.0 | 5 votes |
public static void searchFaceInCollection(RekognitionClient rekClient,String collectionId, String sourceImage) { try { InputStream sourceStream = new FileInputStream(new File(sourceImage)); SdkBytes sourceBytes = SdkBytes.fromInputStream(sourceStream); // Create an Image object for the source image Image souImage = Image.builder() .bytes(sourceBytes) .build(); SearchFacesByImageRequest facesByImageRequest = SearchFacesByImageRequest.builder() .image(souImage) .maxFaces(10) .faceMatchThreshold(70F) .collectionId(collectionId) .build(); // Invoke the searchFacesByImage method SearchFacesByImageResponse imageResponse = rekClient.searchFacesByImage(facesByImageRequest) ; // Display the results System.out.println("Faces matching in the collection"); List<FaceMatch> faceImageMatches = imageResponse.faceMatches(); for (FaceMatch face: faceImageMatches) { System.out.println("The similarity level "+face.similarity()); System.out.println(); } } catch (RekognitionException | FileNotFoundException e) { System.out.println(e.getMessage()); System.exit(1); } // snippet-end:[rekognition.java2.search_faces_collection.main] }
Example 8
Source File: AddFacesToCollection.java From aws-doc-sdk-examples with Apache License 2.0 | 4 votes |
public static void addToCollection(RekognitionClient rekClient, String collectionId, String sourceImage) { try { InputStream sourceStream = new FileInputStream(new File(sourceImage)); SdkBytes sourceBytes = SdkBytes.fromInputStream(sourceStream); // Create an Image object for the source image Image souImage = Image.builder() .bytes(sourceBytes) .build(); // Create an IndexFacesRequest object IndexFacesRequest facesRequest = IndexFacesRequest.builder() .collectionId(collectionId) .image(souImage) .maxFaces(1) .qualityFilter(QualityFilter.AUTO) .detectionAttributes(Attribute.DEFAULT) .build(); // Invoke the indexFaces method IndexFacesResponse facesResponse = rekClient.indexFaces(facesRequest); // Display the results System.out.println("Results for the image"); System.out.println("\n Faces indexed:"); List<FaceRecord> faceRecords = facesResponse.faceRecords(); for (FaceRecord faceRecord : faceRecords) { System.out.println(" Face ID: " + faceRecord.face().faceId()); System.out.println(" Location:" + faceRecord.faceDetail().boundingBox().toString()); } List<UnindexedFace> unindexedFaces = facesResponse.unindexedFaces(); System.out.println("Faces not indexed:"); for (UnindexedFace unindexedFace : unindexedFaces) { System.out.println(" Location:" + unindexedFace.faceDetail().boundingBox().toString()); System.out.println(" Reasons:"); for (Reason reason : unindexedFace.reasons()) { System.out.println("Reason: " + reason); } } } catch (RekognitionException | FileNotFoundException e) { System.out.println(e.getMessage()); System.exit(1); } // snippet-end:[rekognition.java2.add_faces_collection.main] }
Example 9
Source File: CompareFaces.java From aws-doc-sdk-examples with Apache License 2.0 | 4 votes |
public static void compareTwoFaces(RekognitionClient rekClient, Float similarityThreshold, String sourceImage, String targetImage) { try { InputStream sourceStream = new FileInputStream(new File(sourceImage)); InputStream tarStream = new FileInputStream(new File(targetImage)); SdkBytes sourceBytes = SdkBytes.fromInputStream(sourceStream); SdkBytes targetBytes = SdkBytes.fromInputStream(tarStream); // Create an Image object for the source image Image souImage = Image.builder() .bytes(sourceBytes) .build(); // Create an Image object for the target image Image tarImage = Image.builder() .bytes(targetBytes) .build(); // Create a CompareFacesRequest object CompareFacesRequest facesRequest = CompareFacesRequest.builder() .sourceImage(souImage) .targetImage(tarImage) .similarityThreshold(similarityThreshold) .build(); // Compare the two images CompareFacesResponse compareFacesResult = rekClient.compareFaces(facesRequest); // Display results List<CompareFacesMatch> faceDetails = compareFacesResult.faceMatches(); for (CompareFacesMatch match: faceDetails){ ComparedFace face= match.face(); BoundingBox position = face.boundingBox(); System.out.println("Face at " + position.left().toString() + " " + position.top() + " matches with " + face.confidence().toString() + "% confidence."); } List<ComparedFace> uncompared = compareFacesResult.unmatchedFaces(); System.out.println("There was " + uncompared.size() + " face(s) that did not match"); System.out.println("Source image rotation: " + compareFacesResult.sourceImageOrientationCorrection()); System.out.println("target image rotation: " + compareFacesResult.targetImageOrientationCorrection()); } catch(RekognitionException | FileNotFoundException e) { System.out.println("Failed to load source image " + sourceImage); System.exit(1); } // snippet-end:[rekognition.java2.compare_faces.main] }