opencv-rust 系列: 1, 安装及运行自带示例和测试程序

opencv-rust 系列: 1, 安装及运行自带示例和测试程序

    • [运行环境: ubuntu ; rust 已安装; 对rust的掌握为三脚猫程度](#运行环境: ubuntu ; rust 已安装; 对rust的掌握为三脚猫程度)
    • [一. opencv-rust安装:](#一. opencv-rust安装:)
    • [二. 运行自带examples和tests](#二. 运行自带examples和tests)

运行环境: ubuntu ; rust 已安装; 对rust的掌握为三脚猫程度

一. opencv-rust安装:

  1. 安装软件: sudo apt install libopencv-dev clang libclang-dev llvm (clang就是llvm部分)
  2. 查看版本: sudo apt show libopencv-dev ( 目前20241006支持OPENCV 4.6.0)

二. 运行自带examples和tests

  1. 安装最新的opencv库,命令: cargo add opencv ( 此时20241006, 库版本为 0.93.1 )
  2. 使用命令: locate opencv-0.93 找到库所在目录
  3. 复制一份到本地, 例如: cp -av /home/wzw/.cargo/registry/src/index.crates.io-6f17d22bba15001f/opencv-0.93.1 ./
  4. 运行自带示例(示例在examples目录中)
    1. 命令如: cargo run --example video_capture ( 摄像并显示 )
    2. 命令如: cargo run --example video_facedetect ( 人脸测试 )
    3. 备注: examples/ 目录中的程序都可以试试, 有些程序运行需要参数
  5. 运行自带的测试程序
    1. 命令: cargo test
      1. 报错: error[E0599]: no method named points_vec found for struct RotatedRect in the current scope --> tests/core_only_latest_opencv.rs:11:7
      2. 修改程序: tests/core_only_latest_opencv.rs
        1. 被替换内容:
          let mut vec_pts = Vector::new();
          rect.points_vec(&mut vec_pts)?;
          assert_eq!(Point2f::new(50., 50.), vec_pts.get(0)?);
          assert_eq!(Point2f::new(150., 50.), vec_pts.get(1)?);
          assert_eq!(Point2f::new(150., 150.), vec_pts.get(2)?);
          assert_eq!(Point2f::new(50., 150.), vec_pts.get(3)?);
        2. 替换成:
          let mut vec_pts = [Point2f::new(0.0, 0.0); 4];
          rect.points(&mut vec_pts)?;
          assert_eq!(Point2f::new(50., 50.), *vec_pts.get(0).unwrap());
          assert_eq!(Point2f::new(150., 50.), *vec_pts.get(1).unwrap());
          assert_eq!(Point2f::new(150., 150.), *vec_pts.get(2).unwrap());
          assert_eq!(Point2f::new(50., 150.), *vec_pts.get(3).unwrap());
      3. 现在再 cargo test 就可以运行通过了. ( 有两个 warning 可以忽略 )
相关推荐
无名之逆9 分钟前
[特殊字符] 超轻高性能的 Rust HTTP 服务器 —— Hyperlane [特殊字符][特殊字符]
java·服务器·开发语言·前端·网络·http·rust
搞程序的心海37 分钟前
OpenCV 进阶实战与技巧——图像处理的全面解析
图像处理·人工智能·opencv
不爱学英文的码字机器2 小时前
Rust 的征服:从系统编程到全栈开发的 IT 新宠
开发语言·后端·rust
维维酱3 小时前
Rust 智能指针
rust
进来有惊喜3 小时前
OpenCV 微笑检测
人工智能·opencv·计算机视觉
搞程序的心海4 小时前
用Python和OpenCV开启图像处理魔法之旅
图像处理·python·opencv
无名之逆14 小时前
[特殊字符] Hyperlane:Rust 高性能 HTTP 服务器库,开启 Web 服务新纪元!
java·服务器·开发语言·前端·网络·http·rust
无名之逆19 小时前
Hyperlane框架:下一代高性能Rust Web框架 [特殊字符]
服务器·开发语言·前端·后端·http·rust
zidea20 小时前
Rust 闭包:捕获环境的魔法函数
rust·ai编程·函数式编程
www_pp_20 小时前
# 利用OpenCV和Dlib实现疲劳检测:守护安全与专注
人工智能·opencv·计算机视觉