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