Raspberry Pi Support from MATLAB, Part 3: Deploy an Edge Detection Algorithm on Raspberry Pi
From the series: Raspberry Pi Support from MATLAB
Learn how to develop and prototype an Edge Detection algorithm within MATLAB®, and then deploy to the Raspberry Pi hardware using MATLAB® Support Package for Raspberry Pi™ and MATLAB Coder™.
In this video, we'll take a look at deploying an edge detection algorithm to the Raspberry Pi hardware. We will be performing edge detection on light images captured from the webcam, which is a peripheral device connected to the Raspberry Pi hardware through USB. The image feed along with the highlighted edges will be displayed in MATLAB during the connected I/O workflow since the MATLAB function runs in MATLAB.
This will be followed by hardware deployment, wherein the edge detection algorithm will now execute on the hardware independent of MATLAB. The video feed with the highlighted edges will be displayed on Raspberry Pi. We will be remotely connecting to the Raspberry Pi hardware using VNC Viewer to view the live video output. Gain access to the edge detection example discussed in this video by searching in the documentation doc edge detection Raspberry Pi.
This document explains the step-by-step implementation of the algorithm. I recommend going through the link, since we will not be discussing the algorithm in complete detail. Briefly speaking, the MATLAB function captures images over an interval, applies a filter based on a 3-by-3 Sobel operator, and then performs thresholding to highlight edges within the image.
First, let's clear the workspace. Now let's run this MATLAB function. You can see the live image feed alongside the edge detector images being displayed in MATLAB. This is the connected I/O workflow, wherein the edge detection algorithm executes in MATLAB. imshow function is used to display the image feed.
Next, let's open VNC Viewer. It can be easily downloaded from the web in case you don't have it installed. The device address has already been entered previously. We can find this from the target hardware object or the Raspberry Pi object created in the workspace. The default username and password are Pi and Raspberry, respectively.
Next, we will deploy the MATLAB function for a standalone execution on the hardware, independent of MATLAB. Target object equals target hardware, Raspberry Pi, deploy, target object, edge detection.
Uh-oh, we have a problem here. As we can see here, this function, imshow, is not supported for code generation. And the coder report aptly detected this. Hence, we will need to replace it with its codegen counterpart, as discussed earlier. displayImage is the Raspberry Pi function equivalent of imshow used for deploying images on Raspberry Pi. Let's re-attempt to deploy now. Deploy target object, edge detection.
So now you are seeing a live feed from the webcam, alongside the edge-detected images, which is being displayed here on the Raspberry Pi desktop. This is the hardware deployment workflow, wherein the MATLAB function is being executed on the hardware independent of MATLAB. The executable gets generated in the Build folder set in the hardware configuration object.
This executable can also be launched as a Linux application. The exact location of the executable can be found here under the Build Directory, MATLAB workspace, R2019b, the PWD folder structure. The location under the really specific folder, which in this case is R2019b, mimics that of the actual Working Directory folder structure. Let's launch this executable from the terminal. As you can see here, the edge detection algorithm is running as a Linux application on the Raspberry Pi hardware, independent of MATLAB.
Wow, that was interesting. With this, we come to the end of this video. I hope now you'll feel more confident to get started with designing and deploying your applications to Raspberry Pi hardware from MATLAB. For more interesting videos, please visit www.MathWorks.com/videos. Thank you.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
- América Latina (Español)
- Canada (English)
- United States (English)
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- United Kingdom (English)
- Australia (English)
- India (English)
- New Zealand (English)
- 日本Japanese (日本語)
- 한국Korean (한국어)