Detect People with Raspberry Pi and MATLAB Online

In this demo, I will show you how to detect people from a Pi camera using a Raspberry Pi™ and MATLAB Online™.

If you haven’t set up your Raspberry Pi in MATLAB Online, please refer to the documentation to learn how.

Use the command raspilist to see the online Raspberry Pis. You need to connect to your board using the function raspi(). You can either specify a Raspberry Pi or use the default which connects to the most recent board.

Here, I’m using a Raspberry Pi camera Module V2, which is connected to the Pi using the ribbon cable. Connect to it by using the function cameraboard(). Here, I’m using the resolution 640 by 480.

Next, you can load the people detector. This detector was trained using a person data set. It detects upright people using aggregate channel features.

Here you can use a for loop to repeatedly take images using the snapshot() function, and use the detect() function to find the people in the image and store the results as bounding boxes and scores.

Now, you can insert these results into the image using insertObjectAnnotation() and then use imshow() to display the image to the screen.

Click Run and a figure on the right will show up.

As you can see, as people walk into frame, they are highlighted by the yellow bounding boxes along with a score at the top of the box.

We’ve successfully detected people from the Raspberry Pi camera using MATLAB Online.

For more information, please visit the documentation at

Working with Raspberry Pi Camera Board