Google vision + raspberry pi 3 + pi camera

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, but use LANDMARK_DETECTION ?
It can be done ?

Yes. Once you get the picture from the camera you can do whatever you want with it.

But the result I would like to receive on smartphone, analyzing the image almost in real time.
The python program is fine?

import argparse
import base64
import picamera
import json

from googleapiclient import discovery
from oauth2client.client import GoogleCredentials

def takephoto():
camera = picamera.PiCamera()

def main():
takephoto() # First take a picture
""“Run a label request on a single image”""

credentials = GoogleCredentials.get_application_default()
service ='vision', 'v1', credentials=credentials)

with open('image.jpg', 'rb') as image:
    image_content = base64.b64encode(
    service_request = service.images().annotate(body={
        'requests': [{
            'image': {
                'content': image_content.decode('UTF-8')
            'features': [{
                'type': 'LANDMARK_DETECTION',
                'maxResults': 10
    response = service_request.execute()
    print json.dumps(response, indent=4, sort_keys=True)	#Print it out and make it somewhat pretty.

if name == ‘main’:


The results from Google cloud could be sent to your phone through Bluetooth, or WiFi. Not sure how to do that exactly. But Google is your friend! It’s possible you may be able to do a transfer through wires. Can I ask what advantage this would give though? The result is a just a json file. It would take more time to send it to the phone probably.

Are you thinking the image recognition​ is done on the phone? All of that is done in the cloud.

Have I answered your question?

About the phone script. I think it’s fine, well at least looks fine.
I’d recommend looking at the docs. There examples written in python there too so that might help.

If you’re trying to do this with a phone, the best approach might be to use the Pi to take a picture and send it to your phone.

Once you have it there, there are tutorials on the Google website that should help you write a program in either Android (or iOS) to use Google Landmark detection.

Is it still possible to mount raspberry + camera pi on a drone, take pictures and receive information on smartphone?

Is it still possible to mount raspberry + camera on a drone, take pictures and receive information on smartphone or viewer?

Oh I see what you want to do. Yes it is. Sorry for replying a bit late, was out of town. Anyways I’ll explain the code.

So the first 6 lines are just importing the necessary modules.

In the definition of the takephoto() function it creates an object called camera and uses it to take the picture.

In the main function the first line obviously takes a photo then it does some setup with Google. That is done in the next two lines? First the “credentials” object is created and on the next line the “service” object is created. In that line it’s telling Google your goin to be using the vision API.

Then we get to the with open area. So basically the image is opened and when it is (next line) it basically primes the photo for being sent to Google. Skipping down to the service_request = .... that line is telling Google what exactly you want to do with the image and sends the image. Notice the part that says LANDMARK_DETECTION. That’s saying obviously you want to do landmark detection. I also would like to highlight that when it says 'content': image_content.decode('UTF-8') That is telling google what image to send.
So now that Google knows what you want from the image just sent, it’s time to get the image data

So go down to the response = service_request.execute() line. That creates the object called response which allows us to get data about the image from Google.
After that it prints out the response.

And for the last 2 lines that obviously runs the main() function.

I hope this helps. If my explanation was to complex or too basic please ask for clarification.

1 Like

Hi I am having issue unable to get it setup correctly according to instruction from here

  1. sudo wget is downloading an html file instead of folder with examples

  2. I created a single branch and downloaded from github and when try to run the python script, it’s returning error only. pls see screenshot as below. Please advice me how to fix…


My mistake, correcting it now! It should be sudo git clone