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。输入参数如下表所示

requiredcameraEyePositionvec3, list of 3 floatsEye(camera)的位置,以笛卡尔世界坐标表示
required cameraTargetPositionvec3, list of 3 floats目标(焦点)点的位置,以笛卡尔世界坐标表示
requiredcameraUpVectorvec3, list of 3 floatsup vector of the camera, 以笛卡尔世界坐标表示
optionalphysicsClientIdint未使用,已添加以确保API一致性

computeViewMatrixFromYawPitchRoll

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

requiredcameraTargetPosition list of 3 floats笛卡尔世界坐标系中的目标焦点
requireddistancefloateye与焦点之间的距离
requiredyawfloatyaw angle in degrees left/right around up-axis.
requiredpitchfloatpitch in degrees up/down.
requiredrollfloatroll in degrees around forward vector
requiredupAxisIndexinteither 1 for Y or 2 for Z axis up.
optionalphysicsClientIdintunused, added for API consistency.

computeProjectionMatrix

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

requiredleftfloat左屏幕(画布)坐标
requiredrightfloat右屏幕(画布)坐标
requiredbottomfloatbottom screen (canvas) coordinate
requiredtopfloattop screen (canvas) coordinate
requirednearfloatnear plane distance
requiredfarfloatfar plane distance
optionalphysicsClientIdintunused, added for API consistency.

computeProjectionMatrixFOV

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

requiredfovfloatfield of view
requiredaspectfloat长宽比
requirednearValfloatnear plane distance
requiredfarValfloatfar plane distance
optionalphysicsClientIdintunused, added for API consistency.


getCameraImage

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

getCameraImage返回参数列表:

widthint宽度图像分辨率(以像素为单位)(水平)
heightint高度图像分辨率(以像素为单位)(垂直)
rgbPixelslist 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仿真联系起来,并在每个仿真步骤之后手动同步世界坐标变换。输入参数:

requiredobjectUniqueIdint物体的唯一ID,由load方法返回。
optionalphysicsClientId intphysics client id as returned by 'connect'

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

objectUniqueIdint object unique id, same as the input
linkIndexint link index or -1 for the base
visualGeometryTypeint visual geometry type (TBD)
dimensionsvec3, list of 3 floatsdimensions (size, local scale) of the geometry
meshAssetFileNamestring, list of charspath to the triangle mesh, if any. Typically relative to the URDF, SDF or MJCF file location, but could be absolute.
localVisualFrame positionvec3, list of 3 floatsposition of local visual frame, relative to link/joint frame
localVisualFrame orientationvec4, list of 4 floats orientation of local visual frame relative to link/joint frame
rgbaColorvec4, 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一起使用。

  • 4
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值