banner



How To Upload Images To Dexter

gcplogo Google Cloud Vision on the Raspberry PiGive Your GoPiGo Smart Vision

What is Google Cloud Vision API? Cheque out the video by Google here:

Utilise 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.   Start, we'll walk you through setting up the Google Deject Platform. Note: the Google Cloud Platform may modify in the time to come and this is out of our control. Nosotros've updated this tutorial on April 2019.

Adjacent, we will use the Raspberry Pi Camera to have a picture of an object, and then use the Raspberry Pi to upload the movie taken to Google Deject.

Finally, we tin can analyze the moving picture in the cloud, and the cloud will either try to label the picture (tell us in text what'southward going on in the picture), or endeavour to detect logos in the picture (company logos that are in the movie) or analyze faces in the flick (tell us everything from emotions on the face up to where the face is on the flick).  Skynet hither we come!

raspberry-pi-camera-and-ribbon A camera for the Google Cloud Vision on the Raspberry Pi

These directions are meant to simplify getting started with Cloud Vision on your Raspberry Pi.  They are derived from directions found here just modified to work with the Raspberry Pi, and simplify set upwardly.  We volition use Google Deject Vision on the Raspberry Pi to detect images with these three python examples.

raspberry-pi-b-angled-stylizedTools

  • Raspberry Pi  (Pi3 or newer)
  • Raspbian for Robots SD Carte du jour
  • Ability Supply
  • Raspberry Pi Photographic camera
  • Google Deject Business relationship

The Google Deject Account requires a credit bill of fare although low use projects will not incur charges. Do verify the billing information before going ahead. This is controlled by Google and we take no say in it. Verify pricing before going ahead with the project and know your limits!

These directions assume you're using Raspbian for Robots on your SD Card.  You can buy an SD Card with Raspbian for Robots on it, or you tin can download it for free and install it using our directions here.

GoPiGo is analyzed by Google Cloud Vision using the Raspberry PI.

In this picture nosotros've asked Google Cloud Vision to analyze the GoPiGo on the left, with the returned text response on the right.  It returns "labels" (the things information technology sees in the pic) such equally "vehicle", "bike", "toy", "product", and "model machine".  Pretty good task Google!

Google Cloud Set Up

The offset step is to fix a Google Deject Account.  Y'all can create an account hither. You tin can create an account with either your Google or Gmail login.

You will demand to follow the 3 setup steps on the Getting Started page. Y'all do not demand to create a Cloud Storage bucket unless you lot want to upload images straight.

Create a projection:

After you've created your business relationship, you can prepare upwardly a project and enable billing.  First, click here to go to the Google Cloud Manage Resources Folio.

Create a new projection.

Create a new Project in Google Projects

In our example, we named it "vision1"

Create a new Project in Google Projects

Name the new project vision1

It will take a little fleck before the projection is created. Be patient.

Billing:

You lot volition need to enable billing for your account (yous won't be charged if you keep it inside the gratuitous limits).  You can follow the appropriate instructions by clicking here.  Go to the Deject Platform Console here.  Select the project "vision1" and click the hamburger in the upper left mitt corner of the page.

Select Billing on the left hand side.  From here, you tin can enable billing on your Google Cloud business relationship.

If you want to ensure you're not going to be hit by a huge bill, you tin fix a budget for your account. Read more about budgeting with the Google Platform. A budget will ship yous alerts just volition not put a hard limit on your business relationship.  You lot tin also gear up a difficult limit by following capping instructions.

API:

Finally, we'll enable the API.  Click here to enable the API.  Select the "vision1" account we created.  Click "Continue".  You should get a bulletin that API is enabled.

Getting a JSON Fundamental

Now we want to get a JSON fundamental to put on our Raspberry Pi.  This JSON primal will handle all the hallmark to utilise our Google Cloud Account.  Instead of a countersign, we can use the file to authenticate our account on the Raspberry Pi.

Circumspection: You lot should be careful where you shop this primal.  Be sure to change the countersign on your Raspberry Pi earlier putting the JSON key on information technology, leaving your JSON key unprotected could betrayal you to something malicious!  To alter your Raspberry Pi passowrd, open up a final and type:

sudo passwd

And follow the prompts to change the password on the Raspberry Pi.

Become Your Credentials:

  1. Once the API is enabled, you will need your credentials. Click on the "Become to credentials" push button.
  2. Ensure Cloud Vision is selected, nosotros will not exist using the GCE or the GAE. Click the "What credentials do I need?" button.
  3. Create the JSON file. Enter a name for the service account. Select a role: Project/Owner will give total control, not skilful for an actual project, but good enough for experimentation. Click the "Continue" button to download the json file.

A popup should come up up telling y'all y'all have created a new cardinal, and an automatic download of the JSON key should begin.  Keep rails of this file!

That should be it, you lot should have a service account key!

Y'all should at present employ an FTP program (such as FileZilla) or Samba (see our tutorial here!) to move the JSON file over to your Raspberry Pi.  Place the JSON file in the home directory /home/pi

Optional: Test the Account

At present that the account is ready up, why not upload an image from your computer and test it here?  Yous can follow this tutorial to effort out a few images and see what Google thinks they are!

camel

Utilize our picture above.  Is it an brute? A reptile?  Google volition tell you!

Fix Upwards the Hardware

The hardware is pretty unproblematic!  We'll be using a Raspberry Pi Camera with the Raspberry Pi, here are some directions on setting upwardly the camera.

close_camera_port

These Raspberry Pi Camera setup directions assume yous're using Raspbian for Robots on your SD Card.  Y'all can buy an SD Carte du jour with Raspbian for Robots on information technology, or you can download information technology for free and install information technology using our directions here.  If yous're not using Raspbian for Robots, you volition need to take additional steps to enable and setup your camera; hither are some directions on setting up the camera.

Ready the Raspberry Pi

In this project, nosotros're assuming you're using our image, Raspbian for Robots.  If you're not, you lot can download it here!

Next, we'll upgrade a few things, just in example. Note that we are installing these libraries for Python3.

                      python3          -          one thousand          pip          install          -          -user          pip        

Next, install Google API Python Customer.   Again in the control line, run:

          python3 -k pip install --user google-deject-vision

Side by side, install Python Imaging Library.  Again in the command line, run:

          python3 -m pip install --user Pillow

Next, install latest version of Picamera:

          python3 -yard pip install --user picamera

In the home directory, nosotros will make the JSON file available to any application we're running.  Run the control:

consign GOOGLE_APPLICATION_CREDENTIALS=/home/pi/filename.json

Be sure to substitute your JSON filename in this command with the name of the file you have on your Raspberry Pi.

Optional: Make Credentials Permanent

You lot can besides make the Google Awarding Credentials permanent.  You can brand the JSON credentials from Google accessible to any python program running on your Raspberry Pi.

First, open up the bashrc file:

sudo nano ~/.bashrc

Scroll to the very bottom of the file, and add together the line:

          GOOGLE_APPLICATION_CREDENTIALS=          "/home/pi/filename.json"        

Be sure to replace the variable "filename" with the proper name of your file.

Now, load the credential by typing in the command line:

source ~/.bashrc

Finally, confirm that the credentials are set:

          repeat $GOOGLE_APPLICATION_CREDENTIALS

This should render the file path and name:  '/dwelling house/pi/filename.json"

Become the Case Lawmaking

Become the example code: we have iii python examples on Github here.

          git clone https://github.com/DexterInd/GoogleVisionTutorials

Observe a Logo

raspberry-pi-gopigo-robot-with-google-vision-reading-raspberry-pi-logo

First, we'll endeavour to become the Raspberry Pi to detect the Raspberry Pi Logo.  Nosotros'll utilize the big Raspberry Pi label on the Raspberry Pi Box.  Set the Pi box nearly 1 ft from the camera.  Nosotros'll be propping up the camera with a Raspberry Pi Robot, the GoPiGo.  It holds the photographic camera in place with the acrylic body, and nosotros will employ it afterwards for some fun projects!

You lot might want to take a examination motion-picture show to make certain the label is visible.  In the command line, run

          raspistill -o cam.jpg

If the picture looks ok, nosotros'll move forth!

image

If not already done, we'll make our JSON credentials bachelor.  In the command line, type (substitute filename with the bodily filename you got from Google):

          consign GOOGLE_APPLICATION_CREDENTIALS=filename.json

And now, in the example directory, run:

          python3 camera_vision_logo.py

You should get "Raspberry Pi" back!

Heady stuff!  Now you lot tin go effectually the firm looking for more corporate logos!

Label Pictures

One of the absurd things you can exercise with Google Vision is get the cloud to figure out what's in the movie yous take.  Let's have a picture of a GoPiGo Wheel and see what the cloud thinks information technology is.

Gear up upwardly the camera and run the sample program.  Again, we'll be belongings the camera in place with the GoPiGo robot kit.

          python3 camera_vision_label.py

raspberry-pi-gopigo-robot-with-google-vision

With the camera set up, nosotros'll take a test picture.  Looks like the wheel is in there.

image-of-gopigo-wheel-with-raspberry-pi-camera-using-google-cloud-vision

In this sample program we'll return the unabridged JSON response.  We get a few interesting results from the picture:  "xanthous" (with an 80% score), "bike", "product", "tire", "toy" and "automotive tire".

google-vision-label-detection-wheel-detection

Facial Detection With the Raspberry Pi

Hither'due south the scary function!  Let's detect a face up and see if Google can detect some emotions!  With Google Cloud Vision you tin detect a range of emotions, headwear, some head coordinates, and other fun data.  For this office, I made a special selfie-Pi using the GrovePi Case.

raspberry-pi-grovepi-robot-with-google-vision Google Cloud Vision on the Raspberry Pi selfie hardware!

I ran the program in the control line:

python3 camera_vision_face.py

Here'south the picture I took:

Work is so much fun! Google Cloud Vision on the Raspberry Pi takes a picture an analyzes a face!

"Work is so much fun!"

Conspicuously I'thousand trying to smile a piffling for the camera!  The response Google gives for facial analysis is pretty long, the JSON is very detailed, then I'thousand pulling the highlights below:

face-annotations-1

According to Google Vision, I'm non likely to exist Angry (VERY_UNLIKELY)

face-annotations-2

I'thousand not probable to be wearing headwear,  notwithstanding, it is possible that I've got joy (joyLikelihood is "POSSIBLE").

face-annotations-3

Finally, I'yard not likely to be sorrowful, and I'm not likely to be surprised.  These are just some of the emotions that Google Cloud Vision will browse faces for and return information on.

raspberry-pi-camera-on-gopigo-no-servo-front-view Google Cloud Vision on the Raspberry PiConclusion

Google Cloud Vision is a really fun service to just play around with!  Google Deject Vision on the Raspberry Pi is perfect for projects with the Raspberry Pi and Raspberry Pi Camera, and adds in-context vision for the Raspberry Pi.

dex-black-with-white-face-analyzed-by-google-cloud-vision

Above is a picture of "Dex" our company mascot, analyzed by Google for labels.  You can see the computer correctly analyzes it every bit "electronics" and "technology"!

Troubleshooting

A few issues we've run into that might assistance you!

Optimal image size: The optimal prototype size for face recognition with Google Vision is 1600 x 1200 – y'all tin prepare this using the python lines

photographic camera = picamera.PiCamera() camera.resolution = (1600, 200)

Clock and Date Bug: For proper hallmark with the Google Cloud services, your clock must exist correct (or darn about correct within about 12 hours).  If it is non, y'all will see the following error:

raise HttpAccessTokenRefreshError(error_msg, status=resp.status) oauth2client.client.HttpAccessTokenRefreshError: invalid_grant: Invalid JWT: Token must be a short-lived token and in a reasonable timeframe

If the python example throws this error, you demand to update your clock.  This can exist tricky: it should be automatically updated if you kicking the Pi while plugged into an ethernet network.  However, if y'all are using wifi, or your network isn't working properly, you tin can set the Raspberry Pi time manually with the control:

date -u 110316262016

This is using the format "MMDDhhmmCCYY" where M is the calendar month, D is the day, h is the hr, k is the minute, C is the century (probably 20), and Y is the year (in 2016, this is 16).

Questions?

Inquire on our forums!

Learn More!

If you liked this tutorial, consider buying the SD Carte with Raspbian for Robots here, Raspberry Pi Camera hither and the GoPiGo Starter kit hither.

How To Upload Images To Dexter,

Source: https://www.dexterindustries.com/howto/use-google-cloud-vision-on-the-raspberry-pi/

Posted by: petersmuctancer.blogspot.com

0 Response to "How To Upload Images To Dexter"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel