├── Google-Cloud-Vision-on-the-Raspberry-Pi.jpg ├── README.md ├── camel.jpg ├── camera_vision_face.py ├── camera_vision_label.py ├── camera_vision_logo.py ├── face-google-vision.jpg └── wheel.jpg /Google-Cloud-Vision-on-the-Raspberry-Pi.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DexterInd/GoogleVisionTutorials/28e84b234ec2d7548f76234820b5d8222eb4baa1/Google-Cloud-Vision-on-the-Raspberry-Pi.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Google Cloud Vision Tutorials On The Raspberry Pi 2 | 3 | ![alt text](https://raw.githubusercontent.com/DexterInd/GoogleVisionTutorials/master/Google-Cloud-Vision-on-the-Raspberry-Pi.jpg "Use Google Cloud Vision On the Raspberry Pi") 4 | 5 | Google Vision API Tutorial with a Raspberry Pi and Raspberry Pi Camera. See more about it here: https://www.dexterindustries.com/howto/use-google-cloud-vision-on-the-raspberry-pi/ 6 | 7 | Use Google Cloud Vision on the Raspberry Pi to take a picture with the Raspberry Pi Camera and classify it with the Google Cloud Vision API. First, we'll walk you through setting up the Google Cloud Platform. Next, we will use the Raspberry Pi Camera to take a picture of an object, and then use the Raspberry Pi to upload the picture taken to Google Cloud. We can analyze the picture and return labels (what's going on in the picture), logos (company logos that are in the picture) and faces. 8 | -------------------------------------------------------------------------------- /camel.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DexterInd/GoogleVisionTutorials/28e84b234ec2d7548f76234820b5d8222eb4baa1/camel.jpg -------------------------------------------------------------------------------- /camera_vision_face.py: -------------------------------------------------------------------------------- 1 | """ 2 | Google Vision API Tutorial with a Raspberry Pi and Raspberry Pi Camera. See more about it here: https://www.dexterindustries.com/howto/use-google-cloud-vision-on-the-raspberry-pi/ 3 | 4 | Use Google Cloud Vision on the Raspberry Pi to take a picture with the Raspberry Pi Camera and classify it with the Google Cloud Vision API. First, we'll walk you through setting up the Google Cloud Platform. Next, we will use the Raspberry Pi Camera to take a picture of an object, and then use the Raspberry Pi to upload the picture taken to Google Cloud. We can analyze the picture and return labels (what's going on in the picture), logos (company logos that are in the picture) and faces. 5 | 6 | This script uses the Vision API's label detection capabilities to find a label 7 | based on an image's content. 8 | 9 | """ 10 | 11 | import picamera 12 | import os 13 | from PIL import Image, ImageDraw 14 | 15 | from google.cloud import vision 16 | client = vision.ImageAnnotatorClient() 17 | image_name = 'image.jpg' 18 | 19 | def takephoto(): 20 | camera = picamera.PiCamera() 21 | camera.capture(image_name) 22 | 23 | def draw_face_rectangle(image_in, rect_in): 24 | im = Image.open(image_in) 25 | f,e = os.path.splitext(image_in) 26 | image_out = f + "_out_boundrectangle" + e 27 | print("image out is named: "+ image_out) 28 | 29 | draw = ImageDraw.ImageDraw(im) 30 | draw.rectangle(rect_in) 31 | im.save(image_out) 32 | 33 | def main(): 34 | takephoto() # First take a picture 35 | """Run a label request on a single image""" 36 | 37 | with open(image_name, 'rb') as image_file: 38 | content = image_file.read() 39 | 40 | image = vision.types.Image(content=content) 41 | response = client.face_detection(image=image) 42 | faces = response.face_annotations 43 | # print(faces) 44 | 45 | # Names of likelihood from google.cloud.vision.enums 46 | likelihood_name = ('UNKNOWN', 'VERY_UNLIKELY', 'UNLIKELY', 'POSSIBLE', 47 | 'LIKELY', 'VERY_LIKELY') 48 | print('Faces:') 49 | 50 | for face in faces: 51 | print('anger: {}'.format(likelihood_name[face.anger_likelihood])) 52 | print('joy: {}'.format(likelihood_name[face.joy_likelihood])) 53 | print('surprise: {}'.format(likelihood_name[face.surprise_likelihood])) 54 | 55 | vertices = (['({},{})'.format(vertex.x, vertex.y) 56 | for vertex in face.bounding_poly.vertices]) 57 | 58 | rectangle = [] 59 | rectangle.append((face.bounding_poly.vertices[0].x,face.bounding_poly.vertices[0].y)) 60 | rectangle.append((face.bounding_poly.vertices[2].x,face.bounding_poly.vertices[2].y)) 61 | print('face bounds: {}'.format(','.join(vertices))) 62 | 63 | draw_face_rectangle(image_name, rectangle) 64 | 65 | 66 | 67 | if __name__ == '__main__': 68 | 69 | main() 70 | -------------------------------------------------------------------------------- /camera_vision_label.py: -------------------------------------------------------------------------------- 1 | """ 2 | Google Vision API Tutorial with a Raspberry Pi and Raspberry Pi Camera. See more about it here: https://www.dexterindustries.com/howto/use-google-cloud-vision-on-the-raspberry-pi/ 3 | 4 | Use Google Cloud Vision on the Raspberry Pi to take a picture with the Raspberry Pi Camera and classify it with the Google Cloud Vision API. First, we'll walk you through setting up the Google Cloud Platform. Next, we will use the Raspberry Pi Camera to take a picture of an object, and then use the Raspberry Pi to upload the picture taken to Google Cloud. We can analyze the picture and return labels (what's going on in the picture), logos (company logos that are in the picture) and faces. 5 | 6 | This script uses the Vision API's label detection capabilities to find a label 7 | based on an image's content. 8 | 9 | """ 10 | 11 | import picamera 12 | 13 | from google.cloud import vision 14 | client = vision.ImageAnnotatorClient() 15 | 16 | 17 | def takephoto(): 18 | camera = picamera.PiCamera() 19 | camera.capture('image.jpg') 20 | 21 | def main(): 22 | takephoto() # First take a picture 23 | """Run a label request on a single image""" 24 | 25 | with open('image.jpg', 'rb') as image_file: 26 | content = image_file.read() 27 | 28 | image = vision.types.Image(content=content) 29 | 30 | response = client.logo_detection(image=image) 31 | 32 | 33 | response = client.label_detection(image=image) 34 | labels = response.label_annotations 35 | print('Labels:') 36 | 37 | for label in labels: 38 | print(label.description) 39 | 40 | if __name__ == '__main__': 41 | 42 | main() 43 | -------------------------------------------------------------------------------- /camera_vision_logo.py: -------------------------------------------------------------------------------- 1 | import picamera 2 | from google.cloud import vision 3 | 4 | client = vision.ImageAnnotatorClient() 5 | image = 'image.jpg' 6 | 7 | def takephoto(): 8 | camera = picamera.PiCamera() 9 | camera.capture(image) 10 | 11 | def main(): 12 | global image 13 | takephoto() # First take a picture 14 | """Run a label request on a single image""" 15 | 16 | with open(image, 'rb') as image_file: 17 | content = image_file.read() 18 | 19 | image = vision.types.Image(content=content) 20 | 21 | response = client.logo_detection(image=image) 22 | logos = response.logo_annotations 23 | print('Logos:') 24 | 25 | for logo in logos: 26 | print(logo.description) 27 | 28 | if __name__ == '__main__': 29 | main() 30 | -------------------------------------------------------------------------------- /face-google-vision.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DexterInd/GoogleVisionTutorials/28e84b234ec2d7548f76234820b5d8222eb4baa1/face-google-vision.jpg -------------------------------------------------------------------------------- /wheel.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DexterInd/GoogleVisionTutorials/28e84b234ec2d7548f76234820b5d8222eb4baa1/wheel.jpg --------------------------------------------------------------------------------