JanCuhel Hi Jan, thanks a lot for your help. However, here is my script:
from depthai_sdk import OakCamera, ArgsParser
import argparse
latest_z_value = None # Store the most recent Z distance
def process_detections(packet):
global latest_z_value
if packet is None or not hasattr(packet, 'detections'):
print("No detections found.")
return
for det in packet.detections:
if hasattr(det, 'img_detection') and hasattr(det.img_detection, 'spatialCoordinates'):
latest_z_value = det.img_detection.spatialCoordinates.z / 1000
print(f"Drone detected {latest_z_value:.2f}m away.")
else:
print("No spatial data available.")
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-conf", "--config", help="Trained YOLO json config path", default='models/v1/16shaves/droneDetection_v1.json', type=str)
args = ArgsParser.parseArgs(parser)
with OakCamera(args=args) as oak:
color = oak.create_camera('color')
nn = oak.create_nn(args['config'], color, nn_type='yolo', spatial=True)
nn.config_nn(resize_mode='stretch')
oak.callback(nn, process_detections)
oak.visualize(nn, fps=True)
oak.start(blocking=True)
if __name__ == "__main__":
main()
As you can see, I am taking in the .json file and not the .blob. This is because the tools.luxonis.com tool would output a .bin, .json, .xml, .blob, and a .onnx file. Is there any chance that you can help with generating those.
Thanks!