from libero.libero.envs import OffScreenRenderEnv
from IPython.display import display
from PIL import Image
import torch
import torchvision
env_args = {
"bddl_file_name": os.path.join(os.path.join(get_libero_path("bddl_files"), task.problem_folder, task.bddl_file)),
"camera_heights": 128,
"camera_widths": 128
}
env = OffScreenRenderEnv(**env_args)
#设置种子
env.seed(0)
#环境重置
env.reset()
#初始化
env.set_init_state(init_states[0])
#运动机械臂更新环境
obs, _, _, _ = env.step([0.] * 7)
#获取手外相机视角图片
image = (obs["agentview_image"])
image_ = (obs["robot0_eye_in_hand_image"])
display(Image.fromarray(image))
display(Image.fromarray(image_))
obs, _, _, _ = env.step([500.,0.,0.,0.,0.,0.,0.] )
#获取手外相机视角图片
image = (obs["agentview_image"])
display(Image.fromarray(image))
obs, _, _, _ = env.step([500.,0.,0.,0.,0.,0.,0.] )
#获取手外相机视角图片
image = (obs["agentview_image"])
display(Image.fromarray(image))
obs, _, _, _ = env.step([500.,0.,0.,0.,0.,0.,0.] )
#获取手外相机视角图片
image = (obs["agentview_image"])
display(Image.fromarray(image))
运行结果
## 4.关闭环境
env.close()