You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/hardware/04.pro/shields/portenta-vision-shield/tutorials/getting-started-camera/content.md
+15-15Lines changed: 15 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,9 +15,9 @@ This tutorial shows you how to capture frames from the Arduino Portenta Vision S
15
15
16
16
## Goals
17
17
18
-
- Capturing the frames from the camera.
19
-
- Sending the frames as a byte stream through a Serial connection.
20
-
- Visualising the frames in Processing.
18
+
- Capturing the frames from the camera
19
+
- Sending the frames as a byte stream through a Serial connection
20
+
- Visualising the frames in Processing
21
21
22
22
### Required Hardware and Software
23
23
@@ -28,10 +28,10 @@ This tutorial shows you how to capture frames from the Arduino Portenta Vision S
28
28
- Processing 3.5.4+
29
29
30
30
## Instructions
31
-
Accessing the Vision Shield's camera data is done with the help of both Arduino and the Processing IDE. The Arduino sketch handles the capture of image data by the on-board camera while the java applet created with Processing helps to visualize this data with the help of a serial connection. The following steps will run you through how to capture, package the data through the serial port and visualize the output in Processing.
31
+
Accessing the Vision Shield's camera data is done with the help of both Arduino and the Processing IDE. The Arduino sketch handles the capture of image data by the on-board camera, while the java applet created with Processing helps to visualize this data with the help of a serial connection. The following steps will run you through how to capture, package the data through the serial port and visualize the output in Processing.
32
32
33
33
### 1. The Basic Setup
34
-
Connect the Vision Shield to your Portenta H7 as shown in the figure. The top and bottom high density connecters are connected to the corresponding ones on the underside of the H7 board. Plug in the H7 to your computer using the USB C cable.
34
+
Connect the Portenta Vision Shield to your Portenta H7 as shown in the figure. The top and bottom high density connecters are connected to the corresponding ones on the underside of the H7 board. Plug in the H7 to your computer using the USB C cable.
35
35
36
36

37
37
@@ -71,7 +71,7 @@ void setup() {
71
71
}
72
72
```
73
73
74
-
In the loop we need to capture each Frame and send it over a serial connection to the Processing sketch that will display the frames. We will use the `grab(uint8_t *buffer, uint32_t timeout=5000);` function to fetch the frame from the frame buffer and save it into our custom data buffer.
74
+
In the loop you need to capture each Frame and send it over a serial connection to the Processing sketch that will display the frames. You will use the `grab(uint8_t *buffer, uint32_t timeout=5000);` function to fetch the frame from the frame buffer and save it into your custom data buffer.
75
75
76
76
```cpp
77
77
voidloop() {
@@ -102,7 +102,7 @@ Open a new processing sketch file and name it `CameraCapture.pde`.
102
102
103
103

104
104
105
-
Let's start by importing the libraries and initializing the variables you will need to process the captured data. To process the data sent by the Vision Shield you will need to import the following libraries:
105
+
Let's start by importing the libraries and initializing the variables you will need to process. To process the data sent by the Vision Shield, you will need to import the following libraries:
106
106
107
107
-`processing.serial.*`: a [Serial Library](https://processing.org/reference/libraries/serial/index.html) that is used to read and write data to external devices over the serial line.
108
108
-`java.nio.ByteBuffer`: a java class that provides access to operations on byte buffers
@@ -112,7 +112,7 @@ import processing.serial.*;
112
112
importjava.nio.ByteBuffer;
113
113
```
114
114
115
-
Next we initialize the following variables to process the received pixels from the serial port. We set the dimensions, pixel count, and bytes required per frame.
115
+
Next, you can initialize the following variables to process the received pixels from the serial port. You can set the dimensions, pixel count and bytes required per frame.
116
116
117
117
```java
118
118
// must match resolution used in the sketch
@@ -123,7 +123,7 @@ final int cameraPixelCount = cameraWidth * cameraHeight;
To receive the frames you will need a Serial port, a PImage object and an array to store the pixel values of the frame. Add the following variables to the code.
126
+
To receive the frames, you will need a Serial port, a PImage object and an array to store the pixel values of the frame. Add the following variables to the code.
127
127
128
128
```java
129
129
Serial myPort;
@@ -134,7 +134,7 @@ int lastUpdate = 0;
134
134
boolean shouldRedraw =false;
135
135
```
136
136
137
-
Here we will establish a connection to the serial port and prepare the buffer to store the frame pixels. Additionally we send a byte to the Arduino sketch from Processing to let it know that it's ready to receive data.
137
+
Here, you will establish a connection to the serial port and prepare the buffer to store the frame pixels. Additionally, you can send a byte to the Arduino sketch from Processing to let it know that it is ready to receive data.
138
138
139
139
```java
140
140
void setup() {
@@ -156,7 +156,7 @@ void setup() {
156
156
}
157
157
```
158
158
159
-
The draw function checks if the connection is still alive and if there is any new data that can be drawn as an image. In that case the original image gets copied into a new image object so that it can be scaled up.
159
+
The draw function checks if the connection is still alive and if there is any new data that can be drawn as an image. In that case, the original image gets copied into a new image object so that it can be scaled up.
The first thing we do inside this method is to update the timestamp for when the last data was read. This is to detect and recover from a connection timeout. Then read the bytes from the `frameBuffer` array which you can do with the help of the [`readBytes()`](https://processing.org/reference/libraries/serial/Serial_readBytes_.html) method that returns the number of bytes read.
213
+
The first thing you can do inside this method is to update the timestamp when the last data was read. This is to detect and recover from a connection timeout. Then read the bytes from the `frameBuffer` array which you can do with the help of the [`readBytes()`](https://processing.org/reference/libraries/serial/Serial_readBytes_.html) method that returns the number of bytes read.
214
214
215
215
```java
216
216
lastUpdate = millis();
@@ -240,7 +240,7 @@ while (bb.hasRemaining()) {
240
240
}
241
241
```
242
242
243
-
Once all the pixels have been updated, you need to tell the sketch to redraw the image. Additionally we send an acknowledgement back to the arduino sketch to ask it to send the pixels for the next frame. We update the image with `updatePixels()` and write `1` to the serial port for the acknowledgement.
243
+
Once all the pixels have been updated, you need to tell the sketch to redraw the image. Additionally, you can send an acknowledgement back to the arduino sketch to ask it to send the pixels for the next frame. You can update the image with `updatePixels()` and write `1` to the serial port for the acknowledgement.
244
244
245
245
```cpp
246
246
myImage.updatePixels();
@@ -255,13 +255,13 @@ myPort.write(1);
255
255
256
256
### 5. Upload the Sketch
257
257
258
-
Select the right serial port on your IDE and upload the Arduino sketch to your H7. After a successful upload, run the `CameraViewer.pde` sketch in Processing. You should be able to see the rendered camera output on the Processing canvas.
258
+
Select the right serial port on your IDE and upload the Arduino sketch to your Portenta H7. After a successful upload, run the `CameraViewer.pde` sketch in Processing. You should be able to see the rendered camera output on the Processing canvas.
259
259
260
260

261
261
262
262
## Conclusion
263
263
264
-
In this tutorial you learnt how to capture the frames from your Vision Shield's Camera and to visualize the frames through Processing. This knowledge can be useful for you to build and experiment simple computer vision applications for both outdoor and indoor environments.
264
+
In this tutorial you learnt how to capture the frames from your Portenta Vision Shield's Camera and to visualize the frames through Processing. This knowledge can be useful for you to build and experiment simple computer vision applications for both outdoor and indoor environments.
0 commit comments