Hi I'm confused as to when should I pick either one of the methods (get, getAll, tryGet, tryGetAll) receiving data from the DataOutputQueue from Oak-D pro?

  • erik replied to this.

    Hi glitchyordis ,
    Some docs on it here.
    Get vs tryGet - get will block until a new msg is received from the OAK device, while tryGet will return msg if there is one available, otherwise None.
    [try]get vs [try]getAll - the All function will return all msgs available, while without all it will just return one msg (if available). getAll vs tryGetAll has the same difference as get vs tryGet.
    Thanks, Erik

      2 months later

      Hi erik , short follow-up question:

      Are there any benefits (except being more "elegant") or drawbacks of:

      if qNn.has():
          dets=qNn.get().detections

      (e.g. in https://github.com/luxonis/depthai-experiments/blob/master/gen2-full-fov-nn/api/stretching_api.py#L71)

      compared to:

      inDet = qDet.get()
      if inDet is not None:
          detections = inDet.detections

      (e.g. in https://github.com/luxonis/depthai-experiments/blob/master/gen2-yolo/device-decoding/main_api.py#L135)

      Are both approaches basically the same? Or is one better for blocking/non-blocking queues?
      Also if I understood correctly, if inDet is not None: should only make sense for non-blocking .tryGet()?

      Thanks!

        Hi maxsitt

        First approach is more elegant since it doesn't re-set the value of inDet every time. Also, second approach should have tryGet(), otherwise there is no use for follow-up None check.

        You might get an reference error in the first approach if you don't define dets to some empty frame at boot.
        But that is basically it, the approaches should have the exact same functionality.

        Hope this helps,
        Jaka

          Thanks jakaskerl for the info!

          I am now using the following approach:

              while True:
                  if q_frame.has():
                      frame = q_frame.get().getCvFrame()
          
                      if q_nn.has():
                          dets = q_nn.get().detections
          
                          for detection in dets:
                              bbox = frame_norm(frame, (detection.xmin, detection.ymin,
                                                        detection.xmax, detection.ymax))
                              cv2.putText(frame, labels[detection.label], (bbox[0], bbox[3] + 13),
                                          cv2.FONT_HERSHEY_SIMPLEX, 0.4, (255, 255, 255), 1)
                              cv2.putText(frame, f"{round(detection.confidence, 2)}", (bbox[0], bbox[3] + 25),
                                          cv2.FONT_HERSHEY_SIMPLEX, 0.4, (255, 255, 255), 1)
                              cv2.rectangle(frame, (bbox[0], bbox[1]), (bbox[2], bbox[3]), (0, 0, 255), 2)