Hi 2ant
Calculate x and y (in pixels) relative to the center of the image.
midW = int(depthFrame.shape[1] / 2) # middle of the depth img width
midH = int(depthFrame.shape[0] / 2) # middle of the depth img height
x_offset= x - midW # x in pixels
y_offset = y - midH # y in pixels
This will give you the angle (in radians) between the point and the center of the image.
def calc_angle(frame, offset, HFOV):
return math.atan(math.tan(HFOV / 2.0) * offset / (frame.shape[1] / 2.0))
Use the function to calculate angles.
# Required information for calculating spatial coordinates on the host
HFOV = np.deg2rad(self.calibData.getFov(dai.CameraBoardSocket(depthData.getInstanceNum())))
angle_x = self._calc_angle(depthFrame, x_offset, HFOV) # angle in x direction
angle_y = self._calc_angle(depthFrame, y_offset, HFOV) # angle in y direction
Then acquire the x, y and z component of a point on the image.
z = depth,
x = depth * math.tan(angle_x),
y = -depth * math.tan(angle_y)
Hope this helps,
Jaka