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/06.nicla/boards/nicla-sense-env/tutorials/03.elevator-monitoring-application-note/content.md
+37-1Lines changed: 37 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -260,7 +260,43 @@ The `getPeopleCount()` function creates an I2C request asking for the people det
260
260
261
261
### Nicla Vision Code
262
262
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
+
whileTrue:
274
+
clock.tick()
275
+
276
+
img = sensor.snapshot()
277
+
faces = analyze_image(img)
278
+
279
+
green_led.on() if faces >0else 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)***
0 commit comments