RMVL  1.0.0
RoboMaster Vision Library
通过 gcc 和 CMake 使用视觉库

上一篇教程:视觉库的打包与安装
下一篇教程:为基于 ARM 的 Linux 系统配置交叉编译


注解
必须确保您已经成功安装了 RMVL

如果你不熟悉 CMake,请移步到 CMake 教程

详细步骤

1. 创建项目

创建新的文件夹:rmvl_deploy_test,将其链接至 RMVL

mkdir rmvl_deploy_test build
cd rmvl_deploy_test
touch main.cpp CMakeLists.txt

2. 编写测试文件

2.1 编写 main.cpp

将以下内容写至 main.cpp

#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
using namespace std;
using namespace cv;
int main(int argc, char *argv[])
{
Mat src = Mat::zeros(Size(1280, 1024), CV_8UC3);
line(src, Point(450, 380), Point(440, 470), Scalar(0, 0, 255), 18);
line(src, Point(650, 400), Point(640, 490), Scalar(0, 0, 255), 18);
line(src, Point(850, 370), Point(870, 460), Scalar(0, 0, 255), 18);
detect_ptr detector = ArmorDetector::make_detector();
vector<group_ptr> groups;
detector->detect(groups, src, RED, GyroData(), getTickCount());
auto p_combos = detector.combos;
INFO_("size of armors = %ld", p_combos.size());
for (auto &p_combo : p_combos)
{
auto corners = p_combo->getCorners();
line(src, corners[0], corners[2], Scalar(0, 255, 0), 2);
line(src, corners[1], corners[3], Scalar(0, 255, 0), 2);
}
namedWindow("rmvl_deploy_test: src", WINDOW_NORMAL);
resizeWindow("rmvl_deploy_test: src", Size(640, 512));
imshow("rmvl_deploy_test: src", src);
HIGHLIGHT_("RMVL build Successfully!\n\n\t\t-------- "
"press any key to exit this program. --------\n");
waitKey(0);
return 0;
}
#define HIGHLIGHT_(msg...)
Definition: util.hpp:28
#define INFO_(msg...)
Definition: util.hpp:56
std::unique_ptr< detector > detect_ptr
Definition: detector.h:69
@ RED
红色通道
Definition: pretreat.h:27
Definition: uty_math.hpp:63

2.2 编写 CMakeLists.txt

将以下内容写至 CMakeLists.txt

cmake_minimum_required(VERSION 3.19)
project(rmvl_deploy)
find_package(RMVL REQUIRED)
add_executable(demo main.cpp)
target_include_directories(
demo
PUBLIC ${RMVL_INCLUDE_DIRS}
)
target_link_libraries(
demo
${RMVL_LIBS}
)

3. 构建项目

rmvl_deploy_test 的顶层文件夹中打开终端,输入以下命令

cd build
cmake ..
make

4. 运行

继续输入以下命令

./demo