Skip to content

Instantly share code, notes, and snippets.

@rmohta
Last active April 26, 2018 10:29
Show Gist options
  • Save rmohta/b4dcc09648c3748af631710f025e94bb to your computer and use it in GitHub Desktop.
Save rmohta/b4dcc09648c3748af631710f025e94bb to your computer and use it in GitHub Desktop.
import boto3
import os.path
###
# Process a local file and use AWS Rekognition detect labels and confidence factor
###
def process_local_file(file_name, aws_client):
with open(file_name, 'rb') as imageBytes:
response = client.detect_labels(Image={'Bytes': imageBytes.read()})
print('Detected labels in ' + file_name)
return response
def process_s3_file(file_name, bucket, aws_client):
response = client.detect_labels(Image={'S3Object':{'Bucket':bucket,'Name':file_name}})
print('Detected labels in ' + file_name +' in S3 bucket ' + bucket)
return response
def init_process_local_file(file_name):
client=boto3.client('rekognition','eu-west-1')
process_local_file(file_name, client)
for label in response['Labels']:
print (label['Name'] + ' : ' + str(label['Confidence']))
if __name__ == "__main__":
fileName='input.jpg'
bucket='rekognition-examples-bucket'
imageFileName='/var/tmp/IMG_4209.JPG'
capturedImage='/var/tmp/capturedImage.JPG'
client=boto3.client('rekognition','eu-west-1')
response = process_local_file(imageFileName, client)
for label in response['Labels']:
print (label['Name'] + ' : ' + str(label['Confidence']))
import pygame
import pygame.camera
from pygame.locals import *
import pygame.image
import awsRekognition
# pip install Pygame
def list_cameras():
camlist = pygame.camera.list_cameras()
if camlist:
for acam in camlist:
print ('Available Camera: '+ acam)
return camlist[0]
def capture_image(cam_location):
cam = pygame.camera.Camera(cam_location,(640,480))
cam.start()
image = cam.get_image()
pygame.image.save(image, "/var/tmp/capturedImage.JPG")
def main():
# As the camera module is optional, import it
# # and initialize it manually.
pygame.init()
pygame.camera.init()
cameraLocation = list_cameras()
capture_image(cameraLocation)
print('Took image')
pygame.camera.quit()
awsRekognition.init_process_local_file("/var/tmp/capturedImage.JPG")
if __name__=="__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment