def get_camera_data(self): """ Return a tuple containing (RGB_img, Depth_img) """ # Get color image from simulation _, resolution, raw_image = vrep.simxGetVisionSensorImage( self.sim_client, self.cam_handle, 0, vrep.simx_opmode_blocking) color_img = np.asarray(raw_image) color_img.shape = (resolution[1], resolution[0], 3) color_img = color_img.astype(np.float) / 255 color_img[color_img < 0] += 1 color_img *= 255 color_img = np.fliplr(color_img) color_img = color_img.astype(np.uint8) # Get depth image from simulation sim_ret, resolution, depth_buffer = vrep.simxGetVisionSensorDepthBuffer( self.sim_client, self.cam_handle, vrep.simx_opmode_blocking) depth_img = np.asarray(depth_buffer) depth_img.shape = (resolution[1], resolution[0]) depth_img = np.fliplr(depth_img) zNear = 0.01 zFar = 10 depth_img = depth_img * (zFar - zNear) + zNear return color_img, depth_img
def get_VS_image(self, VS_handle): # Get color image from simulation sim_ret, resolution, raw_image = vrep.simxGetVisionSensorImage( self.clientID, VS_handle, 0, vrep.simx_opmode_blocking) if sim_ret == 0: color_img = np.array(raw_image).reshape( (resolution[1], resolution[0], 3)).astype(np.uint8) else: return 8, 0, 0 sim_ret, resolution, depth_buffer = vrep.simxGetVisionSensorDepthBuffer( self.clientID, VS_handle, vrep.simx_opmode_blocking) if sim_ret == 0: depth_img = np.asarray(depth_buffer).reshape( (resolution[1], resolution[0])).astype(np.double) else: return 8, 0, 0 zNear = 0.01 zFar = 10 depth_img = depth_img * (zFar - zNear) + zNear return 0, color_img, depth_img