pybullet学习笔记(三)——相机 Synthetic Camera Rendering

目录

Synthetic Camera Rendering

computeViewMatrix

computeViewMatrixFromYawPitchRoll

computeProjectionMatrix

computeProjectionMatrixFOV

getCameraImage

getVisualShapeData

changeVisualShape

loadTexture


Synthetic Camera Rendering

PyBullet有一个内置的OpenGL GPU可视化工具和一个基于TinyRenderer的内置CPU渲染器。 这使得从任意相机位置渲染图像变得非常容易。
合成相机由两个4x4矩阵指定:视图矩阵投影矩阵。 由于这两个矩阵不是非常直观,因此有一些辅助方法可以利用易于理解的参数来计算这两个矩阵。

computeViewMatrix

computeViewMatrix输出4x4视图矩阵,存储为16个浮点数的list。输入参数如下表所示

required cameraEyePosition vec3, list of 3 floats Eye(camera)的位置,以笛卡尔世界坐标表示
required  cameraTargetPosition vec3, list of 3 floats 目标(焦点)点的位置,以笛卡尔世界坐标表示
required cameraUpVector vec3, list of 3 floats up vector of the camera, 以笛卡尔世界坐标表示
optional physicsClientId int 未使用,已添加以确保API一致性

computeViewMatrixFromYawPitchRoll

输出4x4视图矩阵,存储为16个浮点数的list,输入参数为:

required cameraTargetPosition  list of 3 floats 笛卡尔世界坐标系中的目标焦点
required distance float eye与焦点之间的距离
required yaw float yaw angle in degrees left/right around up-axis.
required pitch float pitch in degrees up/down.
required roll float roll in degrees around forward vector
required upAxisIndex int either 1 for Y or 2 for Z axis up.
optional physicsClientId int unused, added for API consistency.

computeProjectionMatrix

输出是4x4投影矩阵,存储为16个浮点的列表。输入参数如下:

required left float 左屏幕(画布)坐标
required right float 右屏幕(画布)坐标
required bottom float bottom screen (canvas) coordinate
required top float top screen (canvas) coordinate
required near float near plane distance
required far float far plane distance
optional physicsClientId int unused, added for API consistency.

computeProjectionMatrixFOV

此命令还可以使用不同的参数返回4x4投影矩阵。 您可以查看OpenGL文档中有关参数的含义。
输入参数为:

required fov float field of view
required aspect float 长宽比
required nearVal float near plane distance
required farVal float far plane distance
optional physicsClientId int unused, added for API consistency.


getCameraImage

getCameraImage API将返回RGB图像,depth buffer 和segmentation mask buffer,其中每个像素都有可见对象的主体唯一ID。 请注意,可以使用numpy选项编译PyBullet:使用numpy将提高将相机像素从C复制到Python的性能。 注意:旧的renderImage API已过时,已由getCameraImage取代。getCameraImage的输入参数:

getCameraImage返回参数列表:

width int 宽度图像分辨率(以像素为单位)(水平)
height int 高度图像分辨率(以像素为单位)(垂直)
rgbPixels list of [char RED,char GREEN,char BLUE, char ALPHA] [0..width*height] RGB像素颜色列表,一种格式,每种颜色的范围为[0..255]
depthPixels  list of float [0..width*height]  depth buffer
segmentationMaskBuffer  list of int [0..width*height]  Only available when using ER_TINY_RENDERER.
For each pixels the visible object unique id. If ER_SEGMENTATION_MASK_OBJ ECT_AND_LINKINDEX is used, the segmentationMaskBuffer combines the object unique id and link index as follows: value = objectUniqueId + (linkIndex+1)<<24. See example.
So for a free floating body without joints/links, the segmentation mask is equal to its body unique id, since its link index is -1.

请注意,对于大图像而言,将像素从C / C ++复制到Python真的很慢,除非您使用NumPy编译PyBullet。 您可以使用PyBullet.isNumpyEnabled()检查是否启用了NumPy。


getVisualShapeData

您可以使用getVisualShapeData访问visual shape 信息。 您可以使用它将自己的渲染方法与PyBullet仿真联系起来,并在每个仿真步骤之后手动同步世界坐标变换。输入参数:

required objectUniqueId int 物体的唯一ID,由load方法返回。
optional physicsClientId  int physics client id as returned by 'connect'

输出是visual shape 数据的列表,每个visual shape 的格式如下:

objectUniqueId int  object unique id, same as the input
linkIndex int  link index or -1 for the base
visualGeometryType int  visual geometry type (TBD)
dimensions vec3, list of 3 floats dimensions (size, local scale) of the geometry
meshAssetFileName string, list of chars path to the triangle mesh, if any. Typically relative to the URDF, SDF or MJCF file location, but could be absolute.
localVisualFrame position vec3, list of 3 floats position of local visual frame, relative to link/joint frame
localVisualFrame orientation vec4, list of 4 floats  orientation of local visual frame relative to link/joint frame
rgbaColor vec4, list of 4 floats  URDF color (if any specified) in red/green/blue/alpha

The physics simulation uses center of mass as a reference for the Cartesian world transforms, in getBasePositionAndOrientation and in getLinkState. If you implement your own rendering, you need to transform the local visual transform to world space, making use of the center of mass world transform and the (inverse) localInertialFrame. You can access the localInertialFrame using the getLinkState API.


changeVisualShape

可以使用changeVisualShape更改形状的纹理。 当前,此纹理将仅影响软件渲染器(请参见getCameraImage),而不影响OpenGL可视化窗口(yet)。

loadTexture

从文件加载纹理,如果加载成功,则返回非负整数作为纹理的唯一ID。 此唯一的ID可以与changeVisualShape一起使用。

猜你喜欢

转载自blog.csdn.net/zxxxiazai/article/details/101073854
今日推荐