def label_image(img, confidence=50): ''' Creates and returns a copy of the image, with labels from Rekognition displayed on it :param img: a string that is either the URL or filename for the image :param confidence: the confidence level (defaults to 50) :return: a copy of the image, with labels from Rekognition displayed on it ''' # replace pass below with your implementation labelList = get_labels(img,confidence) #get the labels for a given confidence labelListStr = ' , '.join(labelList) #join the list with a comma after each value #convert the image to a pillow image imgbytes = get_image(img) img = get_pillow_img(imgbytes) #create a new image with the text added img2ElectricBogaloo = add_text_to_img(img, labelListStr, font=ImageFont.truetype('Impact.ttf', 28), bgcolor=(255, 255, 255, 100)) return img2ElectricBogaloo
def label_image(img, confidence=50): ''' Creates and returns a copy of the image, with labels from Rekognition displayed on it :param img: a string that is either the URL or filename for the image :param confidence: the confidence level (defaults to 50) :return: a copy of the image, with labels from Rekognition displayed on it ''' # replace pass below with your implementation client = boto3.client('rekognition') imgbytes = image_helpers.get_image(img) pimg = get_pillow_img(imgbytes) rekresp = client.detect_labels(Image={'Bytes': imgbytes}, MinConfidence=50) label_list = [] for label in rekresp['Labels']: print(label['Name'], label['Confidence']) label_list.append(label['Name']) print(label_list) if 'Food' in label_list: if 'Hot Dog' in label_list: img1 = add_text_to_img(pimg, "Hot Dog", pos=(0, 0), color=(0, 220, 0)) return img1 else: img1 = add_text_to_img(pimg, "Not Hot Dog", pos=(0, 0), color=(220, 0, 0)) return img1 else: img1 = add_text_to_img(pimg, "Not Food", pos=(0, 0), color=(0, 0, 220)) return img1
def label_image(img, confidence=50): ''' Creates and returns a copy of the image, with labels from Rekognition displayed on it :param img: a string that is either the URL or filename for the image :param confidence: the confidence level (defaults to 50) :return: a copy of the image, with labels from Rekognition displayed on it ''' # replace pass below with your implementation imgbytes = image_helpers.get_image(img) imgpillow = get_pillow_img(imgbytes) nametext = [] name = get_labels(img, confidence) for label in name: nametext.append(label['Name']) text = ', '.join(nametext) pprint(text) hour = datetime.datetime.now().time().hour if hour <= 10: texttpspeech = "Good Morning. " elif hour > 10 and hour <= 16: texttpspeech = "Good Afternoon. " else: texttpspeech = "Good Evening. " texttpspeech = texttpspeech + "The image contains : " + text + ". " text_on_image = text_image.textImage(imgbytes) if text_on_image == "" or text_on_image == " ": texttpspeech = texttpspeech else: texttpspeech = texttpspeech + " The text written on image is " + text_on_image + ". " myList = [ 'Human', 'People', 'Person', 'Female', 'Male', 'Girl', 'Boy', 'Woman', 'Man', 'Face', 'Laughing', 'Smile', 'Blonde', 'Crowd' ] flag = 0 celebrity = [] for i in myList: if flag == 0 and texttpspeech.__contains__(i): flag = 1 #pprint("Text found "+i) texttpspeech = texttpspeech + (str)( face_detect.describe_faces(imgbytes)) celebrity = celebs.celeb(imgbytes) if not celebrity: foundFaces = searchFacesInCollection.search_faces(imgbytes) if foundFaces == "": texttpspeech = texttpspeech else: foundFaces = foundFaces.replace("_", " ") texttpspeech = texttpspeech + "I can recognize the personal as " + foundFaces + ". " face_detect_draw.acceptImagebytes(imgbytes) else: texttpspeech = texttpspeech + "I can recognize the personal as : " + ', '.join( celebrity) + '. ' text = ', '.join(celebrity) break apptext.text_to_speech(texttpspeech, 'Amy') return add_text_to_img(imgpillow, text)
def label_image(img): ''' Creates and returns a copy of the image, with labels from Rekognition displayed on it :param img: a string that is either the URL or filename for the image :return: a copy of the image, with labels from Rekognition displayed on it ''' # replace pass below with your implementation ## Getting Labels label=get_labels(img) message="" for i in label: if i == label[len(label)-1]: message=message+i['Name'] else: message=message+i['Name']+", " ## Getting Image bytes imgbytes=image_helpers.get_image(img) images=get_pillow_img(imgbytes) return add_text_to_img(images, message)
def get_labels(img, confidence=50): """ Gets the labels from AWS Rekognition for the given image :param img: either the image bytes or a string that is the URL or filename for an image :param confidence: the confidence level (defaults to 50) >>> get_labels('http://www.idothat.us/images/idothat-img/features/pool-patio-lanai/ft-pool-patio-lanai-2.jpg') [{'Name': 'Pool', 'Confidence': 96.66264343261719}, {'Name': 'Water', 'Confidence': 96.66264343261719}, {'Name': 'Resort', 'Confidence': 76.01207733154297}, {'Name': 'Swimming Pool', 'Confidence': 76.01207733154297}, {'Name': 'Balcony', 'Confidence': 66.56996154785156}, {'Name': 'Patio', 'Confidence': 62.89345169067383}, {'Name': 'Flagstone', 'Confidence': 59.46694564819336}, {'Name': 'Backyard', 'Confidence': 56.5162467956543}, {'Name': 'Yard', 'Confidence': 56.5162467956543}, {'Name': 'Path', 'Confidence': 52.408050537109375}, {'Name': 'Sidewalk', 'Confidence': 52.408050537109375}, {'Name': 'Walkway', 'Confidence': 52.408050537109375}, {'Name': 'Alley', 'Confidence': 50.79618835449219}, {'Name': 'Alleyway', 'Confidence': 50.79618835449219}, {'Name': 'Road', 'Confidence': 50.79618835449219}, {'Name': 'Street', 'Confidence': 50.79618835449219}, {'Name': 'Town', 'Confidence': 50.79618835449219}, {'Name': 'Plant', 'Confidence': 50.6763801574707}] >>> get_labels('http://www.idothat.us/images/idothat-img/features/pool-patio-lanai/ft-pool-patio-lanai-2.jpg', 90) [{'Name': 'Pool', 'Confidence': 96.66264343261719}, {'Name': 'Water', 'Confidence': 96.66264343261719}] """ # replace pass below with your implementation client = boto3.client('rekognition') imgbytes = image_helpers.get_image(img) rekresp = client.detect_labels(Image={'Bytes': imgbytes}, MinConfidence=confidence) name = [] for label in rekresp['Labels']: name.append({'Name': label['Name'], 'Confidence': label['Confidence']}) print(name) return name