Hi Djallal
You can use the OakCamera.create_nn()
method to create a YOLO neural network for object detection. This method returns a NNComponent object. Here is an example:
from depthai_sdk import OakCamera
from depthai_sdk.classes import *
import cv2 as cv
def cb(packet: SpatialBbMappingPacket):
spa=packet.spatials
for s in spa.detections:
print("x=",s.spatialCoordinates.x,"y=",s.spatialCoordinates.y,"z=",s.spatialCoordinates.z)
with OakCamera() as oak:
color = oak.create_camera('color')
nn = oak.create_nn('yolov8n_coco_640x352', color, spatial=True)
oak.visualize([nn.out.spatials], fps=True, callback=cb)
oak.start(blocking=True)
In this example, the create_nn() method is used to create a YOLO neural network for object detection. The visualize() method is then used to visualize the results.
To extract the X and Z coordinates of the detected objects, you can use the callback() method of the OakCamera class. This method allows you to add custom callbacks to the pipeline. In the callback function, you can extract the X and Z (I added the Y as well) coordinates.
Thanks,
Jaka