瑞芯微RK3588 RV1126应用学习
image_rect_t原因?1)cv::Rect 是OpenCV标准库中一个功能完整的、面向对象的矩形类。image_rect_t 通常是一个特定硬件平台或嵌入式SDK(如Rockchip RKNN、华为Atlas、或其他AI加速平台)定义的、用于与底层驱动或硬件通信的简单的C语言结构体。
1. Linux 编译库
- gcc-aarch64: GCC-9.3编译,适用于64位Linux系统(适用于RK3588、RK3566、RK3568等芯片平台)
- gcc-armhf: GCC-8.3编译,适用于32位Linux系统(适用于RK3588、RK3566、RK3568、RV1109、RV1126等芯片平台)
- gcc-uclib-armhf:GCC-rockchip830-uclibc编译,适用于特定的使用uclibc的32位Linux系统(适用于RV1103、RV1106芯片平台)
- gcc-armhf-c: GCC-8.3编译,适用于不依赖C++的32位Linux系统(适用于RK3506芯片平台)
- gcc-uclib-armhf-c:GCC-rockchip830-uclibc编译,适用于特定的使用uclibc不依赖C++的32位Linux系统(适用于RV1103B芯片平台)
RV1126相关库及头文件更新的路径为:
/home/thomas/rv1126/repo_new/buildroot/output/rockchip_rv1126_rv1109/host/arm-buildroot-linux-gnueabihf
2. 目标框在RK3588 RV1126的目标框不用cv::Rect而用自定义结构体image_rect_t原因?
1)cv::Rect 是OpenCV标准库中一个功能完整的、面向对象的矩形类。
image_rect_t 通常是一个特定硬件平台或嵌入式SDK(如Rockchip RKNN、华为Atlas、或其他AI加速平台)定义的、用于与底层驱动或硬件通信的简单的C语言结构体。
cv::Rect 来自OpenCV标准OpenCV库 (#include <opencv2/opencv.hpp>)
类型为C++ 类 (class)
特点:
功能丰富:提供大量用于矩形操作的成员函数(计算面积、判断空矩形、求交集/并集、判断包含点等)。
运算符重载:支持 +, -, &, | 等运算符,使代码更直观。与OpenCV生态无缝集成:可以轻松与 cv::Mat (图像), cv::Point, cv::Size 等类型一起使用。
2)image_rect_t 通常来自硬件嵌入式平台的SDK头文件(例如 rknn_api.h, hiai_base_types.h 等)。
类型为C 结构体 (struct) 或 C++ POD类型。
特点:
简单轻量:只有纯粹的数据成员,没有成员函数。设计目标是与C语言API兼容,方便在库、驱动、硬件之间高效地传递数据。
定义不统一:其具体字段名称(left/top/right/bottom 还是 x/y/width/height)和类型(int 还是 unsigned short)完全由定义它的SDK决定。必须查阅对应SDK的文档。
硬件/平台专用:用于将矩形信息传递给特定的硬件加速器(如NPU)或从其中接收结果。
跨语言兼容:由于是简单的C结构体,可以被C、C++、甚至通过FFI被其他语言(如Python)轻松使用。
3)两者之间的转换方法
#include <opencv2/opencv.hpp>
// 假设从SDK头文件引入的定义
typedef struct {
int left;
int top;
int right;
int bottom;
} image_rect_t;
// 1. cv::Rect -> image_rect_t
image_rect_t cvRectToPlatformRect(const cv::Rect& cv_rect) {
image_rect_t plat_rect;
plat_rect.left = cv_rect.x;
plat_rect.top = cv_rect.y;
plat_rect.right = cv_rect.x + cv_rect.width; // 注意:right是 exclusive 边界
plat_rect.bottom = cv_rect.y + cv_rect.height; // 注意:bottom是 exclusive 边界
return plat_rect;
}
// 2. image_rect_t -> cv::Rect
cv::Rect platformRectToCvRect(const image_rect_t& plat_rect) {
// 注意:cv::Rect需要 x, y, width, height
int x = plat_rect.left;
int y = plat_rect.top;
int width = plat_rect.right - plat_rect.left;
int height = plat_rect.bottom - plat_rect.top;
// 确保宽高非负
if (width < 0) { x = plat_rect.right; width = -width; }
if (height < 0) { y = plat_rect.bottom; height = -height; }
return cv::Rect(x, y, width, height);
}
int main() {
// OpenCV处理流程
cv::Rect face_rect(100, 150, 60, 80); // 在图像中检测到的人脸
// 传递给硬件SDK前进行转换
image_rect_t hw_rect = cvRectToPlatformRect(face_rect);
// some_hardware_api_process(&hw_rect);
// 从硬件SDK收到结果
image_rect_t hw_result = {/*...*/};
cv::Rect cv_result = platformRectToCvRect(hw_result);
// 用OpenCV绘制结果
// cv::rectangle(image, cv_result, cv::Scalar(0, 255, 0), 2);
return 0;
}
更多推荐
所有评论(0)