- 安装vscode,rust环境,跑通Hello world,参考:https://www.runoob.com/rust/rust-setup.html
- 安装realsense sdk,版本与https://github.com/Tangram-Vision/realsense-rust/tree/main 提到的版本一致
- 下载https://github.com/Tangram-Vision/realsense-rust/tree/main 源码到本地
- 配置新项目的Cargo.toml,在[dependencies]新增:
[dependencies] realsense-rust = "1.1" anyhow = "1.0" realsense-sys = "2.47.0"
- 将https://github.com/Tangram-Vision/realsense-rust/blob/main/examples/demo_435i.rs 代码拷贝到main.rs中
- vscode 扩展应用搜索:Chocolatey 并安装
- 终端输入 如下命令,可能会提示访问拒绝,请确认文件夹权限
choco install pkgconfiglite
- 终端输入如下代码,路径为第三步下载的源码的realsense-sys目录
$Env:PKG_CONFIG_PATH="F:\project\realsense-rust\realsense-sys"
- 输入
一切正常会显示:cargo build cargo run
Distance of center pixel: 1.5960001 m | Gyro reading: -0.010471975 , 0.0034906585 , -0.0052359877
踩坑:
1. Package realsense2 was not found in the pkg-config search path. Perhaps you should add the directory containing `realsense2.pc' to the PKG_CONFIG_PATH environment variable No package 'realsense2' found
是因为未配置$Env
- use of undeclared crate or module
pkg_config
: 在Cargo.toml加入 anyhow = "1.0"后此错误消失