Deploy an Edge Detection Algorithm on Raspberry Pi | Raspberry Pi Support from MATLAB, Part 3
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™.
Published: 11 Jun 2020
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.
Featured Product
MATLAB Coder
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- 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)
- Switzerland
- United Kingdom (English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)