How to calculate the coordinate by depth, resolution and perspective angle

Typically: "How do I... ", "How can I... " questions
Post Reply
Zhuang
Posts: 31
Joined: 02 Aug 2017, 14:43

How to calculate the coordinate by depth, resolution and perspective angle

Post by Zhuang »

Hi, coppelia
Recently, I try to use depth sensor to calculate a world position of a pixel. I see the sensor is different from real camera. I am not sure if the method that is used to calculate a position by perspective angel and depth is right.

Code: Select all

    camXHalfAngle = camXAngleInDegrees * 0.5 * math.pi/180
    camYHalfAngle = math.atan(math.tan(camXAngleInDegrees*0.5* camYResolution/camXResolution))*math.pi/180   
    nearClippingPlane = 0.01
    depthAmplitude = 3.5
    xAngle = ((320-u+0.5)/320)*camXHalfAngle
    yAngle = ((240-v+0.5)/240)*camYHalfAngle    
    depthValue = image_depth[v-1][u-1]  # u and v are the coordinate of the pixel. because the depth is turned so [v-1]#[u-1]  
    zCoord = nearClippingPlane+depthAmplitude * depthValue
    xCoord = math.tan(xAngle) * zCoord
    yCoord = math.tan(yAngle) * zCoord
    pixels_coordinare_kinetic = np.mat([[xCoord],[yCoord],[zCoord],[1]], np.float)
cheers,
zhuang

coppelia
Site Admin
Posts: 10336
Joined: 14 Dec 2012, 00:25

Re: How to calculate the coordinate by depth, resolution and perspective angle

Post by coppelia »

Hello Zhuang,

did you have a look at the model Models/components/sensors/Blob to 3D position.ttm available since release V3.5.0?

Cheers

Post Reply