Let your Raspberry Pi see with Azure Computer Vision! By the end of this tutorial, you'll have your Raspberry Pi detecting objects that are in the frame of the camera. You can try this out or a prototype a product at no cost using a free tier of the computer vision cognitive service.
- An active Azure account. If you don't have one, you can sign up for a free account.
- VS Code
- Hardware listed below
Item | Description | Link |
---|---|---|
Raspberry Pi 3 or 4 | Single board computer | Adafruit |
Raspberry Pi Camera V2 | Ribbon camera for the Pi | Adafruit |
USB C power supply (Pi 4) | Power cable for Raspberry Pi 4 | Adafruit |
Micro USB USB power supply (Pi 3) | Power cable for Raspberry Pi 3 | Adafruit |
SD Card with Raspberry Pi OS | Operating system for the Pi | Adafruit |
Resource | Description | Link |
---|---|---|
Computer Vision | Computer vision API from Azure | Azure |
-
If you haven't already, clone this repo to your computer
-
Open command prompt or terminal and navigate to pi-azure-recipes
-
In command prompt or terminal type and run
code 03_cv
. This will open the project folder in VS Code
-
First you'll need to create a computer vision resource
-
Select your subscription
-
For resource group select Create new, and give your resource group a name
-
Select a Location that is near you
-
Give your computer vision resource a name
-
Select Free F0 for the pricing tier
Note: You can only have one free tier active per account
-
After your resource is deployed, select Go to resource
-
You will need the key and endpoint from this resource to connect your Raspberry Pi to it. Select Keys and Endpoints from the left navigation.
-
Make a note of the key and endpoint for your resource, you'll use these later on your Pi.
Rember to treat these like passwords
-
Connect your Raspberry Pi to a monitor and keyboard or use the the instructions here to setup your pi for SSH
-
Set up your Pi camera using this guide
-
Using a USB drive or an SSH file transfer software copy the client folder to the Pi
-
Install required C libraries
sudo apt install -y libgfortran5 libatlas3-base
-
Run the python_environment_setup.sh shell script
-
Once the script finishes navigate to the client folder press *Ctrl + H to show hidden files.
-
Open the newly created .env file in a text editor and fill in your key and endpoint
SUBSCRIPTION_KEY='YOUR-SUBSCRIPTION-KEY' ENDPOINT='YOUR-ENDPOINT'
-
Then type
source .venv/bin/activate python raspberry_pi_client.py
-
You should see the picture the camera took and what the Computer Vision service was able to identify in it.
If you keep the resources you provisioned you'll continue to incur costs on them. The steps below will walk you through how to clean up your resources.
-
In the Azure portal navigate to the resource group you created earlier
-
In the Resource group page, review the list of included resources, and verify that they are the ones you want to delete
-
Select Delete resource group, and follow the instructions.
Deletion may take a couple of minutes. When it's done, a notification appears for a few seconds. You can also select the bell icon at the top of the page to view the notification.