# construct string by attributes formated_str = ' {gender} - age {lowage}-{highage},' # mustache and beard detection if details['Mustache']['Value'] and facedeets['Beard']['Value']: formated_str += ' with beard and mustache,' elif details['Mustache']['Value']: formated_str += ' with mustache,' elif details['Beard']['Value']: formated_str += ' with beard,' # Sunglasses/eyeglasses detection if details['Sunglasses']['Value']: formated_str += ' wearing sunglasses,' elif details['Eyeglasses']['Value']: formated_str += ' wearing glasses,' formated_str += ' looks {emotion}' print( formated_str.format( gender=details['Gender']['Value'], lowage=details['AgeRange']['Low'], highage=details['AgeRange']['High'], emotion=details['Emotions'][0]['Type'].lower() ) ) image = get_image_from_file('images/team1.jpeg') facial_analysis(image) # facial_analysis_data(image)
import boto3 from pprint import pprint from image_helper import get_image_from_file, get_image_from_url def compare_faces_data(image_source, image_target): client = boto3.client('rekognition') response = client.compare_faces(SimilarityThreshold=80, SourceImage={'Bytes': image_source}, TargetImage={'Bytes': image_target}) pprint(response) def compare_faces(image_source, image_target): client = boto3.client('rekognition') response = client.compare_faces(SimilarityThreshold=80, SourceImage={'Bytes': image_source}, TargetImage={'Bytes': image_target}) for faceMatch in response['FaceMatches']: similarity = faceMatch['Similarity'] print(f'Matches with {round(similarity, 2)}% confidence') url_img_src = 'images/eu.jpg' url_img_target = 'images/role1.jpeg' img_src = get_image_from_file(url_img_src) img_target = get_image_from_file(url_img_target) # compare_faces(img_src, img_target) compare_faces_data(img_src, img_target)
import boto3 from pprint import pprint from image_helper import get_image_from_file, get_image_from_url def detect_text_data(image_bytes): client = boto3.client('rekognition') response = client.detect_text(Image={'Bytes': image_bytes}) pprint(response) def detect_text(image_bytes): client = boto3.client('rekognition') response = client.detect_text(Image={'Bytes': image_bytes}) textDetections = response['TextDetections'] for text in textDetections: print('Detected text:' + text['DetectedText']) print('Confidence: ' + "{:.2f}".format(text['Confidence']) + "%") print() return len(textDetections) document = get_image_from_file('images/cnh.jpg') card = get_image_from_file('images/card.png') detect_text(card) # detect_text_data(document)
import boto3 from pprint import pprint from image_helper import get_image_from_file, get_image_from_url def detect_labels_data(image_bytes): client = boto3.client('rekognition') response = client.detect_labels(Image={'Bytes': image_bytes}, MinConfidence=50) pprint(response) def detect_labels(image_bytes): client = boto3.client('rekognition') response = client.detect_labels(Image={'Bytes': image_bytes}, MinConfidence=50) print('\n\nLabels:') for label in response['Labels']: label_name = label['Name'] label_confidence = label['Confidence'] print(f' {label_name} -- {round(label_confidence, 2)}%') url = 'https://upload.wikimedia.org/wikipedia/commons/thumb/a/aa/Av_Francisco_Glic%C3%A9rio_-_Campinas_SP_-_panoramio.jpg/1200px-Av_Francisco_Glic%C3%A9rio_-_Campinas_SP_-_panoramio.jpg' image = get_image_from_file('images/role1.jpeg') detect_labels(image) # detect_labels_data(image)