一、环境背景操作系统: Windows 11 WSL 2 (Ubuntu 20.04)硬件: Intel RealSense D435i目标: 在 WSL 中驱动相机采集点云二、关键成功步骤1️⃣ Windows 端USB 设备转发usbipd-winpowershell # 管理员 PowerShell usbipd list # 找到相机 BUSID (1-4) usbipd bind --busid 1-4 # 绑定设备 usbipd attach --wsl --busid 1-4 # 附加到 WSL2️⃣ WSL 端安装依赖bash # 基础依赖 sudo apt-get update sudo apt-get install libusb-1.0-0-dev libudev-dev \ libssl-dev pkg-config libgtk-3-dev \ git wget cmake build-essential \ libglfw3-dev libgl1-mesa-dev libglu1-mesa-dev # Python 相关 sudo apt-get install python3-dev python3-distutils3️⃣ 编译 librealsense跳过内核补丁bash cd ~/catkin_ws git clone https://github.com/IntelRealSense/librealsense.git cd librealsense # 设置 udev 规则 ./scripts/setup_udev_rules.sh # 编译关键FORCE_RSUSB_BACKENDON mkdir build cd build cmake .. -DFORCE_RSUSB_BACKENDON -DBUILD_EXAMPLESfalse make -j4 sudo make install sudo ldconfig4️⃣ 安装 Python 绑定bash # 不要用 pip 装使用源码编译的绑定 cd ~/catkin_ws/librealsense/build cmake .. -DFORCE_RSUSB_BACKENDON -DBUILD_PYTHON_BINDINGSON -DBUILD_EXAMPLESfalse make -j4 sudo make install # 验证版本 python3 -c import pyrealsense2 as rs; print(rs.__version__) # 输出: 2.58.25️⃣ 测试相机bash python3 -c import pyrealsense2 as rs import os os.environ[RSUSB_BACKEND] 1 pipeline rs.pipeline() config rs.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) pipeline.start(config) frames pipeline.wait_for_frames() depth frames.get_depth_frame() color frames.get_color_frame() print(深度图:, depth.get_width(), x, depth.get_height()) print(彩色图:, color.get_width(), x, color.get_height()) pipeline.stop()