Object counting on images¶
This example cycles through a folder of images and counts the number of objects (people in our case) in each image. It displays the count number on the top of the image. It cycles through each image every 3 seconds, but you can change that with:
with OakCamera('path/to/folder') as oak:
oak.replay.set_fps(0.5) # For switching cycling through image every 2 seconds
# ...
Note
Visualization in current example is done with blocking behavor. This means that the program will halt at oak.start()
until the window is closed.
This is done to keep the example simple. For more advanced usage, see Blocking behavior section.
Demo¶
Setup¶
Please run the install script to download all required dependencies. Please note that this script must be ran from git context, so you have to download the depthai repository first and then run the script
git clone https://github.com/luxonis/depthai.git
cd depthai/
python3 install_requirements.py
For additional information, please follow our installation guide.
Pipeline¶
Source Code¶
Also available on GitHub.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #!/usr/bin/env python3 import cv2 from depthai_sdk import OakCamera from depthai_sdk.classes import DetectionPacket from depthai_sdk.visualize.configs import TextPosition def callback(packet: DetectionPacket): visualizer = packet.visualizer num = len(packet.img_detections.detections) print('New msgs! Number of people detected:', num) visualizer.add_text(f"Number of people: {num}", position=TextPosition.TOP_MID) visualizer.draw(packet.frame) cv2.imshow(f'frame {packet.name}', packet.frame) with OakCamera(replay='people-images-01') as oak: color = oak.create_camera('color') nn = oak.create_nn('person-detection-retail-0013', color) oak.replay.set_fps(0.5) oak.visualize(nn, callback=callback) # oak.show_graph() oak.start(blocking=True) |