Skip to content

Commit 3574c00

Browse files
authored
Merge pull request #483 from arduino/martab1994-patch-1
Update content.md
2 parents db1b7c1 + cf7c437 commit 3574c00

File tree

1 file changed

+36
-36
lines changed
  • content/hardware/04.pro/shields/portenta-vision-shield/tutorials/blob-detection

1 file changed

+36
-36
lines changed

content/hardware/04.pro/shields/portenta-vision-shield/tutorials/blob-detection/content.md

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Blob Detection with Portenta and OpenMV
33
coverImage: assets/por_openmv_bt_cover.svg
44
difficulty: intermediate
55
tags: [OpenMV, Blob Detection, Machine Vision, Machine Learning]
6-
description: This tutorial will show you how to use the vision carrier board for Portenta to detect the presence and the position of objects in a camera image.
6+
description: This tutorial will show you how to use the Portenta Vision Shield to detect the presence and the position of objects in a camera image.
77
author: Sebastian Romero
88
hardware:
99
- hardware/04.pro/boards/portenta-h7
@@ -13,12 +13,12 @@ software:
1313
---
1414

1515
## Overview
16-
In this tutorial you will use the vision carrier board for Portenta to detect the presence and the position of objects in a camera image. For that you will use a technique that is often referred to as blob detection. For this task you will write a MicroPython script and run it on the Portenta with the help of the OpenMV IDE.
16+
In this tutorial you will use the Portenta Vision Shield to detect the presence and the position of objects in a camera image. To achieve this goal, you will use a technique that is often referred to as blob detection. You will write a MicroPython script and run it on the Portenta H7 with the help of the OpenMV IDE.
1717

1818
## Goals
1919

2020
- How to use the OpenMV IDE to run MicroPython on Portenta
21-
- How to use the built-in blob detection algorithm of OpenMV
21+
- How to use the built-in blob detection OpenMV algorithm
2222
- How to use MicroPython to toggle the built-in LEDs
2323

2424
### Required Hardware and Software
@@ -31,9 +31,9 @@ In this tutorial you will use the vision carrier board for Portenta to detect th
3131
- OpenMV IDE 2.6.4+
3232

3333
## Portenta and the OpenMV IDE
34-
The OpenMV IDE was built for Machine Vision applications. It is meant to provide an Arduino like experience for simple computer vision tasks using a camera sensor. OpenMV comes with its own firmware that is built on MicroPython. Among other hardware it supports the Portenta board. A statement from the creators of OpenMV on why they built it:
34+
The OpenMV IDE is built for Machine Vision applications. It is meant to provide an Arduino like experience for simple computer vision tasks using a camera sensor. OpenMV comes with its own firmware that is built on MicroPython. Among other hardware, it supports the Portenta board. A statement from the creators of OpenMV on the reason why they built it:
3535

36-
>Currently, doing anything serious involving computer vision requires a computer running an operating system running may layers of software and requiring much setup before you can get computer vision code working. This is all well and fine if you need to do many other things than just processing images, like connecting to the internet, running many different applications concurrently, etc.
36+
>Currently, doing anything serious involving computer vision requires a computer running an operating system running many layers of software and requiring much setup before you can get computer vision code working. This is all well and fine if you need to do many other things than just processing images, like connecting to the internet, running many different applications concurrently, etc.
3737
>
3838
>But, what if, I just want to make an LED turn on if a red object appears in front of a white wall. Why do a need to build up a complex system for that? Or, what if I just want to turn on an LED when a face is in view?
3939
@@ -62,36 +62,36 @@ Follow the instructions of the installer.
6262

6363
Connect the Portenta to your computer via the USB-C cable if you haven't done so yet. Make sure you first update the bootloader to the latest version using the **STM32H747_updateBootloader** sketch in the examples menu in the Arduino IDE.
6464

