Hello, i am new to depthai so i dont know much. i am trying to create a code that detects object and show its xyz coordinates, i am using this example: https://docs.luxonis.com/projects/sdk/en/latest/samples/NNComponent/sdk_spatial_detection/

however when i try it with my oak-d pro, the accuracy of the depth is wrong. it says that an object 40 cm. away is 1.3 mts and when i put it closer the depth goes higher. Can someone help me try to fix this or show me different ways of achieving this? thanks!

this is the code:

from depthai_sdk import OakCamera

import depthai as dai

with OakCamera() as oak:

color = oak.create_camera('color')

# List of models that are supported out-of-the-box by the SDK:

# https://docs.luxonis.com/projects/sdk/en/latest/features/ai_models/#sdk-supported-models

nn = oak.create_nn('mobilenet-ssd', color, spatial=True)

nn.config_spatial(

bb_scale_factor=0.5, # Scaling bounding box before averaging the depth in that ROI

lower_threshold=30, # Discard depth points below 30cm

upper_threshold=10000, # Discard depth pints above 10m

# Average depth points before calculating X and Y spatial coordinates:

calc_algo=dai.SpatialLocationCalculatorAlgorithm.AVERAGE

)

oak.visualize(nn.out.main, fps=True)

oak.visualize([nn.out.passthrough, nn.out.spatials])

oak.start(blocking=True)

    Hi anapaulaSb
    Could you post a screenshot? I'm mainly interested in the bounding box used by depth inference. You can see it by visualizing nn.out.spatials.

    If that square is off the object you are trying to get the spatials of, the depth will be wrong since depth from all pixels inside that square is averaged off to give an estimate of object's position.

    Thanks,
    Jaka

    Hi! Sure. here is the screenshot, the bounding box is around me but still, the depth showed is wrong.

      Hi anapaulaSb
      The bounding box averages out all pixels inside, so if the box isn't completely on top of you, there will be error - like in your screenshot (and mine as well).

      Could you try using the spatial location calculator example to check the depth accuracy? Same thing about bbox applies there, but you can move that bbox manually.

      Thanks,
      Jaka

      6 days later

      Hi! Yes, that other code works. How can i change the original code to make the box smaller so its completely on top of me? Or is there another way that might work for getting the correct coordinates?