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 可以忽略 )
相关推荐
吴声子夜歌39 分钟前
OpenCV——Mat类及常用数据结构
数据结构·opencv·webpack
ArcX2 小时前
从 JS 到 Rust 的旅程
前端·javascript·rust
Humbunklung2 小时前
Rust Floem UI 框架使用简介
开发语言·ui·rust
新知图书5 小时前
OpenCV为图像添加边框
人工智能·opencv·计算机视觉
寻月隐君7 小时前
深入解析 Rust 的面向对象编程:特性、实现与设计模式
后端·rust·github
audyxiao0011 天前
计算机视觉顶刊《International Journal of Computer Vision》2025年5月前沿热点可视化分析
图像处理·人工智能·opencv·目标检测·计算机视觉·大模型·视觉检测
whoarethenext1 天前
使用 C/C++ 和 OpenCV 实现滑动条控制图像旋转
c语言·c++·opencv
SuperW1 天前
Opencv中的copyto函数
人工智能·opencv·计算机视觉
whoarethenext1 天前
使用 OpenCV (C++) 进行人脸边缘提取
c++·人工智能·opencv
阿幸软件杂货间1 天前
PPT转图片拼贴工具 v3.0
python·opencv·计算机视觉·powerpoint