diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..083e14c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/.idea
+Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/build
+Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/cmake-build-debug
+Code/.DS_Store
+.DS_Store
diff --git a/Code/RK3588/Robot_ROS_APP/src/ros_merge_test/.idea/workspace.xml b/Code/RK3588/Robot_ROS_APP/src/ros_merge_test/.idea/workspace.xml
new file mode 100644
index 0000000..5c2e992
--- /dev/null
+++ b/Code/RK3588/Robot_ROS_APP/src/ros_merge_test/.idea/workspace.xml
@@ -0,0 +1,397 @@
+
+
+
+
+
+ {
+ "useNewFormat": true
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {
+ "associatedIndex": 6
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1702950289245
+
+
+ 1702950289245
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/CMakeLists.txt b/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/CMakeLists.txt
index fd8191d..584e797 100644
--- a/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/CMakeLists.txt
+++ b/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/CMakeLists.txt
@@ -32,7 +32,9 @@ include_directories(${CMAKE_SOURCE_DIR}/../3rdparty)
# opencv
# set(OpenCV_DIR ${CMAKE_SOURCE_DIR}/../3rdparty/opencv/opencv-linux-aarch64/share/OpenCV)
+set(CMAKE_PREFIX_PATH "/home/luoruidi/Desktop/Package/opencv-4.8.1/build_arrch64")
find_package(OpenCV REQUIRED)
+message("!!!!!Found OpenCV ${OpenCV_VERSION}")
#Threads
find_package(Threads REQUIRED)
diff --git a/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/include/detection.h b/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/include/detection.h
index e8acb9d..ef270ed 100644
--- a/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/include/detection.h
+++ b/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/include/detection.h
@@ -24,7 +24,7 @@ private:
int img_channel = 0;
const float nms_threshold = NMS_THRESH; // 默认的NMS阈值
const float box_conf_threshold = BOX_THRESH; // 默认的置信度阈值
- char* model_name = "/home/firefly/rknpu2/examples/rknn_yolov5_demo/model/RK3588/yolov5s-640-640.rknn";
+ const char* model_name = "/home/firefly/rknpu2/examples/rknn_yolov5_demo/model/RK3588/yolov5s-640-640.rknn";
cv::Mat orig_img;
rknn_input_output_num io_num;
@@ -42,7 +42,7 @@ public:
Detection();
static unsigned char *load_data(FILE *fp, size_t ofst, size_t sz);
static unsigned char *load_model(const char *filename, int *model_size);
- detect_result_group_t outputParse(cv::Mat netInputImg);
+ detect_result_group_t outputParse(cv::Mat& netInputImg);
};
\ No newline at end of file
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 a070b98..c56f4f1 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
@@ -7,6 +7,12 @@
#include
#include "detection.h"
#include
+#include
+#include
+#include
+#include
+#include
+
using namespace cv;
@@ -18,7 +24,7 @@ private:
cv::VideoCapture vcapture;
Detection yolov5s;
- //new
+ // projection matrix
Mat cam_matrix_left = (Mat_(3, 3) <<
4.809895643547006e+02, 0, 0,
0,4.807599168204821e+02, 0,
@@ -27,6 +33,8 @@ private:
4.903260126250775e+02, 0, 0,
0,4.900310486342847e+02, 0,
3.230124997386542e+02, 2.346297967642670e+02, 1);
+
+ // distortion
Mat distortion_l = (Mat_(1, 5) <<0.113688825569154,-0.106166584327678, 0,
0, 0);
@@ -52,5 +60,11 @@ public:
std::vector pic2cam(int u, int v);
std::vector muban(cv::Mat &left_image, cv::Mat &right_image, const int *coordinates);
std::vector detObjectRanging();
- void horizon_estimate(cv::Mat& img, cv::Mat& bboxs,int k);
+ //void horizon_estimate(cv::Mat& img, cv::Mat& bboxs,int k);
+
+ std::mutex g_mutex;
+
+private:
+ void drawDetectBox(cv::Mat &target_frame , const detect_result_group_t& detect_res, cv::Mat& detBoxs_data);
+ void frameRateShow(cv::Mat ¤t_frame , int64 time);
};
diff --git a/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/install/rknn_yolov5_demo_Linux/lib/librga.so b/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/install/rknn_yolov5_demo_Linux/lib/librga.so
old mode 100644
new mode 100755
diff --git a/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/install/rknn_yolov5_demo_Linux/lib/librknnrt.so b/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/install/rknn_yolov5_demo_Linux/lib/librknnrt.so
old mode 100644
new mode 100755
diff --git a/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/install/rknn_yolov5_demo_Linux/model/RK3588/yolov5s-640-640.rknn b/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/install/rknn_yolov5_demo_Linux/model/RK3588/yolov5s-640-640.rknn
new file mode 100644
index 0000000..87419fd
Binary files /dev/null and b/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/install/rknn_yolov5_demo_Linux/model/RK3588/yolov5s-640-640.rknn differ
diff --git a/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/install/rknn_yolov5_demo_Linux/model/coco_80_labels_list.txt b/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/install/rknn_yolov5_demo_Linux/model/coco_80_labels_list.txt
new file mode 100644
index 0000000..941cb4e
--- /dev/null
+++ b/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/install/rknn_yolov5_demo_Linux/model/coco_80_labels_list.txt
@@ -0,0 +1,80 @@
+person
+bicycle
+car
+motorcycle
+airplane
+bus
+train
+truck
+boat
+traffic light
+fire hydrant
+stop sign
+parking meter
+bench
+bird
+cat
+dog
+horse
+sheep
+cow
+elephant
+bear
+zebra
+giraffe
+backpack
+umbrella
+handbag
+tie
+suitcase
+frisbee
+skis
+snowboard
+sports ball
+kite
+baseball bat
+baseball glove
+skateboard
+surfboard
+tennis racket
+bottle
+wine glass
+cup
+fork
+knife
+spoon
+bowl
+banana
+apple
+sandwich
+orange
+broccoli
+carrot
+hot dog
+pizza
+donut
+cake
+chair
+couch
+potted plant
+bed
+dining table
+toilet
+tv
+laptop
+mouse
+remote
+keyboard
+cell phone
+microwave
+oven
+toaster
+sink
+refrigerator
+book
+clock
+vase
+scissors
+teddy bear
+hair drier
+toothbrush
diff --git a/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/install/rknn_yolov5_demo_Linux/rknn_yolov5_demo b/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/install/rknn_yolov5_demo_Linux/rknn_yolov5_demo
old mode 100644
new mode 100755
index ff58437..25e6ffe
Binary files a/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/install/rknn_yolov5_demo_Linux/rknn_yolov5_demo and b/Code/RK3588/stereo_yolo/rknpu2/examples/rknn_yolov5_demo/install/rknn_yolov5_demo_Linux/rknn_yolov5_demo differ
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 18d9c1d..ba45d56 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
@@ -142,7 +142,7 @@ Detection::Detection()
}
// 这个地方采用直接传值,会影响性能
-detect_result_group_t Detection::outputParse(cv::Mat netInputImg)
+detect_result_group_t Detection::outputParse(cv::Mat& netInputImg)
{
orig_img = netInputImg.clone();
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 c3906b1..7074e2e 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
@@ -4,58 +4,55 @@
* Date of Issued : 2024.01.96 zhanli@review
* Comments : UPbot机器人双目目标测距算法
********************************************************************************/
-#include
+
#include
-// #include "lidar.h"
-// #include
-// #include
-#include
#include "ranging.h"
-// #include "fusion.h"
-#include
#include
#include
-#include
-// #include "detection.h"
-/*#include
-#include */
#include "opencv2/imgcodecs/imgcodecs.hpp"
-#include
#include
#define ANGLE_TO_RADIAN(angle) ((angle)*3141.59 / 180000)
-Ranging r(12, 640, 480);
+//Ranging r(12, 640, 480);
std::queue> frameInfo;
-std::mutex g_mutex;
+//std::mutex g_mutex; /// 这个mutxt 应该属于ranging
/**---------------------------------------------------------------------
* Function : RangingNodeTask
-* Description : 双目测距节点任务,完成摄像头帧读取、目标检测以及目标测距任务
+* Description : 双目测距节点任务,完成摄像头帧读取、目标检测以及目标测距任务 [TODO: 为什么不是一个ranging的成员函数]
* Author : hongchuyuan
* Date : 2023/12/13 zhanli@review 719901725@qq.com
*---------------------------------------------------------------------**/
-void *RangingNodeTask(void *args)
+void* RangingNodeTask(void* arg)
{
+ Ranging& r = *static_cast(arg);
while (true)
{
- // std::cout<<" ************ enter ranging *********** "< result = r.detObjectRanging();
- g_mutex.lock();
- for (uchar i = 0; i < frameInfo.size(); i++) // 只保存当前最新的图片帧信息
- frameInfo.pop();
- frameInfo.push(result);
- g_mutex.unlock();
+ r.g_mutex.lock();
+ for (uchar i = 0; i < frameInfo.size(); i++) // 只保存当前最新的图片帧信息{如果只保存一当前frame,完全不需要队列}
+ frameInfo.pop();
+ frameInfo.push(result);
+ r.g_mutex.unlock();
}
}
int main(int argc, char **argv)
{
- pthread_t tids[1]; // 执行ranging线程
- int ret = pthread_create(&tids[0], NULL, RangingNodeTask, NULL);
+ Ranging r(12, 640, 480);
+ pthread_t trd_ranging; // 执行ranging线程
+
+ if( pthread_create(&trd_ranging,NULL, RangingNodeTask , &r) != 0)
+ {
+ std::cout << "can not init rangging thread" << std::endl;
+ }
+
+ if( pthread_join(trd_ranging,NULL)!=0 )
+ {
+ std::cout << "Error join thread 1" << std::endl;
+ }
+
- 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 b48561b..8c8a7f3 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
@@ -5,33 +5,13 @@
* Date of Issued : 2024.01.07 zhanli@review
* Comments : 双目摄像头目标测距算法,需要依赖OpenCV以及目标检测模块
********************************************************************************/
-#include
-#include
#include "ranging.h"
-#include
-#include
-#include
-#include
-#include
// OpenCV相关
#include "opencv2/core.hpp"
-#include "opencv2/imgcodecs.hpp"
#include "opencv2/imgproc.hpp"
-#include
#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-
-// 上面重复无用的头文件应该删除
-// #include
using namespace cv;
// 重映射函数
@@ -52,6 +32,7 @@ std::vector Ranging::pic2cam(int u, int v)
}
// 模板匹配
+// 在右图像 right_image 中定位左图像中已检测到的目标框的位置。
std::vector Ranging::muban(Mat &left_image, Mat &right_image, const int *coordinates)
{
int x1 = coordinates[0], y1 = coordinates[1], x2 = coordinates[2], y2 = coordinates[3];
@@ -90,7 +71,7 @@ std::vector Ranging::muban(Mat &left_image, Mat &right_image, const int *co
return maxloc;
}
-// 这个函数暂时不知道作用
+/*
void Ranging::horizon_estimate(Mat& img, Mat& bboxs,int k)
{
//保证摄像头与地面平行
@@ -154,15 +135,14 @@ void Ranging::horizon_estimate(Mat& img, Mat& bboxs,int k)
this->Z = Z.clone();
}
+ */
void Ranging::getInfo(Mat &imgL, Mat &imgR, Mat &detBoxes, Mat &info)
{
Mat imgGrayL, imgGrayR;
cvtColor(imgL, imgGrayL, COLOR_BGR2GRAY);
cvtColor(imgR, imgGrayR, COLOR_BGR2GRAY);
- // 优化:这个地方的imgR_weight没有起到任何作用
- // 纯粹浪费CPU计算了
- Mat imgR_weight = imgR.clone();
+
Mat infoRow;
for (uchar i = 0; i < detBoxes.rows; i++)
@@ -176,54 +156,54 @@ void Ranging::getInfo(Mat &imgL, Mat &imgR, Mat &detBoxes, Mat &info)
float Conf = detBoxes.at(i, 4);
int cls = detBoxes.at(i, 5);
- // 当目标框偏左、偏右或者过大,略去该物体
+ // 当目标框偏左、偏右或者过大,略去该物体
if (x1 > 600 || x2 < 50 || y1 < 5 || y2 > 475 || x1 < 2 || x2 > 590 || abs(x2 - x1) > 550) {
continue;
}
// 绘制目标框
- rectangle(imgR, Point(int(x1), int(y1)),Point(int(x2), int(y2)), Scalar(0, 0, 255));
-
+ rectangle(imgR, Point(int(x1), int(y1)),Point(int(x2), int(y2)), Scalar(0, 0, 255));
+
// 检测的是右图,利用模板匹配去找左图的位置
int coordinates[4] = {x1, y1, x2, y2};
// 模板匹配
- std::vector disp_pixel = muban(imgGrayL, imgGrayR, coordinates);
+ std::vector disp_pixel = muban(imgGrayL, imgGrayR, coordinates);
// 这里用disp_x 有点奇怪?用dispDiffX
// 计算水平视差 左图匹配的x坐标和右图的x坐标之差
float disp_pixel_x = disp_pixel[0] - x1;
// 垂直的误差没有起到作用
- float disp_pixel_y = disp_pixel[1] - y1;
+ float disp_pixel_y = disp_pixel[1] - y1;
// 0.12为模板匹配产生的误差,为经验值,通过拟合得到
- disp_pixel_x = (int)(disp_pixel_x + disp_pixel_x * 0.12);
-
+ disp_pixel_x = (int)(disp_pixel_x + disp_pixel_x * 0.12);
+
//Mat disp_matrix = Mat(1, 1, CV_32F, Scalar(disp_pixel_x)), disp_pixel_xyz;
// 定义视差矩阵,所有值均为水平视差,方便转换为三维坐标,并具有水平距离信息
- Mat disp_matrix = Mat(imgGrayL.rows, imgGrayL.cols, CV_32F, Scalar(disp_pixel_x));
- Mat threed_pixel_xyz, threedImage;
+ Mat disp_matrix = Mat(imgGrayL.rows, imgGrayL.cols, CV_32F, Scalar(disp_pixel_x));
+ Mat threed_pixel_xyz, threedImage;
// 通过quat将显示图像从2d映射到3d
reprojectImageTo3D(disp_matrix, threedImage, q, false);
// 图像的3个通道,每一像素点求平方
- threed_pixel_xyz = threedImage.mul(threedImage);
+ threed_pixel_xyz = threedImage.mul(threedImage);
std::vector channels;
// 求平方后的结果,分离为3个通道,然后求和即是欧式距离
split(threed_pixel_xyz.clone(), channels);
// 计算欧式距离 = r^2 + g^2 + b^2
- threed_pixel_xyz = channels[0] + channels[1] + channels[2];
+ threed_pixel_xyz = channels[0] + channels[1] + channels[2];
threed_pixel_xyz.forEach([](float &value, const int *position) { value = sqrt(value); }); // 获得距离d
-
+
int mid_pixel = int((x1 + x2) / 2);
// 计算角度,从像素坐标转为相机坐标
// 这里用结构体比用vector更加节省CPU运算
- std::vector mid = pic2cam(imgGrayR.cols / 2, imgGrayR.rows);
+ std::vector mid = pic2cam(imgGrayR.cols / 2, imgGrayR.rows);
std::vector loc_tar = pic2cam(mid_pixel, imgGrayR.rows);
float alfa = atan((loc_tar[0] - mid[0]) / q.at(2, 3));
// 距离太近,视差过大
- if (disp_pixel_x > 240)
+ if (disp_pixel_x > 240)
{
char cm[15];
//sprintf(cm, "cannot match !");
@@ -273,7 +253,7 @@ void Ranging::getInfo(Mat &imgL, Mat &imgR, Mat &detBoxes, Mat &info)
// sprintf(wh, "W: %.2fcm H: %.2fcm alfa: %2f", w1, h1, alfa);
// putText(imgR, dc, Point(x1, y2), FONT_HERSHEY_PLAIN, 1.5, Scalar(0, 0, 255), 2);
// putText(imgR, wh, Point(x1, y1), FONT_HERSHEY_PLAIN, 1.5, Scalar(0, 0, 255), 1.5);
-
+
//返回数据
infoRow = (Mat_(1, 4) << median, w1, h1, alfa);
infoRow.copyTo(info.row(i));
@@ -284,13 +264,14 @@ void Ranging::getInfo(Mat &imgL, Mat &imgR, Mat &detBoxes, Mat &info)
}
Ranging::Ranging(int index, int imgw, int imgh) : //初始化
- mapX1(imgh, imgw, CV_64F), //初始化矩阵 ,用于计算无畸变和修正转换映射。
+ mapX1(imgh, imgw, CV_64F), //初始化矩阵 ,用于计算无畸变和修正转换映射。
mapX2(imgh, imgw, CV_64F),
mapY1(imgh, imgw, CV_64F),
mapY2(imgh, imgw, CV_64F),
q(4, 4, CV_64F),
imgw(imgw),
- imgh(imgh)
+ imgh(imgh),
+ g_mutex(),detect_result_group()
{
// Z = Mat::zeros(2, 1, CV_32FC1);
vcapture = cv::VideoCapture(index);
@@ -309,7 +290,7 @@ Ranging::Ranging(int index, int imgw, int imgh) : //初始化
imgSize, rotate.t(), trans, r1, r2, p1, p2, q);
// 计算无畸变和修正转换映射
- initUndistortRectifyMap(cam_matrix_left.t(), distortion_l, r1, p1, imgSize, CV_32F, mapX1, mapX2);
+ initUndistortRectifyMap(cam_matrix_left.t(), distortion_l, r1, p1, imgSize, CV_32F, mapX1, mapX2);
// 计算无畸变和修正转换映射
initUndistortRectifyMap(cam_matrix_right.t(), distortion_r, r2, p2, imgSize, CV_32F, mapY1, mapY2);
@@ -323,7 +304,7 @@ Ranging::Ranging(int index, int imgw, int imgh) : //初始化
* Author : hongchuyuan
* Date : 2023/12/13 zhanli@review 719901725@qq.com
*---------------------------------------------------------------------**/
-std::vector Ranging::detObjectRanging()
+std::vector Ranging::detObjectRanging()
{
double rang_old, rang_now;
@@ -338,11 +319,11 @@ std::vector Ranging::detObjectRanging()
{
int64 t = getTickCount();
// 拷贝左图
- Mat lframe(frame.colRange(0, imgw).clone());
+ Mat lframe(frame.colRange(0, imgw).clone());
// 拷贝右图
- Mat rframe(frame.colRange(imgw, imgw * 2).clone());
-
- rectifyImage(lframe, rframe);
+ Mat rframe(frame.colRange(imgw, imgw * 2).clone());
+
+ rectifyImage(lframe, rframe);
// 这里拷贝一次,然后再yolo里面再拷贝一次,以及函数传参也拷贝了一次?
cv::Mat Rframe = rframe.clone();
@@ -352,90 +333,74 @@ std::vector Ranging::detObjectRanging()
if (detect_result_group.count<=0)
{
std::cout<<"detect nothing"<{};
}
// 定义矩阵,存储目标检测内容,存储格式(x,y,x,y,conf,cls)
- Mat detBoxes(detect_result_group.count, 5, CV_32F);
- char text[256];
- // 存储目标检测内容 (x,y,x,y,conf,cls)
+ Mat detBoxes(detect_result_group.count, 5, CV_32F);
+ drawDetectBox(Rframe,detect_result_group,detBoxes);
- // 这里应该写一个函数drawDetectBobox()
- for (int i = 0; i < detect_result_group.count; i++)
- {
- detect_result_t *det_result = &(detect_result_group.results[i]);
- sprintf(text, "%s %.1f%%", det_result->name, det_result->prop * 100);
-
- // printf("%s @ (%d %d %d %d) %f\n", det_result->name, det_result->box.left, det_result->box.top,
- // det_result->box.right, det_result->box.bottom, det_result->prop);
-
- int xmin = det_result->box.left;
- int ymin = det_result->box.top;
- int xmax = det_result->box.right;
- int ymax = det_result->box.bottom;
-
- rectangle(Rframe, cv::Point(xmin, ymin), cv::Point(xmax, ymax), cv::Scalar(256, 0, 0, 256), 3);
- putText(Rframe, text, cv::Point(xmin, ymin + 12), cv::FONT_HERSHEY_SIMPLEX, 0.4, cv::Scalar(255, 255, 255));
-
- // (x,y) (x,y) conf
- detBoxes.at(i, 0) = xmin;
- detBoxes.at(i, 1) = ymin;
- detBoxes.at(i, 2) = xmax;
- detBoxes.at(i, 3) = ymax;
- detBoxes.at(i, 4) = det_result->prop;
- // 实验测试,过滤过大的误检框
- // float ratio = (xmax - xmin) * (ymax - ymin) / 308480.;
- // if (ratio > 0.7)
- // {
- // detBoxes.at(i, 5) = -1;
- // continue;
- // }
- }
// 存储测距信息,存储格式:距离d,宽w,高h,角度alpha
- Mat info(detect_result_group.count, 4, CV_32F);
-
+ Mat info(detect_result_group.count, 4, CV_32F);
+
// 如果有检测目标
if (detect_result_group.count)
{
- // getInfo()修改为calObjectRanging()
+ // getInffpso()修改为calObjectRanging()
// 在这里测量目标的距离并存储到info中
// 优化:这个地方重复的将左右视图转换为灰度图,浪费CPU的算力
getInfo(lframe, rframe, detBoxes, info);
-
- //show stereo distance
- //zai zhe li kai ke neng cheng xu hui beng le
-
- // for(int i=0; i(i, 0);
- // float w1 = info.at(i, 1);
- // float h1 = info.at(i, 2);
- // float alfa = info.at(i, 3);
-
- // int x1 = det_result->box.left;
- // int y1 = det_result->box.top;
- // int x2 = det_result->box.right;
- // int y2 = det_result->box.bottom;
- // char dc[50], wh[50];
- // sprintf(dc, "dis:%.2fcm ", median);
- // sprintf(wh, "W: %.2fcm H: %.2fcm ", w1, h1);
- // putText(Rframe, dc, Point(x1, y2), FONT_HERSHEY_PLAIN, 1.5, Scalar(0, 0, 255), 2);
- // putText(Rframe, wh, Point(x1, y1), FONT_HERSHEY_PLAIN, 1.5, Scalar(0, 0, 255), 1.5);
- // }
}
- // 这个地方应该整为一个函数,负责显示帧率图像
t = getTickCount() - t;
- char fps[50];
- sprintf(fps, "fps: %d", int(1 / (t / getTickFrequency())));
- putText(Rframe, fps, Point(20, 20), FONT_HERSHEY_PLAIN, 1, Scalar(0, 0, 255), 1.5);
-
- cv::imshow("k",Rframe);
- cv::waitKey(1);
+ frameRateShow(Rframe , t);
return std::vector{rframe, detBoxes, info};
}
return std::vector{rframe};
}
+
+void Ranging::drawDetectBox(Mat &target_frame, const detect_result_group_t &detect_res ,cv::Mat& detBoxs_data) {
+ char text[256];
+ // 这里应该写一个函数drawDetectBobox()
+ for (int i = 0; i < detect_result_group.count; i++)
+ {
+ detect_result_t *det_result = &(detect_result_group.results[i]);
+ sprintf(text, "%s %.1f%%", det_result->name, det_result->prop * 100);
+
+ // printf("%s @ (%d %d %d %d) %f\n", det_result->name, det_result->box.left, det_result->box.top,
+ // det_result->box.right, det_result->box.bottom, det_result->prop);
+
+ int xmin = det_result->box.left;
+ int ymin = det_result->box.top;
+ int xmax = det_result->box.right;
+ int ymax = det_result->box.bottom;
+
+ rectangle(target_frame, cv::Point(xmin, ymin), cv::Point(xmax, ymax), cv::Scalar(256, 0, 0, 256), 3);
+ putText(target_frame, text, cv::Point(xmin, ymin + 12), cv::FONT_HERSHEY_SIMPLEX, 0.4, cv::Scalar(255, 255, 255));
+
+ // (x,y) (x,y) conf
+ detBoxs_data.at(i, 0) = xmin;
+ detBoxs_data.at(i, 1) = ymin;
+ detBoxs_data.at(i, 2) = xmax;
+ detBoxs_data.at(i, 3) = ymax;
+ detBoxs_data.at(i, 4) = det_result->prop;
+ // 实验测试,过滤过大的误检框
+ // float ratio = (xmax - xmin) * (ymax - ymin) / 308480.;
+ // if (ratio > 0.7)
+ // {
+ // detBoxes.at(i, 5) = -1;
+ // continue;
+ // }
+ }
+}
+
+void Ranging::frameRateShow(Mat &frame, int64 time) {
+ char fps[50];
+ sprintf(fps, "fps: %d", int(1 / (time / getTickFrequency())));
+ putText( frame, fps, Point(20, 20), FONT_HERSHEY_PLAIN, 1, Scalar(0, 0, 255), 1.5);
+
+ cv::imshow("k", frame);
+ cv::waitKey(1);
+}