宇树Unitree G1机器人摄像机获取
选择librealscense获取摄像头数据编译命令gitclone https://github.com/IntelRealSense/librealsense.gitcdlibrealsensemkdirbuildcdbuild cmake..-DBUILD_EXAMPLESONmake-j$(nproc)sudomakeinstall如果不需要可视化界面可以cmake..-DBUILD_EXAMPLESOFF-DBUILD_GRAPHICAL_EXAMPLESOFF可视化界面的编译非常慢获取RGB和深度图像的python代码importpyrealsense2asrsimportnumpyasnpimportcv2 pipeliners.pipeline()configrs.config()config.enable_stream(rs.stream.color,640,480,rs.format.bgr8,30)config.enable_stream(rs.stream.depth,640,480,rs.format.z16,30)profilepipeline.start()try:whileTrue:framespipeline.wait_for_frames()color_frameframes.get_color_frame()depth_frameframes.get_depth_frame()ifnotcolor_frameornotdepth_frame:continuecolor_imagenp.asanyarray(color_frame.get_data())depth_imagenp.asanyarray(depth_frame.get_data())save_path1rgb.pngsave_path2depth.pngcv2.imwrite(save_path1,color_image)cv2.imwrite(save_path2,depth_image)break# cv2.imshow(G1 RGB, color_image)#if cv2.waitKey(1) 27:# breakfinally:pipeline.stop()获取点云数据的python代码importpyrealsense2asrs pipeliners.pipeline()configrs.config()config.enable_stream(rs.stream.depth,640,480,rs.format.z16,30)config.enable_stream(rs.stream.color,640,480,rs.format.bgr8,30)profilepipeline.start()alignrs.align(rs.stream.color)pcrs.pointcloud()try:for_inrange(30):# 等自动曝光稳定pipeline.wait_for_frames()framespipeline.wait_for_frames()# 如果用了对齐先 align 再取帧alignrs.align(rs.stream.color)aligned_framesalign.process(frames)depth_framealigned_frames.get_depth_frame()color_framealigned_frames.get_color_frame()ifnotdepth_frameornotcolor_frame:raiseRuntimeError(Depth or Color frame is missing!)# ✅ 关键显式转换为 video_framecolor_vframecolor_frame.as_video_frame()pcrs.pointcloud()pc.map_to(color_vframe)# ✅ 传 video_frame不再报类型错pointspc.calculate(depth_frame)# 保存 PLYpoints.export_to_ply(output.ply,color_vframe)exceptExceptionase:print(e)finally:pipeline.stop()