在仿真软件中修改对应机器人仿真脚本内容
将其中对应的函数进行替换,特别注意以下修改会将深度数据改为以m为单位的形式
对应的函数源码如下
- function imagePublish()
- imageBuffer = {}
- local x, y = 0, 0
- local resolution = {}
- -- UVC
- resolution = sim.getVisionSensorResolution(cameraHandle[1aaaa])
- imageBuffer[1] = sim.getVisionSensorImage(cameraHandle[1], x, y, resolution[1], resolution[2], 1)
- simROS.imageTransportPublish(UVCRgbImagePub, imageBuffer[1], resolution[1], resolution[2], tostring(imageFrameId))
- -- D435 coloraaa
- resolution = sim.getVisionSensorResolution(cameraHandle[2])
- imageBuffer[2] = sim.getVisionSensorImage(cameraHandle[2], x, y, resolution[1], resolution[2], 1)
- simROS.imageTransportPublish(D435ColorImagePub, imageBuffer[2], resolution[1], resolution[2], tostring(imageFrameId))
- -- D435 depth
- --imageBuffer[3] = sim.getVisionSensorDepthBuffer(cameraHandle[2]+sim.handleflag_codedstring, x, y, resolution[1], resolution[2])
- imageBuffer[3] = sim.getVisionSensorDepthBuffer(cameraHandle[2]+sim.handleflag_codedstring+sim.handleflag_depthbuffermeters, x, y, resolution[1], resolution[2])
- -- deepData = sim.transformImage(imageBuffer[3],{640,480},4)
-
- depthImageMsg={}
- depthImageMsg['header']={seq=0, stamp=0, frame_id=tostring(imageFrameId)}
- depthImageMsg['height']=resolution[2]
- depthImageMsg['width']=resolution[1]
- depthImageMsg['encoding']='32FC1' -- ?
- depthImageMsg['is_bigendian']=0
- depthImageMsg['step']=640*4
- depthImageMsg['data']=imageBuffer[3]
- simROS.publish(D435DepthImagePub, depthImageMsg)
-
- imageFrameId = imageFrameId + 1
- end
复制代码
可以实现你需求的效果,其中需要注意的是数据的大小端模式会和你使用的平台相关,图片编码是32FC,在cvbridge中需要用到
|