I'm working with the DepthAI experiment called gen2-calc-spatials-on-host, which provides code to extract the relative spatial position in meters of certain pixeles using the camera as reference (X, Y and Z).

I need to save the depth matrix to use it later off-streaming. How can I save the array contained in the 'depthai.ImgFrame' object and simulate the camera parameters without connecting to it?? I will pass the "x" and "y" on the newer script to this code line (59 in main.py ):

spatials, centroid = hostSpatials.calc_spatials(depthai.ImgFrame, (x,y))

I other words, I want to be able to get the "z" (depth) value for any image region off-stream.

Thanks for your help!!

  • erik replied to this.

    erik I've finally found a way to save the camera parameters. I'm saving all I need inside a .json file with the following structure:

    mapDepthData = {

    'FOV': device.readCalibration().getFov(dai.CameraBoardSocket(depthData.getInstanceNum())),

    'MaxDisparity':stereo.initialConfig.getMaxDisparity(),

    'disp': dispQ.get().getFrame().tolist(),

    'depthDataArray': depthData.getFrame().tolist(),

    'calibrations': device.readCalibration().eepromToJson()}

    Then, I just changed some elements inside the HostSpatialsCalc class in calc.py to use directly the elements in the json (in the original class, it takes device-related variables, but they cannot be encoded into json).

    The class CalibrationHandler contains a static method .fromJson(calibrations) to re-generate the object from the dictionary saved in the json file.

    Thanks for your help!!