• DepthAI-v2
  • Yolo Spatial detection FPS drop when not visualising output

Hi. I'm having an issue with depthai_sdk. I have task to detect objects using yolo, but what I need is only detections and a frame once per 1s. I use code below to print outputs of the yolo. with code as it is, I achieve 15FPS, but with commenting the 14,15 line, the FPS drops to 2 and no detection is provided. Als setting blocking = False on line 25 leads to failure.

Thank you, Jan

  1. def callback(packet: DetectionPacket):
  2.     visualizer = packet.visualizer
  3.     try:
  4.         print()
  5.         for inx in range(len(packet.detections)):
  6.             print('Detected: ' + packet.detections[inx].label + ' at' + str(packet.detections[inx].centroid()))
  7.             print('Spatial: x ' + str(visualizer.objects[0].detections[0].spatialCoordinates.x) + 'mm ,y '
  8.                 + str(visualizer.objects[0].detections[inx].spatialCoordinates.y) + 'mm ,z '
  9.                 + str(visualizer.objects[0].detections[inx].spatialCoordinates.z) + 'mm.')
  10.             print('Confidence: ' + str(visualizer.objects[0].detections[inx].confidence))
  11.         print(visualizer.objects[1].text )
  12.     except:
  13.         pass
  14.     frame = visualizer.draw(packet.frame)
  15.     cv2.imshow('Visualizer', frame)
  16.    
  17. with OakCamera(args=args) as oak:
  18.     color = oak.create_camera('color')
  19.     color.config_color_camera(isp_scale=(1,2))
  20.     nn = oak.create_nn(args['config'], color, nn_type='yolo', spatial=True)
  21.     for inx in range(len(nn._labels)):
  22.         nn._labels[inx] = true_labels[inx]
  23.        
  24.     oak.visualize(nn.out.passthrough, fps=True, callback=callback)
  25.     oak.start(blocking=True)

    Hi JanKanka

    1. What happens if instead of your callback, you use the built it visualizer callback (omitting the callback flag inside the oak.visualize())?

    2. What kind of failure are we talking about? Does the script error out or does it freeze. Usually just setting the oak.start() to non blocking will immediately close the device after building the pipeline. You would have to make a while loop, calling oak.poll() in order for the device to function properly.

    Thanks,
    Jaka