depthImg from getCameraImage() is full of 'nan'

Question:

This is the code I’m using the generate the image:

pos_vec = [.15, .15, .15]
up_vec = camera_upvec(pos_vec)

viewMat = p.computeViewMatrix(
    cameraEyePosition=pos_vec,
    cameraTargetPosition=[0, 0, 0],
    cameraUpVector=up_vec)

projMat = p.computeProjectionMatrixFOV(
    fov=70.25,
    aspect=1.0,
    nearVal=0,
    farVal=3.1)

width, height, rgbImg, depthImg, segImg = p.getCameraImage(
    width=1280, 
    height=720,
    viewMatrix=viewMat,
    projectionMatrix=projMat)

print(depthImg)

this is my camera_upvec function if that helps:

from numpy import cos, sin, arccos, arcsin

def camera_upvec(pos_vec):
    theta = arccos(pos_vec[-1])
    sintheta = sin(theta)
    phi = arccos(pos_vec[0]/sintheta)

    u1 = np.array([cos(theta)*cos(phi), cos(theta)*sin(phi), -sin(theta)])
    # u2 = np.array([-sin(phi), cos(phi), 0])

    return -u1

And this is what the gui with the images looks like:
GUI with image visuals

Is there something obvious that is going wrong that anyone can tell?

I tried different camera angles. Some other camera nearVal/farVals. I expected the depthImg to not be full of nan values

Asked By: Manav Kulshrestha

||

Answers:

I figured it out, btw. It was because nearVal needs to be a nonzero value. I’m guessing pybullet divides by nearVal at some point.

Answered By: Manav Kulshrestha
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.