Ver Fonte

modify Listenpic

fujiankuan há 1 ano atrás
pai
commit
c81022aecd
1 ficheiros alterados com 19 adições e 8 exclusões
  1. 19 8
      src/detection/yolov5-trt-v2.0/main_new.cpp

+ 19 - 8
src/detection/yolov5-trt-v2.0/main_new.cpp

@@ -62,7 +62,7 @@ const bool calibrationstate = false;
 const bool cropstate = false;
 cv::Range crop_height = cv::Range(40,680);
 cv::Range crop_width = cv::Range(320,960);
-const bool trackstate = false;
+const bool trackstate = true;
 
 // stuff we know about the network and the input/output blobs
 static const int INPUT_H = 640;
@@ -340,7 +340,7 @@ vector<int> nms(vector<Detection> pre_detection, float iou_thr)
             pre_detection.at(i).index = i;
             pre_detection_new.push_back(pre_detection.at(i));
         }
-        //循环便利获得保留box位置索引-相对输入pre_detection位置
+        //循环遍历获得保留box位置索引-相对输入pre_detection位置
         while (pre_detection_new.size() > 0) {
             index = get_max_index(pre_detection_new);
             if (index >= 0) {
@@ -659,12 +659,11 @@ void Listenpic(const char * strdata,const unsigned int nSize,const unsigned int
         std::vector<unsigned char> buff(pic.picdata().data(),pic.picdata().data() + pic.picdata().size());
         mat = cv::imdecode(buff,cv::IMREAD_COLOR);
     }
-    cv::Mat frame;
     if(calibrationstate)
-        cv::remap(frame,frame,map1,map2,cv::INTER_LINEAR,cv::BORDER_CONSTANT);
+        cv::remap(mat,mat,map1,map2,cv::INTER_LINEAR,cv::BORDER_CONSTANT);
     if(cropstate)
-        frame = frame(crop_height,crop_width);
-    imageBuffer->add(frame);
+        mat = mat(crop_height,crop_width);
+    imageBuffer->add(mat);
     mat.release();
 }
 
@@ -684,6 +683,12 @@ void Listensignal(const char * strdata,const unsigned int nSize,const unsigned i
     lightstart = brain_state.mbtraficlightstart();
 }
 
+
+bool  comp(const od::TrackingBox &a, const od::TrackingBox &b) {
+    return a.id < b.id;
+}
+
+
 int main(int argc, char** argv)
 {
     showversion("yolov5s");
@@ -758,12 +763,12 @@ int main(int argc, char** argv)
                 auto start = std::chrono::system_clock::now();  //时间函数
                 cv::Mat frame;
                 imageBuffer->consume(frame);
-
                 frame_count++;
-
                 cv::Mat res_img; // result image
                 vector<Detection> results;
                 vector<Detection>results_track;
+
+//================================== infer ==========================
                 infer(frame,results);
 
 //================================== track ==========================
@@ -784,6 +789,9 @@ int main(int argc, char** argv)
                     }
                     vector<od::TrackingBox>track_result_90;
                     bool track_flag_90 = od::TrackObstacle(frame_count,trackers_90,outs_90,track_result_90);
+
+                    //sort(track_result_90.begin(), track_result_90.end(), comp);  //track id 本来就是由大到小
+
                     for(unsigned int i=0;i < track_result_90.size(); i++)
                     {
                         Detection obstacle;
@@ -791,6 +799,9 @@ int main(int argc, char** argv)
                         obstacle.bbox[1] = track_result_90[i].box.y;
                         obstacle.bbox[2] = track_result_90[i].box.width;
                         obstacle.bbox[3] = track_result_90[i].box.height;
+
+                        //cout<<"11111: "<<track_result_90[i].id<<endl;
+
                         //通过判断5帧数输出颜色
                         vector<int> class_history;
                         class_history = track_result_90[i].class_history;