Packets¶
Packets are synchronized collections of one or more DepthAI messages. They are used internally for visualization and also forwarded to the callback function if the user:
Specified a callback for visualizing of an output via
OakCamera.visualize(..., callback=fn)
.Used callback output via
OakCamera.callback(..., callback=fn, enable_visualizer=True)
.
API Usage¶
OakCamera.visualize()
: In the example below SDK won’t show the frame to the user, but instead it will send the packet to the callback function. SDK will draw detections (bounding boxes, labels) on thepacket.frame
.OakCamera.callback()
: This will also sendDetectionPacket
to the callback function, the only difference is that the SDK won’t draw on the frame, so you can draw detections on the frame yourself.
Note
If you specify callback function in OakCamera.visualize()
, you need to trigger drawing of detections yourself via Visualizer.draw()
method.
import cv2
from depthai_sdk import OakCamera
from depthai_sdk.classes import DetectionPacket
with OakCamera() as oak:
color = oak.create_camera('color')
nn = oak.create_nn('mobilenet-ssd', color)
# Callback
def cb(packet: DetectionPacket):
print(packet.img_detections)
cv2.imshow(packet.name, packet.frame)
# 1. Callback after visualization:
oak.visualize(nn.out.main, fps=True, callback=cb)
# 2. Callback:
oak.callback(nn.out.main, callback=cb, enable_visualizer=True)
oak.start(blocking=True)