Skip to content

Commit 4b368b9

Browse files
committed
NIcla Vision code finished
1 parent 86d3e6f commit 4b368b9

File tree

1 file changed

+37
-1
lines changed
  • content/hardware/06.nicla/boards/nicla-sense-env/tutorials/03.elevator-monitoring-application-note

1 file changed

+37
-1
lines changed

content/hardware/06.nicla/boards/nicla-sense-env/tutorials/03.elevator-monitoring-application-note/content.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,43 @@ The `getPeopleCount()` function creates an I2C request asking for the people det
260260

261261
### Nicla Vision Code
262262

263-
The people counting feature of the project is achieved by the Nicla Vision running a FOMO face detection model. The
263+
The people counting feature of the project is achieved by the Nicla Vision running a FOMO face detection model.
264+
265+
For this feature we are using the [OpenMV IDE](https://openmv.io/pages/download) for running MicroPython sketches that you can download from [here](https://openmv.io/pages/download).
266+
267+
Let's explain a bit how the code works starting from the main loop of the sketch:
268+
269+
```python
270+
if __name__ == "__main__":
271+
272+
clock = time.clock()
273+
while True:
274+
clock.tick()
275+
276+
img = sensor.snapshot()
277+
faces = analyze_image(img)
278+
279+
green_led.on() if faces > 0 else green_led.off() # Turn on green LED when face is detected
280+
281+
if(faces > 0):
282+
print("Faces detected:", faces)
283+
buf[0] = faces
284+
i2c.send(buf)
285+
286+
now = ticks_ms()
287+
```
288+
289+
In simple words, we are on an infinite loop taking pictures with the `sensor.snapshot()` function which are then used as inputs for the face detection model using the `analyze_image()` function.
290+
291+
If faces are detected, the onboard green LED will light up and the count will be sent by I2C to the Portenta H7.
292+
293+
In the face detection process, some auxiliary functions are used to filter unwanted results including false positives. A brief explanation of these functions are listed below:
294+
295+
- `calculate_distance()`: it returns the distance between two rectangles bounding a possible face to avoid duplicates.
296+
- `merge_rectangles()` and `merge_close_rectangles()`: if two or more bounding rectangles are too close they will be merged into one.
297+
- `fomo_post_process()`: it returns the list of bounding boxes to be analyzed by the previously explained functions.
298+
299+
***You can download the complete example code for the Nicla Vision [here](assets/People_Count_Nicla_Vision.zip)***
264300

265301
### Arduino Cloud Dashboard
266302

0 commit comments

Comments
 (0)