Before you start

Be sure you've followed the steps in Create Categories first.

Setting up the Raspberry Pi

First, follow the instructions in Raspberry Pi Setup. This will load the software onto the Pi.

Launch the capture script

SSH to the pi, or open a Terminal. Then, run these commands to set up the shell:

$ cd rpi-vision
$ sudo bash
# source .venv/bin/activate

Get ready to capture the first samples. Then, at the same shell, type:

# python3 tests/pitft_capture.py 
pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html

Ready. Press ENTER to toggle capture/standby. Press Ctrl+C to quit.    
You may need to adjust the focal distance of your Pi camera by rotating the lens. The Raspberry Pi Camera Board v2 includes a handy adjustment wheel.

At this point, the Raspberry Pi display should look like this.

Record some data

At this point, the STANDBY text indicates that the Pi is not recording data. Make sure the camera is pointed at your object, then press ENTER to toggle between STANDBY and RECORD modes.

In RECORD mode, the script is capturing frames and saving them to the Pi's SD card. The display looks like this.

Press ENTER to toggle between STANDBY and RECORD modes.

Be sure you see the frame count increasing. This means that the Pi is saving data to the SD card.

When finished, press CTRL + C to stop the process.

Copy images to your desktop/laptop computer

Here we show you how to use either samba or scp to copy the generated tar to your desktop/laptop for use with Teachable Machine.

Using Samba

The easiest way is to setup your Raspberry Pi as a file server using Samba. Follow these steps.

Now, copy the generated tarball into your samba share:

$ cp ~/rpi_vision/<<OBJECT_NAME>>.tar /share

On your local desktop, look for the RASPBERRYPI machine on your network. Connect to the share and copy the tar to your local machine.

Using scp

On your local machine (i.e. not the raspberry pi), run:

$ scp [email protected]:~/rpi_vision/<<OBJECT_NAME>>.tar .

Be sure to change <<OBJECT_NAME>>.tar to the actual path you specified to your pitft_capture.py command above.

Upload images to Teachable Machine

Extract the tar by double-clicking it. On Windows, you may need a utility like 7-zip.

Now, in the Teachable Machine UI, follow these steps:

click the Upload button next to the class box these images belong to.

Now drag-n-drop the images from your file browser onto the dialog.

You can also click on the folder to find them from within the browser.

When done, the box looks like this.

Repeat this process for all categories in your project.

This guide was first published on Jan 27, 2020. It was last updated on Mar 08, 2024.

This page (Use Raspberry Pi Camera) was last updated on Mar 08, 2024.

Text editor powered by tinymce.