#debes instalar primero boto3 y pillow asi #sudo pip-3.
6 install pillow
#este programa detecta labels
import boto3
import pprint
from PIL import Image, ImageDraw
rek=boto3.client('rekognition')
with open('monalisaOriginal.jpg', 'rb') as f:
image_bytes=f.read()
response=rek.detect_labels(
Image={
'Bytes': image_bytes
})
pprint.pprint(response)
#este segundo programa detecta LAS CARACTERISTICAS DE LA CARA
response=rek.detect_faces(
Image={
'Bytes': image_bytes
},
Attributes=['ALL'])
pprint.pprint(response)
#este ter cerprograma imprime reconoce las expresiones faciales y
las redondea
src=Image.open('monalisaOriginal.jpg')
draw1=ImageDraw.Draw(src)
width, height=src.size
img=Image.new('RGB',src.size)
draw=ImageDraw.Draw(img)
img.paste(src, (0,0))
for face in response['FaceDetails']:
for point in face['Landmarks']:
x=point['X']*width
y=point['Y']*height
r=5
draw.ellipse((x-r, y-r, x+r, y+r), fill='red')
img.save('monalisaOriginal-rek.jpg')
#este programa reconoce texto
rek=boto3.client('rekognition')
with open('calleFalta.jpg', 'rb') as f:
image_bytes=f.read()
response=rek.detect_text(
Image={
'Bytes': image_bytes
} )
pprint.pprint(response)
# este programa circula el texto detectado y lo guarda en un
nuevo archivo llamado calleFalta-rek
src=Image.open('calleFalta.jpg')
draw1=ImageDraw.Draw(src)
width, height=src.size
img=Image.new('RGB',src.size)
draw=ImageDraw.Draw(img)
img.paste(src, (0,0))
for text in response['TextDetections']:
points=[(point['X']*width, point['Y']*height) for point in text['Geometry']
['Polygon']]
points.append(points[0])
draw.line(points, fill='red',width=9)
img.save('calleFalta-rek.jpg')