65-
Instructions on how to update the bootloader can be found in the [Updating the Portenta Bootloader](https://www.arduino.cc/pro/tutorials/portenta-h7/updating-the-bootloader) tutorial.
65+
Instructions on how to update the bootloader can be found in the [Updating the Portenta Bootloader](https://docs.arduino.cc/tutorials/portenta-h7/updating-the-bootloader) tutorial.
6666

67-
***In bootloader versions 17 and older there was a bug that could put the Portenta in a boot loop when the transmission aborted while flashing a large firmware file. This was fixed in the bootloader version 18. We strongly advise to update the bootloader before you proceed with the next step of this tutorial!***
67+
***In bootloader versions 17 and older, there was a bug that could put the Portenta in a boot loop when the transmission aborted while flashing a large firmware file. This was fixed in the bootloader version 18. We strongly advise to update the bootloader before you proceed with the next step of this tutorial!***
6868

69-
After updating the bootloader put the Portenta in bootloader mode by double pressing the reset button on the board. The built-in green LED will start fading in and out. Now open the OpenMV IDE.
69+
After updating the bootloader, put the Portenta in bootloader mode by double pressing the reset button on the board. The built-in green LED will start fading in and out. Now open the OpenMV IDE.
7070

7171
![The OpenMV IDE after starting it](assets/por_openmv_open_ide.png)
7272

7373
Click on the "connect" symbol at the bottom of the left toolbar.
7474

7575
![Click the connect button to attach the Portenta to the OpenMV IDE](assets/por_openmv_click_connect.png)
7676

77-
A pop-up will ask you how you would like to proceed "DFU bootloader(s) found. What would you like to do?". Select "Reset Firmware to Release Version". This will install the latest OpenMV firmware on the Portenta. If it asks you whether it should erase the internal file system you can click "No".
77+
A pop-up will ask you how you would like to proceed: "DFU bootloader(s) found. What would you like to do?". Select "Reset Firmware to Release Version". This will install the latest OpenMV firmware on the Portenta. If it asks you whether it should erase the internal file system you can click "No".
7878

7979
![Install the latest version of the OpenMV firmware](assets/por_openmv_reset_firmware.png)
8080

81-
Portenta's green LED will start flashing while the OpenMV firmware is being uploaded to the board. A terminal window will open which shows you the upload progress. Wait until the green LED stops flashing and fading. You will see a message saying "DFU firmware update complete!" when the process is done.
81+
Portenta's green LED will start flashing while the OpenMV firmware is being uploaded on the board. A terminal window will open showing you the upload progress. Wait until the green LED stops flashing and fading. You will see a message saying "DFU firmware update complete!" when the process is done.
8282

83-
***Installing the OpenMV firmware will overwrite any existing sketches in the internal Flash of Portenta. As a result the M7 port won't be exposed in the Arduino IDE anymore. To re-flash the M7 with an Arduino firmware you need to put the board into bootloader mode. To do so double press the reset button on the Portenta H7 board. The built-in green LED will start fading in and out. In bootloader mode you will see the Portenta M7 port again in the Arduino IDE.***
83+
***Installing the OpenMV firmware will overwrite any existing sketches in the internal Flash of Portenta. As a result the M7 port will not be exposed in the Arduino IDE anymore. To re-flash the M7 with an Arduino firmware, you need to put the board into bootloader mode. To do so, double press the reset button on the Portenta H7 board. The built-in green LED will start fading in and out. In bootloader mode you will see the Portenta M7 port again in the Arduino IDE.***
8484

85-
The Portenta will start flashing its blue LED when it's ready to be connected. After confirming the completion dialog the Portenta should already be connected to the OpenMV IDE, otherwise click the "connect" button once again.
85+
The Portenta will start flashing its blue LED when it is ready to be connected. After confirming the completion dialog, the Portenta should already be connected to the OpenMV IDE, otherwise click the "connect" button once again.
8686

8787
![When the Portenta is successfully connected to the OpenMV IDE a green play button appears in the lower left](assets/por_openmv_board_connected.png)
8888

8989

9090
## Blob Detection
9191

92-
In this section you will learn how to use the built-in blob detection algorithm to detect the location of objects in an image. That algorithm allows to detect areas in a digital image that differ in properties such as brightness or color compared to surrounding areas. These areas are called blobs.
92+
In this section you will learn how to use the built-in blob detection algorithm to detect the location of objects in an image. That algorithm allows to detect areas in a digital image that differ in properties, such as brightness or color compared to surrounding areas. These areas are called blobs.
9393

94-
To do so you need to feed an image from the camera to the algorithm. It will then analyze it and output the coordinates of the found blobs. You will visualize these coordinates directly on the image and indicate whether a blob was found by using the red and green LED.
94+
To do so, you need to feed an image from the camera to the algorithm. It will then analyze it and output the coordinates of the found blobs. You will visualize these coordinates directly on the image and indicate whether a blob was found by using the red and green LED.
9595

9696
### 1. Prepare the Script
9797

@@ -104,11 +104,11 @@ import image # Import module containing machine vision algorithms
104104
import time # Import module for tracking elapsed time
105105
```
106106

107-
A module in Python is a confined bundle of functionality. By importing it into the script it gets made available.
107+
A module in Python is a confined bundle of functionality. By importing it into the script, it gets made available.
108108

109109
### 2. Preparing the Sensor
110110

111-
In order to take a snapshot with the camera it has to be configured in the script.
111+
In order to take a snapshot with the camera, it has to be configured in the script.
112112

113113
```python
114114
sensor.reset() # Resets the sensor
@@ -117,24 +117,24 @@ sensor.set_framesize(sensor.QVGA) # Sets the resolution to 320x240 px
117117
sensor.skip_frames(time = 2000) # Skip some frames to let the image stabilize
118118
```
119119

120-
The most relevant functions in this snipped are `set_pixformat` and `set_framesize`. The camera that comes with the Portenta Vision Carrier only supports grey scale images. Therefore we need to set it via the `sensor.GRAYSCALE` parameter.
120+
The most relevant functions in this snipped are `set_pixformat` and `set_framesize`. The camera that comes with the Portenta Vision Shield only supports grey scale images. Therefore, you need to set it via the `sensor.GRAYSCALE` parameter.
121121

122-
The resolution of the camera needs to be set to a supported format both by the sensor and the algorithm. Algorithms which use a neural network are usually trained on a specific image resolution. This makes them sensitive to the provided image snapshot resolution. The vision carrier supports `QVGA` which you will use in this tutorial.
122+
The resolution of the camera needs to be set to a supported format both by the sensor and the algorithm. Algorithms which use a neural network are usually trained on a specific image resolution, to make them sensitive to the provided image snapshot resolution. The Portenta Vision Shield supports `QVGA`, which you will use in this tutorial.
123123

124124
### 3. Detecting Blobs
125125

126-
In order to feed the blob detection algorithm with an image you have to take a snapshot from the camera or load the image from memory (e.g. SD card or internal Flash). In this case you will take a snapshot using the `snapshot()` function. The resulting image needs then to be fed to the algorithm using the `find_blobs` function. You will notice that a list of tuples gets passed to the algorithm. In this list you can specify the grey scale values (brightness) that are mostly contained in the object that you would like to track. If you were for example to detect white objects on a black background the resulting range of brightness would be very narrow (e.g. from 200 - 255). Remember that 255 denotes the maximum brightness / white and 0 corresponds to the minimum brightness / black. If we're interested in a wider range of grey scale values to detect various objects we can set the threshold range for example to (100, 255).
126+
In order to feed the blob detection algorithm with an image, you have to take a snapshot from the camera or load the image from memory (e.g. SD card or internal Flash). In this case, you will take a snapshot using the `snapshot()` function. The resulting image needs then to be fed to the algorithm using the `find_blobs` function. You will notice that a list of tuples gets passed to the algorithm. In this list, you can specify the grey scale values (brightness) that are mostly contained in the object that you would like to track. For instance, if you wanted to detect white objects on a black background, the resulting range of brightness would be very narrow (e.g. from 200 - 255). Remember that 255 denotes the maximum brightness / white and 0 corresponds to the minimum brightness / black. If you are interested in a wider range of grey scale values to detect various objects, you can set the threshold range for example to (100, 255).
127127

128128
```python
129-
thresholds = (100, 255) # Define the min/max gray scale values we're looking for
130-
img = sensor.snapshot() # Takes a snapshot and saves it in memory
129+
thresholds = (100, 255) # Define the min/max gray scale values you are looking for
130+
img = sensor.snapshot() # Takes a snapshot and saves it in the memory
131131

132132
# Find blobs with a minimal area of 15x15 = 200 px
133-
# Overlapping blobs won't be merged
133+
# Overlapping blobs will not be merged
134134
blobs = img.find_blobs([thresholds], area_threshold=225, merge=False)
135135
```
136136

137-
Once the blobs are detected you may be interested to see where in the images they were found. This can be done by drawing directly on the camera image.
137+
Once the blobs are detected, you may be interested to see where they have been found in the images. This can be done by drawing directly on the camera image.
138138

139139
```python
140140
# Draw blobs
@@ -152,14 +152,14 @@ The result of that will be visible in the Frame Buffer preview panel on the righ
152152
What if you want some visual feedback from the blob detection without any computer connected to your Portenta? You could use for example the built-in LEDs to indicate whether or not a blob was found in the camera image. Let's initialize the red and the green LEDs with the following code:
153153

154154
```python
155-
ledRed = pyb.LED(1) # Initiates the red led
156-
ledGreen = pyb.LED(2) # Initiates the green led
155+
ledRed = pyb.LED(1) # Initializes the red LED
156+
ledGreen = pyb.LED(2) # Initializes the green LED
157157
```
158158

159159
And then add the logic that will turn on the appropriate LED if a blob is present. This part of the code will be added after the "Draw Blobs" logic.
160160

161161
```python
162-
# Turn on green LED if a blob was found
162+
# Turn the green LED on if a blob was found
163163
if len(blobs) > 0:
164164
ledGreen.on()
165165
ledRed.off()
@@ -169,7 +169,7 @@ else:
169169
ledRed.on()
170170
```
171171

172-
In this example the green LED will light up when there is at least one blob found in the image. The red LED will light up if no blob could be found.
172+
In this example, the green LED will light up when there is at least one blob found in the image. The red LED will light up if no blob could be found.
173173

174174
### 5. Uploading the Script
175175
Let's program the Portenta with the complete script and test if the algorithm works. Copy the following script and paste it into the new script file that you created.
@@ -186,8 +186,8 @@ sensor.set_framesize(sensor.QVGA) # Sets the resolution to 320x240 px
186186
sensor.skip_frames(time = 2000) # Skip some frames to let the image stabilize
187187

188188
thresholds = (100, 255) # Define the min/max gray scale values we're looking for
189-
ledRed = pyb.LED(1) # Initiates the red led
190-
ledGreen = pyb.LED(2) # Initiates the green led
189+
ledRed = pyb.LED(1) # Initializes the red LED
190+
ledGreen = pyb.LED(2) # Initializes the green LED
191191

192192
clock = time.clock() # Instantiates a clock object
193193

@@ -206,7 +206,7 @@ while(True):
206206
# Draw a cross in the middle of the blob
207207
img.draw_cross(blob.cx(), blob.cy(), color=255)
208208

209-
# Turn on green LED if a blob was found
209+
# Turn the green LED on if a blob was found
210210
if len(blobs) > 0:
211211
ledGreen.on()
212212
ledRed.off()
@@ -223,25 +223,25 @@ while(True):
223223

224224
Click on the "Play" button at the bottom of the left toolbar. Place some objects on your desk and check if the Portenta can detect them.
225225

226-
***The MicroPython script doesn't get compiled and linked into an actual firmware. Instead it gets copied to the internal Flash of the Portenta where it gets compiled and executed on the fly.***
226+
***The MicroPython script does not get compiled and linked into an actual firmware. Instead it gets copied to the internal Flash of the Portenta where it gets compiled and executed on the fly.***
227227

228228
![An example of a blob detection running in the OpenMV IDE](assets/por_openmv_blob_detected.png)
229229

230230
## Conclusion
231231

232-
In this tutorial you learned how to use the OpenMV IDE to develop MicroPython scripts that then run on the Portenta board. You also learned how to configure the camera of the Vision Carrier board to be used for machine vision applications in OpenMV. Last but not least you learned how to interact with the built-in LEDs in MicroPython on the OpenMV firmware.
232+
In this tutorial you learned how to use the OpenMV IDE to develop MicroPython scripts that can run on the Portenta board. You also learned how to configure the camera of the Portenta Vision Shield for machine vision applications in OpenMV. Last but not least, you learned how to interact with the built-in LEDs in MicroPython on the OpenMV firmware.
233233

234234
### Next Steps
235235

236-
- Familiarize yourself with the OpenMV IDE. There are many other features that didn't get mentioned in this tutorial (e.g. the Serial Terminal).
236+
- Familiarize yourself with the OpenMV IDE. There are many other features that have not been mentioned in this tutorial (e.g. the Serial Terminal).
237237
- Try out other machine vision examples that come with the OpenMV IDE (e.g. Face Detection). You can find them in the "Examples" menu.
238238

239239
## Troubleshooting
240240

241241
### OpenMV Firmware Flashing Issues
242242

243-
- If the upload of the OpenMV firmware fails during the download, put the board back in boot loader mode and try again. Give it a few tries until the firmware gets successfully uploaded.
243+
- If the upload of the OpenMV firmware fails during the download, put the board back in bootloader mode and try again. Give it a few trials until the firmware gets successfully uploaded.
244244
- If the upload of the OpenMV firmware fails without even starting, try uploading the latest firmware using the "Load Specific Firmware File" option. You can find the latest firmware on the [OpenMV Github repository](https://github.com/openmv/openmv/releases). Look for a file called **firmware.bin** in the PORTENTA folder.
245-
- If you experience issues putting the board in bootloader mode, make sure you first update the bootloader to the latest version using the **STM32H747_updateBootloader** sketch from the examples menu in the Arduino IDE.
246-
- If the camera cannot get recognized by the OpenMV IDE or if you see a "No OpenMV Cams found!" message, press the reset button of Portenta once and wait until you see the blue LED flashing. Then try again connecting to the board.
245+
- If you experience issues putting the board into bootloader mode, make sure you first updated the bootloader to the latest version using the **STM32H747_updateBootloader** sketch from the examples menu in the Arduino IDE.
246+
- If the camera cannot get recognized by the OpenMV IDE or if you see a "No OpenMV Cams found!" message, press the reset button on the Portenta once and wait until you see the blue LED flashing. Then try again connecting to the board.
247247
- If you see a "OSError: Reset Failed" message, reset the board by pressing the reset button. Wait until you see the blue LED flashing, connect the board to the OpenMV IDE and try running the script again.

0 commit comments

Comments
 (0)