From 326173660f8da143d3903dcd8a10b1ba89063229 Mon Sep 17 00:00:00 2001 From: zhanli <719901725@qq.com> Date: Sun, 7 Jan 2024 00:19:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=83=A8=E5=88=86=E6=B3=A8?= =?UTF-8?q?=E9=87=8A=E5=86=85=E5=AE=B9=EF=BC=8C=E9=87=8D=E6=9E=84=E9=83=A8?= =?UTF-8?q?=E5=88=86=E5=87=BD=E6=95=B0=E5=90=8D=E6=9B=B4=E5=8A=A0=E7=AC=A6?= =?UTF-8?q?=E5=90=88=E5=85=B6=E4=BD=9C=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rknn_yolov5_demo/include/ranging.h | 2 +- .../rknn_yolov5_demo/src/detection.cc | 10 ++++++-- .../examples/rknn_yolov5_demo/src/main.cpp | 19 +++++++++++---- .../examples/rknn_yolov5_demo/src/ranging.cpp | 23 +++++++++++++++---- 4 files changed, 42 insertions(+), 12 deletions(-) diff --git a/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/include/ranging.h b/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/include/ranging.h index d6f84fb..a070b98 100644 --- a/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/include/ranging.h +++ b/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/include/ranging.h @@ -51,6 +51,6 @@ public: void getInfo(cv::Mat &imgl, cv::Mat &imgr, cv::Mat &detBoxes, cv::Mat &info); std::vector pic2cam(int u, int v); std::vector muban(cv::Mat &left_image, cv::Mat &right_image, const int *coordinates); - std::vector get_range(); + std::vector detObjectRanging(); void horizon_estimate(cv::Mat& img, cv::Mat& bboxs,int k); }; diff --git a/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/src/detection.cc b/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/src/detection.cc index d58a851..18d9c1d 100644 --- a/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/src/detection.cc +++ b/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/src/detection.cc @@ -1,7 +1,13 @@ +/******************** (C) COPYRIGHT 2024 UPBot ********************************** +* File Name : detection.cpp +* Current Version : V1.0 +* Author : Rockchip & linyuehang +* Date of Issued : 2024.01.07 zhanli@review +* Comments : 目标检测类,负责调用瑞芯微芯片NPU进行目标检测推理 +********************************************************************************/ #include "detection.h" #include - unsigned char * Detection::load_data(FILE *fp, size_t ofst, size_t sz) { unsigned char *data; @@ -130,7 +136,7 @@ Detection::Detection() inputs[0].index = 0; inputs[0].type = RKNN_TENSOR_UINT8; inputs[0].size = width * height * channel; - inputs[0].fmt = RKNN_TENSOR_NHWC; + inputs[0].fmt = RKNN_TENSOR_NHWC; inputs[0].pass_through = 0; } diff --git a/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/src/main.cpp b/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/src/main.cpp index 1ccf57e..c3906b1 100644 --- a/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/src/main.cpp +++ b/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/src/main.cpp @@ -1,3 +1,9 @@ +/******************** (C) COPYRIGHT 2024 UPBot ********************************** +* File Name : main.cpp +* Current Version : V1.0 +* Date of Issued : 2024.01.96 zhanli@review +* Comments : UPbot机器人双目目标测距算法 +********************************************************************************/ #include #include // #include "lidar.h" @@ -23,12 +29,18 @@ Ranging r(12, 640, 480); std::queue> frameInfo; std::mutex g_mutex; -void *ranging(void *args) // ranging线程 +/**--------------------------------------------------------------------- +* Function : RangingNodeTask +* Description : 双目测距节点任务,完成摄像头帧读取、目标检测以及目标测距任务 +* Author : hongchuyuan +* Date : 2023/12/13 zhanli@review 719901725@qq.com +*---------------------------------------------------------------------**/ +void *RangingNodeTask(void *args) { while (true) { // std::cout<<" ************ enter ranging *********** "< result = r.get_range(); + std::vector result = r.detObjectRanging(); g_mutex.lock(); for (uchar i = 0; i < frameInfo.size(); i++) // 只保存当前最新的图片帧信息 frameInfo.pop(); @@ -40,11 +52,10 @@ void *ranging(void *args) // ranging线程 int main(int argc, char **argv) { pthread_t tids[1]; // 执行ranging线程 - int ret = pthread_create(&tids[0], NULL, ranging, NULL); + int ret = pthread_create(&tids[0], NULL, RangingNodeTask, NULL); while(1){ usleep(150000); } - return 0; } diff --git a/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/src/ranging.cpp b/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/src/ranging.cpp index b17b6c8..b48561b 100644 --- a/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/src/ranging.cpp +++ b/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/src/ranging.cpp @@ -1,3 +1,10 @@ +/******************** (C) COPYRIGHT 2024 UPBot ********************************** +* File Name : ranging.cpp +* Current Version : V1.0 +* Author : Rockchip & linyuehang +* Date of Issued : 2024.01.07 zhanli@review +* Comments : 双目摄像头目标测距算法,需要依赖OpenCV以及目标检测模块 +********************************************************************************/ #include #include #include "ranging.h" @@ -297,8 +304,9 @@ Ranging::Ranging(int index, int imgw, int imgh) : //初始化 auto imgSize = Size(imgw, imgh); Mat r1(3, 3, CV_64F), r2(3, 3, CV_64F), p1(3, 4, CV_64F), p2(3, 4, CV_64F); + // 立体校正 stereoRectify(cam_matrix_left.t(), distortion_l, cam_matrix_right.t(), distortion_r, - imgSize, rotate.t(), trans, r1, r2, p1, p2, q);//立体校正 + imgSize, rotate.t(), trans, r1, r2, p1, p2, q); // 计算无畸变和修正转换映射 initUndistortRectifyMap(cam_matrix_left.t(), distortion_l, r1, p1, imgSize, CV_32F, mapX1, mapX2); @@ -309,8 +317,13 @@ Ranging::Ranging(int index, int imgw, int imgh) : //初始化 std::cout<< " ******************* CAMERA initialization ********************" << std::endl; } - -std::vector Ranging::get_range() +/**--------------------------------------------------------------------- +* Function : detObjectRanging +* Description : 摄像头帧读取、目标检测以及目标测距任务 +* Author : hongchuyuan +* Date : 2023/12/13 zhanli@review 719901725@qq.com +*---------------------------------------------------------------------**/ +std::vector Ranging::detObjectRanging() { double rang_old, rang_now; @@ -378,7 +391,7 @@ std::vector Ranging::get_range() // } } - // 存储测距信息,存储格式:距离d,宽w,高h,角度α + // 存储测距信息,存储格式:距离d,宽w,高h,角度alpha Mat info(detect_result_group.count, 4, CV_32F); // 如果有检测目标 @@ -386,7 +399,7 @@ std::vector Ranging::get_range() { // getInfo()修改为calObjectRanging() // 在这里测量目标的距离并存储到info中 - // 优化: 这个地方重复的将左右视图转换为灰度图,浪费CPU的算力 + // 优化:这个地方重复的将左右视图转换为灰度图,浪费CPU的算力 getInfo(lframe, rframe, detBoxes, info); //show stereo distance