我正在尝试在 Pybullet 模拟器中捕获的图像中产生阴影。阴影在 debugGUI 模式下显示,但在调用时不可见,p.getCameraImage
即使使用shadow=True
.
我注意到的另一件事是当shadow=True
有p.getCameraImage
一个大阴影时,好像有一个高大的物体挡住了光线,而不是对应于该物体的小阴影。
问题仍然存在,无论是连接到直接 ( p.connect(p.DIRECT)
) 还是连接到 GUI ( p.connect(p.GUI)
),如下所示:https ://github.com/bulletphysics/bullet3/issues/2610并且我在下面附上了重现问题所需的最低代码示例。
import pybullet as p
import pybullet_data
from PIL import Image
import math
physicsClient = p.connect(p.DIRECT)
p.setAdditionalSearchPath(pybullet_data.getDataPath())
p.configureDebugVisualizer(p.COV_ENABLE_SHADOWS, 1) # Shadows on/off
planeId = p.loadURDF("plane.urdf")
p.loadURDF("sphere_small.urdf",[0,0,0.2])
projectionMatrix = p.computeProjectionMatrixFOV(
fov=90.0,
aspect=16. / 9.,
nearVal=0.1,
farVal=30)
for i in range(360):
viewMatrix = p.computeViewMatrix(
cameraEyePosition=[2*math.cos(math.radians(i)), 2*math.sin(math.radians(i)),2],
cameraTargetPosition=[0.0, 0, 0],
cameraUpVector=[0, 0, 1])
width, height, rgbImg, depthImg, segImg = p.getCameraImage(
width=int(1280),
height=int(720),
viewMatrix=viewMatrix,
projectionMatrix=projectionMatrix,
shadow=True
)
im = Image.fromarray(rgbImg)
im.save('imgs/test/' + str(i) + ".png")